Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: webrtc/video/video_quality_test.cc

Issue 1600973002: Initialize VideoEncoder objects asynchronously. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 24 matching lines...) Expand all
35 #include "webrtc/video/video_quality_test.h" 35 #include "webrtc/video/video_quality_test.h"
36 36
37 namespace webrtc { 37 namespace webrtc {
38 38
39 static const int kSendStatsPollingIntervalMs = 1000; 39 static const int kSendStatsPollingIntervalMs = 1000;
40 static const int kPayloadTypeVP8 = 123; 40 static const int kPayloadTypeVP8 = 123;
41 static const int kPayloadTypeVP9 = 124; 41 static const int kPayloadTypeVP9 = 124;
42 42
43 class VideoAnalyzer : public PacketReceiver, 43 class VideoAnalyzer : public PacketReceiver,
44 public Transport, 44 public Transport,
45 public I420FrameCallback,
45 public VideoRenderer, 46 public VideoRenderer,
46 public VideoCaptureInput, 47 public VideoCaptureInput,
47 public EncodedFrameObserver, 48 public EncodedFrameObserver,
48 public EncodingTimeObserver { 49 public EncodingTimeObserver {
49 public: 50 public:
50 VideoAnalyzer(test::LayerFilteringTransport* transport, 51 VideoAnalyzer(test::LayerFilteringTransport* transport,
51 const std::string& test_label, 52 const std::string& test_label,
52 double avg_psnr_threshold, 53 double avg_psnr_threshold,
53 double avg_ssim_threshold, 54 double avg_ssim_threshold,
54 int duration_frames, 55 int duration_frames,
55 FILE* graph_data_output_file, 56 FILE* graph_data_output_file,
56 const std::string& graph_title, 57 const std::string& graph_title,
57 uint32_t ssrc_to_analyze) 58 uint32_t ssrc_to_analyze)
58 : input_(nullptr), 59 : input_(nullptr),
59 transport_(transport), 60 transport_(transport),
60 receiver_(nullptr), 61 receiver_(nullptr),
61 send_stream_(nullptr), 62 send_stream_(nullptr),
62 test_label_(test_label), 63 test_label_(test_label),
63 graph_data_output_file_(graph_data_output_file), 64 graph_data_output_file_(graph_data_output_file),
64 graph_title_(graph_title), 65 graph_title_(graph_title),
65 ssrc_to_analyze_(ssrc_to_analyze), 66 ssrc_to_analyze_(ssrc_to_analyze),
66 frames_to_process_(duration_frames), 67 frames_to_process_(duration_frames),
67 frames_recorded_(0), 68 frames_recorded_(0),
68 frames_processed_(0), 69 frames_processed_(0),
69 dropped_frames_(0), 70 dropped_frames_(0),
71 frames_dropped_before_first_encode_(0),
70 last_render_time_(0), 72 last_render_time_(0),
71 rtp_timestamp_delta_(0), 73 rtp_timestamp_delta_(0),
72 avg_psnr_threshold_(avg_psnr_threshold), 74 avg_psnr_threshold_(avg_psnr_threshold),
73 avg_ssim_threshold_(avg_ssim_threshold), 75 avg_ssim_threshold_(avg_ssim_threshold),
74 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), 76 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"),
75 comparison_available_event_(false, false), 77 comparison_available_event_(false, false),
76 done_(false, false) { 78 done_(false, false) {
77 // Create thread pool for CPU-expensive PSNR/SSIM calculations. 79 // Create thread pool for CPU-expensive PSNR/SSIM calculations.
78 80
79 // Try to use about as many threads as cores, but leave kMinCoresLeft alone, 81 // Try to use about as many threads as cores, but leave kMinCoresLeft alone,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 130
129 // EncodingTimeObserver. 131 // EncodingTimeObserver.
130 void OnReportEncodedTime(int64_t ntp_time_ms, int encode_time_ms) override { 132 void OnReportEncodedTime(int64_t ntp_time_ms, int encode_time_ms) override {
131 rtc::CritScope crit(&comparison_lock_); 133 rtc::CritScope crit(&comparison_lock_);
132 samples_encode_time_ms_[ntp_time_ms] = encode_time_ms; 134 samples_encode_time_ms_[ntp_time_ms] = encode_time_ms;
133 } 135 }
134 136
135 void IncomingCapturedFrame(const VideoFrame& video_frame) override { 137 void IncomingCapturedFrame(const VideoFrame& video_frame) override {
136 VideoFrame copy = video_frame; 138 VideoFrame copy = video_frame;
137 copy.set_timestamp(copy.ntp_time_ms() * 90); 139 copy.set_timestamp(copy.ntp_time_ms() * 90);
138
139 { 140 {
140 rtc::CritScope lock(&crit_); 141 rtc::CritScope lock(&crit_);
141 if (first_send_frame_.IsZeroSize() && rtp_timestamp_delta_ == 0)
142 first_send_frame_ = copy;
143
144 frames_.push_back(copy); 142 frames_.push_back(copy);
145 } 143 }
146 144
147 input_->IncomingCapturedFrame(video_frame); 145 input_->IncomingCapturedFrame(video_frame);
148 } 146 }
149 147
148 void FrameCallback(VideoFrame* video_frame) {
149 rtc::CritScope lock(&crit_);
150 if (first_send_frame_.IsZeroSize() && rtp_timestamp_delta_ == 0) {
151 while (frames_.front().timestamp() != video_frame->timestamp()) {
152 ++frames_dropped_before_first_encode_;
153 frames_.pop_front();
154 RTC_CHECK(!frames_.empty());
155 }
156 first_send_frame_ = *video_frame;
157 }
158 }
159
150 bool SendRtp(const uint8_t* packet, 160 bool SendRtp(const uint8_t* packet,
151 size_t length, 161 size_t length,
152 const PacketOptions& options) override { 162 const PacketOptions& options) override {
153 RtpUtility::RtpHeaderParser parser(packet, length); 163 RtpUtility::RtpHeaderParser parser(packet, length);
154 RTPHeader header; 164 RTPHeader header;
155 parser.Parse(&header); 165 parser.Parse(&header);
156 166
157 int64_t current_time = 167 int64_t current_time =
158 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); 168 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
159 bool result = transport_->SendRtp(packet, length, options); 169 bool result = transport_->SendRtp(packet, length, options);
160 { 170 {
161 rtc::CritScope lock(&crit_); 171 rtc::CritScope lock(&crit_);
162 if (rtp_timestamp_delta_ == 0) { 172 if (!first_send_frame_.IsZeroSize()) {
163 rtp_timestamp_delta_ = header.timestamp - first_send_frame_.timestamp(); 173 rtp_timestamp_delta_ = header.timestamp - first_send_frame_.timestamp();
164 first_send_frame_.Reset(); 174 first_send_frame_.Reset();
165 } 175 }
166 uint32_t timestamp = header.timestamp - rtp_timestamp_delta_; 176 uint32_t timestamp = header.timestamp - rtp_timestamp_delta_;
167 send_times_[timestamp] = current_time; 177 send_times_[timestamp] = current_time;
168 if (!transport_->DiscardedLastPacket() && 178 if (!transport_->DiscardedLastPacket() &&
169 header.ssrc == ssrc_to_analyze_) { 179 header.ssrc == ssrc_to_analyze_) {
170 encoded_frame_sizes_[timestamp] += 180 encoded_frame_sizes_[timestamp] +=
171 length - (header.headerLength + header.paddingLength); 181 length - (header.headerLength + header.paddingLength);
172 } 182 }
(...skipping 12 matching lines...) Expand all
185 } 195 }
186 196
187 void RenderFrame(const VideoFrame& video_frame, 197 void RenderFrame(const VideoFrame& video_frame,
188 int time_to_render_ms) override { 198 int time_to_render_ms) override {
189 int64_t render_time_ms = 199 int64_t render_time_ms =
190 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); 200 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
191 uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_; 201 uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_;
192 202
193 rtc::CritScope lock(&crit_); 203 rtc::CritScope lock(&crit_);
194 204
195 while (frames_.front().timestamp() < send_timestamp) { 205 while (frames_.front().timestamp() != send_timestamp) {
196 AddFrameComparison(frames_.front(), last_rendered_frame_, true, 206 AddFrameComparison(frames_.front(), last_rendered_frame_, true,
197 render_time_ms); 207 render_time_ms);
198 frames_.pop_front(); 208 frames_.pop_front();
209 RTC_DCHECK(!frames_.empty());
199 } 210 }
200 211
201 VideoFrame reference_frame = frames_.front(); 212 VideoFrame reference_frame = frames_.front();
202 frames_.pop_front(); 213 frames_.pop_front();
203 assert(!reference_frame.IsZeroSize()); 214 assert(!reference_frame.IsZeroSize());
204 if (send_timestamp == reference_frame.timestamp() - 1) { 215 if (send_timestamp == reference_frame.timestamp() - 1) {
205 // TODO(ivica): Make this work for > 2 streams. 216 // TODO(ivica): Make this work for > 2 streams.
206 // Look at rtp_sender.c:RTPSender::BuildRTPHeader. 217 // Look at rtp_sender.c:RTPSender::BuildRTPHeader.
207 ++send_timestamp; 218 ++send_timestamp;
208 } 219 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 size_t encoded_frame_size; 333 size_t encoded_frame_size;
323 double psnr; 334 double psnr;
324 double ssim; 335 double ssim;
325 }; 336 };
326 337
327 void AddFrameComparison(const VideoFrame& reference, 338 void AddFrameComparison(const VideoFrame& reference,
328 const VideoFrame& render, 339 const VideoFrame& render,
329 bool dropped, 340 bool dropped,
330 int64_t render_time_ms) 341 int64_t render_time_ms)
331 EXCLUSIVE_LOCKS_REQUIRED(crit_) { 342 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
343 RTC_CHECK(!render.IsZeroSize());
332 int64_t send_time_ms = send_times_[reference.timestamp()]; 344 int64_t send_time_ms = send_times_[reference.timestamp()];
333 send_times_.erase(reference.timestamp()); 345 send_times_.erase(reference.timestamp());
334 int64_t recv_time_ms = recv_times_[reference.timestamp()]; 346 int64_t recv_time_ms = recv_times_[reference.timestamp()];
335 recv_times_.erase(reference.timestamp()); 347 recv_times_.erase(reference.timestamp());
336 348
337 // TODO(ivica): Make this work for > 2 streams. 349 // TODO(ivica): Make this work for > 2 streams.
338 auto it = encoded_frame_sizes_.find(reference.timestamp()); 350 auto it = encoded_frame_sizes_.find(reference.timestamp());
339 if (it == encoded_frame_sizes_.end()) 351 if (it == encoded_frame_sizes_.end())
340 it = encoded_frame_sizes_.find(reference.timestamp() - 1); 352 it = encoded_frame_sizes_.find(reference.timestamp() - 1);
341 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; 353 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 return frames_processed_ == frames_to_process_; 465 return frames_processed_ == frames_to_process_;
454 } 466 }
455 467
456 void PrintResults() { 468 void PrintResults() {
457 rtc::CritScope crit(&comparison_lock_); 469 rtc::CritScope crit(&comparison_lock_);
458 PrintResult("psnr", psnr_, " dB"); 470 PrintResult("psnr", psnr_, " dB");
459 PrintResult("ssim", ssim_, ""); 471 PrintResult("ssim", ssim_, "");
460 PrintResult("sender_time", sender_time_, " ms"); 472 PrintResult("sender_time", sender_time_, " ms");
461 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(), 473 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(),
462 dropped_frames_); 474 dropped_frames_);
475 printf("RESULT frames_dropped_before_first_encode: %s = %d frames\n",
476 test_label_.c_str(), frames_dropped_before_first_encode_);
463 PrintResult("receiver_time", receiver_time_, " ms"); 477 PrintResult("receiver_time", receiver_time_, " ms");
464 PrintResult("total_delay_incl_network", end_to_end_, " ms"); 478 PrintResult("total_delay_incl_network", end_to_end_, " ms");
465 PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); 479 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
466 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes"); 480 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes");
467 PrintResult("encode_frame_rate", encode_frame_rate_, " fps"); 481 PrintResult("encode_frame_rate", encode_frame_rate_, " fps");
468 PrintResult("encode_time", encode_time_ms, " ms"); 482 PrintResult("encode_time", encode_time_ms, " ms");
469 PrintResult("encode_usage_percent", encode_usage_percent, " percent"); 483 PrintResult("encode_usage_percent", encode_usage_percent, " percent");
470 PrintResult("media_bitrate", media_bitrate_bps, " bps"); 484 PrintResult("media_bitrate", media_bitrate_bps, " bps");
471 485
472 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); 486 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_); 589 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_);
576 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_); 590 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_);
577 test::Statistics encode_time_ms GUARDED_BY(comparison_lock_); 591 test::Statistics encode_time_ms GUARDED_BY(comparison_lock_);
578 test::Statistics encode_usage_percent GUARDED_BY(comparison_lock_); 592 test::Statistics encode_usage_percent GUARDED_BY(comparison_lock_);
579 test::Statistics media_bitrate_bps GUARDED_BY(comparison_lock_); 593 test::Statistics media_bitrate_bps GUARDED_BY(comparison_lock_);
580 594
581 const int frames_to_process_; 595 const int frames_to_process_;
582 int frames_recorded_; 596 int frames_recorded_;
583 int frames_processed_; 597 int frames_processed_;
584 int dropped_frames_; 598 int dropped_frames_;
599 int frames_dropped_before_first_encode_;
585 int64_t last_render_time_; 600 int64_t last_render_time_;
586 uint32_t rtp_timestamp_delta_; 601 uint32_t rtp_timestamp_delta_;
587 602
588 rtc::CriticalSection crit_; 603 rtc::CriticalSection crit_;
589 std::deque<VideoFrame> frames_ GUARDED_BY(crit_); 604 std::deque<VideoFrame> frames_ GUARDED_BY(crit_);
590 VideoFrame last_rendered_frame_ GUARDED_BY(crit_); 605 VideoFrame last_rendered_frame_ GUARDED_BY(crit_);
591 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_); 606 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_);
592 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_); 607 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_);
593 std::map<uint32_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); 608 std::map<uint32_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_);
594 VideoFrame first_send_frame_ GUARDED_BY(crit_); 609 VideoFrame first_send_frame_ GUARDED_BY(crit_);
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 params_.analyzer.test_durations_secs * params_.common.fps, 980 params_.analyzer.test_durations_secs * params_.common.fps,
966 graph_data_output_file, graph_title, 981 graph_data_output_file, graph_title,
967 kVideoSendSsrcs[params_.ss.selected_stream]); 982 kVideoSendSsrcs[params_.ss.selected_stream]);
968 983
969 analyzer.SetReceiver(receiver_call_->Receiver()); 984 analyzer.SetReceiver(receiver_call_->Receiver());
970 send_transport.SetReceiver(&analyzer); 985 send_transport.SetReceiver(&analyzer);
971 recv_transport.SetReceiver(sender_call_->Receiver()); 986 recv_transport.SetReceiver(sender_call_->Receiver());
972 987
973 SetupCommon(&analyzer, &recv_transport); 988 SetupCommon(&analyzer, &recv_transport);
974 video_send_config_.encoding_time_observer = &analyzer; 989 video_send_config_.encoding_time_observer = &analyzer;
990 video_send_config_.pre_encode_callback = &analyzer;
975 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer; 991 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer;
976 for (auto& config : video_receive_configs_) 992 for (auto& config : video_receive_configs_)
977 config.pre_decode_callback = &analyzer; 993 config.pre_decode_callback = &analyzer;
978 994
979 if (params_.screenshare.enabled) 995 if (params_.screenshare.enabled)
980 SetupScreenshare(); 996 SetupScreenshare();
981 997
982 CreateVideoStreams(); 998 CreateVideoStreams();
983 analyzer.input_ = video_send_stream_->Input(); 999 analyzer.input_ = video_send_stream_->Input();
984 analyzer.send_stream_ = video_send_stream_; 1000 analyzer.send_stream_ = video_send_stream_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 video_send_stream_->Stop(); 1080 video_send_stream_->Stop();
1065 receive_stream->Stop(); 1081 receive_stream->Stop();
1066 1082
1067 call->DestroyVideoReceiveStream(receive_stream); 1083 call->DestroyVideoReceiveStream(receive_stream);
1068 call->DestroyVideoSendStream(video_send_stream_); 1084 call->DestroyVideoSendStream(video_send_stream_);
1069 1085
1070 transport.StopSending(); 1086 transport.StopSending();
1071 } 1087 }
1072 1088
1073 } // namespace webrtc 1089 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698