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

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: rename new_codec_settings 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
« no previous file with comments | « webrtc/video/video_capture_input_unittest.cc ('k') | webrtc/video/video_send_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 dropped_frames_before_first_encode_(0),
72 dropped_frames_before_rendering_(0),
70 last_render_time_(0), 73 last_render_time_(0),
71 rtp_timestamp_delta_(0), 74 rtp_timestamp_delta_(0),
72 avg_psnr_threshold_(avg_psnr_threshold), 75 avg_psnr_threshold_(avg_psnr_threshold),
73 avg_ssim_threshold_(avg_ssim_threshold), 76 avg_ssim_threshold_(avg_ssim_threshold),
74 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), 77 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"),
75 comparison_available_event_(false, false), 78 comparison_available_event_(false, false),
76 done_(true, false) { 79 done_(true, false) {
77 // Create thread pool for CPU-expensive PSNR/SSIM calculations. 80 // Create thread pool for CPU-expensive PSNR/SSIM calculations.
78 81
79 // Try to use about as many threads as cores, but leave kMinCoresLeft alone, 82 // 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 131
129 // EncodingTimeObserver. 132 // EncodingTimeObserver.
130 void OnReportEncodedTime(int64_t ntp_time_ms, int encode_time_ms) override { 133 void OnReportEncodedTime(int64_t ntp_time_ms, int encode_time_ms) override {
131 rtc::CritScope crit(&comparison_lock_); 134 rtc::CritScope crit(&comparison_lock_);
132 samples_encode_time_ms_[ntp_time_ms] = encode_time_ms; 135 samples_encode_time_ms_[ntp_time_ms] = encode_time_ms;
133 } 136 }
134 137
135 void IncomingCapturedFrame(const VideoFrame& video_frame) override { 138 void IncomingCapturedFrame(const VideoFrame& video_frame) override {
136 VideoFrame copy = video_frame; 139 VideoFrame copy = video_frame;
137 copy.set_timestamp(copy.ntp_time_ms() * 90); 140 copy.set_timestamp(copy.ntp_time_ms() * 90);
138
139 { 141 {
140 rtc::CritScope lock(&crit_); 142 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); 143 frames_.push_back(copy);
145 } 144 }
146 145
147 input_->IncomingCapturedFrame(video_frame); 146 input_->IncomingCapturedFrame(video_frame);
148 } 147 }
149 148
149 void FrameCallback(VideoFrame* video_frame) {
150 rtc::CritScope lock(&crit_);
151 if (first_send_frame_.IsZeroSize() && rtp_timestamp_delta_ == 0) {
152 while (frames_.front().timestamp() != video_frame->timestamp()) {
153 ++dropped_frames_before_first_encode_;
154 frames_.pop_front();
155 RTC_CHECK(!frames_.empty());
156 }
157 first_send_frame_ = *video_frame;
158 }
159 }
160
150 bool SendRtp(const uint8_t* packet, 161 bool SendRtp(const uint8_t* packet,
151 size_t length, 162 size_t length,
152 const PacketOptions& options) override { 163 const PacketOptions& options) override {
153 RtpUtility::RtpHeaderParser parser(packet, length); 164 RtpUtility::RtpHeaderParser parser(packet, length);
154 RTPHeader header; 165 RTPHeader header;
155 parser.Parse(&header); 166 parser.Parse(&header);
156 167
157 int64_t current_time = 168 int64_t current_time =
158 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); 169 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
159 bool result = transport_->SendRtp(packet, length, options); 170 bool result = transport_->SendRtp(packet, length, options);
160 { 171 {
161 rtc::CritScope lock(&crit_); 172 rtc::CritScope lock(&crit_);
162 if (rtp_timestamp_delta_ == 0) { 173 if (!first_send_frame_.IsZeroSize()) {
163 rtp_timestamp_delta_ = header.timestamp - first_send_frame_.timestamp(); 174 rtp_timestamp_delta_ = header.timestamp - first_send_frame_.timestamp();
164 first_send_frame_.Reset(); 175 first_send_frame_.Reset();
165 } 176 }
166 uint32_t timestamp = header.timestamp - rtp_timestamp_delta_; 177 uint32_t timestamp = header.timestamp - rtp_timestamp_delta_;
167 send_times_[timestamp] = current_time; 178 send_times_[timestamp] = current_time;
168 if (!transport_->DiscardedLastPacket() && 179 if (!transport_->DiscardedLastPacket() &&
169 header.ssrc == ssrc_to_analyze_) { 180 header.ssrc == ssrc_to_analyze_) {
170 encoded_frame_sizes_[timestamp] += 181 encoded_frame_sizes_[timestamp] +=
171 length - (header.headerLength + header.paddingLength); 182 length - (header.headerLength + header.paddingLength);
172 } 183 }
(...skipping 12 matching lines...) Expand all
185 } 196 }
186 197
187 void RenderFrame(const VideoFrame& video_frame, 198 void RenderFrame(const VideoFrame& video_frame,
188 int time_to_render_ms) override { 199 int time_to_render_ms) override {
189 int64_t render_time_ms = 200 int64_t render_time_ms =
190 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); 201 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
191 uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_; 202 uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_;
192 203
193 rtc::CritScope lock(&crit_); 204 rtc::CritScope lock(&crit_);
194 205
195 while (frames_.front().timestamp() < send_timestamp) { 206 while (frames_.front().timestamp() != send_timestamp) {
207 if (last_rendered_frame_.IsZeroSize()) {
208 // No previous frame rendered, this one was dropped after sending but
209 // before rendering.
210 ++dropped_frames_before_rendering_;
211 frames_.pop_front();
212 RTC_CHECK(!frames_.empty());
213 continue;
214 }
196 AddFrameComparison(frames_.front(), last_rendered_frame_, true, 215 AddFrameComparison(frames_.front(), last_rendered_frame_, true,
197 render_time_ms); 216 render_time_ms);
198 frames_.pop_front(); 217 frames_.pop_front();
218 RTC_DCHECK(!frames_.empty());
199 } 219 }
200 220
201 VideoFrame reference_frame = frames_.front(); 221 VideoFrame reference_frame = frames_.front();
202 frames_.pop_front(); 222 frames_.pop_front();
203 assert(!reference_frame.IsZeroSize()); 223 assert(!reference_frame.IsZeroSize());
204 if (send_timestamp == reference_frame.timestamp() - 1) { 224 if (send_timestamp == reference_frame.timestamp() - 1) {
205 // TODO(ivica): Make this work for > 2 streams. 225 // TODO(ivica): Make this work for > 2 streams.
206 // Look at rtp_sender.c:RTPSender::BuildRTPHeader. 226 // Look at rtp_sender.c:RTPSender::BuildRTPHeader.
207 ++send_timestamp; 227 ++send_timestamp;
208 } 228 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 size_t encoded_frame_size; 342 size_t encoded_frame_size;
323 double psnr; 343 double psnr;
324 double ssim; 344 double ssim;
325 }; 345 };
326 346
327 void AddFrameComparison(const VideoFrame& reference, 347 void AddFrameComparison(const VideoFrame& reference,
328 const VideoFrame& render, 348 const VideoFrame& render,
329 bool dropped, 349 bool dropped,
330 int64_t render_time_ms) 350 int64_t render_time_ms)
331 EXCLUSIVE_LOCKS_REQUIRED(crit_) { 351 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
352 RTC_CHECK(!render.IsZeroSize());
332 int64_t send_time_ms = send_times_[reference.timestamp()]; 353 int64_t send_time_ms = send_times_[reference.timestamp()];
333 send_times_.erase(reference.timestamp()); 354 send_times_.erase(reference.timestamp());
334 int64_t recv_time_ms = recv_times_[reference.timestamp()]; 355 int64_t recv_time_ms = recv_times_[reference.timestamp()];
335 recv_times_.erase(reference.timestamp()); 356 recv_times_.erase(reference.timestamp());
336 357
337 // TODO(ivica): Make this work for > 2 streams. 358 // TODO(ivica): Make this work for > 2 streams.
338 auto it = encoded_frame_sizes_.find(reference.timestamp()); 359 auto it = encoded_frame_sizes_.find(reference.timestamp());
339 if (it == encoded_frame_sizes_.end()) 360 if (it == encoded_frame_sizes_.end())
340 it = encoded_frame_sizes_.find(reference.timestamp() - 1); 361 it = encoded_frame_sizes_.find(reference.timestamp() - 1);
341 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; 362 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 return frames_processed_ == frames_to_process_; 470 return frames_processed_ == frames_to_process_;
450 } 471 }
451 472
452 void PrintResults() { 473 void PrintResults() {
453 rtc::CritScope crit(&comparison_lock_); 474 rtc::CritScope crit(&comparison_lock_);
454 PrintResult("psnr", psnr_, " dB"); 475 PrintResult("psnr", psnr_, " dB");
455 PrintResult("ssim", ssim_, ""); 476 PrintResult("ssim", ssim_, "");
456 PrintResult("sender_time", sender_time_, " ms"); 477 PrintResult("sender_time", sender_time_, " ms");
457 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(), 478 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(),
458 dropped_frames_); 479 dropped_frames_);
480 printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n",
481 test_label_.c_str(), dropped_frames_before_first_encode_);
482 printf("RESULT dropped_frames_before_rendering: %s = %d frames\n",
483 test_label_.c_str(), dropped_frames_before_rendering_);
459 PrintResult("receiver_time", receiver_time_, " ms"); 484 PrintResult("receiver_time", receiver_time_, " ms");
460 PrintResult("total_delay_incl_network", end_to_end_, " ms"); 485 PrintResult("total_delay_incl_network", end_to_end_, " ms");
461 PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); 486 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
462 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes"); 487 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes");
463 PrintResult("encode_frame_rate", encode_frame_rate_, " fps"); 488 PrintResult("encode_frame_rate", encode_frame_rate_, " fps");
464 PrintResult("encode_time", encode_time_ms, " ms"); 489 PrintResult("encode_time", encode_time_ms, " ms");
465 PrintResult("encode_usage_percent", encode_usage_percent, " percent"); 490 PrintResult("encode_usage_percent", encode_usage_percent, " percent");
466 PrintResult("media_bitrate", media_bitrate_bps, " bps"); 491 PrintResult("media_bitrate", media_bitrate_bps, " bps");
467 492
468 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); 493 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_); 596 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_);
572 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_); 597 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_);
573 test::Statistics encode_time_ms GUARDED_BY(comparison_lock_); 598 test::Statistics encode_time_ms GUARDED_BY(comparison_lock_);
574 test::Statistics encode_usage_percent GUARDED_BY(comparison_lock_); 599 test::Statistics encode_usage_percent GUARDED_BY(comparison_lock_);
575 test::Statistics media_bitrate_bps GUARDED_BY(comparison_lock_); 600 test::Statistics media_bitrate_bps GUARDED_BY(comparison_lock_);
576 601
577 const int frames_to_process_; 602 const int frames_to_process_;
578 int frames_recorded_; 603 int frames_recorded_;
579 int frames_processed_; 604 int frames_processed_;
580 int dropped_frames_; 605 int dropped_frames_;
606 int dropped_frames_before_first_encode_;
607 int dropped_frames_before_rendering_;
581 int64_t last_render_time_; 608 int64_t last_render_time_;
582 uint32_t rtp_timestamp_delta_; 609 uint32_t rtp_timestamp_delta_;
583 610
584 rtc::CriticalSection crit_; 611 rtc::CriticalSection crit_;
585 std::deque<VideoFrame> frames_ GUARDED_BY(crit_); 612 std::deque<VideoFrame> frames_ GUARDED_BY(crit_);
586 VideoFrame last_rendered_frame_ GUARDED_BY(crit_); 613 VideoFrame last_rendered_frame_ GUARDED_BY(crit_);
587 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_); 614 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_);
588 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_); 615 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_);
589 std::map<uint32_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); 616 std::map<uint32_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_);
590 VideoFrame first_send_frame_ GUARDED_BY(crit_); 617 VideoFrame first_send_frame_ GUARDED_BY(crit_);
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 params_.analyzer.test_durations_secs * params_.common.fps, 988 params_.analyzer.test_durations_secs * params_.common.fps,
962 graph_data_output_file, graph_title, 989 graph_data_output_file, graph_title,
963 kVideoSendSsrcs[params_.ss.selected_stream]); 990 kVideoSendSsrcs[params_.ss.selected_stream]);
964 991
965 analyzer.SetReceiver(receiver_call_->Receiver()); 992 analyzer.SetReceiver(receiver_call_->Receiver());
966 send_transport.SetReceiver(&analyzer); 993 send_transport.SetReceiver(&analyzer);
967 recv_transport.SetReceiver(sender_call_->Receiver()); 994 recv_transport.SetReceiver(sender_call_->Receiver());
968 995
969 SetupCommon(&analyzer, &recv_transport); 996 SetupCommon(&analyzer, &recv_transport);
970 video_send_config_.encoding_time_observer = &analyzer; 997 video_send_config_.encoding_time_observer = &analyzer;
998 video_send_config_.pre_encode_callback = &analyzer;
971 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer; 999 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer;
972 for (auto& config : video_receive_configs_) 1000 for (auto& config : video_receive_configs_)
973 config.pre_decode_callback = &analyzer; 1001 config.pre_decode_callback = &analyzer;
974 1002
975 if (params_.screenshare.enabled) 1003 if (params_.screenshare.enabled)
976 SetupScreenshare(); 1004 SetupScreenshare();
977 1005
978 CreateVideoStreams(); 1006 CreateVideoStreams();
979 analyzer.input_ = video_send_stream_->Input(); 1007 analyzer.input_ = video_send_stream_->Input();
980 analyzer.send_stream_ = video_send_stream_; 1008 analyzer.send_stream_ = video_send_stream_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 video_send_stream_->Stop(); 1088 video_send_stream_->Stop();
1061 receive_stream->Stop(); 1089 receive_stream->Stop();
1062 1090
1063 call->DestroyVideoReceiveStream(receive_stream); 1091 call->DestroyVideoReceiveStream(receive_stream);
1064 call->DestroyVideoSendStream(video_send_stream_); 1092 call->DestroyVideoSendStream(video_send_stream_);
1065 1093
1066 transport.StopSending(); 1094 transport.StopSending();
1067 } 1095 }
1068 1096
1069 } // namespace webrtc 1097 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_capture_input_unittest.cc ('k') | webrtc/video/video_send_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698