blob: d19ecbe3613cbdd240c9a0c58f6743c4ec8bece1 [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>
ilnikcb8c1462017-03-09 09:23:30 -080016#include <set>
sprangce4aef12015-11-02 07:23:20 -080017#include <sstream>
mflodmand1590b22015-12-09 07:07:59 -080018#include <string>
ivica5d6a06c2015-09-17 05:30:24 -070019#include <vector>
20
ivica5d6a06c2015-09-17 05:30:24 -070021#include "webrtc/base/checks.h"
ilnikdf92c5c2017-02-23 02:08:44 -080022#include "webrtc/base/cpu_time.h"
Peter Boström5811a392015-12-10 13:02:50 +010023#include "webrtc/base/event.h"
ivica5d6a06c2015-09-17 05:30:24 -070024#include "webrtc/base/format_macros.h"
ilnikdaa574d2017-03-01 06:46:05 -080025#include "webrtc/base/memory_usage.h"
nissec7fe3c22016-04-20 03:25:36 -070026#include "webrtc/base/optional.h"
palmkviste75f2042016-09-28 06:19:48 -070027#include "webrtc/base/platform_file.h"
sprange1f2f1f2016-02-01 02:04:52 -080028#include "webrtc/base/timeutils.h"
ossuf515ab82016-12-07 04:52:58 -080029#include "webrtc/call/call.h"
ivica5d6a06c2015-09-17 05:30:24 -070030#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
skvlad11a9cbf2016-10-07 11:53:05 -070031#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
sprang67561a62017-06-15 06:34:42 -070032#include "webrtc/media/engine/webrtcvideoengine.h"
aleloi10111bc2016-11-17 06:48:48 -080033#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010034#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
ilnik1e7732c2017-02-23 05:07:56 -080035#include "webrtc/modules/rtp_rtcp/source/rtp_format.h"
sprangce4aef12015-11-02 07:23:20 -080036#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
magjed509e4fe2016-11-18 01:34:11 -080037#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
38#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
ilnikcb8c1462017-03-09 09:23:30 -080039#include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h"
magjed509e4fe2016-11-18 01:34:11 -080040#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010041#include "webrtc/system_wrappers/include/cpu_info.h"
ilnik9ae0d762017-02-15 00:53:12 -080042#include "webrtc/system_wrappers/include/field_trial.h"
kwibergac9f8762016-09-30 22:29:43 -070043#include "webrtc/test/gtest.h"
ivica5d6a06c2015-09-17 05:30:24 -070044#include "webrtc/test/layer_filtering_transport.h"
45#include "webrtc/test/run_loop.h"
46#include "webrtc/test/statistics.h"
47#include "webrtc/test/testsupport/fileutils.h"
perkja49cbd32016-09-16 07:53:41 -070048#include "webrtc/test/vcm_capturer.h"
ivica5d6a06c2015-09-17 05:30:24 -070049#include "webrtc/test/video_renderer.h"
minyue73208662016-08-18 06:28:55 -070050#include "webrtc/voice_engine/include/voe_base.h"
minyue73208662016-08-18 06:28:55 -070051
52namespace {
53
54constexpr int kSendStatsPollingIntervalMs = 1000;
55constexpr int kPayloadTypeH264 = 122;
56constexpr int kPayloadTypeVP8 = 123;
57constexpr int kPayloadTypeVP9 = 124;
minyue20c84cc2017-04-10 16:57:57 -070058
minyue73208662016-08-18 06:28:55 -070059constexpr size_t kMaxComparisons = 10;
60constexpr char kSyncGroup[] = "av_sync";
minyue10cbb462016-11-07 09:29:22 -080061constexpr int kOpusMinBitrateBps = 6000;
62constexpr int kOpusBitrateFbBps = 32000;
ilnik9ae0d762017-02-15 00:53:12 -080063constexpr int kFramesSentInQuickTest = 1;
ilnika014cc52017-03-07 04:21:04 -080064constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000;
65constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000;
minyue73208662016-08-18 06:28:55 -070066
67struct VoiceEngineState {
68 VoiceEngineState()
69 : voice_engine(nullptr),
70 base(nullptr),
minyue73208662016-08-18 06:28:55 -070071 send_channel_id(-1),
72 receive_channel_id(-1) {}
73
74 webrtc::VoiceEngine* voice_engine;
75 webrtc::VoEBase* base;
minyue73208662016-08-18 06:28:55 -070076 int send_channel_id;
77 int receive_channel_id;
78};
79
80void CreateVoiceEngine(VoiceEngineState* voe,
81 rtc::scoped_refptr<webrtc::AudioDecoderFactory>
82 decoder_factory) {
83 voe->voice_engine = webrtc::VoiceEngine::Create();
84 voe->base = webrtc::VoEBase::GetInterface(voe->voice_engine);
minyue73208662016-08-18 06:28:55 -070085 EXPECT_EQ(0, voe->base->Init(nullptr, nullptr, decoder_factory));
solenberg88499ec2016-09-07 07:34:41 -070086 webrtc::VoEBase::ChannelConfig config;
87 config.enable_voice_pacing = true;
88 voe->send_channel_id = voe->base->CreateChannel(config);
minyue73208662016-08-18 06:28:55 -070089 EXPECT_GE(voe->send_channel_id, 0);
90 voe->receive_channel_id = voe->base->CreateChannel();
91 EXPECT_GE(voe->receive_channel_id, 0);
92}
93
94void DestroyVoiceEngine(VoiceEngineState* voe) {
95 voe->base->DeleteChannel(voe->send_channel_id);
96 voe->send_channel_id = -1;
97 voe->base->DeleteChannel(voe->receive_channel_id);
98 voe->receive_channel_id = -1;
99 voe->base->Release();
100 voe->base = nullptr;
minyue73208662016-08-18 06:28:55 -0700101
102 webrtc::VoiceEngine::Delete(voe->voice_engine);
103 voe->voice_engine = nullptr;
104}
105
perkjfa10b552016-10-02 23:45:26 -0700106class VideoStreamFactory
107 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
108 public:
109 explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams)
110 : streams_(streams) {}
111
112 private:
113 std::vector<webrtc::VideoStream> CreateEncoderStreams(
114 int width,
115 int height,
116 const webrtc::VideoEncoderConfig& encoder_config) override {
mflodmand79f97b2016-12-15 07:24:33 -0800117 // The highest layer must match the incoming resolution.
118 std::vector<webrtc::VideoStream> streams = streams_;
119 streams[streams_.size() - 1].height = height;
120 streams[streams_.size() - 1].width = width;
121 return streams;
perkjfa10b552016-10-02 23:45:26 -0700122 }
123
124 std::vector<webrtc::VideoStream> streams_;
125};
126
brandtr504b95e2016-12-21 02:54:35 -0800127bool IsFlexfec(int payload_type) {
128 return payload_type == webrtc::VideoQualityTest::kFlexfecPayloadType;
129}
130
minyue73208662016-08-18 06:28:55 -0700131} // namespace
ivica5d6a06c2015-09-17 05:30:24 -0700132
133namespace webrtc {
134
ivica5d6a06c2015-09-17 05:30:24 -0700135class VideoAnalyzer : public PacketReceiver,
pbos2d566682015-09-28 09:59:31 -0700136 public Transport,
ilnik1e7732c2017-02-23 05:07:56 -0800137 public rtc::VideoSinkInterface<VideoFrame> {
ivica5d6a06c2015-09-17 05:30:24 -0700138 public:
sprangce4aef12015-11-02 07:23:20 -0800139 VideoAnalyzer(test::LayerFilteringTransport* transport,
ivica5d6a06c2015-09-17 05:30:24 -0700140 const std::string& test_label,
141 double avg_psnr_threshold,
142 double avg_ssim_threshold,
143 int duration_frames,
sprangce4aef12015-11-02 07:23:20 -0800144 FILE* graph_data_output_file,
145 const std::string& graph_title,
ilnik3dd5ad92017-02-09 04:58:53 -0800146 uint32_t ssrc_to_analyze,
ilnik46a00212017-02-10 09:16:05 -0800147 uint32_t rtx_ssrc_to_analyze,
ilnikcb8c1462017-03-09 09:23:30 -0800148 size_t selected_stream,
ilnik1e7732c2017-02-23 05:07:56 -0800149 int selected_sl,
150 int selected_tl,
ilnik6b826ef2017-06-16 06:53:48 -0700151 bool is_quick_test_enabled,
152 Clock* clock)
perkja49cbd32016-09-16 07:53:41 -0700153 : transport_(transport),
ivica5d6a06c2015-09-17 05:30:24 -0700154 receiver_(nullptr),
155 send_stream_(nullptr),
philipelfd870db2017-01-23 03:22:15 -0800156 receive_stream_(nullptr),
ilnik6b826ef2017-06-16 06:53:48 -0700157 captured_frame_forwarder_(this, clock),
ivica5d6a06c2015-09-17 05:30:24 -0700158 test_label_(test_label),
159 graph_data_output_file_(graph_data_output_file),
sprangce4aef12015-11-02 07:23:20 -0800160 graph_title_(graph_title),
161 ssrc_to_analyze_(ssrc_to_analyze),
ilnik46a00212017-02-10 09:16:05 -0800162 rtx_ssrc_to_analyze_(rtx_ssrc_to_analyze),
ilnikcb8c1462017-03-09 09:23:30 -0800163 selected_stream_(selected_stream),
ilnik1e7732c2017-02-23 05:07:56 -0800164 selected_sl_(selected_sl),
165 selected_tl_(selected_tl),
pbos14fe7082016-04-20 06:35:56 -0700166 pre_encode_proxy_(this),
Peter Boströme4499152016-02-05 11:13:28 +0100167 encode_timing_proxy_(this),
ivica5d6a06c2015-09-17 05:30:24 -0700168 frames_to_process_(duration_frames),
169 frames_recorded_(0),
170 frames_processed_(0),
171 dropped_frames_(0),
pbos14fe7082016-04-20 06:35:56 -0700172 dropped_frames_before_first_encode_(0),
173 dropped_frames_before_rendering_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700174 last_render_time_(0),
175 rtp_timestamp_delta_(0),
ilnik1e7732c2017-02-23 05:07:56 -0800176 total_media_bytes_(0),
177 first_sending_time_(0),
178 last_sending_time_(0),
ilnikdf92c5c2017-02-23 02:08:44 -0800179 cpu_time_(0),
180 wallclock_time_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700181 avg_psnr_threshold_(avg_psnr_threshold),
182 avg_ssim_threshold_(avg_ssim_threshold),
ilnik9ae0d762017-02-15 00:53:12 -0800183 is_quick_test_enabled_(is_quick_test_enabled),
Peter Boström8c38e8b2015-11-26 17:45:47 +0100184 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"),
Peter Boström5811a392015-12-10 13:02:50 +0100185 comparison_available_event_(false, false),
Peter Boströmdd45eb62016-01-19 15:22:32 +0100186 done_(true, false) {
ivica5d6a06c2015-09-17 05:30:24 -0700187 // Create thread pool for CPU-expensive PSNR/SSIM calculations.
188
189 // Try to use about as many threads as cores, but leave kMinCoresLeft alone,
190 // so that we don't accidentally starve "real" worker threads (codec etc).
191 // Also, don't allocate more than kMaxComparisonThreads, even if there are
192 // spare cores.
193
194 uint32_t num_cores = CpuInfo::DetectNumberOfCores();
kwibergaf476c72016-11-28 15:21:39 -0800195 RTC_DCHECK_GE(num_cores, 1);
ivica5d6a06c2015-09-17 05:30:24 -0700196 static const uint32_t kMinCoresLeft = 4;
197 static const uint32_t kMaxComparisonThreads = 8;
198
199 if (num_cores <= kMinCoresLeft) {
200 num_cores = 1;
201 } else {
202 num_cores -= kMinCoresLeft;
203 num_cores = std::min(num_cores, kMaxComparisonThreads);
204 }
205
206 for (uint32_t i = 0; i < num_cores; ++i) {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100207 rtc::PlatformThread* thread =
208 new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer");
209 thread->Start();
210 comparison_thread_pool_.push_back(thread);
ivica5d6a06c2015-09-17 05:30:24 -0700211 }
ivica5d6a06c2015-09-17 05:30:24 -0700212 }
213
214 ~VideoAnalyzer() {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100215 for (rtc::PlatformThread* thread : comparison_thread_pool_) {
216 thread->Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700217 delete thread;
218 }
219 }
220
221 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; }
222
ilnik6b826ef2017-06-16 06:53:48 -0700223 void SetSource(test::VideoCapturer* video_capturer, bool respect_sink_wants) {
224 if (respect_sink_wants)
225 captured_frame_forwarder_.SetSource(video_capturer);
226 rtc::VideoSinkWants wants;
227 video_capturer->AddOrUpdateSink(InputInterface(), wants);
228 }
229
perkja49cbd32016-09-16 07:53:41 -0700230 void SetSendStream(VideoSendStream* stream) {
231 rtc::CritScope lock(&crit_);
232 RTC_DCHECK(!send_stream_);
233 send_stream_ = stream;
234 }
235
philipelfd870db2017-01-23 03:22:15 -0800236 void SetReceiveStream(VideoReceiveStream* stream) {
237 rtc::CritScope lock(&crit_);
238 RTC_DCHECK(!receive_stream_);
239 receive_stream_ = stream;
240 }
241
perkja49cbd32016-09-16 07:53:41 -0700242 rtc::VideoSinkInterface<VideoFrame>* InputInterface() {
243 return &captured_frame_forwarder_;
244 }
245 rtc::VideoSourceInterface<VideoFrame>* OutputInterface() {
246 return &captured_frame_forwarder_;
247 }
248
ivica5d6a06c2015-09-17 05:30:24 -0700249 DeliveryStatus DeliverPacket(MediaType media_type,
250 const uint8_t* packet,
251 size_t length,
252 const PacketTime& packet_time) override {
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700253 // Ignore timestamps of RTCP packets. They're not synchronized with
254 // RTP packet timestamps and so they would confuse wrap_handler_.
255 if (RtpHeaderParser::IsRtcp(packet, length)) {
256 return receiver_->DeliverPacket(media_type, packet, length, packet_time);
257 }
sprangce4aef12015-11-02 07:23:20 -0800258 RtpUtility::RtpHeaderParser parser(packet, length);
ivica5d6a06c2015-09-17 05:30:24 -0700259 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800260 parser.Parse(&header);
ilnik46a00212017-02-10 09:16:05 -0800261 if (!IsFlexfec(header.payloadType) &&
262 (header.ssrc == ssrc_to_analyze_ ||
263 header.ssrc == rtx_ssrc_to_analyze_)) {
brandtr504b95e2016-12-21 02:54:35 -0800264 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
265 // (FlexFEC and media are sent on different SSRCs, which have different
266 // timestamps spaces.)
ilnik46a00212017-02-10 09:16:05 -0800267 // Also ignore packets from wrong SSRC, but include retransmits.
ivica5d6a06c2015-09-17 05:30:24 -0700268 rtc::CritScope lock(&crit_);
sprang16daaa52016-03-09 01:30:24 -0800269 int64_t timestamp =
270 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
271 recv_times_[timestamp] =
ivica5d6a06c2015-09-17 05:30:24 -0700272 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
273 }
274
275 return receiver_->DeliverPacket(media_type, packet, length, packet_time);
276 }
277
Peter Boströme4499152016-02-05 11:13:28 +0100278 void MeasuredEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) {
ivica8d15bd62015-10-07 02:43:12 -0700279 rtc::CritScope crit(&comparison_lock_);
280 samples_encode_time_ms_[ntp_time_ms] = encode_time_ms;
281 }
282
pbos14fe7082016-04-20 06:35:56 -0700283 void PreEncodeOnFrame(const VideoFrame& video_frame) {
284 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800285 if (!first_encoded_timestamp_) {
pbos14fe7082016-04-20 06:35:56 -0700286 while (frames_.front().timestamp() != video_frame.timestamp()) {
287 ++dropped_frames_before_first_encode_;
288 frames_.pop_front();
289 RTC_CHECK(!frames_.empty());
290 }
ilnik3dd5ad92017-02-09 04:58:53 -0800291 first_encoded_timestamp_ =
292 rtc::Optional<uint32_t>(video_frame.timestamp());
293 }
294 }
295
296 void PostEncodeFrameCallback(const EncodedFrame& encoded_frame) {
297 rtc::CritScope lock(&crit_);
298 if (!first_sent_timestamp_ &&
ilnikcb8c1462017-03-09 09:23:30 -0800299 encoded_frame.stream_id_ == selected_stream_) {
ilnik3dd5ad92017-02-09 04:58:53 -0800300 first_sent_timestamp_ = rtc::Optional<uint32_t>(encoded_frame.timestamp_);
pbos14fe7082016-04-20 06:35:56 -0700301 }
302 }
303
stefan1d8a5062015-10-02 03:39:33 -0700304 bool SendRtp(const uint8_t* packet,
305 size_t length,
306 const PacketOptions& options) override {
sprangce4aef12015-11-02 07:23:20 -0800307 RtpUtility::RtpHeaderParser parser(packet, length);
ivica5d6a06c2015-09-17 05:30:24 -0700308 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800309 parser.Parse(&header);
ivica5d6a06c2015-09-17 05:30:24 -0700310
sprangce4aef12015-11-02 07:23:20 -0800311 int64_t current_time =
312 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
ilnik2a8c2f52017-02-15 02:23:28 -0800313
sprangce4aef12015-11-02 07:23:20 -0800314 bool result = transport_->SendRtp(packet, length, options);
ivica5d6a06c2015-09-17 05:30:24 -0700315 {
316 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800317 if (rtp_timestamp_delta_ == 0 && header.ssrc == ssrc_to_analyze_) {
ilnik1e1c84d2017-02-09 08:32:53 -0800318 RTC_CHECK(static_cast<bool>(first_sent_timestamp_));
ilnik3dd5ad92017-02-09 04:58:53 -0800319 rtp_timestamp_delta_ = header.timestamp - *first_sent_timestamp_;
ilnike67c59e2017-02-09 04:08:56 -0800320 }
ilnik3dd5ad92017-02-09 04:58:53 -0800321
322 if (!IsFlexfec(header.payloadType) && header.ssrc == ssrc_to_analyze_) {
brandtr504b95e2016-12-21 02:54:35 -0800323 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
324 // (FlexFEC and media are sent on different SSRCs, which have different
325 // timestamps spaces.)
ilnik46a00212017-02-10 09:16:05 -0800326 // Also ignore packets from wrong SSRC and retransmits.
brandtr504b95e2016-12-21 02:54:35 -0800327 int64_t timestamp =
328 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
329 send_times_[timestamp] = current_time;
ilnik1e7732c2017-02-23 05:07:56 -0800330
331 if (IsInSelectedSpatialAndTemporalLayer(packet, length, header)) {
brandtr504b95e2016-12-21 02:54:35 -0800332 encoded_frame_sizes_[timestamp] +=
333 length - (header.headerLength + header.paddingLength);
ilnik1e7732c2017-02-23 05:07:56 -0800334 total_media_bytes_ +=
335 length - (header.headerLength + header.paddingLength);
brandtr504b95e2016-12-21 02:54:35 -0800336 }
ilnik1e7732c2017-02-23 05:07:56 -0800337 if (first_sending_time_ == 0)
338 first_sending_time_ = current_time;
339 last_sending_time_ = current_time;
sprangce4aef12015-11-02 07:23:20 -0800340 }
ivica5d6a06c2015-09-17 05:30:24 -0700341 }
sprangce4aef12015-11-02 07:23:20 -0800342 return result;
ivica5d6a06c2015-09-17 05:30:24 -0700343 }
344
345 bool SendRtcp(const uint8_t* packet, size_t length) override {
346 return transport_->SendRtcp(packet, length);
347 }
348
nisseeb83a1a2016-03-21 01:27:56 -0700349 void OnFrame(const VideoFrame& video_frame) override {
ivica5d6a06c2015-09-17 05:30:24 -0700350 int64_t render_time_ms =
351 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
ivica5d6a06c2015-09-17 05:30:24 -0700352
353 rtc::CritScope lock(&crit_);
ilnikdf92c5c2017-02-23 02:08:44 -0800354
355 StartExcludingCpuThreadTime();
356
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700357 int64_t send_timestamp =
sprang16daaa52016-03-09 01:30:24 -0800358 wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_);
ivica5d6a06c2015-09-17 05:30:24 -0700359
sprang16daaa52016-03-09 01:30:24 -0800360 while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) {
nisse97f0b932016-05-26 09:44:40 -0700361 if (!last_rendered_frame_) {
pbos14fe7082016-04-20 06:35:56 -0700362 // No previous frame rendered, this one was dropped after sending but
363 // before rendering.
364 ++dropped_frames_before_rendering_;
kthelgason2bc68642017-02-07 07:02:22 -0800365 } else {
366 AddFrameComparison(frames_.front(), *last_rendered_frame_, true,
367 render_time_ms);
pbos14fe7082016-04-20 06:35:56 -0700368 }
ivica5d6a06c2015-09-17 05:30:24 -0700369 frames_.pop_front();
pbos14fe7082016-04-20 06:35:56 -0700370 RTC_DCHECK(!frames_.empty());
ivica5d6a06c2015-09-17 05:30:24 -0700371 }
372
373 VideoFrame reference_frame = frames_.front();
374 frames_.pop_front();
sprang16daaa52016-03-09 01:30:24 -0800375 int64_t reference_timestamp =
376 wrap_handler_.Unwrap(reference_frame.timestamp());
377 if (send_timestamp == reference_timestamp - 1) {
sprangce4aef12015-11-02 07:23:20 -0800378 // TODO(ivica): Make this work for > 2 streams.
Peter Boströme4499152016-02-05 11:13:28 +0100379 // Look at RTPSender::BuildRTPHeader.
sprangce4aef12015-11-02 07:23:20 -0800380 ++send_timestamp;
381 }
sprang16daaa52016-03-09 01:30:24 -0800382 ASSERT_EQ(reference_timestamp, send_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700383
384 AddFrameComparison(reference_frame, video_frame, false, render_time_ms);
385
nisse97f0b932016-05-26 09:44:40 -0700386 last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame);
ilnikdf92c5c2017-02-23 02:08:44 -0800387
388 StopExcludingCpuThreadTime();
ivica5d6a06c2015-09-17 05:30:24 -0700389 }
390
ivica5d6a06c2015-09-17 05:30:24 -0700391 void Wait() {
392 // Frame comparisons can be very expensive. Wait for test to be done, but
393 // at time-out check if frames_processed is going up. If so, give it more
394 // time, otherwise fail. Hopefully this will reduce test flakiness.
395
Peter Boström8c38e8b2015-11-26 17:45:47 +0100396 stats_polling_thread_.Start();
sprangce4aef12015-11-02 07:23:20 -0800397
ivica5d6a06c2015-09-17 05:30:24 -0700398 int last_frames_processed = -1;
ivica5d6a06c2015-09-17 05:30:24 -0700399 int iteration = 0;
Peter Boström5811a392015-12-10 13:02:50 +0100400 while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) {
ivica5d6a06c2015-09-17 05:30:24 -0700401 int frames_processed;
402 {
403 rtc::CritScope crit(&comparison_lock_);
404 frames_processed = frames_processed_;
405 }
406
407 // Print some output so test infrastructure won't think we've crashed.
408 const char* kKeepAliveMessages[3] = {
409 "Uh, I'm-I'm not quite dead, sir.",
410 "Uh, I-I think uh, I could pull through, sir.",
411 "Actually, I think I'm all right to come with you--"};
412 printf("- %s\n", kKeepAliveMessages[iteration++ % 3]);
413
414 if (last_frames_processed == -1) {
415 last_frames_processed = frames_processed;
416 continue;
417 }
Peter Boströmdd45eb62016-01-19 15:22:32 +0100418 if (frames_processed == last_frames_processed) {
419 EXPECT_GT(frames_processed, last_frames_processed)
420 << "Analyzer stalled while waiting for test to finish.";
421 done_.Set();
422 break;
423 }
ivica5d6a06c2015-09-17 05:30:24 -0700424 last_frames_processed = frames_processed;
425 }
426
427 if (iteration > 0)
428 printf("- Farewell, sweet Concorde!\n");
429
Peter Boström8c38e8b2015-11-26 17:45:47 +0100430 stats_polling_thread_.Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700431 }
432
pbos14fe7082016-04-20 06:35:56 -0700433 rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() {
434 return &pre_encode_proxy_;
435 }
Peter Boströme4499152016-02-05 11:13:28 +0100436 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; }
437
ilnikdf92c5c2017-02-23 02:08:44 -0800438 void StartMeasuringCpuProcessTime() {
439 rtc::CritScope lock(&cpu_measurement_lock_);
440 cpu_time_ -= rtc::GetProcessCpuTimeNanos();
441 wallclock_time_ -= rtc::SystemTimeNanos();
442 }
443
444 void StopMeasuringCpuProcessTime() {
445 rtc::CritScope lock(&cpu_measurement_lock_);
446 cpu_time_ += rtc::GetProcessCpuTimeNanos();
447 wallclock_time_ += rtc::SystemTimeNanos();
448 }
449
450 void StartExcludingCpuThreadTime() {
451 rtc::CritScope lock(&cpu_measurement_lock_);
452 cpu_time_ += rtc::GetThreadCpuTimeNanos();
453 }
454
455 void StopExcludingCpuThreadTime() {
456 rtc::CritScope lock(&cpu_measurement_lock_);
457 cpu_time_ -= rtc::GetThreadCpuTimeNanos();
458 }
459
460 double GetCpuUsagePercent() {
461 rtc::CritScope lock(&cpu_measurement_lock_);
462 return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0;
463 }
464
sprangce4aef12015-11-02 07:23:20 -0800465 test::LayerFilteringTransport* const transport_;
ivica5d6a06c2015-09-17 05:30:24 -0700466 PacketReceiver* receiver_;
ivica5d6a06c2015-09-17 05:30:24 -0700467
468 private:
469 struct FrameComparison {
470 FrameComparison()
471 : dropped(false),
nissedf2ceb82016-12-15 06:29:53 -0800472 input_time_ms(0),
ivica5d6a06c2015-09-17 05:30:24 -0700473 send_time_ms(0),
474 recv_time_ms(0),
475 render_time_ms(0),
476 encoded_frame_size(0) {}
477
478 FrameComparison(const VideoFrame& reference,
479 const VideoFrame& render,
480 bool dropped,
nissedf2ceb82016-12-15 06:29:53 -0800481 int64_t input_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700482 int64_t send_time_ms,
483 int64_t recv_time_ms,
484 int64_t render_time_ms,
485 size_t encoded_frame_size)
486 : reference(reference),
487 render(render),
488 dropped(dropped),
nissedf2ceb82016-12-15 06:29:53 -0800489 input_time_ms(input_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700490 send_time_ms(send_time_ms),
491 recv_time_ms(recv_time_ms),
492 render_time_ms(render_time_ms),
493 encoded_frame_size(encoded_frame_size) {}
494
nissedf2ceb82016-12-15 06:29:53 -0800495 FrameComparison(bool dropped,
496 int64_t input_time_ms,
497 int64_t send_time_ms,
498 int64_t recv_time_ms,
499 int64_t render_time_ms,
500 size_t encoded_frame_size)
501 : dropped(dropped),
502 input_time_ms(input_time_ms),
503 send_time_ms(send_time_ms),
504 recv_time_ms(recv_time_ms),
505 render_time_ms(render_time_ms),
506 encoded_frame_size(encoded_frame_size) {}
507
508 rtc::Optional<VideoFrame> reference;
509 rtc::Optional<VideoFrame> render;
ivica5d6a06c2015-09-17 05:30:24 -0700510 bool dropped;
nissedf2ceb82016-12-15 06:29:53 -0800511 int64_t input_time_ms;
ivica5d6a06c2015-09-17 05:30:24 -0700512 int64_t send_time_ms;
513 int64_t recv_time_ms;
514 int64_t render_time_ms;
515 size_t encoded_frame_size;
516 };
517
518 struct Sample {
ivica8d15bd62015-10-07 02:43:12 -0700519 Sample(int dropped,
520 int64_t input_time_ms,
521 int64_t send_time_ms,
522 int64_t recv_time_ms,
523 int64_t render_time_ms,
524 size_t encoded_frame_size,
ivica5d6a06c2015-09-17 05:30:24 -0700525 double psnr,
ivica8d15bd62015-10-07 02:43:12 -0700526 double ssim)
ivica5d6a06c2015-09-17 05:30:24 -0700527 : dropped(dropped),
528 input_time_ms(input_time_ms),
529 send_time_ms(send_time_ms),
530 recv_time_ms(recv_time_ms),
ivica8d15bd62015-10-07 02:43:12 -0700531 render_time_ms(render_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700532 encoded_frame_size(encoded_frame_size),
533 psnr(psnr),
ivica8d15bd62015-10-07 02:43:12 -0700534 ssim(ssim) {}
ivica5d6a06c2015-09-17 05:30:24 -0700535
ivica8d15bd62015-10-07 02:43:12 -0700536 int dropped;
537 int64_t input_time_ms;
538 int64_t send_time_ms;
539 int64_t recv_time_ms;
540 int64_t render_time_ms;
541 size_t encoded_frame_size;
ivica5d6a06c2015-09-17 05:30:24 -0700542 double psnr;
543 double ssim;
ivica5d6a06c2015-09-17 05:30:24 -0700544 };
545
Peter Boströme4499152016-02-05 11:13:28 +0100546 // This class receives the send-side OnEncodeTiming and is provided to not
547 // conflict with the receiver-side pre_decode_callback.
548 class OnEncodeTimingProxy : public EncodedFrameObserver {
549 public:
550 explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {}
551
552 void OnEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) override {
553 parent_->MeasuredEncodeTiming(ntp_time_ms, encode_time_ms);
554 }
ilnik3dd5ad92017-02-09 04:58:53 -0800555 void EncodedFrameCallback(const EncodedFrame& frame) override {
556 parent_->PostEncodeFrameCallback(frame);
557 }
Peter Boströme4499152016-02-05 11:13:28 +0100558
559 private:
560 VideoAnalyzer* const parent_;
561 };
562
pbos14fe7082016-04-20 06:35:56 -0700563 // This class receives the send-side OnFrame callback and is provided to not
564 // conflict with the receiver-side renderer callback.
565 class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> {
566 public:
567 explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {}
568
569 void OnFrame(const VideoFrame& video_frame) override {
570 parent_->PreEncodeOnFrame(video_frame);
571 }
572
573 private:
574 VideoAnalyzer* const parent_;
575 };
576
ilnik1e7732c2017-02-23 05:07:56 -0800577 bool IsInSelectedSpatialAndTemporalLayer(const uint8_t* packet,
578 size_t length,
579 const RTPHeader& header) {
580 if (header.payloadType != kPayloadTypeVP9 &&
581 header.payloadType != kPayloadTypeVP8) {
582 return true;
583 } else {
584 // Get VP8 and VP9 specific header to check layers indexes.
585 const uint8_t* payload = packet + header.headerLength;
586 const size_t payload_length = length - header.headerLength;
587 const size_t payload_data_length = payload_length - header.paddingLength;
588 const bool is_vp8 = header.payloadType == kPayloadTypeVP8;
589 std::unique_ptr<RtpDepacketizer> depacketizer(
590 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9));
591 RtpDepacketizer::ParsedPayload parsed_payload;
592 bool result =
593 depacketizer->Parse(&parsed_payload, payload, payload_data_length);
594 RTC_DCHECK(result);
595 const int temporal_idx = static_cast<int>(
596 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx
597 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx);
598 const int spatial_idx = static_cast<int>(
599 is_vp8 ? kNoSpatialIdx
600 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx);
601 return (selected_tl_ < 0 || temporal_idx == kNoTemporalIdx ||
602 temporal_idx <= selected_tl_) &&
603 (selected_sl_ < 0 || spatial_idx == kNoSpatialIdx ||
604 spatial_idx <= selected_sl_);
605 }
606 }
607
ivica5d6a06c2015-09-17 05:30:24 -0700608 void AddFrameComparison(const VideoFrame& reference,
609 const VideoFrame& render,
610 bool dropped,
611 int64_t render_time_ms)
612 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
sprange1f2f1f2016-02-01 02:04:52 -0800613 int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp());
614 int64_t send_time_ms = send_times_[reference_timestamp];
615 send_times_.erase(reference_timestamp);
616 int64_t recv_time_ms = recv_times_[reference_timestamp];
617 recv_times_.erase(reference_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700618
sprangce4aef12015-11-02 07:23:20 -0800619 // TODO(ivica): Make this work for > 2 streams.
sprange1f2f1f2016-02-01 02:04:52 -0800620 auto it = encoded_frame_sizes_.find(reference_timestamp);
sprangce4aef12015-11-02 07:23:20 -0800621 if (it == encoded_frame_sizes_.end())
sprange1f2f1f2016-02-01 02:04:52 -0800622 it = encoded_frame_sizes_.find(reference_timestamp - 1);
sprangce4aef12015-11-02 07:23:20 -0800623 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second;
624 if (it != encoded_frame_sizes_.end())
625 encoded_frame_sizes_.erase(it);
ivica5d6a06c2015-09-17 05:30:24 -0700626
ivica5d6a06c2015-09-17 05:30:24 -0700627 rtc::CritScope crit(&comparison_lock_);
stefanb1797672016-08-11 07:00:57 -0700628 if (comparisons_.size() < kMaxComparisons) {
nissedf2ceb82016-12-15 06:29:53 -0800629 comparisons_.push_back(FrameComparison(reference, render, dropped,
630 reference.ntp_time_ms(),
631 send_time_ms, recv_time_ms,
632 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700633 } else {
nissedf2ceb82016-12-15 06:29:53 -0800634 comparisons_.push_back(FrameComparison(dropped,
635 reference.ntp_time_ms(),
636 send_time_ms, recv_time_ms,
637 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700638 }
Peter Boström5811a392015-12-10 13:02:50 +0100639 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700640 }
641
tommi0f8b4032017-02-22 11:22:05 -0800642 static void PollStatsThread(void* obj) {
643 static_cast<VideoAnalyzer*>(obj)->PollStats();
ivica5d6a06c2015-09-17 05:30:24 -0700644 }
645
tommi0f8b4032017-02-22 11:22:05 -0800646 void PollStats() {
647 while (!done_.Wait(kSendStatsPollingIntervalMs)) {
648 rtc::CritScope crit(&comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700649
tommi0f8b4032017-02-22 11:22:05 -0800650 VideoSendStream::Stats send_stats = send_stream_->GetStats();
651 // It's not certain that we yet have estimates for any of these stats.
652 // Check that they are positive before mixing them in.
653 if (send_stats.encode_frame_rate > 0)
654 encode_frame_rate_.AddSample(send_stats.encode_frame_rate);
655 if (send_stats.avg_encode_time_ms > 0)
656 encode_time_ms_.AddSample(send_stats.avg_encode_time_ms);
657 if (send_stats.encode_usage_percent > 0)
658 encode_usage_percent_.AddSample(send_stats.encode_usage_percent);
659 if (send_stats.media_bitrate_bps > 0)
660 media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps);
philipelfd870db2017-01-23 03:22:15 -0800661
tommi0f8b4032017-02-22 11:22:05 -0800662 if (receive_stream_ != nullptr) {
663 VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats();
664 if (receive_stats.decode_ms > 0)
665 decode_time_ms_.AddSample(receive_stats.decode_ms);
666 if (receive_stats.max_decode_ms > 0)
667 decode_time_max_ms_.AddSample(receive_stats.max_decode_ms);
668 }
ilnikdaa574d2017-03-01 06:46:05 -0800669
670 memory_usage_.AddSample(rtc::GetProcessResidentSizeBytes());
philipelfd870db2017-01-23 03:22:15 -0800671 }
ivica5d6a06c2015-09-17 05:30:24 -0700672 }
673
674 static bool FrameComparisonThread(void* obj) {
675 return static_cast<VideoAnalyzer*>(obj)->CompareFrames();
676 }
677
678 bool CompareFrames() {
679 if (AllFramesRecorded())
680 return false;
681
ivica5d6a06c2015-09-17 05:30:24 -0700682 FrameComparison comparison;
683
684 if (!PopComparison(&comparison)) {
685 // Wait until new comparison task is available, or test is done.
686 // If done, wake up remaining threads waiting.
Peter Boström5811a392015-12-10 13:02:50 +0100687 comparison_available_event_.Wait(1000);
ivica5d6a06c2015-09-17 05:30:24 -0700688 if (AllFramesRecorded()) {
Peter Boström5811a392015-12-10 13:02:50 +0100689 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700690 return false;
691 }
692 return true; // Try again.
693 }
694
ilnikdf92c5c2017-02-23 02:08:44 -0800695 StartExcludingCpuThreadTime();
696
ivica5d6a06c2015-09-17 05:30:24 -0700697 PerformFrameComparison(comparison);
698
ilnikdf92c5c2017-02-23 02:08:44 -0800699 StopExcludingCpuThreadTime();
700
ivica5d6a06c2015-09-17 05:30:24 -0700701 if (FrameProcessed()) {
702 PrintResults();
703 if (graph_data_output_file_)
704 PrintSamplesToFile();
Peter Boström5811a392015-12-10 13:02:50 +0100705 done_.Set();
706 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700707 return false;
708 }
709
710 return true;
711 }
712
713 bool PopComparison(FrameComparison* comparison) {
714 rtc::CritScope crit(&comparison_lock_);
715 // If AllFramesRecorded() is true, it means we have already popped
716 // frames_to_process_ frames from comparisons_, so there is no more work
717 // for this thread to be done. frames_processed_ might still be lower if
718 // all comparisons are not done, but those frames are currently being
719 // worked on by other threads.
720 if (comparisons_.empty() || AllFramesRecorded())
721 return false;
722
723 *comparison = comparisons_.front();
724 comparisons_.pop_front();
725
726 FrameRecorded();
727 return true;
728 }
729
730 // Increment counter for number of frames received for comparison.
731 void FrameRecorded() {
732 rtc::CritScope crit(&comparison_lock_);
733 ++frames_recorded_;
734 }
735
736 // Returns true if all frames to be compared have been taken from the queue.
737 bool AllFramesRecorded() {
738 rtc::CritScope crit(&comparison_lock_);
739 assert(frames_recorded_ <= frames_to_process_);
740 return frames_recorded_ == frames_to_process_;
741 }
742
743 // Increase count of number of frames processed. Returns true if this was the
744 // last frame to be processed.
745 bool FrameProcessed() {
746 rtc::CritScope crit(&comparison_lock_);
747 ++frames_processed_;
748 assert(frames_processed_ <= frames_to_process_);
749 return frames_processed_ == frames_to_process_;
750 }
751
752 void PrintResults() {
ilnikdf92c5c2017-02-23 02:08:44 -0800753 StopMeasuringCpuProcessTime();
ivica5d6a06c2015-09-17 05:30:24 -0700754 rtc::CritScope crit(&comparison_lock_);
755 PrintResult("psnr", psnr_, " dB");
tnakamura3123cbc2016-02-10 11:21:51 -0800756 PrintResult("ssim", ssim_, " score");
stefan2da7a242017-03-30 01:02:15 -0700757 PrintResult("sender_time", sender_time_, " ms");
758 PrintResult("receiver_time", receiver_time_, " ms");
ivica5d6a06c2015-09-17 05:30:24 -0700759 PrintResult("total_delay_incl_network", end_to_end_, " ms");
760 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
ivica5d6a06c2015-09-17 05:30:24 -0700761 PrintResult("encode_frame_rate", encode_frame_rate_, " fps");
philipelfd870db2017-01-23 03:22:15 -0800762 PrintResult("encode_time", encode_time_ms_, " ms");
philipelfd870db2017-01-23 03:22:15 -0800763 PrintResult("media_bitrate", media_bitrate_bps_, " bps");
764
765 if (receive_stream_ != nullptr) {
766 PrintResult("decode_time", decode_time_ms_, " ms");
philipelfd870db2017-01-23 03:22:15 -0800767 }
ivica5d6a06c2015-09-17 05:30:24 -0700768
pbos14fe7082016-04-20 06:35:56 -0700769 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(),
770 dropped_frames_);
ilnikdf92c5c2017-02-23 02:08:44 -0800771 printf("RESULT cpu_usage: %s = %lf %%\n", test_label_.c_str(),
772 GetCpuUsagePercent());
ilnikdaa574d2017-03-01 06:46:05 -0800773
774#if defined(WEBRTC_WIN)
775 // On Linux and Mac in Resident Set some unused pages may be counted.
776 // Therefore this metric will depend on order in which tests are run and
777 // will be flaky.
778 PrintResult("memory_usage", memory_usage_, " bytes");
779#endif
780
ilnik9ae0d762017-02-15 00:53:12 -0800781 // Disable quality check for quick test, as quality checks may fail
782 // because too few samples were collected.
783 if (!is_quick_test_enabled_) {
784 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
785 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_);
786 }
ivica5d6a06c2015-09-17 05:30:24 -0700787 }
788
789 void PerformFrameComparison(const FrameComparison& comparison) {
790 // Perform expensive psnr and ssim calculations while not holding lock.
stefanb1797672016-08-11 07:00:57 -0700791 double psnr = -1.0;
792 double ssim = -1.0;
ilnik6b826ef2017-06-16 06:53:48 -0700793 if (comparison.reference && !comparison.dropped) {
nissedf2ceb82016-12-15 06:29:53 -0800794 psnr = I420PSNR(&*comparison.reference, &*comparison.render);
795 ssim = I420SSIM(&*comparison.reference, &*comparison.render);
stefanb1797672016-08-11 07:00:57 -0700796 }
ivica5d6a06c2015-09-17 05:30:24 -0700797
ivica5d6a06c2015-09-17 05:30:24 -0700798 rtc::CritScope crit(&comparison_lock_);
799 if (graph_data_output_file_) {
nissedf2ceb82016-12-15 06:29:53 -0800800 samples_.push_back(Sample(
801 comparison.dropped, comparison.input_time_ms, comparison.send_time_ms,
802 comparison.recv_time_ms, comparison.render_time_ms,
803 comparison.encoded_frame_size, psnr, ssim));
ivica5d6a06c2015-09-17 05:30:24 -0700804 }
stefanb1797672016-08-11 07:00:57 -0700805 if (psnr >= 0.0)
806 psnr_.AddSample(psnr);
807 if (ssim >= 0.0)
808 ssim_.AddSample(ssim);
ivica5d6a06c2015-09-17 05:30:24 -0700809
810 if (comparison.dropped) {
811 ++dropped_frames_;
812 return;
813 }
814 if (last_render_time_ != 0)
815 rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_);
816 last_render_time_ = comparison.render_time_ms;
817
nissedf2ceb82016-12-15 06:29:53 -0800818 sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms);
brandtr504b95e2016-12-21 02:54:35 -0800819 if (comparison.recv_time_ms > 0) {
820 // If recv_time_ms == 0, this frame consisted of a packets which were all
821 // lost in the transport. Since we were able to render the frame, however,
822 // the dropped packets were recovered by FlexFEC. The FlexFEC recovery
823 // happens internally in Call, and we can therefore here not know which
824 // FEC packets that protected the lost media packets. Consequently, we
825 // were not able to record a meaningful recv_time_ms. We therefore skip
826 // this sample.
827 //
828 // The reasoning above does not hold for ULPFEC and RTX, as for those
829 // strategies the timestamp of the received packets is set to the
830 // timestamp of the protected/retransmitted media packet. I.e., then
831 // recv_time_ms != 0, even though the media packets were lost.
832 receiver_time_.AddSample(comparison.render_time_ms -
833 comparison.recv_time_ms);
834 }
nissedf2ceb82016-12-15 06:29:53 -0800835 end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms);
ivica5d6a06c2015-09-17 05:30:24 -0700836 encoded_frame_size_.AddSample(comparison.encoded_frame_size);
837 }
838
839 void PrintResult(const char* result_type,
840 test::Statistics stats,
841 const char* unit) {
842 printf("RESULT %s: %s = {%f, %f}%s\n",
843 result_type,
844 test_label_.c_str(),
845 stats.Mean(),
846 stats.StandardDeviation(),
847 unit);
848 }
849
850 void PrintSamplesToFile(void) {
851 FILE* out = graph_data_output_file_;
852 rtc::CritScope crit(&comparison_lock_);
853 std::sort(samples_.begin(), samples_.end(),
854 [](const Sample& A, const Sample& B) -> bool {
855 return A.input_time_ms < B.input_time_ms;
856 });
857
sprangce4aef12015-11-02 07:23:20 -0800858 fprintf(out, "%s\n", graph_title_.c_str());
ivica5d6a06c2015-09-17 05:30:24 -0700859 fprintf(out, "%" PRIuS "\n", samples_.size());
860 fprintf(out,
861 "dropped "
862 "input_time_ms "
863 "send_time_ms "
864 "recv_time_ms "
ivica8d15bd62015-10-07 02:43:12 -0700865 "render_time_ms "
ivica5d6a06c2015-09-17 05:30:24 -0700866 "encoded_frame_size "
867 "psnr "
868 "ssim "
ivica8d15bd62015-10-07 02:43:12 -0700869 "encode_time_ms\n");
870 int missing_encode_time_samples = 0;
ivica5d6a06c2015-09-17 05:30:24 -0700871 for (const Sample& sample : samples_) {
ivica8d15bd62015-10-07 02:43:12 -0700872 auto it = samples_encode_time_ms_.find(sample.input_time_ms);
873 int encode_time_ms;
874 if (it != samples_encode_time_ms_.end()) {
875 encode_time_ms = it->second;
876 } else {
877 ++missing_encode_time_samples;
878 encode_time_ms = -1;
879 }
880 fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS
881 " %lf %lf %d\n",
882 sample.dropped, sample.input_time_ms, sample.send_time_ms,
883 sample.recv_time_ms, sample.render_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700884 sample.encoded_frame_size, sample.psnr, sample.ssim,
ivica8d15bd62015-10-07 02:43:12 -0700885 encode_time_ms);
886 }
887 if (missing_encode_time_samples) {
888 fprintf(stderr,
889 "Warning: Missing encode_time_ms samples for %d frame(s).\n",
890 missing_encode_time_samples);
ivica5d6a06c2015-09-17 05:30:24 -0700891 }
892 }
893
ilnik1e7732c2017-02-23 05:07:56 -0800894 double GetAverageMediaBitrateBps() {
895 if (last_sending_time_ == first_sending_time_) {
896 return 0;
897 } else {
898 return static_cast<double>(total_media_bytes_) * 8 /
899 (last_sending_time_ - first_sending_time_) *
900 rtc::kNumMillisecsPerSec;
901 }
902 }
903
perkja49cbd32016-09-16 07:53:41 -0700904 // Implements VideoSinkInterface to receive captured frames from a
905 // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act
906 // as a source to VideoSendStream.
907 // It forwards all input frames to the VideoAnalyzer for later comparison and
908 // forwards the captured frames to the VideoSendStream.
909 class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>,
910 public rtc::VideoSourceInterface<VideoFrame> {
911 public:
ilnik6b826ef2017-06-16 06:53:48 -0700912 explicit CapturedFrameForwarder(VideoAnalyzer* analyzer, Clock* clock)
913 : analyzer_(analyzer),
914 send_stream_input_(nullptr),
915 video_capturer_(nullptr),
916 clock_(clock) {}
917
918 void SetSource(test::VideoCapturer* video_capturer) {
919 video_capturer_ = video_capturer;
920 }
perkja49cbd32016-09-16 07:53:41 -0700921
922 private:
923 void OnFrame(const VideoFrame& video_frame) override {
924 VideoFrame copy = video_frame;
ilnik3dd5ad92017-02-09 04:58:53 -0800925 // Frames from the capturer does not have a rtp timestamp.
926 // Create one so it can be used for comparison.
927 RTC_DCHECK_EQ(0, video_frame.timestamp());
ilnik6b826ef2017-06-16 06:53:48 -0700928 if (video_frame.ntp_time_ms() == 0)
929 copy.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
perkja49cbd32016-09-16 07:53:41 -0700930 copy.set_timestamp(copy.ntp_time_ms() * 90);
ilnik3dd5ad92017-02-09 04:58:53 -0800931 analyzer_->AddCapturedFrameForComparison(copy);
perkja49cbd32016-09-16 07:53:41 -0700932 rtc::CritScope lock(&crit_);
933 if (send_stream_input_)
ilnikb82ac6a2017-05-02 00:48:41 -0700934 send_stream_input_->OnFrame(copy);
perkja49cbd32016-09-16 07:53:41 -0700935 }
936
937 // Called when |send_stream_.SetSource()| is called.
938 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
939 const rtc::VideoSinkWants& wants) override {
940 rtc::CritScope lock(&crit_);
941 RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
942 send_stream_input_ = sink;
ilnik6b826ef2017-06-16 06:53:48 -0700943 if (video_capturer_) {
944 video_capturer_->AddOrUpdateSink(this, wants);
945 }
perkja49cbd32016-09-16 07:53:41 -0700946 }
947
948 // Called by |send_stream_| when |send_stream_.SetSource()| is called.
949 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {
950 rtc::CritScope lock(&crit_);
951 RTC_DCHECK(sink == send_stream_input_);
952 send_stream_input_ = nullptr;
953 }
954
955 VideoAnalyzer* const analyzer_;
956 rtc::CriticalSection crit_;
957 rtc::VideoSinkInterface<VideoFrame>* send_stream_input_ GUARDED_BY(crit_);
ilnik6b826ef2017-06-16 06:53:48 -0700958 test::VideoCapturer* video_capturer_;
959 Clock* clock_;
perkja49cbd32016-09-16 07:53:41 -0700960 };
961
962 void AddCapturedFrameForComparison(const VideoFrame& video_frame) {
963 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800964 frames_.push_back(video_frame);
perkja49cbd32016-09-16 07:53:41 -0700965 }
966
967 VideoSendStream* send_stream_;
philipelfd870db2017-01-23 03:22:15 -0800968 VideoReceiveStream* receive_stream_;
perkja49cbd32016-09-16 07:53:41 -0700969 CapturedFrameForwarder captured_frame_forwarder_;
ivica5d6a06c2015-09-17 05:30:24 -0700970 const std::string test_label_;
971 FILE* const graph_data_output_file_;
sprangce4aef12015-11-02 07:23:20 -0800972 const std::string graph_title_;
973 const uint32_t ssrc_to_analyze_;
ilnik46a00212017-02-10 09:16:05 -0800974 const uint32_t rtx_ssrc_to_analyze_;
ilnikcb8c1462017-03-09 09:23:30 -0800975 const size_t selected_stream_;
ilnik1e7732c2017-02-23 05:07:56 -0800976 const int selected_sl_;
977 const int selected_tl_;
pbos14fe7082016-04-20 06:35:56 -0700978 PreEncodeProxy pre_encode_proxy_;
Peter Boströme4499152016-02-05 11:13:28 +0100979 OnEncodeTimingProxy encode_timing_proxy_;
ivica5d6a06c2015-09-17 05:30:24 -0700980 std::vector<Sample> samples_ GUARDED_BY(comparison_lock_);
ivica8d15bd62015-10-07 02:43:12 -0700981 std::map<int64_t, int> samples_encode_time_ms_ GUARDED_BY(comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700982 test::Statistics sender_time_ GUARDED_BY(comparison_lock_);
983 test::Statistics receiver_time_ GUARDED_BY(comparison_lock_);
984 test::Statistics psnr_ GUARDED_BY(comparison_lock_);
985 test::Statistics ssim_ GUARDED_BY(comparison_lock_);
986 test::Statistics end_to_end_ GUARDED_BY(comparison_lock_);
987 test::Statistics rendered_delta_ GUARDED_BY(comparison_lock_);
988 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_);
989 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_);
philipelfd870db2017-01-23 03:22:15 -0800990 test::Statistics encode_time_ms_ GUARDED_BY(comparison_lock_);
991 test::Statistics encode_usage_percent_ GUARDED_BY(comparison_lock_);
992 test::Statistics decode_time_ms_ GUARDED_BY(comparison_lock_);
993 test::Statistics decode_time_max_ms_ GUARDED_BY(comparison_lock_);
994 test::Statistics media_bitrate_bps_ GUARDED_BY(comparison_lock_);
ilnikdaa574d2017-03-01 06:46:05 -0800995 test::Statistics memory_usage_ GUARDED_BY(comparison_lock_);
996
ivica5d6a06c2015-09-17 05:30:24 -0700997
998 const int frames_to_process_;
999 int frames_recorded_;
1000 int frames_processed_;
1001 int dropped_frames_;
pbos14fe7082016-04-20 06:35:56 -07001002 int dropped_frames_before_first_encode_;
1003 int dropped_frames_before_rendering_;
ivica5d6a06c2015-09-17 05:30:24 -07001004 int64_t last_render_time_;
1005 uint32_t rtp_timestamp_delta_;
ilnik1e7732c2017-02-23 05:07:56 -08001006 int64_t total_media_bytes_;
1007 int64_t first_sending_time_;
1008 int64_t last_sending_time_;
ivica5d6a06c2015-09-17 05:30:24 -07001009
ilnikdf92c5c2017-02-23 02:08:44 -08001010 int64_t cpu_time_ GUARDED_BY(cpu_measurement_lock_);
1011 int64_t wallclock_time_ GUARDED_BY(cpu_measurement_lock_);
1012 rtc::CriticalSection cpu_measurement_lock_;
1013
ivica5d6a06c2015-09-17 05:30:24 -07001014 rtc::CriticalSection crit_;
1015 std::deque<VideoFrame> frames_ GUARDED_BY(crit_);
nisse97f0b932016-05-26 09:44:40 -07001016 rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_);
sprange1f2f1f2016-02-01 02:04:52 -08001017 rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_);
1018 std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_);
1019 std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_);
1020 std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_);
ilnik3dd5ad92017-02-09 04:58:53 -08001021 rtc::Optional<uint32_t> first_encoded_timestamp_ GUARDED_BY(crit_);
1022 rtc::Optional<uint32_t> first_sent_timestamp_ GUARDED_BY(crit_);
ivica5d6a06c2015-09-17 05:30:24 -07001023 const double avg_psnr_threshold_;
1024 const double avg_ssim_threshold_;
ilnik9ae0d762017-02-15 00:53:12 -08001025 bool is_quick_test_enabled_;
ivica5d6a06c2015-09-17 05:30:24 -07001026
1027 rtc::CriticalSection comparison_lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +01001028 std::vector<rtc::PlatformThread*> comparison_thread_pool_;
1029 rtc::PlatformThread stats_polling_thread_;
Peter Boström5811a392015-12-10 13:02:50 +01001030 rtc::Event comparison_available_event_;
ivica5d6a06c2015-09-17 05:30:24 -07001031 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);
Peter Boström5811a392015-12-10 13:02:50 +01001032 rtc::Event done_;
ivica5d6a06c2015-09-17 05:30:24 -07001033};
1034
ilnikcb8c1462017-03-09 09:23:30 -08001035class Vp8EncoderFactory : public VideoEncoderFactory {
1036 public:
1037 Vp8EncoderFactory() = default;
1038 ~Vp8EncoderFactory() override { RTC_CHECK(live_encoders_.empty()); }
1039
1040 VideoEncoder* Create() override {
1041 VideoEncoder* encoder = VP8Encoder::Create();
1042 live_encoders_.insert(encoder);
1043 return encoder;
1044 }
1045
1046 void Destroy(VideoEncoder* encoder) override {
1047 auto it = live_encoders_.find(encoder);
1048 RTC_CHECK(it != live_encoders_.end());
1049 live_encoders_.erase(it);
1050 delete encoder;
1051 }
1052
1053 std::set<VideoEncoder*> live_encoders_;
1054};
1055
palmkviste75f2042016-09-28 06:19:48 -07001056VideoQualityTest::VideoQualityTest()
minyue20c84cc2017-04-10 16:57:57 -07001057 : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) {
1058 payload_type_map_ = test::CallTest::payload_type_map_;
1059 RTC_DCHECK(payload_type_map_.find(kPayloadTypeH264) ==
1060 payload_type_map_.end());
1061 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP8) ==
1062 payload_type_map_.end());
1063 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP9) ==
1064 payload_type_map_.end());
1065 payload_type_map_[kPayloadTypeH264] = webrtc::MediaType::VIDEO;
1066 payload_type_map_[kPayloadTypeVP8] = webrtc::MediaType::VIDEO;
1067 payload_type_map_[kPayloadTypeVP9] = webrtc::MediaType::VIDEO;
1068}
ivica5d6a06c2015-09-17 05:30:24 -07001069
minyue626bc952016-10-31 05:47:02 -07001070VideoQualityTest::Params::Params()
1071 : call({false, Call::Config::BitrateConfig()}),
1072 video({false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false,
brandtr1293aca2016-11-16 22:47:29 -08001073 false, "", ""}),
minyue4c8b9422017-03-21 04:11:43 -07001074 audio({false, false, false}),
minyue626bc952016-10-31 05:47:02 -07001075 screenshare({false, 10, 0}),
1076 analyzer({"", 0.0, 0.0, 0, "", ""}),
1077 pipe(),
1078 logs(false),
ilnika014cc52017-03-07 04:21:04 -08001079 ss({std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}),
1080 num_thumbnails(0) {}
minyue626bc952016-10-31 05:47:02 -07001081
1082VideoQualityTest::Params::~Params() = default;
1083
ivica5d6a06c2015-09-17 05:30:24 -07001084void VideoQualityTest::TestBody() {}
1085
sprangce4aef12015-11-02 07:23:20 -08001086std::string VideoQualityTest::GenerateGraphTitle() const {
1087 std::stringstream ss;
minyue626bc952016-10-31 05:47:02 -07001088 ss << params_.video.codec;
1089 ss << " (" << params_.video.target_bitrate_bps / 1000 << "kbps";
1090 ss << ", " << params_.video.fps << " FPS";
sprangce4aef12015-11-02 07:23:20 -08001091 if (params_.screenshare.scroll_duration)
1092 ss << ", " << params_.screenshare.scroll_duration << "s scroll";
1093 if (params_.ss.streams.size() > 1)
1094 ss << ", Stream #" << params_.ss.selected_stream;
1095 if (params_.ss.num_spatial_layers > 1)
1096 ss << ", Layer #" << params_.ss.selected_sl;
1097 ss << ")";
1098 return ss.str();
1099}
1100
1101void VideoQualityTest::CheckParams() {
stefan7de8d642017-02-07 07:14:08 -08001102 if (!params_.video.enabled)
1103 return;
sprangce4aef12015-11-02 07:23:20 -08001104 // Add a default stream in none specified.
1105 if (params_.ss.streams.empty())
1106 params_.ss.streams.push_back(VideoQualityTest::DefaultVideoStream(params_));
1107 if (params_.ss.num_spatial_layers == 0)
1108 params_.ss.num_spatial_layers = 1;
1109
1110 if (params_.pipe.loss_percent != 0 ||
1111 params_.pipe.queue_length_packets != 0) {
1112 // Since LayerFilteringTransport changes the sequence numbers, we can't
1113 // use that feature with pack loss, since the NACK request would end up
1114 // retransmitting the wrong packets.
1115 RTC_CHECK(params_.ss.selected_sl == -1 ||
sprangee37de32015-11-23 06:10:23 -08001116 params_.ss.selected_sl == params_.ss.num_spatial_layers - 1);
minyue626bc952016-10-31 05:47:02 -07001117 RTC_CHECK(params_.video.selected_tl == -1 ||
1118 params_.video.selected_tl ==
1119 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -08001120 }
1121
1122 // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as it
1123 // does in some parts of the code?
minyue626bc952016-10-31 05:47:02 -07001124 RTC_CHECK_GE(params_.video.max_bitrate_bps, params_.video.target_bitrate_bps);
1125 RTC_CHECK_GE(params_.video.target_bitrate_bps, params_.video.min_bitrate_bps);
1126 RTC_CHECK_LT(params_.video.selected_tl, params_.video.num_temporal_layers);
sprangce4aef12015-11-02 07:23:20 -08001127 RTC_CHECK_LT(params_.ss.selected_stream, params_.ss.streams.size());
1128 for (const VideoStream& stream : params_.ss.streams) {
1129 RTC_CHECK_GE(stream.min_bitrate_bps, 0);
1130 RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps);
1131 RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps);
ilnikcb8c1462017-03-09 09:23:30 -08001132 RTC_CHECK_LE(stream.temporal_layer_thresholds_bps.size(),
minyue626bc952016-10-31 05:47:02 -07001133 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -08001134 }
1135 // TODO(ivica): Should we check if the sum of all streams/layers is equal to
1136 // the total bitrate? We anyway have to update them in the case bitrate
1137 // estimator changes the total bitrates.
1138 RTC_CHECK_GE(params_.ss.num_spatial_layers, 1);
1139 RTC_CHECK_LE(params_.ss.selected_sl, params_.ss.num_spatial_layers);
1140 RTC_CHECK(params_.ss.spatial_layers.empty() ||
1141 params_.ss.spatial_layers.size() ==
1142 static_cast<size_t>(params_.ss.num_spatial_layers));
minyue626bc952016-10-31 05:47:02 -07001143 if (params_.video.codec == "VP8") {
sprangce4aef12015-11-02 07:23:20 -08001144 RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1);
minyue626bc952016-10-31 05:47:02 -07001145 } else if (params_.video.codec == "VP9") {
kwibergaf476c72016-11-28 15:21:39 -08001146 RTC_CHECK_EQ(params_.ss.streams.size(), 1);
sprangce4aef12015-11-02 07:23:20 -08001147 }
ilnika014cc52017-03-07 04:21:04 -08001148 RTC_CHECK_GE(params_.num_thumbnails, 0);
1149 if (params_.num_thumbnails > 0) {
1150 RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1);
1151 RTC_CHECK_EQ(params_.ss.streams.size(), 3);
1152 RTC_CHECK_EQ(params_.video.num_temporal_layers, 3);
1153 RTC_CHECK_EQ(params_.video.codec, "VP8");
1154 }
sprangce4aef12015-11-02 07:23:20 -08001155}
1156
1157// Static.
1158std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) {
1159 // Parse comma separated nonnegative integers, where some elements may be
1160 // empty. The empty values are replaced with -1.
1161 // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40}
1162 // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1}
1163 std::vector<int> result;
1164 if (str.empty())
1165 return result;
1166
1167 const char* p = str.c_str();
1168 int value = -1;
1169 int pos;
1170 while (*p) {
1171 if (*p == ',') {
1172 result.push_back(value);
1173 value = -1;
1174 ++p;
1175 continue;
1176 }
1177 RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1)
1178 << "Unexpected non-number value.";
1179 p += pos;
1180 }
1181 result.push_back(value);
1182 return result;
1183}
1184
1185// Static.
1186VideoStream VideoQualityTest::DefaultVideoStream(const Params& params) {
1187 VideoStream stream;
minyue626bc952016-10-31 05:47:02 -07001188 stream.width = params.video.width;
1189 stream.height = params.video.height;
1190 stream.max_framerate = params.video.fps;
1191 stream.min_bitrate_bps = params.video.min_bitrate_bps;
1192 stream.target_bitrate_bps = params.video.target_bitrate_bps;
1193 stream.max_bitrate_bps = params.video.max_bitrate_bps;
sprang67561a62017-06-15 06:34:42 -07001194 stream.max_qp = cricket::WebRtcVideoChannel::kDefaultQpMax;
sprang6ef1b342017-03-13 02:01:32 -07001195 // TODO(sprang): Can we make this less of a hack?
1196 if (params.video.num_temporal_layers == 2) {
1197 stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps);
1198 } else if (params.video.num_temporal_layers == 3) {
1199 stream.temporal_layer_thresholds_bps.push_back(stream.max_bitrate_bps / 4);
1200 stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps);
ilnika014cc52017-03-07 04:21:04 -08001201 }
1202 return stream;
1203}
1204
1205// Static.
1206VideoStream VideoQualityTest::DefaultThumbnailStream() {
1207 VideoStream stream;
1208 stream.width = 320;
1209 stream.height = 180;
1210 stream.max_framerate = 7;
1211 stream.min_bitrate_bps = 7500;
1212 stream.target_bitrate_bps = 37500;
1213 stream.max_bitrate_bps = 50000;
sprang67561a62017-06-15 06:34:42 -07001214 stream.max_qp = cricket::WebRtcVideoChannel::kDefaultQpMax;
sprangce4aef12015-11-02 07:23:20 -08001215 return stream;
1216}
1217
1218// Static.
1219void VideoQualityTest::FillScalabilitySettings(
1220 Params* params,
1221 const std::vector<std::string>& stream_descriptors,
1222 size_t selected_stream,
1223 int num_spatial_layers,
1224 int selected_sl,
1225 const std::vector<std::string>& sl_descriptors) {
1226 // Read VideoStream and SpatialLayer elements from a list of comma separated
1227 // lists. To use a default value for an element, use -1 or leave empty.
1228 // Validity checks performed in CheckParams.
1229
1230 RTC_CHECK(params->ss.streams.empty());
1231 for (auto descriptor : stream_descriptors) {
1232 if (descriptor.empty())
1233 continue;
1234 VideoStream stream = VideoQualityTest::DefaultVideoStream(*params);
1235 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1236 if (v[0] != -1)
1237 stream.width = static_cast<size_t>(v[0]);
1238 if (v[1] != -1)
1239 stream.height = static_cast<size_t>(v[1]);
1240 if (v[2] != -1)
1241 stream.max_framerate = v[2];
1242 if (v[3] != -1)
1243 stream.min_bitrate_bps = v[3];
1244 if (v[4] != -1)
1245 stream.target_bitrate_bps = v[4];
1246 if (v[5] != -1)
1247 stream.max_bitrate_bps = v[5];
1248 if (v.size() > 6 && v[6] != -1)
1249 stream.max_qp = v[6];
1250 if (v.size() > 7) {
1251 stream.temporal_layer_thresholds_bps.clear();
1252 stream.temporal_layer_thresholds_bps.insert(
1253 stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end());
1254 } else {
1255 // Automatic TL thresholds for more than two layers not supported.
minyue626bc952016-10-31 05:47:02 -07001256 RTC_CHECK_LE(params->video.num_temporal_layers, 2);
sprangce4aef12015-11-02 07:23:20 -08001257 }
1258 params->ss.streams.push_back(stream);
1259 }
1260 params->ss.selected_stream = selected_stream;
ilnik6b826ef2017-06-16 06:53:48 -07001261 params->ss.infer_streams = false;
sprangce4aef12015-11-02 07:23:20 -08001262
1263 params->ss.num_spatial_layers = num_spatial_layers ? num_spatial_layers : 1;
1264 params->ss.selected_sl = selected_sl;
1265 RTC_CHECK(params->ss.spatial_layers.empty());
1266 for (auto descriptor : sl_descriptors) {
1267 if (descriptor.empty())
1268 continue;
1269 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1270 RTC_CHECK_GT(v[2], 0);
1271
1272 SpatialLayer layer;
1273 layer.scaling_factor_num = v[0] == -1 ? 1 : v[0];
1274 layer.scaling_factor_den = v[1] == -1 ? 1 : v[1];
1275 layer.target_bitrate_bps = v[2];
1276 params->ss.spatial_layers.push_back(layer);
1277 }
1278}
1279
minyuea27172d2016-11-01 05:59:29 -07001280void VideoQualityTest::SetupVideo(Transport* send_transport,
1281 Transport* recv_transport) {
sprangce4aef12015-11-02 07:23:20 -08001282 if (params_.logs)
ivica5d6a06c2015-09-17 05:30:24 -07001283 trace_to_stderr_.reset(new test::TraceToStderr);
1284
brandtr8313a6f2017-01-13 07:41:19 -08001285 size_t num_video_streams = params_.ss.streams.size();
1286 size_t num_flexfec_streams = params_.video.flexfec ? 1 : 0;
1287 CreateSendConfig(num_video_streams, 0, num_flexfec_streams, send_transport);
ivica5d6a06c2015-09-17 05:30:24 -07001288
1289 int payload_type;
minyue626bc952016-10-31 05:47:02 -07001290 if (params_.video.codec == "H264") {
magjedceecea42016-11-28 07:20:21 -08001291 video_encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264")));
hbosbab934b2016-01-27 01:36:03 -08001292 payload_type = kPayloadTypeH264;
minyue626bc952016-10-31 05:47:02 -07001293 } else if (params_.video.codec == "VP8") {
ilnikcb8c1462017-03-09 09:23:30 -08001294 if (params_.screenshare.enabled && params_.ss.streams.size() > 1) {
1295 // Simulcast screenshare needs a simulcast encoder adapter to work, since
1296 // encoders usually can't natively do simulcast with different frame rates
1297 // for the different layers.
1298 video_encoder_.reset(
1299 new SimulcastEncoderAdapter(new Vp8EncoderFactory()));
1300 } else {
1301 video_encoder_.reset(VP8Encoder::Create());
1302 }
ivica5d6a06c2015-09-17 05:30:24 -07001303 payload_type = kPayloadTypeVP8;
minyue626bc952016-10-31 05:47:02 -07001304 } else if (params_.video.codec == "VP9") {
magjed509e4fe2016-11-18 01:34:11 -08001305 video_encoder_.reset(VP9Encoder::Create());
ivica5d6a06c2015-09-17 05:30:24 -07001306 payload_type = kPayloadTypeVP9;
1307 } else {
1308 RTC_NOTREACHED() << "Codec not supported!";
1309 return;
1310 }
minyuea27172d2016-11-01 05:59:29 -07001311 video_send_config_.encoder_settings.encoder = video_encoder_.get();
minyue626bc952016-10-31 05:47:02 -07001312 video_send_config_.encoder_settings.payload_name = params_.video.codec;
stefanff483612015-12-21 03:14:00 -08001313 video_send_config_.encoder_settings.payload_type = payload_type;
1314 video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1315 video_send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
brandtr8313a6f2017-01-13 07:41:19 -08001316 for (size_t i = 0; i < num_video_streams; ++i)
stefanff483612015-12-21 03:14:00 -08001317 video_send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[i]);
ivica5d6a06c2015-09-17 05:30:24 -07001318
stefanff483612015-12-21 03:14:00 -08001319 video_send_config_.rtp.extensions.clear();
minyue626bc952016-10-31 05:47:02 -07001320 if (params_.call.send_side_bwe) {
stefanff483612015-12-21 03:14:00 -08001321 video_send_config_.rtp.extensions.push_back(
isheriff6f8d6862016-05-26 11:24:55 -07001322 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Stefan Holmer12952972015-10-29 15:13:24 +01001323 test::kTransportSequenceNumberExtensionId));
1324 } else {
stefanff483612015-12-21 03:14:00 -08001325 video_send_config_.rtp.extensions.push_back(RtpExtension(
isheriff6f8d6862016-05-26 11:24:55 -07001326 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
Erik SprĂ¥ng6b8d3552015-09-24 15:06:57 +02001327 }
ilnik00d802b2017-04-11 10:34:31 -07001328 video_send_config_.rtp.extensions.push_back(RtpExtension(
1329 RtpExtension::kVideoContentTypeUri, test::kVideoContentTypeExtensionId));
Erik SprĂ¥ng6b8d3552015-09-24 15:06:57 +02001330
stefanff483612015-12-21 03:14:00 -08001331 video_encoder_config_.min_transmit_bitrate_bps =
minyue626bc952016-10-31 05:47:02 -07001332 params_.video.min_transmit_bps;
perkjfa10b552016-10-02 23:45:26 -07001333
brandtr1293aca2016-11-16 22:47:29 -08001334 video_send_config_.suspend_below_min_bitrate =
1335 params_.video.suspend_below_min_bitrate;
1336
perkjfa10b552016-10-02 23:45:26 -07001337 video_encoder_config_.number_of_streams = params_.ss.streams.size();
1338 video_encoder_config_.max_bitrate_bps = 0;
1339 for (size_t i = 0; i < params_.ss.streams.size(); ++i) {
1340 video_encoder_config_.max_bitrate_bps +=
1341 params_.ss.streams[i].max_bitrate_bps;
1342 }
ilnik6b826ef2017-06-16 06:53:48 -07001343 if (params_.ss.infer_streams) {
1344 video_encoder_config_.video_stream_factory =
1345 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
1346 params_.video.codec, params_.ss.streams[0].max_qp,
1347 params_.video.fps, params_.screenshare.enabled, true);
1348 } else {
1349 video_encoder_config_.video_stream_factory =
1350 new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams);
1351 }
perkjfa10b552016-10-02 23:45:26 -07001352
stefanff483612015-12-21 03:14:00 -08001353 video_encoder_config_.spatial_layers = params_.ss.spatial_layers;
ivica5d6a06c2015-09-17 05:30:24 -07001354
1355 CreateMatchingReceiveConfigs(recv_transport);
1356
brandtr8313a6f2017-01-13 07:41:19 -08001357 for (size_t i = 0; i < num_video_streams; ++i) {
stefanff483612015-12-21 03:14:00 -08001358 video_receive_configs_[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
brandtr14742122017-01-27 04:53:07 -08001359 video_receive_configs_[i].rtp.rtx_ssrc = kSendRtxSsrcs[i];
1360 video_receive_configs_[i].rtp.rtx_payload_types[payload_type] =
sprangce4aef12015-11-02 07:23:20 -08001361 kSendRtxPayloadType;
minyue626bc952016-10-31 05:47:02 -07001362 video_receive_configs_[i].rtp.transport_cc = params_.call.send_side_bwe;
Stefan Holmer85d5ac72017-02-09 16:25:16 +01001363 video_receive_configs_[i].rtp.remb = !params_.call.send_side_bwe;
ilnik00d802b2017-04-11 10:34:31 -07001364 // Enable RTT calculation so NTP time estimator will work.
1365 video_receive_configs_[i].rtp.rtcp_xr.receiver_reference_time_report = true;
ilnik9fd9f6c2017-03-02 08:10:10 -08001366 // Force fake decoders on non-selected simulcast streams.
1367 if (i != params_.ss.selected_stream) {
1368 VideoReceiveStream::Decoder decoder;
1369 decoder.decoder = new test::FakeDecoder();
1370 decoder.payload_type = video_send_config_.encoder_settings.payload_type;
1371 decoder.payload_name = video_send_config_.encoder_settings.payload_name;
1372 video_receive_configs_[i].decoders.clear();
1373 allocated_decoders_.emplace_back(decoder.decoder);
1374 video_receive_configs_[i].decoders.push_back(decoder);
1375 }
sprangce4aef12015-11-02 07:23:20 -08001376 }
brandtr1293aca2016-11-16 22:47:29 -08001377
1378 if (params_.video.flexfec) {
brandtr8313a6f2017-01-13 07:41:19 -08001379 // Override send config constructed by CreateSendConfig.
brandtr1293aca2016-11-16 22:47:29 -08001380 video_send_config_.rtp.flexfec.protected_media_ssrcs = {
1381 kVideoSendSsrcs[params_.ss.selected_stream]};
1382
brandtr8313a6f2017-01-13 07:41:19 -08001383 // The matching receive config is _not_ created by
1384 // CreateMatchingReceiveConfigs, since VideoQualityTest is not a BaseTest.
1385 // Set up the receive config manually instead.
1386 FlexfecReceiveStream::Config flexfec_receive_config(recv_transport);
brandtr1cfbd602016-12-08 04:17:53 -08001387 flexfec_receive_config.payload_type =
brandtr3d200bd2017-01-16 06:59:19 -08001388 video_send_config_.rtp.flexfec.payload_type;
1389 flexfec_receive_config.remote_ssrc = video_send_config_.rtp.flexfec.ssrc;
brandtr1293aca2016-11-16 22:47:29 -08001390 flexfec_receive_config.protected_media_ssrcs =
1391 video_send_config_.rtp.flexfec.protected_media_ssrcs;
brandtrfa5a3682017-01-17 01:33:54 -08001392 flexfec_receive_config.local_ssrc = kReceiverLocalVideoSsrc;
brandtrb29e6522016-12-21 06:37:18 -08001393 flexfec_receive_config.transport_cc = params_.call.send_side_bwe;
1394 if (params_.call.send_side_bwe) {
1395 flexfec_receive_config.rtp_header_extensions.push_back(
1396 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1397 test::kTransportSequenceNumberExtensionId));
1398 } else {
1399 flexfec_receive_config.rtp_header_extensions.push_back(RtpExtension(
1400 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1401 }
brandtr1293aca2016-11-16 22:47:29 -08001402 flexfec_receive_configs_.push_back(flexfec_receive_config);
1403 }
1404
1405 if (params_.video.ulpfec) {
1406 video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType;
1407 video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType;
1408 video_send_config_.rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType;
1409
1410 video_receive_configs_[params_.ss.selected_stream]
1411 .rtp.ulpfec.red_payload_type =
1412 video_send_config_.rtp.ulpfec.red_payload_type;
1413 video_receive_configs_[params_.ss.selected_stream]
1414 .rtp.ulpfec.ulpfec_payload_type =
1415 video_send_config_.rtp.ulpfec.ulpfec_payload_type;
1416 video_receive_configs_[params_.ss.selected_stream]
1417 .rtp.ulpfec.red_rtx_payload_type =
1418 video_send_config_.rtp.ulpfec.red_rtx_payload_type;
1419 }
ivica5d6a06c2015-09-17 05:30:24 -07001420}
1421
ilnika014cc52017-03-07 04:21:04 -08001422void VideoQualityTest::SetupThumbnails(Transport* send_transport,
1423 Transport* recv_transport) {
1424 for (int i = 0; i < params_.num_thumbnails; ++i) {
1425 thumbnail_encoders_.emplace_back(VP8Encoder::Create());
1426
1427 // Thumbnails will be send in the other way: from receiver_call to
1428 // sender_call.
1429 VideoSendStream::Config thumbnail_send_config(recv_transport);
1430 thumbnail_send_config.rtp.ssrcs.push_back(kThumbnailSendSsrcStart + i);
1431 thumbnail_send_config.encoder_settings.encoder =
1432 thumbnail_encoders_.back().get();
1433 thumbnail_send_config.encoder_settings.payload_name = params_.video.codec;
1434 thumbnail_send_config.encoder_settings.payload_type = kPayloadTypeVP8;
1435 thumbnail_send_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1436 thumbnail_send_config.rtp.rtx.payload_type = kSendRtxPayloadType;
1437 thumbnail_send_config.rtp.rtx.ssrcs.push_back(kThumbnailRtxSsrcStart + i);
1438 thumbnail_send_config.rtp.extensions.clear();
1439 if (params_.call.send_side_bwe) {
1440 thumbnail_send_config.rtp.extensions.push_back(
1441 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1442 test::kTransportSequenceNumberExtensionId));
1443 } else {
1444 thumbnail_send_config.rtp.extensions.push_back(RtpExtension(
1445 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1446 }
1447
1448 VideoEncoderConfig thumbnail_encoder_config;
1449 thumbnail_encoder_config.min_transmit_bitrate_bps = 7500;
1450 thumbnail_send_config.suspend_below_min_bitrate =
1451 params_.video.suspend_below_min_bitrate;
1452 thumbnail_encoder_config.number_of_streams = 1;
1453 thumbnail_encoder_config.max_bitrate_bps = 50000;
ilnik6b826ef2017-06-16 06:53:48 -07001454 if (params_.ss.infer_streams) {
1455 thumbnail_encoder_config.video_stream_factory =
1456 new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams);
1457 } else {
1458 thumbnail_encoder_config.video_stream_factory =
1459 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
1460 params_.video.codec, params_.ss.streams[0].max_qp,
1461 params_.video.fps, params_.screenshare.enabled, true);
1462 }
ilnika014cc52017-03-07 04:21:04 -08001463 thumbnail_encoder_config.spatial_layers = params_.ss.spatial_layers;
1464
1465 VideoReceiveStream::Config thumbnail_receive_config(send_transport);
1466 thumbnail_receive_config.rtp.remb = false;
1467 thumbnail_receive_config.rtp.transport_cc = true;
1468 thumbnail_receive_config.rtp.local_ssrc = kReceiverLocalVideoSsrc;
1469 for (const RtpExtension& extension : thumbnail_send_config.rtp.extensions)
1470 thumbnail_receive_config.rtp.extensions.push_back(extension);
1471 thumbnail_receive_config.renderer = &fake_renderer_;
1472
1473 VideoReceiveStream::Decoder decoder =
1474 test::CreateMatchingDecoder(thumbnail_send_config.encoder_settings);
1475 allocated_decoders_.push_back(
1476 std::unique_ptr<VideoDecoder>(decoder.decoder));
1477 thumbnail_receive_config.decoders.clear();
1478 thumbnail_receive_config.decoders.push_back(decoder);
1479 thumbnail_receive_config.rtp.remote_ssrc =
1480 thumbnail_send_config.rtp.ssrcs[0];
1481
1482 thumbnail_receive_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1483 thumbnail_receive_config.rtp.rtx_ssrc = kThumbnailRtxSsrcStart + i;
1484 thumbnail_receive_config.rtp.rtx_payload_types[kPayloadTypeVP8] =
1485 kSendRtxPayloadType;
1486 thumbnail_receive_config.rtp.transport_cc = params_.call.send_side_bwe;
1487 thumbnail_receive_config.rtp.remb = !params_.call.send_side_bwe;
1488
1489 thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy());
1490 thumbnail_send_configs_.push_back(thumbnail_send_config.Copy());
1491 thumbnail_receive_configs_.push_back(thumbnail_receive_config.Copy());
1492 }
1493
1494 for (int i = 0; i < params_.num_thumbnails; ++i) {
1495 thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream(
1496 thumbnail_send_configs_[i].Copy(),
1497 thumbnail_encoder_configs_[i].Copy()));
1498 thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream(
1499 thumbnail_receive_configs_[i].Copy()));
1500 }
1501}
1502
1503void VideoQualityTest::DestroyThumbnailStreams() {
1504 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1505 receiver_call_->DestroyVideoSendStream(thumbnail_send_stream);
1506 thumbnail_send_streams_.clear();
1507 for (VideoReceiveStream* thumbnail_receive_stream :
1508 thumbnail_receive_streams_)
1509 sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream);
1510 thumbnail_send_streams_.clear();
1511 thumbnail_receive_streams_.clear();
1512}
1513
ilnik2a8c2f52017-02-15 02:23:28 -08001514void VideoQualityTest::SetupScreenshareOrSVC() {
1515 if (params_.screenshare.enabled) {
1516 // Fill out codec settings.
1517 video_encoder_config_.content_type =
1518 VideoEncoderConfig::ContentType::kScreen;
1519 degradation_preference_ =
1520 VideoSendStream::DegradationPreference::kMaintainResolution;
1521 if (params_.video.codec == "VP8") {
1522 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
1523 vp8_settings.denoisingOn = false;
1524 vp8_settings.frameDroppingOn = false;
1525 vp8_settings.numberOfTemporalLayers =
1526 static_cast<unsigned char>(params_.video.num_temporal_layers);
1527 video_encoder_config_.encoder_specific_settings =
1528 new rtc::RefCountedObject<
1529 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
1530 } else if (params_.video.codec == "VP9") {
1531 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
1532 vp9_settings.denoisingOn = false;
1533 vp9_settings.frameDroppingOn = false;
1534 vp9_settings.numberOfTemporalLayers =
1535 static_cast<unsigned char>(params_.video.num_temporal_layers);
1536 vp9_settings.numberOfSpatialLayers =
1537 static_cast<unsigned char>(params_.ss.num_spatial_layers);
1538 video_encoder_config_.encoder_specific_settings =
1539 new rtc::RefCountedObject<
1540 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
1541 }
1542 // Setup frame generator.
1543 const size_t kWidth = 1850;
1544 const size_t kHeight = 1110;
ilnik8d8185c2017-04-12 04:52:55 -07001545 std::vector<std::string> slides = params_.screenshare.slides;
1546 if (slides.size() == 0) {
1547 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
1548 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
1549 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
1550 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
1551 }
ilnik2a8c2f52017-02-15 02:23:28 -08001552 if (params_.screenshare.scroll_duration == 0) {
1553 // Cycle image every slide_change_interval seconds.
perkja8ba1952017-02-27 06:52:10 -08001554 frame_generator_ = test::FrameGenerator::CreateFromYuvFile(
ilnik2a8c2f52017-02-15 02:23:28 -08001555 slides, kWidth, kHeight,
perkja8ba1952017-02-27 06:52:10 -08001556 params_.screenshare.slide_change_interval * params_.video.fps);
ilnik2a8c2f52017-02-15 02:23:28 -08001557 } else {
1558 RTC_CHECK_LE(params_.video.width, kWidth);
1559 RTC_CHECK_LE(params_.video.height, kHeight);
1560 RTC_CHECK_GT(params_.screenshare.slide_change_interval, 0);
1561 const int kPauseDurationMs = (params_.screenshare.slide_change_interval -
1562 params_.screenshare.scroll_duration) *
1563 1000;
1564 RTC_CHECK_LE(params_.screenshare.scroll_duration,
1565 params_.screenshare.slide_change_interval);
1566
perkja8ba1952017-02-27 06:52:10 -08001567 frame_generator_ = test::FrameGenerator::CreateScrollingInputFromYuvFiles(
1568 clock_, slides, kWidth, kHeight, params_.video.width,
1569 params_.video.height, params_.screenshare.scroll_duration * 1000,
1570 kPauseDurationMs);
ilnik2a8c2f52017-02-15 02:23:28 -08001571 }
1572 } else if (params_.ss.num_spatial_layers > 1) { // For non-screenshare case.
1573 RTC_CHECK(params_.video.codec == "VP9");
kthelgason29a44e32016-09-27 03:52:02 -07001574 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
kthelgason29a44e32016-09-27 03:52:02 -07001575 vp9_settings.numberOfTemporalLayers =
minyue626bc952016-10-31 05:47:02 -07001576 static_cast<unsigned char>(params_.video.num_temporal_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001577 vp9_settings.numberOfSpatialLayers =
sprangce4aef12015-11-02 07:23:20 -08001578 static_cast<unsigned char>(params_.ss.num_spatial_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001579 video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject<
1580 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
ivica5d6a06c2015-09-17 05:30:24 -07001581 }
ivica5d6a06c2015-09-17 05:30:24 -07001582}
1583
ilnika014cc52017-03-07 04:21:04 -08001584void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) {
1585 VideoStream thumbnail = DefaultThumbnailStream();
1586 for (size_t i = 0; i < num_thumbnail_streams; ++i) {
1587 thumbnail_capturers_.emplace_back(test::FrameGeneratorCapturer::Create(
1588 static_cast<int>(thumbnail.width), static_cast<int>(thumbnail.height),
1589 thumbnail.max_framerate, clock_));
ilnikf89a7382017-03-07 06:15:27 -08001590 RTC_DCHECK(thumbnail_capturers_.back());
ilnika014cc52017-03-07 04:21:04 -08001591 }
1592}
1593
perkja49cbd32016-09-16 07:53:41 -07001594void VideoQualityTest::CreateCapturer() {
sprangce4aef12015-11-02 07:23:20 -08001595 if (params_.screenshare.enabled) {
1596 test::FrameGeneratorCapturer* frame_generator_capturer =
perkja8ba1952017-02-27 06:52:10 -08001597 new test::FrameGeneratorCapturer(clock_, std::move(frame_generator_),
minyue626bc952016-10-31 05:47:02 -07001598 params_.video.fps);
ivica2d4e6c52015-09-23 01:57:06 -07001599 EXPECT_TRUE(frame_generator_capturer->Init());
minyuea27172d2016-11-01 05:59:29 -07001600 video_capturer_.reset(frame_generator_capturer);
ivica5d6a06c2015-09-17 05:30:24 -07001601 } else {
ilnik6b826ef2017-06-16 06:53:48 -07001602 if (params_.video.clip_name == "Generator") {
1603 video_capturer_.reset(test::FrameGeneratorCapturer::Create(
1604 static_cast<int>(params_.video.width),
1605 static_cast<int>(params_.video.height), params_.video.fps, clock_));
1606 } else if (params_.video.clip_name.empty()) {
minyuea27172d2016-11-01 05:59:29 -07001607 video_capturer_.reset(test::VcmCapturer::Create(
Tarun Chawla8e857d12017-05-31 19:20:57 +05301608 params_.video.width, params_.video.height, params_.video.fps,
1609 params_.video.capture_device_index));
sprang1bed2e42017-01-23 08:46:51 -08001610 if (!video_capturer_) {
1611 // Failed to get actual camera, use chroma generator as backup.
1612 video_capturer_.reset(test::FrameGeneratorCapturer::Create(
perkja8ba1952017-02-27 06:52:10 -08001613 static_cast<int>(params_.video.width),
1614 static_cast<int>(params_.video.height), params_.video.fps, clock_));
sprang1bed2e42017-01-23 08:46:51 -08001615 }
ivica5d6a06c2015-09-17 05:30:24 -07001616 } else {
minyuea27172d2016-11-01 05:59:29 -07001617 video_capturer_.reset(test::FrameGeneratorCapturer::CreateFromYuvFile(
perkja49cbd32016-09-16 07:53:41 -07001618 test::ResourcePath(params_.video.clip_name, "yuv"),
minyue626bc952016-10-31 05:47:02 -07001619 params_.video.width, params_.video.height, params_.video.fps,
ivica2d4e6c52015-09-23 01:57:06 -07001620 clock_));
minyuea27172d2016-11-01 05:59:29 -07001621 ASSERT_TRUE(video_capturer_) << "Could not create capturer for "
1622 << params_.video.clip_name
1623 << ".yuv. Is this resource file present?";
ivica5d6a06c2015-09-17 05:30:24 -07001624 }
1625 }
sprang1bed2e42017-01-23 08:46:51 -08001626 RTC_DCHECK(video_capturer_.get());
ivica5d6a06c2015-09-17 05:30:24 -07001627}
1628
sprang7a975f72015-10-12 06:33:21 -07001629void VideoQualityTest::RunWithAnalyzer(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001630 params_ = params;
1631
minyue626bc952016-10-31 05:47:02 -07001632 RTC_CHECK(!params_.audio.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001633 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1634 // differentiate between the analyzer and the renderer case.
sprangce4aef12015-11-02 07:23:20 -08001635 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001636
1637 FILE* graph_data_output_file = nullptr;
sprangce4aef12015-11-02 07:23:20 -08001638 if (!params_.analyzer.graph_data_output_filename.empty()) {
ivica5d6a06c2015-09-17 05:30:24 -07001639 graph_data_output_file =
sprangce4aef12015-11-02 07:23:20 -08001640 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
Peter Boström74f6e9e2016-04-04 17:56:10 +02001641 RTC_CHECK(graph_data_output_file)
sprangce4aef12015-11-02 07:23:20 -08001642 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1643 << "!";
ivica87f83a92015-10-08 05:13:32 -07001644 }
sprang7a975f72015-10-12 06:33:21 -07001645
philipel4fb651d2017-04-10 03:54:05 -07001646 Call::Config call_config(event_log_.get());
minyue626bc952016-10-31 05:47:02 -07001647 call_config.bitrate_config = params.call.call_bitrate_config;
stefanf116bd02015-10-27 08:29:42 -07001648 CreateCalls(call_config, call_config);
1649
ilnik68af10d2017-03-02 04:59:33 -08001650 test::LayerFilteringTransport send_transport(
1651 params_.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9,
minyue20c84cc2017-04-10 16:57:57 -07001652 params_.video.selected_tl, params_.ss.selected_sl, payload_type_map_);
1653
1654 test::DirectTransport recv_transport(params_.pipe, receiver_call_.get(),
1655 payload_type_map_);
stefanf116bd02015-10-27 08:29:42 -07001656
sprangce4aef12015-11-02 07:23:20 -08001657 std::string graph_title = params_.analyzer.graph_title;
1658 if (graph_title.empty())
1659 graph_title = VideoQualityTest::GenerateGraphTitle();
1660
sprangc1b57a12017-02-28 08:50:47 -08001661 bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest");
ivica5d6a06c2015-09-17 05:30:24 -07001662 VideoAnalyzer analyzer(
sprangce4aef12015-11-02 07:23:20 -08001663 &send_transport, params_.analyzer.test_label,
ilnik2a8c2f52017-02-15 02:23:28 -08001664 params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold,
ilnik9ae0d762017-02-15 00:53:12 -08001665 is_quick_test_enabled
1666 ? kFramesSentInQuickTest
1667 : params_.analyzer.test_durations_secs * params_.video.fps,
sprangce4aef12015-11-02 07:23:20 -08001668 graph_data_output_file, graph_title,
ilnik3dd5ad92017-02-09 04:58:53 -08001669 kVideoSendSsrcs[params_.ss.selected_stream],
ilnik46a00212017-02-10 09:16:05 -08001670 kSendRtxSsrcs[params_.ss.selected_stream],
ilnikcb8c1462017-03-09 09:23:30 -08001671 static_cast<size_t>(params_.ss.selected_stream), params.ss.selected_sl,
ilnik6b826ef2017-06-16 06:53:48 -07001672 params_.video.selected_tl, is_quick_test_enabled, clock_);
ivica5d6a06c2015-09-17 05:30:24 -07001673 analyzer.SetReceiver(receiver_call_->Receiver());
1674 send_transport.SetReceiver(&analyzer);
1675 recv_transport.SetReceiver(sender_call_->Receiver());
1676
minyuea27172d2016-11-01 05:59:29 -07001677 SetupVideo(&analyzer, &recv_transport);
ilnika014cc52017-03-07 04:21:04 -08001678 SetupThumbnails(&analyzer, &recv_transport);
stefanff483612015-12-21 03:14:00 -08001679 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer;
pbos14fe7082016-04-20 06:35:56 -07001680 video_send_config_.pre_encode_callback = analyzer.pre_encode_proxy();
Peter Boströme4499152016-02-05 11:13:28 +01001681 RTC_DCHECK(!video_send_config_.post_encode_callback);
1682 video_send_config_.post_encode_callback = analyzer.encode_timing_proxy();
ivica5d6a06c2015-09-17 05:30:24 -07001683
ilnik2a8c2f52017-02-15 02:23:28 -08001684 SetupScreenshareOrSVC();
ivica5d6a06c2015-09-17 05:30:24 -07001685
brandtr1293aca2016-11-16 22:47:29 -08001686 CreateFlexfecStreams();
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001687 CreateVideoStreams();
perkja49cbd32016-09-16 07:53:41 -07001688 analyzer.SetSendStream(video_send_stream_);
philipelfd870db2017-01-23 03:22:15 -08001689 if (video_receive_streams_.size() == 1)
1690 analyzer.SetReceiveStream(video_receive_streams_[0]);
kthelgason2bc68642017-02-07 07:02:22 -08001691
1692 video_send_stream_->SetSource(analyzer.OutputInterface(),
1693 degradation_preference_);
ivica5d6a06c2015-09-17 05:30:24 -07001694
ilnika014cc52017-03-07 04:21:04 -08001695 SetupThumbnailCapturers(params_.num_thumbnails);
1696 for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) {
1697 thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(),
1698 degradation_preference_);
1699 }
1700
perkja49cbd32016-09-16 07:53:41 -07001701 CreateCapturer();
ilnika014cc52017-03-07 04:21:04 -08001702
ilnik6b826ef2017-06-16 06:53:48 -07001703 analyzer.SetSource(video_capturer_.get(), params_.ss.infer_streams);
ivicac1cc8542015-10-08 03:44:06 -07001704
palmkviste75f2042016-09-28 06:19:48 -07001705 StartEncodedFrameLogs(video_send_stream_);
1706 StartEncodedFrameLogs(video_receive_streams_[0]);
stefanff483612015-12-21 03:14:00 -08001707 video_send_stream_->Start();
ilnika014cc52017-03-07 04:21:04 -08001708 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1709 thumbnail_send_stream->Start();
stefanff483612015-12-21 03:14:00 -08001710 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1711 receive_stream->Start();
brandtr1293aca2016-11-16 22:47:29 -08001712 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1713 receive_stream->Start();
ilnika014cc52017-03-07 04:21:04 -08001714 for (VideoReceiveStream* thumbnail_receive_stream :
1715 thumbnail_receive_streams_)
1716 thumbnail_receive_stream->Start();
1717
ilnikdf92c5c2017-02-23 02:08:44 -08001718 analyzer.StartMeasuringCpuProcessTime();
ilnika014cc52017-03-07 04:21:04 -08001719
minyuea27172d2016-11-01 05:59:29 -07001720 video_capturer_->Start();
ilnika014cc52017-03-07 04:21:04 -08001721 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
1722 thumbnail_capturers_) {
1723 video_caputurer->Start();
1724 }
ivica5d6a06c2015-09-17 05:30:24 -07001725
1726 analyzer.Wait();
1727
1728 send_transport.StopSending();
1729 recv_transport.StopSending();
1730
ilnika014cc52017-03-07 04:21:04 -08001731 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
1732 thumbnail_capturers_)
1733 video_caputurer->Stop();
minyuea27172d2016-11-01 05:59:29 -07001734 video_capturer_->Stop();
ilnika014cc52017-03-07 04:21:04 -08001735 for (VideoReceiveStream* thumbnail_receive_stream :
1736 thumbnail_receive_streams_)
1737 thumbnail_receive_stream->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001738 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1739 receive_stream->Stop();
stefanff483612015-12-21 03:14:00 -08001740 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1741 receive_stream->Stop();
ilnika014cc52017-03-07 04:21:04 -08001742 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1743 thumbnail_send_stream->Stop();
stefanff483612015-12-21 03:14:00 -08001744 video_send_stream_->Stop();
ivica5d6a06c2015-09-17 05:30:24 -07001745
1746 DestroyStreams();
ilnika014cc52017-03-07 04:21:04 -08001747 DestroyThumbnailStreams();
ivica5d6a06c2015-09-17 05:30:24 -07001748
1749 if (graph_data_output_file)
1750 fclose(graph_data_output_file);
1751}
1752
minyuea27172d2016-11-01 05:59:29 -07001753void VideoQualityTest::SetupAudio(int send_channel_id,
1754 int receive_channel_id,
1755 Call* call,
1756 Transport* transport,
1757 AudioReceiveStream** audio_receive_stream) {
1758 audio_send_config_ = AudioSendStream::Config(transport);
1759 audio_send_config_.voe_channel_id = send_channel_id;
1760 audio_send_config_.rtp.ssrc = kAudioSendSsrc;
1761
1762 // Add extension to enable audio send side BWE, and allow audio bit rate
1763 // adaptation.
1764 audio_send_config_.rtp.extensions.clear();
1765 if (params_.call.send_side_bwe) {
1766 audio_send_config_.rtp.extensions.push_back(
1767 webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri,
1768 test::kTransportSequenceNumberExtensionId));
minyue10cbb462016-11-07 09:29:22 -08001769 audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps;
1770 audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps;
minyuea27172d2016-11-01 05:59:29 -07001771 }
ossu20a4b3f2017-04-27 02:08:52 -07001772 audio_send_config_.send_codec_spec =
1773 rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
1774 {kAudioSendPayloadType,
1775 {"OPUS", 48000, 2,
1776 {{"usedtx", (params_.audio.dtx ? "1" : "0")},
1777 {"stereo", "1"}}}});
minyue48368ad2017-05-10 04:06:11 -07001778 audio_send_config_.encoder_factory = encoder_factory_;
minyuea27172d2016-11-01 05:59:29 -07001779 audio_send_stream_ = call->CreateAudioSendStream(audio_send_config_);
1780
1781 AudioReceiveStream::Config audio_config;
1782 audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc;
1783 audio_config.rtcp_send_transport = transport;
1784 audio_config.voe_channel_id = receive_channel_id;
1785 audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc;
1786 audio_config.rtp.transport_cc = params_.call.send_side_bwe;
1787 audio_config.rtp.extensions = audio_send_config_.rtp.extensions;
1788 audio_config.decoder_factory = decoder_factory_;
minyue20c84cc2017-04-10 16:57:57 -07001789 audio_config.decoder_map = {{kAudioSendPayloadType, {"OPUS", 48000, 2}}};
minyuea27172d2016-11-01 05:59:29 -07001790 if (params_.video.enabled && params_.audio.sync_video)
1791 audio_config.sync_group = kSyncGroup;
1792
1793 *audio_receive_stream = call->CreateAudioReceiveStream(audio_config);
1794}
1795
minyue73208662016-08-18 06:28:55 -07001796void VideoQualityTest::RunWithRenderers(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001797 params_ = params;
1798 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001799
ivica5d6a06c2015-09-17 05:30:24 -07001800 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
1801 // match the full stack tests.
philipel4fb651d2017-04-10 03:54:05 -07001802 Call::Config call_config(event_log_.get());
minyue626bc952016-10-31 05:47:02 -07001803 call_config.bitrate_config = params_.call.call_bitrate_config;
minyue73208662016-08-18 06:28:55 -07001804
1805 ::VoiceEngineState voe;
minyue626bc952016-10-31 05:47:02 -07001806 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001807 CreateVoiceEngine(&voe, decoder_factory_);
1808 AudioState::Config audio_state_config;
1809 audio_state_config.voice_engine = voe.voice_engine;
aleloi10111bc2016-11-17 06:48:48 -08001810 audio_state_config.audio_mixer = AudioMixerImpl::Create();
minyue73208662016-08-18 06:28:55 -07001811 call_config.audio_state = AudioState::Create(audio_state_config);
1812 }
1813
kwiberg27f982b2016-03-01 11:52:33 -08001814 std::unique_ptr<Call> call(Call::Create(call_config));
ivica5d6a06c2015-09-17 05:30:24 -07001815
minyuea27172d2016-11-01 05:59:29 -07001816 // TODO(minyue): consider if this is a good transport even for audio only
1817 // calls.
ivica5d6a06c2015-09-17 05:30:24 -07001818 test::LayerFilteringTransport transport(
stefanf116bd02015-10-27 08:29:42 -07001819 params.pipe, call.get(), kPayloadTypeVP8, kPayloadTypeVP9,
minyue20c84cc2017-04-10 16:57:57 -07001820 params.video.selected_tl, params_.ss.selected_sl, payload_type_map_);
1821
ivica5d6a06c2015-09-17 05:30:24 -07001822 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
1823 // least share as much code as possible. That way this test would also match
1824 // the full stack tests better.
1825 transport.SetReceiver(call->Receiver());
1826
minyuea27172d2016-11-01 05:59:29 -07001827 VideoReceiveStream* video_receive_stream = nullptr;
brandtr1293aca2016-11-16 22:47:29 -08001828 FlexfecReceiveStream* flexfec_receive_stream = nullptr;
minyuea27172d2016-11-01 05:59:29 -07001829 std::unique_ptr<test::VideoRenderer> local_preview;
1830 std::unique_ptr<test::VideoRenderer> loopback_video;
1831 if (params_.video.enabled) {
1832 // Create video renderers.
1833 local_preview.reset(test::VideoRenderer::Create(
1834 "Local Preview", params_.video.width, params_.video.height));
ivica87f83a92015-10-08 05:13:32 -07001835
minyuea27172d2016-11-01 05:59:29 -07001836 size_t stream_id = params_.ss.selected_stream;
1837 std::string title = "Loopback Video";
1838 if (params_.ss.streams.size() > 1) {
1839 std::ostringstream s;
1840 s << stream_id;
1841 title += " - Stream #" + s.str();
1842 }
sprangce4aef12015-11-02 07:23:20 -08001843
minyuea27172d2016-11-01 05:59:29 -07001844 loopback_video.reset(test::VideoRenderer::Create(
1845 title.c_str(), params_.ss.streams[stream_id].width,
1846 params_.ss.streams[stream_id].height));
mflodman48a4beb2016-07-01 13:03:59 +02001847
minyuea27172d2016-11-01 05:59:29 -07001848 SetupVideo(&transport, &transport);
minyuea27172d2016-11-01 05:59:29 -07001849 video_send_config_.pre_encode_callback = local_preview.get();
1850 video_receive_configs_[stream_id].renderer = loopback_video.get();
1851 if (params_.audio.enabled && params_.audio.sync_video)
1852 video_receive_configs_[stream_id].sync_group = kSyncGroup;
1853
ilnik68af10d2017-03-02 04:59:33 -08001854 if (params_.screenshare.enabled)
1855 SetupScreenshareOrSVC();
minyuea27172d2016-11-01 05:59:29 -07001856
1857 video_send_stream_ = call->CreateVideoSendStream(
1858 video_send_config_.Copy(), video_encoder_config_.Copy());
brandtr1293aca2016-11-16 22:47:29 -08001859 if (params_.video.flexfec) {
1860 RTC_DCHECK(!flexfec_receive_configs_.empty());
1861 flexfec_receive_stream =
1862 call->CreateFlexfecReceiveStream(flexfec_receive_configs_[0]);
1863 }
minyuea27172d2016-11-01 05:59:29 -07001864 video_receive_stream = call->CreateVideoReceiveStream(
1865 video_receive_configs_[stream_id].Copy());
1866 CreateCapturer();
kthelgason2bc68642017-02-07 07:02:22 -08001867 video_send_stream_->SetSource(video_capturer_.get(),
1868 degradation_preference_);
philipel274c1dc2016-05-04 06:21:01 -07001869 }
1870
minyue73208662016-08-18 06:28:55 -07001871 AudioReceiveStream* audio_receive_stream = nullptr;
minyue626bc952016-10-31 05:47:02 -07001872 if (params_.audio.enabled) {
minyuea27172d2016-11-01 05:59:29 -07001873 SetupAudio(voe.send_channel_id, voe.receive_channel_id, call.get(),
1874 &transport, &audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001875 }
1876
palmkviste75f2042016-09-28 06:19:48 -07001877 StartEncodedFrameLogs(video_receive_stream);
1878 StartEncodedFrameLogs(video_send_stream_);
1879
minyue73208662016-08-18 06:28:55 -07001880 // Start sending and receiving video.
minyuea27172d2016-11-01 05:59:29 -07001881 if (params_.video.enabled) {
brandtr1293aca2016-11-16 22:47:29 -08001882 if (flexfec_receive_stream)
1883 flexfec_receive_stream->Start();
minyuea27172d2016-11-01 05:59:29 -07001884 video_receive_stream->Start();
1885 video_send_stream_->Start();
1886 video_capturer_->Start();
1887 }
ivica5d6a06c2015-09-17 05:30:24 -07001888
minyue626bc952016-10-31 05:47:02 -07001889 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001890 // Start receiving audio.
1891 audio_receive_stream->Start();
1892 EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id));
minyue73208662016-08-18 06:28:55 -07001893
1894 // Start sending audio.
1895 audio_send_stream_->Start();
1896 EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id));
1897 }
1898
ivica5d6a06c2015-09-17 05:30:24 -07001899 test::PressEnterToContinue();
1900
minyue626bc952016-10-31 05:47:02 -07001901 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001902 // Stop sending audio.
1903 EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id));
1904 audio_send_stream_->Stop();
1905
1906 // Stop receiving audio.
minyue73208662016-08-18 06:28:55 -07001907 EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id));
1908 audio_receive_stream->Stop();
minyuea27172d2016-11-01 05:59:29 -07001909 call->DestroyAudioSendStream(audio_send_stream_);
1910 call->DestroyAudioReceiveStream(audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001911 }
1912
1913 // Stop receiving and sending video.
minyuea27172d2016-11-01 05:59:29 -07001914 if (params_.video.enabled) {
1915 video_capturer_->Stop();
1916 video_send_stream_->Stop();
1917 video_receive_stream->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001918 if (flexfec_receive_stream) {
1919 flexfec_receive_stream->Stop();
1920 call->DestroyFlexfecReceiveStream(flexfec_receive_stream);
1921 }
minyuea27172d2016-11-01 05:59:29 -07001922 call->DestroyVideoReceiveStream(video_receive_stream);
1923 call->DestroyVideoSendStream(video_send_stream_);
minyue73208662016-08-18 06:28:55 -07001924 }
1925
ivica5d6a06c2015-09-17 05:30:24 -07001926 transport.StopSending();
minyue626bc952016-10-31 05:47:02 -07001927 if (params_.audio.enabled)
minyue73208662016-08-18 06:28:55 -07001928 DestroyVoiceEngine(&voe);
ivica5d6a06c2015-09-17 05:30:24 -07001929}
1930
palmkviste75f2042016-09-28 06:19:48 -07001931void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001932 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001933 std::ostringstream str;
1934 str << send_logs_++;
1935 std::string prefix =
minyue626bc952016-10-31 05:47:02 -07001936 params_.video.encoded_frame_base_path + "." + str.str() + ".send.";
palmkviste75f2042016-09-28 06:19:48 -07001937 stream->EnableEncodedFrameRecording(
1938 std::vector<rtc::PlatformFile>(
1939 {rtc::CreatePlatformFile(prefix + "1.ivf"),
1940 rtc::CreatePlatformFile(prefix + "2.ivf"),
1941 rtc::CreatePlatformFile(prefix + "3.ivf")}),
1942 10000000);
1943 }
1944}
ilnikcb8c1462017-03-09 09:23:30 -08001945
palmkviste75f2042016-09-28 06:19:48 -07001946void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001947 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001948 std::ostringstream str;
1949 str << receive_logs_++;
1950 std::string path =
minyue626bc952016-10-31 05:47:02 -07001951 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
palmkviste75f2042016-09-28 06:19:48 -07001952 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path),
1953 10000000);
1954 }
1955}
ivica5d6a06c2015-09-17 05:30:24 -07001956} // namespace webrtc