blob: 525650ea384f6773519c7121dcfa3687cde1b7eb [file] [log] [blame]
ivica5d6a06c2015-09-17 05:30:24 -07001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#include "video/video_quality_test.h"
perkj9fdbda62016-09-15 09:19:20 -070011
perkja49cbd32016-09-16 07:53:41 -070012#include <stdio.h>
ivica5d6a06c2015-09-17 05:30:24 -070013#include <algorithm>
14#include <deque>
15#include <map>
mflodmand1590b22015-12-09 07:07:59 -080016#include <string>
ivica5d6a06c2015-09-17 05:30:24 -070017#include <vector>
18
Florent Castellie7862cc2018-12-06 13:38:24 +010019#include "absl/memory/memory.h"
Niels Möllerd8b9ed72019-05-08 13:53:51 +020020#include "api/rtc_event_log_output_file.h"
Danil Chapovalov1c41be62019-04-01 09:16:12 +020021#include "api/task_queue/default_task_queue_factory.h"
Jiawei Ouc2ebe212018-11-08 10:02:56 -080022#include "api/video/builtin_video_bitrate_allocator_factory.h"
Artem Titovdd2eebe2018-08-20 13:27:45 +020023#include "call/fake_network_pipe.h"
24#include "call/simulated_network.h"
henrika255750b2018-08-27 16:13:37 +020025#include "media/engine/adm_helpers.h"
Florent Castellie7862cc2018-12-06 13:38:24 +010026#include "media/engine/encoder_simulcast_proxy.h"
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -050027#include "media/engine/fake_video_codec_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "media/engine/internal_encoder_factory.h"
29#include "media/engine/webrtc_video_engine.h"
henrika255750b2018-08-27 16:13:37 +020030#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "modules/audio_mixer/audio_mixer_impl.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "modules/video_coding/codecs/h264/include/h264.h"
Niels Möllercbcbc222018-09-28 09:07:24 +020033#include "modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h"
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080034#include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h"
Niels Möller4db138e2018-04-19 09:04:13 +020035#include "modules/video_coding/codecs/vp8/include/vp8.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "modules/video_coding/codecs/vp9/include/vp9.h"
Niels Möller1beef1a2018-09-03 14:21:44 +020037#include "modules/video_coding/utility/ivf_file_writer.h"
38#include "rtc_base/strings/string_builder.h"
Kári Tristan Helgasonede7cb22019-03-06 10:34:09 +010039#include "test/platform_video_capturer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020040#include "test/run_loop.h"
Steve Anton10542f22019-01-11 09:11:00 -080041#include "test/testsupport/file_utils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "test/video_renderer.h"
Erik Språng96965ae2018-10-23 15:42:37 +020043#include "video/frame_dumping_decoder.h"
henrika255750b2018-08-27 16:13:37 +020044#ifdef WEBRTC_WIN
45#include "modules/audio_device/include/audio_device_factory.h"
46#endif
ilnikee42d192017-08-22 07:16:20 -070047
Niels Möller1beef1a2018-09-03 14:21:44 +020048namespace webrtc {
49
minyue73208662016-08-18 06:28:55 -070050namespace {
Elad Alond8d32482019-02-18 23:45:57 +010051enum : int { // The first valid value is 1.
52 kAbsSendTimeExtensionId = 1,
Elad Alonccb9b752019-02-19 13:01:31 +010053 kGenericFrameDescriptorExtensionId00,
54 kGenericFrameDescriptorExtensionId01,
Elad Alond8d32482019-02-18 23:45:57 +010055 kTransportSequenceNumberExtensionId,
56 kVideoContentTypeExtensionId,
57 kVideoTimingExtensionId,
58};
59
minyue73208662016-08-18 06:28:55 -070060constexpr char kSyncGroup[] = "av_sync";
minyue10cbb462016-11-07 09:29:22 -080061constexpr int kOpusMinBitrateBps = 6000;
62constexpr int kOpusBitrateFbBps = 32000;
ilnik9ae0d762017-02-15 00:53:12 -080063constexpr int kFramesSentInQuickTest = 1;
ilnika014cc52017-03-07 04:21:04 -080064constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000;
65constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000;
minyue73208662016-08-18 06:28:55 -070066
sprang1168fd42017-06-21 09:00:17 -070067constexpr int kDefaultMaxQp = cricket::WebRtcVideoChannel::kDefaultQpMax;
68
Erik Språng616b2332019-02-11 14:16:28 +010069std::pair<uint32_t, uint32_t> GetMinMaxBitratesBps(const VideoCodec& codec,
70 size_t spatial_idx) {
71 uint32_t min_bitrate = codec.minBitrate;
72 uint32_t max_bitrate = codec.maxBitrate;
73 if (spatial_idx < codec.numberOfSimulcastStreams) {
74 min_bitrate =
75 std::max(min_bitrate, codec.simulcastStream[spatial_idx].minBitrate);
76 max_bitrate =
77 std::min(max_bitrate, codec.simulcastStream[spatial_idx].maxBitrate);
78 }
79 if (codec.codecType == VideoCodecType::kVideoCodecVP9 &&
80 spatial_idx < codec.VP9().numberOfSpatialLayers) {
81 min_bitrate =
82 std::max(min_bitrate, codec.spatialLayers[spatial_idx].minBitrate);
83 max_bitrate =
84 std::min(max_bitrate, codec.spatialLayers[spatial_idx].maxBitrate);
85 }
86 max_bitrate = std::max(max_bitrate, min_bitrate);
87 return {min_bitrate * 1000, max_bitrate * 1000};
88}
89
perkjfa10b552016-10-02 23:45:26 -070090class VideoStreamFactory
Niels Möller1beef1a2018-09-03 14:21:44 +020091 : public VideoEncoderConfig::VideoStreamFactoryInterface {
perkjfa10b552016-10-02 23:45:26 -070092 public:
Niels Möller1beef1a2018-09-03 14:21:44 +020093 explicit VideoStreamFactory(const std::vector<VideoStream>& streams)
perkjfa10b552016-10-02 23:45:26 -070094 : streams_(streams) {}
95
96 private:
Niels Möller1beef1a2018-09-03 14:21:44 +020097 std::vector<VideoStream> CreateEncoderStreams(
perkjfa10b552016-10-02 23:45:26 -070098 int width,
99 int height,
Niels Möller1beef1a2018-09-03 14:21:44 +0200100 const VideoEncoderConfig& encoder_config) override {
mflodmand79f97b2016-12-15 07:24:33 -0800101 // The highest layer must match the incoming resolution.
Niels Möller1beef1a2018-09-03 14:21:44 +0200102 std::vector<VideoStream> streams = streams_;
mflodmand79f97b2016-12-15 07:24:33 -0800103 streams[streams_.size() - 1].height = height;
104 streams[streams_.size() - 1].width = width;
Seth Hampson24722b32017-12-22 09:36:42 -0800105
106 streams[0].bitrate_priority = encoder_config.bitrate_priority;
mflodmand79f97b2016-12-15 07:24:33 -0800107 return streams;
perkjfa10b552016-10-02 23:45:26 -0700108 }
109
Niels Möller1beef1a2018-09-03 14:21:44 +0200110 std::vector<VideoStream> streams_;
perkjfa10b552016-10-02 23:45:26 -0700111};
ivica5d6a06c2015-09-17 05:30:24 -0700112
Niels Möller88be9722018-10-10 10:58:52 +0200113// This wrapper provides two features needed by the video quality tests:
114// 1. Invoke VideoAnalyzer callbacks before and after encoding each frame.
115// 2. Write the encoded frames to file, one file per simulcast layer.
116class QualityTestVideoEncoder : public VideoEncoder,
117 private EncodedImageCallback {
Niels Möller1beef1a2018-09-03 14:21:44 +0200118 public:
Niels Möller88be9722018-10-10 10:58:52 +0200119 QualityTestVideoEncoder(std::unique_ptr<VideoEncoder> encoder,
120 VideoAnalyzer* analyzer,
Erik Språng616b2332019-02-11 14:16:28 +0100121 std::vector<FileWrapper> files,
122 double overshoot_factor)
123 : encoder_(std::move(encoder)),
124 overshoot_factor_(overshoot_factor),
125 analyzer_(analyzer) {
Niels Möllerb7edf692019-02-08 16:40:53 +0100126 for (FileWrapper& file : files) {
Niels Möller1beef1a2018-09-03 14:21:44 +0200127 writers_.push_back(
Niels Möllerb7edf692019-02-08 16:40:53 +0100128 IvfFileWriter::Wrap(std::move(file), /* byte_limit= */ 100000000));
Niels Möller1beef1a2018-09-03 14:21:44 +0200129 }
130 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200131
Niels Möller1beef1a2018-09-03 14:21:44 +0200132 // Implement VideoEncoder
133 int32_t InitEncode(const VideoCodec* codec_settings,
134 int32_t number_of_cores,
135 size_t max_payload_size) override {
Erik Språng616b2332019-02-11 14:16:28 +0100136 codec_settings_ = *codec_settings;
Niels Möller1beef1a2018-09-03 14:21:44 +0200137 return encoder_->InitEncode(codec_settings, number_of_cores,
138 max_payload_size);
139 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200140
Niels Möller1beef1a2018-09-03 14:21:44 +0200141 int32_t RegisterEncodeCompleteCallback(
142 EncodedImageCallback* callback) override {
143 callback_ = callback;
144 return encoder_->RegisterEncodeCompleteCallback(this);
145 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200146
Niels Möller1beef1a2018-09-03 14:21:44 +0200147 int32_t Release() override { return encoder_->Release(); }
Elad Alonfe4f6942019-05-07 23:13:42 +0200148
Niels Möller1beef1a2018-09-03 14:21:44 +0200149 int32_t Encode(const VideoFrame& frame,
Niels Möller87e2d782019-03-07 10:18:23 +0100150 const std::vector<VideoFrameType>* frame_types) {
Niels Möller88be9722018-10-10 10:58:52 +0200151 if (analyzer_) {
152 analyzer_->PreEncodeOnFrame(frame);
153 }
Niels Möllerc8d2e732019-03-06 12:00:33 +0100154 return encoder_->Encode(frame, frame_types);
Niels Möller1beef1a2018-09-03 14:21:44 +0200155 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200156
Erik Språng16cb8f52019-04-12 13:59:09 +0200157 void SetRates(const RateControlParameters& parameters) override {
Erik Språng616b2332019-02-11 14:16:28 +0100158 RTC_DCHECK_GT(overshoot_factor_, 0.0);
159 if (overshoot_factor_ == 1.0) {
Erik Språng16cb8f52019-04-12 13:59:09 +0200160 encoder_->SetRates(parameters);
161 return;
Erik Språng616b2332019-02-11 14:16:28 +0100162 }
163
164 // Simulating encoder overshooting target bitrate, by configuring actual
165 // encoder too high. Take care not to adjust past limits of config,
166 // otherwise encoders may crash on DCHECK.
167 VideoBitrateAllocation overshot_allocation;
168 for (size_t si = 0; si < kMaxSpatialLayers; ++si) {
169 const uint32_t spatial_layer_bitrate_bps =
Erik Språng16cb8f52019-04-12 13:59:09 +0200170 parameters.bitrate.GetSpatialLayerSum(si);
Erik Språng616b2332019-02-11 14:16:28 +0100171 if (spatial_layer_bitrate_bps == 0) {
172 continue;
173 }
174
175 uint32_t min_bitrate_bps;
176 uint32_t max_bitrate_bps;
177 std::tie(min_bitrate_bps, max_bitrate_bps) =
178 GetMinMaxBitratesBps(codec_settings_, si);
179 double overshoot_factor = overshoot_factor_;
180 const uint32_t corrected_bitrate = rtc::checked_cast<uint32_t>(
181 overshoot_factor * spatial_layer_bitrate_bps);
182 if (corrected_bitrate < min_bitrate_bps) {
183 overshoot_factor = min_bitrate_bps / spatial_layer_bitrate_bps;
184 } else if (corrected_bitrate > max_bitrate_bps) {
185 overshoot_factor = max_bitrate_bps / spatial_layer_bitrate_bps;
186 }
187
188 for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) {
Erik Språng16cb8f52019-04-12 13:59:09 +0200189 if (parameters.bitrate.HasBitrate(si, ti)) {
Erik Språng616b2332019-02-11 14:16:28 +0100190 overshot_allocation.SetBitrate(
191 si, ti,
Erik Språng16cb8f52019-04-12 13:59:09 +0200192 rtc::checked_cast<uint32_t>(
193 overshoot_factor * parameters.bitrate.GetBitrate(si, ti)));
Erik Språng616b2332019-02-11 14:16:28 +0100194 }
195 }
196 }
197
Erik Språng16cb8f52019-04-12 13:59:09 +0200198 return encoder_->SetRates(
199 RateControlParameters(overshot_allocation, parameters.framerate_fps,
200 parameters.bandwidth_allocation));
Niels Möller1beef1a2018-09-03 14:21:44 +0200201 }
Elad Alonfe4f6942019-05-07 23:13:42 +0200202
203 void OnPacketLossRateUpdate(float packet_loss_rate) override {
204 encoder_->OnPacketLossRateUpdate(packet_loss_rate);
205 }
206
207 void OnRttUpdate(int64_t rtt_ms) override { encoder_->OnRttUpdate(rtt_ms); }
208
209 void OnLossNotification(const LossNotification& loss_notification) override {
210 encoder_->OnLossNotification(loss_notification);
211 }
212
Erik Språng189013b2018-11-01 15:03:57 +0100213 EncoderInfo GetEncoderInfo() const override {
Erik Språng616b2332019-02-11 14:16:28 +0100214 EncoderInfo info = encoder_->GetEncoderInfo();
215 if (overshoot_factor_ != 1.0) {
216 // We're simulating bad encoder, don't forward trusted setting
217 // from eg libvpx.
218 info.has_trusted_rate_controller = false;
219 }
220 return info;
Niels Möller1beef1a2018-09-03 14:21:44 +0200221 }
222
223 private:
224 // Implement EncodedImageCallback
225 Result OnEncodedImage(const EncodedImage& encoded_image,
226 const CodecSpecificInfo* codec_specific_info,
227 const RTPFragmentationHeader* fragmentation) override {
228 if (codec_specific_info) {
229 int simulcast_index;
230 if (codec_specific_info->codecType == kVideoCodecVP9) {
231 simulcast_index = 0;
232 } else {
233 simulcast_index = encoded_image.SpatialIndex().value_or(0);
234 }
235 RTC_DCHECK_GE(simulcast_index, 0);
Niels Möller88be9722018-10-10 10:58:52 +0200236 if (analyzer_) {
237 analyzer_->PostEncodeOnFrame(simulcast_index,
238 encoded_image.Timestamp());
239 }
Niels Möller1beef1a2018-09-03 14:21:44 +0200240 if (static_cast<size_t>(simulcast_index) < writers_.size()) {
241 writers_[simulcast_index]->WriteFrame(encoded_image,
242 codec_specific_info->codecType);
243 }
244 }
245
246 return callback_->OnEncodedImage(encoded_image, codec_specific_info,
247 fragmentation);
248 }
249
250 void OnDroppedFrame(DropReason reason) override {
251 callback_->OnDroppedFrame(reason);
252 }
253
Erik Språng616b2332019-02-11 14:16:28 +0100254 const std::unique_ptr<VideoEncoder> encoder_;
255 const double overshoot_factor_;
Niels Möller88be9722018-10-10 10:58:52 +0200256 VideoAnalyzer* const analyzer_;
Niels Möller1beef1a2018-09-03 14:21:44 +0200257 std::vector<std::unique_ptr<IvfFileWriter>> writers_;
Erik Språng616b2332019-02-11 14:16:28 +0100258 EncodedImageCallback* callback_ = nullptr;
259 VideoCodec codec_settings_;
Niels Möller1beef1a2018-09-03 14:21:44 +0200260};
261
262} // namespace
ivica5d6a06c2015-09-17 05:30:24 -0700263
Niels Möllercbcbc222018-09-28 09:07:24 +0200264std::unique_ptr<VideoDecoder> VideoQualityTest::CreateVideoDecoder(
265 const SdpVideoFormat& format) {
266 std::unique_ptr<VideoDecoder> decoder;
267 if (format.name == "multiplex") {
268 decoder = absl::make_unique<MultiplexDecoderAdapter>(
269 &internal_decoder_factory_, SdpVideoFormat(cricket::kVp9CodecName));
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -0500270 } else if (format.name == "FakeCodec") {
271 decoder = webrtc::FakeVideoDecoderFactory::CreateVideoDecoder();
Niels Möllercbcbc222018-09-28 09:07:24 +0200272 } else {
273 decoder = internal_decoder_factory_.CreateVideoDecoder(format);
274 }
Niels Möller5ca29122018-10-02 09:55:01 +0200275 if (!params_.logging.encoded_frame_base_path.empty()) {
276 rtc::StringBuilder str;
277 str << receive_logs_++;
278 std::string path =
279 params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
280 decoder = absl::make_unique<FrameDumpingDecoder>(
Niels Möllerb7edf692019-02-08 16:40:53 +0100281 std::move(decoder), FileWrapper::OpenWriteOnly(path));
Niels Möller5ca29122018-10-02 09:55:01 +0200282 }
Niels Möllercbcbc222018-09-28 09:07:24 +0200283 return decoder;
284}
285
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200286std::unique_ptr<VideoEncoder> VideoQualityTest::CreateVideoEncoder(
Niels Möller88be9722018-10-10 10:58:52 +0200287 const SdpVideoFormat& format,
288 VideoAnalyzer* analyzer) {
Niels Möller1beef1a2018-09-03 14:21:44 +0200289 std::unique_ptr<VideoEncoder> encoder;
Niels Möller4db138e2018-04-19 09:04:13 +0200290 if (format.name == "VP8") {
Florent Castellie7862cc2018-12-06 13:38:24 +0100291 encoder = absl::make_unique<EncoderSimulcastProxy>(
Karl Wiberg918f50c2018-07-05 11:40:33 +0200292 &internal_encoder_factory_, format);
Niels Möller4db138e2018-04-19 09:04:13 +0200293 } else if (format.name == "multiplex") {
Niels Möller1beef1a2018-09-03 14:21:44 +0200294 encoder = absl::make_unique<MultiplexEncoderAdapter>(
Niels Möller4db138e2018-04-19 09:04:13 +0200295 &internal_encoder_factory_, SdpVideoFormat(cricket::kVp9CodecName));
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -0500296 } else if (format.name == "FakeCodec") {
297 encoder = webrtc::FakeVideoEncoderFactory::CreateVideoEncoder();
Niels Möller1beef1a2018-09-03 14:21:44 +0200298 } else {
299 encoder = internal_encoder_factory_.CreateVideoEncoder(format);
Niels Möller4db138e2018-04-19 09:04:13 +0200300 }
Erik Språng616b2332019-02-11 14:16:28 +0100301
302 std::vector<FileWrapper> encoded_frame_dump_files;
Niels Möller1beef1a2018-09-03 14:21:44 +0200303 if (!params_.logging.encoded_frame_base_path.empty()) {
304 char ss_buf[100];
305 rtc::SimpleStringBuilder sb(ss_buf);
306 sb << send_logs_++;
307 std::string prefix =
308 params_.logging.encoded_frame_base_path + "." + sb.str() + ".send.";
Erik Språng616b2332019-02-11 14:16:28 +0100309 encoded_frame_dump_files.push_back(
310 FileWrapper::OpenWriteOnly(prefix + "1.ivf"));
311 encoded_frame_dump_files.push_back(
312 FileWrapper::OpenWriteOnly(prefix + "2.ivf"));
313 encoded_frame_dump_files.push_back(
314 FileWrapper::OpenWriteOnly(prefix + "3.ivf"));
315 }
Niels Möllerb7edf692019-02-08 16:40:53 +0100316
Erik Språng616b2332019-02-11 14:16:28 +0100317 double overshoot_factor = 1.0;
318 // Match format to either of the streams in dual-stream mode in order to get
319 // the overshoot factor. This is not very robust but we can't know for sure
320 // which stream this encoder is meant for, from within the factory.
321 if (format ==
322 SdpVideoFormat(params_.video[0].codec, params_.video[0].sdp_params)) {
323 overshoot_factor = params_.video[0].encoder_overshoot_factor;
324 } else if (format == SdpVideoFormat(params_.video[1].codec,
325 params_.video[1].sdp_params)) {
326 overshoot_factor = params_.video[1].encoder_overshoot_factor;
327 }
328 if (overshoot_factor == 0.0) {
329 // If params were zero-initialized, set to 1.0 instead.
330 overshoot_factor = 1.0;
331 }
332
333 if (analyzer || !encoded_frame_dump_files.empty() || overshoot_factor > 1.0) {
Niels Möller88be9722018-10-10 10:58:52 +0200334 encoder = absl::make_unique<QualityTestVideoEncoder>(
Erik Språng616b2332019-02-11 14:16:28 +0100335 std::move(encoder), analyzer, std::move(encoded_frame_dump_files),
336 overshoot_factor);
Niels Möller1beef1a2018-09-03 14:21:44 +0200337 }
Niels Möller88be9722018-10-10 10:58:52 +0200338
Niels Möller1beef1a2018-09-03 14:21:44 +0200339 return encoder;
Niels Möller4db138e2018-04-19 09:04:13 +0200340}
341
Patrik Höglundb6b29e02018-06-21 16:58:01 +0200342VideoQualityTest::VideoQualityTest(
Artem Titove269cb42018-08-29 09:59:23 +0200343 std::unique_ptr<InjectionComponents> injection_components)
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200344 : clock_(Clock::GetRealTimeClock()),
Danil Chapovalov1c41be62019-04-01 09:16:12 +0200345 task_queue_factory_(CreateDefaultTaskQueueFactory()),
Danil Chapovalov304ea5f2019-04-11 15:18:18 +0200346 rtc_event_log_factory_(task_queue_factory_.get()),
Niels Möllercbcbc222018-09-28 09:07:24 +0200347 video_decoder_factory_([this](const SdpVideoFormat& format) {
348 return this->CreateVideoDecoder(format);
349 }),
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200350 video_encoder_factory_([this](const SdpVideoFormat& format) {
Niels Möller88be9722018-10-10 10:58:52 +0200351 return this->CreateVideoEncoder(format, nullptr);
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200352 }),
Niels Möller88be9722018-10-10 10:58:52 +0200353 video_encoder_factory_with_analyzer_(
354 [this](const SdpVideoFormat& format) {
355 return this->CreateVideoEncoder(format, analyzer_.get());
356 }),
Jiawei Ouc2ebe212018-11-08 10:02:56 -0800357 video_bitrate_allocator_factory_(
358 CreateBuiltinVideoBitrateAllocatorFactory()),
Sebastian Janssone6d7c3e2018-07-11 15:00:41 +0200359 receive_logs_(0),
Artem Titove269cb42018-08-29 09:59:23 +0200360 send_logs_(0),
Erik Språng96965ae2018-10-23 15:42:37 +0200361 injection_components_(std::move(injection_components)),
362 num_video_streams_(0) {
Artem Titove269cb42018-08-29 09:59:23 +0200363 if (injection_components_ == nullptr) {
364 injection_components_ = absl::make_unique<InjectionComponents>();
365 }
366
minyue20c84cc2017-04-10 16:57:57 -0700367 payload_type_map_ = test::CallTest::payload_type_map_;
368 RTC_DCHECK(payload_type_map_.find(kPayloadTypeH264) ==
369 payload_type_map_.end());
370 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP8) ==
371 payload_type_map_.end());
372 RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP9) ==
373 payload_type_map_.end());
374 payload_type_map_[kPayloadTypeH264] = webrtc::MediaType::VIDEO;
375 payload_type_map_[kPayloadTypeVP8] = webrtc::MediaType::VIDEO;
376 payload_type_map_[kPayloadTypeVP9] = webrtc::MediaType::VIDEO;
ivica5d6a06c2015-09-17 05:30:24 -0700377
Artem Titove269cb42018-08-29 09:59:23 +0200378 fec_controller_factory_ =
379 std::move(injection_components_->fec_controller_factory);
Ying Wangcab77fd2019-04-16 11:12:49 +0200380 network_state_predictor_factory_ =
381 std::move(injection_components_->network_state_predictor_factory);
Sebastian Jansson1391ed22019-04-30 14:23:51 +0200382 network_controller_factory_ =
383 std::move(injection_components_->network_controller_factory);
Ying Wang3b790f32018-01-19 17:58:57 +0100384}
385
minyue626bc952016-10-31 05:47:02 -0700386VideoQualityTest::Params::Params()
philipel569397f2018-09-26 12:25:31 +0200387 : call({false, false, BitrateConstraints(), 0}),
Erik Språng616b2332019-02-11 14:16:28 +0100388 video{{false,
389 640,
390 480,
391 30,
392 50,
393 800,
394 800,
395 false,
396 "VP8",
397 1,
398 -1,
399 0,
400 false,
401 false,
402 false,
403 "",
404 0,
405 {},
406 0.0},
407 {false,
408 640,
409 480,
410 30,
411 50,
412 800,
413 800,
414 false,
415 "VP8",
416 1,
417 -1,
418 0,
419 false,
420 false,
421 false,
422 "",
423 0,
424 {},
425 0.0}},
henrika255750b2018-08-27 16:13:37 +0200426 audio({false, false, false, false}),
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100427 screenshare{{false, false, 10, 0}, {false, false, 10, 0}},
minyue626bc952016-10-31 05:47:02 -0700428 analyzer({"", 0.0, 0.0, 0, "", ""}),
Artem Titovf18b3522018-08-28 16:54:24 +0200429 config(absl::nullopt),
Sergey Silkin57027362018-05-15 09:12:05 +0200430 ss{{std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn,
431 std::vector<SpatialLayer>()},
432 {std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn,
433 std::vector<SpatialLayer>()}},
Mirko Bonadei45a4c412018-07-31 15:07:28 +0200434 logging({"", "", ""}) {}
minyue626bc952016-10-31 05:47:02 -0700435
436VideoQualityTest::Params::~Params() = default;
437
Artem Titove269cb42018-08-29 09:59:23 +0200438VideoQualityTest::InjectionComponents::InjectionComponents() = default;
439
440VideoQualityTest::InjectionComponents::~InjectionComponents() = default;
441
ivica5d6a06c2015-09-17 05:30:24 -0700442void VideoQualityTest::TestBody() {}
443
sprangce4aef12015-11-02 07:23:20 -0800444std::string VideoQualityTest::GenerateGraphTitle() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200445 rtc::StringBuilder ss;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100446 ss << params_.video[0].codec;
447 ss << " (" << params_.video[0].target_bitrate_bps / 1000 << "kbps";
448 ss << ", " << params_.video[0].fps << " FPS";
449 if (params_.screenshare[0].scroll_duration)
450 ss << ", " << params_.screenshare[0].scroll_duration << "s scroll";
451 if (params_.ss[0].streams.size() > 1)
452 ss << ", Stream #" << params_.ss[0].selected_stream;
453 if (params_.ss[0].num_spatial_layers > 1)
454 ss << ", Layer #" << params_.ss[0].selected_sl;
sprangce4aef12015-11-02 07:23:20 -0800455 ss << ")";
Jonas Olsson84df1c72018-09-14 16:59:32 +0200456 return ss.Release();
sprangce4aef12015-11-02 07:23:20 -0800457}
458
Artem Titove269cb42018-08-29 09:59:23 +0200459void VideoQualityTest::CheckParamsAndInjectionComponents() {
460 if (injection_components_ == nullptr) {
461 injection_components_ = absl::make_unique<InjectionComponents>();
462 }
463 if (!params_.config && injection_components_->sender_network == nullptr &&
464 injection_components_->receiver_network == nullptr) {
Artem Titov62ae1782018-10-24 14:14:49 +0200465 params_.config = BuiltInNetworkBehaviorConfig();
Artem Titovf18b3522018-08-28 16:54:24 +0200466 }
Artem Titove269cb42018-08-29 09:59:23 +0200467 RTC_CHECK(
468 (params_.config && injection_components_->sender_network == nullptr &&
469 injection_components_->receiver_network == nullptr) ||
470 (!params_.config && injection_components_->sender_network != nullptr &&
471 injection_components_->receiver_network != nullptr));
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100472 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
473 // Iterate over primary and secondary video streams.
474 if (!params_.video[video_idx].enabled)
475 return;
476 // Add a default stream in none specified.
477 if (params_.ss[video_idx].streams.empty())
478 params_.ss[video_idx].streams.push_back(
479 VideoQualityTest::DefaultVideoStream(params_, video_idx));
480 if (params_.ss[video_idx].num_spatial_layers == 0)
481 params_.ss[video_idx].num_spatial_layers = 1;
sprangce4aef12015-11-02 07:23:20 -0800482
Artem Titove269cb42018-08-29 09:59:23 +0200483 if (params_.config) {
484 if (params_.config->loss_percent != 0 ||
485 params_.config->queue_length_packets != 0) {
486 // Since LayerFilteringTransport changes the sequence numbers, we can't
487 // use that feature with pack loss, since the NACK request would end up
488 // retransmitting the wrong packets.
489 RTC_CHECK(params_.ss[video_idx].selected_sl == -1 ||
490 params_.ss[video_idx].selected_sl ==
491 params_.ss[video_idx].num_spatial_layers - 1);
492 RTC_CHECK(params_.video[video_idx].selected_tl == -1 ||
493 params_.video[video_idx].selected_tl ==
494 params_.video[video_idx].num_temporal_layers - 1);
495 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100496 }
sprangce4aef12015-11-02 07:23:20 -0800497
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100498 // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as
499 // it does in some parts of the code?
500 RTC_CHECK_GE(params_.video[video_idx].max_bitrate_bps,
501 params_.video[video_idx].target_bitrate_bps);
502 RTC_CHECK_GE(params_.video[video_idx].target_bitrate_bps,
503 params_.video[video_idx].min_bitrate_bps);
Ilya Nikolaevskiyaec663e2019-02-27 12:52:11 +0100504 int selected_stream = params_.ss[video_idx].selected_stream;
505 int stream_tl = params_.ss[video_idx]
506 .streams[selected_stream]
507 .num_temporal_layers.value_or(1);
508 RTC_CHECK_LT(params_.video[video_idx].selected_tl, stream_tl);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100509 RTC_CHECK_LE(params_.ss[video_idx].selected_stream,
510 params_.ss[video_idx].streams.size());
511 for (const VideoStream& stream : params_.ss[video_idx].streams) {
512 RTC_CHECK_GE(stream.min_bitrate_bps, 0);
513 RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps);
514 RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps);
515 }
516 // TODO(ivica): Should we check if the sum of all streams/layers is equal to
517 // the total bitrate? We anyway have to update them in the case bitrate
518 // estimator changes the total bitrates.
519 RTC_CHECK_GE(params_.ss[video_idx].num_spatial_layers, 1);
520 RTC_CHECK_LE(params_.ss[video_idx].selected_sl,
521 params_.ss[video_idx].num_spatial_layers);
522 RTC_CHECK(
523 params_.ss[video_idx].spatial_layers.empty() ||
524 params_.ss[video_idx].spatial_layers.size() ==
525 static_cast<size_t>(params_.ss[video_idx].num_spatial_layers));
526 if (params_.video[video_idx].codec == "VP8") {
527 RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1);
528 } else if (params_.video[video_idx].codec == "VP9") {
529 RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 1);
530 }
531 RTC_CHECK_GE(params_.call.num_thumbnails, 0);
532 if (params_.call.num_thumbnails > 0) {
533 RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1);
534 RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 3);
535 RTC_CHECK_EQ(params_.video[video_idx].num_temporal_layers, 3);
536 RTC_CHECK_EQ(params_.video[video_idx].codec, "VP8");
537 }
538 // Dual streams with FEC not supported in tests yet.
539 RTC_CHECK(!params_.video[video_idx].flexfec || num_video_streams_ == 1);
540 RTC_CHECK(!params_.video[video_idx].ulpfec || num_video_streams_ == 1);
ilnika014cc52017-03-07 04:21:04 -0800541 }
sprangce4aef12015-11-02 07:23:20 -0800542}
543
544// Static.
545std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) {
546 // Parse comma separated nonnegative integers, where some elements may be
547 // empty. The empty values are replaced with -1.
548 // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40}
549 // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1}
550 std::vector<int> result;
551 if (str.empty())
552 return result;
553
554 const char* p = str.c_str();
555 int value = -1;
556 int pos;
557 while (*p) {
558 if (*p == ',') {
559 result.push_back(value);
560 value = -1;
561 ++p;
562 continue;
563 }
564 RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1)
565 << "Unexpected non-number value.";
566 p += pos;
567 }
568 result.push_back(value);
569 return result;
570}
571
572// Static.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100573VideoStream VideoQualityTest::DefaultVideoStream(const Params& params,
574 size_t video_idx) {
sprangce4aef12015-11-02 07:23:20 -0800575 VideoStream stream;
Danil Chapovalov350531e2018-06-08 11:04:04 +0000576 stream.width = params.video[video_idx].width;
577 stream.height = params.video[video_idx].height;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100578 stream.max_framerate = params.video[video_idx].fps;
579 stream.min_bitrate_bps = params.video[video_idx].min_bitrate_bps;
580 stream.target_bitrate_bps = params.video[video_idx].target_bitrate_bps;
581 stream.max_bitrate_bps = params.video[video_idx].max_bitrate_bps;
sprang1168fd42017-06-21 09:00:17 -0700582 stream.max_qp = kDefaultMaxQp;
Sergey Silkina796a7e2018-03-01 15:11:29 +0100583 stream.num_temporal_layers = params.video[video_idx].num_temporal_layers;
Seth Hampson46e31ba2018-01-18 10:39:54 -0800584 stream.active = true;
ilnika014cc52017-03-07 04:21:04 -0800585 return stream;
586}
587
588// Static.
589VideoStream VideoQualityTest::DefaultThumbnailStream() {
590 VideoStream stream;
591 stream.width = 320;
592 stream.height = 180;
593 stream.max_framerate = 7;
594 stream.min_bitrate_bps = 7500;
595 stream.target_bitrate_bps = 37500;
596 stream.max_bitrate_bps = 50000;
sprang1168fd42017-06-21 09:00:17 -0700597 stream.max_qp = kDefaultMaxQp;
sprangce4aef12015-11-02 07:23:20 -0800598 return stream;
599}
600
601// Static.
602void VideoQualityTest::FillScalabilitySettings(
603 Params* params,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100604 size_t video_idx,
sprangce4aef12015-11-02 07:23:20 -0800605 const std::vector<std::string>& stream_descriptors,
sprang1168fd42017-06-21 09:00:17 -0700606 int num_streams,
sprangce4aef12015-11-02 07:23:20 -0800607 size_t selected_stream,
608 int num_spatial_layers,
609 int selected_sl,
Sergey Silkin57027362018-05-15 09:12:05 +0200610 InterLayerPredMode inter_layer_pred,
sprangce4aef12015-11-02 07:23:20 -0800611 const std::vector<std::string>& sl_descriptors) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100612 if (params->ss[video_idx].streams.empty() &&
613 params->ss[video_idx].infer_streams) {
sprang1168fd42017-06-21 09:00:17 -0700614 webrtc::VideoEncoderConfig encoder_config;
Niels Möller259a4972018-04-05 15:36:51 +0200615 encoder_config.codec_type =
616 PayloadStringToCodecType(params->video[video_idx].codec);
sprang1168fd42017-06-21 09:00:17 -0700617 encoder_config.content_type =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100618 params->screenshare[video_idx].enabled
sprang1168fd42017-06-21 09:00:17 -0700619 ? webrtc::VideoEncoderConfig::ContentType::kScreen
620 : webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100621 encoder_config.max_bitrate_bps = params->video[video_idx].max_bitrate_bps;
622 encoder_config.min_transmit_bitrate_bps =
623 params->video[video_idx].min_transmit_bps;
sprang1168fd42017-06-21 09:00:17 -0700624 encoder_config.number_of_streams = num_streams;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100625 encoder_config.spatial_layers = params->ss[video_idx].spatial_layers;
Seth Hampson8234ead2018-02-02 15:16:24 -0800626 encoder_config.simulcast_layers = std::vector<VideoStream>(num_streams);
sprang1168fd42017-06-21 09:00:17 -0700627 encoder_config.video_stream_factory =
628 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100629 params->video[video_idx].codec, kDefaultMaxQp,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100630 params->screenshare[video_idx].enabled, true);
631 params->ss[video_idx].streams =
sprang1168fd42017-06-21 09:00:17 -0700632 encoder_config.video_stream_factory->CreateEncoderStreams(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100633 static_cast<int>(params->video[video_idx].width),
634 static_cast<int>(params->video[video_idx].height), encoder_config);
sprang1168fd42017-06-21 09:00:17 -0700635 } else {
636 // Read VideoStream and SpatialLayer elements from a list of comma separated
637 // lists. To use a default value for an element, use -1 or leave empty.
Artem Titove269cb42018-08-29 09:59:23 +0200638 // Validity checks performed in CheckParamsAndInjectionComponents.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100639 RTC_CHECK(params->ss[video_idx].streams.empty());
Mirko Bonadei739baf02019-01-27 17:29:42 +0100640 for (const auto& descriptor : stream_descriptors) {
sprang1168fd42017-06-21 09:00:17 -0700641 if (descriptor.empty())
642 continue;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100643 VideoStream stream =
644 VideoQualityTest::DefaultVideoStream(*params, video_idx);
sprang1168fd42017-06-21 09:00:17 -0700645 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
646 if (v[0] != -1)
647 stream.width = static_cast<size_t>(v[0]);
648 if (v[1] != -1)
649 stream.height = static_cast<size_t>(v[1]);
650 if (v[2] != -1)
651 stream.max_framerate = v[2];
652 if (v[3] != -1)
653 stream.min_bitrate_bps = v[3];
654 if (v[4] != -1)
655 stream.target_bitrate_bps = v[4];
656 if (v[5] != -1)
657 stream.max_bitrate_bps = v[5];
658 if (v.size() > 6 && v[6] != -1)
659 stream.max_qp = v[6];
Sergey Silkina796a7e2018-03-01 15:11:29 +0100660 if (v.size() > 7 && v[7] != -1) {
661 stream.num_temporal_layers = v[7];
sprang1168fd42017-06-21 09:00:17 -0700662 } else {
663 // Automatic TL thresholds for more than two layers not supported.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100664 RTC_CHECK_LE(params->video[video_idx].num_temporal_layers, 2);
sprang1168fd42017-06-21 09:00:17 -0700665 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100666 params->ss[video_idx].streams.push_back(stream);
sprangce4aef12015-11-02 07:23:20 -0800667 }
sprangce4aef12015-11-02 07:23:20 -0800668 }
sprangce4aef12015-11-02 07:23:20 -0800669
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100670 params->ss[video_idx].num_spatial_layers = std::max(1, num_spatial_layers);
671 params->ss[video_idx].selected_stream = selected_stream;
sprang1168fd42017-06-21 09:00:17 -0700672
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100673 params->ss[video_idx].selected_sl = selected_sl;
Sergey Silkin57027362018-05-15 09:12:05 +0200674 params->ss[video_idx].inter_layer_pred = inter_layer_pred;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100675 RTC_CHECK(params->ss[video_idx].spatial_layers.empty());
Mirko Bonadei739baf02019-01-27 17:29:42 +0100676 for (const auto& descriptor : sl_descriptors) {
sprangce4aef12015-11-02 07:23:20 -0800677 if (descriptor.empty())
678 continue;
679 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
Sergey Silkina89800c2019-02-19 12:52:56 +0100680 RTC_CHECK_EQ(v.size(), 8);
sprangce4aef12015-11-02 07:23:20 -0800681
Sergey Silkin13e74342018-03-02 12:28:00 +0100682 SpatialLayer layer = {0};
683 layer.width = v[0];
684 layer.height = v[1];
Sergey Silkina89800c2019-02-19 12:52:56 +0100685 layer.maxFramerate = v[2];
686 layer.numberOfTemporalLayers = v[3];
687 layer.maxBitrate = v[4];
688 layer.minBitrate = v[5];
689 layer.targetBitrate = v[6];
690 layer.qpMax = v[7];
Sergey Silkin13e74342018-03-02 12:28:00 +0100691 layer.active = true;
692
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100693 params->ss[video_idx].spatial_layers.push_back(layer);
sprangce4aef12015-11-02 07:23:20 -0800694 }
695}
696
minyuea27172d2016-11-01 05:59:29 -0700697void VideoQualityTest::SetupVideo(Transport* send_transport,
698 Transport* recv_transport) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100699 size_t total_streams_used = 0;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100700 video_receive_configs_.clear();
701 video_send_configs_.clear();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100702 video_encoder_configs_.clear();
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100703 bool decode_all_receive_streams = true;
704 size_t num_video_substreams = params_.ss[0].streams.size();
705 RTC_CHECK(num_video_streams_ > 0);
706 video_encoder_configs_.resize(num_video_streams_);
707 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
708 video_send_configs_.push_back(VideoSendStream::Config(send_transport));
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100709 video_encoder_configs_.push_back(VideoEncoderConfig());
710 num_video_substreams = params_.ss[video_idx].streams.size();
711 RTC_CHECK_GT(num_video_substreams, 0);
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200712 for (size_t i = 0; i < num_video_substreams; ++i)
713 video_send_configs_[video_idx].rtp.ssrcs.push_back(
714 kVideoSendSsrcs[total_streams_used + i]);
Qingsi Wang2d82ade2018-07-11 06:04:44 +0000715
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100716 int payload_type;
717 if (params_.video[video_idx].codec == "H264") {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100718 payload_type = kPayloadTypeH264;
719 } else if (params_.video[video_idx].codec == "VP8") {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100720 payload_type = kPayloadTypeVP8;
721 } else if (params_.video[video_idx].codec == "VP9") {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100722 payload_type = kPayloadTypeVP9;
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800723 } else if (params_.video[video_idx].codec == "multiplex") {
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800724 payload_type = kPayloadTypeVP9;
Emircan Uysaler7c03bdc2019-01-16 15:07:56 -0500725 } else if (params_.video[video_idx].codec == "FakeCodec") {
726 payload_type = kFakeVideoSendPayloadType;
ilnikcb8c1462017-03-09 09:23:30 -0800727 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100728 RTC_NOTREACHED() << "Codec not supported!";
729 return;
ilnikcb8c1462017-03-09 09:23:30 -0800730 }
Niels Möller4db138e2018-04-19 09:04:13 +0200731 video_send_configs_[video_idx].encoder_settings.encoder_factory =
Niels Möller88be9722018-10-10 10:58:52 +0200732 (video_idx == 0) ? &video_encoder_factory_with_analyzer_
733 : &video_encoder_factory_;
Jiawei Ouc2ebe212018-11-08 10:02:56 -0800734 video_send_configs_[video_idx].encoder_settings.bitrate_allocator_factory =
735 video_bitrate_allocator_factory_.get();
Niels Möller4db138e2018-04-19 09:04:13 +0200736
Niels Möller259a4972018-04-05 15:36:51 +0200737 video_send_configs_[video_idx].rtp.payload_name =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100738 params_.video[video_idx].codec;
Niels Möller259a4972018-04-05 15:36:51 +0200739 video_send_configs_[video_idx].rtp.payload_type = payload_type;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100740 video_send_configs_[video_idx].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
741 video_send_configs_[video_idx].rtp.rtx.payload_type = kSendRtxPayloadType;
742 for (size_t i = 0; i < num_video_substreams; ++i) {
743 video_send_configs_[video_idx].rtp.rtx.ssrcs.push_back(
744 kSendRtxSsrcs[i + total_streams_used]);
ilnik9fd9f6c2017-03-02 08:10:10 -0800745 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100746 video_send_configs_[video_idx].rtp.extensions.clear();
747 if (params_.call.send_side_bwe) {
philipel569397f2018-09-26 12:25:31 +0200748 video_send_configs_[video_idx].rtp.extensions.emplace_back(
749 RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +0100750 kTransportSequenceNumberExtensionId);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100751 } else {
philipel569397f2018-09-26 12:25:31 +0200752 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alond8d32482019-02-18 23:45:57 +0100753 RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100754 }
philipel569397f2018-09-26 12:25:31 +0200755
756 if (params_.call.generic_descriptor) {
757 // The generic descriptor is currently behind a field trial, so it needs
758 // to be set for this flag to have any effect.
759 // TODO(philipel): Remove this check when the experiment is removed.
760 RTC_CHECK(field_trial::IsEnabled("WebRTC-GenericDescriptor"));
761
762 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alonccb9b752019-02-19 13:01:31 +0100763 RtpExtension::kGenericFrameDescriptorUri00,
764 kGenericFrameDescriptorExtensionId00);
765 video_send_configs_[video_idx].rtp.extensions.emplace_back(
766 RtpExtension::kGenericFrameDescriptorUri01,
767 kGenericFrameDescriptorExtensionId01);
philipel569397f2018-09-26 12:25:31 +0200768 }
769
770 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alond8d32482019-02-18 23:45:57 +0100771 RtpExtension::kVideoContentTypeUri, kVideoContentTypeExtensionId);
philipel569397f2018-09-26 12:25:31 +0200772 video_send_configs_[video_idx].rtp.extensions.emplace_back(
Elad Alond8d32482019-02-18 23:45:57 +0100773 RtpExtension::kVideoTimingUri, kVideoTimingExtensionId);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100774
Niels Möller4db138e2018-04-19 09:04:13 +0200775 video_encoder_configs_[video_idx].video_format.name =
776 params_.video[video_idx].codec;
777
Emircan Uysaler0823eec2018-07-13 17:10:00 -0700778 video_encoder_configs_[video_idx].video_format.parameters =
779 params_.video[video_idx].sdp_params;
780
Niels Möller259a4972018-04-05 15:36:51 +0200781 video_encoder_configs_[video_idx].codec_type =
782 PayloadStringToCodecType(params_.video[video_idx].codec);
783
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100784 video_encoder_configs_[video_idx].min_transmit_bitrate_bps =
785 params_.video[video_idx].min_transmit_bps;
786
787 video_send_configs_[video_idx].suspend_below_min_bitrate =
788 params_.video[video_idx].suspend_below_min_bitrate;
789
790 video_encoder_configs_[video_idx].number_of_streams =
791 params_.ss[video_idx].streams.size();
792 video_encoder_configs_[video_idx].max_bitrate_bps = 0;
793 for (size_t i = 0; i < params_.ss[video_idx].streams.size(); ++i) {
794 video_encoder_configs_[video_idx].max_bitrate_bps +=
795 params_.ss[video_idx].streams[i].max_bitrate_bps;
796 }
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100797 video_encoder_configs_[video_idx].simulcast_layers =
798 std::vector<VideoStream>(params_.ss[video_idx].streams.size());
799 if (!params_.ss[video_idx].infer_streams) {
Seth Hampson8234ead2018-02-02 15:16:24 -0800800 video_encoder_configs_[video_idx].simulcast_layers =
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100801 params_.ss[video_idx].streams;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100802 }
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100803 video_encoder_configs_[video_idx].video_stream_factory =
804 new rtc::RefCountedObject<cricket::EncoderStreamFactory>(
805 params_.video[video_idx].codec,
806 params_.ss[video_idx].streams[0].max_qp,
807 params_.screenshare[video_idx].enabled, true);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100808
809 video_encoder_configs_[video_idx].spatial_layers =
810 params_.ss[video_idx].spatial_layers;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100811 decode_all_receive_streams = params_.ss[video_idx].selected_stream ==
812 params_.ss[video_idx].streams.size();
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200813 absl::optional<int> decode_sub_stream;
814 if (!decode_all_receive_streams)
815 decode_sub_stream = params_.ss[video_idx].selected_stream;
816 CreateMatchingVideoReceiveConfigs(
817 video_send_configs_[video_idx], recv_transport,
Niels Möllercbcbc222018-09-28 09:07:24 +0200818 params_.call.send_side_bwe, &video_decoder_factory_, decode_sub_stream,
819 true, kNackRtpHistoryMs);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100820
821 if (params_.screenshare[video_idx].enabled) {
822 // Fill out codec settings.
823 video_encoder_configs_[video_idx].content_type =
824 VideoEncoderConfig::ContentType::kScreen;
Taylor Brandstetter49fcc102018-05-16 14:20:41 -0700825 degradation_preference_ = DegradationPreference::MAINTAIN_RESOLUTION;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100826 if (params_.video[video_idx].codec == "VP8") {
827 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
828 vp8_settings.denoisingOn = false;
829 vp8_settings.frameDroppingOn = false;
830 vp8_settings.numberOfTemporalLayers = static_cast<unsigned char>(
831 params_.video[video_idx].num_temporal_layers);
832 video_encoder_configs_[video_idx].encoder_specific_settings =
833 new rtc::RefCountedObject<
834 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
835 } else if (params_.video[video_idx].codec == "VP9") {
836 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
837 vp9_settings.denoisingOn = false;
838 vp9_settings.frameDroppingOn = false;
839 vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>(
840 params_.video[video_idx].num_temporal_layers);
841 vp9_settings.numberOfSpatialLayers = static_cast<unsigned char>(
842 params_.ss[video_idx].num_spatial_layers);
Sergey Silkin57027362018-05-15 09:12:05 +0200843 vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred;
Ilya Nikolaevskiy5546aef2018-12-04 15:54:52 +0100844 // High FPS vp9 screenshare requires flexible mode.
845 if (params_.video[video_idx].fps > 5) {
846 vp9_settings.flexibleMode = true;
847 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100848 video_encoder_configs_[video_idx].encoder_specific_settings =
849 new rtc::RefCountedObject<
850 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
851 }
852 } else if (params_.ss[video_idx].num_spatial_layers > 1) {
853 // If SVC mode without screenshare, still need to set codec specifics.
854 RTC_CHECK(params_.video[video_idx].codec == "VP9");
855 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
856 vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>(
857 params_.video[video_idx].num_temporal_layers);
858 vp9_settings.numberOfSpatialLayers =
859 static_cast<unsigned char>(params_.ss[video_idx].num_spatial_layers);
Sergey Silkin57027362018-05-15 09:12:05 +0200860 vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100861 video_encoder_configs_[video_idx].encoder_specific_settings =
862 new rtc::RefCountedObject<
863 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
Niels Möller6aa415e2018-06-07 11:14:13 +0200864 } else if (params_.video[video_idx].automatic_scaling) {
865 if (params_.video[video_idx].codec == "VP8") {
866 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
867 vp8_settings.automaticResizeOn = true;
868 video_encoder_configs_[video_idx].encoder_specific_settings =
869 new rtc::RefCountedObject<
870 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
871 } else if (params_.video[video_idx].codec == "VP9") {
872 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
873 vp9_settings.automaticResizeOn = true;
874 video_encoder_configs_[video_idx].encoder_specific_settings =
875 new rtc::RefCountedObject<
876 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
Stefan Holmer1f7a0082019-01-11 15:39:08 +0100877 } else if (params_.video[video_idx].codec == "H264") {
878 // Quality scaling is always on for H.264.
Niels Möller6aa415e2018-06-07 11:14:13 +0200879 } else {
880 RTC_NOTREACHED() << "Automatic scaling not supported for codec "
Yves Gerey665174f2018-06-19 15:03:05 +0200881 << params_.video[video_idx].codec << ", stream "
882 << video_idx;
Niels Möller6aa415e2018-06-07 11:14:13 +0200883 }
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100884 } else {
885 // Default mode. Single SL, no automatic_scaling,
886 if (params_.video[video_idx].codec == "VP8") {
887 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
888 vp8_settings.automaticResizeOn = false;
889 video_encoder_configs_[video_idx].encoder_specific_settings =
890 new rtc::RefCountedObject<
891 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
892 } else if (params_.video[video_idx].codec == "VP9") {
893 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
894 vp9_settings.automaticResizeOn = false;
895 video_encoder_configs_[video_idx].encoder_specific_settings =
896 new rtc::RefCountedObject<
897 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
898 } else if (params_.video[video_idx].codec == "H264") {
899 VideoCodecH264 h264_settings = VideoEncoder::GetDefaultH264Settings();
900 video_encoder_configs_[video_idx].encoder_specific_settings =
901 new rtc::RefCountedObject<
902 VideoEncoderConfig::H264EncoderSpecificSettings>(h264_settings);
903 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100904 }
905 total_streams_used += num_video_substreams;
sprangce4aef12015-11-02 07:23:20 -0800906 }
brandtr1293aca2016-11-16 22:47:29 -0800907
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100908 // FEC supported only for single video stream mode yet.
909 if (params_.video[0].flexfec) {
sprang1168fd42017-06-21 09:00:17 -0700910 if (decode_all_receive_streams) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200911 SetSendFecConfig(GetVideoSendConfig()->rtp.ssrcs);
sprang1168fd42017-06-21 09:00:17 -0700912 } else {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200913 SetSendFecConfig({kVideoSendSsrcs[params_.ss[0].selected_stream]});
sprang1168fd42017-06-21 09:00:17 -0700914 }
brandtr1293aca2016-11-16 22:47:29 -0800915
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200916 CreateMatchingFecConfig(recv_transport, *GetVideoSendConfig());
917 GetFlexFecConfig()->transport_cc = params_.call.send_side_bwe;
brandtrb29e6522016-12-21 06:37:18 -0800918 if (params_.call.send_side_bwe) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200919 GetFlexFecConfig()->rtp_header_extensions.push_back(
brandtrb29e6522016-12-21 06:37:18 -0800920 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +0100921 kTransportSequenceNumberExtensionId));
brandtrb29e6522016-12-21 06:37:18 -0800922 } else {
Elad Alond8d32482019-02-18 23:45:57 +0100923 GetFlexFecConfig()->rtp_header_extensions.push_back(
924 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId));
brandtrb29e6522016-12-21 06:37:18 -0800925 }
brandtr1293aca2016-11-16 22:47:29 -0800926 }
927
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100928 if (params_.video[0].ulpfec) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200929 SetSendUlpFecConfig(GetVideoSendConfig());
sprang1168fd42017-06-21 09:00:17 -0700930 if (decode_all_receive_streams) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200931 for (auto& receive_config : video_receive_configs_) {
932 SetReceiveUlpFecConfig(&receive_config);
sprang1168fd42017-06-21 09:00:17 -0700933 }
934 } else {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200935 SetReceiveUlpFecConfig(
936 &video_receive_configs_[params_.ss[0].selected_stream]);
sprang1168fd42017-06-21 09:00:17 -0700937 }
brandtr1293aca2016-11-16 22:47:29 -0800938 }
ivica5d6a06c2015-09-17 05:30:24 -0700939}
940
ilnika014cc52017-03-07 04:21:04 -0800941void VideoQualityTest::SetupThumbnails(Transport* send_transport,
942 Transport* recv_transport) {
ilnik98436952017-07-13 00:47:03 -0700943 for (int i = 0; i < params_.call.num_thumbnails; ++i) {
ilnika014cc52017-03-07 04:21:04 -0800944 // Thumbnails will be send in the other way: from receiver_call to
945 // sender_call.
946 VideoSendStream::Config thumbnail_send_config(recv_transport);
947 thumbnail_send_config.rtp.ssrcs.push_back(kThumbnailSendSsrcStart + i);
Niels Möller4db138e2018-04-19 09:04:13 +0200948 // TODO(nisse): Could use a simpler VP8-only encoder factory.
949 thumbnail_send_config.encoder_settings.encoder_factory =
950 &video_encoder_factory_;
Jiawei Ouc2ebe212018-11-08 10:02:56 -0800951 thumbnail_send_config.encoder_settings.bitrate_allocator_factory =
952 video_bitrate_allocator_factory_.get();
Niels Möller259a4972018-04-05 15:36:51 +0200953 thumbnail_send_config.rtp.payload_name = params_.video[0].codec;
954 thumbnail_send_config.rtp.payload_type = kPayloadTypeVP8;
ilnika014cc52017-03-07 04:21:04 -0800955 thumbnail_send_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
956 thumbnail_send_config.rtp.rtx.payload_type = kSendRtxPayloadType;
957 thumbnail_send_config.rtp.rtx.ssrcs.push_back(kThumbnailRtxSsrcStart + i);
958 thumbnail_send_config.rtp.extensions.clear();
959 if (params_.call.send_side_bwe) {
960 thumbnail_send_config.rtp.extensions.push_back(
961 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +0100962 kTransportSequenceNumberExtensionId));
ilnika014cc52017-03-07 04:21:04 -0800963 } else {
Elad Alond8d32482019-02-18 23:45:57 +0100964 thumbnail_send_config.rtp.extensions.push_back(
965 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId));
ilnika014cc52017-03-07 04:21:04 -0800966 }
967
968 VideoEncoderConfig thumbnail_encoder_config;
Niels Möller259a4972018-04-05 15:36:51 +0200969 thumbnail_encoder_config.codec_type = kVideoCodecVP8;
Niels Möller4db138e2018-04-19 09:04:13 +0200970 thumbnail_encoder_config.video_format.name = "VP8";
ilnika014cc52017-03-07 04:21:04 -0800971 thumbnail_encoder_config.min_transmit_bitrate_bps = 7500;
972 thumbnail_send_config.suspend_below_min_bitrate =
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100973 params_.video[0].suspend_below_min_bitrate;
ilnika014cc52017-03-07 04:21:04 -0800974 thumbnail_encoder_config.number_of_streams = 1;
975 thumbnail_encoder_config.max_bitrate_bps = 50000;
Ilya Nikolaevskiy6957abe2019-01-29 16:33:04 +0100976 std::vector<VideoStream> streams{params_.ss[0].streams[0]};
977 thumbnail_encoder_config.video_stream_factory =
978 new rtc::RefCountedObject<VideoStreamFactory>(streams);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +0100979 thumbnail_encoder_config.spatial_layers = params_.ss[0].spatial_layers;
ilnika014cc52017-03-07 04:21:04 -0800980
ilnika014cc52017-03-07 04:21:04 -0800981 thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy());
982 thumbnail_send_configs_.push_back(thumbnail_send_config.Copy());
ilnika014cc52017-03-07 04:21:04 -0800983
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200984 AddMatchingVideoReceiveConfigs(
985 &thumbnail_receive_configs_, thumbnail_send_config, send_transport,
Niels Möllercbcbc222018-09-28 09:07:24 +0200986 params_.call.send_side_bwe, &video_decoder_factory_, absl::nullopt,
987 false, kNackRtpHistoryMs);
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200988 }
989 for (size_t i = 0; i < thumbnail_send_configs_.size(); ++i) {
ilnika014cc52017-03-07 04:21:04 -0800990 thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream(
991 thumbnail_send_configs_[i].Copy(),
992 thumbnail_encoder_configs_[i].Copy()));
Sebastian Jansson3bd2c792018-07-13 13:29:03 +0200993 }
994 for (size_t i = 0; i < thumbnail_receive_configs_.size(); ++i) {
ilnika014cc52017-03-07 04:21:04 -0800995 thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream(
996 thumbnail_receive_configs_[i].Copy()));
997 }
998}
999
1000void VideoQualityTest::DestroyThumbnailStreams() {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001001 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) {
ilnika014cc52017-03-07 04:21:04 -08001002 receiver_call_->DestroyVideoSendStream(thumbnail_send_stream);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001003 }
ilnika014cc52017-03-07 04:21:04 -08001004 thumbnail_send_streams_.clear();
1005 for (VideoReceiveStream* thumbnail_receive_stream :
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001006 thumbnail_receive_streams_) {
ilnika014cc52017-03-07 04:21:04 -08001007 sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001008 }
ilnika014cc52017-03-07 04:21:04 -08001009 thumbnail_send_streams_.clear();
1010 thumbnail_receive_streams_.clear();
Niels Möller1c931c42018-12-18 16:08:11 +01001011 for (std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>& video_capturer :
eladalon413ee9a2017-08-22 04:02:52 -07001012 thumbnail_capturers_) {
Niels Möller1c931c42018-12-18 16:08:11 +01001013 video_capturer.reset();
eladalon413ee9a2017-08-22 04:02:52 -07001014 }
ilnika014cc52017-03-07 04:21:04 -08001015}
1016
ilnika014cc52017-03-07 04:21:04 -08001017void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) {
1018 VideoStream thumbnail = DefaultThumbnailStream();
1019 for (size_t i = 0; i < num_thumbnail_streams; ++i) {
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001020 auto frame_generator_capturer =
1021 absl::make_unique<test::FrameGeneratorCapturer>(
1022 clock_,
1023 test::FrameGenerator::CreateSquareGenerator(
1024 static_cast<int>(thumbnail.width),
1025 static_cast<int>(thumbnail.height), absl::nullopt,
1026 absl::nullopt),
1027 thumbnail.max_framerate, *task_queue_factory_);
1028 EXPECT_TRUE(frame_generator_capturer->Init());
1029 thumbnail_capturers_.push_back(std::move(frame_generator_capturer));
ilnika014cc52017-03-07 04:21:04 -08001030 }
1031}
1032
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001033std::unique_ptr<test::FrameGenerator> VideoQualityTest::CreateFrameGenerator(
1034 size_t video_idx) {
1035 // Setup frame generator.
1036 const size_t kWidth = 1850;
1037 const size_t kHeight = 1110;
1038 std::unique_ptr<test::FrameGenerator> frame_generator;
1039 if (params_.screenshare[video_idx].generate_slides) {
1040 frame_generator = test::FrameGenerator::CreateSlideGenerator(
1041 kWidth, kHeight,
1042 params_.screenshare[video_idx].slide_change_interval *
1043 params_.video[video_idx].fps);
ivica5d6a06c2015-09-17 05:30:24 -07001044 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001045 std::vector<std::string> slides = params_.screenshare[video_idx].slides;
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001046 if (slides.empty()) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001047 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
1048 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
1049 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
1050 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
1051 }
1052 if (params_.screenshare[video_idx].scroll_duration == 0) {
1053 // Cycle image every slide_change_interval seconds.
1054 frame_generator = test::FrameGenerator::CreateFromYuvFile(
1055 slides, kWidth, kHeight,
1056 params_.screenshare[video_idx].slide_change_interval *
1057 params_.video[video_idx].fps);
ivica5d6a06c2015-09-17 05:30:24 -07001058 } else {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001059 RTC_CHECK_LE(params_.video[video_idx].width, kWidth);
1060 RTC_CHECK_LE(params_.video[video_idx].height, kHeight);
1061 RTC_CHECK_GT(params_.screenshare[video_idx].slide_change_interval, 0);
1062 const int kPauseDurationMs =
1063 (params_.screenshare[video_idx].slide_change_interval -
1064 params_.screenshare[video_idx].scroll_duration) *
1065 1000;
1066 RTC_CHECK_LE(params_.screenshare[video_idx].scroll_duration,
1067 params_.screenshare[video_idx].slide_change_interval);
1068
1069 frame_generator = test::FrameGenerator::CreateScrollingInputFromYuvFiles(
1070 clock_, slides, kWidth, kHeight, params_.video[video_idx].width,
1071 params_.video[video_idx].height,
1072 params_.screenshare[video_idx].scroll_duration * 1000,
1073 kPauseDurationMs);
ivica5d6a06c2015-09-17 05:30:24 -07001074 }
1075 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001076 return frame_generator;
1077}
1078
1079void VideoQualityTest::CreateCapturers() {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001080 RTC_DCHECK(video_sources_.empty());
Niels Möller1c931c42018-12-18 16:08:11 +01001081 video_sources_.resize(num_video_streams_);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001082 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001083 std::unique_ptr<test::FrameGenerator> frame_generator;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001084 if (params_.screenshare[video_idx].enabled) {
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001085 frame_generator = CreateFrameGenerator(video_idx);
1086 } else if (params_.video[video_idx].clip_path == "Generator") {
1087 frame_generator = test::FrameGenerator::CreateSquareGenerator(
1088 static_cast<int>(params_.video[video_idx].width),
1089 static_cast<int>(params_.video[video_idx].height), absl::nullopt,
1090 absl::nullopt);
1091 } else if (params_.video[video_idx].clip_path == "GeneratorI420A") {
1092 frame_generator = test::FrameGenerator::CreateSquareGenerator(
1093 static_cast<int>(params_.video[video_idx].width),
1094 static_cast<int>(params_.video[video_idx].height),
1095 test::FrameGenerator::OutputType::I420A, absl::nullopt);
1096 } else if (params_.video[video_idx].clip_path == "GeneratorI010") {
1097 frame_generator = test::FrameGenerator::CreateSquareGenerator(
1098 static_cast<int>(params_.video[video_idx].width),
1099 static_cast<int>(params_.video[video_idx].height),
1100 test::FrameGenerator::OutputType::I010, absl::nullopt);
1101 } else if (params_.video[video_idx].clip_path.empty()) {
1102 video_sources_[video_idx] = test::CreateVideoCapturer(
1103 params_.video[video_idx].width, params_.video[video_idx].height,
1104 params_.video[video_idx].fps,
1105 params_.video[video_idx].capture_device_index);
1106 if (video_sources_[video_idx]) {
1107 continue;
1108 } else {
1109 // Failed to get actual camera, use chroma generator as backup.
1110 frame_generator = test::FrameGenerator::CreateSquareGenerator(
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001111 static_cast<int>(params_.video[video_idx].width),
Danil Chapovalovb9b146c2018-06-15 12:28:07 +02001112 static_cast<int>(params_.video[video_idx].height), absl::nullopt,
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001113 absl::nullopt);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001114 }
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001115 } else {
1116 frame_generator = test::FrameGenerator::CreateFromYuvFile(
1117 {params_.video[video_idx].clip_path}, params_.video[video_idx].width,
1118 params_.video[video_idx].height, 1);
1119 ASSERT_TRUE(frame_generator) << "Could not create capturer for "
1120 << params_.video[video_idx].clip_path
1121 << ".yuv. Is this file present?";
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001122 }
Danil Chapovalov908e22e2019-04-18 14:34:16 +02001123 ASSERT_TRUE(frame_generator);
1124 auto frame_generator_capturer =
1125 absl::make_unique<test::FrameGeneratorCapturer>(
1126 clock_, std::move(frame_generator), params_.video[video_idx].fps,
1127 *task_queue_factory_);
1128 EXPECT_TRUE(frame_generator_capturer->Init());
1129 video_sources_[video_idx] = std::move(frame_generator_capturer);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001130 }
ivica5d6a06c2015-09-17 05:30:24 -07001131}
1132
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001133void VideoQualityTest::StartAudioStreams() {
1134 audio_send_stream_->Start();
1135 for (AudioReceiveStream* audio_recv_stream : audio_receive_streams_)
1136 audio_recv_stream->Start();
1137}
1138
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001139void VideoQualityTest::StartThumbnails() {
1140 for (VideoSendStream* send_stream : thumbnail_send_streams_)
1141 send_stream->Start();
1142 for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_)
1143 receive_stream->Start();
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001144}
1145
1146void VideoQualityTest::StopThumbnails() {
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001147 for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_)
1148 receive_stream->Stop();
1149 for (VideoSendStream* send_stream : thumbnail_send_streams_)
1150 send_stream->Stop();
1151}
1152
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001153std::unique_ptr<test::LayerFilteringTransport>
1154VideoQualityTest::CreateSendTransport() {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001155 std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr;
Artem Titove269cb42018-08-29 09:59:23 +02001156 if (injection_components_->sender_network == nullptr) {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001157 network_behavior = absl::make_unique<SimulatedNetwork>(*params_.config);
Artem Titove269cb42018-08-29 09:59:23 +02001158 } else {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001159 network_behavior = std::move(injection_components_->sender_network);
Artem Titove269cb42018-08-29 09:59:23 +02001160 }
Karl Wiberg918f50c2018-07-05 11:40:33 +02001161 return absl::make_unique<test::LayerFilteringTransport>(
Artem Titov4e199e92018-08-20 13:30:39 +02001162 &task_queue_,
Sebastian Jansson11c012a2019-03-29 14:17:26 +01001163 absl::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)),
Artem Titov4e199e92018-08-20 13:30:39 +02001164 sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9,
1165 params_.video[0].selected_tl, params_.ss[0].selected_sl,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001166 payload_type_map_, kVideoSendSsrcs[0],
1167 static_cast<uint32_t>(kVideoSendSsrcs[0] + params_.ss[0].streams.size() -
1168 1));
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001169}
1170
1171std::unique_ptr<test::DirectTransport>
1172VideoQualityTest::CreateReceiveTransport() {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001173 std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr;
Artem Titove269cb42018-08-29 09:59:23 +02001174 if (injection_components_->receiver_network == nullptr) {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001175 network_behavior = absl::make_unique<SimulatedNetwork>(*params_.config);
Artem Titove269cb42018-08-29 09:59:23 +02001176 } else {
Artem Titov8ea1e9d2018-10-04 14:46:31 +02001177 network_behavior = std::move(injection_components_->receiver_network);
Artem Titove269cb42018-08-29 09:59:23 +02001178 }
Karl Wiberg918f50c2018-07-05 11:40:33 +02001179 return absl::make_unique<test::DirectTransport>(
Artem Titovdd2eebe2018-08-20 13:27:45 +02001180 &task_queue_,
Sebastian Jansson11c012a2019-03-29 14:17:26 +01001181 absl::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)),
Artem Titovdd2eebe2018-08-20 13:27:45 +02001182 receiver_call_.get(), payload_type_map_);
Christoffer Rodbrob4bb4eb2017-11-13 13:03:52 +01001183}
1184
sprang7a975f72015-10-12 06:33:21 -07001185void VideoQualityTest::RunWithAnalyzer(const Params& params) {
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001186 num_video_streams_ = params.call.dual_video ? 2 : 1;
eladalon413ee9a2017-08-22 04:02:52 -07001187 std::unique_ptr<test::LayerFilteringTransport> send_transport;
1188 std::unique_ptr<test::DirectTransport> recv_transport;
1189 FILE* graph_data_output_file = nullptr;
eladalon413ee9a2017-08-22 04:02:52 -07001190
sprangce4aef12015-11-02 07:23:20 -08001191 params_ = params;
ivica5d6a06c2015-09-17 05:30:24 -07001192 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1193 // differentiate between the analyzer and the renderer case.
Artem Titove269cb42018-08-29 09:59:23 +02001194 CheckParamsAndInjectionComponents();
ivica5d6a06c2015-09-17 05:30:24 -07001195
sprangce4aef12015-11-02 07:23:20 -08001196 if (!params_.analyzer.graph_data_output_filename.empty()) {
ivica5d6a06c2015-09-17 05:30:24 -07001197 graph_data_output_file =
sprangce4aef12015-11-02 07:23:20 -08001198 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
Peter Boström74f6e9e2016-04-04 17:56:10 +02001199 RTC_CHECK(graph_data_output_file)
sprangce4aef12015-11-02 07:23:20 -08001200 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1201 << "!";
ivica87f83a92015-10-08 05:13:32 -07001202 }
sprang7a975f72015-10-12 06:33:21 -07001203
ilnik98436952017-07-13 00:47:03 -07001204 if (!params.logging.rtc_event_log_name.empty()) {
Danil Chapovalov304ea5f2019-04-11 15:18:18 +02001205 send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1206 RtcEventLog::EncodingType::Legacy);
1207 recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1208 RtcEventLog::EncodingType::Legacy);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001209 std::unique_ptr<RtcEventLogOutputFile> send_output(
Karl Wiberg918f50c2018-07-05 11:40:33 +02001210 absl::make_unique<RtcEventLogOutputFile>(
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001211 params.logging.rtc_event_log_name + "_send",
1212 RtcEventLog::kUnlimitedOutput));
1213 std::unique_ptr<RtcEventLogOutputFile> recv_output(
Karl Wiberg918f50c2018-07-05 11:40:33 +02001214 absl::make_unique<RtcEventLogOutputFile>(
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001215 params.logging.rtc_event_log_name + "_recv",
1216 RtcEventLog::kUnlimitedOutput));
1217 bool event_log_started =
1218 send_event_log_->StartLogging(std::move(send_output),
1219 RtcEventLog::kImmediateOutput) &&
1220 recv_event_log_->StartLogging(std::move(recv_output),
1221 RtcEventLog::kImmediateOutput);
ilnik98436952017-07-13 00:47:03 -07001222 RTC_DCHECK(event_log_started);
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001223 } else {
1224 send_event_log_ = RtcEventLog::CreateNull();
1225 recv_event_log_ = RtcEventLog::CreateNull();
ilnik98436952017-07-13 00:47:03 -07001226 }
1227
Artem Titovff7730d2019-04-02 13:46:53 +02001228 task_queue_.SendTask([this, &params, &send_transport, &recv_transport]() {
1229 Call::Config send_call_config(send_event_log_.get());
1230 Call::Config recv_call_config(recv_event_log_.get());
1231 send_call_config.bitrate_config = params.call.call_bitrate_config;
1232 recv_call_config.bitrate_config = params.call.call_bitrate_config;
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001233 if (params_.audio.enabled)
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001234 InitializeAudioDevice(&send_call_config, &recv_call_config,
1235 params_.audio.use_real_adm);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001236
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001237 CreateCalls(send_call_config, recv_call_config);
1238 send_transport = CreateSendTransport();
1239 recv_transport = CreateReceiveTransport();
1240 });
stefanf116bd02015-10-27 08:29:42 -07001241
sprangce4aef12015-11-02 07:23:20 -08001242 std::string graph_title = params_.analyzer.graph_title;
1243 if (graph_title.empty())
1244 graph_title = VideoQualityTest::GenerateGraphTitle();
sprangc1b57a12017-02-28 08:50:47 -08001245 bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest");
Niels Möller88be9722018-10-10 10:58:52 +02001246 analyzer_ = absl::make_unique<VideoAnalyzer>(
eladalon413ee9a2017-08-22 04:02:52 -07001247 send_transport.get(), params_.analyzer.test_label,
ilnik2a8c2f52017-02-15 02:23:28 -08001248 params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold,
ilnik9ae0d762017-02-15 00:53:12 -08001249 is_quick_test_enabled
1250 ? kFramesSentInQuickTest
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001251 : params_.analyzer.test_durations_secs * params_.video[0].fps,
sprangce4aef12015-11-02 07:23:20 -08001252 graph_data_output_file, graph_title,
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001253 kVideoSendSsrcs[params_.ss[0].selected_stream],
1254 kSendRtxSsrcs[params_.ss[0].selected_stream],
1255 static_cast<size_t>(params_.ss[0].selected_stream),
1256 params.ss[0].selected_sl, params_.video[0].selected_tl,
Artem Titovff7730d2019-04-02 13:46:53 +02001257 is_quick_test_enabled, clock_, params_.logging.rtp_dump_name,
1258 &task_queue_);
ivica5d6a06c2015-09-17 05:30:24 -07001259
eladalon413ee9a2017-08-22 04:02:52 -07001260 task_queue_.SendTask([&]() {
Niels Möller88be9722018-10-10 10:58:52 +02001261 analyzer_->SetCall(sender_call_.get());
1262 analyzer_->SetReceiver(receiver_call_->Receiver());
1263 send_transport->SetReceiver(analyzer_.get());
eladalon413ee9a2017-08-22 04:02:52 -07001264 recv_transport->SetReceiver(sender_call_->Receiver());
ivica5d6a06c2015-09-17 05:30:24 -07001265
Niels Möller88be9722018-10-10 10:58:52 +02001266 SetupVideo(analyzer_.get(), recv_transport.get());
1267 SetupThumbnails(analyzer_.get(), recv_transport.get());
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001268 video_receive_configs_[params_.ss[0].selected_stream].renderer =
Niels Möller88be9722018-10-10 10:58:52 +02001269 analyzer_.get();
kthelgason2bc68642017-02-07 07:02:22 -08001270
eladalon413ee9a2017-08-22 04:02:52 -07001271 CreateFlexfecStreams();
1272 CreateVideoStreams();
Niels Möller88be9722018-10-10 10:58:52 +02001273 analyzer_->SetSendStream(video_send_streams_[0]);
Ilya Nikolaevskiyd47d3eb2019-01-21 16:27:17 +01001274 analyzer_->SetReceiveStream(
1275 video_receive_streams_[params_.ss[0].selected_stream]);
ivica5d6a06c2015-09-17 05:30:24 -07001276
Niels Möller88be9722018-10-10 10:58:52 +02001277 GetVideoSendStream()->SetSource(analyzer_->OutputInterface(),
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001278 degradation_preference_);
eladalon413ee9a2017-08-22 04:02:52 -07001279 SetupThumbnailCapturers(params_.call.num_thumbnails);
1280 for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) {
1281 thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(),
1282 degradation_preference_);
1283 }
ilnika014cc52017-03-07 04:21:04 -08001284
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001285 CreateCapturers();
ivicac1cc8542015-10-08 03:44:06 -07001286
Stefan Holmer1f7a0082019-01-11 15:39:08 +01001287 analyzer_->SetSource(video_sources_[0].get(), true);
ilnika014cc52017-03-07 04:21:04 -08001288
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001289 for (size_t video_idx = 1; video_idx < num_video_streams_; ++video_idx) {
Niels Möller1c931c42018-12-18 16:08:11 +01001290 video_send_streams_[video_idx]->SetSource(video_sources_[video_idx].get(),
1291 degradation_preference_);
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001292 }
1293
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001294 if (params_.audio.enabled) {
1295 SetupAudio(send_transport.get());
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001296 StartAudioStreams();
Niels Möller88be9722018-10-10 10:58:52 +02001297 analyzer_->SetAudioReceiveStream(audio_receive_streams_[0]);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001298 }
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001299 StartVideoStreams();
1300 StartThumbnails();
Niels Möller88be9722018-10-10 10:58:52 +02001301 analyzer_->StartMeasuringCpuProcessTime();
eladalon413ee9a2017-08-22 04:02:52 -07001302 });
ivica5d6a06c2015-09-17 05:30:24 -07001303
Niels Möller88be9722018-10-10 10:58:52 +02001304 analyzer_->Wait();
ivica5d6a06c2015-09-17 05:30:24 -07001305
eladalon413ee9a2017-08-22 04:02:52 -07001306 task_queue_.SendTask([&]() {
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001307 StopThumbnails();
1308 Stop();
ivica5d6a06c2015-09-17 05:30:24 -07001309
eladalon413ee9a2017-08-22 04:02:52 -07001310 DestroyStreams();
1311 DestroyThumbnailStreams();
ivica5d6a06c2015-09-17 05:30:24 -07001312
eladalon413ee9a2017-08-22 04:02:52 -07001313 if (graph_data_output_file)
1314 fclose(graph_data_output_file);
1315
Niels Möller1c931c42018-12-18 16:08:11 +01001316 video_sources_.clear();
eladalon413ee9a2017-08-22 04:02:52 -07001317 send_transport.reset();
1318 recv_transport.reset();
1319
1320 DestroyCalls();
1321 });
Niels Möller88be9722018-10-10 10:58:52 +02001322 analyzer_ = nullptr;
ivica5d6a06c2015-09-17 05:30:24 -07001323}
1324
henrika255750b2018-08-27 16:13:37 +02001325rtc::scoped_refptr<AudioDeviceModule> VideoQualityTest::CreateAudioDevice() {
1326#ifdef WEBRTC_WIN
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001327 RTC_LOG(INFO) << "Using latest version of ADM on Windows";
1328 // We must initialize the COM library on a thread before we calling any of
1329 // the library functions. All COM functions in the ADM will return
1330 // CO_E_NOTINITIALIZED otherwise. The legacy ADM for Windows used internal
1331 // COM initialization but the new ADM requires COM to be initialized
1332 // externally.
1333 com_initializer_ = absl::make_unique<webrtc_win::ScopedCOMInitializer>(
1334 webrtc_win::ScopedCOMInitializer::kMTA);
1335 RTC_CHECK(com_initializer_->Succeeded());
1336 RTC_CHECK(webrtc_win::core_audio_utility::IsSupported());
1337 RTC_CHECK(webrtc_win::core_audio_utility::IsMMCSSSupported());
Danil Chapovalov1c41be62019-04-01 09:16:12 +02001338 return CreateWindowsCoreAudioAudioDeviceModule(task_queue_factory_.get());
henrika255750b2018-08-27 16:13:37 +02001339#else
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001340 // Use legacy factory method on all platforms except Windows.
Danil Chapovalov1c41be62019-04-01 09:16:12 +02001341 return AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio,
1342 task_queue_factory_.get());
henrika255750b2018-08-27 16:13:37 +02001343#endif
1344}
1345
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001346void VideoQualityTest::InitializeAudioDevice(Call::Config* send_call_config,
henrika255750b2018-08-27 16:13:37 +02001347 Call::Config* recv_call_config,
1348 bool use_real_adm) {
1349 rtc::scoped_refptr<AudioDeviceModule> audio_device;
1350 if (use_real_adm) {
1351 // Run test with real ADM (using default audio devices) if user has
1352 // explicitly set the --audio and --use_real_adm command-line flags.
1353 audio_device = CreateAudioDevice();
1354 } else {
1355 // By default, create a test ADM which fakes audio.
1356 audio_device = TestAudioDeviceModule::CreateTestAudioDeviceModule(
1357 TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, 48000),
1358 TestAudioDeviceModule::CreateDiscardRenderer(48000), 1.f);
1359 }
1360 RTC_CHECK(audio_device);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001361
1362 AudioState::Config audio_state_config;
1363 audio_state_config.audio_mixer = AudioMixerImpl::Create();
1364 audio_state_config.audio_processing = AudioProcessingBuilder().Create();
henrika255750b2018-08-27 16:13:37 +02001365 audio_state_config.audio_device_module = audio_device;
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001366 send_call_config->audio_state = AudioState::Create(audio_state_config);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001367 recv_call_config->audio_state = AudioState::Create(audio_state_config);
henrika255750b2018-08-27 16:13:37 +02001368 if (use_real_adm) {
1369 // The real ADM requires extra initialization: setting default devices,
1370 // setting up number of channels etc. Helper class also calls
1371 // AudioDeviceModule::Init().
1372 webrtc::adm_helpers::Init(audio_device.get());
1373 } else {
1374 audio_device->Init();
1375 }
1376 // Always initialize the ADM before injecting a valid audio transport.
1377 RTC_CHECK(audio_device->RegisterAudioCallback(
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001378 send_call_config->audio_state->audio_transport()) == 0);
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001379}
1380
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001381void VideoQualityTest::SetupAudio(Transport* transport) {
Niels Möller7d76a312018-10-26 12:57:07 +02001382 AudioSendStream::Config audio_send_config(transport,
1383 /*media_transport=*/nullptr);
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001384 audio_send_config.rtp.ssrc = kAudioSendSsrc;
minyuea27172d2016-11-01 05:59:29 -07001385
1386 // Add extension to enable audio send side BWE, and allow audio bit rate
1387 // adaptation.
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001388 audio_send_config.rtp.extensions.clear();
1389 audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec(
Oskar Sundbom8e07c132018-01-08 16:45:42 +01001390 kAudioSendPayloadType,
Yves Gerey665174f2018-06-19 15:03:05 +02001391 {"OPUS",
1392 48000,
1393 2,
1394 {{"usedtx", (params_.audio.dtx ? "1" : "0")}, {"stereo", "1"}}});
minyuea27172d2016-11-01 05:59:29 -07001395
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001396 if (params_.call.send_side_bwe) {
1397 audio_send_config.rtp.extensions.push_back(
1398 webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri,
Elad Alond8d32482019-02-18 23:45:57 +01001399 kTransportSequenceNumberExtensionId));
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001400 audio_send_config.min_bitrate_bps = kOpusMinBitrateBps;
1401 audio_send_config.max_bitrate_bps = kOpusBitrateFbBps;
1402 audio_send_config.send_codec_spec->transport_cc_enabled = true;
Minyue Li455d27c2019-01-07 13:14:30 +01001403 // Only allow ANA when send-side BWE is enabled.
1404 audio_send_config.audio_network_adaptor_config = params_.audio.ana_config;
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001405 }
1406 audio_send_config.encoder_factory = audio_encoder_factory_;
1407 SetAudioConfig(audio_send_config);
1408
Christoffer Rodbroc2a02882018-08-07 14:10:56 +02001409 std::string sync_group;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001410 if (params_.video[0].enabled && params_.audio.sync_video)
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001411 sync_group = kSyncGroup;
minyuea27172d2016-11-01 05:59:29 -07001412
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001413 CreateMatchingAudioConfigs(transport, sync_group);
1414 CreateAudioStreams();
minyuea27172d2016-11-01 05:59:29 -07001415}
1416
minyue73208662016-08-18 06:28:55 -07001417void VideoQualityTest::RunWithRenderers(const Params& params) {
henrika255750b2018-08-27 16:13:37 +02001418 RTC_LOG(INFO) << __FUNCTION__;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001419 num_video_streams_ = params.call.dual_video ? 2 : 1;
eladalon413ee9a2017-08-22 04:02:52 -07001420 std::unique_ptr<test::LayerFilteringTransport> send_transport;
1421 std::unique_ptr<test::DirectTransport> recv_transport;
minyuea27172d2016-11-01 05:59:29 -07001422 std::unique_ptr<test::VideoRenderer> local_preview;
eladalon413ee9a2017-08-22 04:02:52 -07001423 std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers;
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001424
1425 if (!params.logging.rtc_event_log_name.empty()) {
Danil Chapovalov304ea5f2019-04-11 15:18:18 +02001426 send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1427 RtcEventLog::EncodingType::Legacy);
1428 recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog(
1429 RtcEventLog::EncodingType::Legacy);
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001430 std::unique_ptr<RtcEventLogOutputFile> send_output(
1431 absl::make_unique<RtcEventLogOutputFile>(
1432 params.logging.rtc_event_log_name + "_send",
1433 RtcEventLog::kUnlimitedOutput));
1434 std::unique_ptr<RtcEventLogOutputFile> recv_output(
1435 absl::make_unique<RtcEventLogOutputFile>(
1436 params.logging.rtc_event_log_name + "_recv",
1437 RtcEventLog::kUnlimitedOutput));
1438 bool event_log_started =
1439 send_event_log_->StartLogging(std::move(send_output),
1440 /*output_period_ms=*/5000) &&
1441 recv_event_log_->StartLogging(std::move(recv_output),
1442 /*output_period_ms=*/5000);
1443 RTC_DCHECK(event_log_started);
1444 } else {
1445 send_event_log_ = RtcEventLog::CreateNull();
1446 recv_event_log_ = RtcEventLog::CreateNull();
1447 }
minyue73208662016-08-18 06:28:55 -07001448
eladalon413ee9a2017-08-22 04:02:52 -07001449 task_queue_.SendTask([&]() {
1450 params_ = params;
Artem Titove269cb42018-08-29 09:59:23 +02001451 CheckParamsAndInjectionComponents();
palmkviste75f2042016-09-28 06:19:48 -07001452
eladalon413ee9a2017-08-22 04:02:52 -07001453 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
1454 // match the full stack tests.
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001455 Call::Config send_call_config(send_event_log_.get());
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001456 send_call_config.bitrate_config = params_.call.call_bitrate_config;
Ilya Nikolaevskiy42e7d9c2018-11-02 13:14:37 +01001457 Call::Config recv_call_config(recv_event_log_.get());
ivica5d6a06c2015-09-17 05:30:24 -07001458
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001459 if (params_.audio.enabled)
Benjamin Wright1f4173e2019-03-13 17:59:32 -07001460 InitializeAudioDevice(&send_call_config, &recv_call_config,
1461 params_.audio.use_real_adm);
minyue73208662016-08-18 06:28:55 -07001462
Christoffer Rodbro39a44b22018-08-07 17:07:24 +02001463 CreateCalls(send_call_config, recv_call_config);
eladalon413ee9a2017-08-22 04:02:52 -07001464
1465 // TODO(minyue): consider if this is a good transport even for audio only
1466 // calls.
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001467 send_transport = CreateSendTransport();
eladalon413ee9a2017-08-22 04:02:52 -07001468
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001469 recv_transport = CreateReceiveTransport();
eladalon413ee9a2017-08-22 04:02:52 -07001470
1471 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
1472 // least share as much code as possible. That way this test would also match
1473 // the full stack tests better.
1474 send_transport->SetReceiver(receiver_call_->Receiver());
1475 recv_transport->SetReceiver(sender_call_->Receiver());
1476
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001477 if (params_.video[0].enabled) {
eladalon413ee9a2017-08-22 04:02:52 -07001478 // Create video renderers.
eladalon413ee9a2017-08-22 04:02:52 -07001479 SetupVideo(send_transport.get(), recv_transport.get());
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001480 size_t num_streams_processed = 0;
1481 for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
1482 const size_t selected_stream_id = params_.ss[video_idx].selected_stream;
1483 const size_t num_streams = params_.ss[video_idx].streams.size();
1484 if (selected_stream_id == num_streams) {
1485 for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) {
Jonas Olsson366a50c2018-09-06 13:41:30 +02001486 rtc::StringBuilder oss;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001487 oss << "Loopback Video #" << video_idx << " - Stream #"
1488 << static_cast<int>(stream_id);
1489 loopback_renderers.emplace_back(test::VideoRenderer::Create(
1490 oss.str().c_str(),
1491 params_.ss[video_idx].streams[stream_id].width,
1492 params_.ss[video_idx].streams[stream_id].height));
1493 video_receive_configs_[stream_id + num_streams_processed].renderer =
1494 loopback_renderers.back().get();
1495 if (params_.audio.enabled && params_.audio.sync_video)
1496 video_receive_configs_[stream_id + num_streams_processed]
1497 .sync_group = kSyncGroup;
1498 }
1499 } else {
Jonas Olsson366a50c2018-09-06 13:41:30 +02001500 rtc::StringBuilder oss;
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001501 oss << "Loopback Video #" << video_idx;
1502 loopback_renderers.emplace_back(test::VideoRenderer::Create(
1503 oss.str().c_str(),
1504 params_.ss[video_idx].streams[selected_stream_id].width,
1505 params_.ss[video_idx].streams[selected_stream_id].height));
1506 video_receive_configs_[selected_stream_id + num_streams_processed]
1507 .renderer = loopback_renderers.back().get();
eladalon413ee9a2017-08-22 04:02:52 -07001508 if (params_.audio.enabled && params_.audio.sync_video)
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001509 video_receive_configs_[num_streams_processed + selected_stream_id]
1510 .sync_group = kSyncGroup;
eladalon413ee9a2017-08-22 04:02:52 -07001511 }
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001512 num_streams_processed += num_streams;
eladalon413ee9a2017-08-22 04:02:52 -07001513 }
eladalon413ee9a2017-08-22 04:02:52 -07001514 CreateFlexfecStreams();
1515 CreateVideoStreams();
1516
Ilya Nikolaevskiy255d1cd2017-12-21 18:02:59 +01001517 CreateCapturers();
Niels Möller412d1852019-01-02 09:42:54 +01001518 if (params_.video[0].enabled) {
1519 // Create local preview
1520 local_preview.reset(test::VideoRenderer::Create(
1521 "Local Preview", params_.video[0].width, params_.video[0].height));
1522
1523 video_sources_[0]->AddOrUpdateSink(local_preview.get(),
1524 rtc::VideoSinkWants());
1525 }
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001526 ConnectVideoSourcesToStreams();
eladalon413ee9a2017-08-22 04:02:52 -07001527 }
1528
1529 if (params_.audio.enabled) {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001530 SetupAudio(send_transport.get());
eladalon413ee9a2017-08-22 04:02:52 -07001531 }
1532
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001533 Start();
eladalon413ee9a2017-08-22 04:02:52 -07001534 });
minyue73208662016-08-18 06:28:55 -07001535
Danail Kirov6fcf6ca2018-10-25 10:45:47 -07001536 test::PressEnterToContinue(task_queue_);
ivica5d6a06c2015-09-17 05:30:24 -07001537
eladalon413ee9a2017-08-22 04:02:52 -07001538 task_queue_.SendTask([&]() {
Sebastian Jansson3bd2c792018-07-13 13:29:03 +02001539 Stop();
1540 DestroyStreams();
minyue73208662016-08-18 06:28:55 -07001541
Niels Möller1c931c42018-12-18 16:08:11 +01001542 video_sources_.clear();
eladalon413ee9a2017-08-22 04:02:52 -07001543 send_transport.reset();
1544 recv_transport.reset();
sprang1168fd42017-06-21 09:00:17 -07001545
eladalon413ee9a2017-08-22 04:02:52 -07001546 local_preview.reset();
1547 loopback_renderers.clear();
1548
1549 DestroyCalls();
1550 });
ivica5d6a06c2015-09-17 05:30:24 -07001551}
1552
ivica5d6a06c2015-09-17 05:30:24 -07001553} // namespace webrtc