blob: 826567c21f8f94a9a12b33a266102129aeb2c2b8 [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
ivica5d6a06c2015-09-17 05:30:24 -070014#include <algorithm>
15#include <deque>
16#include <map>
Mirko Bonadei317a1f02019-09-17 17:06:18 +020017#include <memory>
mflodmand1590b22015-12-09 07:07:59 -080018#include <string>
ivica5d6a06c2015-09-17 05:30:24 -070019#include <vector>
20
Elad Alon8f01c4e2019-06-28 15:19:43 +020021#include "api/fec_controller_override.h"
Niels Möllerd8b9ed72019-05-08 13:53:51 +020022#include "api/rtc_event_log_output_file.h"
Danil Chapovalov1c41be62019-04-01 09:16:12 +020023#include "api/task_queue/default_task_queue_factory.h"
Danil Chapovalov44db4362019-09-30 04:16:28 +020024#include "api/task_queue/task_queue_base.h"
Artem Titov33f9d2b2019-12-05 15:59:00 +010025#include "api/test/create_frame_generator.h"
Jiawei Ouc2ebe212018-11-08 10:02:56 -080026#include "api/video/builtin_video_bitrate_allocator_factory.h"
Elad Alon370f93a2019-06-11 14:57:57 +020027#include "api/video_codecs/video_encoder.h"
Artem Titovdd2eebe2018-08-20 13:27:45 +020028#include "call/fake_network_pipe.h"
29#include "call/simulated_network.h"
henrika255750b2018-08-27 16:13:37 +020030#include "media/engine/adm_helpers.h"
Florent Castellie7862cc2018-12-06 13:38:24 +010031#include "media/engine/encoder_simulcast_proxy.h"
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -050032#include "media/engine/fake_video_codec_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "media/engine/internal_encoder_factory.h"
34#include "media/engine/webrtc_video_engine.h"
henrika255750b2018-08-27 16:13:37 +020035#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "modules/audio_mixer/audio_mixer_impl.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "modules/video_coding/codecs/h264/include/h264.h"
Niels Möllercbcbc222018-09-28 09:07:24 +020038#include "modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h"
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080039#include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h"
Niels Möller4db138e2018-04-19 09:04:13 +020040#include "modules/video_coding/codecs/vp8/include/vp8.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020041#include "modules/video_coding/codecs/vp9/include/vp9.h"
Niels Möller1beef1a2018-09-03 14:21:44 +020042#include "modules/video_coding/utility/ivf_file_writer.h"
43#include "rtc_base/strings/string_builder.h"
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +020044#include "rtc_base/task_queue_for_test.h"
Kári Tristan Helgasonede7cb22019-03-06 10:34:09 +010045#include "test/platform_video_capturer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "test/run_loop.h"
Steve Anton10542f22019-01-11 09:11:00 -080047#include "test/testsupport/file_utils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "test/video_renderer.h"
Erik Språng96965ae2018-10-23 15:42:37 +020049#include "video/frame_dumping_decoder.h"
henrika255750b2018-08-27 16:13:37 +020050#ifdef WEBRTC_WIN
51#include "modules/audio_device/include/audio_device_factory.h"
52#endif
ilnikee42d192017-08-22 07:16:20 -070053
Niels Möller1beef1a2018-09-03 14:21:44 +020054namespace webrtc {
55
minyue73208662016-08-18 06:28:55 -070056namespace {
Elad Alond8d32482019-02-18 23:45:57 +010057enum : int { // The first valid value is 1.
58 kAbsSendTimeExtensionId = 1,
Elad Alonccb9b752019-02-19 13:01:31 +010059 kGenericFrameDescriptorExtensionId00,
60 kGenericFrameDescriptorExtensionId01,
Elad Alond8d32482019-02-18 23:45:57 +010061 kTransportSequenceNumberExtensionId,
62 kVideoContentTypeExtensionId,
63 kVideoTimingExtensionId,
64};
65
minyue73208662016-08-18 06:28:55 -070066constexpr char kSyncGroup[] = "av_sync";
minyue10cbb462016-11-07 09:29:22 -080067constexpr int kOpusMinBitrateBps = 6000;
68constexpr int kOpusBitrateFbBps = 32000;
ilnik9ae0d762017-02-15 00:53:12 -080069constexpr int kFramesSentInQuickTest = 1;
ilnika014cc52017-03-07 04:21:04 -080070constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000;
71constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000;
minyue73208662016-08-18 06:28:55 -070072
sprang1168fd42017-06-21 09:00:17 -070073constexpr int kDefaultMaxQp = cricket::WebRtcVideoChannel::kDefaultQpMax;
74
Elad Alon370f93a2019-06-11 14:57:57 +020075const VideoEncoder::Capabilities kCapabilities(false);
76
Erik Språng616b2332019-02-11 14:16:28 +010077std::pair<uint32_t, uint32_t> GetMinMaxBitratesBps(const VideoCodec& codec,
78 size_t spatial_idx) {
79 uint32_t min_bitrate = codec.minBitrate;
80 uint32_t max_bitrate = codec.maxBitrate;
81 if (spatial_idx < codec.numberOfSimulcastStreams) {
82 min_bitrate =
83 std::max(min_bitrate, codec.simulcastStream[spatial_idx].minBitrate);
84 max_bitrate =
85 std::min(max_bitrate, codec.simulcastStream[spatial_idx].maxBitrate);
86 }
87 if (codec.codecType == VideoCodecType::kVideoCodecVP9 &&
88 spatial_idx < codec.VP9().numberOfSpatialLayers) {
89 min_bitrate =
90 std::max(min_bitrate, codec.spatialLayers[spatial_idx].minBitrate);
91 max_bitrate =
92 std::min(max_bitrate, codec.spatialLayers[spatial_idx].maxBitrate);
93 }
94 max_bitrate = std::max(max_bitrate, min_bitrate);
95 return {min_bitrate * 1000, max_bitrate * 1000};
96}
97
perkjfa10b552016-10-02 23:45:26 -070098class VideoStreamFactory
Niels Möller1beef1a2018-09-03 14:21:44 +020099 : public VideoEncoderConfig::VideoStreamFactoryInterface {
perkjfa10b552016-10-02 23:45:26 -0700100 public:
Niels Möller1beef1a2018-09-03 14:21:44 +0200101 explicit VideoStreamFactory(const std::vector<VideoStream>& streams)
perkjfa10b552016-10-02 23:45:26 -0700102 : streams_(streams) {}
103
104 private:
Niels Möller1beef1a2018-09-03 14:21:44 +0200105 std::vector<VideoStream> CreateEncoderStreams(
perkjfa10b552016-10-02 23:45:26 -0700106 int width,
107 int height,
Niels Möller1beef1a2018-09-03 14:21:44 +0200108 const VideoEncoderConfig& encoder_config) override {
mflodmand79f97b2016-12-15 07:24:33 -0800109 // The highest layer must match the incoming resolution.
Niels Möller1beef1a2018-09-03 14:21:44 +0200110 std::vector<VideoStream> streams = streams_;
mflodmand79f97b2016-12-15 07:24:33 -0800111 streams[streams_.size() - 1].height = height;
112 streams[streams_.size() - 1].width = width;
Seth Hampson24722b32017-12-22 09:36:42 -0800113
114 streams[0].bitrate_priority = encoder_config.bitrate_priority;
mflodmand79f97b2016-12-15 07:24:33 -0800115 return streams;
perkjfa10b552016-10-02 23:45:26 -0700116 }
117
Niels Möller1beef1a2018-09-03 14:21:44 +0200118 std::vector<VideoStream> streams_;
perkjfa10b552016-10-02 23:45:26 -0700119};
ivica5d6a06c2015-09-17 05:30:24 -0700120
Niels Möller88be9722018-10-10 10:58:52 +0200121// This wrapper provides two features needed by the video quality tests:
122// 1. Invoke VideoAnalyzer callbacks before and after encoding each frame.
123// 2. Write the encoded frames to file, one file per simulcast layer.
124class QualityTestVideoEncoder : public VideoEncoder,
125 private EncodedImageCallback {
Niels Möller1beef1a2018-09-03 14:21:44 +0200126 public:
Niels Möller88be9722018-10-10 10:58:52 +0200127 QualityTestVideoEncoder(std::unique_ptr<VideoEncoder> encoder,
128 VideoAnalyzer* analyzer,
Erik Språng616b2332019-02-11 14:16:28 +0100129 std::vector<FileWrapper> files,
130 double overshoot_factor)
131 : encoder_(std::move(encoder)),
132 overshoot_factor_(overshoot_factor),
133 analyzer_(analyzer) {
Niels Möllerb7edf692019-02-08 16:40:53 +0100134 for (FileWrapper& file : files) {
Niels Möller1beef1a2018-09-03 14:21:44 +0200135 writers_.push_back(
Niels Möllerb7edf692019-02-08 16:40:53 +0100136 IvfFileWriter::Wrap(std::move(file), /* byte_limit= */ 100000000));
Niels Möller1beef1a2018-09-03 14:21:44 +0200137 }
138 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200139
Niels Möller1beef1a2018-09-03 14:21:44 +0200140 // Implement VideoEncoder
Elad Alon8f01c4e2019-06-28 15:19:43 +0200141 void SetFecControllerOverride(
142 FecControllerOverride* fec_controller_override) {
143 // Ignored.
144 }
145
Niels Möller1beef1a2018-09-03 14:21:44 +0200146 int32_t InitEncode(const VideoCodec* codec_settings,
Elad Alon370f93a2019-06-11 14:57:57 +0200147 const Settings& settings) override {
Erik Språng616b2332019-02-11 14:16:28 +0100148 codec_settings_ = *codec_settings;
Elad Alon370f93a2019-06-11 14:57:57 +0200149 return encoder_->InitEncode(codec_settings, settings);
Niels Möller1beef1a2018-09-03 14:21:44 +0200150 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200151
Niels Möller1beef1a2018-09-03 14:21:44 +0200152 int32_t RegisterEncodeCompleteCallback(
153 EncodedImageCallback* callback) override {
154 callback_ = callback;
155 return encoder_->RegisterEncodeCompleteCallback(this);
156 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200157
Niels Möller1beef1a2018-09-03 14:21:44 +0200158 int32_t Release() override { return encoder_->Release(); }
Elad Alonfe4f6942019-05-07 23:13:42 +0200159
Niels Möller1beef1a2018-09-03 14:21:44 +0200160 int32_t Encode(const VideoFrame& frame,
Niels Möller87e2d782019-03-07 10:18:23 +0100161 const std::vector<VideoFrameType>* frame_types) {
Niels Möller88be9722018-10-10 10:58:52 +0200162 if (analyzer_) {
163 analyzer_->PreEncodeOnFrame(frame);
164 }
Niels Möllerc8d2e732019-03-06 12:00:33 +0100165 return encoder_->Encode(frame, frame_types);
Niels Möller1beef1a2018-09-03 14:21:44 +0200166 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200167
Erik Språng16cb8f52019-04-12 13:59:09 +0200168 void SetRates(const RateControlParameters& parameters) override {
Erik Språng616b2332019-02-11 14:16:28 +0100169 RTC_DCHECK_GT(overshoot_factor_, 0.0);
170 if (overshoot_factor_ == 1.0) {
Erik Språng16cb8f52019-04-12 13:59:09 +0200171 encoder_->SetRates(parameters);
172 return;
Erik Språng616b2332019-02-11 14:16:28 +0100173 }
174
175 // Simulating encoder overshooting target bitrate, by configuring actual
176 // encoder too high. Take care not to adjust past limits of config,
177 // otherwise encoders may crash on DCHECK.
178 VideoBitrateAllocation overshot_allocation;
179 for (size_t si = 0; si < kMaxSpatialLayers; ++si) {
180 const uint32_t spatial_layer_bitrate_bps =
Erik Språng16cb8f52019-04-12 13:59:09 +0200181 parameters.bitrate.GetSpatialLayerSum(si);
Erik Språng616b2332019-02-11 14:16:28 +0100182 if (spatial_layer_bitrate_bps == 0) {
183 continue;
184 }
185
186 uint32_t min_bitrate_bps;
187 uint32_t max_bitrate_bps;
188 std::tie(min_bitrate_bps, max_bitrate_bps) =
189 GetMinMaxBitratesBps(codec_settings_, si);
190 double overshoot_factor = overshoot_factor_;
191 const uint32_t corrected_bitrate = rtc::checked_cast<uint32_t>(
192 overshoot_factor * spatial_layer_bitrate_bps);
193 if (corrected_bitrate < min_bitrate_bps) {
194 overshoot_factor = min_bitrate_bps / spatial_layer_bitrate_bps;
195 } else if (corrected_bitrate > max_bitrate_bps) {
196 overshoot_factor = max_bitrate_bps / spatial_layer_bitrate_bps;
197 }
198
199 for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) {
Erik Språng16cb8f52019-04-12 13:59:09 +0200200 if (parameters.bitrate.HasBitrate(si, ti)) {
Erik Språng616b2332019-02-11 14:16:28 +0100201 overshot_allocation.SetBitrate(
202 si, ti,
Erik Språng16cb8f52019-04-12 13:59:09 +0200203 rtc::checked_cast<uint32_t>(
204 overshoot_factor * parameters.bitrate.GetBitrate(si, ti)));
Erik Språng616b2332019-02-11 14:16:28 +0100205 }
206 }
207 }
208
Erik Språng16cb8f52019-04-12 13:59:09 +0200209 return encoder_->SetRates(
210 RateControlParameters(overshot_allocation, parameters.framerate_fps,
211 parameters.bandwidth_allocation));
Niels Möller1beef1a2018-09-03 14:21:44 +0200212 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200213
214 void OnPacketLossRateUpdate(float packet_loss_rate) override {
215 encoder_->OnPacketLossRateUpdate(packet_loss_rate);
216 }
217
218 void OnRttUpdate(int64_t rtt_ms) override { encoder_->OnRttUpdate(rtt_ms); }
219
220 void OnLossNotification(const LossNotification& loss_notification) override {
221 encoder_->OnLossNotification(loss_notification);
222 }
223
Erik Språng189013b2018-11-01 15:03:57 +0100224 EncoderInfo GetEncoderInfo() const override {
Erik Språng616b2332019-02-11 14:16:28 +0100225 EncoderInfo info = encoder_->GetEncoderInfo();
226 if (overshoot_factor_ != 1.0) {
227 // We're simulating bad encoder, don't forward trusted setting
228 // from eg libvpx.
229 info.has_trusted_rate_controller = false;
230 }
231 return info;
Niels Möller1beef1a2018-09-03 14:21:44 +0200232 }
233
234 private:
235 // Implement EncodedImageCallback
236 Result OnEncodedImage(const EncodedImage& encoded_image,
237 const CodecSpecificInfo* codec_specific_info,
238 const RTPFragmentationHeader* fragmentation) override {
239 if (codec_specific_info) {
240 int simulcast_index;
241 if (codec_specific_info->codecType == kVideoCodecVP9) {
242 simulcast_index = 0;
243 } else {
244 simulcast_index = encoded_image.SpatialIndex().value_or(0);
245 }
246 RTC_DCHECK_GE(simulcast_index, 0);
Niels Möller88be9722018-10-10 10:58:52 +0200247 if (analyzer_) {
248 analyzer_->PostEncodeOnFrame(simulcast_index,
249 encoded_image.Timestamp());
250 }
Niels Möller1beef1a2018-09-03 14:21:44 +0200251 if (static_cast<size_t>(simulcast_index) < writers_.size()) {
252 writers_[simulcast_index]->WriteFrame(encoded_image,
253 codec_specific_info->codecType);
254 }
255 }
256
257 return callback_->OnEncodedImage(encoded_image, codec_specific_info,
258 fragmentation);
259 }
260
261 void OnDroppedFrame(DropReason reason) override {
262 callback_->OnDroppedFrame(reason);
263 }
264
Erik Språng616b2332019-02-11 14:16:28 +0100265 const std::unique_ptr<VideoEncoder> encoder_;
266 const double overshoot_factor_;
Niels Möller88be9722018-10-10 10:58:52 +0200267 VideoAnalyzer* const analyzer_;
Niels Möller1beef1a2018-09-03 14:21:44 +0200268 std::vector<std::unique_ptr<IvfFileWriter>> writers_;
Erik Språng616b2332019-02-11 14:16:28 +0100269 EncodedImageCallback* callback_ = nullptr;
270 VideoCodec codec_settings_;
Niels Möller1beef1a2018-09-03 14:21:44 +0200271};
272
273} // namespace
ivica5d6a06c2015-09-17 05:30:24 -0700274
Niels Möllercbcbc222018-09-28 09:07:24 +0200275std::unique_ptr<VideoDecoder> VideoQualityTest::CreateVideoDecoder(
276 const SdpVideoFormat& format) {
277 std::unique_ptr<VideoDecoder> decoder;
278 if (format.name == "multiplex") {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200279 decoder = std::make_unique<MultiplexDecoderAdapter>(
“Michael3c396e52019-06-12 09:47:14 -0500280 decoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName));
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -0500281 } else if (format.name == "FakeCodec") {
282 decoder = webrtc::FakeVideoDecoderFactory::CreateVideoDecoder();
Niels Möllercbcbc222018-09-28 09:07:24 +0200283 } else {
“Michael3c396e52019-06-12 09:47:14 -0500284 decoder = decoder_factory_->CreateVideoDecoder(format);
Niels Möllercbcbc222018-09-28 09:07:24 +0200285 }
Niels Möller5ca29122018-10-02 09:55:01 +0200286 if (!params_.logging.encoded_frame_base_path.empty()) {
287 rtc::StringBuilder str;
288 str << receive_logs_++;
289 std::string path =
290 params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
Markus Handell1c2f6372019-08-20 20:21:37 +0200291 decoder = CreateFrameDumpingDecoderWrapper(
Niels Möllerb7edf692019-02-08 16:40:53 +0100292 std::move(decoder), FileWrapper::OpenWriteOnly(path));
Niels Möller5ca29122018-10-02 09:55:01 +0200293 }
Niels Möllercbcbc222018-09-28 09:07:24 +0200294 return decoder;
295}
296
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200297std::unique_ptr<VideoEncoder> VideoQualityTest::CreateVideoEncoder(
Niels Möller88be9722018-10-10 10:58:52 +0200298 const SdpVideoFormat& format,
299 VideoAnalyzer* analyzer) {
Niels Möller1beef1a2018-09-03 14:21:44 +0200300 std::unique_ptr<VideoEncoder> encoder;
Niels Möller4db138e2018-04-19 09:04:13 +0200301 if (format.name == "VP8") {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200302 encoder =
303 std::make_unique<EncoderSimulcastProxy>(encoder_factory_.get(), format);
Niels Möller4db138e2018-04-19 09:04:13 +0200304 } else if (format.name == "multiplex") {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200305 encoder = std::make_unique<MultiplexEncoderAdapter>(
“Michael3c396e52019-06-12 09:47:14 -0500306 encoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName));
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -0500307 } else if (format.name == "FakeCodec") {
308 encoder = webrtc::FakeVideoEncoderFactory::CreateVideoEncoder();
Niels Möller1beef1a2018-09-03 14:21:44 +0200309 } else {
“Michael3c396e52019-06-12 09:47:14 -0500310 encoder = encoder_factory_->CreateVideoEncoder(format);
Niels Möller4db138e2018-04-19 09:04:13 +0200311 }
Erik Språng616b2332019-02-11 14:16:28 +0100312
313 std::vector<FileWrapper> encoded_frame_dump_files;
Niels Möller1beef1a2018-09-03 14:21:44 +0200314 if (!params_.logging.encoded_frame_base_path.empty()) {
315 char ss_buf[100];
316 rtc::SimpleStringBuilder sb(ss_buf);
317 sb << send_logs_++;
318 std::string prefix =
319 params_.logging.encoded_frame_base_path + "." + sb.str() + ".send.";
Erik Språng616b2332019-02-11 14:16:28 +0100320 encoded_frame_dump_files.push_back(
321 FileWrapper::OpenWriteOnly(prefix + "1.ivf"));
322 encoded_frame_dump_files.push_back(
323 FileWrapper::OpenWriteOnly(prefix + "2.ivf"));
324 encoded_frame_dump_files.push_back(
325 FileWrapper::OpenWriteOnly(prefix + "3.ivf"));
326 }
Niels Möllerb7edf692019-02-08 16:40:53 +0100327
Erik Språng616b2332019-02-11 14:16:28 +0100328 double overshoot_factor = 1.0;
329 // Match format to either of the streams in dual-stream mode in order to get
330 // the overshoot factor. This is not very robust but we can't know for sure
331 // which stream this encoder is meant for, from within the factory.
332 if (format ==
333 SdpVideoFormat(params_.video[0].codec, params_.video[0].sdp_params)) {
334 overshoot_factor = params_.video[0].encoder_overshoot_factor;
335 } else if (format == SdpVideoFormat(params_.video[1].codec,
336 params_.video[1].sdp_params)) {
337 overshoot_factor = params_.video[1].encoder_overshoot_factor;
338 }
339 if (overshoot_factor == 0.0) {
340 // If params were zero-initialized, set to 1.0 instead.
341 overshoot_factor = 1.0;
342 }
343
344 if (analyzer || !encoded_frame_dump_files.empty() || overshoot_factor > 1.0) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200345 encoder = std::make_unique<QualityTestVideoEncoder>(
Erik Språng616b2332019-02-11 14:16:28 +0100346 std::move(encoder), analyzer, std::move(encoded_frame_dump_files),
347 overshoot_factor);
Niels Möller1beef1a2018-09-03 14:21:44 +0200348 }
Niels Möller88be9722018-10-10 10:58:52 +0200349
Niels Möller1beef1a2018-09-03 14:21:44 +0200350 return encoder;
Niels Möller4db138e2018-04-19 09:04:13 +0200351}
352
Patrik Höglundb6b29e02018-06-21 16:58:01 +0200353VideoQualityTest::VideoQualityTest(
Artem Titove269cb42018-08-29 09:59:23 +0200354 std::unique_ptr<InjectionComponents> injection_components)
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200355 : clock_(Clock::GetRealTimeClock()),
Danil Chapovalov1c41be62019-04-01 09:16:12 +0200356 task_queue_factory_(CreateDefaultTaskQueueFactory()),
Danil Chapovalov304ea5f2019-04-11 15:18:18 +0200357 rtc_event_log_factory_(task_queue_factory_.get()),
Niels Möllercbcbc222018-09-28 09:07:24 +0200358 video_decoder_factory_([this](const SdpVideoFormat& format) {
359 return this->CreateVideoDecoder(format);
360 }),
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200361 video_encoder_factory_([this](const SdpVideoFormat& format) {
Niels Möller88be9722018-10-10 10:58:52 +0200362 return this->CreateVideoEncoder(format, nullptr);
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200363 }),
Niels Möller88be9722018-10-10 10:58:52 +0200364 video_encoder_factory_with_analyzer_(
365 [this](const SdpVideoFormat& format) {
366 return this->CreateVideoEncoder(format, analyzer_.get());
367 }),
Jiawei Ouc2ebe212018-11-08 10:02:56 -0800368 video_bitrate_allocator_factory_(
369 CreateBuiltinVideoBitrateAllocatorFactory()),
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200370 receive_logs_(0),
Artem Titove269cb42018-08-29 09:59:23 +0200371 send_logs_(0),
Erik Språng96965ae2018-10-23 15:42:37 +0200372 injection_components_(std::move(injection_components)),
373 num_video_streams_(0) {
Artem Titove269cb42018-08-29 09:59:23 +0200374 if (injection_components_ == nullptr) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200375 injection_components_ = std::make_unique<InjectionComponents>();
Artem Titove269cb42018-08-29 09:59:23 +0200376 }
“Michael3c396e52019-06-12 09:47:14 -0500377 if (injection_components_->video_decoder_factory != nullptr) {
378 decoder_factory_ = std::move(injection_components_->video_decoder_factory);
379 } else {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200380 decoder_factory_ = std::make_unique<InternalDecoderFactory>();
“Michael3c396e52019-06-12 09:47:14 -0500381 }
382 if (injection_components_->video_encoder_factory != nullptr) {
383 encoder_factory_ = std::move(injection_components_->video_encoder_factory);
384 } else {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200385 encoder_factory_ = std::make_unique<InternalEncoderFactory>();
“Michael3c396e52019-06-12 09:47:14 -0500386 }
Artem Titove269cb42018-08-29 09:59:23 +0200387
minyue20c84cc2017-04-10 16:57:57 -0700388 payload_type_map_ = test::CallTest::payload_type_map_;
389 RTC_DCHECK(payload_type_map_.find(kPayloadTypeH264) ==
390 payload_type_map_.end());
391 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP8) ==
392 payload_type_map_.end());
393 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP9) ==
394 payload_type_map_.end());
Rasmus Brandt5894b6a2019-06-13 16:28:14 +0200395 RTC_DCHECK(payload_type_map_.find(kPayloadTypeGeneric) ==
396 payload_type_map_.end());
minyue20c84cc2017-04-10 16:57:57 -0700397 payload_type_map_[kPayloadTypeH264] = webrtc::MediaType::VIDEO;
398 payload_type_map_[kPayloadTypeVP8] = webrtc::MediaType::VIDEO;
399 payload_type_map_[kPayloadTypeVP9] = webrtc::MediaType::VIDEO;
Rasmus Brandt5894b6a2019-06-13 16:28:14 +0200400 payload_type_map_[kPayloadTypeGeneric] = webrtc::MediaType::VIDEO;
ivica5d6a06c2015-09-17 05:30:24 -0700401
Artem Titove269cb42018-08-29 09:59:23 +0200402 fec_controller_factory_ =
403 std::move(injection_components_->fec_controller_factory);
Ying Wangcab77fd2019-04-16 11:12:49 +0200404 network_state_predictor_factory_ =
405 std::move(injection_components_->network_state_predictor_factory);
Sebastian Jansson1391ed22019-04-30 14:23:51 +0200406 network_controller_factory_ =
407 std::move(injection_components_->network_controller_factory);
Ying Wang3b790f32018-01-19 17:58:57 +0100408}
409
minyue626bc952016-10-31 05:47:02 -0700410VideoQualityTest::Params::Params()
philipel569397f2018-09-26 12:25:31 +0200411 : call({false, false, BitrateConstraints(), 0}),
Erik Språng616b2332019-02-11 14:16:28 +0100412 video{{false,
413 640,
414 480,
415 30,
416 50,
417 800,
418 800,
419 false,
420 "VP8",
421 1,
422 -1,
423 0,
424 false,
425 false,
426 false,
427 "",
428 0,
429 {},
430 0.0},
431 {false,
432 640,
433 480,
434 30,
435 50,
436 800,
437 800,
438 false,
439 "VP8",
440 1,
441 -1,
442 0,
443 false,
444 false,
445 false,
446 "",
447 0,
448 {},
449 0.0}},
henrika255750b2018-08-27 16:13:37 +0200450 audio({false, false, false, false}),
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100451 screenshare{{false, false, 10, 0}, {false, false, 10, 0}},
minyue626bc952016-10-31 05:47:02 -0700452 analyzer({"", 0.0, 0.0, 0, "", ""}),
Artem Titovf18b3522018-08-28 16:54:24 +0200453 config(absl::nullopt),
Sergey Silkin57027362018-05-15 09:12:05 +0200454 ss{{std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn,
455 std::vector<SpatialLayer>()},
456 {std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn,
457 std::vector<SpatialLayer>()}},
Mirko Bonadei45a4c412018-07-31 15:07:28 +0200458 logging({"", "", ""}) {}
minyue626bc952016-10-31 05:47:02 -0700459
460VideoQualityTest::Params::~Params() = default;
461
Artem Titove269cb42018-08-29 09:59:23 +0200462VideoQualityTest::InjectionComponents::InjectionComponents() = default;
463
464VideoQualityTest::InjectionComponents::~InjectionComponents() = default;
465
ivica5d6a06c2015-09-17 05:30:24 -0700466void VideoQualityTest::TestBody() {}
467
sprangce4aef12015-11-02 07:23:20 -0800468std::string VideoQualityTest::GenerateGraphTitle() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200469 rtc::StringBuilder ss;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100470 ss << params_.video[0].codec;
471 ss << " (" << params_.video[0].target_bitrate_bps / 1000 << "kbps";
472 ss << ", " << params_.video[0].fps << " FPS";
473 if (params_.screenshare[0].scroll_duration)
474 ss << ", " << params_.screenshare[0].scroll_duration << "s scroll";
475 if (params_.ss[0].streams.size() > 1)
476 ss << ", Stream #" << params_.ss[0].selected_stream;
477 if (params_.ss[0].num_spatial_layers > 1)
478 ss << ", Layer #" << params_.ss[0].selected_sl;
sprangce4aef12015-11-02 07:23:20 -0800479 ss << ")";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200480 return ss.Release();
sprangce4aef12015-11-02 07:23:20 -0800481}
482
Artem Titove269cb42018-08-29 09:59:23 +0200483void VideoQualityTest::CheckParamsAndInjectionComponents() {
484 if (injection_components_ == nullptr) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200485 injection_components_ = std::make_unique<InjectionComponents>();
Artem Titove269cb42018-08-29 09:59:23 +0200486 }
487 if (!params_.config && injection_components_->sender_network == nullptr &&
488 injection_components_->receiver_network == nullptr) {
Artem Titov62ae1782018-10-24 14:14:49 +0200489 params_.config = BuiltInNetworkBehaviorConfig();
Artem Titovf18b3522018-08-28 16:54:24 +0200490 }
Artem Titove269cb42018-08-29 09:59:23 +0200491 RTC_CHECK(
492 (params_.config && injection_components_->sender_network == nullptr &&
493 injection_components_->receiver_network == nullptr) ||
494 (!params_.config && injection_components_->sender_network != nullptr &&
495 injection_components_->receiver_network != nullptr));
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100496 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
497 // Iterate over primary and secondary video streams.
498 if (!params_.video[video_idx].enabled)
499 return;
500 // Add a default stream in none specified.
501 if (params_.ss[video_idx].streams.empty())
502 params_.ss[video_idx].streams.push_back(
503 VideoQualityTest::DefaultVideoStream(params_, video_idx));
504 if (params_.ss[video_idx].num_spatial_layers == 0)
505 params_.ss[video_idx].num_spatial_layers = 1;
sprangce4aef12015-11-02 07:23:20 -0800506
Artem Titove269cb42018-08-29 09:59:23 +0200507 if (params_.config) {
508 if (params_.config->loss_percent != 0 ||
509 params_.config->queue_length_packets != 0) {
510 // Since LayerFilteringTransport changes the sequence numbers, we can't
511 // use that feature with pack loss, since the NACK request would end up
512 // retransmitting the wrong packets.
513 RTC_CHECK(params_.ss[video_idx].selected_sl == -1 ||
514 params_.ss[video_idx].selected_sl ==
515 params_.ss[video_idx].num_spatial_layers - 1);
516 RTC_CHECK(params_.video[video_idx].selected_tl == -1 ||
517 params_.video[video_idx].selected_tl ==
518 params_.video[video_idx].num_temporal_layers - 1);
519 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100520 }
sprangce4aef12015-11-02 07:23:20 -0800521
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100522 // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as
523 // it does in some parts of the code?
524 RTC_CHECK_GE(params_.video[video_idx].max_bitrate_bps,
525 params_.video[video_idx].target_bitrate_bps);
526 RTC_CHECK_GE(params_.video[video_idx].target_bitrate_bps,
527 params_.video[video_idx].min_bitrate_bps);
Ilya Nikolaevskiyaec663e2019-02-27 12:52:11 +0100528 int selected_stream = params_.ss[video_idx].selected_stream;
Evan Shrubsole420ad1a2020-03-04 10:42:28 +0100529 if (params_.video[video_idx].selected_tl > -1) {
530 RTC_CHECK_LT(selected_stream, params_.ss[video_idx].streams.size())
531 << "Can not use --selected_tl when --selected_stream is all streams";
532 int stream_tl = params_.ss[video_idx]
533 .streams[selected_stream]
534 .num_temporal_layers.value_or(1);
535 RTC_CHECK_LT(params_.video[video_idx].selected_tl, stream_tl);
536 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100537 RTC_CHECK_LE(params_.ss[video_idx].selected_stream,
538 params_.ss[video_idx].streams.size());
539 for (const VideoStream& stream : params_.ss[video_idx].streams) {
540 RTC_CHECK_GE(stream.min_bitrate_bps, 0);
541 RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps);
542 RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps);
543 }
544 // TODO(ivica): Should we check if the sum of all streams/layers is equal to
545 // the total bitrate? We anyway have to update them in the case bitrate
546 // estimator changes the total bitrates.
547 RTC_CHECK_GE(params_.ss[video_idx].num_spatial_layers, 1);
548 RTC_CHECK_LE(params_.ss[video_idx].selected_sl,
549 params_.ss[video_idx].num_spatial_layers);
550 RTC_CHECK(
551 params_.ss[video_idx].spatial_layers.empty() ||
552 params_.ss[video_idx].spatial_layers.size() ==
553 static_cast<size_t>(params_.ss[video_idx].num_spatial_layers));
554 if (params_.video[video_idx].codec == "VP8") {
555 RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1);
556 } else if (params_.video[video_idx].codec == "VP9") {
557 RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 1);
558 }
559 RTC_CHECK_GE(params_.call.num_thumbnails, 0);
560 if (params_.call.num_thumbnails > 0) {
561 RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1);
562 RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 3);
563 RTC_CHECK_EQ(params_.video[video_idx].num_temporal_layers, 3);
564 RTC_CHECK_EQ(params_.video[video_idx].codec, "VP8");
565 }
566 // Dual streams with FEC not supported in tests yet.
567 RTC_CHECK(!params_.video[video_idx].flexfec || num_video_streams_ == 1);
568 RTC_CHECK(!params_.video[video_idx].ulpfec || num_video_streams_ == 1);
ilnika014cc52017-03-07 04:21:04 -0800569 }
sprangce4aef12015-11-02 07:23:20 -0800570}
571
572// Static.
573std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) {
574 // Parse comma separated nonnegative integers, where some elements may be
575 // empty. The empty values are replaced with -1.
576 // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40}
577 // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1}
578 std::vector<int> result;
579 if (str.empty())
580 return result;
581
582 const char* p = str.c_str();
583 int value = -1;
584 int pos;
585 while (*p) {
586 if (*p == ',') {
587 result.push_back(value);
588 value = -1;
589 ++p;
590 continue;
591 }
592 RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1)
593 << "Unexpected non-number value.";
594 p += pos;
595 }
596 result.push_back(value);
597 return result;
598}
599
600// Static.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100601VideoStream VideoQualityTest::DefaultVideoStream(const Params& params,
602 size_t video_idx) {
sprangce4aef12015-11-02 07:23:20 -0800603 VideoStream stream;
Danil Chapovalov350531e2018-06-08 11:04:04 +0000604 stream.width = params.video[video_idx].width;
605 stream.height = params.video[video_idx].height;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100606 stream.max_framerate = params.video[video_idx].fps;
607 stream.min_bitrate_bps = params.video[video_idx].min_bitrate_bps;
608 stream.target_bitrate_bps = params.video[video_idx].target_bitrate_bps;
609 stream.max_bitrate_bps = params.video[video_idx].max_bitrate_bps;
sprang1168fd42017-06-21 09:00:17 -0700610 stream.max_qp = kDefaultMaxQp;
Sergey Silkina796a7e2018-03-01 15:11:29 +0100611 stream.num_temporal_layers = params.video[video_idx].num_temporal_layers;
Seth Hampson46e31ba2018-01-18 10:39:54 -0800612 stream.active = true;
ilnika014cc52017-03-07 04:21:04 -0800613 return stream;
614}
615
616// Static.
617VideoStream VideoQualityTest::DefaultThumbnailStream() {
618 VideoStream stream;
619 stream.width = 320;
620 stream.height = 180;
621 stream.max_framerate = 7;
622 stream.min_bitrate_bps = 7500;
623 stream.target_bitrate_bps = 37500;
624 stream.max_bitrate_bps = 50000;
sprang1168fd42017-06-21 09:00:17 -0700625 stream.max_qp = kDefaultMaxQp;
sprangce4aef12015-11-02 07:23:20 -0800626 return stream;
627}
628
629// Static.
630void VideoQualityTest::FillScalabilitySettings(
631 Params* params,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100632 size_t video_idx,
sprangce4aef12015-11-02 07:23:20 -0800633 const std::vector<std::string>& stream_descriptors,
sprang1168fd42017-06-21 09:00:17 -0700634 int num_streams,
sprangce4aef12015-11-02 07:23:20 -0800635 size_t selected_stream,
636 int num_spatial_layers,
637 int selected_sl,
Sergey Silkin57027362018-05-15 09:12:05 +0200638 InterLayerPredMode inter_layer_pred,
sprangce4aef12015-11-02 07:23:20 -0800639 const std::vector<std::string>& sl_descriptors) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100640 if (params->ss[video_idx].streams.empty() &&
641 params->ss[video_idx].infer_streams) {
sprang1168fd42017-06-21 09:00:17 -0700642 webrtc::VideoEncoderConfig encoder_config;
Niels Möller259a4972018-04-05 15:36:51 +0200643 encoder_config.codec_type =
644 PayloadStringToCodecType(params->video[video_idx].codec);
sprang1168fd42017-06-21 09:00:17 -0700645 encoder_config.content_type =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100646 params->screenshare[video_idx].enabled
sprang1168fd42017-06-21 09:00:17 -0700647 ? webrtc::VideoEncoderConfig::ContentType::kScreen
648 : webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100649 encoder_config.max_bitrate_bps = params->video[video_idx].max_bitrate_bps;
650 encoder_config.min_transmit_bitrate_bps =
651 params->video[video_idx].min_transmit_bps;
sprang1168fd42017-06-21 09:00:17 -0700652 encoder_config.number_of_streams = num_streams;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100653 encoder_config.spatial_layers = params->ss[video_idx].spatial_layers;
Seth Hampson8234ead2018-02-02 15:16:24 -0800654 encoder_config.simulcast_layers = std::vector<VideoStream>(num_streams);
sprang1168fd42017-06-21 09:00:17 -0700655 encoder_config.video_stream_factory =
656 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100657 params->video[video_idx].codec, kDefaultMaxQp,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100658 params->screenshare[video_idx].enabled, true);
659 params->ss[video_idx].streams =
sprang1168fd42017-06-21 09:00:17 -0700660 encoder_config.video_stream_factory->CreateEncoderStreams(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100661 static_cast<int>(params->video[video_idx].width),
662 static_cast<int>(params->video[video_idx].height), encoder_config);
sprang1168fd42017-06-21 09:00:17 -0700663 } else {
664 // Read VideoStream and SpatialLayer elements from a list of comma separated
665 // lists. To use a default value for an element, use -1 or leave empty.
Artem Titove269cb42018-08-29 09:59:23 +0200666 // Validity checks performed in CheckParamsAndInjectionComponents.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100667 RTC_CHECK(params->ss[video_idx].streams.empty());
Mirko Bonadei739baf02019-01-27 17:29:42 +0100668 for (const auto& descriptor : stream_descriptors) {
sprang1168fd42017-06-21 09:00:17 -0700669 if (descriptor.empty())
670 continue;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100671 VideoStream stream =
672 VideoQualityTest::DefaultVideoStream(*params, video_idx);
sprang1168fd42017-06-21 09:00:17 -0700673 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
674 if (v[0] != -1)
675 stream.width = static_cast<size_t>(v[0]);
676 if (v[1] != -1)
677 stream.height = static_cast<size_t>(v[1]);
678 if (v[2] != -1)
679 stream.max_framerate = v[2];
680 if (v[3] != -1)
681 stream.min_bitrate_bps = v[3];
682 if (v[4] != -1)
683 stream.target_bitrate_bps = v[4];
684 if (v[5] != -1)
685 stream.max_bitrate_bps = v[5];
686 if (v.size() > 6 && v[6] != -1)
687 stream.max_qp = v[6];
Sergey Silkina796a7e2018-03-01 15:11:29 +0100688 if (v.size() > 7 && v[7] != -1) {
689 stream.num_temporal_layers = v[7];
sprang1168fd42017-06-21 09:00:17 -0700690 } else {
691 // Automatic TL thresholds for more than two layers not supported.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100692 RTC_CHECK_LE(params->video[video_idx].num_temporal_layers, 2);
sprang1168fd42017-06-21 09:00:17 -0700693 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100694 params->ss[video_idx].streams.push_back(stream);
sprangce4aef12015-11-02 07:23:20 -0800695 }
sprangce4aef12015-11-02 07:23:20 -0800696 }
sprangce4aef12015-11-02 07:23:20 -0800697
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100698 params->ss[video_idx].num_spatial_layers = std::max(1, num_spatial_layers);
699 params->ss[video_idx].selected_stream = selected_stream;
sprang1168fd42017-06-21 09:00:17 -0700700
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100701 params->ss[video_idx].selected_sl = selected_sl;
Sergey Silkin57027362018-05-15 09:12:05 +0200702 params->ss[video_idx].inter_layer_pred = inter_layer_pred;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100703 RTC_CHECK(params->ss[video_idx].spatial_layers.empty());
Mirko Bonadei739baf02019-01-27 17:29:42 +0100704 for (const auto& descriptor : sl_descriptors) {
sprangce4aef12015-11-02 07:23:20 -0800705 if (descriptor.empty())
706 continue;
707 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
Sergey Silkina89800c2019-02-19 12:52:56 +0100708 RTC_CHECK_EQ(v.size(), 8);
sprangce4aef12015-11-02 07:23:20 -0800709
Sergey Silkin13e74342018-03-02 12:28:00 +0100710 SpatialLayer layer = {0};
711 layer.width = v[0];
712 layer.height = v[1];
Sergey Silkina89800c2019-02-19 12:52:56 +0100713 layer.maxFramerate = v[2];
714 layer.numberOfTemporalLayers = v[3];
715 layer.maxBitrate = v[4];
716 layer.minBitrate = v[5];
717 layer.targetBitrate = v[6];
718 layer.qpMax = v[7];
Sergey Silkin13e74342018-03-02 12:28:00 +0100719 layer.active = true;
720
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100721 params->ss[video_idx].spatial_layers.push_back(layer);
sprangce4aef12015-11-02 07:23:20 -0800722 }
723}
724
minyuea27172d2016-11-01 05:59:29 -0700725void VideoQualityTest::SetupVideo(Transport* send_transport,
726 Transport* recv_transport) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100727 size_t total_streams_used = 0;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100728 video_receive_configs_.clear();
729 video_send_configs_.clear();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100730 video_encoder_configs_.clear();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100731 bool decode_all_receive_streams = true;
732 size_t num_video_substreams = params_.ss[0].streams.size();
733 RTC_CHECK(num_video_streams_ > 0);
734 video_encoder_configs_.resize(num_video_streams_);
Rasmus Brandt5894b6a2019-06-13 16:28:14 +0200735 std::string generic_codec_name;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100736 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
737 video_send_configs_.push_back(VideoSendStream::Config(send_transport));
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100738 video_encoder_configs_.push_back(VideoEncoderConfig());
739 num_video_substreams = params_.ss[video_idx].streams.size();
740 RTC_CHECK_GT(num_video_substreams, 0);
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200741 for (size_t i = 0; i < num_video_substreams; ++i)
742 video_send_configs_[video_idx].rtp.ssrcs.push_back(
743 kVideoSendSsrcs[total_streams_used + i]);
Qingsi Wang2d82ade2018-07-11 06:04:44 +0000744
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100745 int payload_type;
746 if (params_.video[video_idx].codec == "H264") {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100747 payload_type = kPayloadTypeH264;
748 } else if (params_.video[video_idx].codec == "VP8") {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100749 payload_type = kPayloadTypeVP8;
750 } else if (params_.video[video_idx].codec == "VP9") {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100751 payload_type = kPayloadTypeVP9;
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800752 } else if (params_.video[video_idx].codec == "multiplex") {
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800753 payload_type = kPayloadTypeVP9;
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -0500754 } else if (params_.video[video_idx].codec == "FakeCodec") {
755 payload_type = kFakeVideoSendPayloadType;
ilnikcb8c1462017-03-09 09:23:30 -0800756 } else {
Rasmus Brandt5894b6a2019-06-13 16:28:14 +0200757 RTC_CHECK(generic_codec_name.empty() ||
758 generic_codec_name == params_.video[video_idx].codec)
759 << "Supplying multiple generic codecs is unsupported.";
760 RTC_LOG(LS_INFO) << "Treating codec " << params_.video[video_idx].codec
761 << " as generic.";
762 payload_type = kPayloadTypeGeneric;
763 generic_codec_name = params_.video[video_idx].codec;
ilnikcb8c1462017-03-09 09:23:30 -0800764 }
Niels Möller4db138e2018-04-19 09:04:13 +0200765 video_send_configs_[video_idx].encoder_settings.encoder_factory =
Niels Möller88be9722018-10-10 10:58:52 +0200766 (video_idx == 0) ? &video_encoder_factory_with_analyzer_
767 : &video_encoder_factory_;
Jiawei Ouc2ebe212018-11-08 10:02:56 -0800768 video_send_configs_[video_idx].encoder_settings.bitrate_allocator_factory =
769 video_bitrate_allocator_factory_.get();
Niels Möller4db138e2018-04-19 09:04:13 +0200770
Niels Möller259a4972018-04-05 15:36:51 +0200771 video_send_configs_[video_idx].rtp.payload_name =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100772 params_.video[video_idx].codec;
Niels Möller259a4972018-04-05 15:36:51 +0200773 video_send_configs_[video_idx].rtp.payload_type = payload_type;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100774 video_send_configs_[video_idx].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
775 video_send_configs_[video_idx].rtp.rtx.payload_type = kSendRtxPayloadType;
776 for (size_t i = 0; i < num_video_substreams; ++i) {
777 video_send_configs_[video_idx].rtp.rtx.ssrcs.push_back(
778 kSendRtxSsrcs[i + total_streams_used]);
ilnik9fd9f6c2017-03-02 08:10:10 -0800779 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100780 video_send_configs_[video_idx].rtp.extensions.clear();
781 if (params_.call.send_side_bwe) {
philipel569397f2018-09-26 12:25:31 +0200782 video_send_configs_[video_idx].rtp.extensions.emplace_back(
783 RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +0100784 kTransportSequenceNumberExtensionId);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100785 } else {
philipel569397f2018-09-26 12:25:31 +0200786 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alond8d32482019-02-18 23:45:57 +0100787 RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100788 }
philipel569397f2018-09-26 12:25:31 +0200789
790 if (params_.call.generic_descriptor) {
791 // The generic descriptor is currently behind a field trial, so it needs
792 // to be set for this flag to have any effect.
793 // TODO(philipel): Remove this check when the experiment is removed.
794 RTC_CHECK(field_trial::IsEnabled("WebRTC-GenericDescriptor"));
795
796 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alonccb9b752019-02-19 13:01:31 +0100797 RtpExtension::kGenericFrameDescriptorUri00,
798 kGenericFrameDescriptorExtensionId00);
799 video_send_configs_[video_idx].rtp.extensions.emplace_back(
800 RtpExtension::kGenericFrameDescriptorUri01,
801 kGenericFrameDescriptorExtensionId01);
philipel569397f2018-09-26 12:25:31 +0200802 }
803
804 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alond8d32482019-02-18 23:45:57 +0100805 RtpExtension::kVideoContentTypeUri, kVideoContentTypeExtensionId);
philipel569397f2018-09-26 12:25:31 +0200806 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alond8d32482019-02-18 23:45:57 +0100807 RtpExtension::kVideoTimingUri, kVideoTimingExtensionId);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100808
Niels Möller4db138e2018-04-19 09:04:13 +0200809 video_encoder_configs_[video_idx].video_format.name =
810 params_.video[video_idx].codec;
811
Emircan Uysaler0823eec2018-07-13 17:10:00 -0700812 video_encoder_configs_[video_idx].video_format.parameters =
813 params_.video[video_idx].sdp_params;
814
Niels Möller259a4972018-04-05 15:36:51 +0200815 video_encoder_configs_[video_idx].codec_type =
816 PayloadStringToCodecType(params_.video[video_idx].codec);
817
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100818 video_encoder_configs_[video_idx].min_transmit_bitrate_bps =
819 params_.video[video_idx].min_transmit_bps;
820
821 video_send_configs_[video_idx].suspend_below_min_bitrate =
822 params_.video[video_idx].suspend_below_min_bitrate;
823
824 video_encoder_configs_[video_idx].number_of_streams =
825 params_.ss[video_idx].streams.size();
826 video_encoder_configs_[video_idx].max_bitrate_bps = 0;
827 for (size_t i = 0; i < params_.ss[video_idx].streams.size(); ++i) {
828 video_encoder_configs_[video_idx].max_bitrate_bps +=
829 params_.ss[video_idx].streams[i].max_bitrate_bps;
830 }
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100831 video_encoder_configs_[video_idx].simulcast_layers =
832 std::vector<VideoStream>(params_.ss[video_idx].streams.size());
833 if (!params_.ss[video_idx].infer_streams) {
Seth Hampson8234ead2018-02-02 15:16:24 -0800834 video_encoder_configs_[video_idx].simulcast_layers =
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100835 params_.ss[video_idx].streams;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100836 }
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100837 video_encoder_configs_[video_idx].video_stream_factory =
838 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
839 params_.video[video_idx].codec,
840 params_.ss[video_idx].streams[0].max_qp,
841 params_.screenshare[video_idx].enabled, true);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100842
843 video_encoder_configs_[video_idx].spatial_layers =
844 params_.ss[video_idx].spatial_layers;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100845 decode_all_receive_streams = params_.ss[video_idx].selected_stream ==
846 params_.ss[video_idx].streams.size();
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200847 absl::optional<int> decode_sub_stream;
848 if (!decode_all_receive_streams)
849 decode_sub_stream = params_.ss[video_idx].selected_stream;
850 CreateMatchingVideoReceiveConfigs(
851 video_send_configs_[video_idx], recv_transport,
Niels Möllercbcbc222018-09-28 09:07:24 +0200852 params_.call.send_side_bwe, &video_decoder_factory_, decode_sub_stream,
853 true, kNackRtpHistoryMs);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100854
855 if (params_.screenshare[video_idx].enabled) {
856 // Fill out codec settings.
857 video_encoder_configs_[video_idx].content_type =
858 VideoEncoderConfig::ContentType::kScreen;
Taylor Brandstetter49fcc102018-05-16 14:20:41 -0700859 degradation_preference_ = DegradationPreference::MAINTAIN_RESOLUTION;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100860 if (params_.video[video_idx].codec == "VP8") {
861 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
862 vp8_settings.denoisingOn = false;
863 vp8_settings.frameDroppingOn = false;
864 vp8_settings.numberOfTemporalLayers = static_cast<unsigned char>(
865 params_.video[video_idx].num_temporal_layers);
866 video_encoder_configs_[video_idx].encoder_specific_settings =
867 new rtc::RefCountedObject<
868 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
869 } else if (params_.video[video_idx].codec == "VP9") {
870 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
871 vp9_settings.denoisingOn = false;
872 vp9_settings.frameDroppingOn = false;
Ilya Nikolaevskiyeac08bf2020-03-10 09:50:26 +0000873 vp9_settings.automaticResizeOn = false;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100874 vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>(
875 params_.video[video_idx].num_temporal_layers);
876 vp9_settings.numberOfSpatialLayers = static_cast<unsigned char>(
877 params_.ss[video_idx].num_spatial_layers);
Sergey Silkin57027362018-05-15 09:12:05 +0200878 vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred;
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +0100879 // High FPS vp9 screenshare requires flexible mode.
Ilya Nikolaevskiy5c18a5f2019-05-24 11:51:31 +0200880 if (params_.ss[video_idx].num_spatial_layers > 1) {
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +0100881 vp9_settings.flexibleMode = true;
882 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100883 video_encoder_configs_[video_idx].encoder_specific_settings =
884 new rtc::RefCountedObject<
885 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
886 }
887 } else if (params_.ss[video_idx].num_spatial_layers > 1) {
888 // If SVC mode without screenshare, still need to set codec specifics.
889 RTC_CHECK(params_.video[video_idx].codec == "VP9");
890 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
891 vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>(
892 params_.video[video_idx].num_temporal_layers);
893 vp9_settings.numberOfSpatialLayers =
894 static_cast<unsigned char>(params_.ss[video_idx].num_spatial_layers);
Sergey Silkin57027362018-05-15 09:12:05 +0200895 vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred;
Ilya Nikolaevskiyeac08bf2020-03-10 09:50:26 +0000896 vp9_settings.automaticResizeOn = false;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100897 video_encoder_configs_[video_idx].encoder_specific_settings =
898 new rtc::RefCountedObject<
899 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
Niels Möller6aa415e2018-06-07 11:14:13 +0200900 } else if (params_.video[video_idx].automatic_scaling) {
901 if (params_.video[video_idx].codec == "VP8") {
902 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
903 vp8_settings.automaticResizeOn = true;
904 video_encoder_configs_[video_idx].encoder_specific_settings =
905 new rtc::RefCountedObject<
906 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
907 } else if (params_.video[video_idx].codec == "VP9") {
908 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
Ilya Nikolaevskiyeac08bf2020-03-10 09:50:26 +0000909 // Only enable quality scaler for single spatial layer.
910 vp9_settings.automaticResizeOn =
911 params_.ss[video_idx].num_spatial_layers == 1;
Niels Möller6aa415e2018-06-07 11:14:13 +0200912 video_encoder_configs_[video_idx].encoder_specific_settings =
913 new rtc::RefCountedObject<
914 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
Stefan Holmer1f7a0082019-01-11 15:39:08 +0100915 } else if (params_.video[video_idx].codec == "H264") {
916 // Quality scaling is always on for H.264.
Niels Möller6aa415e2018-06-07 11:14:13 +0200917 } else {
918 RTC_NOTREACHED() << "Automatic scaling not supported for codec "
Yves Gerey665174f2018-06-19 15:03:05 +0200919 << params_.video[video_idx].codec << ", stream "
920 << video_idx;
Niels Möller6aa415e2018-06-07 11:14:13 +0200921 }
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100922 } else {
923 // Default mode. Single SL, no automatic_scaling,
924 if (params_.video[video_idx].codec == "VP8") {
925 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
926 vp8_settings.automaticResizeOn = false;
927 video_encoder_configs_[video_idx].encoder_specific_settings =
928 new rtc::RefCountedObject<
929 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
930 } else if (params_.video[video_idx].codec == "VP9") {
931 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
932 vp9_settings.automaticResizeOn = false;
933 video_encoder_configs_[video_idx].encoder_specific_settings =
934 new rtc::RefCountedObject<
935 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
936 } else if (params_.video[video_idx].codec == "H264") {
937 VideoCodecH264 h264_settings = VideoEncoder::GetDefaultH264Settings();
938 video_encoder_configs_[video_idx].encoder_specific_settings =
939 new rtc::RefCountedObject<
940 VideoEncoderConfig::H264EncoderSpecificSettings>(h264_settings);
941 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100942 }
943 total_streams_used += num_video_substreams;
sprangce4aef12015-11-02 07:23:20 -0800944 }
brandtr1293aca2016-11-16 22:47:29 -0800945
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100946 // FEC supported only for single video stream mode yet.
947 if (params_.video[0].flexfec) {
sprang1168fd42017-06-21 09:00:17 -0700948 if (decode_all_receive_streams) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200949 SetSendFecConfig(GetVideoSendConfig()->rtp.ssrcs);
sprang1168fd42017-06-21 09:00:17 -0700950 } else {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200951 SetSendFecConfig({kVideoSendSsrcs[params_.ss[0].selected_stream]});
sprang1168fd42017-06-21 09:00:17 -0700952 }
brandtr1293aca2016-11-16 22:47:29 -0800953
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200954 CreateMatchingFecConfig(recv_transport, *GetVideoSendConfig());
955 GetFlexFecConfig()->transport_cc = params_.call.send_side_bwe;
brandtrb29e6522016-12-21 06:37:18 -0800956 if (params_.call.send_side_bwe) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200957 GetFlexFecConfig()->rtp_header_extensions.push_back(
brandtrb29e6522016-12-21 06:37:18 -0800958 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +0100959 kTransportSequenceNumberExtensionId));
brandtrb29e6522016-12-21 06:37:18 -0800960 } else {
Elad Alond8d32482019-02-18 23:45:57 +0100961 GetFlexFecConfig()->rtp_header_extensions.push_back(
962 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId));
brandtrb29e6522016-12-21 06:37:18 -0800963 }
brandtr1293aca2016-11-16 22:47:29 -0800964 }
965
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100966 if (params_.video[0].ulpfec) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200967 SetSendUlpFecConfig(GetVideoSendConfig());
sprang1168fd42017-06-21 09:00:17 -0700968 if (decode_all_receive_streams) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200969 for (auto& receive_config : video_receive_configs_) {
970 SetReceiveUlpFecConfig(&receive_config);
sprang1168fd42017-06-21 09:00:17 -0700971 }
972 } else {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200973 SetReceiveUlpFecConfig(
974 &video_receive_configs_[params_.ss[0].selected_stream]);
sprang1168fd42017-06-21 09:00:17 -0700975 }
brandtr1293aca2016-11-16 22:47:29 -0800976 }
ivica5d6a06c2015-09-17 05:30:24 -0700977}
978
ilnika014cc52017-03-07 04:21:04 -0800979void VideoQualityTest::SetupThumbnails(Transport* send_transport,
980 Transport* recv_transport) {
ilnik98436952017-07-13 00:47:03 -0700981 for (int i = 0; i < params_.call.num_thumbnails; ++i) {
ilnika014cc52017-03-07 04:21:04 -0800982 // Thumbnails will be send in the other way: from receiver_call to
983 // sender_call.
984 VideoSendStream::Config thumbnail_send_config(recv_transport);
985 thumbnail_send_config.rtp.ssrcs.push_back(kThumbnailSendSsrcStart + i);
Niels Möller4db138e2018-04-19 09:04:13 +0200986 // TODO(nisse): Could use a simpler VP8-only encoder factory.
987 thumbnail_send_config.encoder_settings.encoder_factory =
988 &video_encoder_factory_;
Jiawei Ouc2ebe212018-11-08 10:02:56 -0800989 thumbnail_send_config.encoder_settings.bitrate_allocator_factory =
990 video_bitrate_allocator_factory_.get();
Niels Möller259a4972018-04-05 15:36:51 +0200991 thumbnail_send_config.rtp.payload_name = params_.video[0].codec;
992 thumbnail_send_config.rtp.payload_type = kPayloadTypeVP8;
ilnika014cc52017-03-07 04:21:04 -0800993 thumbnail_send_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
994 thumbnail_send_config.rtp.rtx.payload_type = kSendRtxPayloadType;
995 thumbnail_send_config.rtp.rtx.ssrcs.push_back(kThumbnailRtxSsrcStart + i);
996 thumbnail_send_config.rtp.extensions.clear();
997 if (params_.call.send_side_bwe) {
998 thumbnail_send_config.rtp.extensions.push_back(
999 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +01001000 kTransportSequenceNumberExtensionId));
ilnika014cc52017-03-07 04:21:04 -08001001 } else {
Elad Alond8d32482019-02-18 23:45:57 +01001002 thumbnail_send_config.rtp.extensions.push_back(
1003 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId));
ilnika014cc52017-03-07 04:21:04 -08001004 }
1005
1006 VideoEncoderConfig thumbnail_encoder_config;
Niels Möller259a4972018-04-05 15:36:51 +02001007 thumbnail_encoder_config.codec_type = kVideoCodecVP8;
Niels Möller4db138e2018-04-19 09:04:13 +02001008 thumbnail_encoder_config.video_format.name = "VP8";
ilnika014cc52017-03-07 04:21:04 -08001009 thumbnail_encoder_config.min_transmit_bitrate_bps = 7500;
1010 thumbnail_send_config.suspend_below_min_bitrate =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001011 params_.video[0].suspend_below_min_bitrate;
ilnika014cc52017-03-07 04:21:04 -08001012 thumbnail_encoder_config.number_of_streams = 1;
1013 thumbnail_encoder_config.max_bitrate_bps = 50000;
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +01001014 std::vector<VideoStream> streams{params_.ss[0].streams[0]};
1015 thumbnail_encoder_config.video_stream_factory =
1016 new rtc::RefCountedObject<VideoStreamFactory>(streams);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001017 thumbnail_encoder_config.spatial_layers = params_.ss[0].spatial_layers;
ilnika014cc52017-03-07 04:21:04 -08001018
ilnika014cc52017-03-07 04:21:04 -08001019 thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy());
1020 thumbnail_send_configs_.push_back(thumbnail_send_config.Copy());
ilnika014cc52017-03-07 04:21:04 -08001021
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001022 AddMatchingVideoReceiveConfigs(
1023 &thumbnail_receive_configs_, thumbnail_send_config, send_transport,
Niels Möllercbcbc222018-09-28 09:07:24 +02001024 params_.call.send_side_bwe, &video_decoder_factory_, absl::nullopt,
1025 false, kNackRtpHistoryMs);
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001026 }
1027 for (size_t i = 0; i < thumbnail_send_configs_.size(); ++i) {
ilnika014cc52017-03-07 04:21:04 -08001028 thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream(
1029 thumbnail_send_configs_[i].Copy(),
1030 thumbnail_encoder_configs_[i].Copy()));
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001031 }
1032 for (size_t i = 0; i < thumbnail_receive_configs_.size(); ++i) {
ilnika014cc52017-03-07 04:21:04 -08001033 thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream(
1034 thumbnail_receive_configs_[i].Copy()));
1035 }
1036}
1037
1038void VideoQualityTest::DestroyThumbnailStreams() {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001039 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) {
ilnika014cc52017-03-07 04:21:04 -08001040 receiver_call_->DestroyVideoSendStream(thumbnail_send_stream);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001041 }
ilnika014cc52017-03-07 04:21:04 -08001042 thumbnail_send_streams_.clear();
1043 for (VideoReceiveStream* thumbnail_receive_stream :
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001044 thumbnail_receive_streams_) {
ilnika014cc52017-03-07 04:21:04 -08001045 sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001046 }
ilnika014cc52017-03-07 04:21:04 -08001047 thumbnail_send_streams_.clear();
1048 thumbnail_receive_streams_.clear();
Niels Möller1c931c42018-12-18 16:08:11 +01001049 for (std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>& video_capturer :
eladalon413ee9a2017-08-22 04:02:52 -07001050 thumbnail_capturers_) {
Niels Möller1c931c42018-12-18 16:08:11 +01001051 video_capturer.reset();
eladalon413ee9a2017-08-22 04:02:52 -07001052 }
ilnika014cc52017-03-07 04:21:04 -08001053}
1054
ilnika014cc52017-03-07 04:21:04 -08001055void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) {
1056 VideoStream thumbnail = DefaultThumbnailStream();
1057 for (size_t i = 0; i < num_thumbnail_streams; ++i) {
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001058 auto frame_generator_capturer =
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001059 std::make_unique<test::FrameGeneratorCapturer>(
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001060 clock_,
Artem Titov33f9d2b2019-12-05 15:59:00 +01001061 test::CreateSquareFrameGenerator(static_cast<int>(thumbnail.width),
1062 static_cast<int>(thumbnail.height),
1063 absl::nullopt, absl::nullopt),
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001064 thumbnail.max_framerate, *task_queue_factory_);
1065 EXPECT_TRUE(frame_generator_capturer->Init());
1066 thumbnail_capturers_.push_back(std::move(frame_generator_capturer));
ilnika014cc52017-03-07 04:21:04 -08001067 }
1068}
1069
Artem Titov33f9d2b2019-12-05 15:59:00 +01001070std::unique_ptr<test::FrameGeneratorInterface>
1071VideoQualityTest::CreateFrameGenerator(size_t video_idx) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001072 // Setup frame generator.
1073 const size_t kWidth = 1850;
1074 const size_t kHeight = 1110;
Artem Titov33f9d2b2019-12-05 15:59:00 +01001075 std::unique_ptr<test::FrameGeneratorInterface> frame_generator;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001076 if (params_.screenshare[video_idx].generate_slides) {
Artem Titov33f9d2b2019-12-05 15:59:00 +01001077 frame_generator = test::CreateSlideFrameGenerator(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001078 kWidth, kHeight,
1079 params_.screenshare[video_idx].slide_change_interval *
1080 params_.video[video_idx].fps);
ivica5d6a06c2015-09-17 05:30:24 -07001081 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001082 std::vector<std::string> slides = params_.screenshare[video_idx].slides;
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001083 if (slides.empty()) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001084 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
1085 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
1086 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
1087 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
1088 }
1089 if (params_.screenshare[video_idx].scroll_duration == 0) {
1090 // Cycle image every slide_change_interval seconds.
Artem Titov33f9d2b2019-12-05 15:59:00 +01001091 frame_generator = test::CreateFromYuvFileFrameGenerator(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001092 slides, kWidth, kHeight,
1093 params_.screenshare[video_idx].slide_change_interval *
1094 params_.video[video_idx].fps);
ivica5d6a06c2015-09-17 05:30:24 -07001095 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001096 RTC_CHECK_LE(params_.video[video_idx].width, kWidth);
1097 RTC_CHECK_LE(params_.video[video_idx].height, kHeight);
1098 RTC_CHECK_GT(params_.screenshare[video_idx].slide_change_interval, 0);
1099 const int kPauseDurationMs =
1100 (params_.screenshare[video_idx].slide_change_interval -
1101 params_.screenshare[video_idx].scroll_duration) *
1102 1000;
1103 RTC_CHECK_LE(params_.screenshare[video_idx].scroll_duration,
1104 params_.screenshare[video_idx].slide_change_interval);
1105
Artem Titov33f9d2b2019-12-05 15:59:00 +01001106 frame_generator = test::CreateScrollingInputFromYuvFilesFrameGenerator(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001107 clock_, slides, kWidth, kHeight, params_.video[video_idx].width,
1108 params_.video[video_idx].height,
1109 params_.screenshare[video_idx].scroll_duration * 1000,
1110 kPauseDurationMs);
ivica5d6a06c2015-09-17 05:30:24 -07001111 }
1112 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001113 return frame_generator;
1114}
1115
1116void VideoQualityTest::CreateCapturers() {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001117 RTC_DCHECK(video_sources_.empty());
Niels Möller1c931c42018-12-18 16:08:11 +01001118 video_sources_.resize(num_video_streams_);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001119 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
Artem Titov33f9d2b2019-12-05 15:59:00 +01001120 std::unique_ptr<test::FrameGeneratorInterface> frame_generator;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001121 if (params_.screenshare[video_idx].enabled) {
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001122 frame_generator = CreateFrameGenerator(video_idx);
1123 } else if (params_.video[video_idx].clip_path == "Generator") {
Artem Titov33f9d2b2019-12-05 15:59:00 +01001124 frame_generator = test::CreateSquareFrameGenerator(
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001125 static_cast<int>(params_.video[video_idx].width),
1126 static_cast<int>(params_.video[video_idx].height), absl::nullopt,
1127 absl::nullopt);
1128 } else if (params_.video[video_idx].clip_path == "GeneratorI420A") {
Artem Titov33f9d2b2019-12-05 15:59:00 +01001129 frame_generator = test::CreateSquareFrameGenerator(
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001130 static_cast<int>(params_.video[video_idx].width),
1131 static_cast<int>(params_.video[video_idx].height),
Artem Titov33f9d2b2019-12-05 15:59:00 +01001132 test::FrameGeneratorInterface::OutputType::kI420A, absl::nullopt);
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001133 } else if (params_.video[video_idx].clip_path == "GeneratorI010") {
Artem Titov33f9d2b2019-12-05 15:59:00 +01001134 frame_generator = test::CreateSquareFrameGenerator(
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001135 static_cast<int>(params_.video[video_idx].width),
1136 static_cast<int>(params_.video[video_idx].height),
Artem Titov33f9d2b2019-12-05 15:59:00 +01001137 test::FrameGeneratorInterface::OutputType::kI010, absl::nullopt);
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001138 } else if (params_.video[video_idx].clip_path.empty()) {
1139 video_sources_[video_idx] = test::CreateVideoCapturer(
1140 params_.video[video_idx].width, params_.video[video_idx].height,
1141 params_.video[video_idx].fps,
1142 params_.video[video_idx].capture_device_index);
1143 if (video_sources_[video_idx]) {
1144 continue;
1145 } else {
1146 // Failed to get actual camera, use chroma generator as backup.
Artem Titov33f9d2b2019-12-05 15:59:00 +01001147 frame_generator = test::CreateSquareFrameGenerator(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001148 static_cast<int>(params_.video[video_idx].width),
Danil Chapovalovb9b146c2018-06-15 12:28:07 +02001149 static_cast<int>(params_.video[video_idx].height), absl::nullopt,
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001150 absl::nullopt);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001151 }
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001152 } else {
Artem Titov33f9d2b2019-12-05 15:59:00 +01001153 frame_generator = test::CreateFromYuvFileFrameGenerator(
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001154 {params_.video[video_idx].clip_path}, params_.video[video_idx].width,
1155 params_.video[video_idx].height, 1);
1156 ASSERT_TRUE(frame_generator) << "Could not create capturer for "
1157 << params_.video[video_idx].clip_path
1158 << ".yuv. Is this file present?";
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001159 }
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001160 ASSERT_TRUE(frame_generator);
1161 auto frame_generator_capturer =
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001162 std::make_unique<test::FrameGeneratorCapturer>(
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001163 clock_, std::move(frame_generator), params_.video[video_idx].fps,
1164 *task_queue_factory_);
1165 EXPECT_TRUE(frame_generator_capturer->Init());
1166 video_sources_[video_idx] = std::move(frame_generator_capturer);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001167 }
ivica5d6a06c2015-09-17 05:30:24 -07001168}
1169
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001170void VideoQualityTest::StartAudioStreams() {
1171 audio_send_stream_->Start();
1172 for (AudioReceiveStream* audio_recv_stream : audio_receive_streams_)
1173 audio_recv_stream->Start();
1174}
1175
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001176void VideoQualityTest::StartThumbnails() {
1177 for (VideoSendStream* send_stream : thumbnail_send_streams_)
1178 send_stream->Start();
1179 for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_)
1180 receive_stream->Start();
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001181}
1182
1183void VideoQualityTest::StopThumbnails() {
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001184 for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_)
1185 receive_stream->Stop();
1186 for (VideoSendStream* send_stream : thumbnail_send_streams_)
1187 send_stream->Stop();
1188}
1189
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001190std::unique_ptr<test::LayerFilteringTransport>
1191VideoQualityTest::CreateSendTransport() {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001192 std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr;
Artem Titove269cb42018-08-29 09:59:23 +02001193 if (injection_components_->sender_network == nullptr) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001194 network_behavior = std::make_unique<SimulatedNetwork>(*params_.config);
Artem Titove269cb42018-08-29 09:59:23 +02001195 } else {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001196 network_behavior = std::move(injection_components_->sender_network);
Artem Titove269cb42018-08-29 09:59:23 +02001197 }
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001198 return std::make_unique<test::LayerFilteringTransport>(
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001199 task_queue(),
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001200 std::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)),
Artem Titov4e199e92018-08-20 13:30:39 +02001201 sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9,
1202 params_.video[0].selected_tl, params_.ss[0].selected_sl,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001203 payload_type_map_, kVideoSendSsrcs[0],
1204 static_cast<uint32_t>(kVideoSendSsrcs[0] + params_.ss[0].streams.size() -
1205 1));
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001206}
1207
1208std::unique_ptr<test::DirectTransport>
1209VideoQualityTest::CreateReceiveTransport() {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001210 std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr;
Artem Titove269cb42018-08-29 09:59:23 +02001211 if (injection_components_->receiver_network == nullptr) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001212 network_behavior = std::make_unique<SimulatedNetwork>(*params_.config);
Artem Titove269cb42018-08-29 09:59:23 +02001213 } else {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001214 network_behavior = std::move(injection_components_->receiver_network);
Artem Titove269cb42018-08-29 09:59:23 +02001215 }
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001216 return std::make_unique<test::DirectTransport>(
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001217 task_queue(),
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001218 std::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)),
Artem Titovdd2eebe2018-08-20 13:27:45 +02001219 receiver_call_.get(), payload_type_map_);
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001220}
1221
sprang7a975f72015-10-12 06:33:21 -07001222void VideoQualityTest::RunWithAnalyzer(const Params& params) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001223 num_video_streams_ = params.call.dual_video ? 2 : 1;
eladalon413ee9a2017-08-22 04:02:52 -07001224 std::unique_ptr<test::LayerFilteringTransport> send_transport;
1225 std::unique_ptr<test::DirectTransport> recv_transport;
1226 FILE* graph_data_output_file = nullptr;
eladalon413ee9a2017-08-22 04:02:52 -07001227
sprangce4aef12015-11-02 07:23:20 -08001228 params_ = params;
ivica5d6a06c2015-09-17 05:30:24 -07001229 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1230 // differentiate between the analyzer and the renderer case.
Artem Titove269cb42018-08-29 09:59:23 +02001231 CheckParamsAndInjectionComponents();
ivica5d6a06c2015-09-17 05:30:24 -07001232
sprangce4aef12015-11-02 07:23:20 -08001233 if (!params_.analyzer.graph_data_output_filename.empty()) {
ivica5d6a06c2015-09-17 05:30:24 -07001234 graph_data_output_file =
sprangce4aef12015-11-02 07:23:20 -08001235 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
Peter Boström74f6e9e2016-04-04 17:56:10 +02001236 RTC_CHECK(graph_data_output_file)
sprangce4aef12015-11-02 07:23:20 -08001237 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1238 << "!";
ivica87f83a92015-10-08 05:13:32 -07001239 }
sprang7a975f72015-10-12 06:33:21 -07001240
ilnik98436952017-07-13 00:47:03 -07001241 if (!params.logging.rtc_event_log_name.empty()) {
Danil Chapovalov304ea5f2019-04-11 15:18:18 +02001242 send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1243 RtcEventLog::EncodingType::Legacy);
1244 recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1245 RtcEventLog::EncodingType::Legacy);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001246 std::unique_ptr<RtcEventLogOutputFile> send_output(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001247 std::make_unique<RtcEventLogOutputFile>(
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001248 params.logging.rtc_event_log_name + "_send",
1249 RtcEventLog::kUnlimitedOutput));
1250 std::unique_ptr<RtcEventLogOutputFile> recv_output(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001251 std::make_unique<RtcEventLogOutputFile>(
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001252 params.logging.rtc_event_log_name + "_recv",
1253 RtcEventLog::kUnlimitedOutput));
1254 bool event_log_started =
1255 send_event_log_->StartLogging(std::move(send_output),
1256 RtcEventLog::kImmediateOutput) &&
1257 recv_event_log_->StartLogging(std::move(recv_output),
1258 RtcEventLog::kImmediateOutput);
ilnik98436952017-07-13 00:47:03 -07001259 RTC_DCHECK(event_log_started);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001260 } else {
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001261 send_event_log_ = std::make_unique<RtcEventLogNull>();
1262 recv_event_log_ = std::make_unique<RtcEventLogNull>();
ilnik98436952017-07-13 00:47:03 -07001263 }
1264
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001265 SendTask(RTC_FROM_HERE, task_queue(),
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +02001266 [this, &params, &send_transport, &recv_transport]() {
1267 Call::Config send_call_config(send_event_log_.get());
1268 Call::Config recv_call_config(recv_event_log_.get());
1269 send_call_config.bitrate_config = params.call.call_bitrate_config;
1270 recv_call_config.bitrate_config = params.call.call_bitrate_config;
1271 if (params_.audio.enabled)
1272 InitializeAudioDevice(&send_call_config, &recv_call_config,
1273 params_.audio.use_real_adm);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001274
Danil Chapovalov82a3f0a2019-10-21 09:24:27 +02001275 CreateCalls(send_call_config, recv_call_config);
1276 send_transport = CreateSendTransport();
1277 recv_transport = CreateReceiveTransport();
1278 });
stefanf116bd02015-10-27 08:29:42 -07001279
sprangce4aef12015-11-02 07:23:20 -08001280 std::string graph_title = params_.analyzer.graph_title;
1281 if (graph_title.empty())
1282 graph_title = VideoQualityTest::GenerateGraphTitle();
sprangc1b57a12017-02-28 08:50:47 -08001283 bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest");
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001284 analyzer_ = std::make_unique<VideoAnalyzer>(
eladalon413ee9a2017-08-22 04:02:52 -07001285 send_transport.get(), params_.analyzer.test_label,
ilnik2a8c2f52017-02-15 02:23:28 -08001286 params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold,
ilnik9ae0d762017-02-15 00:53:12 -08001287 is_quick_test_enabled
1288 ? kFramesSentInQuickTest
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001289 : params_.analyzer.test_durations_secs * params_.video[0].fps,
sprangce4aef12015-11-02 07:23:20 -08001290 graph_data_output_file, graph_title,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001291 kVideoSendSsrcs[params_.ss[0].selected_stream],
1292 kSendRtxSsrcs[params_.ss[0].selected_stream],
1293 static_cast<size_t>(params_.ss[0].selected_stream),
1294 params.ss[0].selected_sl, params_.video[0].selected_tl,
Artem Titovff7730d2019-04-02 13:46:53 +02001295 is_quick_test_enabled, clock_, params_.logging.rtp_dump_name,
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001296 task_queue());
ivica5d6a06c2015-09-17 05:30:24 -07001297
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001298 SendTask(RTC_FROM_HERE, task_queue(), [&]() {
Niels Möller88be9722018-10-10 10:58:52 +02001299 analyzer_->SetCall(sender_call_.get());
1300 analyzer_->SetReceiver(receiver_call_->Receiver());
1301 send_transport->SetReceiver(analyzer_.get());
eladalon413ee9a2017-08-22 04:02:52 -07001302 recv_transport->SetReceiver(sender_call_->Receiver());
ivica5d6a06c2015-09-17 05:30:24 -07001303
Niels Möller88be9722018-10-10 10:58:52 +02001304 SetupVideo(analyzer_.get(), recv_transport.get());
1305 SetupThumbnails(analyzer_.get(), recv_transport.get());
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001306 video_receive_configs_[params_.ss[0].selected_stream].renderer =
Niels Möller88be9722018-10-10 10:58:52 +02001307 analyzer_.get();
kthelgason2bc68642017-02-07 07:02:22 -08001308
eladalon413ee9a2017-08-22 04:02:52 -07001309 CreateFlexfecStreams();
1310 CreateVideoStreams();
Niels Möller88be9722018-10-10 10:58:52 +02001311 analyzer_->SetSendStream(video_send_streams_[0]);
Ilya Nikolaevskiyd47d3eb2019-01-21 16:27:17 +01001312 analyzer_->SetReceiveStream(
1313 video_receive_streams_[params_.ss[0].selected_stream]);
ivica5d6a06c2015-09-17 05:30:24 -07001314
Niels Möller88be9722018-10-10 10:58:52 +02001315 GetVideoSendStream()->SetSource(analyzer_->OutputInterface(),
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001316 degradation_preference_);
eladalon413ee9a2017-08-22 04:02:52 -07001317 SetupThumbnailCapturers(params_.call.num_thumbnails);
1318 for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) {
1319 thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(),
1320 degradation_preference_);
1321 }
ilnika014cc52017-03-07 04:21:04 -08001322
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001323 CreateCapturers();
ivicac1cc8542015-10-08 03:44:06 -07001324
Stefan Holmer1f7a0082019-01-11 15:39:08 +01001325 analyzer_->SetSource(video_sources_[0].get(), true);
ilnika014cc52017-03-07 04:21:04 -08001326
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001327 for (size_t video_idx = 1; video_idx < num_video_streams_; ++video_idx) {
Niels Möller1c931c42018-12-18 16:08:11 +01001328 video_send_streams_[video_idx]->SetSource(video_sources_[video_idx].get(),
1329 degradation_preference_);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001330 }
1331
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001332 if (params_.audio.enabled) {
1333 SetupAudio(send_transport.get());
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001334 StartAudioStreams();
Niels Möller88be9722018-10-10 10:58:52 +02001335 analyzer_->SetAudioReceiveStream(audio_receive_streams_[0]);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001336 }
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001337 StartVideoStreams();
1338 StartThumbnails();
Niels Möller88be9722018-10-10 10:58:52 +02001339 analyzer_->StartMeasuringCpuProcessTime();
eladalon413ee9a2017-08-22 04:02:52 -07001340 });
ivica5d6a06c2015-09-17 05:30:24 -07001341
Niels Möller88be9722018-10-10 10:58:52 +02001342 analyzer_->Wait();
ivica5d6a06c2015-09-17 05:30:24 -07001343
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001344 SendTask(RTC_FROM_HERE, task_queue(), [&]() {
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001345 StopThumbnails();
1346 Stop();
ivica5d6a06c2015-09-17 05:30:24 -07001347
eladalon413ee9a2017-08-22 04:02:52 -07001348 DestroyStreams();
1349 DestroyThumbnailStreams();
ivica5d6a06c2015-09-17 05:30:24 -07001350
eladalon413ee9a2017-08-22 04:02:52 -07001351 if (graph_data_output_file)
1352 fclose(graph_data_output_file);
1353
eladalon413ee9a2017-08-22 04:02:52 -07001354 send_transport.reset();
1355 recv_transport.reset();
1356
1357 DestroyCalls();
1358 });
Niels Möller88be9722018-10-10 10:58:52 +02001359 analyzer_ = nullptr;
ivica5d6a06c2015-09-17 05:30:24 -07001360}
1361
henrika255750b2018-08-27 16:13:37 +02001362rtc::scoped_refptr<AudioDeviceModule> VideoQualityTest::CreateAudioDevice() {
1363#ifdef WEBRTC_WIN
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001364 RTC_LOG(INFO) << "Using latest version of ADM on Windows";
1365 // We must initialize the COM library on a thread before we calling any of
1366 // the library functions. All COM functions in the ADM will return
1367 // CO_E_NOTINITIALIZED otherwise. The legacy ADM for Windows used internal
1368 // COM initialization but the new ADM requires COM to be initialized
1369 // externally.
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001370 com_initializer_ = std::make_unique<webrtc_win::ScopedCOMInitializer>(
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001371 webrtc_win::ScopedCOMInitializer::kMTA);
1372 RTC_CHECK(com_initializer_->Succeeded());
1373 RTC_CHECK(webrtc_win::core_audio_utility::IsSupported());
1374 RTC_CHECK(webrtc_win::core_audio_utility::IsMMCSSSupported());
Danil Chapovalov1c41be62019-04-01 09:16:12 +02001375 return CreateWindowsCoreAudioAudioDeviceModule(task_queue_factory_.get());
henrika255750b2018-08-27 16:13:37 +02001376#else
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001377 // Use legacy factory method on all platforms except Windows.
Danil Chapovalov1c41be62019-04-01 09:16:12 +02001378 return AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio,
1379 task_queue_factory_.get());
henrika255750b2018-08-27 16:13:37 +02001380#endif
1381}
1382
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001383void VideoQualityTest::InitializeAudioDevice(Call::Config* send_call_config,
henrika255750b2018-08-27 16:13:37 +02001384 Call::Config* recv_call_config,
1385 bool use_real_adm) {
1386 rtc::scoped_refptr<AudioDeviceModule> audio_device;
1387 if (use_real_adm) {
1388 // Run test with real ADM (using default audio devices) if user has
1389 // explicitly set the --audio and --use_real_adm command-line flags.
1390 audio_device = CreateAudioDevice();
1391 } else {
1392 // By default, create a test ADM which fakes audio.
Danil Chapovalov08fa9532019-06-12 11:49:17 +00001393 audio_device = TestAudioDeviceModule::Create(
1394 task_queue_factory_.get(),
henrika255750b2018-08-27 16:13:37 +02001395 TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, 48000),
1396 TestAudioDeviceModule::CreateDiscardRenderer(48000), 1.f);
1397 }
1398 RTC_CHECK(audio_device);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001399
1400 AudioState::Config audio_state_config;
1401 audio_state_config.audio_mixer = AudioMixerImpl::Create();
1402 audio_state_config.audio_processing = AudioProcessingBuilder().Create();
henrika255750b2018-08-27 16:13:37 +02001403 audio_state_config.audio_device_module = audio_device;
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001404 send_call_config->audio_state = AudioState::Create(audio_state_config);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001405 recv_call_config->audio_state = AudioState::Create(audio_state_config);
henrika255750b2018-08-27 16:13:37 +02001406 if (use_real_adm) {
1407 // The real ADM requires extra initialization: setting default devices,
1408 // setting up number of channels etc. Helper class also calls
1409 // AudioDeviceModule::Init().
1410 webrtc::adm_helpers::Init(audio_device.get());
1411 } else {
1412 audio_device->Init();
1413 }
1414 // Always initialize the ADM before injecting a valid audio transport.
1415 RTC_CHECK(audio_device->RegisterAudioCallback(
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001416 send_call_config->audio_state->audio_transport()) == 0);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001417}
1418
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001419void VideoQualityTest::SetupAudio(Transport* transport) {
Bjorn A Mellem7a9a0922019-11-26 09:19:40 -08001420 AudioSendStream::Config audio_send_config(transport);
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001421 audio_send_config.rtp.ssrc = kAudioSendSsrc;
minyuea27172d2016-11-01 05:59:29 -07001422
1423 // Add extension to enable audio send side BWE, and allow audio bit rate
1424 // adaptation.
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001425 audio_send_config.rtp.extensions.clear();
1426 audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec(
Oskar Sundbom8e07c132018-01-08 16:45:42 +01001427 kAudioSendPayloadType,
Yves Gerey665174f2018-06-19 15:03:05 +02001428 {"OPUS",
1429 48000,
1430 2,
1431 {{"usedtx", (params_.audio.dtx ? "1" : "0")}, {"stereo", "1"}}});
minyuea27172d2016-11-01 05:59:29 -07001432
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001433 if (params_.call.send_side_bwe) {
1434 audio_send_config.rtp.extensions.push_back(
1435 webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +01001436 kTransportSequenceNumberExtensionId));
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001437 audio_send_config.min_bitrate_bps = kOpusMinBitrateBps;
1438 audio_send_config.max_bitrate_bps = kOpusBitrateFbBps;
1439 audio_send_config.send_codec_spec->transport_cc_enabled = true;
Minyue Li455d27c2019-01-07 13:14:30 +01001440 // Only allow ANA when send-side BWE is enabled.
1441 audio_send_config.audio_network_adaptor_config = params_.audio.ana_config;
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001442 }
1443 audio_send_config.encoder_factory = audio_encoder_factory_;
1444 SetAudioConfig(audio_send_config);
1445
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001446 std::string sync_group;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001447 if (params_.video[0].enabled && params_.audio.sync_video)
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001448 sync_group = kSyncGroup;
minyuea27172d2016-11-01 05:59:29 -07001449
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001450 CreateMatchingAudioConfigs(transport, sync_group);
1451 CreateAudioStreams();
minyuea27172d2016-11-01 05:59:29 -07001452}
1453
minyue73208662016-08-18 06:28:55 -07001454void VideoQualityTest::RunWithRenderers(const Params& params) {
henrika255750b2018-08-27 16:13:37 +02001455 RTC_LOG(INFO) << __FUNCTION__;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001456 num_video_streams_ = params.call.dual_video ? 2 : 1;
eladalon413ee9a2017-08-22 04:02:52 -07001457 std::unique_ptr<test::LayerFilteringTransport> send_transport;
1458 std::unique_ptr<test::DirectTransport> recv_transport;
minyuea27172d2016-11-01 05:59:29 -07001459 std::unique_ptr<test::VideoRenderer> local_preview;
eladalon413ee9a2017-08-22 04:02:52 -07001460 std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers;
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001461
1462 if (!params.logging.rtc_event_log_name.empty()) {
Danil Chapovalov304ea5f2019-04-11 15:18:18 +02001463 send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1464 RtcEventLog::EncodingType::Legacy);
1465 recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1466 RtcEventLog::EncodingType::Legacy);
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001467 std::unique_ptr<RtcEventLogOutputFile> send_output(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001468 std::make_unique<RtcEventLogOutputFile>(
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001469 params.logging.rtc_event_log_name + "_send",
1470 RtcEventLog::kUnlimitedOutput));
1471 std::unique_ptr<RtcEventLogOutputFile> recv_output(
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001472 std::make_unique<RtcEventLogOutputFile>(
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001473 params.logging.rtc_event_log_name + "_recv",
1474 RtcEventLog::kUnlimitedOutput));
1475 bool event_log_started =
1476 send_event_log_->StartLogging(std::move(send_output),
1477 /*output_period_ms=*/5000) &&
1478 recv_event_log_->StartLogging(std::move(recv_output),
1479 /*output_period_ms=*/5000);
1480 RTC_DCHECK(event_log_started);
1481 } else {
Mirko Bonadei317a1f02019-09-17 17:06:18 +02001482 send_event_log_ = std::make_unique<RtcEventLogNull>();
1483 recv_event_log_ = std::make_unique<RtcEventLogNull>();
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001484 }
minyue73208662016-08-18 06:28:55 -07001485
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001486 SendTask(RTC_FROM_HERE, task_queue(), [&]() {
eladalon413ee9a2017-08-22 04:02:52 -07001487 params_ = params;
Artem Titove269cb42018-08-29 09:59:23 +02001488 CheckParamsAndInjectionComponents();
palmkviste75f2042016-09-28 06:19:48 -07001489
eladalon413ee9a2017-08-22 04:02:52 -07001490 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
1491 // match the full stack tests.
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001492 Call::Config send_call_config(send_event_log_.get());
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001493 send_call_config.bitrate_config = params_.call.call_bitrate_config;
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001494 Call::Config recv_call_config(recv_event_log_.get());
ivica5d6a06c2015-09-17 05:30:24 -07001495
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001496 if (params_.audio.enabled)
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001497 InitializeAudioDevice(&send_call_config, &recv_call_config,
1498 params_.audio.use_real_adm);
minyue73208662016-08-18 06:28:55 -07001499
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001500 CreateCalls(send_call_config, recv_call_config);
eladalon413ee9a2017-08-22 04:02:52 -07001501
1502 // TODO(minyue): consider if this is a good transport even for audio only
1503 // calls.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001504 send_transport = CreateSendTransport();
eladalon413ee9a2017-08-22 04:02:52 -07001505
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001506 recv_transport = CreateReceiveTransport();
eladalon413ee9a2017-08-22 04:02:52 -07001507
1508 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
1509 // least share as much code as possible. That way this test would also match
1510 // the full stack tests better.
1511 send_transport->SetReceiver(receiver_call_->Receiver());
1512 recv_transport->SetReceiver(sender_call_->Receiver());
1513
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001514 if (params_.video[0].enabled) {
eladalon413ee9a2017-08-22 04:02:52 -07001515 // Create video renderers.
eladalon413ee9a2017-08-22 04:02:52 -07001516 SetupVideo(send_transport.get(), recv_transport.get());
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001517 size_t num_streams_processed = 0;
1518 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
1519 const size_t selected_stream_id = params_.ss[video_idx].selected_stream;
1520 const size_t num_streams = params_.ss[video_idx].streams.size();
1521 if (selected_stream_id == num_streams) {
1522 for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) {
Jonas Olsson366a50c2018-09-06 13:41:30 +02001523 rtc::StringBuilder oss;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001524 oss << "Loopback Video #" << video_idx << " - Stream #"
1525 << static_cast<int>(stream_id);
1526 loopback_renderers.emplace_back(test::VideoRenderer::Create(
1527 oss.str().c_str(),
1528 params_.ss[video_idx].streams[stream_id].width,
1529 params_.ss[video_idx].streams[stream_id].height));
1530 video_receive_configs_[stream_id + num_streams_processed].renderer =
1531 loopback_renderers.back().get();
1532 if (params_.audio.enabled && params_.audio.sync_video)
1533 video_receive_configs_[stream_id + num_streams_processed]
1534 .sync_group = kSyncGroup;
1535 }
1536 } else {
Jonas Olsson366a50c2018-09-06 13:41:30 +02001537 rtc::StringBuilder oss;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001538 oss << "Loopback Video #" << video_idx;
1539 loopback_renderers.emplace_back(test::VideoRenderer::Create(
1540 oss.str().c_str(),
1541 params_.ss[video_idx].streams[selected_stream_id].width,
1542 params_.ss[video_idx].streams[selected_stream_id].height));
1543 video_receive_configs_[selected_stream_id + num_streams_processed]
1544 .renderer = loopback_renderers.back().get();
eladalon413ee9a2017-08-22 04:02:52 -07001545 if (params_.audio.enabled && params_.audio.sync_video)
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001546 video_receive_configs_[num_streams_processed + selected_stream_id]
1547 .sync_group = kSyncGroup;
eladalon413ee9a2017-08-22 04:02:52 -07001548 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001549 num_streams_processed += num_streams;
eladalon413ee9a2017-08-22 04:02:52 -07001550 }
eladalon413ee9a2017-08-22 04:02:52 -07001551 CreateFlexfecStreams();
1552 CreateVideoStreams();
1553
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001554 CreateCapturers();
Niels Möller412d1852019-01-02 09:42:54 +01001555 if (params_.video[0].enabled) {
1556 // Create local preview
1557 local_preview.reset(test::VideoRenderer::Create(
1558 "Local Preview", params_.video[0].width, params_.video[0].height));
1559
1560 video_sources_[0]->AddOrUpdateSink(local_preview.get(),
1561 rtc::VideoSinkWants());
1562 }
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001563 ConnectVideoSourcesToStreams();
eladalon413ee9a2017-08-22 04:02:52 -07001564 }
1565
1566 if (params_.audio.enabled) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001567 SetupAudio(send_transport.get());
eladalon413ee9a2017-08-22 04:02:52 -07001568 }
1569
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001570 Start();
eladalon413ee9a2017-08-22 04:02:52 -07001571 });
minyue73208662016-08-18 06:28:55 -07001572
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001573 test::PressEnterToContinue(task_queue());
ivica5d6a06c2015-09-17 05:30:24 -07001574
Danil Chapovalovd15a0282019-10-22 10:48:17 +02001575 SendTask(RTC_FROM_HERE, task_queue(), [&]() {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001576 Stop();
1577 DestroyStreams();
minyue73208662016-08-18 06:28:55 -07001578
eladalon413ee9a2017-08-22 04:02:52 -07001579 send_transport.reset();
1580 recv_transport.reset();
sprang1168fd42017-06-21 09:00:17 -07001581
eladalon413ee9a2017-08-22 04:02:52 -07001582 local_preview.reset();
1583 loopback_renderers.clear();
1584
1585 DestroyCalls();
1586 });
ivica5d6a06c2015-09-17 05:30:24 -07001587}
1588
ivica5d6a06c2015-09-17 05:30:24 -07001589} // namespace webrtc