ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "video/video_quality_test.h" |
perkj | 9fdbda6 | 2016-09-15 09:19:20 -0700 | [diff] [blame] | 11 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 12 | #include <stdio.h> |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | #include <deque> |
| 15 | #include <map> |
mflodman | d1590b2 | 2015-12-09 07:07:59 -0800 | [diff] [blame] | 16 | #include <string> |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 19 | #include "absl/memory/memory.h" |
Niels Möller | d8b9ed7 | 2019-05-08 13:53:51 +0200 | [diff] [blame^] | 20 | #include "api/rtc_event_log_output_file.h" |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 21 | #include "api/task_queue/default_task_queue_factory.h" |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 22 | #include "api/video/builtin_video_bitrate_allocator_factory.h" |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 23 | #include "call/fake_network_pipe.h" |
| 24 | #include "call/simulated_network.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 25 | #include "media/engine/adm_helpers.h" |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 26 | #include "media/engine/encoder_simulcast_proxy.h" |
Emircan Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 27 | #include "media/engine/fake_video_codec_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "media/engine/internal_encoder_factory.h" |
| 29 | #include "media/engine/webrtc_video_engine.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 30 | #include "modules/audio_device/include/audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "modules/audio_mixer/audio_mixer_impl.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "modules/video_coding/codecs/h264/include/h264.h" |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 33 | #include "modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h" |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 34 | #include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h" |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 35 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "modules/video_coding/codecs/vp9/include/vp9.h" |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 37 | #include "modules/video_coding/utility/ivf_file_writer.h" |
| 38 | #include "rtc_base/strings/string_builder.h" |
Kári Tristan Helgason | ede7cb2 | 2019-03-06 10:34:09 +0100 | [diff] [blame] | 39 | #include "test/platform_video_capturer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 40 | #include "test/run_loop.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 41 | #include "test/testsupport/file_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 42 | #include "test/video_renderer.h" |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 43 | #include "video/frame_dumping_decoder.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 44 | #ifdef WEBRTC_WIN |
| 45 | #include "modules/audio_device/include/audio_device_factory.h" |
| 46 | #endif |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 47 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 48 | namespace webrtc { |
| 49 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 50 | namespace { |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 51 | enum : int { // The first valid value is 1. |
| 52 | kAbsSendTimeExtensionId = 1, |
Elad Alon | ccb9b75 | 2019-02-19 13:01:31 +0100 | [diff] [blame] | 53 | kGenericFrameDescriptorExtensionId00, |
| 54 | kGenericFrameDescriptorExtensionId01, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 55 | kTransportSequenceNumberExtensionId, |
| 56 | kVideoContentTypeExtensionId, |
| 57 | kVideoTimingExtensionId, |
| 58 | }; |
| 59 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 60 | constexpr char kSyncGroup[] = "av_sync"; |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 61 | constexpr int kOpusMinBitrateBps = 6000; |
| 62 | constexpr int kOpusBitrateFbBps = 32000; |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 63 | constexpr int kFramesSentInQuickTest = 1; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 64 | constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000; |
| 65 | constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 66 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 67 | constexpr int kDefaultMaxQp = cricket::WebRtcVideoChannel::kDefaultQpMax; |
| 68 | |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 69 | std::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 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 90 | class VideoStreamFactory |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 91 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 92 | public: |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 93 | explicit VideoStreamFactory(const std::vector<VideoStream>& streams) |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 94 | : streams_(streams) {} |
| 95 | |
| 96 | private: |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 97 | std::vector<VideoStream> CreateEncoderStreams( |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 98 | int width, |
| 99 | int height, |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 100 | const VideoEncoderConfig& encoder_config) override { |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 101 | // The highest layer must match the incoming resolution. |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 102 | std::vector<VideoStream> streams = streams_; |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 103 | streams[streams_.size() - 1].height = height; |
| 104 | streams[streams_.size() - 1].width = width; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 105 | |
| 106 | streams[0].bitrate_priority = encoder_config.bitrate_priority; |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 107 | return streams; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 110 | std::vector<VideoStream> streams_; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 111 | }; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 112 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 113 | // 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. |
| 116 | class QualityTestVideoEncoder : public VideoEncoder, |
| 117 | private EncodedImageCallback { |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 118 | public: |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 119 | QualityTestVideoEncoder(std::unique_ptr<VideoEncoder> encoder, |
| 120 | VideoAnalyzer* analyzer, |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 121 | std::vector<FileWrapper> files, |
| 122 | double overshoot_factor) |
| 123 | : encoder_(std::move(encoder)), |
| 124 | overshoot_factor_(overshoot_factor), |
| 125 | analyzer_(analyzer) { |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 126 | for (FileWrapper& file : files) { |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 127 | writers_.push_back( |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 128 | IvfFileWriter::Wrap(std::move(file), /* byte_limit= */ 100000000)); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 129 | } |
| 130 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 131 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 132 | // 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ång | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 136 | codec_settings_ = *codec_settings; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 137 | return encoder_->InitEncode(codec_settings, number_of_cores, |
| 138 | max_payload_size); |
| 139 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 140 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 141 | int32_t RegisterEncodeCompleteCallback( |
| 142 | EncodedImageCallback* callback) override { |
| 143 | callback_ = callback; |
| 144 | return encoder_->RegisterEncodeCompleteCallback(this); |
| 145 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 146 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 147 | int32_t Release() override { return encoder_->Release(); } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 148 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 149 | int32_t Encode(const VideoFrame& frame, |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 150 | const std::vector<VideoFrameType>* frame_types) { |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 151 | if (analyzer_) { |
| 152 | analyzer_->PreEncodeOnFrame(frame); |
| 153 | } |
Niels Möller | c8d2e73 | 2019-03-06 12:00:33 +0100 | [diff] [blame] | 154 | return encoder_->Encode(frame, frame_types); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 155 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 156 | |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 157 | void SetRates(const RateControlParameters& parameters) override { |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 158 | RTC_DCHECK_GT(overshoot_factor_, 0.0); |
| 159 | if (overshoot_factor_ == 1.0) { |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 160 | encoder_->SetRates(parameters); |
| 161 | return; |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 162 | } |
| 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ång | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 170 | parameters.bitrate.GetSpatialLayerSum(si); |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 171 | 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ång | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 189 | if (parameters.bitrate.HasBitrate(si, ti)) { |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 190 | overshot_allocation.SetBitrate( |
| 191 | si, ti, |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 192 | rtc::checked_cast<uint32_t>( |
| 193 | overshoot_factor * parameters.bitrate.GetBitrate(si, ti))); |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 198 | return encoder_->SetRates( |
| 199 | RateControlParameters(overshot_allocation, parameters.framerate_fps, |
| 200 | parameters.bandwidth_allocation)); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 201 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 202 | |
| 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ång | 189013b | 2018-11-01 15:03:57 +0100 | [diff] [blame] | 213 | EncoderInfo GetEncoderInfo() const override { |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 214 | 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öller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 221 | } |
| 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öller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 236 | if (analyzer_) { |
| 237 | analyzer_->PostEncodeOnFrame(simulcast_index, |
| 238 | encoded_image.Timestamp()); |
| 239 | } |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 240 | 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ång | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 254 | const std::unique_ptr<VideoEncoder> encoder_; |
| 255 | const double overshoot_factor_; |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 256 | VideoAnalyzer* const analyzer_; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 257 | std::vector<std::unique_ptr<IvfFileWriter>> writers_; |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 258 | EncodedImageCallback* callback_ = nullptr; |
| 259 | VideoCodec codec_settings_; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | } // namespace |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 263 | |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 264 | std::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 Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 270 | } else if (format.name == "FakeCodec") { |
| 271 | decoder = webrtc::FakeVideoDecoderFactory::CreateVideoDecoder(); |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 272 | } else { |
| 273 | decoder = internal_decoder_factory_.CreateVideoDecoder(format); |
| 274 | } |
Niels Möller | 5ca2912 | 2018-10-02 09:55:01 +0200 | [diff] [blame] | 275 | 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öller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 281 | std::move(decoder), FileWrapper::OpenWriteOnly(path)); |
Niels Möller | 5ca2912 | 2018-10-02 09:55:01 +0200 | [diff] [blame] | 282 | } |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 283 | return decoder; |
| 284 | } |
| 285 | |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 286 | std::unique_ptr<VideoEncoder> VideoQualityTest::CreateVideoEncoder( |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 287 | const SdpVideoFormat& format, |
| 288 | VideoAnalyzer* analyzer) { |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 289 | std::unique_ptr<VideoEncoder> encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 290 | if (format.name == "VP8") { |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 291 | encoder = absl::make_unique<EncoderSimulcastProxy>( |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 292 | &internal_encoder_factory_, format); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 293 | } else if (format.name == "multiplex") { |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 294 | encoder = absl::make_unique<MultiplexEncoderAdapter>( |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 295 | &internal_encoder_factory_, SdpVideoFormat(cricket::kVp9CodecName)); |
Emircan Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 296 | } else if (format.name == "FakeCodec") { |
| 297 | encoder = webrtc::FakeVideoEncoderFactory::CreateVideoEncoder(); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 298 | } else { |
| 299 | encoder = internal_encoder_factory_.CreateVideoEncoder(format); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 300 | } |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 301 | |
| 302 | std::vector<FileWrapper> encoded_frame_dump_files; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 303 | 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ång | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 309 | 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öller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 316 | |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 317 | 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öller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 334 | encoder = absl::make_unique<QualityTestVideoEncoder>( |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 335 | std::move(encoder), analyzer, std::move(encoded_frame_dump_files), |
| 336 | overshoot_factor); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 337 | } |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 338 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 339 | return encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 342 | VideoQualityTest::VideoQualityTest( |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 343 | std::unique_ptr<InjectionComponents> injection_components) |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 344 | : clock_(Clock::GetRealTimeClock()), |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 345 | task_queue_factory_(CreateDefaultTaskQueueFactory()), |
Danil Chapovalov | 304ea5f | 2019-04-11 15:18:18 +0200 | [diff] [blame] | 346 | rtc_event_log_factory_(task_queue_factory_.get()), |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 347 | video_decoder_factory_([this](const SdpVideoFormat& format) { |
| 348 | return this->CreateVideoDecoder(format); |
| 349 | }), |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 350 | video_encoder_factory_([this](const SdpVideoFormat& format) { |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 351 | return this->CreateVideoEncoder(format, nullptr); |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 352 | }), |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 353 | video_encoder_factory_with_analyzer_( |
| 354 | [this](const SdpVideoFormat& format) { |
| 355 | return this->CreateVideoEncoder(format, analyzer_.get()); |
| 356 | }), |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 357 | video_bitrate_allocator_factory_( |
| 358 | CreateBuiltinVideoBitrateAllocatorFactory()), |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 359 | receive_logs_(0), |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 360 | send_logs_(0), |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 361 | injection_components_(std::move(injection_components)), |
| 362 | num_video_streams_(0) { |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 363 | if (injection_components_ == nullptr) { |
| 364 | injection_components_ = absl::make_unique<InjectionComponents>(); |
| 365 | } |
| 366 | |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 367 | 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; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 377 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 378 | fec_controller_factory_ = |
| 379 | std::move(injection_components_->fec_controller_factory); |
Ying Wang | cab77fd | 2019-04-16 11:12:49 +0200 | [diff] [blame] | 380 | network_state_predictor_factory_ = |
| 381 | std::move(injection_components_->network_state_predictor_factory); |
Sebastian Jansson | 1391ed2 | 2019-04-30 14:23:51 +0200 | [diff] [blame] | 382 | network_controller_factory_ = |
| 383 | std::move(injection_components_->network_controller_factory); |
Ying Wang | 3b790f3 | 2018-01-19 17:58:57 +0100 | [diff] [blame] | 384 | } |
| 385 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 386 | VideoQualityTest::Params::Params() |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 387 | : call({false, false, BitrateConstraints(), 0}), |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 388 | 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}}, |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 426 | audio({false, false, false, false}), |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 427 | screenshare{{false, false, 10, 0}, {false, false, 10, 0}}, |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 428 | analyzer({"", 0.0, 0.0, 0, "", ""}), |
Artem Titov | f18b352 | 2018-08-28 16:54:24 +0200 | [diff] [blame] | 429 | config(absl::nullopt), |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 430 | 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 Bonadei | 45a4c41 | 2018-07-31 15:07:28 +0200 | [diff] [blame] | 434 | logging({"", "", ""}) {} |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 435 | |
| 436 | VideoQualityTest::Params::~Params() = default; |
| 437 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 438 | VideoQualityTest::InjectionComponents::InjectionComponents() = default; |
| 439 | |
| 440 | VideoQualityTest::InjectionComponents::~InjectionComponents() = default; |
| 441 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 442 | void VideoQualityTest::TestBody() {} |
| 443 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 444 | std::string VideoQualityTest::GenerateGraphTitle() const { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 445 | rtc::StringBuilder ss; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 446 | 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; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 455 | ss << ")"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 456 | return ss.Release(); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 459 | void 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 Titov | 62ae178 | 2018-10-24 14:14:49 +0200 | [diff] [blame] | 465 | params_.config = BuiltInNetworkBehaviorConfig(); |
Artem Titov | f18b352 | 2018-08-28 16:54:24 +0200 | [diff] [blame] | 466 | } |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 467 | 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 472 | 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; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 482 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 483 | 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 496 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 497 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 498 | // 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 Nikolaevskiy | aec663e | 2019-02-27 12:52:11 +0100 | [diff] [blame] | 504 | 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 509 | 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); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 541 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | // Static. |
| 545 | std::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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 573 | VideoStream VideoQualityTest::DefaultVideoStream(const Params& params, |
| 574 | size_t video_idx) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 575 | VideoStream stream; |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 576 | stream.width = params.video[video_idx].width; |
| 577 | stream.height = params.video[video_idx].height; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 578 | 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; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 582 | stream.max_qp = kDefaultMaxQp; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 583 | stream.num_temporal_layers = params.video[video_idx].num_temporal_layers; |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 584 | stream.active = true; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 585 | return stream; |
| 586 | } |
| 587 | |
| 588 | // Static. |
| 589 | VideoStream 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; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 597 | stream.max_qp = kDefaultMaxQp; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 598 | return stream; |
| 599 | } |
| 600 | |
| 601 | // Static. |
| 602 | void VideoQualityTest::FillScalabilitySettings( |
| 603 | Params* params, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 604 | size_t video_idx, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 605 | const std::vector<std::string>& stream_descriptors, |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 606 | int num_streams, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 607 | size_t selected_stream, |
| 608 | int num_spatial_layers, |
| 609 | int selected_sl, |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 610 | InterLayerPredMode inter_layer_pred, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 611 | const std::vector<std::string>& sl_descriptors) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 612 | if (params->ss[video_idx].streams.empty() && |
| 613 | params->ss[video_idx].infer_streams) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 614 | webrtc::VideoEncoderConfig encoder_config; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 615 | encoder_config.codec_type = |
| 616 | PayloadStringToCodecType(params->video[video_idx].codec); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 617 | encoder_config.content_type = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 618 | params->screenshare[video_idx].enabled |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 619 | ? webrtc::VideoEncoderConfig::ContentType::kScreen |
| 620 | : webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 621 | 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; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 624 | encoder_config.number_of_streams = num_streams; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 625 | encoder_config.spatial_layers = params->ss[video_idx].spatial_layers; |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 626 | encoder_config.simulcast_layers = std::vector<VideoStream>(num_streams); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 627 | encoder_config.video_stream_factory = |
| 628 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 629 | params->video[video_idx].codec, kDefaultMaxQp, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 630 | params->screenshare[video_idx].enabled, true); |
| 631 | params->ss[video_idx].streams = |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 632 | encoder_config.video_stream_factory->CreateEncoderStreams( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 633 | static_cast<int>(params->video[video_idx].width), |
| 634 | static_cast<int>(params->video[video_idx].height), encoder_config); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 635 | } 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 Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 638 | // Validity checks performed in CheckParamsAndInjectionComponents. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 639 | RTC_CHECK(params->ss[video_idx].streams.empty()); |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 640 | for (const auto& descriptor : stream_descriptors) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 641 | if (descriptor.empty()) |
| 642 | continue; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 643 | VideoStream stream = |
| 644 | VideoQualityTest::DefaultVideoStream(*params, video_idx); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 645 | 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 Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 660 | if (v.size() > 7 && v[7] != -1) { |
| 661 | stream.num_temporal_layers = v[7]; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 662 | } else { |
| 663 | // Automatic TL thresholds for more than two layers not supported. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 664 | RTC_CHECK_LE(params->video[video_idx].num_temporal_layers, 2); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 665 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 666 | params->ss[video_idx].streams.push_back(stream); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 667 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 668 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 669 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 670 | params->ss[video_idx].num_spatial_layers = std::max(1, num_spatial_layers); |
| 671 | params->ss[video_idx].selected_stream = selected_stream; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 672 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 673 | params->ss[video_idx].selected_sl = selected_sl; |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 674 | params->ss[video_idx].inter_layer_pred = inter_layer_pred; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 675 | RTC_CHECK(params->ss[video_idx].spatial_layers.empty()); |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 676 | for (const auto& descriptor : sl_descriptors) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 677 | if (descriptor.empty()) |
| 678 | continue; |
| 679 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
Sergey Silkin | a89800c | 2019-02-19 12:52:56 +0100 | [diff] [blame] | 680 | RTC_CHECK_EQ(v.size(), 8); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 681 | |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 682 | SpatialLayer layer = {0}; |
| 683 | layer.width = v[0]; |
| 684 | layer.height = v[1]; |
Sergey Silkin | a89800c | 2019-02-19 12:52:56 +0100 | [diff] [blame] | 685 | 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 Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 691 | layer.active = true; |
| 692 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 693 | params->ss[video_idx].spatial_layers.push_back(layer); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 697 | void VideoQualityTest::SetupVideo(Transport* send_transport, |
| 698 | Transport* recv_transport) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 699 | size_t total_streams_used = 0; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 700 | video_receive_configs_.clear(); |
| 701 | video_send_configs_.clear(); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 702 | video_encoder_configs_.clear(); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 703 | 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 709 | 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 Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 712 | 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 Wang | 2d82ade | 2018-07-11 06:04:44 +0000 | [diff] [blame] | 715 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 716 | int payload_type; |
| 717 | if (params_.video[video_idx].codec == "H264") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 718 | payload_type = kPayloadTypeH264; |
| 719 | } else if (params_.video[video_idx].codec == "VP8") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 720 | payload_type = kPayloadTypeVP8; |
| 721 | } else if (params_.video[video_idx].codec == "VP9") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 722 | payload_type = kPayloadTypeVP9; |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 723 | } else if (params_.video[video_idx].codec == "multiplex") { |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 724 | payload_type = kPayloadTypeVP9; |
Emircan Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 725 | } else if (params_.video[video_idx].codec == "FakeCodec") { |
| 726 | payload_type = kFakeVideoSendPayloadType; |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 727 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 728 | RTC_NOTREACHED() << "Codec not supported!"; |
| 729 | return; |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 730 | } |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 731 | video_send_configs_[video_idx].encoder_settings.encoder_factory = |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 732 | (video_idx == 0) ? &video_encoder_factory_with_analyzer_ |
| 733 | : &video_encoder_factory_; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 734 | video_send_configs_[video_idx].encoder_settings.bitrate_allocator_factory = |
| 735 | video_bitrate_allocator_factory_.get(); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 736 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 737 | video_send_configs_[video_idx].rtp.payload_name = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 738 | params_.video[video_idx].codec; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 739 | video_send_configs_[video_idx].rtp.payload_type = payload_type; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 740 | 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]); |
ilnik | 9fd9f6c | 2017-03-02 08:10:10 -0800 | [diff] [blame] | 745 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 746 | video_send_configs_[video_idx].rtp.extensions.clear(); |
| 747 | if (params_.call.send_side_bwe) { |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 748 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
| 749 | RtpExtension::kTransportSequenceNumberUri, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 750 | kTransportSequenceNumberExtensionId); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 751 | } else { |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 752 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 753 | RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 754 | } |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 755 | |
| 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 Alon | ccb9b75 | 2019-02-19 13:01:31 +0100 | [diff] [blame] | 763 | RtpExtension::kGenericFrameDescriptorUri00, |
| 764 | kGenericFrameDescriptorExtensionId00); |
| 765 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
| 766 | RtpExtension::kGenericFrameDescriptorUri01, |
| 767 | kGenericFrameDescriptorExtensionId01); |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 771 | RtpExtension::kVideoContentTypeUri, kVideoContentTypeExtensionId); |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 772 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 773 | RtpExtension::kVideoTimingUri, kVideoTimingExtensionId); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 774 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 775 | video_encoder_configs_[video_idx].video_format.name = |
| 776 | params_.video[video_idx].codec; |
| 777 | |
Emircan Uysaler | 0823eec | 2018-07-13 17:10:00 -0700 | [diff] [blame] | 778 | video_encoder_configs_[video_idx].video_format.parameters = |
| 779 | params_.video[video_idx].sdp_params; |
| 780 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 781 | video_encoder_configs_[video_idx].codec_type = |
| 782 | PayloadStringToCodecType(params_.video[video_idx].codec); |
| 783 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 784 | 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 Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 797 | 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 Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 800 | video_encoder_configs_[video_idx].simulcast_layers = |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 801 | params_.ss[video_idx].streams; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 802 | } |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 803 | 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 808 | |
| 809 | video_encoder_configs_[video_idx].spatial_layers = |
| 810 | params_.ss[video_idx].spatial_layers; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 811 | decode_all_receive_streams = params_.ss[video_idx].selected_stream == |
| 812 | params_.ss[video_idx].streams.size(); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 813 | 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öller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 818 | params_.call.send_side_bwe, &video_decoder_factory_, decode_sub_stream, |
| 819 | true, kNackRtpHistoryMs); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 820 | |
| 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 Brandstetter | 49fcc10 | 2018-05-16 14:20:41 -0700 | [diff] [blame] | 825 | degradation_preference_ = DegradationPreference::MAINTAIN_RESOLUTION; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 826 | 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 Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 843 | vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred; |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 844 | // High FPS vp9 screenshare requires flexible mode. |
| 845 | if (params_.video[video_idx].fps > 5) { |
| 846 | vp9_settings.flexibleMode = true; |
| 847 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 848 | 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 Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 860 | vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 861 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 862 | new rtc::RefCountedObject< |
| 863 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 864 | } 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 Holmer | 1f7a008 | 2019-01-11 15:39:08 +0100 | [diff] [blame] | 877 | } else if (params_.video[video_idx].codec == "H264") { |
| 878 | // Quality scaling is always on for H.264. |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 879 | } else { |
| 880 | RTC_NOTREACHED() << "Automatic scaling not supported for codec " |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 881 | << params_.video[video_idx].codec << ", stream " |
| 882 | << video_idx; |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 883 | } |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 884 | } 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 904 | } |
| 905 | total_streams_used += num_video_substreams; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 906 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 907 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 908 | // FEC supported only for single video stream mode yet. |
| 909 | if (params_.video[0].flexfec) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 910 | if (decode_all_receive_streams) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 911 | SetSendFecConfig(GetVideoSendConfig()->rtp.ssrcs); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 912 | } else { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 913 | SetSendFecConfig({kVideoSendSsrcs[params_.ss[0].selected_stream]}); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 914 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 915 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 916 | CreateMatchingFecConfig(recv_transport, *GetVideoSendConfig()); |
| 917 | GetFlexFecConfig()->transport_cc = params_.call.send_side_bwe; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 918 | if (params_.call.send_side_bwe) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 919 | GetFlexFecConfig()->rtp_header_extensions.push_back( |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 920 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 921 | kTransportSequenceNumberExtensionId)); |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 922 | } else { |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 923 | GetFlexFecConfig()->rtp_header_extensions.push_back( |
| 924 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId)); |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 925 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 926 | } |
| 927 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 928 | if (params_.video[0].ulpfec) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 929 | SetSendUlpFecConfig(GetVideoSendConfig()); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 930 | if (decode_all_receive_streams) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 931 | for (auto& receive_config : video_receive_configs_) { |
| 932 | SetReceiveUlpFecConfig(&receive_config); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 933 | } |
| 934 | } else { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 935 | SetReceiveUlpFecConfig( |
| 936 | &video_receive_configs_[params_.ss[0].selected_stream]); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 937 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 938 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 939 | } |
| 940 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 941 | void VideoQualityTest::SetupThumbnails(Transport* send_transport, |
| 942 | Transport* recv_transport) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 943 | for (int i = 0; i < params_.call.num_thumbnails; ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 944 | // 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öller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 948 | // TODO(nisse): Could use a simpler VP8-only encoder factory. |
| 949 | thumbnail_send_config.encoder_settings.encoder_factory = |
| 950 | &video_encoder_factory_; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 951 | thumbnail_send_config.encoder_settings.bitrate_allocator_factory = |
| 952 | video_bitrate_allocator_factory_.get(); |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 953 | thumbnail_send_config.rtp.payload_name = params_.video[0].codec; |
| 954 | thumbnail_send_config.rtp.payload_type = kPayloadTypeVP8; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 955 | 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 Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 962 | kTransportSequenceNumberExtensionId)); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 963 | } else { |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 964 | thumbnail_send_config.rtp.extensions.push_back( |
| 965 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId)); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | VideoEncoderConfig thumbnail_encoder_config; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 969 | thumbnail_encoder_config.codec_type = kVideoCodecVP8; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 970 | thumbnail_encoder_config.video_format.name = "VP8"; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 971 | thumbnail_encoder_config.min_transmit_bitrate_bps = 7500; |
| 972 | thumbnail_send_config.suspend_below_min_bitrate = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 973 | params_.video[0].suspend_below_min_bitrate; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 974 | thumbnail_encoder_config.number_of_streams = 1; |
| 975 | thumbnail_encoder_config.max_bitrate_bps = 50000; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 976 | std::vector<VideoStream> streams{params_.ss[0].streams[0]}; |
| 977 | thumbnail_encoder_config.video_stream_factory = |
| 978 | new rtc::RefCountedObject<VideoStreamFactory>(streams); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 979 | thumbnail_encoder_config.spatial_layers = params_.ss[0].spatial_layers; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 980 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 981 | thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy()); |
| 982 | thumbnail_send_configs_.push_back(thumbnail_send_config.Copy()); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 983 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 984 | AddMatchingVideoReceiveConfigs( |
| 985 | &thumbnail_receive_configs_, thumbnail_send_config, send_transport, |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 986 | params_.call.send_side_bwe, &video_decoder_factory_, absl::nullopt, |
| 987 | false, kNackRtpHistoryMs); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 988 | } |
| 989 | for (size_t i = 0; i < thumbnail_send_configs_.size(); ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 990 | thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream( |
| 991 | thumbnail_send_configs_[i].Copy(), |
| 992 | thumbnail_encoder_configs_[i].Copy())); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 993 | } |
| 994 | for (size_t i = 0; i < thumbnail_receive_configs_.size(); ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 995 | thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream( |
| 996 | thumbnail_receive_configs_[i].Copy())); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | void VideoQualityTest::DestroyThumbnailStreams() { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1001 | for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1002 | receiver_call_->DestroyVideoSendStream(thumbnail_send_stream); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1003 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1004 | thumbnail_send_streams_.clear(); |
| 1005 | for (VideoReceiveStream* thumbnail_receive_stream : |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1006 | thumbnail_receive_streams_) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1007 | sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1008 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1009 | thumbnail_send_streams_.clear(); |
| 1010 | thumbnail_receive_streams_.clear(); |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1011 | for (std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>& video_capturer : |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1012 | thumbnail_capturers_) { |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1013 | video_capturer.reset(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1014 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1017 | void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) { |
| 1018 | VideoStream thumbnail = DefaultThumbnailStream(); |
| 1019 | for (size_t i = 0; i < num_thumbnail_streams; ++i) { |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1020 | 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)); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1033 | std::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); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1044 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1045 | std::vector<std::string> slides = params_.screenshare[video_idx].slides; |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1046 | if (slides.empty()) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1047 | 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); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1058 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1059 | 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); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1074 | } |
| 1075 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1076 | return frame_generator; |
| 1077 | } |
| 1078 | |
| 1079 | void VideoQualityTest::CreateCapturers() { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1080 | RTC_DCHECK(video_sources_.empty()); |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1081 | video_sources_.resize(num_video_streams_); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1082 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1083 | std::unique_ptr<test::FrameGenerator> frame_generator; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1084 | if (params_.screenshare[video_idx].enabled) { |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1085 | 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1111 | static_cast<int>(params_.video[video_idx].width), |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1112 | static_cast<int>(params_.video[video_idx].height), absl::nullopt, |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1113 | absl::nullopt); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1114 | } |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1115 | } 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1122 | } |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1123 | 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1130 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1133 | void VideoQualityTest::StartAudioStreams() { |
| 1134 | audio_send_stream_->Start(); |
| 1135 | for (AudioReceiveStream* audio_recv_stream : audio_receive_streams_) |
| 1136 | audio_recv_stream->Start(); |
| 1137 | } |
| 1138 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1139 | void 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 Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | void VideoQualityTest::StopThumbnails() { |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1147 | 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 Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 1153 | std::unique_ptr<test::LayerFilteringTransport> |
| 1154 | VideoQualityTest::CreateSendTransport() { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1155 | std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr; |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1156 | if (injection_components_->sender_network == nullptr) { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1157 | network_behavior = absl::make_unique<SimulatedNetwork>(*params_.config); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1158 | } else { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1159 | network_behavior = std::move(injection_components_->sender_network); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1160 | } |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 1161 | return absl::make_unique<test::LayerFilteringTransport>( |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 1162 | &task_queue_, |
Sebastian Jansson | 11c012a | 2019-03-29 14:17:26 +0100 | [diff] [blame] | 1163 | absl::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)), |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 1164 | sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9, |
| 1165 | params_.video[0].selected_tl, params_.ss[0].selected_sl, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1166 | payload_type_map_, kVideoSendSsrcs[0], |
| 1167 | static_cast<uint32_t>(kVideoSendSsrcs[0] + params_.ss[0].streams.size() - |
| 1168 | 1)); |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | std::unique_ptr<test::DirectTransport> |
| 1172 | VideoQualityTest::CreateReceiveTransport() { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1173 | std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr; |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1174 | if (injection_components_->receiver_network == nullptr) { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1175 | network_behavior = absl::make_unique<SimulatedNetwork>(*params_.config); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1176 | } else { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1177 | network_behavior = std::move(injection_components_->receiver_network); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1178 | } |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 1179 | return absl::make_unique<test::DirectTransport>( |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 1180 | &task_queue_, |
Sebastian Jansson | 11c012a | 2019-03-29 14:17:26 +0100 | [diff] [blame] | 1181 | absl::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)), |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 1182 | receiver_call_.get(), payload_type_map_); |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 1183 | } |
| 1184 | |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1185 | void VideoQualityTest::RunWithAnalyzer(const Params& params) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1186 | num_video_streams_ = params.call.dual_video ? 2 : 1; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1187 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 1188 | std::unique_ptr<test::DirectTransport> recv_transport; |
| 1189 | FILE* graph_data_output_file = nullptr; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1190 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1191 | params_ = params; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1192 | // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to |
| 1193 | // differentiate between the analyzer and the renderer case. |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1194 | CheckParamsAndInjectionComponents(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1195 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1196 | if (!params_.analyzer.graph_data_output_filename.empty()) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1197 | graph_data_output_file = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1198 | fopen(params_.analyzer.graph_data_output_filename.c_str(), "w"); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 1199 | RTC_CHECK(graph_data_output_file) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1200 | << "Can't open the file " << params_.analyzer.graph_data_output_filename |
| 1201 | << "!"; |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1202 | } |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1203 | |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1204 | if (!params.logging.rtc_event_log_name.empty()) { |
Danil Chapovalov | 304ea5f | 2019-04-11 15:18:18 +0200 | [diff] [blame] | 1205 | 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 Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1209 | std::unique_ptr<RtcEventLogOutputFile> send_output( |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 1210 | absl::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1211 | params.logging.rtc_event_log_name + "_send", |
| 1212 | RtcEventLog::kUnlimitedOutput)); |
| 1213 | std::unique_ptr<RtcEventLogOutputFile> recv_output( |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 1214 | absl::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1215 | 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); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1222 | RTC_DCHECK(event_log_started); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1223 | } else { |
| 1224 | send_event_log_ = RtcEventLog::CreateNull(); |
| 1225 | recv_event_log_ = RtcEventLog::CreateNull(); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 1228 | task_queue_.SendTask([this, ¶ms, &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 Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1233 | if (params_.audio.enabled) |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1234 | InitializeAudioDevice(&send_call_config, &recv_call_config, |
| 1235 | params_.audio.use_real_adm); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1236 | |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1237 | CreateCalls(send_call_config, recv_call_config); |
| 1238 | send_transport = CreateSendTransport(); |
| 1239 | recv_transport = CreateReceiveTransport(); |
| 1240 | }); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1241 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1242 | std::string graph_title = params_.analyzer.graph_title; |
| 1243 | if (graph_title.empty()) |
| 1244 | graph_title = VideoQualityTest::GenerateGraphTitle(); |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame] | 1245 | bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest"); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1246 | analyzer_ = absl::make_unique<VideoAnalyzer>( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1247 | send_transport.get(), params_.analyzer.test_label, |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1248 | params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold, |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 1249 | is_quick_test_enabled |
| 1250 | ? kFramesSentInQuickTest |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1251 | : params_.analyzer.test_durations_secs * params_.video[0].fps, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1252 | graph_data_output_file, graph_title, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1253 | 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 Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 1257 | is_quick_test_enabled, clock_, params_.logging.rtp_dump_name, |
| 1258 | &task_queue_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1259 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1260 | task_queue_.SendTask([&]() { |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1261 | analyzer_->SetCall(sender_call_.get()); |
| 1262 | analyzer_->SetReceiver(receiver_call_->Receiver()); |
| 1263 | send_transport->SetReceiver(analyzer_.get()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1264 | recv_transport->SetReceiver(sender_call_->Receiver()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1265 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1266 | SetupVideo(analyzer_.get(), recv_transport.get()); |
| 1267 | SetupThumbnails(analyzer_.get(), recv_transport.get()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1268 | video_receive_configs_[params_.ss[0].selected_stream].renderer = |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1269 | analyzer_.get(); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 1270 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1271 | CreateFlexfecStreams(); |
| 1272 | CreateVideoStreams(); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1273 | analyzer_->SetSendStream(video_send_streams_[0]); |
Ilya Nikolaevskiy | d47d3eb | 2019-01-21 16:27:17 +0100 | [diff] [blame] | 1274 | analyzer_->SetReceiveStream( |
| 1275 | video_receive_streams_[params_.ss[0].selected_stream]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1276 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1277 | GetVideoSendStream()->SetSource(analyzer_->OutputInterface(), |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1278 | degradation_preference_); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1279 | 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 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1284 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1285 | CreateCapturers(); |
ivica | c1cc854 | 2015-10-08 03:44:06 -0700 | [diff] [blame] | 1286 | |
Stefan Holmer | 1f7a008 | 2019-01-11 15:39:08 +0100 | [diff] [blame] | 1287 | analyzer_->SetSource(video_sources_[0].get(), true); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1288 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1289 | for (size_t video_idx = 1; video_idx < num_video_streams_; ++video_idx) { |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1290 | video_send_streams_[video_idx]->SetSource(video_sources_[video_idx].get(), |
| 1291 | degradation_preference_); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1292 | } |
| 1293 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1294 | if (params_.audio.enabled) { |
| 1295 | SetupAudio(send_transport.get()); |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1296 | StartAudioStreams(); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1297 | analyzer_->SetAudioReceiveStream(audio_receive_streams_[0]); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1298 | } |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1299 | StartVideoStreams(); |
| 1300 | StartThumbnails(); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1301 | analyzer_->StartMeasuringCpuProcessTime(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1302 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1303 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1304 | analyzer_->Wait(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1305 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1306 | task_queue_.SendTask([&]() { |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1307 | StopThumbnails(); |
| 1308 | Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1309 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1310 | DestroyStreams(); |
| 1311 | DestroyThumbnailStreams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1312 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1313 | if (graph_data_output_file) |
| 1314 | fclose(graph_data_output_file); |
| 1315 | |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1316 | video_sources_.clear(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1317 | send_transport.reset(); |
| 1318 | recv_transport.reset(); |
| 1319 | |
| 1320 | DestroyCalls(); |
| 1321 | }); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1322 | analyzer_ = nullptr; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1325 | rtc::scoped_refptr<AudioDeviceModule> VideoQualityTest::CreateAudioDevice() { |
| 1326 | #ifdef WEBRTC_WIN |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1327 | 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 Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 1338 | return CreateWindowsCoreAudioAudioDeviceModule(task_queue_factory_.get()); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1339 | #else |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1340 | // Use legacy factory method on all platforms except Windows. |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 1341 | return AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio, |
| 1342 | task_queue_factory_.get()); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1343 | #endif |
| 1344 | } |
| 1345 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1346 | void VideoQualityTest::InitializeAudioDevice(Call::Config* send_call_config, |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1347 | 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 Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1361 | |
| 1362 | AudioState::Config audio_state_config; |
| 1363 | audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
| 1364 | audio_state_config.audio_processing = AudioProcessingBuilder().Create(); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1365 | audio_state_config.audio_device_module = audio_device; |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1366 | send_call_config->audio_state = AudioState::Create(audio_state_config); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1367 | recv_call_config->audio_state = AudioState::Create(audio_state_config); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1368 | 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 Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1378 | send_call_config->audio_state->audio_transport()) == 0); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1379 | } |
| 1380 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1381 | void VideoQualityTest::SetupAudio(Transport* transport) { |
Niels Möller | 7d76a31 | 2018-10-26 12:57:07 +0200 | [diff] [blame] | 1382 | AudioSendStream::Config audio_send_config(transport, |
| 1383 | /*media_transport=*/nullptr); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1384 | audio_send_config.rtp.ssrc = kAudioSendSsrc; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1385 | |
| 1386 | // Add extension to enable audio send side BWE, and allow audio bit rate |
| 1387 | // adaptation. |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1388 | audio_send_config.rtp.extensions.clear(); |
| 1389 | audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec( |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 1390 | kAudioSendPayloadType, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1391 | {"OPUS", |
| 1392 | 48000, |
| 1393 | 2, |
| 1394 | {{"usedtx", (params_.audio.dtx ? "1" : "0")}, {"stereo", "1"}}}); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1395 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1396 | if (params_.call.send_side_bwe) { |
| 1397 | audio_send_config.rtp.extensions.push_back( |
| 1398 | webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 1399 | kTransportSequenceNumberExtensionId)); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1400 | 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 Li | 455d27c | 2019-01-07 13:14:30 +0100 | [diff] [blame] | 1403 | // Only allow ANA when send-side BWE is enabled. |
| 1404 | audio_send_config.audio_network_adaptor_config = params_.audio.ana_config; |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1405 | } |
| 1406 | audio_send_config.encoder_factory = audio_encoder_factory_; |
| 1407 | SetAudioConfig(audio_send_config); |
| 1408 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1409 | std::string sync_group; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1410 | if (params_.video[0].enabled && params_.audio.sync_video) |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1411 | sync_group = kSyncGroup; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1412 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1413 | CreateMatchingAudioConfigs(transport, sync_group); |
| 1414 | CreateAudioStreams(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1417 | void VideoQualityTest::RunWithRenderers(const Params& params) { |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1418 | RTC_LOG(INFO) << __FUNCTION__; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1419 | num_video_streams_ = params.call.dual_video ? 2 : 1; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1420 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 1421 | std::unique_ptr<test::DirectTransport> recv_transport; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1422 | std::unique_ptr<test::VideoRenderer> local_preview; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1423 | std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers; |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1424 | |
| 1425 | if (!params.logging.rtc_event_log_name.empty()) { |
Danil Chapovalov | 304ea5f | 2019-04-11 15:18:18 +0200 | [diff] [blame] | 1426 | 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 Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1430 | 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 | } |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1448 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1449 | task_queue_.SendTask([&]() { |
| 1450 | params_ = params; |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1451 | CheckParamsAndInjectionComponents(); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1452 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1453 | // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to |
| 1454 | // match the full stack tests. |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1455 | Call::Config send_call_config(send_event_log_.get()); |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1456 | send_call_config.bitrate_config = params_.call.call_bitrate_config; |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1457 | Call::Config recv_call_config(recv_event_log_.get()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1458 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1459 | if (params_.audio.enabled) |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1460 | InitializeAudioDevice(&send_call_config, &recv_call_config, |
| 1461 | params_.audio.use_real_adm); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1462 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1463 | CreateCalls(send_call_config, recv_call_config); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1464 | |
| 1465 | // TODO(minyue): consider if this is a good transport even for audio only |
| 1466 | // calls. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1467 | send_transport = CreateSendTransport(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1468 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1469 | recv_transport = CreateReceiveTransport(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1470 | |
| 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 Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1477 | if (params_.video[0].enabled) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1478 | // Create video renderers. |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1479 | SetupVideo(send_transport.get(), recv_transport.get()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1480 | 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 Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 1486 | rtc::StringBuilder oss; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1487 | 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 Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 1500 | rtc::StringBuilder oss; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1501 | 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(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1508 | if (params_.audio.enabled && params_.audio.sync_video) |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1509 | video_receive_configs_[num_streams_processed + selected_stream_id] |
| 1510 | .sync_group = kSyncGroup; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1511 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1512 | num_streams_processed += num_streams; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1513 | } |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1514 | CreateFlexfecStreams(); |
| 1515 | CreateVideoStreams(); |
| 1516 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1517 | CreateCapturers(); |
Niels Möller | 412d185 | 2019-01-02 09:42:54 +0100 | [diff] [blame] | 1518 | 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 Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1526 | ConnectVideoSourcesToStreams(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | if (params_.audio.enabled) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1530 | SetupAudio(send_transport.get()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1533 | Start(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1534 | }); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1535 | |
Danail Kirov | 6fcf6ca | 2018-10-25 10:45:47 -0700 | [diff] [blame] | 1536 | test::PressEnterToContinue(task_queue_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1537 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1538 | task_queue_.SendTask([&]() { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1539 | Stop(); |
| 1540 | DestroyStreams(); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1541 | |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1542 | video_sources_.clear(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1543 | send_transport.reset(); |
| 1544 | recv_transport.reset(); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1545 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1546 | local_preview.reset(); |
| 1547 | loopback_renderers.clear(); |
| 1548 | |
| 1549 | DestroyCalls(); |
| 1550 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1553 | } // namespace webrtc |