blob: 9f8ac5062092053fc7680d5a406305c2a86fcfbc [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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#include "video/video_quality_test.h"
perkj9fdbda62016-09-15 09:19:20 -070011
perkja49cbd32016-09-16 07:53:41 -070012#include <stdio.h>
ivica5d6a06c2015-09-17 05:30:24 -070013#include <algorithm>
14#include <deque>
15#include <map>
sprangce4aef12015-11-02 07:23:20 -080016#include <sstream>
mflodmand1590b22015-12-09 07:07:59 -080017#include <string>
ivica5d6a06c2015-09-17 05:30:24 -070018#include <vector>
19
Elad Alon83ccca12017-10-04 13:18:26 +020020#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Magnus Jedvert46a27652017-11-13 14:10:02 +010021#include "media/engine/internalencoderfactory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "media/engine/webrtcvideoengine.h"
23#include "modules/audio_mixer/audio_mixer_impl.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "modules/rtp_rtcp/source/rtp_format.h"
25#include "modules/rtp_rtcp/source/rtp_utility.h"
26#include "modules/video_coding/codecs/h264/include/h264.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/video_coding/codecs/vp8/include/vp8_common_types.h"
28#include "modules/video_coding/codecs/vp9/include/vp9.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_base/cpu_time.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "rtc_base/flags.h"
31#include "rtc_base/format_macros.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "rtc_base/memory_usage.h"
33#include "rtc_base/pathutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "system_wrappers/include/cpu_info.h"
Mirko Bonadei5f99e652017-12-19 13:40:40 +010035#include "test/rtp_file_writer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "test/run_loop.h"
37#include "test/statistics.h"
38#include "test/testsupport/fileutils.h"
39#include "test/testsupport/frame_writer.h"
Edward Lemurd1d67432018-01-02 11:54:37 +010040#include "test/testsupport/perf_test.h"
Edward Lemuraf8659a2017-09-27 14:46:24 +020041#include "test/testsupport/test_artifacts.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "test/vcm_capturer.h"
43#include "test/video_renderer.h"
minyue73208662016-08-18 06:28:55 -070044
ilnikee42d192017-08-22 07:16:20 -070045DEFINE_bool(save_worst_frame,
46 false,
47 "Enable saving a frame with the lowest PSNR to a jpeg file in the "
Edward Lemuraf8659a2017-09-27 14:46:24 +020048 "test_artifacts_dir");
ilnikee42d192017-08-22 07:16:20 -070049
minyue73208662016-08-18 06:28:55 -070050namespace {
51
52constexpr int kSendStatsPollingIntervalMs = 1000;
minyue20c84cc2017-04-10 16:57:57 -070053
minyue73208662016-08-18 06:28:55 -070054constexpr size_t kMaxComparisons = 10;
55constexpr char kSyncGroup[] = "av_sync";
minyue10cbb462016-11-07 09:29:22 -080056constexpr int kOpusMinBitrateBps = 6000;
57constexpr int kOpusBitrateFbBps = 32000;
ilnik9ae0d762017-02-15 00:53:12 -080058constexpr int kFramesSentInQuickTest = 1;
ilnika014cc52017-03-07 04:21:04 -080059constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000;
60constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000;
minyue73208662016-08-18 06:28:55 -070061
sprang1168fd42017-06-21 09:00:17 -070062constexpr int kDefaultMaxQp = cricket::WebRtcVideoChannel::kDefaultQpMax;
63
perkjfa10b552016-10-02 23:45:26 -070064class VideoStreamFactory
65 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
66 public:
67 explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams)
68 : streams_(streams) {}
69
70 private:
71 std::vector<webrtc::VideoStream> CreateEncoderStreams(
72 int width,
73 int height,
74 const webrtc::VideoEncoderConfig& encoder_config) override {
mflodmand79f97b2016-12-15 07:24:33 -080075 // The highest layer must match the incoming resolution.
76 std::vector<webrtc::VideoStream> streams = streams_;
77 streams[streams_.size() - 1].height = height;
78 streams[streams_.size() - 1].width = width;
Seth Hampson24722b32017-12-22 09:36:42 -080079
80 streams[0].bitrate_priority = encoder_config.bitrate_priority;
mflodmand79f97b2016-12-15 07:24:33 -080081 return streams;
perkjfa10b552016-10-02 23:45:26 -070082 }
83
84 std::vector<webrtc::VideoStream> streams_;
85};
86
brandtr504b95e2016-12-21 02:54:35 -080087bool IsFlexfec(int payload_type) {
88 return payload_type == webrtc::VideoQualityTest::kFlexfecPayloadType;
89}
90
minyue73208662016-08-18 06:28:55 -070091} // namespace
ivica5d6a06c2015-09-17 05:30:24 -070092
93namespace webrtc {
94
ivica5d6a06c2015-09-17 05:30:24 -070095class VideoAnalyzer : public PacketReceiver,
pbos2d566682015-09-28 09:59:31 -070096 public Transport,
ilnik1e7732c2017-02-23 05:07:56 -080097 public rtc::VideoSinkInterface<VideoFrame> {
ivica5d6a06c2015-09-17 05:30:24 -070098 public:
sprangce4aef12015-11-02 07:23:20 -080099 VideoAnalyzer(test::LayerFilteringTransport* transport,
ivica5d6a06c2015-09-17 05:30:24 -0700100 const std::string& test_label,
101 double avg_psnr_threshold,
102 double avg_ssim_threshold,
103 int duration_frames,
sprangce4aef12015-11-02 07:23:20 -0800104 FILE* graph_data_output_file,
105 const std::string& graph_title,
ilnik3dd5ad92017-02-09 04:58:53 -0800106 uint32_t ssrc_to_analyze,
ilnik46a00212017-02-10 09:16:05 -0800107 uint32_t rtx_ssrc_to_analyze,
ilnikcb8c1462017-03-09 09:23:30 -0800108 size_t selected_stream,
ilnik1e7732c2017-02-23 05:07:56 -0800109 int selected_sl,
110 int selected_tl,
ilnik6b826ef2017-06-16 06:53:48 -0700111 bool is_quick_test_enabled,
ilnik98436952017-07-13 00:47:03 -0700112 Clock* clock,
113 std::string rtp_dump_name)
perkja49cbd32016-09-16 07:53:41 -0700114 : transport_(transport),
ivica5d6a06c2015-09-17 05:30:24 -0700115 receiver_(nullptr),
stefan889d9652017-07-05 03:03:02 -0700116 call_(nullptr),
ivica5d6a06c2015-09-17 05:30:24 -0700117 send_stream_(nullptr),
philipelfd870db2017-01-23 03:22:15 -0800118 receive_stream_(nullptr),
ilnik6b826ef2017-06-16 06:53:48 -0700119 captured_frame_forwarder_(this, clock),
ivica5d6a06c2015-09-17 05:30:24 -0700120 test_label_(test_label),
121 graph_data_output_file_(graph_data_output_file),
sprangce4aef12015-11-02 07:23:20 -0800122 graph_title_(graph_title),
123 ssrc_to_analyze_(ssrc_to_analyze),
ilnik46a00212017-02-10 09:16:05 -0800124 rtx_ssrc_to_analyze_(rtx_ssrc_to_analyze),
ilnikcb8c1462017-03-09 09:23:30 -0800125 selected_stream_(selected_stream),
ilnik1e7732c2017-02-23 05:07:56 -0800126 selected_sl_(selected_sl),
127 selected_tl_(selected_tl),
pbos14fe7082016-04-20 06:35:56 -0700128 pre_encode_proxy_(this),
Peter Boströme4499152016-02-05 11:13:28 +0100129 encode_timing_proxy_(this),
stefan889d9652017-07-05 03:03:02 -0700130 last_fec_bytes_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700131 frames_to_process_(duration_frames),
132 frames_recorded_(0),
133 frames_processed_(0),
134 dropped_frames_(0),
pbos14fe7082016-04-20 06:35:56 -0700135 dropped_frames_before_first_encode_(0),
136 dropped_frames_before_rendering_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700137 last_render_time_(0),
Stefan Holmer32e930f2018-02-09 09:43:45 +0100138 last_render_delta_ms_(0),
139 last_unfreeze_time_ms_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700140 rtp_timestamp_delta_(0),
ilnik1e7732c2017-02-23 05:07:56 -0800141 total_media_bytes_(0),
142 first_sending_time_(0),
143 last_sending_time_(0),
ilnikdf92c5c2017-02-23 02:08:44 -0800144 cpu_time_(0),
145 wallclock_time_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700146 avg_psnr_threshold_(avg_psnr_threshold),
147 avg_ssim_threshold_(avg_ssim_threshold),
ilnik9ae0d762017-02-15 00:53:12 -0800148 is_quick_test_enabled_(is_quick_test_enabled),
Peter Boström8c38e8b2015-11-26 17:45:47 +0100149 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"),
Peter Boström5811a392015-12-10 13:02:50 +0100150 comparison_available_event_(false, false),
ilnik98436952017-07-13 00:47:03 -0700151 done_(true, false),
152 clock_(clock),
153 start_ms_(clock->TimeInMilliseconds()) {
ivica5d6a06c2015-09-17 05:30:24 -0700154 // Create thread pool for CPU-expensive PSNR/SSIM calculations.
155
156 // Try to use about as many threads as cores, but leave kMinCoresLeft alone,
157 // so that we don't accidentally starve "real" worker threads (codec etc).
158 // Also, don't allocate more than kMaxComparisonThreads, even if there are
159 // spare cores.
160
161 uint32_t num_cores = CpuInfo::DetectNumberOfCores();
kwibergaf476c72016-11-28 15:21:39 -0800162 RTC_DCHECK_GE(num_cores, 1);
ivica5d6a06c2015-09-17 05:30:24 -0700163 static const uint32_t kMinCoresLeft = 4;
164 static const uint32_t kMaxComparisonThreads = 8;
165
166 if (num_cores <= kMinCoresLeft) {
167 num_cores = 1;
168 } else {
169 num_cores -= kMinCoresLeft;
170 num_cores = std::min(num_cores, kMaxComparisonThreads);
171 }
172
173 for (uint32_t i = 0; i < num_cores; ++i) {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100174 rtc::PlatformThread* thread =
175 new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer");
176 thread->Start();
177 comparison_thread_pool_.push_back(thread);
ivica5d6a06c2015-09-17 05:30:24 -0700178 }
ilnik98436952017-07-13 00:47:03 -0700179
180 if (!rtp_dump_name.empty()) {
181 fprintf(stdout, "Writing rtp dump to %s\n", rtp_dump_name.c_str());
182 rtp_file_writer_.reset(test::RtpFileWriter::Create(
183 test::RtpFileWriter::kRtpDump, rtp_dump_name));
184 }
ivica5d6a06c2015-09-17 05:30:24 -0700185 }
186
187 ~VideoAnalyzer() {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100188 for (rtc::PlatformThread* thread : comparison_thread_pool_) {
189 thread->Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700190 delete thread;
191 }
192 }
193
194 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; }
195
ilnik6b826ef2017-06-16 06:53:48 -0700196 void SetSource(test::VideoCapturer* video_capturer, bool respect_sink_wants) {
197 if (respect_sink_wants)
198 captured_frame_forwarder_.SetSource(video_capturer);
199 rtc::VideoSinkWants wants;
200 video_capturer->AddOrUpdateSink(InputInterface(), wants);
201 }
202
stefan889d9652017-07-05 03:03:02 -0700203 void SetCall(Call* call) {
204 rtc::CritScope lock(&crit_);
205 RTC_DCHECK(!call_);
206 call_ = call;
207 }
208
perkja49cbd32016-09-16 07:53:41 -0700209 void SetSendStream(VideoSendStream* stream) {
210 rtc::CritScope lock(&crit_);
211 RTC_DCHECK(!send_stream_);
212 send_stream_ = stream;
213 }
214
philipelfd870db2017-01-23 03:22:15 -0800215 void SetReceiveStream(VideoReceiveStream* stream) {
216 rtc::CritScope lock(&crit_);
217 RTC_DCHECK(!receive_stream_);
218 receive_stream_ = stream;
219 }
220
perkja49cbd32016-09-16 07:53:41 -0700221 rtc::VideoSinkInterface<VideoFrame>* InputInterface() {
222 return &captured_frame_forwarder_;
223 }
224 rtc::VideoSourceInterface<VideoFrame>* OutputInterface() {
225 return &captured_frame_forwarder_;
226 }
227
ivica5d6a06c2015-09-17 05:30:24 -0700228 DeliveryStatus DeliverPacket(MediaType media_type,
Danil Chapovalov292a73e2017-12-07 17:00:40 +0100229 rtc::CopyOnWriteBuffer packet,
ivica5d6a06c2015-09-17 05:30:24 -0700230 const PacketTime& packet_time) override {
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700231 // Ignore timestamps of RTCP packets. They're not synchronized with
232 // RTP packet timestamps and so they would confuse wrap_handler_.
Danil Chapovalov292a73e2017-12-07 17:00:40 +0100233 if (RtpHeaderParser::IsRtcp(packet.cdata(), packet.size())) {
234 return receiver_->DeliverPacket(media_type, std::move(packet),
235 packet_time);
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700236 }
ilnik98436952017-07-13 00:47:03 -0700237
238 if (rtp_file_writer_) {
239 test::RtpPacket p;
Danil Chapovalov292a73e2017-12-07 17:00:40 +0100240 memcpy(p.data, packet.cdata(), packet.size());
241 p.length = packet.size();
242 p.original_length = packet.size();
ilnik98436952017-07-13 00:47:03 -0700243 p.time_ms = clock_->TimeInMilliseconds() - start_ms_;
244 rtp_file_writer_->WritePacket(&p);
245 }
246
Danil Chapovalov292a73e2017-12-07 17:00:40 +0100247 RtpUtility::RtpHeaderParser parser(packet.cdata(), packet.size());
ivica5d6a06c2015-09-17 05:30:24 -0700248 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800249 parser.Parse(&header);
ilnik46a00212017-02-10 09:16:05 -0800250 if (!IsFlexfec(header.payloadType) &&
251 (header.ssrc == ssrc_to_analyze_ ||
252 header.ssrc == rtx_ssrc_to_analyze_)) {
brandtr504b95e2016-12-21 02:54:35 -0800253 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
254 // (FlexFEC and media are sent on different SSRCs, which have different
255 // timestamps spaces.)
ilnik46a00212017-02-10 09:16:05 -0800256 // Also ignore packets from wrong SSRC, but include retransmits.
ivica5d6a06c2015-09-17 05:30:24 -0700257 rtc::CritScope lock(&crit_);
sprang16daaa52016-03-09 01:30:24 -0800258 int64_t timestamp =
259 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
260 recv_times_[timestamp] =
ivica5d6a06c2015-09-17 05:30:24 -0700261 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
262 }
263
Danil Chapovalov292a73e2017-12-07 17:00:40 +0100264 return receiver_->DeliverPacket(media_type, std::move(packet), packet_time);
ivica5d6a06c2015-09-17 05:30:24 -0700265 }
266
pbos14fe7082016-04-20 06:35:56 -0700267 void PreEncodeOnFrame(const VideoFrame& video_frame) {
268 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800269 if (!first_encoded_timestamp_) {
pbos14fe7082016-04-20 06:35:56 -0700270 while (frames_.front().timestamp() != video_frame.timestamp()) {
271 ++dropped_frames_before_first_encode_;
272 frames_.pop_front();
273 RTC_CHECK(!frames_.empty());
274 }
Oskar Sundbom8e07c132018-01-08 16:45:42 +0100275 first_encoded_timestamp_ = video_frame.timestamp();
ilnik3dd5ad92017-02-09 04:58:53 -0800276 }
277 }
278
279 void PostEncodeFrameCallback(const EncodedFrame& encoded_frame) {
280 rtc::CritScope lock(&crit_);
281 if (!first_sent_timestamp_ &&
ilnikcb8c1462017-03-09 09:23:30 -0800282 encoded_frame.stream_id_ == selected_stream_) {
Oskar Sundbom8e07c132018-01-08 16:45:42 +0100283 first_sent_timestamp_ = encoded_frame.timestamp_;
pbos14fe7082016-04-20 06:35:56 -0700284 }
285 }
286
stefan1d8a5062015-10-02 03:39:33 -0700287 bool SendRtp(const uint8_t* packet,
288 size_t length,
289 const PacketOptions& options) override {
sprangce4aef12015-11-02 07:23:20 -0800290 RtpUtility::RtpHeaderParser parser(packet, length);
ivica5d6a06c2015-09-17 05:30:24 -0700291 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800292 parser.Parse(&header);
ivica5d6a06c2015-09-17 05:30:24 -0700293
sprangce4aef12015-11-02 07:23:20 -0800294 int64_t current_time =
295 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
ilnik2a8c2f52017-02-15 02:23:28 -0800296
sprangce4aef12015-11-02 07:23:20 -0800297 bool result = transport_->SendRtp(packet, length, options);
ivica5d6a06c2015-09-17 05:30:24 -0700298 {
299 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800300 if (rtp_timestamp_delta_ == 0 && header.ssrc == ssrc_to_analyze_) {
ilnik1e1c84d2017-02-09 08:32:53 -0800301 RTC_CHECK(static_cast<bool>(first_sent_timestamp_));
ilnik3dd5ad92017-02-09 04:58:53 -0800302 rtp_timestamp_delta_ = header.timestamp - *first_sent_timestamp_;
ilnike67c59e2017-02-09 04:08:56 -0800303 }
ilnik3dd5ad92017-02-09 04:58:53 -0800304
305 if (!IsFlexfec(header.payloadType) && header.ssrc == ssrc_to_analyze_) {
brandtr504b95e2016-12-21 02:54:35 -0800306 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
307 // (FlexFEC and media are sent on different SSRCs, which have different
308 // timestamps spaces.)
ilnik46a00212017-02-10 09:16:05 -0800309 // Also ignore packets from wrong SSRC and retransmits.
brandtr504b95e2016-12-21 02:54:35 -0800310 int64_t timestamp =
311 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
312 send_times_[timestamp] = current_time;
ilnik1e7732c2017-02-23 05:07:56 -0800313
314 if (IsInSelectedSpatialAndTemporalLayer(packet, length, header)) {
brandtr504b95e2016-12-21 02:54:35 -0800315 encoded_frame_sizes_[timestamp] +=
316 length - (header.headerLength + header.paddingLength);
ilnik1e7732c2017-02-23 05:07:56 -0800317 total_media_bytes_ +=
318 length - (header.headerLength + header.paddingLength);
brandtr504b95e2016-12-21 02:54:35 -0800319 }
ilnik1e7732c2017-02-23 05:07:56 -0800320 if (first_sending_time_ == 0)
321 first_sending_time_ = current_time;
322 last_sending_time_ = current_time;
sprangce4aef12015-11-02 07:23:20 -0800323 }
ivica5d6a06c2015-09-17 05:30:24 -0700324 }
sprangce4aef12015-11-02 07:23:20 -0800325 return result;
ivica5d6a06c2015-09-17 05:30:24 -0700326 }
327
328 bool SendRtcp(const uint8_t* packet, size_t length) override {
329 return transport_->SendRtcp(packet, length);
330 }
331
nisseeb83a1a2016-03-21 01:27:56 -0700332 void OnFrame(const VideoFrame& video_frame) override {
ivica5d6a06c2015-09-17 05:30:24 -0700333 int64_t render_time_ms =
334 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
ivica5d6a06c2015-09-17 05:30:24 -0700335
336 rtc::CritScope lock(&crit_);
ilnikdf92c5c2017-02-23 02:08:44 -0800337
338 StartExcludingCpuThreadTime();
339
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700340 int64_t send_timestamp =
sprang16daaa52016-03-09 01:30:24 -0800341 wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_);
ivica5d6a06c2015-09-17 05:30:24 -0700342
sprang16daaa52016-03-09 01:30:24 -0800343 while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) {
nisse97f0b932016-05-26 09:44:40 -0700344 if (!last_rendered_frame_) {
pbos14fe7082016-04-20 06:35:56 -0700345 // No previous frame rendered, this one was dropped after sending but
346 // before rendering.
347 ++dropped_frames_before_rendering_;
kthelgason2bc68642017-02-07 07:02:22 -0800348 } else {
349 AddFrameComparison(frames_.front(), *last_rendered_frame_, true,
350 render_time_ms);
pbos14fe7082016-04-20 06:35:56 -0700351 }
ivica5d6a06c2015-09-17 05:30:24 -0700352 frames_.pop_front();
pbos14fe7082016-04-20 06:35:56 -0700353 RTC_DCHECK(!frames_.empty());
ivica5d6a06c2015-09-17 05:30:24 -0700354 }
355
356 VideoFrame reference_frame = frames_.front();
357 frames_.pop_front();
sprang16daaa52016-03-09 01:30:24 -0800358 int64_t reference_timestamp =
359 wrap_handler_.Unwrap(reference_frame.timestamp());
360 if (send_timestamp == reference_timestamp - 1) {
sprangce4aef12015-11-02 07:23:20 -0800361 // TODO(ivica): Make this work for > 2 streams.
Peter Boströme4499152016-02-05 11:13:28 +0100362 // Look at RTPSender::BuildRTPHeader.
sprangce4aef12015-11-02 07:23:20 -0800363 ++send_timestamp;
364 }
sprang16daaa52016-03-09 01:30:24 -0800365 ASSERT_EQ(reference_timestamp, send_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700366
367 AddFrameComparison(reference_frame, video_frame, false, render_time_ms);
368
Oskar Sundbom8e07c132018-01-08 16:45:42 +0100369 last_rendered_frame_ = video_frame;
ilnikdf92c5c2017-02-23 02:08:44 -0800370
371 StopExcludingCpuThreadTime();
ivica5d6a06c2015-09-17 05:30:24 -0700372 }
373
ivica5d6a06c2015-09-17 05:30:24 -0700374 void Wait() {
375 // Frame comparisons can be very expensive. Wait for test to be done, but
376 // at time-out check if frames_processed is going up. If so, give it more
377 // time, otherwise fail. Hopefully this will reduce test flakiness.
378
Peter Boström8c38e8b2015-11-26 17:45:47 +0100379 stats_polling_thread_.Start();
sprangce4aef12015-11-02 07:23:20 -0800380
ivica5d6a06c2015-09-17 05:30:24 -0700381 int last_frames_processed = -1;
ivica5d6a06c2015-09-17 05:30:24 -0700382 int iteration = 0;
Peter Boström5811a392015-12-10 13:02:50 +0100383 while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) {
ivica5d6a06c2015-09-17 05:30:24 -0700384 int frames_processed;
385 {
386 rtc::CritScope crit(&comparison_lock_);
387 frames_processed = frames_processed_;
388 }
389
390 // Print some output so test infrastructure won't think we've crashed.
391 const char* kKeepAliveMessages[3] = {
392 "Uh, I'm-I'm not quite dead, sir.",
393 "Uh, I-I think uh, I could pull through, sir.",
394 "Actually, I think I'm all right to come with you--"};
395 printf("- %s\n", kKeepAliveMessages[iteration++ % 3]);
396
397 if (last_frames_processed == -1) {
398 last_frames_processed = frames_processed;
399 continue;
400 }
Peter Boströmdd45eb62016-01-19 15:22:32 +0100401 if (frames_processed == last_frames_processed) {
402 EXPECT_GT(frames_processed, last_frames_processed)
403 << "Analyzer stalled while waiting for test to finish.";
404 done_.Set();
405 break;
406 }
ivica5d6a06c2015-09-17 05:30:24 -0700407 last_frames_processed = frames_processed;
408 }
409
410 if (iteration > 0)
411 printf("- Farewell, sweet Concorde!\n");
412
Peter Boström8c38e8b2015-11-26 17:45:47 +0100413 stats_polling_thread_.Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700414 }
415
pbos14fe7082016-04-20 06:35:56 -0700416 rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() {
417 return &pre_encode_proxy_;
418 }
Peter Boströme4499152016-02-05 11:13:28 +0100419 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; }
420
ilnikdf92c5c2017-02-23 02:08:44 -0800421 void StartMeasuringCpuProcessTime() {
422 rtc::CritScope lock(&cpu_measurement_lock_);
423 cpu_time_ -= rtc::GetProcessCpuTimeNanos();
424 wallclock_time_ -= rtc::SystemTimeNanos();
425 }
426
427 void StopMeasuringCpuProcessTime() {
428 rtc::CritScope lock(&cpu_measurement_lock_);
429 cpu_time_ += rtc::GetProcessCpuTimeNanos();
430 wallclock_time_ += rtc::SystemTimeNanos();
431 }
432
433 void StartExcludingCpuThreadTime() {
434 rtc::CritScope lock(&cpu_measurement_lock_);
435 cpu_time_ += rtc::GetThreadCpuTimeNanos();
436 }
437
438 void StopExcludingCpuThreadTime() {
439 rtc::CritScope lock(&cpu_measurement_lock_);
440 cpu_time_ -= rtc::GetThreadCpuTimeNanos();
441 }
442
443 double GetCpuUsagePercent() {
444 rtc::CritScope lock(&cpu_measurement_lock_);
445 return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0;
446 }
447
sprangce4aef12015-11-02 07:23:20 -0800448 test::LayerFilteringTransport* const transport_;
ivica5d6a06c2015-09-17 05:30:24 -0700449 PacketReceiver* receiver_;
ivica5d6a06c2015-09-17 05:30:24 -0700450
451 private:
452 struct FrameComparison {
453 FrameComparison()
454 : dropped(false),
nissedf2ceb82016-12-15 06:29:53 -0800455 input_time_ms(0),
ivica5d6a06c2015-09-17 05:30:24 -0700456 send_time_ms(0),
457 recv_time_ms(0),
458 render_time_ms(0),
459 encoded_frame_size(0) {}
460
461 FrameComparison(const VideoFrame& reference,
462 const VideoFrame& render,
463 bool dropped,
nissedf2ceb82016-12-15 06:29:53 -0800464 int64_t input_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700465 int64_t send_time_ms,
466 int64_t recv_time_ms,
467 int64_t render_time_ms,
468 size_t encoded_frame_size)
469 : reference(reference),
470 render(render),
471 dropped(dropped),
nissedf2ceb82016-12-15 06:29:53 -0800472 input_time_ms(input_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700473 send_time_ms(send_time_ms),
474 recv_time_ms(recv_time_ms),
475 render_time_ms(render_time_ms),
476 encoded_frame_size(encoded_frame_size) {}
477
nissedf2ceb82016-12-15 06:29:53 -0800478 FrameComparison(bool dropped,
479 int64_t input_time_ms,
480 int64_t send_time_ms,
481 int64_t recv_time_ms,
482 int64_t render_time_ms,
483 size_t encoded_frame_size)
484 : dropped(dropped),
485 input_time_ms(input_time_ms),
486 send_time_ms(send_time_ms),
487 recv_time_ms(recv_time_ms),
488 render_time_ms(render_time_ms),
489 encoded_frame_size(encoded_frame_size) {}
490
491 rtc::Optional<VideoFrame> reference;
492 rtc::Optional<VideoFrame> render;
ivica5d6a06c2015-09-17 05:30:24 -0700493 bool dropped;
nissedf2ceb82016-12-15 06:29:53 -0800494 int64_t input_time_ms;
ivica5d6a06c2015-09-17 05:30:24 -0700495 int64_t send_time_ms;
496 int64_t recv_time_ms;
497 int64_t render_time_ms;
498 size_t encoded_frame_size;
499 };
500
501 struct Sample {
ivica8d15bd62015-10-07 02:43:12 -0700502 Sample(int dropped,
503 int64_t input_time_ms,
504 int64_t send_time_ms,
505 int64_t recv_time_ms,
506 int64_t render_time_ms,
507 size_t encoded_frame_size,
ivica5d6a06c2015-09-17 05:30:24 -0700508 double psnr,
ivica8d15bd62015-10-07 02:43:12 -0700509 double ssim)
ivica5d6a06c2015-09-17 05:30:24 -0700510 : dropped(dropped),
511 input_time_ms(input_time_ms),
512 send_time_ms(send_time_ms),
513 recv_time_ms(recv_time_ms),
ivica8d15bd62015-10-07 02:43:12 -0700514 render_time_ms(render_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700515 encoded_frame_size(encoded_frame_size),
516 psnr(psnr),
ivica8d15bd62015-10-07 02:43:12 -0700517 ssim(ssim) {}
ivica5d6a06c2015-09-17 05:30:24 -0700518
ivica8d15bd62015-10-07 02:43:12 -0700519 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;
526 double ssim;
ivica5d6a06c2015-09-17 05:30:24 -0700527 };
528
Peter Boströme4499152016-02-05 11:13:28 +0100529 // This class receives the send-side OnEncodeTiming and is provided to not
530 // conflict with the receiver-side pre_decode_callback.
531 class OnEncodeTimingProxy : public EncodedFrameObserver {
532 public:
533 explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {}
534
ilnik3dd5ad92017-02-09 04:58:53 -0800535 void EncodedFrameCallback(const EncodedFrame& frame) override {
536 parent_->PostEncodeFrameCallback(frame);
537 }
Peter Boströme4499152016-02-05 11:13:28 +0100538
539 private:
540 VideoAnalyzer* const parent_;
541 };
542
pbos14fe7082016-04-20 06:35:56 -0700543 // This class receives the send-side OnFrame callback and is provided to not
544 // conflict with the receiver-side renderer callback.
545 class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> {
546 public:
547 explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {}
548
549 void OnFrame(const VideoFrame& video_frame) override {
550 parent_->PreEncodeOnFrame(video_frame);
551 }
552
553 private:
554 VideoAnalyzer* const parent_;
555 };
556
ilnik1e7732c2017-02-23 05:07:56 -0800557 bool IsInSelectedSpatialAndTemporalLayer(const uint8_t* packet,
558 size_t length,
559 const RTPHeader& header) {
ilnik863f03b2017-07-11 02:38:36 -0700560 if (header.payloadType != test::CallTest::kPayloadTypeVP9 &&
561 header.payloadType != test::CallTest::kPayloadTypeVP8) {
ilnik1e7732c2017-02-23 05:07:56 -0800562 return true;
563 } else {
564 // Get VP8 and VP9 specific header to check layers indexes.
565 const uint8_t* payload = packet + header.headerLength;
566 const size_t payload_length = length - header.headerLength;
567 const size_t payload_data_length = payload_length - header.paddingLength;
ilnik863f03b2017-07-11 02:38:36 -0700568 const bool is_vp8 = header.payloadType == test::CallTest::kPayloadTypeVP8;
ilnik1e7732c2017-02-23 05:07:56 -0800569 std::unique_ptr<RtpDepacketizer> depacketizer(
570 RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9));
571 RtpDepacketizer::ParsedPayload parsed_payload;
572 bool result =
573 depacketizer->Parse(&parsed_payload, payload, payload_data_length);
574 RTC_DCHECK(result);
575 const int temporal_idx = static_cast<int>(
576 is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx
577 : parsed_payload.type.Video.codecHeader.VP9.temporal_idx);
578 const int spatial_idx = static_cast<int>(
579 is_vp8 ? kNoSpatialIdx
580 : parsed_payload.type.Video.codecHeader.VP9.spatial_idx);
581 return (selected_tl_ < 0 || temporal_idx == kNoTemporalIdx ||
582 temporal_idx <= selected_tl_) &&
583 (selected_sl_ < 0 || spatial_idx == kNoSpatialIdx ||
584 spatial_idx <= selected_sl_);
585 }
586 }
587
ivica5d6a06c2015-09-17 05:30:24 -0700588 void AddFrameComparison(const VideoFrame& reference,
589 const VideoFrame& render,
590 bool dropped,
591 int64_t render_time_ms)
danilchapa37de392017-09-09 04:17:22 -0700592 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
sprange1f2f1f2016-02-01 02:04:52 -0800593 int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp());
594 int64_t send_time_ms = send_times_[reference_timestamp];
595 send_times_.erase(reference_timestamp);
596 int64_t recv_time_ms = recv_times_[reference_timestamp];
597 recv_times_.erase(reference_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700598
sprangce4aef12015-11-02 07:23:20 -0800599 // TODO(ivica): Make this work for > 2 streams.
sprange1f2f1f2016-02-01 02:04:52 -0800600 auto it = encoded_frame_sizes_.find(reference_timestamp);
sprangce4aef12015-11-02 07:23:20 -0800601 if (it == encoded_frame_sizes_.end())
sprange1f2f1f2016-02-01 02:04:52 -0800602 it = encoded_frame_sizes_.find(reference_timestamp - 1);
sprangce4aef12015-11-02 07:23:20 -0800603 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second;
604 if (it != encoded_frame_sizes_.end())
605 encoded_frame_sizes_.erase(it);
ivica5d6a06c2015-09-17 05:30:24 -0700606
ivica5d6a06c2015-09-17 05:30:24 -0700607 rtc::CritScope crit(&comparison_lock_);
stefanb1797672016-08-11 07:00:57 -0700608 if (comparisons_.size() < kMaxComparisons) {
nissedf2ceb82016-12-15 06:29:53 -0800609 comparisons_.push_back(FrameComparison(reference, render, dropped,
610 reference.ntp_time_ms(),
611 send_time_ms, recv_time_ms,
612 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700613 } else {
nissedf2ceb82016-12-15 06:29:53 -0800614 comparisons_.push_back(FrameComparison(dropped,
615 reference.ntp_time_ms(),
616 send_time_ms, recv_time_ms,
617 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700618 }
Peter Boström5811a392015-12-10 13:02:50 +0100619 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700620 }
621
tommi0f8b4032017-02-22 11:22:05 -0800622 static void PollStatsThread(void* obj) {
623 static_cast<VideoAnalyzer*>(obj)->PollStats();
ivica5d6a06c2015-09-17 05:30:24 -0700624 }
625
tommi0f8b4032017-02-22 11:22:05 -0800626 void PollStats() {
627 while (!done_.Wait(kSendStatsPollingIntervalMs)) {
628 rtc::CritScope crit(&comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700629
stefan889d9652017-07-05 03:03:02 -0700630 Call::Stats call_stats = call_->GetStats();
631 send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps);
632
tommi0f8b4032017-02-22 11:22:05 -0800633 VideoSendStream::Stats send_stats = send_stream_->GetStats();
634 // It's not certain that we yet have estimates for any of these stats.
635 // Check that they are positive before mixing them in.
636 if (send_stats.encode_frame_rate > 0)
637 encode_frame_rate_.AddSample(send_stats.encode_frame_rate);
638 if (send_stats.avg_encode_time_ms > 0)
639 encode_time_ms_.AddSample(send_stats.avg_encode_time_ms);
640 if (send_stats.encode_usage_percent > 0)
641 encode_usage_percent_.AddSample(send_stats.encode_usage_percent);
642 if (send_stats.media_bitrate_bps > 0)
643 media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps);
stefan889d9652017-07-05 03:03:02 -0700644 size_t fec_bytes = 0;
645 for (auto kv : send_stats.substreams) {
646 fec_bytes += kv.second.rtp_stats.fec.payload_bytes +
647 kv.second.rtp_stats.fec.padding_bytes;
648 }
649 fec_bitrate_bps_.AddSample((fec_bytes - last_fec_bytes_) * 8);
650 last_fec_bytes_ = fec_bytes;
philipelfd870db2017-01-23 03:22:15 -0800651
tommi0f8b4032017-02-22 11:22:05 -0800652 if (receive_stream_ != nullptr) {
653 VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats();
654 if (receive_stats.decode_ms > 0)
655 decode_time_ms_.AddSample(receive_stats.decode_ms);
656 if (receive_stats.max_decode_ms > 0)
657 decode_time_max_ms_.AddSample(receive_stats.max_decode_ms);
658 }
ilnikdaa574d2017-03-01 06:46:05 -0800659
660 memory_usage_.AddSample(rtc::GetProcessResidentSizeBytes());
philipelfd870db2017-01-23 03:22:15 -0800661 }
ivica5d6a06c2015-09-17 05:30:24 -0700662 }
663
664 static bool FrameComparisonThread(void* obj) {
665 return static_cast<VideoAnalyzer*>(obj)->CompareFrames();
666 }
667
668 bool CompareFrames() {
669 if (AllFramesRecorded())
670 return false;
671
ivica5d6a06c2015-09-17 05:30:24 -0700672 FrameComparison comparison;
673
674 if (!PopComparison(&comparison)) {
675 // Wait until new comparison task is available, or test is done.
676 // If done, wake up remaining threads waiting.
Peter Boström5811a392015-12-10 13:02:50 +0100677 comparison_available_event_.Wait(1000);
ivica5d6a06c2015-09-17 05:30:24 -0700678 if (AllFramesRecorded()) {
Peter Boström5811a392015-12-10 13:02:50 +0100679 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700680 return false;
681 }
682 return true; // Try again.
683 }
684
ilnikdf92c5c2017-02-23 02:08:44 -0800685 StartExcludingCpuThreadTime();
686
ivica5d6a06c2015-09-17 05:30:24 -0700687 PerformFrameComparison(comparison);
688
ilnikdf92c5c2017-02-23 02:08:44 -0800689 StopExcludingCpuThreadTime();
690
ivica5d6a06c2015-09-17 05:30:24 -0700691 if (FrameProcessed()) {
692 PrintResults();
693 if (graph_data_output_file_)
694 PrintSamplesToFile();
Peter Boström5811a392015-12-10 13:02:50 +0100695 done_.Set();
696 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700697 return false;
698 }
699
700 return true;
701 }
702
703 bool PopComparison(FrameComparison* comparison) {
704 rtc::CritScope crit(&comparison_lock_);
705 // If AllFramesRecorded() is true, it means we have already popped
706 // frames_to_process_ frames from comparisons_, so there is no more work
707 // for this thread to be done. frames_processed_ might still be lower if
708 // all comparisons are not done, but those frames are currently being
709 // worked on by other threads.
710 if (comparisons_.empty() || AllFramesRecorded())
711 return false;
712
713 *comparison = comparisons_.front();
714 comparisons_.pop_front();
715
716 FrameRecorded();
717 return true;
718 }
719
720 // Increment counter for number of frames received for comparison.
721 void FrameRecorded() {
722 rtc::CritScope crit(&comparison_lock_);
723 ++frames_recorded_;
724 }
725
726 // Returns true if all frames to be compared have been taken from the queue.
727 bool AllFramesRecorded() {
728 rtc::CritScope crit(&comparison_lock_);
729 assert(frames_recorded_ <= frames_to_process_);
730 return frames_recorded_ == frames_to_process_;
731 }
732
733 // Increase count of number of frames processed. Returns true if this was the
734 // last frame to be processed.
735 bool FrameProcessed() {
736 rtc::CritScope crit(&comparison_lock_);
737 ++frames_processed_;
738 assert(frames_processed_ <= frames_to_process_);
739 return frames_processed_ == frames_to_process_;
740 }
741
742 void PrintResults() {
ilnikdf92c5c2017-02-23 02:08:44 -0800743 StopMeasuringCpuProcessTime();
ivica5d6a06c2015-09-17 05:30:24 -0700744 rtc::CritScope crit(&comparison_lock_);
Stefan Holmer32e930f2018-02-09 09:43:45 +0100745 // Record the time from the last freeze until the last rendered frame to
746 // ensure we cover the full timespan of the session. Otherwise the metric
747 // would penalize an early freeze followed by no freezes until the end.
748 time_between_freezes_.AddSample(last_render_time_ - last_unfreeze_time_ms_);
ivica5d6a06c2015-09-17 05:30:24 -0700749 PrintResult("psnr", psnr_, " dB");
tnakamura3123cbc2016-02-10 11:21:51 -0800750 PrintResult("ssim", ssim_, " score");
stefan2da7a242017-03-30 01:02:15 -0700751 PrintResult("sender_time", sender_time_, " ms");
752 PrintResult("receiver_time", receiver_time_, " ms");
ivica5d6a06c2015-09-17 05:30:24 -0700753 PrintResult("total_delay_incl_network", end_to_end_, " ms");
754 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
ivica5d6a06c2015-09-17 05:30:24 -0700755 PrintResult("encode_frame_rate", encode_frame_rate_, " fps");
philipelfd870db2017-01-23 03:22:15 -0800756 PrintResult("encode_time", encode_time_ms_, " ms");
philipelfd870db2017-01-23 03:22:15 -0800757 PrintResult("media_bitrate", media_bitrate_bps_, " bps");
stefan889d9652017-07-05 03:03:02 -0700758 PrintResult("fec_bitrate", fec_bitrate_bps_, " bps");
759 PrintResult("send_bandwidth", send_bandwidth_bps_, " bps");
Stefan Holmer32e930f2018-02-09 09:43:45 +0100760 PrintResult("time_between_freezes", time_between_freezes_, " ms");
philipelfd870db2017-01-23 03:22:15 -0800761
ilnik59cac992017-07-25 05:45:03 -0700762 if (worst_frame_) {
Edward Lemurd1d67432018-01-02 11:54:37 +0100763 test::PrintResult("min_psnr", "", test_label_.c_str(), worst_frame_->psnr,
764 "dB", false);
ilnik59cac992017-07-25 05:45:03 -0700765 }
766
philipelfd870db2017-01-23 03:22:15 -0800767 if (receive_stream_ != nullptr) {
768 PrintResult("decode_time", decode_time_ms_, " ms");
philipelfd870db2017-01-23 03:22:15 -0800769 }
ivica5d6a06c2015-09-17 05:30:24 -0700770
Edward Lemurd1d67432018-01-02 11:54:37 +0100771 test::PrintResult("dropped_frames", "", test_label_.c_str(),
772 dropped_frames_, "frames", false);
773 test::PrintResult("cpu_usage", "", test_label_.c_str(),
774 GetCpuUsagePercent(), "%", false);
ilnikdaa574d2017-03-01 06:46:05 -0800775
776#if defined(WEBRTC_WIN)
777 // On Linux and Mac in Resident Set some unused pages may be counted.
778 // Therefore this metric will depend on order in which tests are run and
779 // will be flaky.
780 PrintResult("memory_usage", memory_usage_, " bytes");
781#endif
ilnik59cac992017-07-25 05:45:03 -0700782
ilnikee42d192017-08-22 07:16:20 -0700783 // Saving only the worst frame for manual analysis. Intention here is to
784 // only detect video corruptions and not to track picture quality. Thus,
785 // jpeg is used here.
oprypin9b2f20c2017-08-29 05:51:57 -0700786 if (FLAG_save_worst_frame && worst_frame_) {
ilnikee42d192017-08-22 07:16:20 -0700787 std::string output_dir;
Edward Lemuraf8659a2017-09-27 14:46:24 +0200788 test::GetTestArtifactsDir(&output_dir);
ilnikee42d192017-08-22 07:16:20 -0700789 std::string output_path =
790 rtc::Pathname(output_dir, test_label_ + ".jpg").pathname();
Mirko Bonadei675513b2017-11-09 11:09:25 +0100791 RTC_LOG(LS_INFO) << "Saving worst frame to " << output_path;
ilnikee42d192017-08-22 07:16:20 -0700792 test::JpegFrameWriter frame_writer(output_path);
793 RTC_CHECK(frame_writer.WriteFrame(worst_frame_->frame,
794 100 /*best quality*/));
ilnik59cac992017-07-25 05:45:03 -0700795 }
ilnikdaa574d2017-03-01 06:46:05 -0800796
ilnik9ae0d762017-02-15 00:53:12 -0800797 // Disable quality check for quick test, as quality checks may fail
798 // because too few samples were collected.
799 if (!is_quick_test_enabled_) {
800 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
801 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_);
802 }
ivica5d6a06c2015-09-17 05:30:24 -0700803 }
804
805 void PerformFrameComparison(const FrameComparison& comparison) {
806 // Perform expensive psnr and ssim calculations while not holding lock.
stefanb1797672016-08-11 07:00:57 -0700807 double psnr = -1.0;
808 double ssim = -1.0;
ilnik6b826ef2017-06-16 06:53:48 -0700809 if (comparison.reference && !comparison.dropped) {
nissedf2ceb82016-12-15 06:29:53 -0800810 psnr = I420PSNR(&*comparison.reference, &*comparison.render);
811 ssim = I420SSIM(&*comparison.reference, &*comparison.render);
stefanb1797672016-08-11 07:00:57 -0700812 }
ivica5d6a06c2015-09-17 05:30:24 -0700813
ivica5d6a06c2015-09-17 05:30:24 -0700814 rtc::CritScope crit(&comparison_lock_);
ilnik59cac992017-07-25 05:45:03 -0700815
816 if (psnr >= 0.0 && (!worst_frame_ || worst_frame_->psnr > psnr)) {
817 worst_frame_.emplace(FrameWithPsnr{psnr, *comparison.render});
818 }
819
ivica5d6a06c2015-09-17 05:30:24 -0700820 if (graph_data_output_file_) {
nissedf2ceb82016-12-15 06:29:53 -0800821 samples_.push_back(Sample(
822 comparison.dropped, comparison.input_time_ms, comparison.send_time_ms,
823 comparison.recv_time_ms, comparison.render_time_ms,
824 comparison.encoded_frame_size, psnr, ssim));
ivica5d6a06c2015-09-17 05:30:24 -0700825 }
stefanb1797672016-08-11 07:00:57 -0700826 if (psnr >= 0.0)
827 psnr_.AddSample(psnr);
828 if (ssim >= 0.0)
829 ssim_.AddSample(ssim);
ivica5d6a06c2015-09-17 05:30:24 -0700830
831 if (comparison.dropped) {
832 ++dropped_frames_;
833 return;
834 }
Stefan Holmer32e930f2018-02-09 09:43:45 +0100835 if (last_unfreeze_time_ms_ == 0)
836 last_unfreeze_time_ms_ = comparison.render_time_ms;
837 if (last_render_time_ != 0) {
838 const int64_t render_delta_ms =
839 comparison.render_time_ms - last_render_time_;
840 rendered_delta_.AddSample(render_delta_ms);
841 if (last_render_delta_ms_ != 0 &&
842 render_delta_ms - last_render_delta_ms_ > 150) {
843 time_between_freezes_.AddSample(last_render_time_ -
844 last_unfreeze_time_ms_);
845 last_unfreeze_time_ms_ = comparison.render_time_ms;
846 }
847 last_render_delta_ms_ = render_delta_ms;
848 }
ivica5d6a06c2015-09-17 05:30:24 -0700849 last_render_time_ = comparison.render_time_ms;
850
nissedf2ceb82016-12-15 06:29:53 -0800851 sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms);
brandtr504b95e2016-12-21 02:54:35 -0800852 if (comparison.recv_time_ms > 0) {
853 // If recv_time_ms == 0, this frame consisted of a packets which were all
854 // lost in the transport. Since we were able to render the frame, however,
855 // the dropped packets were recovered by FlexFEC. The FlexFEC recovery
856 // happens internally in Call, and we can therefore here not know which
857 // FEC packets that protected the lost media packets. Consequently, we
858 // were not able to record a meaningful recv_time_ms. We therefore skip
859 // this sample.
860 //
861 // The reasoning above does not hold for ULPFEC and RTX, as for those
862 // strategies the timestamp of the received packets is set to the
863 // timestamp of the protected/retransmitted media packet. I.e., then
864 // recv_time_ms != 0, even though the media packets were lost.
865 receiver_time_.AddSample(comparison.render_time_ms -
866 comparison.recv_time_ms);
867 }
nissedf2ceb82016-12-15 06:29:53 -0800868 end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms);
ivica5d6a06c2015-09-17 05:30:24 -0700869 encoded_frame_size_.AddSample(comparison.encoded_frame_size);
870 }
871
872 void PrintResult(const char* result_type,
873 test::Statistics stats,
874 const char* unit) {
Edward Lemurd1d67432018-01-02 11:54:37 +0100875 test::PrintResultMeanAndError(result_type, "", test_label_.c_str(),
876 stats.Mean(), stats.StandardDeviation(), unit,
877 false);
ivica5d6a06c2015-09-17 05:30:24 -0700878 }
879
880 void PrintSamplesToFile(void) {
881 FILE* out = graph_data_output_file_;
882 rtc::CritScope crit(&comparison_lock_);
883 std::sort(samples_.begin(), samples_.end(),
884 [](const Sample& A, const Sample& B) -> bool {
885 return A.input_time_ms < B.input_time_ms;
886 });
887
sprangce4aef12015-11-02 07:23:20 -0800888 fprintf(out, "%s\n", graph_title_.c_str());
ivica5d6a06c2015-09-17 05:30:24 -0700889 fprintf(out, "%" PRIuS "\n", samples_.size());
890 fprintf(out,
891 "dropped "
892 "input_time_ms "
893 "send_time_ms "
894 "recv_time_ms "
ivica8d15bd62015-10-07 02:43:12 -0700895 "render_time_ms "
ivica5d6a06c2015-09-17 05:30:24 -0700896 "encoded_frame_size "
897 "psnr "
898 "ssim "
ivica8d15bd62015-10-07 02:43:12 -0700899 "encode_time_ms\n");
ivica5d6a06c2015-09-17 05:30:24 -0700900 for (const Sample& sample : samples_) {
ivica8d15bd62015-10-07 02:43:12 -0700901 fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS
Niels Möller6b642f72017-12-08 14:11:14 +0100902 " %lf %lf\n",
ivica8d15bd62015-10-07 02:43:12 -0700903 sample.dropped, sample.input_time_ms, sample.send_time_ms,
904 sample.recv_time_ms, sample.render_time_ms,
Niels Möller6b642f72017-12-08 14:11:14 +0100905 sample.encoded_frame_size, sample.psnr, sample.ssim);
ivica5d6a06c2015-09-17 05:30:24 -0700906 }
907 }
908
ilnik1e7732c2017-02-23 05:07:56 -0800909 double GetAverageMediaBitrateBps() {
910 if (last_sending_time_ == first_sending_time_) {
911 return 0;
912 } else {
913 return static_cast<double>(total_media_bytes_) * 8 /
914 (last_sending_time_ - first_sending_time_) *
915 rtc::kNumMillisecsPerSec;
916 }
917 }
918
perkja49cbd32016-09-16 07:53:41 -0700919 // Implements VideoSinkInterface to receive captured frames from a
920 // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act
921 // as a source to VideoSendStream.
922 // It forwards all input frames to the VideoAnalyzer for later comparison and
923 // forwards the captured frames to the VideoSendStream.
924 class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>,
925 public rtc::VideoSourceInterface<VideoFrame> {
926 public:
ilnik6b826ef2017-06-16 06:53:48 -0700927 explicit CapturedFrameForwarder(VideoAnalyzer* analyzer, Clock* clock)
928 : analyzer_(analyzer),
929 send_stream_input_(nullptr),
930 video_capturer_(nullptr),
931 clock_(clock) {}
932
933 void SetSource(test::VideoCapturer* video_capturer) {
934 video_capturer_ = video_capturer;
935 }
perkja49cbd32016-09-16 07:53:41 -0700936
937 private:
938 void OnFrame(const VideoFrame& video_frame) override {
939 VideoFrame copy = video_frame;
ilnik3dd5ad92017-02-09 04:58:53 -0800940 // Frames from the capturer does not have a rtp timestamp.
941 // Create one so it can be used for comparison.
942 RTC_DCHECK_EQ(0, video_frame.timestamp());
ilnik6b826ef2017-06-16 06:53:48 -0700943 if (video_frame.ntp_time_ms() == 0)
944 copy.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
perkja49cbd32016-09-16 07:53:41 -0700945 copy.set_timestamp(copy.ntp_time_ms() * 90);
ilnik3dd5ad92017-02-09 04:58:53 -0800946 analyzer_->AddCapturedFrameForComparison(copy);
perkja49cbd32016-09-16 07:53:41 -0700947 rtc::CritScope lock(&crit_);
948 if (send_stream_input_)
ilnikb82ac6a2017-05-02 00:48:41 -0700949 send_stream_input_->OnFrame(copy);
perkja49cbd32016-09-16 07:53:41 -0700950 }
951
952 // Called when |send_stream_.SetSource()| is called.
953 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
954 const rtc::VideoSinkWants& wants) override {
ilnik267041c2017-06-27 07:21:01 -0700955 {
956 rtc::CritScope lock(&crit_);
957 RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
958 send_stream_input_ = sink;
959 }
ilnik6b826ef2017-06-16 06:53:48 -0700960 if (video_capturer_) {
961 video_capturer_->AddOrUpdateSink(this, wants);
962 }
perkja49cbd32016-09-16 07:53:41 -0700963 }
964
965 // Called by |send_stream_| when |send_stream_.SetSource()| is called.
966 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {
967 rtc::CritScope lock(&crit_);
968 RTC_DCHECK(sink == send_stream_input_);
969 send_stream_input_ = nullptr;
970 }
971
972 VideoAnalyzer* const analyzer_;
973 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -0700974 rtc::VideoSinkInterface<VideoFrame>* send_stream_input_
975 RTC_GUARDED_BY(crit_);
ilnik6b826ef2017-06-16 06:53:48 -0700976 test::VideoCapturer* video_capturer_;
977 Clock* clock_;
perkja49cbd32016-09-16 07:53:41 -0700978 };
979
980 void AddCapturedFrameForComparison(const VideoFrame& video_frame) {
981 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800982 frames_.push_back(video_frame);
perkja49cbd32016-09-16 07:53:41 -0700983 }
984
stefan889d9652017-07-05 03:03:02 -0700985 Call* call_;
perkja49cbd32016-09-16 07:53:41 -0700986 VideoSendStream* send_stream_;
philipelfd870db2017-01-23 03:22:15 -0800987 VideoReceiveStream* receive_stream_;
perkja49cbd32016-09-16 07:53:41 -0700988 CapturedFrameForwarder captured_frame_forwarder_;
ivica5d6a06c2015-09-17 05:30:24 -0700989 const std::string test_label_;
990 FILE* const graph_data_output_file_;
sprangce4aef12015-11-02 07:23:20 -0800991 const std::string graph_title_;
992 const uint32_t ssrc_to_analyze_;
ilnik46a00212017-02-10 09:16:05 -0800993 const uint32_t rtx_ssrc_to_analyze_;
ilnikcb8c1462017-03-09 09:23:30 -0800994 const size_t selected_stream_;
ilnik1e7732c2017-02-23 05:07:56 -0800995 const int selected_sl_;
996 const int selected_tl_;
pbos14fe7082016-04-20 06:35:56 -0700997 PreEncodeProxy pre_encode_proxy_;
Peter Boströme4499152016-02-05 11:13:28 +0100998 OnEncodeTimingProxy encode_timing_proxy_;
danilchapa37de392017-09-09 04:17:22 -0700999 std::vector<Sample> samples_ RTC_GUARDED_BY(comparison_lock_);
danilchapa37de392017-09-09 04:17:22 -07001000 test::Statistics sender_time_ RTC_GUARDED_BY(comparison_lock_);
1001 test::Statistics receiver_time_ RTC_GUARDED_BY(comparison_lock_);
1002 test::Statistics psnr_ RTC_GUARDED_BY(comparison_lock_);
1003 test::Statistics ssim_ RTC_GUARDED_BY(comparison_lock_);
1004 test::Statistics end_to_end_ RTC_GUARDED_BY(comparison_lock_);
1005 test::Statistics rendered_delta_ RTC_GUARDED_BY(comparison_lock_);
1006 test::Statistics encoded_frame_size_ RTC_GUARDED_BY(comparison_lock_);
1007 test::Statistics encode_frame_rate_ RTC_GUARDED_BY(comparison_lock_);
1008 test::Statistics encode_time_ms_ RTC_GUARDED_BY(comparison_lock_);
1009 test::Statistics encode_usage_percent_ RTC_GUARDED_BY(comparison_lock_);
1010 test::Statistics decode_time_ms_ RTC_GUARDED_BY(comparison_lock_);
1011 test::Statistics decode_time_max_ms_ RTC_GUARDED_BY(comparison_lock_);
1012 test::Statistics media_bitrate_bps_ RTC_GUARDED_BY(comparison_lock_);
1013 test::Statistics fec_bitrate_bps_ RTC_GUARDED_BY(comparison_lock_);
1014 test::Statistics send_bandwidth_bps_ RTC_GUARDED_BY(comparison_lock_);
1015 test::Statistics memory_usage_ RTC_GUARDED_BY(comparison_lock_);
Stefan Holmer32e930f2018-02-09 09:43:45 +01001016 test::Statistics time_between_freezes_ RTC_GUARDED_BY(comparison_lock_);
ilnikdaa574d2017-03-01 06:46:05 -08001017
ilnik59cac992017-07-25 05:45:03 -07001018 struct FrameWithPsnr {
1019 double psnr;
1020 VideoFrame frame;
1021 };
1022
1023 // Rendered frame with worst PSNR is saved for further analysis.
danilchapa37de392017-09-09 04:17:22 -07001024 rtc::Optional<FrameWithPsnr> worst_frame_ RTC_GUARDED_BY(comparison_lock_);
ilnik59cac992017-07-25 05:45:03 -07001025
stefan889d9652017-07-05 03:03:02 -07001026 size_t last_fec_bytes_;
ivica5d6a06c2015-09-17 05:30:24 -07001027
1028 const int frames_to_process_;
1029 int frames_recorded_;
1030 int frames_processed_;
1031 int dropped_frames_;
pbos14fe7082016-04-20 06:35:56 -07001032 int dropped_frames_before_first_encode_;
1033 int dropped_frames_before_rendering_;
ivica5d6a06c2015-09-17 05:30:24 -07001034 int64_t last_render_time_;
Stefan Holmer32e930f2018-02-09 09:43:45 +01001035 int64_t last_render_delta_ms_;
1036 int64_t last_unfreeze_time_ms_;
ivica5d6a06c2015-09-17 05:30:24 -07001037 uint32_t rtp_timestamp_delta_;
ilnik1e7732c2017-02-23 05:07:56 -08001038 int64_t total_media_bytes_;
1039 int64_t first_sending_time_;
1040 int64_t last_sending_time_;
ivica5d6a06c2015-09-17 05:30:24 -07001041
danilchapa37de392017-09-09 04:17:22 -07001042 int64_t cpu_time_ RTC_GUARDED_BY(cpu_measurement_lock_);
1043 int64_t wallclock_time_ RTC_GUARDED_BY(cpu_measurement_lock_);
ilnikdf92c5c2017-02-23 02:08:44 -08001044 rtc::CriticalSection cpu_measurement_lock_;
1045
ivica5d6a06c2015-09-17 05:30:24 -07001046 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -07001047 std::deque<VideoFrame> frames_ RTC_GUARDED_BY(crit_);
1048 rtc::Optional<VideoFrame> last_rendered_frame_ RTC_GUARDED_BY(crit_);
1049 rtc::TimestampWrapAroundHandler wrap_handler_ RTC_GUARDED_BY(crit_);
1050 std::map<int64_t, int64_t> send_times_ RTC_GUARDED_BY(crit_);
1051 std::map<int64_t, int64_t> recv_times_ RTC_GUARDED_BY(crit_);
1052 std::map<int64_t, size_t> encoded_frame_sizes_ RTC_GUARDED_BY(crit_);
1053 rtc::Optional<uint32_t> first_encoded_timestamp_ RTC_GUARDED_BY(crit_);
1054 rtc::Optional<uint32_t> first_sent_timestamp_ RTC_GUARDED_BY(crit_);
ivica5d6a06c2015-09-17 05:30:24 -07001055 const double avg_psnr_threshold_;
1056 const double avg_ssim_threshold_;
ilnik9ae0d762017-02-15 00:53:12 -08001057 bool is_quick_test_enabled_;
ivica5d6a06c2015-09-17 05:30:24 -07001058
1059 rtc::CriticalSection comparison_lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +01001060 std::vector<rtc::PlatformThread*> comparison_thread_pool_;
1061 rtc::PlatformThread stats_polling_thread_;
Peter Boström5811a392015-12-10 13:02:50 +01001062 rtc::Event comparison_available_event_;
danilchapa37de392017-09-09 04:17:22 -07001063 std::deque<FrameComparison> comparisons_ RTC_GUARDED_BY(comparison_lock_);
Peter Boström5811a392015-12-10 13:02:50 +01001064 rtc::Event done_;
ilnik98436952017-07-13 00:47:03 -07001065
1066 std::unique_ptr<test::RtpFileWriter> rtp_file_writer_;
1067 Clock* const clock_;
1068 const int64_t start_ms_;
ivica5d6a06c2015-09-17 05:30:24 -07001069};
1070
palmkviste75f2042016-09-28 06:19:48 -07001071VideoQualityTest::VideoQualityTest()
minyue20c84cc2017-04-10 16:57:57 -07001072 : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) {
1073 payload_type_map_ = test::CallTest::payload_type_map_;
1074 RTC_DCHECK(payload_type_map_.find(kPayloadTypeH264) ==
1075 payload_type_map_.end());
1076 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP8) ==
1077 payload_type_map_.end());
1078 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP9) ==
1079 payload_type_map_.end());
1080 payload_type_map_[kPayloadTypeH264] = webrtc::MediaType::VIDEO;
1081 payload_type_map_[kPayloadTypeVP8] = webrtc::MediaType::VIDEO;
1082 payload_type_map_[kPayloadTypeVP9] = webrtc::MediaType::VIDEO;
1083}
ivica5d6a06c2015-09-17 05:30:24 -07001084
Ying Wang3b790f32018-01-19 17:58:57 +01001085VideoQualityTest::VideoQualityTest(
1086 std::unique_ptr<FecController> fec_controller)
1087 : VideoQualityTest() {
1088 fec_controller_ = std::move(fec_controller);
1089}
1090
minyue626bc952016-10-31 05:47:02 -07001091VideoQualityTest::Params::Params()
ilnik98436952017-07-13 00:47:03 -07001092 : call({false, Call::Config::BitrateConfig(), 0}),
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001093 video{{false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false,
1094 false, ""},
1095 {false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false,
1096 false, ""}},
minyue4c8b9422017-03-21 04:11:43 -07001097 audio({false, false, false}),
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001098 screenshare{{false, false, 10, 0}, {false, false, 10, 0}},
minyue626bc952016-10-31 05:47:02 -07001099 analyzer({"", 0.0, 0.0, 0, "", ""}),
1100 pipe(),
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001101 ss{{std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()},
1102 {std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}},
ilnik98436952017-07-13 00:47:03 -07001103 logging({false, "", "", ""}) {}
minyue626bc952016-10-31 05:47:02 -07001104
1105VideoQualityTest::Params::~Params() = default;
1106
ivica5d6a06c2015-09-17 05:30:24 -07001107void VideoQualityTest::TestBody() {}
1108
sprangce4aef12015-11-02 07:23:20 -08001109std::string VideoQualityTest::GenerateGraphTitle() const {
1110 std::stringstream ss;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001111 ss << params_.video[0].codec;
1112 ss << " (" << params_.video[0].target_bitrate_bps / 1000 << "kbps";
1113 ss << ", " << params_.video[0].fps << " FPS";
1114 if (params_.screenshare[0].scroll_duration)
1115 ss << ", " << params_.screenshare[0].scroll_duration << "s scroll";
1116 if (params_.ss[0].streams.size() > 1)
1117 ss << ", Stream #" << params_.ss[0].selected_stream;
1118 if (params_.ss[0].num_spatial_layers > 1)
1119 ss << ", Layer #" << params_.ss[0].selected_sl;
sprangce4aef12015-11-02 07:23:20 -08001120 ss << ")";
1121 return ss.str();
1122}
1123
1124void VideoQualityTest::CheckParams() {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001125 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
1126 // Iterate over primary and secondary video streams.
1127 if (!params_.video[video_idx].enabled)
1128 return;
1129 // Add a default stream in none specified.
1130 if (params_.ss[video_idx].streams.empty())
1131 params_.ss[video_idx].streams.push_back(
1132 VideoQualityTest::DefaultVideoStream(params_, video_idx));
1133 if (params_.ss[video_idx].num_spatial_layers == 0)
1134 params_.ss[video_idx].num_spatial_layers = 1;
sprangce4aef12015-11-02 07:23:20 -08001135
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001136 if (params_.pipe.loss_percent != 0 ||
1137 params_.pipe.queue_length_packets != 0) {
1138 // Since LayerFilteringTransport changes the sequence numbers, we can't
1139 // use that feature with pack loss, since the NACK request would end up
1140 // retransmitting the wrong packets.
1141 RTC_CHECK(params_.ss[video_idx].selected_sl == -1 ||
1142 params_.ss[video_idx].selected_sl ==
1143 params_.ss[video_idx].num_spatial_layers - 1);
1144 RTC_CHECK(params_.video[video_idx].selected_tl == -1 ||
1145 params_.video[video_idx].selected_tl ==
1146 params_.video[video_idx].num_temporal_layers - 1);
1147 }
sprangce4aef12015-11-02 07:23:20 -08001148
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001149 // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as
1150 // it does in some parts of the code?
1151 RTC_CHECK_GE(params_.video[video_idx].max_bitrate_bps,
1152 params_.video[video_idx].target_bitrate_bps);
1153 RTC_CHECK_GE(params_.video[video_idx].target_bitrate_bps,
1154 params_.video[video_idx].min_bitrate_bps);
1155 RTC_CHECK_LT(params_.video[video_idx].selected_tl,
1156 params_.video[video_idx].num_temporal_layers);
1157 RTC_CHECK_LE(params_.ss[video_idx].selected_stream,
1158 params_.ss[video_idx].streams.size());
1159 for (const VideoStream& stream : params_.ss[video_idx].streams) {
1160 RTC_CHECK_GE(stream.min_bitrate_bps, 0);
1161 RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps);
1162 RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps);
1163 }
1164 // TODO(ivica): Should we check if the sum of all streams/layers is equal to
1165 // the total bitrate? We anyway have to update them in the case bitrate
1166 // estimator changes the total bitrates.
1167 RTC_CHECK_GE(params_.ss[video_idx].num_spatial_layers, 1);
1168 RTC_CHECK_LE(params_.ss[video_idx].selected_sl,
1169 params_.ss[video_idx].num_spatial_layers);
1170 RTC_CHECK(
1171 params_.ss[video_idx].spatial_layers.empty() ||
1172 params_.ss[video_idx].spatial_layers.size() ==
1173 static_cast<size_t>(params_.ss[video_idx].num_spatial_layers));
1174 if (params_.video[video_idx].codec == "VP8") {
1175 RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1);
1176 } else if (params_.video[video_idx].codec == "VP9") {
1177 RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 1);
1178 }
1179 RTC_CHECK_GE(params_.call.num_thumbnails, 0);
1180 if (params_.call.num_thumbnails > 0) {
1181 RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1);
1182 RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 3);
1183 RTC_CHECK_EQ(params_.video[video_idx].num_temporal_layers, 3);
1184 RTC_CHECK_EQ(params_.video[video_idx].codec, "VP8");
1185 }
1186 // Dual streams with FEC not supported in tests yet.
1187 RTC_CHECK(!params_.video[video_idx].flexfec || num_video_streams_ == 1);
1188 RTC_CHECK(!params_.video[video_idx].ulpfec || num_video_streams_ == 1);
ilnika014cc52017-03-07 04:21:04 -08001189 }
sprangce4aef12015-11-02 07:23:20 -08001190}
1191
1192// Static.
1193std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) {
1194 // Parse comma separated nonnegative integers, where some elements may be
1195 // empty. The empty values are replaced with -1.
1196 // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40}
1197 // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1}
1198 std::vector<int> result;
1199 if (str.empty())
1200 return result;
1201
1202 const char* p = str.c_str();
1203 int value = -1;
1204 int pos;
1205 while (*p) {
1206 if (*p == ',') {
1207 result.push_back(value);
1208 value = -1;
1209 ++p;
1210 continue;
1211 }
1212 RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1)
1213 << "Unexpected non-number value.";
1214 p += pos;
1215 }
1216 result.push_back(value);
1217 return result;
1218}
1219
1220// Static.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001221VideoStream VideoQualityTest::DefaultVideoStream(const Params& params,
1222 size_t video_idx) {
sprangce4aef12015-11-02 07:23:20 -08001223 VideoStream stream;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001224 stream.width = params.video[video_idx].width;
1225 stream.height = params.video[video_idx].height;
1226 stream.max_framerate = params.video[video_idx].fps;
1227 stream.min_bitrate_bps = params.video[video_idx].min_bitrate_bps;
1228 stream.target_bitrate_bps = params.video[video_idx].target_bitrate_bps;
1229 stream.max_bitrate_bps = params.video[video_idx].max_bitrate_bps;
sprang1168fd42017-06-21 09:00:17 -07001230 stream.max_qp = kDefaultMaxQp;
Seth Hampson46e31ba2018-01-18 10:39:54 -08001231 stream.active = true;
sprang6ef1b342017-03-13 02:01:32 -07001232 // TODO(sprang): Can we make this less of a hack?
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001233 if (params.video[video_idx].num_temporal_layers == 2) {
sprang6ef1b342017-03-13 02:01:32 -07001234 stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001235 } else if (params.video[video_idx].num_temporal_layers == 3) {
sprang6ef1b342017-03-13 02:01:32 -07001236 stream.temporal_layer_thresholds_bps.push_back(stream.max_bitrate_bps / 4);
1237 stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps);
sprangff19d352017-09-06 07:14:02 -07001238 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001239 RTC_CHECK_LE(params.video[video_idx].num_temporal_layers,
1240 kMaxTemporalStreams);
1241 for (int i = 0; i < params.video[video_idx].num_temporal_layers - 1; ++i) {
sprangff19d352017-09-06 07:14:02 -07001242 stream.temporal_layer_thresholds_bps.push_back(static_cast<int>(
1243 stream.max_bitrate_bps * kVp8LayerRateAlloction[0][i] + 0.5));
1244 }
ilnika014cc52017-03-07 04:21:04 -08001245 }
1246 return stream;
1247}
1248
1249// Static.
1250VideoStream VideoQualityTest::DefaultThumbnailStream() {
1251 VideoStream stream;
1252 stream.width = 320;
1253 stream.height = 180;
1254 stream.max_framerate = 7;
1255 stream.min_bitrate_bps = 7500;
1256 stream.target_bitrate_bps = 37500;
1257 stream.max_bitrate_bps = 50000;
sprang1168fd42017-06-21 09:00:17 -07001258 stream.max_qp = kDefaultMaxQp;
sprangce4aef12015-11-02 07:23:20 -08001259 return stream;
1260}
1261
1262// Static.
1263void VideoQualityTest::FillScalabilitySettings(
1264 Params* params,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001265 size_t video_idx,
sprangce4aef12015-11-02 07:23:20 -08001266 const std::vector<std::string>& stream_descriptors,
sprang1168fd42017-06-21 09:00:17 -07001267 int num_streams,
sprangce4aef12015-11-02 07:23:20 -08001268 size_t selected_stream,
1269 int num_spatial_layers,
1270 int selected_sl,
1271 const std::vector<std::string>& sl_descriptors) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001272 if (params->ss[video_idx].streams.empty() &&
1273 params->ss[video_idx].infer_streams) {
sprang1168fd42017-06-21 09:00:17 -07001274 webrtc::VideoEncoderConfig encoder_config;
1275 encoder_config.content_type =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001276 params->screenshare[video_idx].enabled
sprang1168fd42017-06-21 09:00:17 -07001277 ? webrtc::VideoEncoderConfig::ContentType::kScreen
1278 : webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001279 encoder_config.max_bitrate_bps = params->video[video_idx].max_bitrate_bps;
1280 encoder_config.min_transmit_bitrate_bps =
1281 params->video[video_idx].min_transmit_bps;
sprang1168fd42017-06-21 09:00:17 -07001282 encoder_config.number_of_streams = num_streams;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001283 encoder_config.spatial_layers = params->ss[video_idx].spatial_layers;
Seth Hampson8234ead2018-02-02 15:16:24 -08001284 encoder_config.simulcast_layers = std::vector<VideoStream>(num_streams);
sprang1168fd42017-06-21 09:00:17 -07001285 encoder_config.video_stream_factory =
1286 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001287 params->video[video_idx].codec, kDefaultMaxQp,
1288 params->video[video_idx].fps,
1289 params->screenshare[video_idx].enabled, true);
1290 params->ss[video_idx].streams =
sprang1168fd42017-06-21 09:00:17 -07001291 encoder_config.video_stream_factory->CreateEncoderStreams(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001292 static_cast<int>(params->video[video_idx].width),
1293 static_cast<int>(params->video[video_idx].height), encoder_config);
sprang1168fd42017-06-21 09:00:17 -07001294 } else {
1295 // Read VideoStream and SpatialLayer elements from a list of comma separated
1296 // lists. To use a default value for an element, use -1 or leave empty.
1297 // Validity checks performed in CheckParams.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001298 RTC_CHECK(params->ss[video_idx].streams.empty());
sprang1168fd42017-06-21 09:00:17 -07001299 for (auto descriptor : stream_descriptors) {
1300 if (descriptor.empty())
1301 continue;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001302 VideoStream stream =
1303 VideoQualityTest::DefaultVideoStream(*params, video_idx);
sprang1168fd42017-06-21 09:00:17 -07001304 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1305 if (v[0] != -1)
1306 stream.width = static_cast<size_t>(v[0]);
1307 if (v[1] != -1)
1308 stream.height = static_cast<size_t>(v[1]);
1309 if (v[2] != -1)
1310 stream.max_framerate = v[2];
1311 if (v[3] != -1)
1312 stream.min_bitrate_bps = v[3];
1313 if (v[4] != -1)
1314 stream.target_bitrate_bps = v[4];
1315 if (v[5] != -1)
1316 stream.max_bitrate_bps = v[5];
1317 if (v.size() > 6 && v[6] != -1)
1318 stream.max_qp = v[6];
1319 if (v.size() > 7) {
1320 stream.temporal_layer_thresholds_bps.clear();
1321 stream.temporal_layer_thresholds_bps.insert(
1322 stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end());
1323 } else {
1324 // Automatic TL thresholds for more than two layers not supported.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001325 RTC_CHECK_LE(params->video[video_idx].num_temporal_layers, 2);
sprang1168fd42017-06-21 09:00:17 -07001326 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001327 params->ss[video_idx].streams.push_back(stream);
sprangce4aef12015-11-02 07:23:20 -08001328 }
sprangce4aef12015-11-02 07:23:20 -08001329 }
sprangce4aef12015-11-02 07:23:20 -08001330
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001331 params->ss[video_idx].num_spatial_layers = std::max(1, num_spatial_layers);
1332 params->ss[video_idx].selected_stream = selected_stream;
sprang1168fd42017-06-21 09:00:17 -07001333
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001334 params->ss[video_idx].selected_sl = selected_sl;
1335 RTC_CHECK(params->ss[video_idx].spatial_layers.empty());
sprangce4aef12015-11-02 07:23:20 -08001336 for (auto descriptor : sl_descriptors) {
1337 if (descriptor.empty())
1338 continue;
1339 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1340 RTC_CHECK_GT(v[2], 0);
1341
1342 SpatialLayer layer;
1343 layer.scaling_factor_num = v[0] == -1 ? 1 : v[0];
1344 layer.scaling_factor_den = v[1] == -1 ? 1 : v[1];
1345 layer.target_bitrate_bps = v[2];
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001346 params->ss[video_idx].spatial_layers.push_back(layer);
sprangce4aef12015-11-02 07:23:20 -08001347 }
1348}
1349
minyuea27172d2016-11-01 05:59:29 -07001350void VideoQualityTest::SetupVideo(Transport* send_transport,
1351 Transport* recv_transport) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001352 size_t total_streams_used = 0;
1353 size_t num_flexfec_streams = params_.video[0].flexfec ? 1 : 0;
1354 CreateAudioAndFecSendConfigs(0, num_flexfec_streams, send_transport);
1355 CreateMatchingAudioAndFecConfigs(recv_transport);
1356 video_receive_configs_.clear();
1357 video_send_configs_.clear();
1358 video_encoders_.clear();
1359 video_encoder_configs_.clear();
1360 allocated_decoders_.clear();
1361 bool decode_all_receive_streams = true;
1362 size_t num_video_substreams = params_.ss[0].streams.size();
1363 RTC_CHECK(num_video_streams_ > 0);
1364 video_encoder_configs_.resize(num_video_streams_);
1365 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
1366 video_send_configs_.push_back(VideoSendStream::Config(send_transport));
1367 video_encoders_.push_back(nullptr);
1368 video_encoder_configs_.push_back(VideoEncoderConfig());
1369 num_video_substreams = params_.ss[video_idx].streams.size();
1370 RTC_CHECK_GT(num_video_substreams, 0);
1371 CreateVideoSendConfig(&video_send_configs_[video_idx], num_video_substreams,
1372 total_streams_used, send_transport);
ivica5d6a06c2015-09-17 05:30:24 -07001373
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001374 int payload_type;
1375 if (params_.video[video_idx].codec == "H264") {
1376 video_encoders_[video_idx] =
1377 H264Encoder::Create(cricket::VideoCodec("H264"));
1378 payload_type = kPayloadTypeH264;
1379 } else if (params_.video[video_idx].codec == "VP8") {
1380 if (params_.screenshare[video_idx].enabled &&
1381 params_.ss[video_idx].streams.size() > 1) {
1382 // Simulcast screenshare needs a simulcast encoder adapter to work,
1383 // since encoders usually can't natively do simulcast with different
1384 // frame rates for the different layers.
1385 video_encoders_[video_idx].reset(
1386 new SimulcastEncoderAdapter(new InternalEncoderFactory()));
1387 } else {
1388 video_encoders_[video_idx] = VP8Encoder::Create();
1389 }
1390 payload_type = kPayloadTypeVP8;
1391 } else if (params_.video[video_idx].codec == "VP9") {
1392 video_encoders_[video_idx] = VP9Encoder::Create();
1393 payload_type = kPayloadTypeVP9;
ilnikcb8c1462017-03-09 09:23:30 -08001394 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001395 RTC_NOTREACHED() << "Codec not supported!";
1396 return;
ilnikcb8c1462017-03-09 09:23:30 -08001397 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001398 video_send_configs_[video_idx].encoder_settings.encoder =
1399 video_encoders_[video_idx].get();
1400 video_send_configs_[video_idx].encoder_settings.payload_name =
1401 params_.video[video_idx].codec;
1402 video_send_configs_[video_idx].encoder_settings.payload_type = payload_type;
1403 video_send_configs_[video_idx].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1404 video_send_configs_[video_idx].rtp.rtx.payload_type = kSendRtxPayloadType;
1405 for (size_t i = 0; i < num_video_substreams; ++i) {
1406 video_send_configs_[video_idx].rtp.rtx.ssrcs.push_back(
1407 kSendRtxSsrcs[i + total_streams_used]);
ilnik9fd9f6c2017-03-02 08:10:10 -08001408 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001409 video_send_configs_[video_idx].rtp.extensions.clear();
1410 if (params_.call.send_side_bwe) {
1411 video_send_configs_[video_idx].rtp.extensions.push_back(
1412 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1413 test::kTransportSequenceNumberExtensionId));
1414 } else {
1415 video_send_configs_[video_idx].rtp.extensions.push_back(RtpExtension(
1416 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1417 }
1418 video_send_configs_[video_idx].rtp.extensions.push_back(
1419 RtpExtension(RtpExtension::kVideoContentTypeUri,
1420 test::kVideoContentTypeExtensionId));
1421 video_send_configs_[video_idx].rtp.extensions.push_back(RtpExtension(
1422 RtpExtension::kVideoTimingUri, test::kVideoTimingExtensionId));
1423
1424 video_encoder_configs_[video_idx].min_transmit_bitrate_bps =
1425 params_.video[video_idx].min_transmit_bps;
1426
1427 video_send_configs_[video_idx].suspend_below_min_bitrate =
1428 params_.video[video_idx].suspend_below_min_bitrate;
1429
1430 video_encoder_configs_[video_idx].number_of_streams =
1431 params_.ss[video_idx].streams.size();
1432 video_encoder_configs_[video_idx].max_bitrate_bps = 0;
1433 for (size_t i = 0; i < params_.ss[video_idx].streams.size(); ++i) {
1434 video_encoder_configs_[video_idx].max_bitrate_bps +=
1435 params_.ss[video_idx].streams[i].max_bitrate_bps;
1436 }
1437 if (params_.ss[video_idx].infer_streams) {
Seth Hampson8234ead2018-02-02 15:16:24 -08001438 video_encoder_configs_[video_idx].simulcast_layers =
1439 std::vector<VideoStream>(params_.ss[video_idx].streams.size());
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001440 video_encoder_configs_[video_idx].video_stream_factory =
1441 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
1442 params_.video[video_idx].codec,
1443 params_.ss[video_idx].streams[0].max_qp,
1444 params_.video[video_idx].fps,
1445 params_.screenshare[video_idx].enabled, true);
1446 } else {
1447 video_encoder_configs_[video_idx].video_stream_factory =
1448 new rtc::RefCountedObject<VideoStreamFactory>(
1449 params_.ss[video_idx].streams);
1450 }
1451
1452 video_encoder_configs_[video_idx].spatial_layers =
1453 params_.ss[video_idx].spatial_layers;
1454
1455 std::vector<VideoReceiveStream::Config> new_receive_configs =
1456 CreateMatchingVideoReceiveConfigs(video_send_configs_[video_idx],
1457 recv_transport);
1458
1459 decode_all_receive_streams = params_.ss[video_idx].selected_stream ==
1460 params_.ss[video_idx].streams.size();
1461
1462 for (size_t i = 0; i < num_video_substreams; ++i) {
1463 new_receive_configs[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1464 new_receive_configs[i].rtp.rtx_ssrc =
1465 kSendRtxSsrcs[i + total_streams_used];
1466 new_receive_configs[i]
1467 .rtp.rtx_associated_payload_types[kSendRtxPayloadType] = payload_type;
1468 new_receive_configs[i].rtp.transport_cc = params_.call.send_side_bwe;
1469 new_receive_configs[i].rtp.remb = !params_.call.send_side_bwe;
1470 // Enable RTT calculation so NTP time estimator will work.
1471 new_receive_configs[i].rtp.rtcp_xr.receiver_reference_time_report = true;
1472 // Force fake decoders on non-selected simulcast streams.
1473 if (!decode_all_receive_streams &&
1474 i != params_.ss[video_idx].selected_stream) {
1475 VideoReceiveStream::Decoder decoder;
1476 decoder.decoder = new test::FakeDecoder();
1477 decoder.payload_type =
1478 video_send_configs_[video_idx].encoder_settings.payload_type;
1479 decoder.payload_name =
1480 video_send_configs_[video_idx].encoder_settings.payload_name;
1481 new_receive_configs[i].decoders.clear();
1482 allocated_decoders_.emplace_back(decoder.decoder);
1483 new_receive_configs[i].decoders.push_back(decoder);
1484 }
1485 }
1486
1487 for (VideoReceiveStream::Config& config : new_receive_configs) {
1488 video_receive_configs_.push_back(config.Copy());
1489 }
1490
1491 if (params_.screenshare[video_idx].enabled) {
1492 // Fill out codec settings.
1493 video_encoder_configs_[video_idx].content_type =
1494 VideoEncoderConfig::ContentType::kScreen;
1495 degradation_preference_ =
1496 VideoSendStream::DegradationPreference::kMaintainResolution;
1497 if (params_.video[video_idx].codec == "VP8") {
1498 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
1499 vp8_settings.denoisingOn = false;
1500 vp8_settings.frameDroppingOn = false;
1501 vp8_settings.numberOfTemporalLayers = static_cast<unsigned char>(
1502 params_.video[video_idx].num_temporal_layers);
1503 video_encoder_configs_[video_idx].encoder_specific_settings =
1504 new rtc::RefCountedObject<
1505 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
1506 } else if (params_.video[video_idx].codec == "VP9") {
1507 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
1508 vp9_settings.denoisingOn = false;
1509 vp9_settings.frameDroppingOn = false;
1510 vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>(
1511 params_.video[video_idx].num_temporal_layers);
1512 vp9_settings.numberOfSpatialLayers = static_cast<unsigned char>(
1513 params_.ss[video_idx].num_spatial_layers);
1514 video_encoder_configs_[video_idx].encoder_specific_settings =
1515 new rtc::RefCountedObject<
1516 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
1517 }
1518 } else if (params_.ss[video_idx].num_spatial_layers > 1) {
1519 // If SVC mode without screenshare, still need to set codec specifics.
1520 RTC_CHECK(params_.video[video_idx].codec == "VP9");
1521 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
1522 vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>(
1523 params_.video[video_idx].num_temporal_layers);
1524 vp9_settings.numberOfSpatialLayers =
1525 static_cast<unsigned char>(params_.ss[video_idx].num_spatial_layers);
1526 video_encoder_configs_[video_idx].encoder_specific_settings =
1527 new rtc::RefCountedObject<
1528 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
1529 }
1530 total_streams_used += num_video_substreams;
sprangce4aef12015-11-02 07:23:20 -08001531 }
brandtr1293aca2016-11-16 22:47:29 -08001532
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001533 // FEC supported only for single video stream mode yet.
1534 if (params_.video[0].flexfec) {
Ilya Nikolaevskiy38aaf692017-12-22 14:39:09 +01001535 video_send_configs_[0].rtp.flexfec.payload_type = kFlexfecPayloadType;
1536 video_send_configs_[0].rtp.flexfec.ssrc = kFlexfecSendSsrc;
sprang1168fd42017-06-21 09:00:17 -07001537 if (decode_all_receive_streams) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001538 for (uint32_t media_ssrc : video_send_configs_[0].rtp.ssrcs) {
1539 video_send_configs_[0].rtp.flexfec.protected_media_ssrcs.push_back(
sprang1168fd42017-06-21 09:00:17 -07001540 media_ssrc);
1541 }
1542 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001543 video_send_configs_[0].rtp.flexfec.protected_media_ssrcs = {
1544 kVideoSendSsrcs[params_.ss[0].selected_stream]};
sprang1168fd42017-06-21 09:00:17 -07001545 }
brandtr1293aca2016-11-16 22:47:29 -08001546
brandtr8313a6f2017-01-13 07:41:19 -08001547 // The matching receive config is _not_ created by
1548 // CreateMatchingReceiveConfigs, since VideoQualityTest is not a BaseTest.
1549 // Set up the receive config manually instead.
1550 FlexfecReceiveStream::Config flexfec_receive_config(recv_transport);
brandtr1cfbd602016-12-08 04:17:53 -08001551 flexfec_receive_config.payload_type =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001552 video_send_configs_[0].rtp.flexfec.payload_type;
1553 flexfec_receive_config.remote_ssrc =
1554 video_send_configs_[0].rtp.flexfec.ssrc;
brandtr1293aca2016-11-16 22:47:29 -08001555 flexfec_receive_config.protected_media_ssrcs =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001556 video_send_configs_[0].rtp.flexfec.protected_media_ssrcs;
brandtrfa5a3682017-01-17 01:33:54 -08001557 flexfec_receive_config.local_ssrc = kReceiverLocalVideoSsrc;
brandtrb29e6522016-12-21 06:37:18 -08001558 flexfec_receive_config.transport_cc = params_.call.send_side_bwe;
1559 if (params_.call.send_side_bwe) {
1560 flexfec_receive_config.rtp_header_extensions.push_back(
1561 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1562 test::kTransportSequenceNumberExtensionId));
1563 } else {
1564 flexfec_receive_config.rtp_header_extensions.push_back(RtpExtension(
1565 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1566 }
brandtr1293aca2016-11-16 22:47:29 -08001567 flexfec_receive_configs_.push_back(flexfec_receive_config);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001568 if (num_video_substreams > 0) {
brandtr7cd28b92017-09-22 00:26:25 -07001569 video_receive_configs_[0].rtp.protected_by_flexfec = true;
1570 }
brandtr1293aca2016-11-16 22:47:29 -08001571 }
1572
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001573 if (params_.video[0].ulpfec) {
1574 video_send_configs_[0].rtp.ulpfec.red_payload_type = kRedPayloadType;
1575 video_send_configs_[0].rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType;
1576 video_send_configs_[0].rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType;
brandtr1293aca2016-11-16 22:47:29 -08001577
sprang1168fd42017-06-21 09:00:17 -07001578 if (decode_all_receive_streams) {
1579 for (auto it = video_receive_configs_.begin();
1580 it != video_receive_configs_.end(); ++it) {
nisse3b3622f2017-09-26 02:49:21 -07001581 it->rtp.red_payload_type =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001582 video_send_configs_[0].rtp.ulpfec.red_payload_type;
nisse3b3622f2017-09-26 02:49:21 -07001583 it->rtp.ulpfec_payload_type =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001584 video_send_configs_[0].rtp.ulpfec.ulpfec_payload_type;
1585 it->rtp.rtx_associated_payload_types
1586 [video_send_configs_[0].rtp.ulpfec.red_rtx_payload_type] =
1587 video_send_configs_[0].rtp.ulpfec.red_payload_type;
sprang1168fd42017-06-21 09:00:17 -07001588 }
1589 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001590 video_receive_configs_[params_.ss[0].selected_stream]
1591 .rtp.red_payload_type =
1592 video_send_configs_[0].rtp.ulpfec.red_payload_type;
1593 video_receive_configs_[params_.ss[0].selected_stream]
nisse3b3622f2017-09-26 02:49:21 -07001594 .rtp.ulpfec_payload_type =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001595 video_send_configs_[0].rtp.ulpfec.ulpfec_payload_type;
1596 video_receive_configs_[params_.ss[0].selected_stream]
1597 .rtp.rtx_associated_payload_types
1598 [video_send_configs_[0].rtp.ulpfec.red_rtx_payload_type] =
1599 video_send_configs_[0].rtp.ulpfec.red_payload_type;
sprang1168fd42017-06-21 09:00:17 -07001600 }
brandtr1293aca2016-11-16 22:47:29 -08001601 }
ivica5d6a06c2015-09-17 05:30:24 -07001602}
1603
ilnika014cc52017-03-07 04:21:04 -08001604void VideoQualityTest::SetupThumbnails(Transport* send_transport,
1605 Transport* recv_transport) {
ilnik98436952017-07-13 00:47:03 -07001606 for (int i = 0; i < params_.call.num_thumbnails; ++i) {
ilnika014cc52017-03-07 04:21:04 -08001607 thumbnail_encoders_.emplace_back(VP8Encoder::Create());
1608
1609 // Thumbnails will be send in the other way: from receiver_call to
1610 // sender_call.
1611 VideoSendStream::Config thumbnail_send_config(recv_transport);
1612 thumbnail_send_config.rtp.ssrcs.push_back(kThumbnailSendSsrcStart + i);
1613 thumbnail_send_config.encoder_settings.encoder =
1614 thumbnail_encoders_.back().get();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001615 thumbnail_send_config.encoder_settings.payload_name =
1616 params_.video[0].codec;
ilnika014cc52017-03-07 04:21:04 -08001617 thumbnail_send_config.encoder_settings.payload_type = kPayloadTypeVP8;
1618 thumbnail_send_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1619 thumbnail_send_config.rtp.rtx.payload_type = kSendRtxPayloadType;
1620 thumbnail_send_config.rtp.rtx.ssrcs.push_back(kThumbnailRtxSsrcStart + i);
1621 thumbnail_send_config.rtp.extensions.clear();
1622 if (params_.call.send_side_bwe) {
1623 thumbnail_send_config.rtp.extensions.push_back(
1624 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1625 test::kTransportSequenceNumberExtensionId));
1626 } else {
1627 thumbnail_send_config.rtp.extensions.push_back(RtpExtension(
1628 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1629 }
1630
1631 VideoEncoderConfig thumbnail_encoder_config;
1632 thumbnail_encoder_config.min_transmit_bitrate_bps = 7500;
1633 thumbnail_send_config.suspend_below_min_bitrate =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001634 params_.video[0].suspend_below_min_bitrate;
ilnika014cc52017-03-07 04:21:04 -08001635 thumbnail_encoder_config.number_of_streams = 1;
1636 thumbnail_encoder_config.max_bitrate_bps = 50000;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001637 if (params_.ss[0].infer_streams) {
ilnik6b826ef2017-06-16 06:53:48 -07001638 thumbnail_encoder_config.video_stream_factory =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001639 new rtc::RefCountedObject<VideoStreamFactory>(params_.ss[0].streams);
ilnik6b826ef2017-06-16 06:53:48 -07001640 } else {
Seth Hampson8234ead2018-02-02 15:16:24 -08001641 thumbnail_encoder_config.simulcast_layers = std::vector<VideoStream>(1);
ilnik6b826ef2017-06-16 06:53:48 -07001642 thumbnail_encoder_config.video_stream_factory =
1643 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001644 params_.video[0].codec, params_.ss[0].streams[0].max_qp,
1645 params_.video[0].fps, params_.screenshare[0].enabled, true);
ilnik6b826ef2017-06-16 06:53:48 -07001646 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001647 thumbnail_encoder_config.spatial_layers = params_.ss[0].spatial_layers;
ilnika014cc52017-03-07 04:21:04 -08001648
1649 VideoReceiveStream::Config thumbnail_receive_config(send_transport);
1650 thumbnail_receive_config.rtp.remb = false;
1651 thumbnail_receive_config.rtp.transport_cc = true;
1652 thumbnail_receive_config.rtp.local_ssrc = kReceiverLocalVideoSsrc;
1653 for (const RtpExtension& extension : thumbnail_send_config.rtp.extensions)
1654 thumbnail_receive_config.rtp.extensions.push_back(extension);
1655 thumbnail_receive_config.renderer = &fake_renderer_;
1656
1657 VideoReceiveStream::Decoder decoder =
1658 test::CreateMatchingDecoder(thumbnail_send_config.encoder_settings);
1659 allocated_decoders_.push_back(
1660 std::unique_ptr<VideoDecoder>(decoder.decoder));
1661 thumbnail_receive_config.decoders.clear();
1662 thumbnail_receive_config.decoders.push_back(decoder);
1663 thumbnail_receive_config.rtp.remote_ssrc =
1664 thumbnail_send_config.rtp.ssrcs[0];
1665
1666 thumbnail_receive_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1667 thumbnail_receive_config.rtp.rtx_ssrc = kThumbnailRtxSsrcStart + i;
nisse26e3abb2017-08-25 04:44:25 -07001668 thumbnail_receive_config.rtp
1669 .rtx_associated_payload_types[kSendRtxPayloadType] = kPayloadTypeVP8;
ilnika014cc52017-03-07 04:21:04 -08001670 thumbnail_receive_config.rtp.transport_cc = params_.call.send_side_bwe;
1671 thumbnail_receive_config.rtp.remb = !params_.call.send_side_bwe;
1672
1673 thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy());
1674 thumbnail_send_configs_.push_back(thumbnail_send_config.Copy());
1675 thumbnail_receive_configs_.push_back(thumbnail_receive_config.Copy());
1676 }
1677
ilnik98436952017-07-13 00:47:03 -07001678 for (int i = 0; i < params_.call.num_thumbnails; ++i) {
ilnika014cc52017-03-07 04:21:04 -08001679 thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream(
1680 thumbnail_send_configs_[i].Copy(),
1681 thumbnail_encoder_configs_[i].Copy()));
1682 thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream(
1683 thumbnail_receive_configs_[i].Copy()));
1684 }
1685}
1686
1687void VideoQualityTest::DestroyThumbnailStreams() {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001688 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) {
ilnika014cc52017-03-07 04:21:04 -08001689 receiver_call_->DestroyVideoSendStream(thumbnail_send_stream);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001690 }
ilnika014cc52017-03-07 04:21:04 -08001691 thumbnail_send_streams_.clear();
1692 for (VideoReceiveStream* thumbnail_receive_stream :
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001693 thumbnail_receive_streams_) {
ilnika014cc52017-03-07 04:21:04 -08001694 sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001695 }
ilnika014cc52017-03-07 04:21:04 -08001696 thumbnail_send_streams_.clear();
1697 thumbnail_receive_streams_.clear();
eladalon413ee9a2017-08-22 04:02:52 -07001698 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
1699 thumbnail_capturers_) {
1700 video_caputurer.reset();
1701 }
ilnika014cc52017-03-07 04:21:04 -08001702}
1703
ilnika014cc52017-03-07 04:21:04 -08001704void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) {
1705 VideoStream thumbnail = DefaultThumbnailStream();
1706 for (size_t i = 0; i < num_thumbnail_streams; ++i) {
1707 thumbnail_capturers_.emplace_back(test::FrameGeneratorCapturer::Create(
1708 static_cast<int>(thumbnail.width), static_cast<int>(thumbnail.height),
1709 thumbnail.max_framerate, clock_));
ilnikf89a7382017-03-07 06:15:27 -08001710 RTC_DCHECK(thumbnail_capturers_.back());
ilnika014cc52017-03-07 04:21:04 -08001711 }
1712}
1713
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001714std::unique_ptr<test::FrameGenerator> VideoQualityTest::CreateFrameGenerator(
1715 size_t video_idx) {
1716 // Setup frame generator.
1717 const size_t kWidth = 1850;
1718 const size_t kHeight = 1110;
1719 std::unique_ptr<test::FrameGenerator> frame_generator;
1720 if (params_.screenshare[video_idx].generate_slides) {
1721 frame_generator = test::FrameGenerator::CreateSlideGenerator(
1722 kWidth, kHeight,
1723 params_.screenshare[video_idx].slide_change_interval *
1724 params_.video[video_idx].fps);
ivica5d6a06c2015-09-17 05:30:24 -07001725 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001726 std::vector<std::string> slides = params_.screenshare[video_idx].slides;
1727 if (slides.size() == 0) {
1728 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
1729 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
1730 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
1731 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
1732 }
1733 if (params_.screenshare[video_idx].scroll_duration == 0) {
1734 // Cycle image every slide_change_interval seconds.
1735 frame_generator = test::FrameGenerator::CreateFromYuvFile(
1736 slides, kWidth, kHeight,
1737 params_.screenshare[video_idx].slide_change_interval *
1738 params_.video[video_idx].fps);
ivica5d6a06c2015-09-17 05:30:24 -07001739 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001740 RTC_CHECK_LE(params_.video[video_idx].width, kWidth);
1741 RTC_CHECK_LE(params_.video[video_idx].height, kHeight);
1742 RTC_CHECK_GT(params_.screenshare[video_idx].slide_change_interval, 0);
1743 const int kPauseDurationMs =
1744 (params_.screenshare[video_idx].slide_change_interval -
1745 params_.screenshare[video_idx].scroll_duration) *
1746 1000;
1747 RTC_CHECK_LE(params_.screenshare[video_idx].scroll_duration,
1748 params_.screenshare[video_idx].slide_change_interval);
1749
1750 frame_generator = test::FrameGenerator::CreateScrollingInputFromYuvFiles(
1751 clock_, slides, kWidth, kHeight, params_.video[video_idx].width,
1752 params_.video[video_idx].height,
1753 params_.screenshare[video_idx].scroll_duration * 1000,
1754 kPauseDurationMs);
ivica5d6a06c2015-09-17 05:30:24 -07001755 }
1756 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001757 return frame_generator;
1758}
1759
1760void VideoQualityTest::CreateCapturers() {
1761 video_capturers_.resize(num_video_streams_);
1762 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
1763 if (params_.screenshare[video_idx].enabled) {
1764 std::unique_ptr<test::FrameGenerator> frame_generator =
1765 CreateFrameGenerator(video_idx);
1766 test::FrameGeneratorCapturer* frame_generator_capturer =
1767 new test::FrameGeneratorCapturer(clock_, std::move(frame_generator),
1768 params_.video[video_idx].fps);
1769 EXPECT_TRUE(frame_generator_capturer->Init());
1770 video_capturers_[video_idx].reset(frame_generator_capturer);
1771 } else {
1772 if (params_.video[video_idx].clip_name == "Generator") {
1773 video_capturers_[video_idx].reset(test::FrameGeneratorCapturer::Create(
1774 static_cast<int>(params_.video[video_idx].width),
1775 static_cast<int>(params_.video[video_idx].height),
1776 params_.video[video_idx].fps, clock_));
1777 } else if (params_.video[video_idx].clip_name.empty()) {
1778 video_capturers_[video_idx].reset(test::VcmCapturer::Create(
1779 params_.video[video_idx].width, params_.video[video_idx].height,
1780 params_.video[video_idx].fps,
1781 params_.video[video_idx].capture_device_index));
1782 if (!video_capturers_[video_idx]) {
1783 // Failed to get actual camera, use chroma generator as backup.
1784 video_capturers_[video_idx].reset(
1785 test::FrameGeneratorCapturer::Create(
1786 static_cast<int>(params_.video[video_idx].width),
1787 static_cast<int>(params_.video[video_idx].height),
1788 params_.video[video_idx].fps, clock_));
1789 }
1790 } else {
1791 video_capturers_[video_idx].reset(
1792 test::FrameGeneratorCapturer::CreateFromYuvFile(
1793 test::ResourcePath(params_.video[video_idx].clip_name, "yuv"),
1794 params_.video[video_idx].width, params_.video[video_idx].height,
1795 params_.video[video_idx].fps, clock_));
1796 ASSERT_TRUE(video_capturers_[video_idx])
1797 << "Could not create capturer for "
1798 << params_.video[video_idx].clip_name
1799 << ".yuv. Is this resource file present?";
1800 }
1801 }
1802 RTC_DCHECK(video_capturers_[video_idx].get());
1803 }
ivica5d6a06c2015-09-17 05:30:24 -07001804}
1805
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001806std::unique_ptr<test::LayerFilteringTransport>
1807VideoQualityTest::CreateSendTransport() {
1808 return rtc::MakeUnique<test::LayerFilteringTransport>(
1809 &task_queue_, params_.pipe, sender_call_.get(), kPayloadTypeVP8,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001810 kPayloadTypeVP9, params_.video[0].selected_tl, params_.ss[0].selected_sl,
1811 payload_type_map_, kVideoSendSsrcs[0],
1812 static_cast<uint32_t>(kVideoSendSsrcs[0] + params_.ss[0].streams.size() -
1813 1));
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001814}
1815
1816std::unique_ptr<test::DirectTransport>
1817VideoQualityTest::CreateReceiveTransport() {
1818 return rtc::MakeUnique<test::DirectTransport>(
1819 &task_queue_, params_.pipe, receiver_call_.get(), payload_type_map_);
1820}
1821
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001822void VideoQualityTest::CreateVideoStreams() {
1823 RTC_DCHECK(video_send_streams_.empty());
1824 RTC_DCHECK(video_receive_streams_.empty());
1825 RTC_DCHECK_EQ(video_send_configs_.size(), num_video_streams_);
Stefan Holmerc6b224a2018-02-06 13:52:44 +01001826 // We currently only support testing external fec controllers with a single
1827 // VideoSendStream.
1828 if (fec_controller_.get()) {
1829 RTC_DCHECK_LE(video_send_configs_.size(), 1);
1830 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001831 for (size_t i = 0; i < video_send_configs_.size(); ++i) {
Stefan Holmerc6b224a2018-02-06 13:52:44 +01001832 if (fec_controller_.get()) {
1833 video_send_streams_.push_back(sender_call_->CreateVideoSendStream(
1834 video_send_configs_[i].Copy(), video_encoder_configs_[i].Copy(),
1835 std::move(fec_controller_)));
1836 } else {
1837 video_send_streams_.push_back(sender_call_->CreateVideoSendStream(
1838 video_send_configs_[i].Copy(), video_encoder_configs_[i].Copy()));
1839 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001840 }
1841 for (size_t i = 0; i < video_receive_configs_.size(); ++i) {
1842 video_receive_streams_.push_back(receiver_call_->CreateVideoReceiveStream(
1843 video_receive_configs_[i].Copy()));
1844 }
1845
1846 AssociateFlexfecStreamsWithVideoStreams();
1847}
1848
Ying Wang3b790f32018-01-19 17:58:57 +01001849void VideoQualityTest::CreateVideoStreamsWithProtectionBitrateCalculator(
1850 std::unique_ptr<FecController> fec_controller) {
1851 RTC_DCHECK(video_send_streams_.empty());
1852 RTC_DCHECK(video_receive_streams_.empty());
1853 RTC_DCHECK_EQ(video_send_configs_.size(), num_video_streams_);
1854 for (size_t i = 0; i < video_send_configs_.size(); ++i) {
1855 video_send_streams_.push_back(sender_call_->CreateVideoSendStream(
1856 video_send_configs_[i].Copy(), video_encoder_configs_[i].Copy(),
1857 std::move(fec_controller)));
1858 }
1859 for (size_t i = 0; i < video_receive_configs_.size(); ++i) {
1860 video_receive_streams_.push_back(receiver_call_->CreateVideoReceiveStream(
1861 video_receive_configs_[i].Copy()));
1862 }
1863
1864 AssociateFlexfecStreamsWithVideoStreams();
1865}
1866
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001867void VideoQualityTest::DestroyStreams() {
1868 CallTest::DestroyStreams();
1869
1870 for (VideoSendStream* video_send_stream : video_send_streams_)
1871 sender_call_->DestroyVideoSendStream(video_send_stream);
1872}
1873
sprang7a975f72015-10-12 06:33:21 -07001874void VideoQualityTest::RunWithAnalyzer(const Params& params) {
Ilya Nikolaevskiyad556762018-01-17 11:48:59 +01001875 rtc::LogMessage::SetLogToStderr(params.logging.logs);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001876 num_video_streams_ = params.call.dual_video ? 2 : 1;
eladalon413ee9a2017-08-22 04:02:52 -07001877 std::unique_ptr<test::LayerFilteringTransport> send_transport;
1878 std::unique_ptr<test::DirectTransport> recv_transport;
1879 FILE* graph_data_output_file = nullptr;
1880 std::unique_ptr<VideoAnalyzer> analyzer;
1881
sprangce4aef12015-11-02 07:23:20 -08001882 params_ = params;
1883
minyue626bc952016-10-31 05:47:02 -07001884 RTC_CHECK(!params_.audio.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001885 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1886 // differentiate between the analyzer and the renderer case.
sprangce4aef12015-11-02 07:23:20 -08001887 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001888
sprangce4aef12015-11-02 07:23:20 -08001889 if (!params_.analyzer.graph_data_output_filename.empty()) {
ivica5d6a06c2015-09-17 05:30:24 -07001890 graph_data_output_file =
sprangce4aef12015-11-02 07:23:20 -08001891 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
Peter Boström74f6e9e2016-04-04 17:56:10 +02001892 RTC_CHECK(graph_data_output_file)
sprangce4aef12015-11-02 07:23:20 -08001893 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1894 << "!";
ivica87f83a92015-10-08 05:13:32 -07001895 }
sprang7a975f72015-10-12 06:33:21 -07001896
ilnik98436952017-07-13 00:47:03 -07001897 if (!params.logging.rtc_event_log_name.empty()) {
Bjorn Terelius0a6a2b72018-01-19 17:52:38 +01001898 send_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
1899 recv_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001900 std::unique_ptr<RtcEventLogOutputFile> send_output(
Bjorn Tereliusde939432017-11-20 17:38:14 +01001901 rtc::MakeUnique<RtcEventLogOutputFile>(
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001902 params.logging.rtc_event_log_name + "_send",
1903 RtcEventLog::kUnlimitedOutput));
1904 std::unique_ptr<RtcEventLogOutputFile> recv_output(
1905 rtc::MakeUnique<RtcEventLogOutputFile>(
1906 params.logging.rtc_event_log_name + "_recv",
1907 RtcEventLog::kUnlimitedOutput));
1908 bool event_log_started =
1909 send_event_log_->StartLogging(std::move(send_output),
1910 RtcEventLog::kImmediateOutput) &&
1911 recv_event_log_->StartLogging(std::move(recv_output),
1912 RtcEventLog::kImmediateOutput);
ilnik98436952017-07-13 00:47:03 -07001913 RTC_DCHECK(event_log_started);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001914 } else {
1915 send_event_log_ = RtcEventLog::CreateNull();
1916 recv_event_log_ = RtcEventLog::CreateNull();
ilnik98436952017-07-13 00:47:03 -07001917 }
1918
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001919 Call::Config send_call_config(send_event_log_.get());
1920 Call::Config recv_call_config(recv_event_log_.get());
1921 send_call_config.bitrate_config = params.call.call_bitrate_config;
1922 recv_call_config.bitrate_config = params.call.call_bitrate_config;
stefanf116bd02015-10-27 08:29:42 -07001923
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001924 task_queue_.SendTask([this, &send_call_config, &recv_call_config,
1925 &send_transport, &recv_transport]() {
1926 CreateCalls(send_call_config, recv_call_config);
1927 send_transport = CreateSendTransport();
1928 recv_transport = CreateReceiveTransport();
1929 });
stefanf116bd02015-10-27 08:29:42 -07001930
sprangce4aef12015-11-02 07:23:20 -08001931 std::string graph_title = params_.analyzer.graph_title;
1932 if (graph_title.empty())
1933 graph_title = VideoQualityTest::GenerateGraphTitle();
sprangc1b57a12017-02-28 08:50:47 -08001934 bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest");
eladalon413ee9a2017-08-22 04:02:52 -07001935 analyzer = rtc::MakeUnique<VideoAnalyzer>(
1936 send_transport.get(), params_.analyzer.test_label,
ilnik2a8c2f52017-02-15 02:23:28 -08001937 params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold,
ilnik9ae0d762017-02-15 00:53:12 -08001938 is_quick_test_enabled
1939 ? kFramesSentInQuickTest
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001940 : params_.analyzer.test_durations_secs * params_.video[0].fps,
sprangce4aef12015-11-02 07:23:20 -08001941 graph_data_output_file, graph_title,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001942 kVideoSendSsrcs[params_.ss[0].selected_stream],
1943 kSendRtxSsrcs[params_.ss[0].selected_stream],
1944 static_cast<size_t>(params_.ss[0].selected_stream),
1945 params.ss[0].selected_sl, params_.video[0].selected_tl,
1946 is_quick_test_enabled, clock_, params_.logging.rtp_dump_name);
ivica5d6a06c2015-09-17 05:30:24 -07001947
eladalon413ee9a2017-08-22 04:02:52 -07001948 task_queue_.SendTask([&]() {
1949 analyzer->SetCall(sender_call_.get());
1950 analyzer->SetReceiver(receiver_call_->Receiver());
1951 send_transport->SetReceiver(analyzer.get());
1952 recv_transport->SetReceiver(sender_call_->Receiver());
ivica5d6a06c2015-09-17 05:30:24 -07001953
eladalon413ee9a2017-08-22 04:02:52 -07001954 SetupVideo(analyzer.get(), recv_transport.get());
1955 SetupThumbnails(analyzer.get(), recv_transport.get());
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001956 video_receive_configs_[params_.ss[0].selected_stream].renderer =
eladalon413ee9a2017-08-22 04:02:52 -07001957 analyzer.get();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001958 video_send_configs_[0].pre_encode_callback = analyzer->pre_encode_proxy();
1959 RTC_DCHECK(!video_send_configs_[0].post_encode_callback);
1960 video_send_configs_[0].post_encode_callback =
1961 analyzer->encode_timing_proxy();
kthelgason2bc68642017-02-07 07:02:22 -08001962
eladalon413ee9a2017-08-22 04:02:52 -07001963 CreateFlexfecStreams();
1964 CreateVideoStreams();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001965 analyzer->SetSendStream(video_send_streams_[0]);
eladalon413ee9a2017-08-22 04:02:52 -07001966 if (video_receive_streams_.size() == 1)
1967 analyzer->SetReceiveStream(video_receive_streams_[0]);
ivica5d6a06c2015-09-17 05:30:24 -07001968
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001969 video_send_streams_[0]->SetSource(analyzer->OutputInterface(),
1970 degradation_preference_);
eladalon413ee9a2017-08-22 04:02:52 -07001971 SetupThumbnailCapturers(params_.call.num_thumbnails);
1972 for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) {
1973 thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(),
1974 degradation_preference_);
1975 }
ilnika014cc52017-03-07 04:21:04 -08001976
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001977 CreateCapturers();
ivicac1cc8542015-10-08 03:44:06 -07001978
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001979 analyzer->SetSource(video_capturers_[0].get(), params_.ss[0].infer_streams);
ilnika014cc52017-03-07 04:21:04 -08001980
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001981 for (size_t video_idx = 1; video_idx < num_video_streams_; ++video_idx) {
1982 video_send_streams_[video_idx]->SetSource(
1983 video_capturers_[video_idx].get(), degradation_preference_);
1984 }
1985
1986 StartEncodedFrameLogs(video_send_streams_[0]);
1987 StartEncodedFrameLogs(
1988 video_receive_streams_[params_.ss[0].selected_stream]);
1989 for (VideoSendStream* video_send_stream : video_send_streams_)
1990 video_send_stream->Start();
eladalon413ee9a2017-08-22 04:02:52 -07001991 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1992 thumbnail_send_stream->Start();
1993 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1994 receive_stream->Start();
1995 for (VideoReceiveStream* thumbnail_receive_stream :
1996 thumbnail_receive_streams_)
1997 thumbnail_receive_stream->Start();
ilnika014cc52017-03-07 04:21:04 -08001998
eladalon413ee9a2017-08-22 04:02:52 -07001999 analyzer->StartMeasuringCpuProcessTime();
ivica5d6a06c2015-09-17 05:30:24 -07002000
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002001 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
2002 video_capturers_[video_idx]->Start();
2003 }
eladalon413ee9a2017-08-22 04:02:52 -07002004 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
2005 thumbnail_capturers_) {
2006 video_caputurer->Start();
2007 }
2008 });
ivica5d6a06c2015-09-17 05:30:24 -07002009
eladalon413ee9a2017-08-22 04:02:52 -07002010 analyzer->Wait();
ivica5d6a06c2015-09-17 05:30:24 -07002011
Ilya Nikolaevskiy2c72fe82017-10-02 13:01:04 +02002012 event_log_->StopLogging();
2013
eladalon413ee9a2017-08-22 04:02:52 -07002014 task_queue_.SendTask([&]() {
2015 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
2016 thumbnail_capturers_)
2017 video_caputurer->Stop();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002018 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
2019 video_capturers_[video_idx]->Stop();
2020 }
eladalon413ee9a2017-08-22 04:02:52 -07002021 for (VideoReceiveStream* thumbnail_receive_stream :
2022 thumbnail_receive_streams_)
2023 thumbnail_receive_stream->Stop();
2024 for (VideoReceiveStream* receive_stream : video_receive_streams_)
2025 receive_stream->Stop();
2026 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
2027 thumbnail_send_stream->Stop();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002028 for (VideoSendStream* video_send_stream : video_send_streams_)
2029 video_send_stream->Stop();
ivica5d6a06c2015-09-17 05:30:24 -07002030
eladalon413ee9a2017-08-22 04:02:52 -07002031 DestroyStreams();
2032 DestroyThumbnailStreams();
ivica5d6a06c2015-09-17 05:30:24 -07002033
eladalon413ee9a2017-08-22 04:02:52 -07002034 if (graph_data_output_file)
2035 fclose(graph_data_output_file);
2036
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002037 video_capturers_.clear();
eladalon413ee9a2017-08-22 04:02:52 -07002038 send_transport.reset();
2039 recv_transport.reset();
2040
2041 DestroyCalls();
2042 });
ivica5d6a06c2015-09-17 05:30:24 -07002043}
2044
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +01002045void VideoQualityTest::SetupAudio(Transport* transport,
minyuea27172d2016-11-01 05:59:29 -07002046 AudioReceiveStream** audio_receive_stream) {
2047 audio_send_config_ = AudioSendStream::Config(transport);
minyuea27172d2016-11-01 05:59:29 -07002048 audio_send_config_.rtp.ssrc = kAudioSendSsrc;
2049
2050 // Add extension to enable audio send side BWE, and allow audio bit rate
2051 // adaptation.
2052 audio_send_config_.rtp.extensions.clear();
2053 if (params_.call.send_side_bwe) {
2054 audio_send_config_.rtp.extensions.push_back(
2055 webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri,
2056 test::kTransportSequenceNumberExtensionId));
minyue10cbb462016-11-07 09:29:22 -08002057 audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps;
2058 audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps;
minyuea27172d2016-11-01 05:59:29 -07002059 }
Oskar Sundbom8e07c132018-01-08 16:45:42 +01002060 audio_send_config_.send_codec_spec = AudioSendStream::Config::SendCodecSpec(
2061 kAudioSendPayloadType,
2062 {"OPUS", 48000, 2,
2063 {{"usedtx", (params_.audio.dtx ? "1" : "0")},
2064 {"stereo", "1"}}});
Rasmus Brandt31027342017-09-29 13:48:12 +00002065 audio_send_config_.encoder_factory = encoder_factory_;
sprang1168fd42017-06-21 09:00:17 -07002066 audio_send_stream_ = sender_call_->CreateAudioSendStream(audio_send_config_);
minyuea27172d2016-11-01 05:59:29 -07002067
2068 AudioReceiveStream::Config audio_config;
2069 audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc;
2070 audio_config.rtcp_send_transport = transport;
minyuea27172d2016-11-01 05:59:29 -07002071 audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc;
2072 audio_config.rtp.transport_cc = params_.call.send_side_bwe;
2073 audio_config.rtp.extensions = audio_send_config_.rtp.extensions;
Rasmus Brandt31027342017-09-29 13:48:12 +00002074 audio_config.decoder_factory = decoder_factory_;
minyue20c84cc2017-04-10 16:57:57 -07002075 audio_config.decoder_map = {{kAudioSendPayloadType, {"OPUS", 48000, 2}}};
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002076 if (params_.video[0].enabled && params_.audio.sync_video)
minyuea27172d2016-11-01 05:59:29 -07002077 audio_config.sync_group = kSyncGroup;
2078
sprang1168fd42017-06-21 09:00:17 -07002079 *audio_receive_stream =
2080 receiver_call_->CreateAudioReceiveStream(audio_config);
minyuea27172d2016-11-01 05:59:29 -07002081}
2082
minyue73208662016-08-18 06:28:55 -07002083void VideoQualityTest::RunWithRenderers(const Params& params) {
Ilya Nikolaevskiyad556762018-01-17 11:48:59 +01002084 rtc::LogMessage::SetLogToStderr(params.logging.logs);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002085 num_video_streams_ = params.call.dual_video ? 2 : 1;
eladalon413ee9a2017-08-22 04:02:52 -07002086 std::unique_ptr<test::LayerFilteringTransport> send_transport;
2087 std::unique_ptr<test::DirectTransport> recv_transport;
minyuea27172d2016-11-01 05:59:29 -07002088 std::unique_ptr<test::VideoRenderer> local_preview;
eladalon413ee9a2017-08-22 04:02:52 -07002089 std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers;
minyue73208662016-08-18 06:28:55 -07002090 AudioReceiveStream* audio_receive_stream = nullptr;
minyue73208662016-08-18 06:28:55 -07002091
eladalon413ee9a2017-08-22 04:02:52 -07002092 task_queue_.SendTask([&]() {
2093 params_ = params;
2094 CheckParams();
palmkviste75f2042016-09-28 06:19:48 -07002095
eladalon413ee9a2017-08-22 04:02:52 -07002096 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
2097 // match the full stack tests.
2098 Call::Config call_config(event_log_.get());
2099 call_config.bitrate_config = params_.call.call_bitrate_config;
Niels Möller2bf9e732017-08-14 11:26:16 +02002100
Fredrik Solenberg2a877972017-12-15 16:42:15 +01002101 rtc::scoped_refptr<test::FakeAudioDevice> fake_audio_device =
2102 new rtc::RefCountedObject<test::FakeAudioDevice>(
2103 test::FakeAudioDevice::CreatePulsedNoiseCapturer(32000, 48000),
2104 test::FakeAudioDevice::CreateDiscardRenderer(48000),
2105 1.f);
ivica5d6a06c2015-09-17 05:30:24 -07002106
eladalon413ee9a2017-08-22 04:02:52 -07002107 if (params_.audio.enabled) {
eladalon413ee9a2017-08-22 04:02:52 -07002108 AudioState::Config audio_state_config;
eladalon413ee9a2017-08-22 04:02:52 -07002109 audio_state_config.audio_mixer = AudioMixerImpl::Create();
Ivo Creusen62337e52018-01-09 14:17:33 +01002110 audio_state_config.audio_processing = AudioProcessingBuilder().Create();
Fredrik Solenberg2a877972017-12-15 16:42:15 +01002111 audio_state_config.audio_device_module = fake_audio_device;
eladalon413ee9a2017-08-22 04:02:52 -07002112 call_config.audio_state = AudioState::Create(audio_state_config);
Fredrik Solenbergd3195342017-11-21 20:33:05 +01002113 fake_audio_device->RegisterAudioCallback(
2114 call_config.audio_state->audio_transport());
eladalon413ee9a2017-08-22 04:02:52 -07002115 }
minyue73208662016-08-18 06:28:55 -07002116
eladalon413ee9a2017-08-22 04:02:52 -07002117 CreateCalls(call_config, call_config);
2118
2119 // TODO(minyue): consider if this is a good transport even for audio only
2120 // calls.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002121 send_transport = CreateSendTransport();
eladalon413ee9a2017-08-22 04:02:52 -07002122
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002123 recv_transport = CreateReceiveTransport();
eladalon413ee9a2017-08-22 04:02:52 -07002124
2125 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
2126 // least share as much code as possible. That way this test would also match
2127 // the full stack tests better.
2128 send_transport->SetReceiver(receiver_call_->Receiver());
2129 recv_transport->SetReceiver(sender_call_->Receiver());
2130
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002131 if (params_.video[0].enabled) {
eladalon413ee9a2017-08-22 04:02:52 -07002132 // Create video renderers.
2133 local_preview.reset(test::VideoRenderer::Create(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002134 "Local Preview", params_.video[0].width, params_.video[0].height));
eladalon413ee9a2017-08-22 04:02:52 -07002135
2136 SetupVideo(send_transport.get(), recv_transport.get());
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002137 video_send_configs_[0].pre_encode_callback = local_preview.get();
eladalon413ee9a2017-08-22 04:02:52 -07002138
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002139 size_t num_streams_processed = 0;
2140 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
2141 const size_t selected_stream_id = params_.ss[video_idx].selected_stream;
2142 const size_t num_streams = params_.ss[video_idx].streams.size();
2143 if (selected_stream_id == num_streams) {
2144 for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) {
2145 std::ostringstream oss;
2146 oss << "Loopback Video #" << video_idx << " - Stream #"
2147 << static_cast<int>(stream_id);
2148 loopback_renderers.emplace_back(test::VideoRenderer::Create(
2149 oss.str().c_str(),
2150 params_.ss[video_idx].streams[stream_id].width,
2151 params_.ss[video_idx].streams[stream_id].height));
2152 video_receive_configs_[stream_id + num_streams_processed].renderer =
2153 loopback_renderers.back().get();
2154 if (params_.audio.enabled && params_.audio.sync_video)
2155 video_receive_configs_[stream_id + num_streams_processed]
2156 .sync_group = kSyncGroup;
2157 }
2158 } else {
2159 std::ostringstream oss;
2160 oss << "Loopback Video #" << video_idx;
2161 loopback_renderers.emplace_back(test::VideoRenderer::Create(
2162 oss.str().c_str(),
2163 params_.ss[video_idx].streams[selected_stream_id].width,
2164 params_.ss[video_idx].streams[selected_stream_id].height));
2165 video_receive_configs_[selected_stream_id + num_streams_processed]
2166 .renderer = loopback_renderers.back().get();
eladalon413ee9a2017-08-22 04:02:52 -07002167 if (params_.audio.enabled && params_.audio.sync_video)
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002168 video_receive_configs_[num_streams_processed + selected_stream_id]
2169 .sync_group = kSyncGroup;
eladalon413ee9a2017-08-22 04:02:52 -07002170 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002171 num_streams_processed += num_streams;
eladalon413ee9a2017-08-22 04:02:52 -07002172 }
eladalon413ee9a2017-08-22 04:02:52 -07002173 CreateFlexfecStreams();
2174 CreateVideoStreams();
2175
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002176 CreateCapturers();
2177 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
2178 video_send_streams_[video_idx]->SetSource(
2179 video_capturers_[video_idx].get(), degradation_preference_);
2180 }
eladalon413ee9a2017-08-22 04:02:52 -07002181 }
2182
2183 if (params_.audio.enabled) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +01002184 SetupAudio(send_transport.get(), &audio_receive_stream);
eladalon413ee9a2017-08-22 04:02:52 -07002185 }
2186
2187 for (VideoReceiveStream* receive_stream : video_receive_streams_)
2188 StartEncodedFrameLogs(receive_stream);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002189 StartEncodedFrameLogs(video_send_streams_[0]);
eladalon413ee9a2017-08-22 04:02:52 -07002190
2191 // Start sending and receiving video.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002192 if (params_.video[0].enabled) {
eladalon413ee9a2017-08-22 04:02:52 -07002193 for (VideoReceiveStream* video_receive_stream : video_receive_streams_)
2194 video_receive_stream->Start();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002195 for (VideoSendStream* video_send_stream : video_send_streams_)
2196 video_send_stream->Start();
2197 for (auto& video_capturer : video_capturers_)
2198 video_capturer->Start();
eladalon413ee9a2017-08-22 04:02:52 -07002199 }
2200
2201 if (params_.audio.enabled) {
2202 // Start receiving audio.
2203 audio_receive_stream->Start();
eladalon413ee9a2017-08-22 04:02:52 -07002204
2205 // Start sending audio.
2206 audio_send_stream_->Start();
eladalon413ee9a2017-08-22 04:02:52 -07002207 }
2208 });
minyue73208662016-08-18 06:28:55 -07002209
ivica5d6a06c2015-09-17 05:30:24 -07002210 test::PressEnterToContinue();
2211
eladalon413ee9a2017-08-22 04:02:52 -07002212 task_queue_.SendTask([&]() {
2213 if (params_.audio.enabled) {
2214 // Stop sending audio.
eladalon413ee9a2017-08-22 04:02:52 -07002215 audio_send_stream_->Stop();
minyue73208662016-08-18 06:28:55 -07002216
eladalon413ee9a2017-08-22 04:02:52 -07002217 // Stop receiving audio.
eladalon413ee9a2017-08-22 04:02:52 -07002218 audio_receive_stream->Stop();
eladalon413ee9a2017-08-22 04:02:52 -07002219 }
minyue73208662016-08-18 06:28:55 -07002220
eladalon413ee9a2017-08-22 04:02:52 -07002221 // Stop receiving and sending video.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002222 if (params_.video[0].enabled) {
2223 for (auto& video_capturer : video_capturers_)
2224 video_capturer->Stop();
2225 for (VideoSendStream* video_send_stream : video_send_streams_)
2226 video_send_stream->Stop();
2227 DestroyStreams();
brandtr1293aca2016-11-16 22:47:29 -08002228 }
minyue73208662016-08-18 06:28:55 -07002229
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01002230 video_capturers_.clear();
eladalon413ee9a2017-08-22 04:02:52 -07002231 send_transport.reset();
2232 recv_transport.reset();
sprang1168fd42017-06-21 09:00:17 -07002233
eladalon413ee9a2017-08-22 04:02:52 -07002234 local_preview.reset();
2235 loopback_renderers.clear();
2236
2237 DestroyCalls();
2238 });
ivica5d6a06c2015-09-17 05:30:24 -07002239}
2240
palmkviste75f2042016-09-28 06:19:48 -07002241void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) {
ilnik98436952017-07-13 00:47:03 -07002242 if (!params_.logging.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07002243 std::ostringstream str;
2244 str << send_logs_++;
2245 std::string prefix =
ilnik98436952017-07-13 00:47:03 -07002246 params_.logging.encoded_frame_base_path + "." + str.str() + ".send.";
palmkviste75f2042016-09-28 06:19:48 -07002247 stream->EnableEncodedFrameRecording(
2248 std::vector<rtc::PlatformFile>(
2249 {rtc::CreatePlatformFile(prefix + "1.ivf"),
2250 rtc::CreatePlatformFile(prefix + "2.ivf"),
2251 rtc::CreatePlatformFile(prefix + "3.ivf")}),
ilnik98436952017-07-13 00:47:03 -07002252 100000000);
palmkviste75f2042016-09-28 06:19:48 -07002253 }
2254}
ilnikcb8c1462017-03-09 09:23:30 -08002255
palmkviste75f2042016-09-28 06:19:48 -07002256void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) {
ilnik98436952017-07-13 00:47:03 -07002257 if (!params_.logging.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07002258 std::ostringstream str;
2259 str << receive_logs_++;
2260 std::string path =
ilnik98436952017-07-13 00:47:03 -07002261 params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
palmkviste75f2042016-09-28 06:19:48 -07002262 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path),
ilnik98436952017-07-13 00:47:03 -07002263 100000000);
palmkviste75f2042016-09-28 06:19:48 -07002264 }
2265}
ivica5d6a06c2015-09-17 05:30:24 -07002266} // namespace webrtc