blob: fad7e0764b3df3de718b55f69597421a0490f1a4 [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,
ilnik3dd5ad92017-02-09 04:58:53 -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),
ilnik3dd5ad92017-02-09 04:58:53 -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);
ilnik1e1c84d2017-02-09 08:32:53 -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.)
ilnik3dd5ad92017-02-09 04:58:53 -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_);
ilnik3dd5ad92017-02-09 04:58:53 -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 }
ilnik3dd5ad92017-02-09 04:58:53 -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_);
ilnik3dd5ad92017-02-09 04:58:53 -0800287 if (rtp_timestamp_delta_ == 0 && header.ssrc == ssrc_to_analyze_) {
ilnik1e1c84d2017-02-09 08:32:53 -0800288 RTC_CHECK(static_cast<bool>(first_sent_timestamp_));
ilnik3dd5ad92017-02-09 04:58:53 -0800289 rtp_timestamp_delta_ = header.timestamp - *first_sent_timestamp_;
ilnike67c59e2017-02-09 04:08:56 -0800290 }
ilnik3dd5ad92017-02-09 04:58:53 -0800291
292 if (!IsFlexfec(header.payloadType) && header.ssrc == ssrc_to_analyze_) {
brandtr504b95e2016-12-21 02:54:35 -0800293 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
294 // (FlexFEC and media are sent on different SSRCs, which have different
295 // timestamps spaces.)
ilnik3dd5ad92017-02-09 04:58:53 -0800296 // Also ignore packets from wrong SSRC.
brandtr504b95e2016-12-21 02:54:35 -0800297 int64_t timestamp =
298 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
299 send_times_[timestamp] = current_time;
300 if (!transport_->DiscardedLastPacket() &&
301 header.ssrc == ssrc_to_analyze_) {
302 encoded_frame_sizes_[timestamp] +=
303 length - (header.headerLength + header.paddingLength);
304 }
sprangce4aef12015-11-02 07:23:20 -0800305 }
ivica5d6a06c2015-09-17 05:30:24 -0700306 }
sprangce4aef12015-11-02 07:23:20 -0800307 return result;
ivica5d6a06c2015-09-17 05:30:24 -0700308 }
309
310 bool SendRtcp(const uint8_t* packet, size_t length) override {
311 return transport_->SendRtcp(packet, length);
312 }
313
314 void EncodedFrameCallback(const EncodedFrame& frame) override {
315 rtc::CritScope lock(&comparison_lock_);
316 if (frames_recorded_ < frames_to_process_)
317 encoded_frame_size_.AddSample(frame.length_);
318 }
319
nisseeb83a1a2016-03-21 01:27:56 -0700320 void OnFrame(const VideoFrame& video_frame) override {
ivica5d6a06c2015-09-17 05:30:24 -0700321 int64_t render_time_ms =
322 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
ivica5d6a06c2015-09-17 05:30:24 -0700323
324 rtc::CritScope lock(&crit_);
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700325 int64_t send_timestamp =
sprang16daaa52016-03-09 01:30:24 -0800326 wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_);
ivica5d6a06c2015-09-17 05:30:24 -0700327
sprang16daaa52016-03-09 01:30:24 -0800328 while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) {
nisse97f0b932016-05-26 09:44:40 -0700329 if (!last_rendered_frame_) {
pbos14fe7082016-04-20 06:35:56 -0700330 // No previous frame rendered, this one was dropped after sending but
331 // before rendering.
332 ++dropped_frames_before_rendering_;
kthelgason2bc68642017-02-07 07:02:22 -0800333 } else {
334 AddFrameComparison(frames_.front(), *last_rendered_frame_, true,
335 render_time_ms);
pbos14fe7082016-04-20 06:35:56 -0700336 }
ivica5d6a06c2015-09-17 05:30:24 -0700337 frames_.pop_front();
pbos14fe7082016-04-20 06:35:56 -0700338 RTC_DCHECK(!frames_.empty());
ivica5d6a06c2015-09-17 05:30:24 -0700339 }
340
341 VideoFrame reference_frame = frames_.front();
342 frames_.pop_front();
sprang16daaa52016-03-09 01:30:24 -0800343 int64_t reference_timestamp =
344 wrap_handler_.Unwrap(reference_frame.timestamp());
345 if (send_timestamp == reference_timestamp - 1) {
sprangce4aef12015-11-02 07:23:20 -0800346 // TODO(ivica): Make this work for > 2 streams.
Peter Boströme4499152016-02-05 11:13:28 +0100347 // Look at RTPSender::BuildRTPHeader.
sprangce4aef12015-11-02 07:23:20 -0800348 ++send_timestamp;
349 }
sprang16daaa52016-03-09 01:30:24 -0800350 ASSERT_EQ(reference_timestamp, send_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700351
352 AddFrameComparison(reference_frame, video_frame, false, render_time_ms);
353
nisse97f0b932016-05-26 09:44:40 -0700354 last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame);
ivica5d6a06c2015-09-17 05:30:24 -0700355 }
356
ivica5d6a06c2015-09-17 05:30:24 -0700357 void Wait() {
358 // Frame comparisons can be very expensive. Wait for test to be done, but
359 // at time-out check if frames_processed is going up. If so, give it more
360 // time, otherwise fail. Hopefully this will reduce test flakiness.
361
Peter Boström8c38e8b2015-11-26 17:45:47 +0100362 stats_polling_thread_.Start();
sprangce4aef12015-11-02 07:23:20 -0800363
ivica5d6a06c2015-09-17 05:30:24 -0700364 int last_frames_processed = -1;
ivica5d6a06c2015-09-17 05:30:24 -0700365 int iteration = 0;
Peter Boström5811a392015-12-10 13:02:50 +0100366 while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) {
ivica5d6a06c2015-09-17 05:30:24 -0700367 int frames_processed;
368 {
369 rtc::CritScope crit(&comparison_lock_);
370 frames_processed = frames_processed_;
371 }
372
373 // Print some output so test infrastructure won't think we've crashed.
374 const char* kKeepAliveMessages[3] = {
375 "Uh, I'm-I'm not quite dead, sir.",
376 "Uh, I-I think uh, I could pull through, sir.",
377 "Actually, I think I'm all right to come with you--"};
378 printf("- %s\n", kKeepAliveMessages[iteration++ % 3]);
379
380 if (last_frames_processed == -1) {
381 last_frames_processed = frames_processed;
382 continue;
383 }
Peter Boströmdd45eb62016-01-19 15:22:32 +0100384 if (frames_processed == last_frames_processed) {
385 EXPECT_GT(frames_processed, last_frames_processed)
386 << "Analyzer stalled while waiting for test to finish.";
387 done_.Set();
388 break;
389 }
ivica5d6a06c2015-09-17 05:30:24 -0700390 last_frames_processed = frames_processed;
391 }
392
393 if (iteration > 0)
394 printf("- Farewell, sweet Concorde!\n");
395
Peter Boström8c38e8b2015-11-26 17:45:47 +0100396 stats_polling_thread_.Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700397 }
398
pbos14fe7082016-04-20 06:35:56 -0700399 rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() {
400 return &pre_encode_proxy_;
401 }
Peter Boströme4499152016-02-05 11:13:28 +0100402 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; }
403
sprangce4aef12015-11-02 07:23:20 -0800404 test::LayerFilteringTransport* const transport_;
ivica5d6a06c2015-09-17 05:30:24 -0700405 PacketReceiver* receiver_;
ivica5d6a06c2015-09-17 05:30:24 -0700406
407 private:
408 struct FrameComparison {
409 FrameComparison()
410 : dropped(false),
nissedf2ceb82016-12-15 06:29:53 -0800411 input_time_ms(0),
ivica5d6a06c2015-09-17 05:30:24 -0700412 send_time_ms(0),
413 recv_time_ms(0),
414 render_time_ms(0),
415 encoded_frame_size(0) {}
416
417 FrameComparison(const VideoFrame& reference,
418 const VideoFrame& render,
419 bool dropped,
nissedf2ceb82016-12-15 06:29:53 -0800420 int64_t input_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700421 int64_t send_time_ms,
422 int64_t recv_time_ms,
423 int64_t render_time_ms,
424 size_t encoded_frame_size)
425 : reference(reference),
426 render(render),
427 dropped(dropped),
nissedf2ceb82016-12-15 06:29:53 -0800428 input_time_ms(input_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700429 send_time_ms(send_time_ms),
430 recv_time_ms(recv_time_ms),
431 render_time_ms(render_time_ms),
432 encoded_frame_size(encoded_frame_size) {}
433
nissedf2ceb82016-12-15 06:29:53 -0800434 FrameComparison(bool dropped,
435 int64_t input_time_ms,
436 int64_t send_time_ms,
437 int64_t recv_time_ms,
438 int64_t render_time_ms,
439 size_t encoded_frame_size)
440 : dropped(dropped),
441 input_time_ms(input_time_ms),
442 send_time_ms(send_time_ms),
443 recv_time_ms(recv_time_ms),
444 render_time_ms(render_time_ms),
445 encoded_frame_size(encoded_frame_size) {}
446
447 rtc::Optional<VideoFrame> reference;
448 rtc::Optional<VideoFrame> render;
ivica5d6a06c2015-09-17 05:30:24 -0700449 bool dropped;
nissedf2ceb82016-12-15 06:29:53 -0800450 int64_t input_time_ms;
ivica5d6a06c2015-09-17 05:30:24 -0700451 int64_t send_time_ms;
452 int64_t recv_time_ms;
453 int64_t render_time_ms;
454 size_t encoded_frame_size;
455 };
456
457 struct Sample {
ivica8d15bd62015-10-07 02:43:12 -0700458 Sample(int dropped,
459 int64_t input_time_ms,
460 int64_t send_time_ms,
461 int64_t recv_time_ms,
462 int64_t render_time_ms,
463 size_t encoded_frame_size,
ivica5d6a06c2015-09-17 05:30:24 -0700464 double psnr,
ivica8d15bd62015-10-07 02:43:12 -0700465 double ssim)
ivica5d6a06c2015-09-17 05:30:24 -0700466 : dropped(dropped),
467 input_time_ms(input_time_ms),
468 send_time_ms(send_time_ms),
469 recv_time_ms(recv_time_ms),
ivica8d15bd62015-10-07 02:43:12 -0700470 render_time_ms(render_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700471 encoded_frame_size(encoded_frame_size),
472 psnr(psnr),
ivica8d15bd62015-10-07 02:43:12 -0700473 ssim(ssim) {}
ivica5d6a06c2015-09-17 05:30:24 -0700474
ivica8d15bd62015-10-07 02:43:12 -0700475 int dropped;
476 int64_t input_time_ms;
477 int64_t send_time_ms;
478 int64_t recv_time_ms;
479 int64_t render_time_ms;
480 size_t encoded_frame_size;
ivica5d6a06c2015-09-17 05:30:24 -0700481 double psnr;
482 double ssim;
ivica5d6a06c2015-09-17 05:30:24 -0700483 };
484
Peter Boströme4499152016-02-05 11:13:28 +0100485 // This class receives the send-side OnEncodeTiming and is provided to not
486 // conflict with the receiver-side pre_decode_callback.
487 class OnEncodeTimingProxy : public EncodedFrameObserver {
488 public:
489 explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {}
490
491 void OnEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) override {
492 parent_->MeasuredEncodeTiming(ntp_time_ms, encode_time_ms);
493 }
ilnik3dd5ad92017-02-09 04:58:53 -0800494 void EncodedFrameCallback(const EncodedFrame& frame) override {
495 parent_->PostEncodeFrameCallback(frame);
496 }
Peter Boströme4499152016-02-05 11:13:28 +0100497
498 private:
499 VideoAnalyzer* const parent_;
500 };
501
pbos14fe7082016-04-20 06:35:56 -0700502 // This class receives the send-side OnFrame callback and is provided to not
503 // conflict with the receiver-side renderer callback.
504 class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> {
505 public:
506 explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {}
507
508 void OnFrame(const VideoFrame& video_frame) override {
509 parent_->PreEncodeOnFrame(video_frame);
510 }
511
512 private:
513 VideoAnalyzer* const parent_;
514 };
515
ivica5d6a06c2015-09-17 05:30:24 -0700516 void AddFrameComparison(const VideoFrame& reference,
517 const VideoFrame& render,
518 bool dropped,
519 int64_t render_time_ms)
520 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
sprange1f2f1f2016-02-01 02:04:52 -0800521 int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp());
522 int64_t send_time_ms = send_times_[reference_timestamp];
523 send_times_.erase(reference_timestamp);
524 int64_t recv_time_ms = recv_times_[reference_timestamp];
525 recv_times_.erase(reference_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700526
sprangce4aef12015-11-02 07:23:20 -0800527 // TODO(ivica): Make this work for > 2 streams.
sprange1f2f1f2016-02-01 02:04:52 -0800528 auto it = encoded_frame_sizes_.find(reference_timestamp);
sprangce4aef12015-11-02 07:23:20 -0800529 if (it == encoded_frame_sizes_.end())
sprange1f2f1f2016-02-01 02:04:52 -0800530 it = encoded_frame_sizes_.find(reference_timestamp - 1);
sprangce4aef12015-11-02 07:23:20 -0800531 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second;
532 if (it != encoded_frame_sizes_.end())
533 encoded_frame_sizes_.erase(it);
ivica5d6a06c2015-09-17 05:30:24 -0700534
ivica5d6a06c2015-09-17 05:30:24 -0700535 rtc::CritScope crit(&comparison_lock_);
stefanb1797672016-08-11 07:00:57 -0700536 if (comparisons_.size() < kMaxComparisons) {
nissedf2ceb82016-12-15 06:29:53 -0800537 comparisons_.push_back(FrameComparison(reference, render, dropped,
538 reference.ntp_time_ms(),
539 send_time_ms, recv_time_ms,
540 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700541 } else {
nissedf2ceb82016-12-15 06:29:53 -0800542 comparisons_.push_back(FrameComparison(dropped,
543 reference.ntp_time_ms(),
544 send_time_ms, recv_time_ms,
545 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700546 }
Peter Boström5811a392015-12-10 13:02:50 +0100547 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700548 }
549
550 static bool PollStatsThread(void* obj) {
551 return static_cast<VideoAnalyzer*>(obj)->PollStats();
552 }
553
554 bool PollStats() {
Peter Boströmdd45eb62016-01-19 15:22:32 +0100555 if (done_.Wait(kSendStatsPollingIntervalMs))
Peter Boström5811a392015-12-10 13:02:50 +0100556 return false;
ivica5d6a06c2015-09-17 05:30:24 -0700557
ivica5d6a06c2015-09-17 05:30:24 -0700558 rtc::CritScope crit(&comparison_lock_);
philipelfd870db2017-01-23 03:22:15 -0800559
560 VideoSendStream::Stats send_stats = send_stream_->GetStats();
Peter Boströmb1eaa8d2016-02-23 17:30:49 +0100561 // It's not certain that we yet have estimates for any of these stats. Check
562 // that they are positive before mixing them in.
philipelfd870db2017-01-23 03:22:15 -0800563 if (send_stats.encode_frame_rate > 0)
564 encode_frame_rate_.AddSample(send_stats.encode_frame_rate);
565 if (send_stats.avg_encode_time_ms > 0)
566 encode_time_ms_.AddSample(send_stats.avg_encode_time_ms);
567 if (send_stats.encode_usage_percent > 0)
568 encode_usage_percent_.AddSample(send_stats.encode_usage_percent);
569 if (send_stats.media_bitrate_bps > 0)
570 media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps);
571
572 if (receive_stream_ != nullptr) {
573 VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats();
574 if (receive_stats.decode_ms > 0)
575 decode_time_ms_.AddSample(receive_stats.decode_ms);
576 if (receive_stats.max_decode_ms > 0)
577 decode_time_max_ms_.AddSample(receive_stats.max_decode_ms);
578 }
ivica5d6a06c2015-09-17 05:30:24 -0700579
580 return true;
581 }
582
583 static bool FrameComparisonThread(void* obj) {
584 return static_cast<VideoAnalyzer*>(obj)->CompareFrames();
585 }
586
587 bool CompareFrames() {
588 if (AllFramesRecorded())
589 return false;
590
ivica5d6a06c2015-09-17 05:30:24 -0700591 FrameComparison comparison;
592
593 if (!PopComparison(&comparison)) {
594 // Wait until new comparison task is available, or test is done.
595 // If done, wake up remaining threads waiting.
Peter Boström5811a392015-12-10 13:02:50 +0100596 comparison_available_event_.Wait(1000);
ivica5d6a06c2015-09-17 05:30:24 -0700597 if (AllFramesRecorded()) {
Peter Boström5811a392015-12-10 13:02:50 +0100598 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700599 return false;
600 }
601 return true; // Try again.
602 }
603
604 PerformFrameComparison(comparison);
605
606 if (FrameProcessed()) {
607 PrintResults();
608 if (graph_data_output_file_)
609 PrintSamplesToFile();
Peter Boström5811a392015-12-10 13:02:50 +0100610 done_.Set();
611 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700612 return false;
613 }
614
615 return true;
616 }
617
618 bool PopComparison(FrameComparison* comparison) {
619 rtc::CritScope crit(&comparison_lock_);
620 // If AllFramesRecorded() is true, it means we have already popped
621 // frames_to_process_ frames from comparisons_, so there is no more work
622 // for this thread to be done. frames_processed_ might still be lower if
623 // all comparisons are not done, but those frames are currently being
624 // worked on by other threads.
625 if (comparisons_.empty() || AllFramesRecorded())
626 return false;
627
628 *comparison = comparisons_.front();
629 comparisons_.pop_front();
630
631 FrameRecorded();
632 return true;
633 }
634
635 // Increment counter for number of frames received for comparison.
636 void FrameRecorded() {
637 rtc::CritScope crit(&comparison_lock_);
638 ++frames_recorded_;
639 }
640
641 // Returns true if all frames to be compared have been taken from the queue.
642 bool AllFramesRecorded() {
643 rtc::CritScope crit(&comparison_lock_);
644 assert(frames_recorded_ <= frames_to_process_);
645 return frames_recorded_ == frames_to_process_;
646 }
647
648 // Increase count of number of frames processed. Returns true if this was the
649 // last frame to be processed.
650 bool FrameProcessed() {
651 rtc::CritScope crit(&comparison_lock_);
652 ++frames_processed_;
653 assert(frames_processed_ <= frames_to_process_);
654 return frames_processed_ == frames_to_process_;
655 }
656
657 void PrintResults() {
658 rtc::CritScope crit(&comparison_lock_);
659 PrintResult("psnr", psnr_, " dB");
tnakamura3123cbc2016-02-10 11:21:51 -0800660 PrintResult("ssim", ssim_, " score");
ivica5d6a06c2015-09-17 05:30:24 -0700661 PrintResult("sender_time", sender_time_, " ms");
ivica5d6a06c2015-09-17 05:30:24 -0700662 PrintResult("receiver_time", receiver_time_, " ms");
663 PrintResult("total_delay_incl_network", end_to_end_, " ms");
664 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
665 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes");
666 PrintResult("encode_frame_rate", encode_frame_rate_, " fps");
philipelfd870db2017-01-23 03:22:15 -0800667 PrintResult("encode_time", encode_time_ms_, " ms");
668 PrintResult("encode_usage_percent", encode_usage_percent_, " percent");
669 PrintResult("media_bitrate", media_bitrate_bps_, " bps");
670
671 if (receive_stream_ != nullptr) {
672 PrintResult("decode_time", decode_time_ms_, " ms");
673 PrintResult("decode_time_max", decode_time_max_ms_, " ms");
674 }
ivica5d6a06c2015-09-17 05:30:24 -0700675
pbos14fe7082016-04-20 06:35:56 -0700676 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(),
677 dropped_frames_);
678 printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n",
679 test_label_.c_str(), dropped_frames_before_first_encode_);
680 printf("RESULT dropped_frames_before_rendering: %s = %d frames\n",
681 test_label_.c_str(), dropped_frames_before_rendering_);
682
ivica5d6a06c2015-09-17 05:30:24 -0700683 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
684 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_);
685 }
686
687 void PerformFrameComparison(const FrameComparison& comparison) {
688 // Perform expensive psnr and ssim calculations while not holding lock.
stefanb1797672016-08-11 07:00:57 -0700689 double psnr = -1.0;
690 double ssim = -1.0;
nissedf2ceb82016-12-15 06:29:53 -0800691 if (comparison.reference) {
692 psnr = I420PSNR(&*comparison.reference, &*comparison.render);
693 ssim = I420SSIM(&*comparison.reference, &*comparison.render);
stefanb1797672016-08-11 07:00:57 -0700694 }
ivica5d6a06c2015-09-17 05:30:24 -0700695
ivica5d6a06c2015-09-17 05:30:24 -0700696 rtc::CritScope crit(&comparison_lock_);
697 if (graph_data_output_file_) {
nissedf2ceb82016-12-15 06:29:53 -0800698 samples_.push_back(Sample(
699 comparison.dropped, comparison.input_time_ms, comparison.send_time_ms,
700 comparison.recv_time_ms, comparison.render_time_ms,
701 comparison.encoded_frame_size, psnr, ssim));
ivica5d6a06c2015-09-17 05:30:24 -0700702 }
stefanb1797672016-08-11 07:00:57 -0700703 if (psnr >= 0.0)
704 psnr_.AddSample(psnr);
705 if (ssim >= 0.0)
706 ssim_.AddSample(ssim);
ivica5d6a06c2015-09-17 05:30:24 -0700707
708 if (comparison.dropped) {
709 ++dropped_frames_;
710 return;
711 }
712 if (last_render_time_ != 0)
713 rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_);
714 last_render_time_ = comparison.render_time_ms;
715
nissedf2ceb82016-12-15 06:29:53 -0800716 sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms);
brandtr504b95e2016-12-21 02:54:35 -0800717 if (comparison.recv_time_ms > 0) {
718 // If recv_time_ms == 0, this frame consisted of a packets which were all
719 // lost in the transport. Since we were able to render the frame, however,
720 // the dropped packets were recovered by FlexFEC. The FlexFEC recovery
721 // happens internally in Call, and we can therefore here not know which
722 // FEC packets that protected the lost media packets. Consequently, we
723 // were not able to record a meaningful recv_time_ms. We therefore skip
724 // this sample.
725 //
726 // The reasoning above does not hold for ULPFEC and RTX, as for those
727 // strategies the timestamp of the received packets is set to the
728 // timestamp of the protected/retransmitted media packet. I.e., then
729 // recv_time_ms != 0, even though the media packets were lost.
730 receiver_time_.AddSample(comparison.render_time_ms -
731 comparison.recv_time_ms);
732 }
nissedf2ceb82016-12-15 06:29:53 -0800733 end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms);
ivica5d6a06c2015-09-17 05:30:24 -0700734 encoded_frame_size_.AddSample(comparison.encoded_frame_size);
735 }
736
737 void PrintResult(const char* result_type,
738 test::Statistics stats,
739 const char* unit) {
740 printf("RESULT %s: %s = {%f, %f}%s\n",
741 result_type,
742 test_label_.c_str(),
743 stats.Mean(),
744 stats.StandardDeviation(),
745 unit);
746 }
747
748 void PrintSamplesToFile(void) {
749 FILE* out = graph_data_output_file_;
750 rtc::CritScope crit(&comparison_lock_);
751 std::sort(samples_.begin(), samples_.end(),
752 [](const Sample& A, const Sample& B) -> bool {
753 return A.input_time_ms < B.input_time_ms;
754 });
755
sprangce4aef12015-11-02 07:23:20 -0800756 fprintf(out, "%s\n", graph_title_.c_str());
ivica5d6a06c2015-09-17 05:30:24 -0700757 fprintf(out, "%" PRIuS "\n", samples_.size());
758 fprintf(out,
759 "dropped "
760 "input_time_ms "
761 "send_time_ms "
762 "recv_time_ms "
ivica8d15bd62015-10-07 02:43:12 -0700763 "render_time_ms "
ivica5d6a06c2015-09-17 05:30:24 -0700764 "encoded_frame_size "
765 "psnr "
766 "ssim "
ivica8d15bd62015-10-07 02:43:12 -0700767 "encode_time_ms\n");
768 int missing_encode_time_samples = 0;
ivica5d6a06c2015-09-17 05:30:24 -0700769 for (const Sample& sample : samples_) {
ivica8d15bd62015-10-07 02:43:12 -0700770 auto it = samples_encode_time_ms_.find(sample.input_time_ms);
771 int encode_time_ms;
772 if (it != samples_encode_time_ms_.end()) {
773 encode_time_ms = it->second;
774 } else {
775 ++missing_encode_time_samples;
776 encode_time_ms = -1;
777 }
778 fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS
779 " %lf %lf %d\n",
780 sample.dropped, sample.input_time_ms, sample.send_time_ms,
781 sample.recv_time_ms, sample.render_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700782 sample.encoded_frame_size, sample.psnr, sample.ssim,
ivica8d15bd62015-10-07 02:43:12 -0700783 encode_time_ms);
784 }
785 if (missing_encode_time_samples) {
786 fprintf(stderr,
787 "Warning: Missing encode_time_ms samples for %d frame(s).\n",
788 missing_encode_time_samples);
ivica5d6a06c2015-09-17 05:30:24 -0700789 }
790 }
791
perkja49cbd32016-09-16 07:53:41 -0700792 // Implements VideoSinkInterface to receive captured frames from a
793 // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act
794 // as a source to VideoSendStream.
795 // It forwards all input frames to the VideoAnalyzer for later comparison and
796 // forwards the captured frames to the VideoSendStream.
797 class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>,
798 public rtc::VideoSourceInterface<VideoFrame> {
799 public:
800 explicit CapturedFrameForwarder(VideoAnalyzer* analyzer)
801 : analyzer_(analyzer), send_stream_input_(nullptr) {}
802
803 private:
804 void OnFrame(const VideoFrame& video_frame) override {
805 VideoFrame copy = video_frame;
ilnik3dd5ad92017-02-09 04:58:53 -0800806 // Frames from the capturer does not have a rtp timestamp.
807 // Create one so it can be used for comparison.
808 RTC_DCHECK_EQ(0, video_frame.timestamp());
perkja49cbd32016-09-16 07:53:41 -0700809 copy.set_timestamp(copy.ntp_time_ms() * 90);
ilnik3dd5ad92017-02-09 04:58:53 -0800810 analyzer_->AddCapturedFrameForComparison(copy);
perkja49cbd32016-09-16 07:53:41 -0700811 rtc::CritScope lock(&crit_);
812 if (send_stream_input_)
813 send_stream_input_->OnFrame(video_frame);
814 }
815
816 // Called when |send_stream_.SetSource()| is called.
817 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
818 const rtc::VideoSinkWants& wants) override {
819 rtc::CritScope lock(&crit_);
820 RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
821 send_stream_input_ = sink;
822 }
823
824 // Called by |send_stream_| when |send_stream_.SetSource()| is called.
825 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {
826 rtc::CritScope lock(&crit_);
827 RTC_DCHECK(sink == send_stream_input_);
828 send_stream_input_ = nullptr;
829 }
830
831 VideoAnalyzer* const analyzer_;
832 rtc::CriticalSection crit_;
833 rtc::VideoSinkInterface<VideoFrame>* send_stream_input_ GUARDED_BY(crit_);
834 };
835
836 void AddCapturedFrameForComparison(const VideoFrame& video_frame) {
837 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800838 frames_.push_back(video_frame);
perkja49cbd32016-09-16 07:53:41 -0700839 }
840
841 VideoSendStream* send_stream_;
philipelfd870db2017-01-23 03:22:15 -0800842 VideoReceiveStream* receive_stream_;
perkja49cbd32016-09-16 07:53:41 -0700843 CapturedFrameForwarder captured_frame_forwarder_;
ivica5d6a06c2015-09-17 05:30:24 -0700844 const std::string test_label_;
845 FILE* const graph_data_output_file_;
sprangce4aef12015-11-02 07:23:20 -0800846 const std::string graph_title_;
847 const uint32_t ssrc_to_analyze_;
ilnik3dd5ad92017-02-09 04:58:53 -0800848 const uint32_t selected_width_;
849 const uint32_t selected_height_;
pbos14fe7082016-04-20 06:35:56 -0700850 PreEncodeProxy pre_encode_proxy_;
Peter Boströme4499152016-02-05 11:13:28 +0100851 OnEncodeTimingProxy encode_timing_proxy_;
ivica5d6a06c2015-09-17 05:30:24 -0700852 std::vector<Sample> samples_ GUARDED_BY(comparison_lock_);
ivica8d15bd62015-10-07 02:43:12 -0700853 std::map<int64_t, int> samples_encode_time_ms_ GUARDED_BY(comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700854 test::Statistics sender_time_ GUARDED_BY(comparison_lock_);
855 test::Statistics receiver_time_ GUARDED_BY(comparison_lock_);
856 test::Statistics psnr_ GUARDED_BY(comparison_lock_);
857 test::Statistics ssim_ GUARDED_BY(comparison_lock_);
858 test::Statistics end_to_end_ GUARDED_BY(comparison_lock_);
859 test::Statistics rendered_delta_ GUARDED_BY(comparison_lock_);
860 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_);
861 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_);
philipelfd870db2017-01-23 03:22:15 -0800862 test::Statistics encode_time_ms_ GUARDED_BY(comparison_lock_);
863 test::Statistics encode_usage_percent_ GUARDED_BY(comparison_lock_);
864 test::Statistics decode_time_ms_ GUARDED_BY(comparison_lock_);
865 test::Statistics decode_time_max_ms_ GUARDED_BY(comparison_lock_);
866 test::Statistics media_bitrate_bps_ GUARDED_BY(comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700867
868 const int frames_to_process_;
869 int frames_recorded_;
870 int frames_processed_;
871 int dropped_frames_;
pbos14fe7082016-04-20 06:35:56 -0700872 int dropped_frames_before_first_encode_;
873 int dropped_frames_before_rendering_;
ivica5d6a06c2015-09-17 05:30:24 -0700874 int64_t last_render_time_;
875 uint32_t rtp_timestamp_delta_;
876
877 rtc::CriticalSection crit_;
878 std::deque<VideoFrame> frames_ GUARDED_BY(crit_);
nisse97f0b932016-05-26 09:44:40 -0700879 rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_);
sprange1f2f1f2016-02-01 02:04:52 -0800880 rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_);
881 std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_);
882 std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_);
883 std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800884 rtc::Optional<uint32_t> first_encoded_timestamp_ GUARDED_BY(crit_);
885 rtc::Optional<uint32_t> first_sent_timestamp_ GUARDED_BY(crit_);
ivica5d6a06c2015-09-17 05:30:24 -0700886 const double avg_psnr_threshold_;
887 const double avg_ssim_threshold_;
888
889 rtc::CriticalSection comparison_lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +0100890 std::vector<rtc::PlatformThread*> comparison_thread_pool_;
891 rtc::PlatformThread stats_polling_thread_;
Peter Boström5811a392015-12-10 13:02:50 +0100892 rtc::Event comparison_available_event_;
ivica5d6a06c2015-09-17 05:30:24 -0700893 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);
Peter Boström5811a392015-12-10 13:02:50 +0100894 rtc::Event done_;
ivica5d6a06c2015-09-17 05:30:24 -0700895};
896
palmkviste75f2042016-09-28 06:19:48 -0700897VideoQualityTest::VideoQualityTest()
898 : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) {}
ivica5d6a06c2015-09-17 05:30:24 -0700899
minyue626bc952016-10-31 05:47:02 -0700900VideoQualityTest::Params::Params()
901 : call({false, Call::Config::BitrateConfig()}),
902 video({false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false,
brandtr1293aca2016-11-16 22:47:29 -0800903 false, "", ""}),
minyue626bc952016-10-31 05:47:02 -0700904 audio({false, false}),
905 screenshare({false, 10, 0}),
906 analyzer({"", 0.0, 0.0, 0, "", ""}),
907 pipe(),
908 logs(false),
909 ss({std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}) {}
910
911VideoQualityTest::Params::~Params() = default;
912
ivica5d6a06c2015-09-17 05:30:24 -0700913void VideoQualityTest::TestBody() {}
914
sprangce4aef12015-11-02 07:23:20 -0800915std::string VideoQualityTest::GenerateGraphTitle() const {
916 std::stringstream ss;
minyue626bc952016-10-31 05:47:02 -0700917 ss << params_.video.codec;
918 ss << " (" << params_.video.target_bitrate_bps / 1000 << "kbps";
919 ss << ", " << params_.video.fps << " FPS";
sprangce4aef12015-11-02 07:23:20 -0800920 if (params_.screenshare.scroll_duration)
921 ss << ", " << params_.screenshare.scroll_duration << "s scroll";
922 if (params_.ss.streams.size() > 1)
923 ss << ", Stream #" << params_.ss.selected_stream;
924 if (params_.ss.num_spatial_layers > 1)
925 ss << ", Layer #" << params_.ss.selected_sl;
926 ss << ")";
927 return ss.str();
928}
929
930void VideoQualityTest::CheckParams() {
stefan7de8d642017-02-07 07:14:08 -0800931 if (!params_.video.enabled)
932 return;
sprangce4aef12015-11-02 07:23:20 -0800933 // Add a default stream in none specified.
934 if (params_.ss.streams.empty())
935 params_.ss.streams.push_back(VideoQualityTest::DefaultVideoStream(params_));
936 if (params_.ss.num_spatial_layers == 0)
937 params_.ss.num_spatial_layers = 1;
938
939 if (params_.pipe.loss_percent != 0 ||
940 params_.pipe.queue_length_packets != 0) {
941 // Since LayerFilteringTransport changes the sequence numbers, we can't
942 // use that feature with pack loss, since the NACK request would end up
943 // retransmitting the wrong packets.
944 RTC_CHECK(params_.ss.selected_sl == -1 ||
sprangee37de32015-11-23 06:10:23 -0800945 params_.ss.selected_sl == params_.ss.num_spatial_layers - 1);
minyue626bc952016-10-31 05:47:02 -0700946 RTC_CHECK(params_.video.selected_tl == -1 ||
947 params_.video.selected_tl ==
948 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -0800949 }
950
951 // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as it
952 // does in some parts of the code?
minyue626bc952016-10-31 05:47:02 -0700953 RTC_CHECK_GE(params_.video.max_bitrate_bps, params_.video.target_bitrate_bps);
954 RTC_CHECK_GE(params_.video.target_bitrate_bps, params_.video.min_bitrate_bps);
955 RTC_CHECK_LT(params_.video.selected_tl, params_.video.num_temporal_layers);
sprangce4aef12015-11-02 07:23:20 -0800956 RTC_CHECK_LT(params_.ss.selected_stream, params_.ss.streams.size());
957 for (const VideoStream& stream : params_.ss.streams) {
958 RTC_CHECK_GE(stream.min_bitrate_bps, 0);
959 RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps);
960 RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps);
kwiberg352444f2016-11-28 15:58:53 -0800961 RTC_CHECK_EQ(stream.temporal_layer_thresholds_bps.size(),
minyue626bc952016-10-31 05:47:02 -0700962 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -0800963 }
964 // TODO(ivica): Should we check if the sum of all streams/layers is equal to
965 // the total bitrate? We anyway have to update them in the case bitrate
966 // estimator changes the total bitrates.
967 RTC_CHECK_GE(params_.ss.num_spatial_layers, 1);
968 RTC_CHECK_LE(params_.ss.selected_sl, params_.ss.num_spatial_layers);
969 RTC_CHECK(params_.ss.spatial_layers.empty() ||
970 params_.ss.spatial_layers.size() ==
971 static_cast<size_t>(params_.ss.num_spatial_layers));
minyue626bc952016-10-31 05:47:02 -0700972 if (params_.video.codec == "VP8") {
sprangce4aef12015-11-02 07:23:20 -0800973 RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1);
minyue626bc952016-10-31 05:47:02 -0700974 } else if (params_.video.codec == "VP9") {
kwibergaf476c72016-11-28 15:21:39 -0800975 RTC_CHECK_EQ(params_.ss.streams.size(), 1);
sprangce4aef12015-11-02 07:23:20 -0800976 }
977}
978
979// Static.
980std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) {
981 // Parse comma separated nonnegative integers, where some elements may be
982 // empty. The empty values are replaced with -1.
983 // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40}
984 // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1}
985 std::vector<int> result;
986 if (str.empty())
987 return result;
988
989 const char* p = str.c_str();
990 int value = -1;
991 int pos;
992 while (*p) {
993 if (*p == ',') {
994 result.push_back(value);
995 value = -1;
996 ++p;
997 continue;
998 }
999 RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1)
1000 << "Unexpected non-number value.";
1001 p += pos;
1002 }
1003 result.push_back(value);
1004 return result;
1005}
1006
1007// Static.
1008VideoStream VideoQualityTest::DefaultVideoStream(const Params& params) {
1009 VideoStream stream;
minyue626bc952016-10-31 05:47:02 -07001010 stream.width = params.video.width;
1011 stream.height = params.video.height;
1012 stream.max_framerate = params.video.fps;
1013 stream.min_bitrate_bps = params.video.min_bitrate_bps;
1014 stream.target_bitrate_bps = params.video.target_bitrate_bps;
1015 stream.max_bitrate_bps = params.video.max_bitrate_bps;
sprangce4aef12015-11-02 07:23:20 -08001016 stream.max_qp = 52;
minyue626bc952016-10-31 05:47:02 -07001017 if (params.video.num_temporal_layers == 2)
sprangce4aef12015-11-02 07:23:20 -08001018 stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps);
1019 return stream;
1020}
1021
1022// Static.
1023void VideoQualityTest::FillScalabilitySettings(
1024 Params* params,
1025 const std::vector<std::string>& stream_descriptors,
1026 size_t selected_stream,
1027 int num_spatial_layers,
1028 int selected_sl,
1029 const std::vector<std::string>& sl_descriptors) {
1030 // Read VideoStream and SpatialLayer elements from a list of comma separated
1031 // lists. To use a default value for an element, use -1 or leave empty.
1032 // Validity checks performed in CheckParams.
1033
1034 RTC_CHECK(params->ss.streams.empty());
1035 for (auto descriptor : stream_descriptors) {
1036 if (descriptor.empty())
1037 continue;
1038 VideoStream stream = VideoQualityTest::DefaultVideoStream(*params);
1039 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1040 if (v[0] != -1)
1041 stream.width = static_cast<size_t>(v[0]);
1042 if (v[1] != -1)
1043 stream.height = static_cast<size_t>(v[1]);
1044 if (v[2] != -1)
1045 stream.max_framerate = v[2];
1046 if (v[3] != -1)
1047 stream.min_bitrate_bps = v[3];
1048 if (v[4] != -1)
1049 stream.target_bitrate_bps = v[4];
1050 if (v[5] != -1)
1051 stream.max_bitrate_bps = v[5];
1052 if (v.size() > 6 && v[6] != -1)
1053 stream.max_qp = v[6];
1054 if (v.size() > 7) {
1055 stream.temporal_layer_thresholds_bps.clear();
1056 stream.temporal_layer_thresholds_bps.insert(
1057 stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end());
1058 } else {
1059 // Automatic TL thresholds for more than two layers not supported.
minyue626bc952016-10-31 05:47:02 -07001060 RTC_CHECK_LE(params->video.num_temporal_layers, 2);
sprangce4aef12015-11-02 07:23:20 -08001061 }
1062 params->ss.streams.push_back(stream);
1063 }
1064 params->ss.selected_stream = selected_stream;
1065
1066 params->ss.num_spatial_layers = num_spatial_layers ? num_spatial_layers : 1;
1067 params->ss.selected_sl = selected_sl;
1068 RTC_CHECK(params->ss.spatial_layers.empty());
1069 for (auto descriptor : sl_descriptors) {
1070 if (descriptor.empty())
1071 continue;
1072 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1073 RTC_CHECK_GT(v[2], 0);
1074
1075 SpatialLayer layer;
1076 layer.scaling_factor_num = v[0] == -1 ? 1 : v[0];
1077 layer.scaling_factor_den = v[1] == -1 ? 1 : v[1];
1078 layer.target_bitrate_bps = v[2];
1079 params->ss.spatial_layers.push_back(layer);
1080 }
1081}
1082
minyuea27172d2016-11-01 05:59:29 -07001083void VideoQualityTest::SetupVideo(Transport* send_transport,
1084 Transport* recv_transport) {
sprangce4aef12015-11-02 07:23:20 -08001085 if (params_.logs)
ivica5d6a06c2015-09-17 05:30:24 -07001086 trace_to_stderr_.reset(new test::TraceToStderr);
1087
brandtr8313a6f2017-01-13 07:41:19 -08001088 size_t num_video_streams = params_.ss.streams.size();
1089 size_t num_flexfec_streams = params_.video.flexfec ? 1 : 0;
1090 CreateSendConfig(num_video_streams, 0, num_flexfec_streams, send_transport);
ivica5d6a06c2015-09-17 05:30:24 -07001091
1092 int payload_type;
minyue626bc952016-10-31 05:47:02 -07001093 if (params_.video.codec == "H264") {
magjedceecea42016-11-28 07:20:21 -08001094 video_encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264")));
hbosbab934b2016-01-27 01:36:03 -08001095 payload_type = kPayloadTypeH264;
minyue626bc952016-10-31 05:47:02 -07001096 } else if (params_.video.codec == "VP8") {
magjed509e4fe2016-11-18 01:34:11 -08001097 video_encoder_.reset(VP8Encoder::Create());
ivica5d6a06c2015-09-17 05:30:24 -07001098 payload_type = kPayloadTypeVP8;
minyue626bc952016-10-31 05:47:02 -07001099 } else if (params_.video.codec == "VP9") {
magjed509e4fe2016-11-18 01:34:11 -08001100 video_encoder_.reset(VP9Encoder::Create());
ivica5d6a06c2015-09-17 05:30:24 -07001101 payload_type = kPayloadTypeVP9;
1102 } else {
1103 RTC_NOTREACHED() << "Codec not supported!";
1104 return;
1105 }
minyuea27172d2016-11-01 05:59:29 -07001106 video_send_config_.encoder_settings.encoder = video_encoder_.get();
minyue626bc952016-10-31 05:47:02 -07001107 video_send_config_.encoder_settings.payload_name = params_.video.codec;
stefanff483612015-12-21 03:14:00 -08001108 video_send_config_.encoder_settings.payload_type = payload_type;
1109 video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1110 video_send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
brandtr8313a6f2017-01-13 07:41:19 -08001111 for (size_t i = 0; i < num_video_streams; ++i)
stefanff483612015-12-21 03:14:00 -08001112 video_send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[i]);
ivica5d6a06c2015-09-17 05:30:24 -07001113
stefanff483612015-12-21 03:14:00 -08001114 video_send_config_.rtp.extensions.clear();
minyue626bc952016-10-31 05:47:02 -07001115 if (params_.call.send_side_bwe) {
stefanff483612015-12-21 03:14:00 -08001116 video_send_config_.rtp.extensions.push_back(
isheriff6f8d6862016-05-26 11:24:55 -07001117 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Stefan Holmer12952972015-10-29 15:13:24 +01001118 test::kTransportSequenceNumberExtensionId));
1119 } else {
stefanff483612015-12-21 03:14:00 -08001120 video_send_config_.rtp.extensions.push_back(RtpExtension(
isheriff6f8d6862016-05-26 11:24:55 -07001121 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
Erik SprĂ¥ng6b8d3552015-09-24 15:06:57 +02001122 }
1123
stefanff483612015-12-21 03:14:00 -08001124 video_encoder_config_.min_transmit_bitrate_bps =
minyue626bc952016-10-31 05:47:02 -07001125 params_.video.min_transmit_bps;
perkjfa10b552016-10-02 23:45:26 -07001126
brandtr1293aca2016-11-16 22:47:29 -08001127 video_send_config_.suspend_below_min_bitrate =
1128 params_.video.suspend_below_min_bitrate;
1129
perkjfa10b552016-10-02 23:45:26 -07001130 video_encoder_config_.number_of_streams = params_.ss.streams.size();
1131 video_encoder_config_.max_bitrate_bps = 0;
1132 for (size_t i = 0; i < params_.ss.streams.size(); ++i) {
1133 video_encoder_config_.max_bitrate_bps +=
1134 params_.ss.streams[i].max_bitrate_bps;
1135 }
1136 video_encoder_config_.video_stream_factory =
1137 new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams);
1138
stefanff483612015-12-21 03:14:00 -08001139 video_encoder_config_.spatial_layers = params_.ss.spatial_layers;
ivica5d6a06c2015-09-17 05:30:24 -07001140
1141 CreateMatchingReceiveConfigs(recv_transport);
1142
brandtr8313a6f2017-01-13 07:41:19 -08001143 for (size_t i = 0; i < num_video_streams; ++i) {
stefanff483612015-12-21 03:14:00 -08001144 video_receive_configs_[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
brandtr14742122017-01-27 04:53:07 -08001145 video_receive_configs_[i].rtp.rtx_ssrc = kSendRtxSsrcs[i];
1146 video_receive_configs_[i].rtp.rtx_payload_types[payload_type] =
sprangce4aef12015-11-02 07:23:20 -08001147 kSendRtxPayloadType;
minyue626bc952016-10-31 05:47:02 -07001148 video_receive_configs_[i].rtp.transport_cc = params_.call.send_side_bwe;
Stefan Holmer85d5ac72017-02-09 16:25:16 +01001149 video_receive_configs_[i].rtp.remb = !params_.call.send_side_bwe;
sprangce4aef12015-11-02 07:23:20 -08001150 }
brandtr1293aca2016-11-16 22:47:29 -08001151
1152 if (params_.video.flexfec) {
brandtr8313a6f2017-01-13 07:41:19 -08001153 // Override send config constructed by CreateSendConfig.
brandtr1293aca2016-11-16 22:47:29 -08001154 video_send_config_.rtp.flexfec.protected_media_ssrcs = {
1155 kVideoSendSsrcs[params_.ss.selected_stream]};
1156
brandtr8313a6f2017-01-13 07:41:19 -08001157 // The matching receive config is _not_ created by
1158 // CreateMatchingReceiveConfigs, since VideoQualityTest is not a BaseTest.
1159 // Set up the receive config manually instead.
1160 FlexfecReceiveStream::Config flexfec_receive_config(recv_transport);
brandtr1cfbd602016-12-08 04:17:53 -08001161 flexfec_receive_config.payload_type =
brandtr3d200bd2017-01-16 06:59:19 -08001162 video_send_config_.rtp.flexfec.payload_type;
1163 flexfec_receive_config.remote_ssrc = video_send_config_.rtp.flexfec.ssrc;
brandtr1293aca2016-11-16 22:47:29 -08001164 flexfec_receive_config.protected_media_ssrcs =
1165 video_send_config_.rtp.flexfec.protected_media_ssrcs;
brandtrfa5a3682017-01-17 01:33:54 -08001166 flexfec_receive_config.local_ssrc = kReceiverLocalVideoSsrc;
brandtrb29e6522016-12-21 06:37:18 -08001167 flexfec_receive_config.transport_cc = params_.call.send_side_bwe;
1168 if (params_.call.send_side_bwe) {
1169 flexfec_receive_config.rtp_header_extensions.push_back(
1170 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1171 test::kTransportSequenceNumberExtensionId));
1172 } else {
1173 flexfec_receive_config.rtp_header_extensions.push_back(RtpExtension(
1174 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1175 }
brandtr1293aca2016-11-16 22:47:29 -08001176 flexfec_receive_configs_.push_back(flexfec_receive_config);
1177 }
1178
1179 if (params_.video.ulpfec) {
1180 video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType;
1181 video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType;
1182 video_send_config_.rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType;
1183
1184 video_receive_configs_[params_.ss.selected_stream]
1185 .rtp.ulpfec.red_payload_type =
1186 video_send_config_.rtp.ulpfec.red_payload_type;
1187 video_receive_configs_[params_.ss.selected_stream]
1188 .rtp.ulpfec.ulpfec_payload_type =
1189 video_send_config_.rtp.ulpfec.ulpfec_payload_type;
1190 video_receive_configs_[params_.ss.selected_stream]
1191 .rtp.ulpfec.red_rtx_payload_type =
1192 video_send_config_.rtp.ulpfec.red_rtx_payload_type;
1193 }
ivica5d6a06c2015-09-17 05:30:24 -07001194}
1195
sprangce4aef12015-11-02 07:23:20 -08001196void VideoQualityTest::SetupScreenshare() {
1197 RTC_CHECK(params_.screenshare.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001198
1199 // Fill out codec settings.
stefanff483612015-12-21 03:14:00 -08001200 video_encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
kthelgason2bc68642017-02-07 07:02:22 -08001201 degradation_preference_ =
1202 VideoSendStream::DegradationPreference::kMaintainResolution;
minyue626bc952016-10-31 05:47:02 -07001203 if (params_.video.codec == "VP8") {
kthelgason29a44e32016-09-27 03:52:02 -07001204 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
1205 vp8_settings.denoisingOn = false;
1206 vp8_settings.frameDroppingOn = false;
1207 vp8_settings.numberOfTemporalLayers =
minyue626bc952016-10-31 05:47:02 -07001208 static_cast<unsigned char>(params_.video.num_temporal_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001209 video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject<
1210 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
minyue626bc952016-10-31 05:47:02 -07001211 } else if (params_.video.codec == "VP9") {
kthelgason29a44e32016-09-27 03:52:02 -07001212 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
1213 vp9_settings.denoisingOn = false;
1214 vp9_settings.frameDroppingOn = false;
1215 vp9_settings.numberOfTemporalLayers =
minyue626bc952016-10-31 05:47:02 -07001216 static_cast<unsigned char>(params_.video.num_temporal_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001217 vp9_settings.numberOfSpatialLayers =
sprangce4aef12015-11-02 07:23:20 -08001218 static_cast<unsigned char>(params_.ss.num_spatial_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001219 video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject<
1220 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
ivica5d6a06c2015-09-17 05:30:24 -07001221 }
1222
1223 // Setup frame generator.
1224 const size_t kWidth = 1850;
1225 const size_t kHeight = 1110;
1226 std::vector<std::string> slides;
1227 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
1228 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
1229 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
1230 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
1231
sprangce4aef12015-11-02 07:23:20 -08001232 if (params_.screenshare.scroll_duration == 0) {
ivica5d6a06c2015-09-17 05:30:24 -07001233 // Cycle image every slide_change_interval seconds.
1234 frame_generator_.reset(test::FrameGenerator::CreateFromYuvFile(
1235 slides, kWidth, kHeight,
minyue626bc952016-10-31 05:47:02 -07001236 params_.screenshare.slide_change_interval * params_.video.fps));
ivica5d6a06c2015-09-17 05:30:24 -07001237 } else {
minyue626bc952016-10-31 05:47:02 -07001238 RTC_CHECK_LE(params_.video.width, kWidth);
1239 RTC_CHECK_LE(params_.video.height, kHeight);
sprangce4aef12015-11-02 07:23:20 -08001240 RTC_CHECK_GT(params_.screenshare.slide_change_interval, 0);
1241 const int kPauseDurationMs = (params_.screenshare.slide_change_interval -
1242 params_.screenshare.scroll_duration) *
1243 1000;
1244 RTC_CHECK_LE(params_.screenshare.scroll_duration,
1245 params_.screenshare.slide_change_interval);
ivica5d6a06c2015-09-17 05:30:24 -07001246
sprangce4aef12015-11-02 07:23:20 -08001247 frame_generator_.reset(
1248 test::FrameGenerator::CreateScrollingInputFromYuvFiles(
minyue626bc952016-10-31 05:47:02 -07001249 clock_, slides, kWidth, kHeight, params_.video.width,
1250 params_.video.height, params_.screenshare.scroll_duration * 1000,
sprangce4aef12015-11-02 07:23:20 -08001251 kPauseDurationMs));
ivica5d6a06c2015-09-17 05:30:24 -07001252 }
1253}
1254
perkja49cbd32016-09-16 07:53:41 -07001255void VideoQualityTest::CreateCapturer() {
sprangce4aef12015-11-02 07:23:20 -08001256 if (params_.screenshare.enabled) {
1257 test::FrameGeneratorCapturer* frame_generator_capturer =
perkja49cbd32016-09-16 07:53:41 -07001258 new test::FrameGeneratorCapturer(clock_, frame_generator_.release(),
minyue626bc952016-10-31 05:47:02 -07001259 params_.video.fps);
ivica2d4e6c52015-09-23 01:57:06 -07001260 EXPECT_TRUE(frame_generator_capturer->Init());
minyuea27172d2016-11-01 05:59:29 -07001261 video_capturer_.reset(frame_generator_capturer);
ivica5d6a06c2015-09-17 05:30:24 -07001262 } else {
sprangce4aef12015-11-02 07:23:20 -08001263 if (params_.video.clip_name.empty()) {
minyuea27172d2016-11-01 05:59:29 -07001264 video_capturer_.reset(test::VcmCapturer::Create(
minyue626bc952016-10-31 05:47:02 -07001265 params_.video.width, params_.video.height, params_.video.fps));
sprang1bed2e42017-01-23 08:46:51 -08001266 if (!video_capturer_) {
1267 // Failed to get actual camera, use chroma generator as backup.
1268 video_capturer_.reset(test::FrameGeneratorCapturer::Create(
1269 params_.video.width, params_.video.height, params_.video.fps,
1270 clock_));
1271 }
ivica5d6a06c2015-09-17 05:30:24 -07001272 } else {
minyuea27172d2016-11-01 05:59:29 -07001273 video_capturer_.reset(test::FrameGeneratorCapturer::CreateFromYuvFile(
perkja49cbd32016-09-16 07:53:41 -07001274 test::ResourcePath(params_.video.clip_name, "yuv"),
minyue626bc952016-10-31 05:47:02 -07001275 params_.video.width, params_.video.height, params_.video.fps,
ivica2d4e6c52015-09-23 01:57:06 -07001276 clock_));
minyuea27172d2016-11-01 05:59:29 -07001277 ASSERT_TRUE(video_capturer_) << "Could not create capturer for "
1278 << params_.video.clip_name
1279 << ".yuv. Is this resource file present?";
ivica5d6a06c2015-09-17 05:30:24 -07001280 }
1281 }
sprang1bed2e42017-01-23 08:46:51 -08001282 RTC_DCHECK(video_capturer_.get());
ivica5d6a06c2015-09-17 05:30:24 -07001283}
1284
sprang7a975f72015-10-12 06:33:21 -07001285void VideoQualityTest::RunWithAnalyzer(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001286 params_ = params;
1287
minyue626bc952016-10-31 05:47:02 -07001288 RTC_CHECK(!params_.audio.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001289 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1290 // differentiate between the analyzer and the renderer case.
sprangce4aef12015-11-02 07:23:20 -08001291 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001292
1293 FILE* graph_data_output_file = nullptr;
sprangce4aef12015-11-02 07:23:20 -08001294 if (!params_.analyzer.graph_data_output_filename.empty()) {
ivica5d6a06c2015-09-17 05:30:24 -07001295 graph_data_output_file =
sprangce4aef12015-11-02 07:23:20 -08001296 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
Peter Boström74f6e9e2016-04-04 17:56:10 +02001297 RTC_CHECK(graph_data_output_file)
sprangce4aef12015-11-02 07:23:20 -08001298 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1299 << "!";
ivica87f83a92015-10-08 05:13:32 -07001300 }
sprang7a975f72015-10-12 06:33:21 -07001301
skvlad11a9cbf2016-10-07 11:53:05 -07001302 webrtc::RtcEventLogNullImpl event_log;
1303 Call::Config call_config(&event_log_);
minyue626bc952016-10-31 05:47:02 -07001304 call_config.bitrate_config = params.call.call_bitrate_config;
stefanf116bd02015-10-27 08:29:42 -07001305 CreateCalls(call_config, call_config);
1306
ivica87f83a92015-10-08 05:13:32 -07001307 test::LayerFilteringTransport send_transport(
minyue626bc952016-10-31 05:47:02 -07001308 params_.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9,
1309 params_.video.selected_tl, params_.ss.selected_sl);
1310 test::DirectTransport recv_transport(params_.pipe, receiver_call_.get());
stefanf116bd02015-10-27 08:29:42 -07001311
sprangce4aef12015-11-02 07:23:20 -08001312 std::string graph_title = params_.analyzer.graph_title;
1313 if (graph_title.empty())
1314 graph_title = VideoQualityTest::GenerateGraphTitle();
1315
1316 // In the case of different resolutions, the functions calculating PSNR and
1317 // SSIM return -1.0, instead of a positive value as usual. VideoAnalyzer
1318 // aborts if the average psnr/ssim are below the given threshold, which is
1319 // 0.0 by default. Setting the thresholds to -1.1 prevents the unnecessary
1320 // abort.
1321 VideoStream& selected_stream = params_.ss.streams[params_.ss.selected_stream];
1322 int selected_sl = params_.ss.selected_sl != -1
1323 ? params_.ss.selected_sl
1324 : params_.ss.num_spatial_layers - 1;
1325 bool disable_quality_check =
minyue626bc952016-10-31 05:47:02 -07001326 selected_stream.width != params_.video.width ||
1327 selected_stream.height != params_.video.height ||
sprangce4aef12015-11-02 07:23:20 -08001328 (!params_.ss.spatial_layers.empty() &&
1329 params_.ss.spatial_layers[selected_sl].scaling_factor_num !=
1330 params_.ss.spatial_layers[selected_sl].scaling_factor_den);
1331 if (disable_quality_check) {
1332 fprintf(stderr,
1333 "Warning: Calculating PSNR and SSIM for downsized resolution "
ilnik3dd5ad92017-02-09 04:58:53 -08001334 "not implemented yet! Skipping PSNR and SSIM calculations!\n");
sprangce4aef12015-11-02 07:23:20 -08001335 }
1336
ivica5d6a06c2015-09-17 05:30:24 -07001337 VideoAnalyzer analyzer(
sprangce4aef12015-11-02 07:23:20 -08001338 &send_transport, params_.analyzer.test_label,
1339 disable_quality_check ? -1.1 : params_.analyzer.avg_psnr_threshold,
1340 disable_quality_check ? -1.1 : params_.analyzer.avg_ssim_threshold,
minyue626bc952016-10-31 05:47:02 -07001341 params_.analyzer.test_durations_secs * params_.video.fps,
sprangce4aef12015-11-02 07:23:20 -08001342 graph_data_output_file, graph_title,
ilnik3dd5ad92017-02-09 04:58:53 -08001343 kVideoSendSsrcs[params_.ss.selected_stream],
1344 static_cast<uint32_t>(selected_stream.width),
1345 static_cast<uint32_t>(selected_stream.height));
ivica5d6a06c2015-09-17 05:30:24 -07001346
ivica5d6a06c2015-09-17 05:30:24 -07001347 analyzer.SetReceiver(receiver_call_->Receiver());
1348 send_transport.SetReceiver(&analyzer);
1349 recv_transport.SetReceiver(sender_call_->Receiver());
1350
minyuea27172d2016-11-01 05:59:29 -07001351 SetupVideo(&analyzer, &recv_transport);
stefanff483612015-12-21 03:14:00 -08001352 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer;
pbos14fe7082016-04-20 06:35:56 -07001353 video_send_config_.pre_encode_callback = analyzer.pre_encode_proxy();
stefanff483612015-12-21 03:14:00 -08001354 for (auto& config : video_receive_configs_)
ivica5d6a06c2015-09-17 05:30:24 -07001355 config.pre_decode_callback = &analyzer;
Peter Boströme4499152016-02-05 11:13:28 +01001356 RTC_DCHECK(!video_send_config_.post_encode_callback);
1357 video_send_config_.post_encode_callback = analyzer.encode_timing_proxy();
ivica5d6a06c2015-09-17 05:30:24 -07001358
sprangce4aef12015-11-02 07:23:20 -08001359 if (params_.screenshare.enabled)
1360 SetupScreenshare();
ivica5d6a06c2015-09-17 05:30:24 -07001361
brandtr1293aca2016-11-16 22:47:29 -08001362 CreateFlexfecStreams();
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001363 CreateVideoStreams();
perkja49cbd32016-09-16 07:53:41 -07001364 analyzer.SetSendStream(video_send_stream_);
philipelfd870db2017-01-23 03:22:15 -08001365 if (video_receive_streams_.size() == 1)
1366 analyzer.SetReceiveStream(video_receive_streams_[0]);
kthelgason2bc68642017-02-07 07:02:22 -08001367
1368 video_send_stream_->SetSource(analyzer.OutputInterface(),
1369 degradation_preference_);
ivica5d6a06c2015-09-17 05:30:24 -07001370
perkja49cbd32016-09-16 07:53:41 -07001371 CreateCapturer();
1372 rtc::VideoSinkWants wants;
minyuea27172d2016-11-01 05:59:29 -07001373 video_capturer_->AddOrUpdateSink(analyzer.InputInterface(), wants);
ivicac1cc8542015-10-08 03:44:06 -07001374
palmkviste75f2042016-09-28 06:19:48 -07001375 StartEncodedFrameLogs(video_send_stream_);
1376 StartEncodedFrameLogs(video_receive_streams_[0]);
stefanff483612015-12-21 03:14:00 -08001377 video_send_stream_->Start();
1378 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1379 receive_stream->Start();
brandtr1293aca2016-11-16 22:47:29 -08001380 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1381 receive_stream->Start();
minyuea27172d2016-11-01 05:59:29 -07001382 video_capturer_->Start();
ivica5d6a06c2015-09-17 05:30:24 -07001383
1384 analyzer.Wait();
1385
1386 send_transport.StopSending();
1387 recv_transport.StopSending();
1388
minyuea27172d2016-11-01 05:59:29 -07001389 video_capturer_->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001390 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1391 receive_stream->Stop();
stefanff483612015-12-21 03:14:00 -08001392 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1393 receive_stream->Stop();
1394 video_send_stream_->Stop();
ivica5d6a06c2015-09-17 05:30:24 -07001395
1396 DestroyStreams();
1397
1398 if (graph_data_output_file)
1399 fclose(graph_data_output_file);
1400}
1401
minyuea27172d2016-11-01 05:59:29 -07001402void VideoQualityTest::SetupAudio(int send_channel_id,
1403 int receive_channel_id,
1404 Call* call,
1405 Transport* transport,
1406 AudioReceiveStream** audio_receive_stream) {
1407 audio_send_config_ = AudioSendStream::Config(transport);
1408 audio_send_config_.voe_channel_id = send_channel_id;
1409 audio_send_config_.rtp.ssrc = kAudioSendSsrc;
1410
1411 // Add extension to enable audio send side BWE, and allow audio bit rate
1412 // adaptation.
1413 audio_send_config_.rtp.extensions.clear();
1414 if (params_.call.send_side_bwe) {
1415 audio_send_config_.rtp.extensions.push_back(
1416 webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri,
1417 test::kTransportSequenceNumberExtensionId));
minyue10cbb462016-11-07 09:29:22 -08001418 audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps;
1419 audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps;
minyuea27172d2016-11-01 05:59:29 -07001420 }
1421 audio_send_config_.send_codec_spec.codec_inst =
1422 CodecInst{120, "OPUS", 48000, 960, 2, 64000};
1423
1424 audio_send_stream_ = call->CreateAudioSendStream(audio_send_config_);
1425
1426 AudioReceiveStream::Config audio_config;
1427 audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc;
1428 audio_config.rtcp_send_transport = transport;
1429 audio_config.voe_channel_id = receive_channel_id;
1430 audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc;
1431 audio_config.rtp.transport_cc = params_.call.send_side_bwe;
1432 audio_config.rtp.extensions = audio_send_config_.rtp.extensions;
1433 audio_config.decoder_factory = decoder_factory_;
1434 if (params_.video.enabled && params_.audio.sync_video)
1435 audio_config.sync_group = kSyncGroup;
1436
1437 *audio_receive_stream = call->CreateAudioReceiveStream(audio_config);
1438}
1439
minyue73208662016-08-18 06:28:55 -07001440void VideoQualityTest::RunWithRenderers(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001441 params_ = params;
1442 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001443
ivica5d6a06c2015-09-17 05:30:24 -07001444 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
1445 // match the full stack tests.
skvlad11a9cbf2016-10-07 11:53:05 -07001446 webrtc::RtcEventLogNullImpl event_log;
1447 Call::Config call_config(&event_log_);
minyue626bc952016-10-31 05:47:02 -07001448 call_config.bitrate_config = params_.call.call_bitrate_config;
minyue73208662016-08-18 06:28:55 -07001449
1450 ::VoiceEngineState voe;
minyue626bc952016-10-31 05:47:02 -07001451 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001452 CreateVoiceEngine(&voe, decoder_factory_);
1453 AudioState::Config audio_state_config;
1454 audio_state_config.voice_engine = voe.voice_engine;
aleloi10111bc2016-11-17 06:48:48 -08001455 audio_state_config.audio_mixer = AudioMixerImpl::Create();
minyue73208662016-08-18 06:28:55 -07001456 call_config.audio_state = AudioState::Create(audio_state_config);
1457 }
1458
kwiberg27f982b2016-03-01 11:52:33 -08001459 std::unique_ptr<Call> call(Call::Create(call_config));
ivica5d6a06c2015-09-17 05:30:24 -07001460
minyuea27172d2016-11-01 05:59:29 -07001461 // TODO(minyue): consider if this is a good transport even for audio only
1462 // calls.
ivica5d6a06c2015-09-17 05:30:24 -07001463 test::LayerFilteringTransport transport(
stefanf116bd02015-10-27 08:29:42 -07001464 params.pipe, call.get(), kPayloadTypeVP8, kPayloadTypeVP9,
minyue626bc952016-10-31 05:47:02 -07001465 params.video.selected_tl, params_.ss.selected_sl);
ivica5d6a06c2015-09-17 05:30:24 -07001466 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
1467 // least share as much code as possible. That way this test would also match
1468 // the full stack tests better.
1469 transport.SetReceiver(call->Receiver());
1470
minyuea27172d2016-11-01 05:59:29 -07001471 VideoReceiveStream* video_receive_stream = nullptr;
brandtr1293aca2016-11-16 22:47:29 -08001472 FlexfecReceiveStream* flexfec_receive_stream = nullptr;
minyuea27172d2016-11-01 05:59:29 -07001473 std::unique_ptr<test::VideoRenderer> local_preview;
1474 std::unique_ptr<test::VideoRenderer> loopback_video;
1475 if (params_.video.enabled) {
1476 // Create video renderers.
1477 local_preview.reset(test::VideoRenderer::Create(
1478 "Local Preview", params_.video.width, params_.video.height));
ivica87f83a92015-10-08 05:13:32 -07001479
minyuea27172d2016-11-01 05:59:29 -07001480 size_t stream_id = params_.ss.selected_stream;
1481 std::string title = "Loopback Video";
1482 if (params_.ss.streams.size() > 1) {
1483 std::ostringstream s;
1484 s << stream_id;
1485 title += " - Stream #" + s.str();
1486 }
sprangce4aef12015-11-02 07:23:20 -08001487
minyuea27172d2016-11-01 05:59:29 -07001488 loopback_video.reset(test::VideoRenderer::Create(
1489 title.c_str(), params_.ss.streams[stream_id].width,
1490 params_.ss.streams[stream_id].height));
mflodman48a4beb2016-07-01 13:03:59 +02001491
minyuea27172d2016-11-01 05:59:29 -07001492 SetupVideo(&transport, &transport);
minyuea27172d2016-11-01 05:59:29 -07001493 video_send_config_.pre_encode_callback = local_preview.get();
1494 video_receive_configs_[stream_id].renderer = loopback_video.get();
1495 if (params_.audio.enabled && params_.audio.sync_video)
1496 video_receive_configs_[stream_id].sync_group = kSyncGroup;
1497
minyuea27172d2016-11-01 05:59:29 -07001498 if (params_.screenshare.enabled)
1499 SetupScreenshare();
1500
1501 video_send_stream_ = call->CreateVideoSendStream(
1502 video_send_config_.Copy(), video_encoder_config_.Copy());
brandtr1293aca2016-11-16 22:47:29 -08001503 if (params_.video.flexfec) {
1504 RTC_DCHECK(!flexfec_receive_configs_.empty());
1505 flexfec_receive_stream =
1506 call->CreateFlexfecReceiveStream(flexfec_receive_configs_[0]);
1507 }
minyuea27172d2016-11-01 05:59:29 -07001508 video_receive_stream = call->CreateVideoReceiveStream(
1509 video_receive_configs_[stream_id].Copy());
1510 CreateCapturer();
kthelgason2bc68642017-02-07 07:02:22 -08001511 video_send_stream_->SetSource(video_capturer_.get(),
1512 degradation_preference_);
philipel274c1dc2016-05-04 06:21:01 -07001513 }
1514
minyue73208662016-08-18 06:28:55 -07001515 AudioReceiveStream* audio_receive_stream = nullptr;
minyue626bc952016-10-31 05:47:02 -07001516 if (params_.audio.enabled) {
minyuea27172d2016-11-01 05:59:29 -07001517 SetupAudio(voe.send_channel_id, voe.receive_channel_id, call.get(),
1518 &transport, &audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001519 }
1520
palmkviste75f2042016-09-28 06:19:48 -07001521 StartEncodedFrameLogs(video_receive_stream);
1522 StartEncodedFrameLogs(video_send_stream_);
1523
minyue73208662016-08-18 06:28:55 -07001524 // Start sending and receiving video.
minyuea27172d2016-11-01 05:59:29 -07001525 if (params_.video.enabled) {
brandtr1293aca2016-11-16 22:47:29 -08001526 if (flexfec_receive_stream)
1527 flexfec_receive_stream->Start();
minyuea27172d2016-11-01 05:59:29 -07001528 video_receive_stream->Start();
1529 video_send_stream_->Start();
1530 video_capturer_->Start();
1531 }
ivica5d6a06c2015-09-17 05:30:24 -07001532
minyue626bc952016-10-31 05:47:02 -07001533 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001534 // Start receiving audio.
1535 audio_receive_stream->Start();
1536 EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id));
minyue73208662016-08-18 06:28:55 -07001537
1538 // Start sending audio.
1539 audio_send_stream_->Start();
1540 EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id));
1541 }
1542
ivica5d6a06c2015-09-17 05:30:24 -07001543 test::PressEnterToContinue();
1544
minyue626bc952016-10-31 05:47:02 -07001545 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001546 // Stop sending audio.
1547 EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id));
1548 audio_send_stream_->Stop();
1549
1550 // Stop receiving audio.
minyue73208662016-08-18 06:28:55 -07001551 EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id));
1552 audio_receive_stream->Stop();
minyuea27172d2016-11-01 05:59:29 -07001553 call->DestroyAudioSendStream(audio_send_stream_);
1554 call->DestroyAudioReceiveStream(audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001555 }
1556
1557 // Stop receiving and sending video.
minyuea27172d2016-11-01 05:59:29 -07001558 if (params_.video.enabled) {
1559 video_capturer_->Stop();
1560 video_send_stream_->Stop();
1561 video_receive_stream->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001562 if (flexfec_receive_stream) {
1563 flexfec_receive_stream->Stop();
1564 call->DestroyFlexfecReceiveStream(flexfec_receive_stream);
1565 }
minyuea27172d2016-11-01 05:59:29 -07001566 call->DestroyVideoReceiveStream(video_receive_stream);
1567 call->DestroyVideoSendStream(video_send_stream_);
minyue73208662016-08-18 06:28:55 -07001568 }
1569
ivica5d6a06c2015-09-17 05:30:24 -07001570 transport.StopSending();
minyue626bc952016-10-31 05:47:02 -07001571 if (params_.audio.enabled)
minyue73208662016-08-18 06:28:55 -07001572 DestroyVoiceEngine(&voe);
ivica5d6a06c2015-09-17 05:30:24 -07001573}
1574
palmkviste75f2042016-09-28 06:19:48 -07001575void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001576 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001577 std::ostringstream str;
1578 str << send_logs_++;
1579 std::string prefix =
minyue626bc952016-10-31 05:47:02 -07001580 params_.video.encoded_frame_base_path + "." + str.str() + ".send.";
palmkviste75f2042016-09-28 06:19:48 -07001581 stream->EnableEncodedFrameRecording(
1582 std::vector<rtc::PlatformFile>(
1583 {rtc::CreatePlatformFile(prefix + "1.ivf"),
1584 rtc::CreatePlatformFile(prefix + "2.ivf"),
1585 rtc::CreatePlatformFile(prefix + "3.ivf")}),
1586 10000000);
1587 }
1588}
1589void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001590 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001591 std::ostringstream str;
1592 str << receive_logs_++;
1593 std::string path =
minyue626bc952016-10-31 05:47:02 -07001594 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
palmkviste75f2042016-09-28 06:19:48 -07001595 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path),
1596 10000000);
1597 }
1598}
1599
ivica5d6a06c2015-09-17 05:30:24 -07001600} // namespace webrtc