blob: a419195c0760e48bc969fc679763e42aec906b62 [file] [log] [blame]
ivica5d6a06c2015-09-17 05:30:24 -07001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
perkja49cbd32016-09-16 07:53:41 -070010#include "webrtc/video/video_quality_test.h"
perkj9fdbda62016-09-15 09:19:20 -070011
perkja49cbd32016-09-16 07:53:41 -070012#include <stdio.h>
ivica5d6a06c2015-09-17 05:30:24 -070013#include <algorithm>
14#include <deque>
15#include <map>
sprangce4aef12015-11-02 07:23:20 -080016#include <sstream>
mflodmand1590b22015-12-09 07:07:59 -080017#include <string>
ivica5d6a06c2015-09-17 05:30:24 -070018#include <vector>
19
ivica5d6a06c2015-09-17 05:30:24 -070020#include "webrtc/base/checks.h"
Peter Boström5811a392015-12-10 13:02:50 +010021#include "webrtc/base/event.h"
ivica5d6a06c2015-09-17 05:30:24 -070022#include "webrtc/base/format_macros.h"
nissec7fe3c22016-04-20 03:25:36 -070023#include "webrtc/base/optional.h"
palmkviste75f2042016-09-28 06:19:48 -070024#include "webrtc/base/platform_file.h"
sprange1f2f1f2016-02-01 02:04:52 -080025#include "webrtc/base/timeutils.h"
ossuf515ab82016-12-07 04:52:58 -080026#include "webrtc/call/call.h"
ivica5d6a06c2015-09-17 05:30:24 -070027#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
skvlad11a9cbf2016-10-07 11:53:05 -070028#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
aleloi10111bc2016-11-17 06:48:48 -080029#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010030#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
sprangce4aef12015-11-02 07:23:20 -080031#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
magjed509e4fe2016-11-18 01:34:11 -080032#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
33#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
34#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010035#include "webrtc/system_wrappers/include/cpu_info.h"
kwibergac9f8762016-09-30 22:29:43 -070036#include "webrtc/test/gtest.h"
ivica5d6a06c2015-09-17 05:30:24 -070037#include "webrtc/test/layer_filtering_transport.h"
38#include "webrtc/test/run_loop.h"
39#include "webrtc/test/statistics.h"
40#include "webrtc/test/testsupport/fileutils.h"
perkja49cbd32016-09-16 07:53:41 -070041#include "webrtc/test/vcm_capturer.h"
ivica5d6a06c2015-09-17 05:30:24 -070042#include "webrtc/test/video_renderer.h"
minyue73208662016-08-18 06:28:55 -070043#include "webrtc/voice_engine/include/voe_base.h"
minyue73208662016-08-18 06:28:55 -070044
45namespace {
46
47constexpr int kSendStatsPollingIntervalMs = 1000;
48constexpr int kPayloadTypeH264 = 122;
49constexpr int kPayloadTypeVP8 = 123;
50constexpr int kPayloadTypeVP9 = 124;
51constexpr size_t kMaxComparisons = 10;
52constexpr char kSyncGroup[] = "av_sync";
minyue10cbb462016-11-07 09:29:22 -080053constexpr int kOpusMinBitrateBps = 6000;
54constexpr int kOpusBitrateFbBps = 32000;
minyue73208662016-08-18 06:28:55 -070055
56struct VoiceEngineState {
57 VoiceEngineState()
58 : voice_engine(nullptr),
59 base(nullptr),
minyue73208662016-08-18 06:28:55 -070060 send_channel_id(-1),
61 receive_channel_id(-1) {}
62
63 webrtc::VoiceEngine* voice_engine;
64 webrtc::VoEBase* base;
minyue73208662016-08-18 06:28:55 -070065 int send_channel_id;
66 int receive_channel_id;
67};
68
69void CreateVoiceEngine(VoiceEngineState* voe,
70 rtc::scoped_refptr<webrtc::AudioDecoderFactory>
71 decoder_factory) {
72 voe->voice_engine = webrtc::VoiceEngine::Create();
73 voe->base = webrtc::VoEBase::GetInterface(voe->voice_engine);
minyue73208662016-08-18 06:28:55 -070074 EXPECT_EQ(0, voe->base->Init(nullptr, nullptr, decoder_factory));
solenberg88499ec2016-09-07 07:34:41 -070075 webrtc::VoEBase::ChannelConfig config;
76 config.enable_voice_pacing = true;
77 voe->send_channel_id = voe->base->CreateChannel(config);
minyue73208662016-08-18 06:28:55 -070078 EXPECT_GE(voe->send_channel_id, 0);
79 voe->receive_channel_id = voe->base->CreateChannel();
80 EXPECT_GE(voe->receive_channel_id, 0);
81}
82
83void DestroyVoiceEngine(VoiceEngineState* voe) {
84 voe->base->DeleteChannel(voe->send_channel_id);
85 voe->send_channel_id = -1;
86 voe->base->DeleteChannel(voe->receive_channel_id);
87 voe->receive_channel_id = -1;
88 voe->base->Release();
89 voe->base = nullptr;
minyue73208662016-08-18 06:28:55 -070090
91 webrtc::VoiceEngine::Delete(voe->voice_engine);
92 voe->voice_engine = nullptr;
93}
94
perkjfa10b552016-10-02 23:45:26 -070095class VideoStreamFactory
96 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
97 public:
98 explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams)
99 : streams_(streams) {}
100
101 private:
102 std::vector<webrtc::VideoStream> CreateEncoderStreams(
103 int width,
104 int height,
105 const webrtc::VideoEncoderConfig& encoder_config) override {
mflodmand79f97b2016-12-15 07:24:33 -0800106 // The highest layer must match the incoming resolution.
107 std::vector<webrtc::VideoStream> streams = streams_;
108 streams[streams_.size() - 1].height = height;
109 streams[streams_.size() - 1].width = width;
110 return streams;
perkjfa10b552016-10-02 23:45:26 -0700111 }
112
113 std::vector<webrtc::VideoStream> streams_;
114};
115
brandtr504b95e2016-12-21 02:54:35 -0800116bool IsFlexfec(int payload_type) {
117 return payload_type == webrtc::VideoQualityTest::kFlexfecPayloadType;
118}
119
minyue73208662016-08-18 06:28:55 -0700120} // namespace
ivica5d6a06c2015-09-17 05:30:24 -0700121
122namespace webrtc {
123
ivica5d6a06c2015-09-17 05:30:24 -0700124class VideoAnalyzer : public PacketReceiver,
pbos2d566682015-09-28 09:59:31 -0700125 public Transport,
nisse7ade7b32016-03-23 04:48:10 -0700126 public rtc::VideoSinkInterface<VideoFrame>,
Peter Boströme4499152016-02-05 11:13:28 +0100127 public EncodedFrameObserver {
ivica5d6a06c2015-09-17 05:30:24 -0700128 public:
sprangce4aef12015-11-02 07:23:20 -0800129 VideoAnalyzer(test::LayerFilteringTransport* transport,
ivica5d6a06c2015-09-17 05:30:24 -0700130 const std::string& test_label,
131 double avg_psnr_threshold,
132 double avg_ssim_threshold,
133 int duration_frames,
sprangce4aef12015-11-02 07:23:20 -0800134 FILE* graph_data_output_file,
135 const std::string& graph_title,
ilnik5f471262017-02-03 02:02:17 -0800136 uint32_t ssrc_to_analyze,
137 uint32_t selected_width,
138 uint32_t selected_height)
perkja49cbd32016-09-16 07:53:41 -0700139 : transport_(transport),
ivica5d6a06c2015-09-17 05:30:24 -0700140 receiver_(nullptr),
141 send_stream_(nullptr),
philipelfd870db2017-01-23 03:22:15 -0800142 receive_stream_(nullptr),
perkja49cbd32016-09-16 07:53:41 -0700143 captured_frame_forwarder_(this),
ivica5d6a06c2015-09-17 05:30:24 -0700144 test_label_(test_label),
145 graph_data_output_file_(graph_data_output_file),
sprangce4aef12015-11-02 07:23:20 -0800146 graph_title_(graph_title),
147 ssrc_to_analyze_(ssrc_to_analyze),
ilnik5f471262017-02-03 02:02:17 -0800148 selected_width_(selected_width),
149 selected_height_(selected_height),
pbos14fe7082016-04-20 06:35:56 -0700150 pre_encode_proxy_(this),
Peter Boströme4499152016-02-05 11:13:28 +0100151 encode_timing_proxy_(this),
ivica5d6a06c2015-09-17 05:30:24 -0700152 frames_to_process_(duration_frames),
153 frames_recorded_(0),
154 frames_processed_(0),
155 dropped_frames_(0),
pbos14fe7082016-04-20 06:35:56 -0700156 dropped_frames_before_first_encode_(0),
157 dropped_frames_before_rendering_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700158 last_render_time_(0),
159 rtp_timestamp_delta_(0),
160 avg_psnr_threshold_(avg_psnr_threshold),
161 avg_ssim_threshold_(avg_ssim_threshold),
Peter Boström8c38e8b2015-11-26 17:45:47 +0100162 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"),
Peter Boström5811a392015-12-10 13:02:50 +0100163 comparison_available_event_(false, false),
Peter Boströmdd45eb62016-01-19 15:22:32 +0100164 done_(true, false) {
ivica5d6a06c2015-09-17 05:30:24 -0700165 // Create thread pool for CPU-expensive PSNR/SSIM calculations.
166
167 // Try to use about as many threads as cores, but leave kMinCoresLeft alone,
168 // so that we don't accidentally starve "real" worker threads (codec etc).
169 // Also, don't allocate more than kMaxComparisonThreads, even if there are
170 // spare cores.
171
172 uint32_t num_cores = CpuInfo::DetectNumberOfCores();
kwibergaf476c72016-11-28 15:21:39 -0800173 RTC_DCHECK_GE(num_cores, 1);
ivica5d6a06c2015-09-17 05:30:24 -0700174 static const uint32_t kMinCoresLeft = 4;
175 static const uint32_t kMaxComparisonThreads = 8;
176
177 if (num_cores <= kMinCoresLeft) {
178 num_cores = 1;
179 } else {
180 num_cores -= kMinCoresLeft;
181 num_cores = std::min(num_cores, kMaxComparisonThreads);
182 }
183
184 for (uint32_t i = 0; i < num_cores; ++i) {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100185 rtc::PlatformThread* thread =
186 new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer");
187 thread->Start();
188 comparison_thread_pool_.push_back(thread);
ivica5d6a06c2015-09-17 05:30:24 -0700189 }
ivica5d6a06c2015-09-17 05:30:24 -0700190 }
191
192 ~VideoAnalyzer() {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100193 for (rtc::PlatformThread* thread : comparison_thread_pool_) {
194 thread->Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700195 delete thread;
196 }
197 }
198
199 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; }
200
perkja49cbd32016-09-16 07:53:41 -0700201 void SetSendStream(VideoSendStream* stream) {
202 rtc::CritScope lock(&crit_);
203 RTC_DCHECK(!send_stream_);
204 send_stream_ = stream;
205 }
206
philipelfd870db2017-01-23 03:22:15 -0800207 void SetReceiveStream(VideoReceiveStream* stream) {
208 rtc::CritScope lock(&crit_);
209 RTC_DCHECK(!receive_stream_);
210 receive_stream_ = stream;
211 }
212
perkja49cbd32016-09-16 07:53:41 -0700213 rtc::VideoSinkInterface<VideoFrame>* InputInterface() {
214 return &captured_frame_forwarder_;
215 }
216 rtc::VideoSourceInterface<VideoFrame>* OutputInterface() {
217 return &captured_frame_forwarder_;
218 }
219
ivica5d6a06c2015-09-17 05:30:24 -0700220 DeliveryStatus DeliverPacket(MediaType media_type,
221 const uint8_t* packet,
222 size_t length,
223 const PacketTime& packet_time) override {
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700224 // Ignore timestamps of RTCP packets. They're not synchronized with
225 // RTP packet timestamps and so they would confuse wrap_handler_.
226 if (RtpHeaderParser::IsRtcp(packet, length)) {
227 return receiver_->DeliverPacket(media_type, packet, length, packet_time);
228 }
229
sprangce4aef12015-11-02 07:23:20 -0800230 RtpUtility::RtpHeaderParser parser(packet, length);
ivica5d6a06c2015-09-17 05:30:24 -0700231 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800232 parser.Parse(&header);
ilnik5f471262017-02-03 02:02:17 -0800233 if (!IsFlexfec(header.payloadType) && header.ssrc != ssrc_to_analyze_) {
brandtr504b95e2016-12-21 02:54:35 -0800234 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
235 // (FlexFEC and media are sent on different SSRCs, which have different
236 // timestamps spaces.)
ilnik5f471262017-02-03 02:02:17 -0800237 // Also ignore packets from wrong SSRC.
ivica5d6a06c2015-09-17 05:30:24 -0700238 rtc::CritScope lock(&crit_);
sprang16daaa52016-03-09 01:30:24 -0800239 int64_t timestamp =
240 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
241 recv_times_[timestamp] =
ivica5d6a06c2015-09-17 05:30:24 -0700242 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
243 }
244
245 return receiver_->DeliverPacket(media_type, packet, length, packet_time);
246 }
247
Peter Boströme4499152016-02-05 11:13:28 +0100248 void MeasuredEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) {
ivica8d15bd62015-10-07 02:43:12 -0700249 rtc::CritScope crit(&comparison_lock_);
250 samples_encode_time_ms_[ntp_time_ms] = encode_time_ms;
251 }
252
pbos14fe7082016-04-20 06:35:56 -0700253 void PreEncodeOnFrame(const VideoFrame& video_frame) {
254 rtc::CritScope lock(&crit_);
ilnik5f471262017-02-03 02:02:17 -0800255 if (!first_encoded_timestamp_) {
pbos14fe7082016-04-20 06:35:56 -0700256 while (frames_.front().timestamp() != video_frame.timestamp()) {
257 ++dropped_frames_before_first_encode_;
258 frames_.pop_front();
259 RTC_CHECK(!frames_.empty());
260 }
ilnik5f471262017-02-03 02:02:17 -0800261 first_encoded_timestamp_ =
262 rtc::Optional<uint32_t>(video_frame.timestamp());
263 }
264 }
265
266 void PostEncodeFrameCallback(const EncodedFrame& encoded_frame) {
267 rtc::CritScope lock(&crit_);
268 if (!first_sent_timestamp_ &&
269 encoded_frame.encoded_width_ == selected_width_ &&
270 encoded_frame.encoded_height_ == selected_height_) {
271 first_sent_timestamp_ = rtc::Optional<uint32_t>(encoded_frame.timestamp_);
pbos14fe7082016-04-20 06:35:56 -0700272 }
273 }
274
stefan1d8a5062015-10-02 03:39:33 -0700275 bool SendRtp(const uint8_t* packet,
276 size_t length,
277 const PacketOptions& options) override {
sprangce4aef12015-11-02 07:23:20 -0800278 RtpUtility::RtpHeaderParser parser(packet, length);
ivica5d6a06c2015-09-17 05:30:24 -0700279 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800280 parser.Parse(&header);
ivica5d6a06c2015-09-17 05:30:24 -0700281
sprangce4aef12015-11-02 07:23:20 -0800282 int64_t current_time =
283 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
284 bool result = transport_->SendRtp(packet, length, options);
ivica5d6a06c2015-09-17 05:30:24 -0700285 {
286 rtc::CritScope lock(&crit_);
ilnik5f471262017-02-03 02:02:17 -0800287 if (rtp_timestamp_delta_ == 0 && header.ssrc == ssrc_to_analyze_) {
288 rtp_timestamp_delta_ = header.timestamp - *first_sent_timestamp_;
ivica5d6a06c2015-09-17 05:30:24 -0700289 }
ilnik5f471262017-02-03 02:02:17 -0800290
291 if (!IsFlexfec(header.payloadType) && header.ssrc == ssrc_to_analyze_) {
brandtr504b95e2016-12-21 02:54:35 -0800292 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
293 // (FlexFEC and media are sent on different SSRCs, which have different
294 // timestamps spaces.)
ilnik5f471262017-02-03 02:02:17 -0800295 // Also ignore packets from wrong SSRC.
brandtr504b95e2016-12-21 02:54:35 -0800296 int64_t timestamp =
297 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
298 send_times_[timestamp] = current_time;
299 if (!transport_->DiscardedLastPacket() &&
300 header.ssrc == ssrc_to_analyze_) {
301 encoded_frame_sizes_[timestamp] +=
302 length - (header.headerLength + header.paddingLength);
303 }
sprangce4aef12015-11-02 07:23:20 -0800304 }
ivica5d6a06c2015-09-17 05:30:24 -0700305 }
sprangce4aef12015-11-02 07:23:20 -0800306 return result;
ivica5d6a06c2015-09-17 05:30:24 -0700307 }
308
309 bool SendRtcp(const uint8_t* packet, size_t length) override {
310 return transport_->SendRtcp(packet, length);
311 }
312
313 void EncodedFrameCallback(const EncodedFrame& frame) override {
314 rtc::CritScope lock(&comparison_lock_);
315 if (frames_recorded_ < frames_to_process_)
316 encoded_frame_size_.AddSample(frame.length_);
317 }
318
nisseeb83a1a2016-03-21 01:27:56 -0700319 void OnFrame(const VideoFrame& video_frame) override {
ivica5d6a06c2015-09-17 05:30:24 -0700320 int64_t render_time_ms =
321 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
ivica5d6a06c2015-09-17 05:30:24 -0700322
323 rtc::CritScope lock(&crit_);
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700324 int64_t send_timestamp =
sprang16daaa52016-03-09 01:30:24 -0800325 wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_);
ivica5d6a06c2015-09-17 05:30:24 -0700326
sprang16daaa52016-03-09 01:30:24 -0800327 while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) {
nisse97f0b932016-05-26 09:44:40 -0700328 if (!last_rendered_frame_) {
pbos14fe7082016-04-20 06:35:56 -0700329 // No previous frame rendered, this one was dropped after sending but
330 // before rendering.
331 ++dropped_frames_before_rendering_;
332 frames_.pop_front();
333 RTC_CHECK(!frames_.empty());
334 continue;
335 }
nisse97f0b932016-05-26 09:44:40 -0700336 AddFrameComparison(frames_.front(), *last_rendered_frame_, true,
ivica5d6a06c2015-09-17 05:30:24 -0700337 render_time_ms);
338 frames_.pop_front();
pbos14fe7082016-04-20 06:35:56 -0700339 RTC_DCHECK(!frames_.empty());
ivica5d6a06c2015-09-17 05:30:24 -0700340 }
341
342 VideoFrame reference_frame = frames_.front();
343 frames_.pop_front();
sprang16daaa52016-03-09 01:30:24 -0800344 int64_t reference_timestamp =
345 wrap_handler_.Unwrap(reference_frame.timestamp());
346 if (send_timestamp == reference_timestamp - 1) {
sprangce4aef12015-11-02 07:23:20 -0800347 // TODO(ivica): Make this work for > 2 streams.
Peter Boströme4499152016-02-05 11:13:28 +0100348 // Look at RTPSender::BuildRTPHeader.
sprangce4aef12015-11-02 07:23:20 -0800349 ++send_timestamp;
350 }
sprang16daaa52016-03-09 01:30:24 -0800351 ASSERT_EQ(reference_timestamp, send_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700352
353 AddFrameComparison(reference_frame, video_frame, false, render_time_ms);
354
nisse97f0b932016-05-26 09:44:40 -0700355 last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame);
ivica5d6a06c2015-09-17 05:30:24 -0700356 }
357
ivica5d6a06c2015-09-17 05:30:24 -0700358 void Wait() {
359 // Frame comparisons can be very expensive. Wait for test to be done, but
360 // at time-out check if frames_processed is going up. If so, give it more
361 // time, otherwise fail. Hopefully this will reduce test flakiness.
362
Peter Boström8c38e8b2015-11-26 17:45:47 +0100363 stats_polling_thread_.Start();
sprangce4aef12015-11-02 07:23:20 -0800364
ivica5d6a06c2015-09-17 05:30:24 -0700365 int last_frames_processed = -1;
ivica5d6a06c2015-09-17 05:30:24 -0700366 int iteration = 0;
Peter Boström5811a392015-12-10 13:02:50 +0100367 while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) {
ivica5d6a06c2015-09-17 05:30:24 -0700368 int frames_processed;
369 {
370 rtc::CritScope crit(&comparison_lock_);
371 frames_processed = frames_processed_;
372 }
373
374 // Print some output so test infrastructure won't think we've crashed.
375 const char* kKeepAliveMessages[3] = {
376 "Uh, I'm-I'm not quite dead, sir.",
377 "Uh, I-I think uh, I could pull through, sir.",
378 "Actually, I think I'm all right to come with you--"};
379 printf("- %s\n", kKeepAliveMessages[iteration++ % 3]);
380
381 if (last_frames_processed == -1) {
382 last_frames_processed = frames_processed;
383 continue;
384 }
Peter Boströmdd45eb62016-01-19 15:22:32 +0100385 if (frames_processed == last_frames_processed) {
386 EXPECT_GT(frames_processed, last_frames_processed)
387 << "Analyzer stalled while waiting for test to finish.";
388 done_.Set();
389 break;
390 }
ivica5d6a06c2015-09-17 05:30:24 -0700391 last_frames_processed = frames_processed;
392 }
393
394 if (iteration > 0)
395 printf("- Farewell, sweet Concorde!\n");
396
Peter Boström8c38e8b2015-11-26 17:45:47 +0100397 stats_polling_thread_.Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700398 }
399
pbos14fe7082016-04-20 06:35:56 -0700400 rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() {
401 return &pre_encode_proxy_;
402 }
Peter Boströme4499152016-02-05 11:13:28 +0100403 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; }
404
sprangce4aef12015-11-02 07:23:20 -0800405 test::LayerFilteringTransport* const transport_;
ivica5d6a06c2015-09-17 05:30:24 -0700406 PacketReceiver* receiver_;
ivica5d6a06c2015-09-17 05:30:24 -0700407
408 private:
409 struct FrameComparison {
410 FrameComparison()
411 : dropped(false),
nissedf2ceb82016-12-15 06:29:53 -0800412 input_time_ms(0),
ivica5d6a06c2015-09-17 05:30:24 -0700413 send_time_ms(0),
414 recv_time_ms(0),
415 render_time_ms(0),
416 encoded_frame_size(0) {}
417
418 FrameComparison(const VideoFrame& reference,
419 const VideoFrame& render,
420 bool dropped,
nissedf2ceb82016-12-15 06:29:53 -0800421 int64_t input_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700422 int64_t send_time_ms,
423 int64_t recv_time_ms,
424 int64_t render_time_ms,
425 size_t encoded_frame_size)
426 : reference(reference),
427 render(render),
428 dropped(dropped),
nissedf2ceb82016-12-15 06:29:53 -0800429 input_time_ms(input_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700430 send_time_ms(send_time_ms),
431 recv_time_ms(recv_time_ms),
432 render_time_ms(render_time_ms),
433 encoded_frame_size(encoded_frame_size) {}
434
nissedf2ceb82016-12-15 06:29:53 -0800435 FrameComparison(bool dropped,
436 int64_t input_time_ms,
437 int64_t send_time_ms,
438 int64_t recv_time_ms,
439 int64_t render_time_ms,
440 size_t encoded_frame_size)
441 : dropped(dropped),
442 input_time_ms(input_time_ms),
443 send_time_ms(send_time_ms),
444 recv_time_ms(recv_time_ms),
445 render_time_ms(render_time_ms),
446 encoded_frame_size(encoded_frame_size) {}
447
448 rtc::Optional<VideoFrame> reference;
449 rtc::Optional<VideoFrame> render;
ivica5d6a06c2015-09-17 05:30:24 -0700450 bool dropped;
nissedf2ceb82016-12-15 06:29:53 -0800451 int64_t input_time_ms;
ivica5d6a06c2015-09-17 05:30:24 -0700452 int64_t send_time_ms;
453 int64_t recv_time_ms;
454 int64_t render_time_ms;
455 size_t encoded_frame_size;
456 };
457
458 struct Sample {
ivica8d15bd62015-10-07 02:43:12 -0700459 Sample(int dropped,
460 int64_t input_time_ms,
461 int64_t send_time_ms,
462 int64_t recv_time_ms,
463 int64_t render_time_ms,
464 size_t encoded_frame_size,
ivica5d6a06c2015-09-17 05:30:24 -0700465 double psnr,
ivica8d15bd62015-10-07 02:43:12 -0700466 double ssim)
ivica5d6a06c2015-09-17 05:30:24 -0700467 : dropped(dropped),
468 input_time_ms(input_time_ms),
469 send_time_ms(send_time_ms),
470 recv_time_ms(recv_time_ms),
ivica8d15bd62015-10-07 02:43:12 -0700471 render_time_ms(render_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700472 encoded_frame_size(encoded_frame_size),
473 psnr(psnr),
ivica8d15bd62015-10-07 02:43:12 -0700474 ssim(ssim) {}
ivica5d6a06c2015-09-17 05:30:24 -0700475
ivica8d15bd62015-10-07 02:43:12 -0700476 int dropped;
477 int64_t input_time_ms;
478 int64_t send_time_ms;
479 int64_t recv_time_ms;
480 int64_t render_time_ms;
481 size_t encoded_frame_size;
ivica5d6a06c2015-09-17 05:30:24 -0700482 double psnr;
483 double ssim;
ivica5d6a06c2015-09-17 05:30:24 -0700484 };
485
Peter Boströme4499152016-02-05 11:13:28 +0100486 // This class receives the send-side OnEncodeTiming and is provided to not
487 // conflict with the receiver-side pre_decode_callback.
488 class OnEncodeTimingProxy : public EncodedFrameObserver {
489 public:
490 explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {}
491
492 void OnEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) override {
493 parent_->MeasuredEncodeTiming(ntp_time_ms, encode_time_ms);
494 }
ilnik5f471262017-02-03 02:02:17 -0800495 void EncodedFrameCallback(const EncodedFrame& frame) override {
496 parent_->PostEncodeFrameCallback(frame);
497 }
Peter Boströme4499152016-02-05 11:13:28 +0100498
499 private:
500 VideoAnalyzer* const parent_;
501 };
502
pbos14fe7082016-04-20 06:35:56 -0700503 // This class receives the send-side OnFrame callback and is provided to not
504 // conflict with the receiver-side renderer callback.
505 class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> {
506 public:
507 explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {}
508
509 void OnFrame(const VideoFrame& video_frame) override {
510 parent_->PreEncodeOnFrame(video_frame);
511 }
512
513 private:
514 VideoAnalyzer* const parent_;
515 };
516
ivica5d6a06c2015-09-17 05:30:24 -0700517 void AddFrameComparison(const VideoFrame& reference,
518 const VideoFrame& render,
519 bool dropped,
520 int64_t render_time_ms)
521 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
sprange1f2f1f2016-02-01 02:04:52 -0800522 int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp());
523 int64_t send_time_ms = send_times_[reference_timestamp];
524 send_times_.erase(reference_timestamp);
525 int64_t recv_time_ms = recv_times_[reference_timestamp];
526 recv_times_.erase(reference_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700527
sprangce4aef12015-11-02 07:23:20 -0800528 // TODO(ivica): Make this work for > 2 streams.
sprange1f2f1f2016-02-01 02:04:52 -0800529 auto it = encoded_frame_sizes_.find(reference_timestamp);
sprangce4aef12015-11-02 07:23:20 -0800530 if (it == encoded_frame_sizes_.end())
sprange1f2f1f2016-02-01 02:04:52 -0800531 it = encoded_frame_sizes_.find(reference_timestamp - 1);
sprangce4aef12015-11-02 07:23:20 -0800532 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second;
533 if (it != encoded_frame_sizes_.end())
534 encoded_frame_sizes_.erase(it);
ivica5d6a06c2015-09-17 05:30:24 -0700535
ivica5d6a06c2015-09-17 05:30:24 -0700536 rtc::CritScope crit(&comparison_lock_);
stefanb1797672016-08-11 07:00:57 -0700537 if (comparisons_.size() < kMaxComparisons) {
nissedf2ceb82016-12-15 06:29:53 -0800538 comparisons_.push_back(FrameComparison(reference, render, dropped,
539 reference.ntp_time_ms(),
540 send_time_ms, recv_time_ms,
541 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700542 } else {
nissedf2ceb82016-12-15 06:29:53 -0800543 comparisons_.push_back(FrameComparison(dropped,
544 reference.ntp_time_ms(),
545 send_time_ms, recv_time_ms,
546 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700547 }
Peter Boström5811a392015-12-10 13:02:50 +0100548 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700549 }
550
551 static bool PollStatsThread(void* obj) {
552 return static_cast<VideoAnalyzer*>(obj)->PollStats();
553 }
554
555 bool PollStats() {
Peter Boströmdd45eb62016-01-19 15:22:32 +0100556 if (done_.Wait(kSendStatsPollingIntervalMs))
Peter Boström5811a392015-12-10 13:02:50 +0100557 return false;
ivica5d6a06c2015-09-17 05:30:24 -0700558
ivica5d6a06c2015-09-17 05:30:24 -0700559 rtc::CritScope crit(&comparison_lock_);
philipelfd870db2017-01-23 03:22:15 -0800560
561 VideoSendStream::Stats send_stats = send_stream_->GetStats();
Peter Boströmb1eaa8d2016-02-23 17:30:49 +0100562 // It's not certain that we yet have estimates for any of these stats. Check
563 // that they are positive before mixing them in.
philipelfd870db2017-01-23 03:22:15 -0800564 if (send_stats.encode_frame_rate > 0)
565 encode_frame_rate_.AddSample(send_stats.encode_frame_rate);
566 if (send_stats.avg_encode_time_ms > 0)
567 encode_time_ms_.AddSample(send_stats.avg_encode_time_ms);
568 if (send_stats.encode_usage_percent > 0)
569 encode_usage_percent_.AddSample(send_stats.encode_usage_percent);
570 if (send_stats.media_bitrate_bps > 0)
571 media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps);
572
573 if (receive_stream_ != nullptr) {
574 VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats();
575 if (receive_stats.decode_ms > 0)
576 decode_time_ms_.AddSample(receive_stats.decode_ms);
577 if (receive_stats.max_decode_ms > 0)
578 decode_time_max_ms_.AddSample(receive_stats.max_decode_ms);
579 }
ivica5d6a06c2015-09-17 05:30:24 -0700580
581 return true;
582 }
583
584 static bool FrameComparisonThread(void* obj) {
585 return static_cast<VideoAnalyzer*>(obj)->CompareFrames();
586 }
587
588 bool CompareFrames() {
589 if (AllFramesRecorded())
590 return false;
591
ivica5d6a06c2015-09-17 05:30:24 -0700592 FrameComparison comparison;
593
594 if (!PopComparison(&comparison)) {
595 // Wait until new comparison task is available, or test is done.
596 // If done, wake up remaining threads waiting.
Peter Boström5811a392015-12-10 13:02:50 +0100597 comparison_available_event_.Wait(1000);
ivica5d6a06c2015-09-17 05:30:24 -0700598 if (AllFramesRecorded()) {
Peter Boström5811a392015-12-10 13:02:50 +0100599 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700600 return false;
601 }
602 return true; // Try again.
603 }
604
605 PerformFrameComparison(comparison);
606
607 if (FrameProcessed()) {
608 PrintResults();
609 if (graph_data_output_file_)
610 PrintSamplesToFile();
Peter Boström5811a392015-12-10 13:02:50 +0100611 done_.Set();
612 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700613 return false;
614 }
615
616 return true;
617 }
618
619 bool PopComparison(FrameComparison* comparison) {
620 rtc::CritScope crit(&comparison_lock_);
621 // If AllFramesRecorded() is true, it means we have already popped
622 // frames_to_process_ frames from comparisons_, so there is no more work
623 // for this thread to be done. frames_processed_ might still be lower if
624 // all comparisons are not done, but those frames are currently being
625 // worked on by other threads.
626 if (comparisons_.empty() || AllFramesRecorded())
627 return false;
628
629 *comparison = comparisons_.front();
630 comparisons_.pop_front();
631
632 FrameRecorded();
633 return true;
634 }
635
636 // Increment counter for number of frames received for comparison.
637 void FrameRecorded() {
638 rtc::CritScope crit(&comparison_lock_);
639 ++frames_recorded_;
640 }
641
642 // Returns true if all frames to be compared have been taken from the queue.
643 bool AllFramesRecorded() {
644 rtc::CritScope crit(&comparison_lock_);
645 assert(frames_recorded_ <= frames_to_process_);
646 return frames_recorded_ == frames_to_process_;
647 }
648
649 // Increase count of number of frames processed. Returns true if this was the
650 // last frame to be processed.
651 bool FrameProcessed() {
652 rtc::CritScope crit(&comparison_lock_);
653 ++frames_processed_;
654 assert(frames_processed_ <= frames_to_process_);
655 return frames_processed_ == frames_to_process_;
656 }
657
658 void PrintResults() {
659 rtc::CritScope crit(&comparison_lock_);
660 PrintResult("psnr", psnr_, " dB");
tnakamura3123cbc2016-02-10 11:21:51 -0800661 PrintResult("ssim", ssim_, " score");
ivica5d6a06c2015-09-17 05:30:24 -0700662 PrintResult("sender_time", sender_time_, " ms");
ivica5d6a06c2015-09-17 05:30:24 -0700663 PrintResult("receiver_time", receiver_time_, " ms");
664 PrintResult("total_delay_incl_network", end_to_end_, " ms");
665 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
666 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes");
667 PrintResult("encode_frame_rate", encode_frame_rate_, " fps");
philipelfd870db2017-01-23 03:22:15 -0800668 PrintResult("encode_time", encode_time_ms_, " ms");
669 PrintResult("encode_usage_percent", encode_usage_percent_, " percent");
670 PrintResult("media_bitrate", media_bitrate_bps_, " bps");
671
672 if (receive_stream_ != nullptr) {
673 PrintResult("decode_time", decode_time_ms_, " ms");
674 PrintResult("decode_time_max", decode_time_max_ms_, " ms");
675 }
ivica5d6a06c2015-09-17 05:30:24 -0700676
pbos14fe7082016-04-20 06:35:56 -0700677 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(),
678 dropped_frames_);
679 printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n",
680 test_label_.c_str(), dropped_frames_before_first_encode_);
681 printf("RESULT dropped_frames_before_rendering: %s = %d frames\n",
682 test_label_.c_str(), dropped_frames_before_rendering_);
683
ivica5d6a06c2015-09-17 05:30:24 -0700684 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
685 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_);
686 }
687
688 void PerformFrameComparison(const FrameComparison& comparison) {
689 // Perform expensive psnr and ssim calculations while not holding lock.
stefanb1797672016-08-11 07:00:57 -0700690 double psnr = -1.0;
691 double ssim = -1.0;
nissedf2ceb82016-12-15 06:29:53 -0800692 if (comparison.reference) {
693 psnr = I420PSNR(&*comparison.reference, &*comparison.render);
694 ssim = I420SSIM(&*comparison.reference, &*comparison.render);
stefanb1797672016-08-11 07:00:57 -0700695 }
ivica5d6a06c2015-09-17 05:30:24 -0700696
ivica5d6a06c2015-09-17 05:30:24 -0700697 rtc::CritScope crit(&comparison_lock_);
698 if (graph_data_output_file_) {
nissedf2ceb82016-12-15 06:29:53 -0800699 samples_.push_back(Sample(
700 comparison.dropped, comparison.input_time_ms, comparison.send_time_ms,
701 comparison.recv_time_ms, comparison.render_time_ms,
702 comparison.encoded_frame_size, psnr, ssim));
ivica5d6a06c2015-09-17 05:30:24 -0700703 }
stefanb1797672016-08-11 07:00:57 -0700704 if (psnr >= 0.0)
705 psnr_.AddSample(psnr);
706 if (ssim >= 0.0)
707 ssim_.AddSample(ssim);
ivica5d6a06c2015-09-17 05:30:24 -0700708
709 if (comparison.dropped) {
710 ++dropped_frames_;
711 return;
712 }
713 if (last_render_time_ != 0)
714 rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_);
715 last_render_time_ = comparison.render_time_ms;
716
nissedf2ceb82016-12-15 06:29:53 -0800717 sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms);
brandtr504b95e2016-12-21 02:54:35 -0800718 if (comparison.recv_time_ms > 0) {
719 // If recv_time_ms == 0, this frame consisted of a packets which were all
720 // lost in the transport. Since we were able to render the frame, however,
721 // the dropped packets were recovered by FlexFEC. The FlexFEC recovery
722 // happens internally in Call, and we can therefore here not know which
723 // FEC packets that protected the lost media packets. Consequently, we
724 // were not able to record a meaningful recv_time_ms. We therefore skip
725 // this sample.
726 //
727 // The reasoning above does not hold for ULPFEC and RTX, as for those
728 // strategies the timestamp of the received packets is set to the
729 // timestamp of the protected/retransmitted media packet. I.e., then
730 // recv_time_ms != 0, even though the media packets were lost.
731 receiver_time_.AddSample(comparison.render_time_ms -
732 comparison.recv_time_ms);
733 }
nissedf2ceb82016-12-15 06:29:53 -0800734 end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms);
ivica5d6a06c2015-09-17 05:30:24 -0700735 encoded_frame_size_.AddSample(comparison.encoded_frame_size);
736 }
737
738 void PrintResult(const char* result_type,
739 test::Statistics stats,
740 const char* unit) {
741 printf("RESULT %s: %s = {%f, %f}%s\n",
742 result_type,
743 test_label_.c_str(),
744 stats.Mean(),
745 stats.StandardDeviation(),
746 unit);
747 }
748
749 void PrintSamplesToFile(void) {
750 FILE* out = graph_data_output_file_;
751 rtc::CritScope crit(&comparison_lock_);
752 std::sort(samples_.begin(), samples_.end(),
753 [](const Sample& A, const Sample& B) -> bool {
754 return A.input_time_ms < B.input_time_ms;
755 });
756
sprangce4aef12015-11-02 07:23:20 -0800757 fprintf(out, "%s\n", graph_title_.c_str());
ivica5d6a06c2015-09-17 05:30:24 -0700758 fprintf(out, "%" PRIuS "\n", samples_.size());
759 fprintf(out,
760 "dropped "
761 "input_time_ms "
762 "send_time_ms "
763 "recv_time_ms "
ivica8d15bd62015-10-07 02:43:12 -0700764 "render_time_ms "
ivica5d6a06c2015-09-17 05:30:24 -0700765 "encoded_frame_size "
766 "psnr "
767 "ssim "
ivica8d15bd62015-10-07 02:43:12 -0700768 "encode_time_ms\n");
769 int missing_encode_time_samples = 0;
ivica5d6a06c2015-09-17 05:30:24 -0700770 for (const Sample& sample : samples_) {
ivica8d15bd62015-10-07 02:43:12 -0700771 auto it = samples_encode_time_ms_.find(sample.input_time_ms);
772 int encode_time_ms;
773 if (it != samples_encode_time_ms_.end()) {
774 encode_time_ms = it->second;
775 } else {
776 ++missing_encode_time_samples;
777 encode_time_ms = -1;
778 }
779 fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS
780 " %lf %lf %d\n",
781 sample.dropped, sample.input_time_ms, sample.send_time_ms,
782 sample.recv_time_ms, sample.render_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700783 sample.encoded_frame_size, sample.psnr, sample.ssim,
ivica8d15bd62015-10-07 02:43:12 -0700784 encode_time_ms);
785 }
786 if (missing_encode_time_samples) {
787 fprintf(stderr,
788 "Warning: Missing encode_time_ms samples for %d frame(s).\n",
789 missing_encode_time_samples);
ivica5d6a06c2015-09-17 05:30:24 -0700790 }
791 }
792
perkja49cbd32016-09-16 07:53:41 -0700793 // Implements VideoSinkInterface to receive captured frames from a
794 // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act
795 // as a source to VideoSendStream.
796 // It forwards all input frames to the VideoAnalyzer for later comparison and
797 // forwards the captured frames to the VideoSendStream.
798 class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>,
799 public rtc::VideoSourceInterface<VideoFrame> {
800 public:
801 explicit CapturedFrameForwarder(VideoAnalyzer* analyzer)
802 : analyzer_(analyzer), send_stream_input_(nullptr) {}
803
804 private:
805 void OnFrame(const VideoFrame& video_frame) override {
806 VideoFrame copy = video_frame;
ilnik5f471262017-02-03 02:02:17 -0800807 // Frames from the capturer does not have a rtp timestamp.
808 // Create one so it can be used for comparison.
809 RTC_DCHECK_EQ(0, video_frame.timestamp());
perkja49cbd32016-09-16 07:53:41 -0700810 copy.set_timestamp(copy.ntp_time_ms() * 90);
ilnik5f471262017-02-03 02:02:17 -0800811 analyzer_->AddCapturedFrameForComparison(copy);
perkja49cbd32016-09-16 07:53:41 -0700812 rtc::CritScope lock(&crit_);
813 if (send_stream_input_)
814 send_stream_input_->OnFrame(video_frame);
815 }
816
817 // Called when |send_stream_.SetSource()| is called.
818 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
819 const rtc::VideoSinkWants& wants) override {
820 rtc::CritScope lock(&crit_);
821 RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
822 send_stream_input_ = sink;
823 }
824
825 // Called by |send_stream_| when |send_stream_.SetSource()| is called.
826 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {
827 rtc::CritScope lock(&crit_);
828 RTC_DCHECK(sink == send_stream_input_);
829 send_stream_input_ = nullptr;
830 }
831
832 VideoAnalyzer* const analyzer_;
833 rtc::CriticalSection crit_;
834 rtc::VideoSinkInterface<VideoFrame>* send_stream_input_ GUARDED_BY(crit_);
835 };
836
837 void AddCapturedFrameForComparison(const VideoFrame& video_frame) {
838 rtc::CritScope lock(&crit_);
ilnik5f471262017-02-03 02:02:17 -0800839 frames_.push_back(video_frame);
perkja49cbd32016-09-16 07:53:41 -0700840 }
841
842 VideoSendStream* send_stream_;
philipelfd870db2017-01-23 03:22:15 -0800843 VideoReceiveStream* receive_stream_;
perkja49cbd32016-09-16 07:53:41 -0700844 CapturedFrameForwarder captured_frame_forwarder_;
ivica5d6a06c2015-09-17 05:30:24 -0700845 const std::string test_label_;
846 FILE* const graph_data_output_file_;
sprangce4aef12015-11-02 07:23:20 -0800847 const std::string graph_title_;
848 const uint32_t ssrc_to_analyze_;
ilnik5f471262017-02-03 02:02:17 -0800849 const uint32_t selected_width_;
850 const uint32_t selected_height_;
pbos14fe7082016-04-20 06:35:56 -0700851 PreEncodeProxy pre_encode_proxy_;
Peter Boströme4499152016-02-05 11:13:28 +0100852 OnEncodeTimingProxy encode_timing_proxy_;
ivica5d6a06c2015-09-17 05:30:24 -0700853 std::vector<Sample> samples_ GUARDED_BY(comparison_lock_);
ivica8d15bd62015-10-07 02:43:12 -0700854 std::map<int64_t, int> samples_encode_time_ms_ GUARDED_BY(comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700855 test::Statistics sender_time_ GUARDED_BY(comparison_lock_);
856 test::Statistics receiver_time_ GUARDED_BY(comparison_lock_);
857 test::Statistics psnr_ GUARDED_BY(comparison_lock_);
858 test::Statistics ssim_ GUARDED_BY(comparison_lock_);
859 test::Statistics end_to_end_ GUARDED_BY(comparison_lock_);
860 test::Statistics rendered_delta_ GUARDED_BY(comparison_lock_);
861 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_);
862 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_);
philipelfd870db2017-01-23 03:22:15 -0800863 test::Statistics encode_time_ms_ GUARDED_BY(comparison_lock_);
864 test::Statistics encode_usage_percent_ GUARDED_BY(comparison_lock_);
865 test::Statistics decode_time_ms_ GUARDED_BY(comparison_lock_);
866 test::Statistics decode_time_max_ms_ GUARDED_BY(comparison_lock_);
867 test::Statistics media_bitrate_bps_ GUARDED_BY(comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700868
869 const int frames_to_process_;
870 int frames_recorded_;
871 int frames_processed_;
872 int dropped_frames_;
pbos14fe7082016-04-20 06:35:56 -0700873 int dropped_frames_before_first_encode_;
874 int dropped_frames_before_rendering_;
ivica5d6a06c2015-09-17 05:30:24 -0700875 int64_t last_render_time_;
876 uint32_t rtp_timestamp_delta_;
877
878 rtc::CriticalSection crit_;
879 std::deque<VideoFrame> frames_ GUARDED_BY(crit_);
nisse97f0b932016-05-26 09:44:40 -0700880 rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_);
sprange1f2f1f2016-02-01 02:04:52 -0800881 rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_);
882 std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_);
883 std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_);
884 std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_);
ilnik5f471262017-02-03 02:02:17 -0800885 rtc::Optional<uint32_t> first_encoded_timestamp_ GUARDED_BY(crit_);
886 rtc::Optional<uint32_t> first_sent_timestamp_ GUARDED_BY(crit_);
ivica5d6a06c2015-09-17 05:30:24 -0700887 const double avg_psnr_threshold_;
888 const double avg_ssim_threshold_;
889
890 rtc::CriticalSection comparison_lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +0100891 std::vector<rtc::PlatformThread*> comparison_thread_pool_;
892 rtc::PlatformThread stats_polling_thread_;
Peter Boström5811a392015-12-10 13:02:50 +0100893 rtc::Event comparison_available_event_;
ivica5d6a06c2015-09-17 05:30:24 -0700894 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);
Peter Boström5811a392015-12-10 13:02:50 +0100895 rtc::Event done_;
ivica5d6a06c2015-09-17 05:30:24 -0700896};
897
palmkviste75f2042016-09-28 06:19:48 -0700898VideoQualityTest::VideoQualityTest()
899 : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) {}
ivica5d6a06c2015-09-17 05:30:24 -0700900
minyue626bc952016-10-31 05:47:02 -0700901VideoQualityTest::Params::Params()
902 : call({false, Call::Config::BitrateConfig()}),
903 video({false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false,
brandtr1293aca2016-11-16 22:47:29 -0800904 false, "", ""}),
minyue626bc952016-10-31 05:47:02 -0700905 audio({false, false}),
906 screenshare({false, 10, 0}),
907 analyzer({"", 0.0, 0.0, 0, "", ""}),
908 pipe(),
909 logs(false),
910 ss({std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}) {}
911
912VideoQualityTest::Params::~Params() = default;
913
ivica5d6a06c2015-09-17 05:30:24 -0700914void VideoQualityTest::TestBody() {}
915
sprangce4aef12015-11-02 07:23:20 -0800916std::string VideoQualityTest::GenerateGraphTitle() const {
917 std::stringstream ss;
minyue626bc952016-10-31 05:47:02 -0700918 ss << params_.video.codec;
919 ss << " (" << params_.video.target_bitrate_bps / 1000 << "kbps";
920 ss << ", " << params_.video.fps << " FPS";
sprangce4aef12015-11-02 07:23:20 -0800921 if (params_.screenshare.scroll_duration)
922 ss << ", " << params_.screenshare.scroll_duration << "s scroll";
923 if (params_.ss.streams.size() > 1)
924 ss << ", Stream #" << params_.ss.selected_stream;
925 if (params_.ss.num_spatial_layers > 1)
926 ss << ", Layer #" << params_.ss.selected_sl;
927 ss << ")";
928 return ss.str();
929}
930
931void VideoQualityTest::CheckParams() {
932 // Add a default stream in none specified.
933 if (params_.ss.streams.empty())
934 params_.ss.streams.push_back(VideoQualityTest::DefaultVideoStream(params_));
935 if (params_.ss.num_spatial_layers == 0)
936 params_.ss.num_spatial_layers = 1;
937
938 if (params_.pipe.loss_percent != 0 ||
939 params_.pipe.queue_length_packets != 0) {
940 // Since LayerFilteringTransport changes the sequence numbers, we can't
941 // use that feature with pack loss, since the NACK request would end up
942 // retransmitting the wrong packets.
943 RTC_CHECK(params_.ss.selected_sl == -1 ||
sprangee37de32015-11-23 06:10:23 -0800944 params_.ss.selected_sl == params_.ss.num_spatial_layers - 1);
minyue626bc952016-10-31 05:47:02 -0700945 RTC_CHECK(params_.video.selected_tl == -1 ||
946 params_.video.selected_tl ==
947 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -0800948 }
949
950 // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as it
951 // does in some parts of the code?
minyue626bc952016-10-31 05:47:02 -0700952 RTC_CHECK_GE(params_.video.max_bitrate_bps, params_.video.target_bitrate_bps);
953 RTC_CHECK_GE(params_.video.target_bitrate_bps, params_.video.min_bitrate_bps);
954 RTC_CHECK_LT(params_.video.selected_tl, params_.video.num_temporal_layers);
sprangce4aef12015-11-02 07:23:20 -0800955 RTC_CHECK_LT(params_.ss.selected_stream, params_.ss.streams.size());
956 for (const VideoStream& stream : params_.ss.streams) {
957 RTC_CHECK_GE(stream.min_bitrate_bps, 0);
958 RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps);
959 RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps);
kwiberg352444f2016-11-28 15:58:53 -0800960 RTC_CHECK_EQ(stream.temporal_layer_thresholds_bps.size(),
minyue626bc952016-10-31 05:47:02 -0700961 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -0800962 }
963 // TODO(ivica): Should we check if the sum of all streams/layers is equal to
964 // the total bitrate? We anyway have to update them in the case bitrate
965 // estimator changes the total bitrates.
966 RTC_CHECK_GE(params_.ss.num_spatial_layers, 1);
967 RTC_CHECK_LE(params_.ss.selected_sl, params_.ss.num_spatial_layers);
968 RTC_CHECK(params_.ss.spatial_layers.empty() ||
969 params_.ss.spatial_layers.size() ==
970 static_cast<size_t>(params_.ss.num_spatial_layers));
minyue626bc952016-10-31 05:47:02 -0700971 if (params_.video.codec == "VP8") {
sprangce4aef12015-11-02 07:23:20 -0800972 RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1);
minyue626bc952016-10-31 05:47:02 -0700973 } else if (params_.video.codec == "VP9") {
kwibergaf476c72016-11-28 15:21:39 -0800974 RTC_CHECK_EQ(params_.ss.streams.size(), 1);
sprangce4aef12015-11-02 07:23:20 -0800975 }
976}
977
978// Static.
979std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) {
980 // Parse comma separated nonnegative integers, where some elements may be
981 // empty. The empty values are replaced with -1.
982 // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40}
983 // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1}
984 std::vector<int> result;
985 if (str.empty())
986 return result;
987
988 const char* p = str.c_str();
989 int value = -1;
990 int pos;
991 while (*p) {
992 if (*p == ',') {
993 result.push_back(value);
994 value = -1;
995 ++p;
996 continue;
997 }
998 RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1)
999 << "Unexpected non-number value.";
1000 p += pos;
1001 }
1002 result.push_back(value);
1003 return result;
1004}
1005
1006// Static.
1007VideoStream VideoQualityTest::DefaultVideoStream(const Params& params) {
1008 VideoStream stream;
minyue626bc952016-10-31 05:47:02 -07001009 stream.width = params.video.width;
1010 stream.height = params.video.height;
1011 stream.max_framerate = params.video.fps;
1012 stream.min_bitrate_bps = params.video.min_bitrate_bps;
1013 stream.target_bitrate_bps = params.video.target_bitrate_bps;
1014 stream.max_bitrate_bps = params.video.max_bitrate_bps;
sprangce4aef12015-11-02 07:23:20 -08001015 stream.max_qp = 52;
minyue626bc952016-10-31 05:47:02 -07001016 if (params.video.num_temporal_layers == 2)
sprangce4aef12015-11-02 07:23:20 -08001017 stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps);
1018 return stream;
1019}
1020
1021// Static.
1022void VideoQualityTest::FillScalabilitySettings(
1023 Params* params,
1024 const std::vector<std::string>& stream_descriptors,
1025 size_t selected_stream,
1026 int num_spatial_layers,
1027 int selected_sl,
1028 const std::vector<std::string>& sl_descriptors) {
1029 // Read VideoStream and SpatialLayer elements from a list of comma separated
1030 // lists. To use a default value for an element, use -1 or leave empty.
1031 // Validity checks performed in CheckParams.
1032
1033 RTC_CHECK(params->ss.streams.empty());
1034 for (auto descriptor : stream_descriptors) {
1035 if (descriptor.empty())
1036 continue;
1037 VideoStream stream = VideoQualityTest::DefaultVideoStream(*params);
1038 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1039 if (v[0] != -1)
1040 stream.width = static_cast<size_t>(v[0]);
1041 if (v[1] != -1)
1042 stream.height = static_cast<size_t>(v[1]);
1043 if (v[2] != -1)
1044 stream.max_framerate = v[2];
1045 if (v[3] != -1)
1046 stream.min_bitrate_bps = v[3];
1047 if (v[4] != -1)
1048 stream.target_bitrate_bps = v[4];
1049 if (v[5] != -1)
1050 stream.max_bitrate_bps = v[5];
1051 if (v.size() > 6 && v[6] != -1)
1052 stream.max_qp = v[6];
1053 if (v.size() > 7) {
1054 stream.temporal_layer_thresholds_bps.clear();
1055 stream.temporal_layer_thresholds_bps.insert(
1056 stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end());
1057 } else {
1058 // Automatic TL thresholds for more than two layers not supported.
minyue626bc952016-10-31 05:47:02 -07001059 RTC_CHECK_LE(params->video.num_temporal_layers, 2);
sprangce4aef12015-11-02 07:23:20 -08001060 }
1061 params->ss.streams.push_back(stream);
1062 }
1063 params->ss.selected_stream = selected_stream;
1064
1065 params->ss.num_spatial_layers = num_spatial_layers ? num_spatial_layers : 1;
1066 params->ss.selected_sl = selected_sl;
1067 RTC_CHECK(params->ss.spatial_layers.empty());
1068 for (auto descriptor : sl_descriptors) {
1069 if (descriptor.empty())
1070 continue;
1071 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1072 RTC_CHECK_GT(v[2], 0);
1073
1074 SpatialLayer layer;
1075 layer.scaling_factor_num = v[0] == -1 ? 1 : v[0];
1076 layer.scaling_factor_den = v[1] == -1 ? 1 : v[1];
1077 layer.target_bitrate_bps = v[2];
1078 params->ss.spatial_layers.push_back(layer);
1079 }
1080}
1081
minyuea27172d2016-11-01 05:59:29 -07001082void VideoQualityTest::SetupVideo(Transport* send_transport,
1083 Transport* recv_transport) {
sprangce4aef12015-11-02 07:23:20 -08001084 if (params_.logs)
ivica5d6a06c2015-09-17 05:30:24 -07001085 trace_to_stderr_.reset(new test::TraceToStderr);
1086
brandtr8313a6f2017-01-13 07:41:19 -08001087 size_t num_video_streams = params_.ss.streams.size();
1088 size_t num_flexfec_streams = params_.video.flexfec ? 1 : 0;
1089 CreateSendConfig(num_video_streams, 0, num_flexfec_streams, send_transport);
ivica5d6a06c2015-09-17 05:30:24 -07001090
1091 int payload_type;
minyue626bc952016-10-31 05:47:02 -07001092 if (params_.video.codec == "H264") {
magjedceecea42016-11-28 07:20:21 -08001093 video_encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264")));
hbosbab934b2016-01-27 01:36:03 -08001094 payload_type = kPayloadTypeH264;
minyue626bc952016-10-31 05:47:02 -07001095 } else if (params_.video.codec == "VP8") {
magjed509e4fe2016-11-18 01:34:11 -08001096 video_encoder_.reset(VP8Encoder::Create());
ivica5d6a06c2015-09-17 05:30:24 -07001097 payload_type = kPayloadTypeVP8;
minyue626bc952016-10-31 05:47:02 -07001098 } else if (params_.video.codec == "VP9") {
magjed509e4fe2016-11-18 01:34:11 -08001099 video_encoder_.reset(VP9Encoder::Create());
ivica5d6a06c2015-09-17 05:30:24 -07001100 payload_type = kPayloadTypeVP9;
1101 } else {
1102 RTC_NOTREACHED() << "Codec not supported!";
1103 return;
1104 }
minyuea27172d2016-11-01 05:59:29 -07001105 video_send_config_.encoder_settings.encoder = video_encoder_.get();
minyue626bc952016-10-31 05:47:02 -07001106 video_send_config_.encoder_settings.payload_name = params_.video.codec;
stefanff483612015-12-21 03:14:00 -08001107 video_send_config_.encoder_settings.payload_type = payload_type;
1108 video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1109 video_send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
brandtr8313a6f2017-01-13 07:41:19 -08001110 for (size_t i = 0; i < num_video_streams; ++i)
stefanff483612015-12-21 03:14:00 -08001111 video_send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[i]);
ivica5d6a06c2015-09-17 05:30:24 -07001112
stefanff483612015-12-21 03:14:00 -08001113 video_send_config_.rtp.extensions.clear();
minyue626bc952016-10-31 05:47:02 -07001114 if (params_.call.send_side_bwe) {
stefanff483612015-12-21 03:14:00 -08001115 video_send_config_.rtp.extensions.push_back(
isheriff6f8d6862016-05-26 11:24:55 -07001116 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Stefan Holmer12952972015-10-29 15:13:24 +01001117 test::kTransportSequenceNumberExtensionId));
1118 } else {
stefanff483612015-12-21 03:14:00 -08001119 video_send_config_.rtp.extensions.push_back(RtpExtension(
isheriff6f8d6862016-05-26 11:24:55 -07001120 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
Erik SprĂ¥ng6b8d3552015-09-24 15:06:57 +02001121 }
1122
stefanff483612015-12-21 03:14:00 -08001123 video_encoder_config_.min_transmit_bitrate_bps =
minyue626bc952016-10-31 05:47:02 -07001124 params_.video.min_transmit_bps;
perkjfa10b552016-10-02 23:45:26 -07001125
brandtr1293aca2016-11-16 22:47:29 -08001126 video_send_config_.suspend_below_min_bitrate =
1127 params_.video.suspend_below_min_bitrate;
1128
perkjfa10b552016-10-02 23:45:26 -07001129 video_encoder_config_.number_of_streams = params_.ss.streams.size();
1130 video_encoder_config_.max_bitrate_bps = 0;
1131 for (size_t i = 0; i < params_.ss.streams.size(); ++i) {
1132 video_encoder_config_.max_bitrate_bps +=
1133 params_.ss.streams[i].max_bitrate_bps;
1134 }
1135 video_encoder_config_.video_stream_factory =
1136 new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams);
1137
stefanff483612015-12-21 03:14:00 -08001138 video_encoder_config_.spatial_layers = params_.ss.spatial_layers;
ivica5d6a06c2015-09-17 05:30:24 -07001139
1140 CreateMatchingReceiveConfigs(recv_transport);
1141
brandtr8313a6f2017-01-13 07:41:19 -08001142 for (size_t i = 0; i < num_video_streams; ++i) {
stefanff483612015-12-21 03:14:00 -08001143 video_receive_configs_[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
brandtr14742122017-01-27 04:53:07 -08001144 video_receive_configs_[i].rtp.rtx_ssrc = kSendRtxSsrcs[i];
1145 video_receive_configs_[i].rtp.rtx_payload_types[payload_type] =
sprangce4aef12015-11-02 07:23:20 -08001146 kSendRtxPayloadType;
minyue626bc952016-10-31 05:47:02 -07001147 video_receive_configs_[i].rtp.transport_cc = params_.call.send_side_bwe;
sprangce4aef12015-11-02 07:23:20 -08001148 }
brandtr1293aca2016-11-16 22:47:29 -08001149
1150 if (params_.video.flexfec) {
brandtr8313a6f2017-01-13 07:41:19 -08001151 // Override send config constructed by CreateSendConfig.
brandtr1293aca2016-11-16 22:47:29 -08001152 video_send_config_.rtp.flexfec.protected_media_ssrcs = {
1153 kVideoSendSsrcs[params_.ss.selected_stream]};
1154
brandtr8313a6f2017-01-13 07:41:19 -08001155 // The matching receive config is _not_ created by
1156 // CreateMatchingReceiveConfigs, since VideoQualityTest is not a BaseTest.
1157 // Set up the receive config manually instead.
1158 FlexfecReceiveStream::Config flexfec_receive_config(recv_transport);
brandtr1cfbd602016-12-08 04:17:53 -08001159 flexfec_receive_config.payload_type =
brandtr3d200bd2017-01-16 06:59:19 -08001160 video_send_config_.rtp.flexfec.payload_type;
1161 flexfec_receive_config.remote_ssrc = video_send_config_.rtp.flexfec.ssrc;
brandtr1293aca2016-11-16 22:47:29 -08001162 flexfec_receive_config.protected_media_ssrcs =
1163 video_send_config_.rtp.flexfec.protected_media_ssrcs;
brandtrfa5a3682017-01-17 01:33:54 -08001164 flexfec_receive_config.local_ssrc = kReceiverLocalVideoSsrc;
brandtrb29e6522016-12-21 06:37:18 -08001165 flexfec_receive_config.transport_cc = params_.call.send_side_bwe;
1166 if (params_.call.send_side_bwe) {
1167 flexfec_receive_config.rtp_header_extensions.push_back(
1168 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1169 test::kTransportSequenceNumberExtensionId));
1170 } else {
1171 flexfec_receive_config.rtp_header_extensions.push_back(RtpExtension(
1172 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1173 }
brandtr1293aca2016-11-16 22:47:29 -08001174 flexfec_receive_configs_.push_back(flexfec_receive_config);
1175 }
1176
1177 if (params_.video.ulpfec) {
1178 video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType;
1179 video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType;
1180 video_send_config_.rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType;
1181
1182 video_receive_configs_[params_.ss.selected_stream]
1183 .rtp.ulpfec.red_payload_type =
1184 video_send_config_.rtp.ulpfec.red_payload_type;
1185 video_receive_configs_[params_.ss.selected_stream]
1186 .rtp.ulpfec.ulpfec_payload_type =
1187 video_send_config_.rtp.ulpfec.ulpfec_payload_type;
1188 video_receive_configs_[params_.ss.selected_stream]
1189 .rtp.ulpfec.red_rtx_payload_type =
1190 video_send_config_.rtp.ulpfec.red_rtx_payload_type;
1191 }
ivica5d6a06c2015-09-17 05:30:24 -07001192}
1193
sprangce4aef12015-11-02 07:23:20 -08001194void VideoQualityTest::SetupScreenshare() {
1195 RTC_CHECK(params_.screenshare.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001196
1197 // Fill out codec settings.
stefanff483612015-12-21 03:14:00 -08001198 video_encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
minyue626bc952016-10-31 05:47:02 -07001199 if (params_.video.codec == "VP8") {
kthelgason29a44e32016-09-27 03:52:02 -07001200 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
1201 vp8_settings.denoisingOn = false;
1202 vp8_settings.frameDroppingOn = false;
1203 vp8_settings.numberOfTemporalLayers =
minyue626bc952016-10-31 05:47:02 -07001204 static_cast<unsigned char>(params_.video.num_temporal_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001205 video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject<
1206 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
minyue626bc952016-10-31 05:47:02 -07001207 } else if (params_.video.codec == "VP9") {
kthelgason29a44e32016-09-27 03:52:02 -07001208 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
1209 vp9_settings.denoisingOn = false;
1210 vp9_settings.frameDroppingOn = false;
1211 vp9_settings.numberOfTemporalLayers =
minyue626bc952016-10-31 05:47:02 -07001212 static_cast<unsigned char>(params_.video.num_temporal_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001213 vp9_settings.numberOfSpatialLayers =
sprangce4aef12015-11-02 07:23:20 -08001214 static_cast<unsigned char>(params_.ss.num_spatial_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001215 video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject<
1216 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
ivica5d6a06c2015-09-17 05:30:24 -07001217 }
1218
1219 // Setup frame generator.
1220 const size_t kWidth = 1850;
1221 const size_t kHeight = 1110;
1222 std::vector<std::string> slides;
1223 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
1224 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
1225 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
1226 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
1227
sprangce4aef12015-11-02 07:23:20 -08001228 if (params_.screenshare.scroll_duration == 0) {
ivica5d6a06c2015-09-17 05:30:24 -07001229 // Cycle image every slide_change_interval seconds.
1230 frame_generator_.reset(test::FrameGenerator::CreateFromYuvFile(
1231 slides, kWidth, kHeight,
minyue626bc952016-10-31 05:47:02 -07001232 params_.screenshare.slide_change_interval * params_.video.fps));
ivica5d6a06c2015-09-17 05:30:24 -07001233 } else {
minyue626bc952016-10-31 05:47:02 -07001234 RTC_CHECK_LE(params_.video.width, kWidth);
1235 RTC_CHECK_LE(params_.video.height, kHeight);
sprangce4aef12015-11-02 07:23:20 -08001236 RTC_CHECK_GT(params_.screenshare.slide_change_interval, 0);
1237 const int kPauseDurationMs = (params_.screenshare.slide_change_interval -
1238 params_.screenshare.scroll_duration) *
1239 1000;
1240 RTC_CHECK_LE(params_.screenshare.scroll_duration,
1241 params_.screenshare.slide_change_interval);
ivica5d6a06c2015-09-17 05:30:24 -07001242
sprangce4aef12015-11-02 07:23:20 -08001243 frame_generator_.reset(
1244 test::FrameGenerator::CreateScrollingInputFromYuvFiles(
minyue626bc952016-10-31 05:47:02 -07001245 clock_, slides, kWidth, kHeight, params_.video.width,
1246 params_.video.height, params_.screenshare.scroll_duration * 1000,
sprangce4aef12015-11-02 07:23:20 -08001247 kPauseDurationMs));
ivica5d6a06c2015-09-17 05:30:24 -07001248 }
1249}
1250
perkja49cbd32016-09-16 07:53:41 -07001251void VideoQualityTest::CreateCapturer() {
sprangce4aef12015-11-02 07:23:20 -08001252 if (params_.screenshare.enabled) {
1253 test::FrameGeneratorCapturer* frame_generator_capturer =
perkja49cbd32016-09-16 07:53:41 -07001254 new test::FrameGeneratorCapturer(clock_, frame_generator_.release(),
minyue626bc952016-10-31 05:47:02 -07001255 params_.video.fps);
ivica2d4e6c52015-09-23 01:57:06 -07001256 EXPECT_TRUE(frame_generator_capturer->Init());
minyuea27172d2016-11-01 05:59:29 -07001257 video_capturer_.reset(frame_generator_capturer);
ivica5d6a06c2015-09-17 05:30:24 -07001258 } else {
sprangce4aef12015-11-02 07:23:20 -08001259 if (params_.video.clip_name.empty()) {
minyuea27172d2016-11-01 05:59:29 -07001260 video_capturer_.reset(test::VcmCapturer::Create(
minyue626bc952016-10-31 05:47:02 -07001261 params_.video.width, params_.video.height, params_.video.fps));
sprang1bed2e42017-01-23 08:46:51 -08001262 if (!video_capturer_) {
1263 // Failed to get actual camera, use chroma generator as backup.
1264 video_capturer_.reset(test::FrameGeneratorCapturer::Create(
1265 params_.video.width, params_.video.height, params_.video.fps,
1266 clock_));
1267 }
ivica5d6a06c2015-09-17 05:30:24 -07001268 } else {
minyuea27172d2016-11-01 05:59:29 -07001269 video_capturer_.reset(test::FrameGeneratorCapturer::CreateFromYuvFile(
perkja49cbd32016-09-16 07:53:41 -07001270 test::ResourcePath(params_.video.clip_name, "yuv"),
minyue626bc952016-10-31 05:47:02 -07001271 params_.video.width, params_.video.height, params_.video.fps,
ivica2d4e6c52015-09-23 01:57:06 -07001272 clock_));
minyuea27172d2016-11-01 05:59:29 -07001273 ASSERT_TRUE(video_capturer_) << "Could not create capturer for "
1274 << params_.video.clip_name
1275 << ".yuv. Is this resource file present?";
ivica5d6a06c2015-09-17 05:30:24 -07001276 }
1277 }
sprang1bed2e42017-01-23 08:46:51 -08001278 RTC_DCHECK(video_capturer_.get());
ivica5d6a06c2015-09-17 05:30:24 -07001279}
1280
sprang7a975f72015-10-12 06:33:21 -07001281void VideoQualityTest::RunWithAnalyzer(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001282 params_ = params;
1283
minyue626bc952016-10-31 05:47:02 -07001284 RTC_CHECK(!params_.audio.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001285 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1286 // differentiate between the analyzer and the renderer case.
sprangce4aef12015-11-02 07:23:20 -08001287 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001288
1289 FILE* graph_data_output_file = nullptr;
sprangce4aef12015-11-02 07:23:20 -08001290 if (!params_.analyzer.graph_data_output_filename.empty()) {
ivica5d6a06c2015-09-17 05:30:24 -07001291 graph_data_output_file =
sprangce4aef12015-11-02 07:23:20 -08001292 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
Peter Boström74f6e9e2016-04-04 17:56:10 +02001293 RTC_CHECK(graph_data_output_file)
sprangce4aef12015-11-02 07:23:20 -08001294 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1295 << "!";
ivica87f83a92015-10-08 05:13:32 -07001296 }
sprang7a975f72015-10-12 06:33:21 -07001297
skvlad11a9cbf2016-10-07 11:53:05 -07001298 webrtc::RtcEventLogNullImpl event_log;
1299 Call::Config call_config(&event_log_);
minyue626bc952016-10-31 05:47:02 -07001300 call_config.bitrate_config = params.call.call_bitrate_config;
stefanf116bd02015-10-27 08:29:42 -07001301 CreateCalls(call_config, call_config);
1302
ivica87f83a92015-10-08 05:13:32 -07001303 test::LayerFilteringTransport send_transport(
minyue626bc952016-10-31 05:47:02 -07001304 params_.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9,
1305 params_.video.selected_tl, params_.ss.selected_sl);
1306 test::DirectTransport recv_transport(params_.pipe, receiver_call_.get());
stefanf116bd02015-10-27 08:29:42 -07001307
sprangce4aef12015-11-02 07:23:20 -08001308 std::string graph_title = params_.analyzer.graph_title;
1309 if (graph_title.empty())
1310 graph_title = VideoQualityTest::GenerateGraphTitle();
1311
1312 // In the case of different resolutions, the functions calculating PSNR and
1313 // SSIM return -1.0, instead of a positive value as usual. VideoAnalyzer
1314 // aborts if the average psnr/ssim are below the given threshold, which is
1315 // 0.0 by default. Setting the thresholds to -1.1 prevents the unnecessary
1316 // abort.
1317 VideoStream& selected_stream = params_.ss.streams[params_.ss.selected_stream];
1318 int selected_sl = params_.ss.selected_sl != -1
1319 ? params_.ss.selected_sl
1320 : params_.ss.num_spatial_layers - 1;
1321 bool disable_quality_check =
minyue626bc952016-10-31 05:47:02 -07001322 selected_stream.width != params_.video.width ||
1323 selected_stream.height != params_.video.height ||
sprangce4aef12015-11-02 07:23:20 -08001324 (!params_.ss.spatial_layers.empty() &&
1325 params_.ss.spatial_layers[selected_sl].scaling_factor_num !=
1326 params_.ss.spatial_layers[selected_sl].scaling_factor_den);
1327 if (disable_quality_check) {
1328 fprintf(stderr,
1329 "Warning: Calculating PSNR and SSIM for downsized resolution "
ilnik5f471262017-02-03 02:02:17 -08001330 "not implemented yet! Skipping PSNR and SSIM calculations!\n");
sprangce4aef12015-11-02 07:23:20 -08001331 }
1332
ivica5d6a06c2015-09-17 05:30:24 -07001333 VideoAnalyzer analyzer(
sprangce4aef12015-11-02 07:23:20 -08001334 &send_transport, params_.analyzer.test_label,
1335 disable_quality_check ? -1.1 : params_.analyzer.avg_psnr_threshold,
1336 disable_quality_check ? -1.1 : params_.analyzer.avg_ssim_threshold,
minyue626bc952016-10-31 05:47:02 -07001337 params_.analyzer.test_durations_secs * params_.video.fps,
sprangce4aef12015-11-02 07:23:20 -08001338 graph_data_output_file, graph_title,
ilnik5f471262017-02-03 02:02:17 -08001339 kVideoSendSsrcs[params_.ss.selected_stream],
1340 static_cast<uint32_t>(selected_stream.width),
1341 static_cast<uint32_t>(selected_stream.height));
ivica5d6a06c2015-09-17 05:30:24 -07001342
ivica5d6a06c2015-09-17 05:30:24 -07001343 analyzer.SetReceiver(receiver_call_->Receiver());
1344 send_transport.SetReceiver(&analyzer);
1345 recv_transport.SetReceiver(sender_call_->Receiver());
1346
minyuea27172d2016-11-01 05:59:29 -07001347 SetupVideo(&analyzer, &recv_transport);
stefanff483612015-12-21 03:14:00 -08001348 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer;
pbos14fe7082016-04-20 06:35:56 -07001349 video_send_config_.pre_encode_callback = analyzer.pre_encode_proxy();
stefanff483612015-12-21 03:14:00 -08001350 for (auto& config : video_receive_configs_)
ivica5d6a06c2015-09-17 05:30:24 -07001351 config.pre_decode_callback = &analyzer;
Peter Boströme4499152016-02-05 11:13:28 +01001352 RTC_DCHECK(!video_send_config_.post_encode_callback);
1353 video_send_config_.post_encode_callback = analyzer.encode_timing_proxy();
ivica5d6a06c2015-09-17 05:30:24 -07001354
sprangce4aef12015-11-02 07:23:20 -08001355 if (params_.screenshare.enabled)
1356 SetupScreenshare();
ivica5d6a06c2015-09-17 05:30:24 -07001357
brandtr1293aca2016-11-16 22:47:29 -08001358 CreateFlexfecStreams();
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001359 CreateVideoStreams();
perkja49cbd32016-09-16 07:53:41 -07001360 analyzer.SetSendStream(video_send_stream_);
philipelfd870db2017-01-23 03:22:15 -08001361 if (video_receive_streams_.size() == 1)
1362 analyzer.SetReceiveStream(video_receive_streams_[0]);
perkj803d97f2016-11-01 11:45:46 -07001363 video_send_stream_->SetSource(
1364 analyzer.OutputInterface(),
1365 VideoSendStream::DegradationPreference::kBalanced);
ivica5d6a06c2015-09-17 05:30:24 -07001366
perkja49cbd32016-09-16 07:53:41 -07001367 CreateCapturer();
1368 rtc::VideoSinkWants wants;
minyuea27172d2016-11-01 05:59:29 -07001369 video_capturer_->AddOrUpdateSink(analyzer.InputInterface(), wants);
ivicac1cc8542015-10-08 03:44:06 -07001370
palmkviste75f2042016-09-28 06:19:48 -07001371 StartEncodedFrameLogs(video_send_stream_);
1372 StartEncodedFrameLogs(video_receive_streams_[0]);
stefanff483612015-12-21 03:14:00 -08001373 video_send_stream_->Start();
1374 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1375 receive_stream->Start();
brandtr1293aca2016-11-16 22:47:29 -08001376 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1377 receive_stream->Start();
minyuea27172d2016-11-01 05:59:29 -07001378 video_capturer_->Start();
ivica5d6a06c2015-09-17 05:30:24 -07001379
1380 analyzer.Wait();
1381
1382 send_transport.StopSending();
1383 recv_transport.StopSending();
1384
minyuea27172d2016-11-01 05:59:29 -07001385 video_capturer_->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001386 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1387 receive_stream->Stop();
stefanff483612015-12-21 03:14:00 -08001388 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1389 receive_stream->Stop();
1390 video_send_stream_->Stop();
ivica5d6a06c2015-09-17 05:30:24 -07001391
1392 DestroyStreams();
1393
1394 if (graph_data_output_file)
1395 fclose(graph_data_output_file);
1396}
1397
minyuea27172d2016-11-01 05:59:29 -07001398void VideoQualityTest::SetupAudio(int send_channel_id,
1399 int receive_channel_id,
1400 Call* call,
1401 Transport* transport,
1402 AudioReceiveStream** audio_receive_stream) {
1403 audio_send_config_ = AudioSendStream::Config(transport);
1404 audio_send_config_.voe_channel_id = send_channel_id;
1405 audio_send_config_.rtp.ssrc = kAudioSendSsrc;
1406
1407 // Add extension to enable audio send side BWE, and allow audio bit rate
1408 // adaptation.
1409 audio_send_config_.rtp.extensions.clear();
1410 if (params_.call.send_side_bwe) {
1411 audio_send_config_.rtp.extensions.push_back(
1412 webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri,
1413 test::kTransportSequenceNumberExtensionId));
minyue10cbb462016-11-07 09:29:22 -08001414 audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps;
1415 audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps;
minyuea27172d2016-11-01 05:59:29 -07001416 }
1417 audio_send_config_.send_codec_spec.codec_inst =
1418 CodecInst{120, "OPUS", 48000, 960, 2, 64000};
1419
1420 audio_send_stream_ = call->CreateAudioSendStream(audio_send_config_);
1421
1422 AudioReceiveStream::Config audio_config;
1423 audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc;
1424 audio_config.rtcp_send_transport = transport;
1425 audio_config.voe_channel_id = receive_channel_id;
1426 audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc;
1427 audio_config.rtp.transport_cc = params_.call.send_side_bwe;
1428 audio_config.rtp.extensions = audio_send_config_.rtp.extensions;
1429 audio_config.decoder_factory = decoder_factory_;
1430 if (params_.video.enabled && params_.audio.sync_video)
1431 audio_config.sync_group = kSyncGroup;
1432
1433 *audio_receive_stream = call->CreateAudioReceiveStream(audio_config);
1434}
1435
minyue73208662016-08-18 06:28:55 -07001436void VideoQualityTest::RunWithRenderers(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001437 params_ = params;
1438 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001439
ivica5d6a06c2015-09-17 05:30:24 -07001440 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
1441 // match the full stack tests.
skvlad11a9cbf2016-10-07 11:53:05 -07001442 webrtc::RtcEventLogNullImpl event_log;
1443 Call::Config call_config(&event_log_);
minyue626bc952016-10-31 05:47:02 -07001444 call_config.bitrate_config = params_.call.call_bitrate_config;
minyue73208662016-08-18 06:28:55 -07001445
1446 ::VoiceEngineState voe;
minyue626bc952016-10-31 05:47:02 -07001447 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001448 CreateVoiceEngine(&voe, decoder_factory_);
1449 AudioState::Config audio_state_config;
1450 audio_state_config.voice_engine = voe.voice_engine;
aleloi10111bc2016-11-17 06:48:48 -08001451 audio_state_config.audio_mixer = AudioMixerImpl::Create();
minyue73208662016-08-18 06:28:55 -07001452 call_config.audio_state = AudioState::Create(audio_state_config);
1453 }
1454
kwiberg27f982b2016-03-01 11:52:33 -08001455 std::unique_ptr<Call> call(Call::Create(call_config));
ivica5d6a06c2015-09-17 05:30:24 -07001456
minyuea27172d2016-11-01 05:59:29 -07001457 // TODO(minyue): consider if this is a good transport even for audio only
1458 // calls.
ivica5d6a06c2015-09-17 05:30:24 -07001459 test::LayerFilteringTransport transport(
stefanf116bd02015-10-27 08:29:42 -07001460 params.pipe, call.get(), kPayloadTypeVP8, kPayloadTypeVP9,
minyue626bc952016-10-31 05:47:02 -07001461 params.video.selected_tl, params_.ss.selected_sl);
ivica5d6a06c2015-09-17 05:30:24 -07001462 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
1463 // least share as much code as possible. That way this test would also match
1464 // the full stack tests better.
1465 transport.SetReceiver(call->Receiver());
1466
minyuea27172d2016-11-01 05:59:29 -07001467 VideoReceiveStream* video_receive_stream = nullptr;
brandtr1293aca2016-11-16 22:47:29 -08001468 FlexfecReceiveStream* flexfec_receive_stream = nullptr;
minyuea27172d2016-11-01 05:59:29 -07001469 std::unique_ptr<test::VideoRenderer> local_preview;
1470 std::unique_ptr<test::VideoRenderer> loopback_video;
1471 if (params_.video.enabled) {
1472 // Create video renderers.
1473 local_preview.reset(test::VideoRenderer::Create(
1474 "Local Preview", params_.video.width, params_.video.height));
ivica87f83a92015-10-08 05:13:32 -07001475
minyuea27172d2016-11-01 05:59:29 -07001476 size_t stream_id = params_.ss.selected_stream;
1477 std::string title = "Loopback Video";
1478 if (params_.ss.streams.size() > 1) {
1479 std::ostringstream s;
1480 s << stream_id;
1481 title += " - Stream #" + s.str();
1482 }
sprangce4aef12015-11-02 07:23:20 -08001483
minyuea27172d2016-11-01 05:59:29 -07001484 loopback_video.reset(test::VideoRenderer::Create(
1485 title.c_str(), params_.ss.streams[stream_id].width,
1486 params_.ss.streams[stream_id].height));
mflodman48a4beb2016-07-01 13:03:59 +02001487
minyuea27172d2016-11-01 05:59:29 -07001488 SetupVideo(&transport, &transport);
minyuea27172d2016-11-01 05:59:29 -07001489 video_send_config_.pre_encode_callback = local_preview.get();
1490 video_receive_configs_[stream_id].renderer = loopback_video.get();
1491 if (params_.audio.enabled && params_.audio.sync_video)
1492 video_receive_configs_[stream_id].sync_group = kSyncGroup;
1493
minyuea27172d2016-11-01 05:59:29 -07001494 if (params_.screenshare.enabled)
1495 SetupScreenshare();
1496
1497 video_send_stream_ = call->CreateVideoSendStream(
1498 video_send_config_.Copy(), video_encoder_config_.Copy());
brandtr1293aca2016-11-16 22:47:29 -08001499 if (params_.video.flexfec) {
1500 RTC_DCHECK(!flexfec_receive_configs_.empty());
1501 flexfec_receive_stream =
1502 call->CreateFlexfecReceiveStream(flexfec_receive_configs_[0]);
1503 }
minyuea27172d2016-11-01 05:59:29 -07001504 video_receive_stream = call->CreateVideoReceiveStream(
1505 video_receive_configs_[stream_id].Copy());
1506 CreateCapturer();
perkj803d97f2016-11-01 11:45:46 -07001507 video_send_stream_->SetSource(
1508 video_capturer_.get(),
1509 VideoSendStream::DegradationPreference::kBalanced);
philipel274c1dc2016-05-04 06:21:01 -07001510 }
1511
minyue73208662016-08-18 06:28:55 -07001512 AudioReceiveStream* audio_receive_stream = nullptr;
minyue626bc952016-10-31 05:47:02 -07001513 if (params_.audio.enabled) {
minyuea27172d2016-11-01 05:59:29 -07001514 SetupAudio(voe.send_channel_id, voe.receive_channel_id, call.get(),
1515 &transport, &audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001516 }
1517
palmkviste75f2042016-09-28 06:19:48 -07001518 StartEncodedFrameLogs(video_receive_stream);
1519 StartEncodedFrameLogs(video_send_stream_);
1520
minyue73208662016-08-18 06:28:55 -07001521 // Start sending and receiving video.
minyuea27172d2016-11-01 05:59:29 -07001522 if (params_.video.enabled) {
brandtr1293aca2016-11-16 22:47:29 -08001523 if (flexfec_receive_stream)
1524 flexfec_receive_stream->Start();
minyuea27172d2016-11-01 05:59:29 -07001525 video_receive_stream->Start();
1526 video_send_stream_->Start();
1527 video_capturer_->Start();
1528 }
ivica5d6a06c2015-09-17 05:30:24 -07001529
minyue626bc952016-10-31 05:47:02 -07001530 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001531 // Start receiving audio.
1532 audio_receive_stream->Start();
1533 EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id));
minyue73208662016-08-18 06:28:55 -07001534
1535 // Start sending audio.
1536 audio_send_stream_->Start();
1537 EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id));
1538 }
1539
ivica5d6a06c2015-09-17 05:30:24 -07001540 test::PressEnterToContinue();
1541
minyue626bc952016-10-31 05:47:02 -07001542 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001543 // Stop sending audio.
1544 EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id));
1545 audio_send_stream_->Stop();
1546
1547 // Stop receiving audio.
minyue73208662016-08-18 06:28:55 -07001548 EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id));
1549 audio_receive_stream->Stop();
minyuea27172d2016-11-01 05:59:29 -07001550 call->DestroyAudioSendStream(audio_send_stream_);
1551 call->DestroyAudioReceiveStream(audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001552 }
1553
1554 // Stop receiving and sending video.
minyuea27172d2016-11-01 05:59:29 -07001555 if (params_.video.enabled) {
1556 video_capturer_->Stop();
1557 video_send_stream_->Stop();
1558 video_receive_stream->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001559 if (flexfec_receive_stream) {
1560 flexfec_receive_stream->Stop();
1561 call->DestroyFlexfecReceiveStream(flexfec_receive_stream);
1562 }
minyuea27172d2016-11-01 05:59:29 -07001563 call->DestroyVideoReceiveStream(video_receive_stream);
1564 call->DestroyVideoSendStream(video_send_stream_);
minyue73208662016-08-18 06:28:55 -07001565 }
1566
ivica5d6a06c2015-09-17 05:30:24 -07001567 transport.StopSending();
minyue626bc952016-10-31 05:47:02 -07001568 if (params_.audio.enabled)
minyue73208662016-08-18 06:28:55 -07001569 DestroyVoiceEngine(&voe);
ivica5d6a06c2015-09-17 05:30:24 -07001570}
1571
palmkviste75f2042016-09-28 06:19:48 -07001572void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001573 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001574 std::ostringstream str;
1575 str << send_logs_++;
1576 std::string prefix =
minyue626bc952016-10-31 05:47:02 -07001577 params_.video.encoded_frame_base_path + "." + str.str() + ".send.";
palmkviste75f2042016-09-28 06:19:48 -07001578 stream->EnableEncodedFrameRecording(
1579 std::vector<rtc::PlatformFile>(
1580 {rtc::CreatePlatformFile(prefix + "1.ivf"),
1581 rtc::CreatePlatformFile(prefix + "2.ivf"),
1582 rtc::CreatePlatformFile(prefix + "3.ivf")}),
1583 10000000);
1584 }
1585}
1586void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001587 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001588 std::ostringstream str;
1589 str << receive_logs_++;
1590 std::string path =
minyue626bc952016-10-31 05:47:02 -07001591 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
palmkviste75f2042016-09-28 06:19:48 -07001592 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path),
1593 10000000);
1594 }
1595}
1596
ivica5d6a06c2015-09-17 05:30:24 -07001597} // namespace webrtc