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> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 13 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 14 | #include <algorithm> |
| 15 | #include <deque> |
| 16 | #include <map> |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 17 | #include <memory> |
mflodman | d1590b2 | 2015-12-09 07:07:59 -0800 | [diff] [blame] | 18 | #include <string> |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
Elad Alon | 8f01c4e | 2019-06-28 15:19:43 +0200 | [diff] [blame] | 21 | #include "api/fec_controller_override.h" |
Niels Möller | d8b9ed7 | 2019-05-08 13:53:51 +0200 | [diff] [blame] | 22 | #include "api/rtc_event_log_output_file.h" |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 23 | #include "api/task_queue/default_task_queue_factory.h" |
Danil Chapovalov | 44db436 | 2019-09-30 04:16:28 +0200 | [diff] [blame] | 24 | #include "api/task_queue/task_queue_base.h" |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 25 | #include "api/test/create_frame_generator.h" |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 26 | #include "api/video/builtin_video_bitrate_allocator_factory.h" |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 27 | #include "api/video_codecs/video_encoder.h" |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 28 | #include "call/fake_network_pipe.h" |
| 29 | #include "call/simulated_network.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 30 | #include "media/engine/adm_helpers.h" |
Florent Castelli | e7862cc | 2018-12-06 13:38:24 +0100 | [diff] [blame] | 31 | #include "media/engine/encoder_simulcast_proxy.h" |
Emircan Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 32 | #include "media/engine/fake_video_codec_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 33 | #include "media/engine/internal_encoder_factory.h" |
| 34 | #include "media/engine/webrtc_video_engine.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 35 | #include "modules/audio_device/include/audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "modules/audio_mixer/audio_mixer_impl.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 37 | #include "modules/video_coding/codecs/h264/include/h264.h" |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 38 | #include "modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h" |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 39 | #include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h" |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 40 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 41 | #include "modules/video_coding/codecs/vp9/include/vp9.h" |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 42 | #include "modules/video_coding/utility/ivf_file_writer.h" |
| 43 | #include "rtc_base/strings/string_builder.h" |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 44 | #include "rtc_base/task_queue_for_test.h" |
Kári Tristan Helgason | ede7cb2 | 2019-03-06 10:34:09 +0100 | [diff] [blame] | 45 | #include "test/platform_video_capturer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 46 | #include "test/run_loop.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 47 | #include "test/testsupport/file_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 48 | #include "test/video_renderer.h" |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 49 | #include "video/frame_dumping_decoder.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 50 | #ifdef WEBRTC_WIN |
| 51 | #include "modules/audio_device/include/audio_device_factory.h" |
| 52 | #endif |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 53 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 54 | namespace webrtc { |
| 55 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 56 | namespace { |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 57 | enum : int { // The first valid value is 1. |
| 58 | kAbsSendTimeExtensionId = 1, |
Elad Alon | ccb9b75 | 2019-02-19 13:01:31 +0100 | [diff] [blame] | 59 | kGenericFrameDescriptorExtensionId00, |
| 60 | kGenericFrameDescriptorExtensionId01, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 61 | kTransportSequenceNumberExtensionId, |
| 62 | kVideoContentTypeExtensionId, |
| 63 | kVideoTimingExtensionId, |
| 64 | }; |
| 65 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 66 | constexpr char kSyncGroup[] = "av_sync"; |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 67 | constexpr int kOpusMinBitrateBps = 6000; |
| 68 | constexpr int kOpusBitrateFbBps = 32000; |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 69 | constexpr int kFramesSentInQuickTest = 1; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 70 | constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000; |
| 71 | constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 72 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 73 | constexpr int kDefaultMaxQp = cricket::WebRtcVideoChannel::kDefaultQpMax; |
| 74 | |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 75 | const VideoEncoder::Capabilities kCapabilities(false); |
| 76 | |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 77 | std::pair<uint32_t, uint32_t> GetMinMaxBitratesBps(const VideoCodec& codec, |
| 78 | size_t spatial_idx) { |
| 79 | uint32_t min_bitrate = codec.minBitrate; |
| 80 | uint32_t max_bitrate = codec.maxBitrate; |
| 81 | if (spatial_idx < codec.numberOfSimulcastStreams) { |
| 82 | min_bitrate = |
| 83 | std::max(min_bitrate, codec.simulcastStream[spatial_idx].minBitrate); |
| 84 | max_bitrate = |
| 85 | std::min(max_bitrate, codec.simulcastStream[spatial_idx].maxBitrate); |
| 86 | } |
| 87 | if (codec.codecType == VideoCodecType::kVideoCodecVP9 && |
| 88 | spatial_idx < codec.VP9().numberOfSpatialLayers) { |
| 89 | min_bitrate = |
| 90 | std::max(min_bitrate, codec.spatialLayers[spatial_idx].minBitrate); |
| 91 | max_bitrate = |
| 92 | std::min(max_bitrate, codec.spatialLayers[spatial_idx].maxBitrate); |
| 93 | } |
| 94 | max_bitrate = std::max(max_bitrate, min_bitrate); |
| 95 | return {min_bitrate * 1000, max_bitrate * 1000}; |
| 96 | } |
| 97 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 98 | class VideoStreamFactory |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 99 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 100 | public: |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 101 | explicit VideoStreamFactory(const std::vector<VideoStream>& streams) |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 102 | : streams_(streams) {} |
| 103 | |
| 104 | private: |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 105 | std::vector<VideoStream> CreateEncoderStreams( |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 106 | int width, |
| 107 | int height, |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 108 | const VideoEncoderConfig& encoder_config) override { |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 109 | // The highest layer must match the incoming resolution. |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 110 | std::vector<VideoStream> streams = streams_; |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 111 | streams[streams_.size() - 1].height = height; |
| 112 | streams[streams_.size() - 1].width = width; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 113 | |
| 114 | streams[0].bitrate_priority = encoder_config.bitrate_priority; |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 115 | return streams; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 118 | std::vector<VideoStream> streams_; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 119 | }; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 120 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 121 | // This wrapper provides two features needed by the video quality tests: |
| 122 | // 1. Invoke VideoAnalyzer callbacks before and after encoding each frame. |
| 123 | // 2. Write the encoded frames to file, one file per simulcast layer. |
| 124 | class QualityTestVideoEncoder : public VideoEncoder, |
| 125 | private EncodedImageCallback { |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 126 | public: |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 127 | QualityTestVideoEncoder(std::unique_ptr<VideoEncoder> encoder, |
| 128 | VideoAnalyzer* analyzer, |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 129 | std::vector<FileWrapper> files, |
| 130 | double overshoot_factor) |
| 131 | : encoder_(std::move(encoder)), |
| 132 | overshoot_factor_(overshoot_factor), |
| 133 | analyzer_(analyzer) { |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 134 | for (FileWrapper& file : files) { |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 135 | writers_.push_back( |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 136 | IvfFileWriter::Wrap(std::move(file), /* byte_limit= */ 100000000)); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 137 | } |
| 138 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 139 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 140 | // Implement VideoEncoder |
Elad Alon | 8f01c4e | 2019-06-28 15:19:43 +0200 | [diff] [blame] | 141 | void SetFecControllerOverride( |
| 142 | FecControllerOverride* fec_controller_override) { |
| 143 | // Ignored. |
| 144 | } |
| 145 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 146 | int32_t InitEncode(const VideoCodec* codec_settings, |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 147 | const Settings& settings) override { |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 148 | codec_settings_ = *codec_settings; |
Elad Alon | 370f93a | 2019-06-11 14:57:57 +0200 | [diff] [blame] | 149 | return encoder_->InitEncode(codec_settings, settings); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 150 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 151 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 152 | int32_t RegisterEncodeCompleteCallback( |
| 153 | EncodedImageCallback* callback) override { |
| 154 | callback_ = callback; |
| 155 | return encoder_->RegisterEncodeCompleteCallback(this); |
| 156 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 157 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 158 | int32_t Release() override { return encoder_->Release(); } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 159 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 160 | int32_t Encode(const VideoFrame& frame, |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 161 | const std::vector<VideoFrameType>* frame_types) { |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 162 | if (analyzer_) { |
| 163 | analyzer_->PreEncodeOnFrame(frame); |
| 164 | } |
Niels Möller | c8d2e73 | 2019-03-06 12:00:33 +0100 | [diff] [blame] | 165 | return encoder_->Encode(frame, frame_types); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 166 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 167 | |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 168 | void SetRates(const RateControlParameters& parameters) override { |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 169 | RTC_DCHECK_GT(overshoot_factor_, 0.0); |
| 170 | if (overshoot_factor_ == 1.0) { |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 171 | encoder_->SetRates(parameters); |
| 172 | return; |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // Simulating encoder overshooting target bitrate, by configuring actual |
| 176 | // encoder too high. Take care not to adjust past limits of config, |
| 177 | // otherwise encoders may crash on DCHECK. |
| 178 | VideoBitrateAllocation overshot_allocation; |
| 179 | for (size_t si = 0; si < kMaxSpatialLayers; ++si) { |
| 180 | const uint32_t spatial_layer_bitrate_bps = |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 181 | parameters.bitrate.GetSpatialLayerSum(si); |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 182 | if (spatial_layer_bitrate_bps == 0) { |
| 183 | continue; |
| 184 | } |
| 185 | |
| 186 | uint32_t min_bitrate_bps; |
| 187 | uint32_t max_bitrate_bps; |
| 188 | std::tie(min_bitrate_bps, max_bitrate_bps) = |
| 189 | GetMinMaxBitratesBps(codec_settings_, si); |
| 190 | double overshoot_factor = overshoot_factor_; |
| 191 | const uint32_t corrected_bitrate = rtc::checked_cast<uint32_t>( |
| 192 | overshoot_factor * spatial_layer_bitrate_bps); |
| 193 | if (corrected_bitrate < min_bitrate_bps) { |
| 194 | overshoot_factor = min_bitrate_bps / spatial_layer_bitrate_bps; |
| 195 | } else if (corrected_bitrate > max_bitrate_bps) { |
| 196 | overshoot_factor = max_bitrate_bps / spatial_layer_bitrate_bps; |
| 197 | } |
| 198 | |
| 199 | for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) { |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 200 | if (parameters.bitrate.HasBitrate(si, ti)) { |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 201 | overshot_allocation.SetBitrate( |
| 202 | si, ti, |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 203 | rtc::checked_cast<uint32_t>( |
| 204 | overshoot_factor * parameters.bitrate.GetBitrate(si, ti))); |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
Erik Språng | 16cb8f5 | 2019-04-12 13:59:09 +0200 | [diff] [blame] | 209 | return encoder_->SetRates( |
| 210 | RateControlParameters(overshot_allocation, parameters.framerate_fps, |
| 211 | parameters.bandwidth_allocation)); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 212 | } |
Elad Alon | fe4f694 | 2019-05-07 23:13:42 +0200 | [diff] [blame] | 213 | |
| 214 | void OnPacketLossRateUpdate(float packet_loss_rate) override { |
| 215 | encoder_->OnPacketLossRateUpdate(packet_loss_rate); |
| 216 | } |
| 217 | |
| 218 | void OnRttUpdate(int64_t rtt_ms) override { encoder_->OnRttUpdate(rtt_ms); } |
| 219 | |
| 220 | void OnLossNotification(const LossNotification& loss_notification) override { |
| 221 | encoder_->OnLossNotification(loss_notification); |
| 222 | } |
| 223 | |
Erik Språng | 189013b | 2018-11-01 15:03:57 +0100 | [diff] [blame] | 224 | EncoderInfo GetEncoderInfo() const override { |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 225 | EncoderInfo info = encoder_->GetEncoderInfo(); |
| 226 | if (overshoot_factor_ != 1.0) { |
| 227 | // We're simulating bad encoder, don't forward trusted setting |
| 228 | // from eg libvpx. |
| 229 | info.has_trusted_rate_controller = false; |
| 230 | } |
| 231 | return info; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | private: |
| 235 | // Implement EncodedImageCallback |
| 236 | Result OnEncodedImage(const EncodedImage& encoded_image, |
| 237 | const CodecSpecificInfo* codec_specific_info, |
| 238 | const RTPFragmentationHeader* fragmentation) override { |
| 239 | if (codec_specific_info) { |
| 240 | int simulcast_index; |
| 241 | if (codec_specific_info->codecType == kVideoCodecVP9) { |
| 242 | simulcast_index = 0; |
| 243 | } else { |
| 244 | simulcast_index = encoded_image.SpatialIndex().value_or(0); |
| 245 | } |
| 246 | RTC_DCHECK_GE(simulcast_index, 0); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 247 | if (analyzer_) { |
| 248 | analyzer_->PostEncodeOnFrame(simulcast_index, |
| 249 | encoded_image.Timestamp()); |
| 250 | } |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 251 | if (static_cast<size_t>(simulcast_index) < writers_.size()) { |
| 252 | writers_[simulcast_index]->WriteFrame(encoded_image, |
| 253 | codec_specific_info->codecType); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | return callback_->OnEncodedImage(encoded_image, codec_specific_info, |
| 258 | fragmentation); |
| 259 | } |
| 260 | |
| 261 | void OnDroppedFrame(DropReason reason) override { |
| 262 | callback_->OnDroppedFrame(reason); |
| 263 | } |
| 264 | |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 265 | const std::unique_ptr<VideoEncoder> encoder_; |
| 266 | const double overshoot_factor_; |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 267 | VideoAnalyzer* const analyzer_; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 268 | std::vector<std::unique_ptr<IvfFileWriter>> writers_; |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 269 | EncodedImageCallback* callback_ = nullptr; |
| 270 | VideoCodec codec_settings_; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | } // namespace |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 274 | |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 275 | std::unique_ptr<VideoDecoder> VideoQualityTest::CreateVideoDecoder( |
| 276 | const SdpVideoFormat& format) { |
| 277 | std::unique_ptr<VideoDecoder> decoder; |
| 278 | if (format.name == "multiplex") { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 279 | decoder = std::make_unique<MultiplexDecoderAdapter>( |
“Michael | 3c396e5 | 2019-06-12 09:47:14 -0500 | [diff] [blame] | 280 | decoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName)); |
Emircan Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 281 | } else if (format.name == "FakeCodec") { |
| 282 | decoder = webrtc::FakeVideoDecoderFactory::CreateVideoDecoder(); |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 283 | } else { |
“Michael | 3c396e5 | 2019-06-12 09:47:14 -0500 | [diff] [blame] | 284 | decoder = decoder_factory_->CreateVideoDecoder(format); |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 285 | } |
Niels Möller | 5ca2912 | 2018-10-02 09:55:01 +0200 | [diff] [blame] | 286 | if (!params_.logging.encoded_frame_base_path.empty()) { |
| 287 | rtc::StringBuilder str; |
| 288 | str << receive_logs_++; |
| 289 | std::string path = |
| 290 | params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; |
Markus Handell | 1c2f637 | 2019-08-20 20:21:37 +0200 | [diff] [blame] | 291 | decoder = CreateFrameDumpingDecoderWrapper( |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 292 | std::move(decoder), FileWrapper::OpenWriteOnly(path)); |
Niels Möller | 5ca2912 | 2018-10-02 09:55:01 +0200 | [diff] [blame] | 293 | } |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 294 | return decoder; |
| 295 | } |
| 296 | |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 297 | std::unique_ptr<VideoEncoder> VideoQualityTest::CreateVideoEncoder( |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 298 | const SdpVideoFormat& format, |
| 299 | VideoAnalyzer* analyzer) { |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 300 | std::unique_ptr<VideoEncoder> encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 301 | if (format.name == "VP8") { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 302 | encoder = |
| 303 | std::make_unique<EncoderSimulcastProxy>(encoder_factory_.get(), format); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 304 | } else if (format.name == "multiplex") { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 305 | encoder = std::make_unique<MultiplexEncoderAdapter>( |
“Michael | 3c396e5 | 2019-06-12 09:47:14 -0500 | [diff] [blame] | 306 | encoder_factory_.get(), SdpVideoFormat(cricket::kVp9CodecName)); |
Emircan Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 307 | } else if (format.name == "FakeCodec") { |
| 308 | encoder = webrtc::FakeVideoEncoderFactory::CreateVideoEncoder(); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 309 | } else { |
“Michael | 3c396e5 | 2019-06-12 09:47:14 -0500 | [diff] [blame] | 310 | encoder = encoder_factory_->CreateVideoEncoder(format); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 311 | } |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 312 | |
| 313 | std::vector<FileWrapper> encoded_frame_dump_files; |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 314 | if (!params_.logging.encoded_frame_base_path.empty()) { |
| 315 | char ss_buf[100]; |
| 316 | rtc::SimpleStringBuilder sb(ss_buf); |
| 317 | sb << send_logs_++; |
| 318 | std::string prefix = |
| 319 | params_.logging.encoded_frame_base_path + "." + sb.str() + ".send."; |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 320 | encoded_frame_dump_files.push_back( |
| 321 | FileWrapper::OpenWriteOnly(prefix + "1.ivf")); |
| 322 | encoded_frame_dump_files.push_back( |
| 323 | FileWrapper::OpenWriteOnly(prefix + "2.ivf")); |
| 324 | encoded_frame_dump_files.push_back( |
| 325 | FileWrapper::OpenWriteOnly(prefix + "3.ivf")); |
| 326 | } |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 327 | |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 328 | double overshoot_factor = 1.0; |
| 329 | // Match format to either of the streams in dual-stream mode in order to get |
| 330 | // the overshoot factor. This is not very robust but we can't know for sure |
| 331 | // which stream this encoder is meant for, from within the factory. |
| 332 | if (format == |
| 333 | SdpVideoFormat(params_.video[0].codec, params_.video[0].sdp_params)) { |
| 334 | overshoot_factor = params_.video[0].encoder_overshoot_factor; |
| 335 | } else if (format == SdpVideoFormat(params_.video[1].codec, |
| 336 | params_.video[1].sdp_params)) { |
| 337 | overshoot_factor = params_.video[1].encoder_overshoot_factor; |
| 338 | } |
| 339 | if (overshoot_factor == 0.0) { |
| 340 | // If params were zero-initialized, set to 1.0 instead. |
| 341 | overshoot_factor = 1.0; |
| 342 | } |
| 343 | |
| 344 | if (analyzer || !encoded_frame_dump_files.empty() || overshoot_factor > 1.0) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 345 | encoder = std::make_unique<QualityTestVideoEncoder>( |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 346 | std::move(encoder), analyzer, std::move(encoded_frame_dump_files), |
| 347 | overshoot_factor); |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 348 | } |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 349 | |
Niels Möller | 1beef1a | 2018-09-03 14:21:44 +0200 | [diff] [blame] | 350 | return encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 353 | VideoQualityTest::VideoQualityTest( |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 354 | std::unique_ptr<InjectionComponents> injection_components) |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 355 | : clock_(Clock::GetRealTimeClock()), |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 356 | task_queue_factory_(CreateDefaultTaskQueueFactory()), |
Danil Chapovalov | 304ea5f | 2019-04-11 15:18:18 +0200 | [diff] [blame] | 357 | rtc_event_log_factory_(task_queue_factory_.get()), |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 358 | video_decoder_factory_([this](const SdpVideoFormat& format) { |
| 359 | return this->CreateVideoDecoder(format); |
| 360 | }), |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 361 | video_encoder_factory_([this](const SdpVideoFormat& format) { |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 362 | return this->CreateVideoEncoder(format, nullptr); |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 363 | }), |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 364 | video_encoder_factory_with_analyzer_( |
| 365 | [this](const SdpVideoFormat& format) { |
| 366 | return this->CreateVideoEncoder(format, analyzer_.get()); |
| 367 | }), |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 368 | video_bitrate_allocator_factory_( |
| 369 | CreateBuiltinVideoBitrateAllocatorFactory()), |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 370 | receive_logs_(0), |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 371 | send_logs_(0), |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 372 | injection_components_(std::move(injection_components)), |
| 373 | num_video_streams_(0) { |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 374 | if (injection_components_ == nullptr) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 375 | injection_components_ = std::make_unique<InjectionComponents>(); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 376 | } |
“Michael | 3c396e5 | 2019-06-12 09:47:14 -0500 | [diff] [blame] | 377 | if (injection_components_->video_decoder_factory != nullptr) { |
| 378 | decoder_factory_ = std::move(injection_components_->video_decoder_factory); |
| 379 | } else { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 380 | decoder_factory_ = std::make_unique<InternalDecoderFactory>(); |
“Michael | 3c396e5 | 2019-06-12 09:47:14 -0500 | [diff] [blame] | 381 | } |
| 382 | if (injection_components_->video_encoder_factory != nullptr) { |
| 383 | encoder_factory_ = std::move(injection_components_->video_encoder_factory); |
| 384 | } else { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 385 | encoder_factory_ = std::make_unique<InternalEncoderFactory>(); |
“Michael | 3c396e5 | 2019-06-12 09:47:14 -0500 | [diff] [blame] | 386 | } |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 387 | |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 388 | payload_type_map_ = test::CallTest::payload_type_map_; |
| 389 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeH264) == |
| 390 | payload_type_map_.end()); |
| 391 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP8) == |
| 392 | payload_type_map_.end()); |
| 393 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP9) == |
| 394 | payload_type_map_.end()); |
Rasmus Brandt | 5894b6a | 2019-06-13 16:28:14 +0200 | [diff] [blame] | 395 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeGeneric) == |
| 396 | payload_type_map_.end()); |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 397 | payload_type_map_[kPayloadTypeH264] = webrtc::MediaType::VIDEO; |
| 398 | payload_type_map_[kPayloadTypeVP8] = webrtc::MediaType::VIDEO; |
| 399 | payload_type_map_[kPayloadTypeVP9] = webrtc::MediaType::VIDEO; |
Rasmus Brandt | 5894b6a | 2019-06-13 16:28:14 +0200 | [diff] [blame] | 400 | payload_type_map_[kPayloadTypeGeneric] = webrtc::MediaType::VIDEO; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 401 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 402 | fec_controller_factory_ = |
| 403 | std::move(injection_components_->fec_controller_factory); |
Ying Wang | cab77fd | 2019-04-16 11:12:49 +0200 | [diff] [blame] | 404 | network_state_predictor_factory_ = |
| 405 | std::move(injection_components_->network_state_predictor_factory); |
Sebastian Jansson | 1391ed2 | 2019-04-30 14:23:51 +0200 | [diff] [blame] | 406 | network_controller_factory_ = |
| 407 | std::move(injection_components_->network_controller_factory); |
Ying Wang | 3b790f3 | 2018-01-19 17:58:57 +0100 | [diff] [blame] | 408 | } |
| 409 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 410 | VideoQualityTest::Params::Params() |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 411 | : call({false, false, BitrateConstraints(), 0}), |
Erik Språng | 616b233 | 2019-02-11 14:16:28 +0100 | [diff] [blame] | 412 | video{{false, |
| 413 | 640, |
| 414 | 480, |
| 415 | 30, |
| 416 | 50, |
| 417 | 800, |
| 418 | 800, |
| 419 | false, |
| 420 | "VP8", |
| 421 | 1, |
| 422 | -1, |
| 423 | 0, |
| 424 | false, |
| 425 | false, |
| 426 | false, |
| 427 | "", |
| 428 | 0, |
| 429 | {}, |
| 430 | 0.0}, |
| 431 | {false, |
| 432 | 640, |
| 433 | 480, |
| 434 | 30, |
| 435 | 50, |
| 436 | 800, |
| 437 | 800, |
| 438 | false, |
| 439 | "VP8", |
| 440 | 1, |
| 441 | -1, |
| 442 | 0, |
| 443 | false, |
| 444 | false, |
| 445 | false, |
| 446 | "", |
| 447 | 0, |
| 448 | {}, |
| 449 | 0.0}}, |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 450 | audio({false, false, false, false}), |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 451 | screenshare{{false, false, 10, 0}, {false, false, 10, 0}}, |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 452 | analyzer({"", 0.0, 0.0, 0, "", ""}), |
Artem Titov | f18b352 | 2018-08-28 16:54:24 +0200 | [diff] [blame] | 453 | config(absl::nullopt), |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 454 | ss{{std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn, |
| 455 | std::vector<SpatialLayer>()}, |
| 456 | {std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn, |
| 457 | std::vector<SpatialLayer>()}}, |
Mirko Bonadei | 45a4c41 | 2018-07-31 15:07:28 +0200 | [diff] [blame] | 458 | logging({"", "", ""}) {} |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 459 | |
| 460 | VideoQualityTest::Params::~Params() = default; |
| 461 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 462 | VideoQualityTest::InjectionComponents::InjectionComponents() = default; |
| 463 | |
| 464 | VideoQualityTest::InjectionComponents::~InjectionComponents() = default; |
| 465 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 466 | void VideoQualityTest::TestBody() {} |
| 467 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 468 | std::string VideoQualityTest::GenerateGraphTitle() const { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 469 | rtc::StringBuilder ss; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 470 | ss << params_.video[0].codec; |
| 471 | ss << " (" << params_.video[0].target_bitrate_bps / 1000 << "kbps"; |
| 472 | ss << ", " << params_.video[0].fps << " FPS"; |
| 473 | if (params_.screenshare[0].scroll_duration) |
| 474 | ss << ", " << params_.screenshare[0].scroll_duration << "s scroll"; |
| 475 | if (params_.ss[0].streams.size() > 1) |
| 476 | ss << ", Stream #" << params_.ss[0].selected_stream; |
| 477 | if (params_.ss[0].num_spatial_layers > 1) |
| 478 | ss << ", Layer #" << params_.ss[0].selected_sl; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 479 | ss << ")"; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 480 | return ss.Release(); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 483 | void VideoQualityTest::CheckParamsAndInjectionComponents() { |
| 484 | if (injection_components_ == nullptr) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 485 | injection_components_ = std::make_unique<InjectionComponents>(); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 486 | } |
| 487 | if (!params_.config && injection_components_->sender_network == nullptr && |
| 488 | injection_components_->receiver_network == nullptr) { |
Artem Titov | 62ae178 | 2018-10-24 14:14:49 +0200 | [diff] [blame] | 489 | params_.config = BuiltInNetworkBehaviorConfig(); |
Artem Titov | f18b352 | 2018-08-28 16:54:24 +0200 | [diff] [blame] | 490 | } |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 491 | RTC_CHECK( |
| 492 | (params_.config && injection_components_->sender_network == nullptr && |
| 493 | injection_components_->receiver_network == nullptr) || |
| 494 | (!params_.config && injection_components_->sender_network != nullptr && |
| 495 | injection_components_->receiver_network != nullptr)); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 496 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
| 497 | // Iterate over primary and secondary video streams. |
| 498 | if (!params_.video[video_idx].enabled) |
| 499 | return; |
| 500 | // Add a default stream in none specified. |
| 501 | if (params_.ss[video_idx].streams.empty()) |
| 502 | params_.ss[video_idx].streams.push_back( |
| 503 | VideoQualityTest::DefaultVideoStream(params_, video_idx)); |
| 504 | if (params_.ss[video_idx].num_spatial_layers == 0) |
| 505 | params_.ss[video_idx].num_spatial_layers = 1; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 506 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 507 | if (params_.config) { |
| 508 | if (params_.config->loss_percent != 0 || |
| 509 | params_.config->queue_length_packets != 0) { |
| 510 | // Since LayerFilteringTransport changes the sequence numbers, we can't |
| 511 | // use that feature with pack loss, since the NACK request would end up |
| 512 | // retransmitting the wrong packets. |
| 513 | RTC_CHECK(params_.ss[video_idx].selected_sl == -1 || |
| 514 | params_.ss[video_idx].selected_sl == |
| 515 | params_.ss[video_idx].num_spatial_layers - 1); |
| 516 | RTC_CHECK(params_.video[video_idx].selected_tl == -1 || |
| 517 | params_.video[video_idx].selected_tl == |
| 518 | params_.video[video_idx].num_temporal_layers - 1); |
| 519 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 520 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 521 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 522 | // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as |
| 523 | // it does in some parts of the code? |
| 524 | RTC_CHECK_GE(params_.video[video_idx].max_bitrate_bps, |
| 525 | params_.video[video_idx].target_bitrate_bps); |
| 526 | RTC_CHECK_GE(params_.video[video_idx].target_bitrate_bps, |
| 527 | params_.video[video_idx].min_bitrate_bps); |
Ilya Nikolaevskiy | aec663e | 2019-02-27 12:52:11 +0100 | [diff] [blame] | 528 | int selected_stream = params_.ss[video_idx].selected_stream; |
Evan Shrubsole | 420ad1a | 2020-03-04 10:42:28 +0100 | [diff] [blame] | 529 | if (params_.video[video_idx].selected_tl > -1) { |
| 530 | RTC_CHECK_LT(selected_stream, params_.ss[video_idx].streams.size()) |
| 531 | << "Can not use --selected_tl when --selected_stream is all streams"; |
| 532 | int stream_tl = params_.ss[video_idx] |
| 533 | .streams[selected_stream] |
| 534 | .num_temporal_layers.value_or(1); |
| 535 | RTC_CHECK_LT(params_.video[video_idx].selected_tl, stream_tl); |
| 536 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 537 | RTC_CHECK_LE(params_.ss[video_idx].selected_stream, |
| 538 | params_.ss[video_idx].streams.size()); |
| 539 | for (const VideoStream& stream : params_.ss[video_idx].streams) { |
| 540 | RTC_CHECK_GE(stream.min_bitrate_bps, 0); |
| 541 | RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps); |
| 542 | RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps); |
| 543 | } |
| 544 | // TODO(ivica): Should we check if the sum of all streams/layers is equal to |
| 545 | // the total bitrate? We anyway have to update them in the case bitrate |
| 546 | // estimator changes the total bitrates. |
| 547 | RTC_CHECK_GE(params_.ss[video_idx].num_spatial_layers, 1); |
| 548 | RTC_CHECK_LE(params_.ss[video_idx].selected_sl, |
| 549 | params_.ss[video_idx].num_spatial_layers); |
| 550 | RTC_CHECK( |
| 551 | params_.ss[video_idx].spatial_layers.empty() || |
| 552 | params_.ss[video_idx].spatial_layers.size() == |
| 553 | static_cast<size_t>(params_.ss[video_idx].num_spatial_layers)); |
| 554 | if (params_.video[video_idx].codec == "VP8") { |
| 555 | RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1); |
| 556 | } else if (params_.video[video_idx].codec == "VP9") { |
| 557 | RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 1); |
| 558 | } |
| 559 | RTC_CHECK_GE(params_.call.num_thumbnails, 0); |
| 560 | if (params_.call.num_thumbnails > 0) { |
| 561 | RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1); |
| 562 | RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 3); |
| 563 | RTC_CHECK_EQ(params_.video[video_idx].num_temporal_layers, 3); |
| 564 | RTC_CHECK_EQ(params_.video[video_idx].codec, "VP8"); |
| 565 | } |
| 566 | // Dual streams with FEC not supported in tests yet. |
| 567 | RTC_CHECK(!params_.video[video_idx].flexfec || num_video_streams_ == 1); |
| 568 | RTC_CHECK(!params_.video[video_idx].ulpfec || num_video_streams_ == 1); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 569 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | // Static. |
| 573 | std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) { |
| 574 | // Parse comma separated nonnegative integers, where some elements may be |
| 575 | // empty. The empty values are replaced with -1. |
| 576 | // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40} |
| 577 | // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1} |
| 578 | std::vector<int> result; |
| 579 | if (str.empty()) |
| 580 | return result; |
| 581 | |
| 582 | const char* p = str.c_str(); |
| 583 | int value = -1; |
| 584 | int pos; |
| 585 | while (*p) { |
| 586 | if (*p == ',') { |
| 587 | result.push_back(value); |
| 588 | value = -1; |
| 589 | ++p; |
| 590 | continue; |
| 591 | } |
| 592 | RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1) |
| 593 | << "Unexpected non-number value."; |
| 594 | p += pos; |
| 595 | } |
| 596 | result.push_back(value); |
| 597 | return result; |
| 598 | } |
| 599 | |
| 600 | // Static. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 601 | VideoStream VideoQualityTest::DefaultVideoStream(const Params& params, |
| 602 | size_t video_idx) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 603 | VideoStream stream; |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 604 | stream.width = params.video[video_idx].width; |
| 605 | stream.height = params.video[video_idx].height; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 606 | stream.max_framerate = params.video[video_idx].fps; |
| 607 | stream.min_bitrate_bps = params.video[video_idx].min_bitrate_bps; |
| 608 | stream.target_bitrate_bps = params.video[video_idx].target_bitrate_bps; |
| 609 | stream.max_bitrate_bps = params.video[video_idx].max_bitrate_bps; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 610 | stream.max_qp = kDefaultMaxQp; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 611 | stream.num_temporal_layers = params.video[video_idx].num_temporal_layers; |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 612 | stream.active = true; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 613 | return stream; |
| 614 | } |
| 615 | |
| 616 | // Static. |
| 617 | VideoStream VideoQualityTest::DefaultThumbnailStream() { |
| 618 | VideoStream stream; |
| 619 | stream.width = 320; |
| 620 | stream.height = 180; |
| 621 | stream.max_framerate = 7; |
| 622 | stream.min_bitrate_bps = 7500; |
| 623 | stream.target_bitrate_bps = 37500; |
| 624 | stream.max_bitrate_bps = 50000; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 625 | stream.max_qp = kDefaultMaxQp; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 626 | return stream; |
| 627 | } |
| 628 | |
| 629 | // Static. |
| 630 | void VideoQualityTest::FillScalabilitySettings( |
| 631 | Params* params, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 632 | size_t video_idx, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 633 | const std::vector<std::string>& stream_descriptors, |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 634 | int num_streams, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 635 | size_t selected_stream, |
| 636 | int num_spatial_layers, |
| 637 | int selected_sl, |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 638 | InterLayerPredMode inter_layer_pred, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 639 | const std::vector<std::string>& sl_descriptors) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 640 | if (params->ss[video_idx].streams.empty() && |
| 641 | params->ss[video_idx].infer_streams) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 642 | webrtc::VideoEncoderConfig encoder_config; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 643 | encoder_config.codec_type = |
| 644 | PayloadStringToCodecType(params->video[video_idx].codec); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 645 | encoder_config.content_type = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 646 | params->screenshare[video_idx].enabled |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 647 | ? webrtc::VideoEncoderConfig::ContentType::kScreen |
| 648 | : webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 649 | encoder_config.max_bitrate_bps = params->video[video_idx].max_bitrate_bps; |
| 650 | encoder_config.min_transmit_bitrate_bps = |
| 651 | params->video[video_idx].min_transmit_bps; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 652 | encoder_config.number_of_streams = num_streams; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 653 | encoder_config.spatial_layers = params->ss[video_idx].spatial_layers; |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 654 | encoder_config.simulcast_layers = std::vector<VideoStream>(num_streams); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 655 | encoder_config.video_stream_factory = |
| 656 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 657 | params->video[video_idx].codec, kDefaultMaxQp, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 658 | params->screenshare[video_idx].enabled, true); |
| 659 | params->ss[video_idx].streams = |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 660 | encoder_config.video_stream_factory->CreateEncoderStreams( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 661 | static_cast<int>(params->video[video_idx].width), |
| 662 | static_cast<int>(params->video[video_idx].height), encoder_config); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 663 | } else { |
| 664 | // Read VideoStream and SpatialLayer elements from a list of comma separated |
| 665 | // lists. To use a default value for an element, use -1 or leave empty. |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 666 | // Validity checks performed in CheckParamsAndInjectionComponents. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 667 | RTC_CHECK(params->ss[video_idx].streams.empty()); |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 668 | for (const auto& descriptor : stream_descriptors) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 669 | if (descriptor.empty()) |
| 670 | continue; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 671 | VideoStream stream = |
| 672 | VideoQualityTest::DefaultVideoStream(*params, video_idx); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 673 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 674 | if (v[0] != -1) |
| 675 | stream.width = static_cast<size_t>(v[0]); |
| 676 | if (v[1] != -1) |
| 677 | stream.height = static_cast<size_t>(v[1]); |
| 678 | if (v[2] != -1) |
| 679 | stream.max_framerate = v[2]; |
| 680 | if (v[3] != -1) |
| 681 | stream.min_bitrate_bps = v[3]; |
| 682 | if (v[4] != -1) |
| 683 | stream.target_bitrate_bps = v[4]; |
| 684 | if (v[5] != -1) |
| 685 | stream.max_bitrate_bps = v[5]; |
| 686 | if (v.size() > 6 && v[6] != -1) |
| 687 | stream.max_qp = v[6]; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 688 | if (v.size() > 7 && v[7] != -1) { |
| 689 | stream.num_temporal_layers = v[7]; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 690 | } else { |
| 691 | // Automatic TL thresholds for more than two layers not supported. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 692 | RTC_CHECK_LE(params->video[video_idx].num_temporal_layers, 2); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 693 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 694 | params->ss[video_idx].streams.push_back(stream); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 695 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 696 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 697 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 698 | params->ss[video_idx].num_spatial_layers = std::max(1, num_spatial_layers); |
| 699 | params->ss[video_idx].selected_stream = selected_stream; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 700 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 701 | params->ss[video_idx].selected_sl = selected_sl; |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 702 | params->ss[video_idx].inter_layer_pred = inter_layer_pred; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 703 | RTC_CHECK(params->ss[video_idx].spatial_layers.empty()); |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 704 | for (const auto& descriptor : sl_descriptors) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 705 | if (descriptor.empty()) |
| 706 | continue; |
| 707 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
Sergey Silkin | a89800c | 2019-02-19 12:52:56 +0100 | [diff] [blame] | 708 | RTC_CHECK_EQ(v.size(), 8); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 709 | |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 710 | SpatialLayer layer = {0}; |
| 711 | layer.width = v[0]; |
| 712 | layer.height = v[1]; |
Sergey Silkin | a89800c | 2019-02-19 12:52:56 +0100 | [diff] [blame] | 713 | layer.maxFramerate = v[2]; |
| 714 | layer.numberOfTemporalLayers = v[3]; |
| 715 | layer.maxBitrate = v[4]; |
| 716 | layer.minBitrate = v[5]; |
| 717 | layer.targetBitrate = v[6]; |
| 718 | layer.qpMax = v[7]; |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 719 | layer.active = true; |
| 720 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 721 | params->ss[video_idx].spatial_layers.push_back(layer); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 725 | void VideoQualityTest::SetupVideo(Transport* send_transport, |
| 726 | Transport* recv_transport) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 727 | size_t total_streams_used = 0; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 728 | video_receive_configs_.clear(); |
| 729 | video_send_configs_.clear(); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 730 | video_encoder_configs_.clear(); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 731 | bool decode_all_receive_streams = true; |
| 732 | size_t num_video_substreams = params_.ss[0].streams.size(); |
| 733 | RTC_CHECK(num_video_streams_ > 0); |
| 734 | video_encoder_configs_.resize(num_video_streams_); |
Rasmus Brandt | 5894b6a | 2019-06-13 16:28:14 +0200 | [diff] [blame] | 735 | std::string generic_codec_name; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 736 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
| 737 | video_send_configs_.push_back(VideoSendStream::Config(send_transport)); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 738 | video_encoder_configs_.push_back(VideoEncoderConfig()); |
| 739 | num_video_substreams = params_.ss[video_idx].streams.size(); |
| 740 | RTC_CHECK_GT(num_video_substreams, 0); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 741 | for (size_t i = 0; i < num_video_substreams; ++i) |
| 742 | video_send_configs_[video_idx].rtp.ssrcs.push_back( |
| 743 | kVideoSendSsrcs[total_streams_used + i]); |
Qingsi Wang | 2d82ade | 2018-07-11 06:04:44 +0000 | [diff] [blame] | 744 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 745 | int payload_type; |
| 746 | if (params_.video[video_idx].codec == "H264") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 747 | payload_type = kPayloadTypeH264; |
| 748 | } else if (params_.video[video_idx].codec == "VP8") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 749 | payload_type = kPayloadTypeVP8; |
| 750 | } else if (params_.video[video_idx].codec == "VP9") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 751 | payload_type = kPayloadTypeVP9; |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 752 | } else if (params_.video[video_idx].codec == "multiplex") { |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 753 | payload_type = kPayloadTypeVP9; |
Emircan Uysaler | 7c03bdc | 2019-01-16 15:07:56 -0500 | [diff] [blame] | 754 | } else if (params_.video[video_idx].codec == "FakeCodec") { |
| 755 | payload_type = kFakeVideoSendPayloadType; |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 756 | } else { |
Rasmus Brandt | 5894b6a | 2019-06-13 16:28:14 +0200 | [diff] [blame] | 757 | RTC_CHECK(generic_codec_name.empty() || |
| 758 | generic_codec_name == params_.video[video_idx].codec) |
| 759 | << "Supplying multiple generic codecs is unsupported."; |
| 760 | RTC_LOG(LS_INFO) << "Treating codec " << params_.video[video_idx].codec |
| 761 | << " as generic."; |
| 762 | payload_type = kPayloadTypeGeneric; |
| 763 | generic_codec_name = params_.video[video_idx].codec; |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 764 | } |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 765 | video_send_configs_[video_idx].encoder_settings.encoder_factory = |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 766 | (video_idx == 0) ? &video_encoder_factory_with_analyzer_ |
| 767 | : &video_encoder_factory_; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 768 | video_send_configs_[video_idx].encoder_settings.bitrate_allocator_factory = |
| 769 | video_bitrate_allocator_factory_.get(); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 770 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 771 | video_send_configs_[video_idx].rtp.payload_name = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 772 | params_.video[video_idx].codec; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 773 | video_send_configs_[video_idx].rtp.payload_type = payload_type; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 774 | video_send_configs_[video_idx].rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 775 | video_send_configs_[video_idx].rtp.rtx.payload_type = kSendRtxPayloadType; |
| 776 | for (size_t i = 0; i < num_video_substreams; ++i) { |
| 777 | video_send_configs_[video_idx].rtp.rtx.ssrcs.push_back( |
| 778 | kSendRtxSsrcs[i + total_streams_used]); |
ilnik | 9fd9f6c | 2017-03-02 08:10:10 -0800 | [diff] [blame] | 779 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 780 | video_send_configs_[video_idx].rtp.extensions.clear(); |
| 781 | if (params_.call.send_side_bwe) { |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 782 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
| 783 | RtpExtension::kTransportSequenceNumberUri, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 784 | kTransportSequenceNumberExtensionId); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 785 | } else { |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 786 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 787 | RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 788 | } |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 789 | |
| 790 | if (params_.call.generic_descriptor) { |
| 791 | // The generic descriptor is currently behind a field trial, so it needs |
| 792 | // to be set for this flag to have any effect. |
| 793 | // TODO(philipel): Remove this check when the experiment is removed. |
| 794 | RTC_CHECK(field_trial::IsEnabled("WebRTC-GenericDescriptor")); |
| 795 | |
| 796 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
Elad Alon | ccb9b75 | 2019-02-19 13:01:31 +0100 | [diff] [blame] | 797 | RtpExtension::kGenericFrameDescriptorUri00, |
| 798 | kGenericFrameDescriptorExtensionId00); |
| 799 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
| 800 | RtpExtension::kGenericFrameDescriptorUri01, |
| 801 | kGenericFrameDescriptorExtensionId01); |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 805 | RtpExtension::kVideoContentTypeUri, kVideoContentTypeExtensionId); |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 806 | video_send_configs_[video_idx].rtp.extensions.emplace_back( |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 807 | RtpExtension::kVideoTimingUri, kVideoTimingExtensionId); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 808 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 809 | video_encoder_configs_[video_idx].video_format.name = |
| 810 | params_.video[video_idx].codec; |
| 811 | |
Emircan Uysaler | 0823eec | 2018-07-13 17:10:00 -0700 | [diff] [blame] | 812 | video_encoder_configs_[video_idx].video_format.parameters = |
| 813 | params_.video[video_idx].sdp_params; |
| 814 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 815 | video_encoder_configs_[video_idx].codec_type = |
| 816 | PayloadStringToCodecType(params_.video[video_idx].codec); |
| 817 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 818 | video_encoder_configs_[video_idx].min_transmit_bitrate_bps = |
| 819 | params_.video[video_idx].min_transmit_bps; |
| 820 | |
| 821 | video_send_configs_[video_idx].suspend_below_min_bitrate = |
| 822 | params_.video[video_idx].suspend_below_min_bitrate; |
| 823 | |
| 824 | video_encoder_configs_[video_idx].number_of_streams = |
| 825 | params_.ss[video_idx].streams.size(); |
| 826 | video_encoder_configs_[video_idx].max_bitrate_bps = 0; |
| 827 | for (size_t i = 0; i < params_.ss[video_idx].streams.size(); ++i) { |
| 828 | video_encoder_configs_[video_idx].max_bitrate_bps += |
| 829 | params_.ss[video_idx].streams[i].max_bitrate_bps; |
| 830 | } |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 831 | video_encoder_configs_[video_idx].simulcast_layers = |
| 832 | std::vector<VideoStream>(params_.ss[video_idx].streams.size()); |
| 833 | if (!params_.ss[video_idx].infer_streams) { |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 834 | video_encoder_configs_[video_idx].simulcast_layers = |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 835 | params_.ss[video_idx].streams; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 836 | } |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 837 | video_encoder_configs_[video_idx].video_stream_factory = |
| 838 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
| 839 | params_.video[video_idx].codec, |
| 840 | params_.ss[video_idx].streams[0].max_qp, |
| 841 | params_.screenshare[video_idx].enabled, true); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 842 | |
| 843 | video_encoder_configs_[video_idx].spatial_layers = |
| 844 | params_.ss[video_idx].spatial_layers; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 845 | decode_all_receive_streams = params_.ss[video_idx].selected_stream == |
| 846 | params_.ss[video_idx].streams.size(); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 847 | absl::optional<int> decode_sub_stream; |
| 848 | if (!decode_all_receive_streams) |
| 849 | decode_sub_stream = params_.ss[video_idx].selected_stream; |
| 850 | CreateMatchingVideoReceiveConfigs( |
| 851 | video_send_configs_[video_idx], recv_transport, |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 852 | params_.call.send_side_bwe, &video_decoder_factory_, decode_sub_stream, |
| 853 | true, kNackRtpHistoryMs); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 854 | |
| 855 | if (params_.screenshare[video_idx].enabled) { |
| 856 | // Fill out codec settings. |
| 857 | video_encoder_configs_[video_idx].content_type = |
| 858 | VideoEncoderConfig::ContentType::kScreen; |
Taylor Brandstetter | 49fcc10 | 2018-05-16 14:20:41 -0700 | [diff] [blame] | 859 | degradation_preference_ = DegradationPreference::MAINTAIN_RESOLUTION; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 860 | if (params_.video[video_idx].codec == "VP8") { |
| 861 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 862 | vp8_settings.denoisingOn = false; |
| 863 | vp8_settings.frameDroppingOn = false; |
| 864 | vp8_settings.numberOfTemporalLayers = static_cast<unsigned char>( |
| 865 | params_.video[video_idx].num_temporal_layers); |
| 866 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 867 | new rtc::RefCountedObject< |
| 868 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
| 869 | } else if (params_.video[video_idx].codec == "VP9") { |
| 870 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 871 | vp9_settings.denoisingOn = false; |
| 872 | vp9_settings.frameDroppingOn = false; |
Ilya Nikolaevskiy | eac08bf | 2020-03-10 09:50:26 +0000 | [diff] [blame] | 873 | vp9_settings.automaticResizeOn = false; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 874 | vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>( |
| 875 | params_.video[video_idx].num_temporal_layers); |
| 876 | vp9_settings.numberOfSpatialLayers = static_cast<unsigned char>( |
| 877 | params_.ss[video_idx].num_spatial_layers); |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 878 | vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred; |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 879 | // High FPS vp9 screenshare requires flexible mode. |
Ilya Nikolaevskiy | 5c18a5f | 2019-05-24 11:51:31 +0200 | [diff] [blame] | 880 | if (params_.ss[video_idx].num_spatial_layers > 1) { |
Ilya Nikolaevskiy | 5546aef | 2018-12-04 15:54:52 +0100 | [diff] [blame] | 881 | vp9_settings.flexibleMode = true; |
| 882 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 883 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 884 | new rtc::RefCountedObject< |
| 885 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
| 886 | } |
| 887 | } else if (params_.ss[video_idx].num_spatial_layers > 1) { |
| 888 | // If SVC mode without screenshare, still need to set codec specifics. |
| 889 | RTC_CHECK(params_.video[video_idx].codec == "VP9"); |
| 890 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 891 | vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>( |
| 892 | params_.video[video_idx].num_temporal_layers); |
| 893 | vp9_settings.numberOfSpatialLayers = |
| 894 | static_cast<unsigned char>(params_.ss[video_idx].num_spatial_layers); |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 895 | vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred; |
Ilya Nikolaevskiy | eac08bf | 2020-03-10 09:50:26 +0000 | [diff] [blame] | 896 | vp9_settings.automaticResizeOn = false; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 897 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 898 | new rtc::RefCountedObject< |
| 899 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 900 | } else if (params_.video[video_idx].automatic_scaling) { |
| 901 | if (params_.video[video_idx].codec == "VP8") { |
| 902 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 903 | vp8_settings.automaticResizeOn = true; |
| 904 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 905 | new rtc::RefCountedObject< |
| 906 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
| 907 | } else if (params_.video[video_idx].codec == "VP9") { |
| 908 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
Ilya Nikolaevskiy | eac08bf | 2020-03-10 09:50:26 +0000 | [diff] [blame] | 909 | // Only enable quality scaler for single spatial layer. |
| 910 | vp9_settings.automaticResizeOn = |
| 911 | params_.ss[video_idx].num_spatial_layers == 1; |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 912 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 913 | new rtc::RefCountedObject< |
| 914 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
Stefan Holmer | 1f7a008 | 2019-01-11 15:39:08 +0100 | [diff] [blame] | 915 | } else if (params_.video[video_idx].codec == "H264") { |
| 916 | // Quality scaling is always on for H.264. |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 917 | } else { |
| 918 | RTC_NOTREACHED() << "Automatic scaling not supported for codec " |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 919 | << params_.video[video_idx].codec << ", stream " |
| 920 | << video_idx; |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 921 | } |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 922 | } else { |
| 923 | // Default mode. Single SL, no automatic_scaling, |
| 924 | if (params_.video[video_idx].codec == "VP8") { |
| 925 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 926 | vp8_settings.automaticResizeOn = false; |
| 927 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 928 | new rtc::RefCountedObject< |
| 929 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
| 930 | } else if (params_.video[video_idx].codec == "VP9") { |
| 931 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 932 | vp9_settings.automaticResizeOn = false; |
| 933 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 934 | new rtc::RefCountedObject< |
| 935 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
| 936 | } else if (params_.video[video_idx].codec == "H264") { |
| 937 | VideoCodecH264 h264_settings = VideoEncoder::GetDefaultH264Settings(); |
| 938 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 939 | new rtc::RefCountedObject< |
| 940 | VideoEncoderConfig::H264EncoderSpecificSettings>(h264_settings); |
| 941 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 942 | } |
| 943 | total_streams_used += num_video_substreams; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 944 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 945 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 946 | // FEC supported only for single video stream mode yet. |
| 947 | if (params_.video[0].flexfec) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 948 | if (decode_all_receive_streams) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 949 | SetSendFecConfig(GetVideoSendConfig()->rtp.ssrcs); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 950 | } else { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 951 | SetSendFecConfig({kVideoSendSsrcs[params_.ss[0].selected_stream]}); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 952 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 953 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 954 | CreateMatchingFecConfig(recv_transport, *GetVideoSendConfig()); |
| 955 | GetFlexFecConfig()->transport_cc = params_.call.send_side_bwe; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 956 | if (params_.call.send_side_bwe) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 957 | GetFlexFecConfig()->rtp_header_extensions.push_back( |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 958 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 959 | kTransportSequenceNumberExtensionId)); |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 960 | } else { |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 961 | GetFlexFecConfig()->rtp_header_extensions.push_back( |
| 962 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId)); |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 963 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 964 | } |
| 965 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 966 | if (params_.video[0].ulpfec) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 967 | SetSendUlpFecConfig(GetVideoSendConfig()); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 968 | if (decode_all_receive_streams) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 969 | for (auto& receive_config : video_receive_configs_) { |
| 970 | SetReceiveUlpFecConfig(&receive_config); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 971 | } |
| 972 | } else { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 973 | SetReceiveUlpFecConfig( |
| 974 | &video_receive_configs_[params_.ss[0].selected_stream]); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 975 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 976 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 977 | } |
| 978 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 979 | void VideoQualityTest::SetupThumbnails(Transport* send_transport, |
| 980 | Transport* recv_transport) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 981 | for (int i = 0; i < params_.call.num_thumbnails; ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 982 | // Thumbnails will be send in the other way: from receiver_call to |
| 983 | // sender_call. |
| 984 | VideoSendStream::Config thumbnail_send_config(recv_transport); |
| 985 | thumbnail_send_config.rtp.ssrcs.push_back(kThumbnailSendSsrcStart + i); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 986 | // TODO(nisse): Could use a simpler VP8-only encoder factory. |
| 987 | thumbnail_send_config.encoder_settings.encoder_factory = |
| 988 | &video_encoder_factory_; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 989 | thumbnail_send_config.encoder_settings.bitrate_allocator_factory = |
| 990 | video_bitrate_allocator_factory_.get(); |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 991 | thumbnail_send_config.rtp.payload_name = params_.video[0].codec; |
| 992 | thumbnail_send_config.rtp.payload_type = kPayloadTypeVP8; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 993 | thumbnail_send_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 994 | thumbnail_send_config.rtp.rtx.payload_type = kSendRtxPayloadType; |
| 995 | thumbnail_send_config.rtp.rtx.ssrcs.push_back(kThumbnailRtxSsrcStart + i); |
| 996 | thumbnail_send_config.rtp.extensions.clear(); |
| 997 | if (params_.call.send_side_bwe) { |
| 998 | thumbnail_send_config.rtp.extensions.push_back( |
| 999 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 1000 | kTransportSequenceNumberExtensionId)); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1001 | } else { |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 1002 | thumbnail_send_config.rtp.extensions.push_back( |
| 1003 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeExtensionId)); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | VideoEncoderConfig thumbnail_encoder_config; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 1007 | thumbnail_encoder_config.codec_type = kVideoCodecVP8; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1008 | thumbnail_encoder_config.video_format.name = "VP8"; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1009 | thumbnail_encoder_config.min_transmit_bitrate_bps = 7500; |
| 1010 | thumbnail_send_config.suspend_below_min_bitrate = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1011 | params_.video[0].suspend_below_min_bitrate; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1012 | thumbnail_encoder_config.number_of_streams = 1; |
| 1013 | thumbnail_encoder_config.max_bitrate_bps = 50000; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 1014 | std::vector<VideoStream> streams{params_.ss[0].streams[0]}; |
| 1015 | thumbnail_encoder_config.video_stream_factory = |
| 1016 | new rtc::RefCountedObject<VideoStreamFactory>(streams); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1017 | thumbnail_encoder_config.spatial_layers = params_.ss[0].spatial_layers; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1018 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1019 | thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy()); |
| 1020 | thumbnail_send_configs_.push_back(thumbnail_send_config.Copy()); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1021 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1022 | AddMatchingVideoReceiveConfigs( |
| 1023 | &thumbnail_receive_configs_, thumbnail_send_config, send_transport, |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 1024 | params_.call.send_side_bwe, &video_decoder_factory_, absl::nullopt, |
| 1025 | false, kNackRtpHistoryMs); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1026 | } |
| 1027 | for (size_t i = 0; i < thumbnail_send_configs_.size(); ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1028 | thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream( |
| 1029 | thumbnail_send_configs_[i].Copy(), |
| 1030 | thumbnail_encoder_configs_[i].Copy())); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1031 | } |
| 1032 | for (size_t i = 0; i < thumbnail_receive_configs_.size(); ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1033 | thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream( |
| 1034 | thumbnail_receive_configs_[i].Copy())); |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | void VideoQualityTest::DestroyThumbnailStreams() { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1039 | for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1040 | receiver_call_->DestroyVideoSendStream(thumbnail_send_stream); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1041 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1042 | thumbnail_send_streams_.clear(); |
| 1043 | for (VideoReceiveStream* thumbnail_receive_stream : |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1044 | thumbnail_receive_streams_) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1045 | sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1046 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1047 | thumbnail_send_streams_.clear(); |
| 1048 | thumbnail_receive_streams_.clear(); |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1049 | for (std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>& video_capturer : |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1050 | thumbnail_capturers_) { |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1051 | video_capturer.reset(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1052 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1053 | } |
| 1054 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1055 | void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) { |
| 1056 | VideoStream thumbnail = DefaultThumbnailStream(); |
| 1057 | for (size_t i = 0; i < num_thumbnail_streams; ++i) { |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1058 | auto frame_generator_capturer = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1059 | std::make_unique<test::FrameGeneratorCapturer>( |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1060 | clock_, |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1061 | test::CreateSquareFrameGenerator(static_cast<int>(thumbnail.width), |
| 1062 | static_cast<int>(thumbnail.height), |
| 1063 | absl::nullopt, absl::nullopt), |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1064 | thumbnail.max_framerate, *task_queue_factory_); |
| 1065 | EXPECT_TRUE(frame_generator_capturer->Init()); |
| 1066 | thumbnail_capturers_.push_back(std::move(frame_generator_capturer)); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1070 | std::unique_ptr<test::FrameGeneratorInterface> |
| 1071 | VideoQualityTest::CreateFrameGenerator(size_t video_idx) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1072 | // Setup frame generator. |
| 1073 | const size_t kWidth = 1850; |
| 1074 | const size_t kHeight = 1110; |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1075 | std::unique_ptr<test::FrameGeneratorInterface> frame_generator; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1076 | if (params_.screenshare[video_idx].generate_slides) { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1077 | frame_generator = test::CreateSlideFrameGenerator( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1078 | kWidth, kHeight, |
| 1079 | params_.screenshare[video_idx].slide_change_interval * |
| 1080 | params_.video[video_idx].fps); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1081 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1082 | std::vector<std::string> slides = params_.screenshare[video_idx].slides; |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1083 | if (slides.empty()) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1084 | slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); |
| 1085 | slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); |
| 1086 | slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); |
| 1087 | slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); |
| 1088 | } |
| 1089 | if (params_.screenshare[video_idx].scroll_duration == 0) { |
| 1090 | // Cycle image every slide_change_interval seconds. |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1091 | frame_generator = test::CreateFromYuvFileFrameGenerator( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1092 | slides, kWidth, kHeight, |
| 1093 | params_.screenshare[video_idx].slide_change_interval * |
| 1094 | params_.video[video_idx].fps); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1095 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1096 | RTC_CHECK_LE(params_.video[video_idx].width, kWidth); |
| 1097 | RTC_CHECK_LE(params_.video[video_idx].height, kHeight); |
| 1098 | RTC_CHECK_GT(params_.screenshare[video_idx].slide_change_interval, 0); |
| 1099 | const int kPauseDurationMs = |
| 1100 | (params_.screenshare[video_idx].slide_change_interval - |
| 1101 | params_.screenshare[video_idx].scroll_duration) * |
| 1102 | 1000; |
| 1103 | RTC_CHECK_LE(params_.screenshare[video_idx].scroll_duration, |
| 1104 | params_.screenshare[video_idx].slide_change_interval); |
| 1105 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1106 | frame_generator = test::CreateScrollingInputFromYuvFilesFrameGenerator( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1107 | clock_, slides, kWidth, kHeight, params_.video[video_idx].width, |
| 1108 | params_.video[video_idx].height, |
| 1109 | params_.screenshare[video_idx].scroll_duration * 1000, |
| 1110 | kPauseDurationMs); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1111 | } |
| 1112 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1113 | return frame_generator; |
| 1114 | } |
| 1115 | |
| 1116 | void VideoQualityTest::CreateCapturers() { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1117 | RTC_DCHECK(video_sources_.empty()); |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1118 | video_sources_.resize(num_video_streams_); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1119 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1120 | std::unique_ptr<test::FrameGeneratorInterface> frame_generator; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1121 | if (params_.screenshare[video_idx].enabled) { |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1122 | frame_generator = CreateFrameGenerator(video_idx); |
| 1123 | } else if (params_.video[video_idx].clip_path == "Generator") { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1124 | frame_generator = test::CreateSquareFrameGenerator( |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1125 | static_cast<int>(params_.video[video_idx].width), |
| 1126 | static_cast<int>(params_.video[video_idx].height), absl::nullopt, |
| 1127 | absl::nullopt); |
| 1128 | } else if (params_.video[video_idx].clip_path == "GeneratorI420A") { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1129 | frame_generator = test::CreateSquareFrameGenerator( |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1130 | static_cast<int>(params_.video[video_idx].width), |
| 1131 | static_cast<int>(params_.video[video_idx].height), |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1132 | test::FrameGeneratorInterface::OutputType::kI420A, absl::nullopt); |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1133 | } else if (params_.video[video_idx].clip_path == "GeneratorI010") { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1134 | frame_generator = test::CreateSquareFrameGenerator( |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1135 | static_cast<int>(params_.video[video_idx].width), |
| 1136 | static_cast<int>(params_.video[video_idx].height), |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1137 | test::FrameGeneratorInterface::OutputType::kI010, absl::nullopt); |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1138 | } else if (params_.video[video_idx].clip_path.empty()) { |
| 1139 | video_sources_[video_idx] = test::CreateVideoCapturer( |
| 1140 | params_.video[video_idx].width, params_.video[video_idx].height, |
| 1141 | params_.video[video_idx].fps, |
| 1142 | params_.video[video_idx].capture_device_index); |
| 1143 | if (video_sources_[video_idx]) { |
| 1144 | continue; |
| 1145 | } else { |
| 1146 | // Failed to get actual camera, use chroma generator as backup. |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1147 | frame_generator = test::CreateSquareFrameGenerator( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1148 | static_cast<int>(params_.video[video_idx].width), |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 1149 | static_cast<int>(params_.video[video_idx].height), absl::nullopt, |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1150 | absl::nullopt); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1151 | } |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1152 | } else { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 1153 | frame_generator = test::CreateFromYuvFileFrameGenerator( |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1154 | {params_.video[video_idx].clip_path}, params_.video[video_idx].width, |
| 1155 | params_.video[video_idx].height, 1); |
| 1156 | ASSERT_TRUE(frame_generator) << "Could not create capturer for " |
| 1157 | << params_.video[video_idx].clip_path |
| 1158 | << ".yuv. Is this file present?"; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1159 | } |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1160 | ASSERT_TRUE(frame_generator); |
| 1161 | auto frame_generator_capturer = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1162 | std::make_unique<test::FrameGeneratorCapturer>( |
Danil Chapovalov | 908e22e | 2019-04-18 14:34:16 +0200 | [diff] [blame] | 1163 | clock_, std::move(frame_generator), params_.video[video_idx].fps, |
| 1164 | *task_queue_factory_); |
| 1165 | EXPECT_TRUE(frame_generator_capturer->Init()); |
| 1166 | video_sources_[video_idx] = std::move(frame_generator_capturer); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1167 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1170 | void VideoQualityTest::StartAudioStreams() { |
| 1171 | audio_send_stream_->Start(); |
| 1172 | for (AudioReceiveStream* audio_recv_stream : audio_receive_streams_) |
| 1173 | audio_recv_stream->Start(); |
| 1174 | } |
| 1175 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1176 | void VideoQualityTest::StartThumbnails() { |
| 1177 | for (VideoSendStream* send_stream : thumbnail_send_streams_) |
| 1178 | send_stream->Start(); |
| 1179 | for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_) |
| 1180 | receive_stream->Start(); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | void VideoQualityTest::StopThumbnails() { |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1184 | for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_) |
| 1185 | receive_stream->Stop(); |
| 1186 | for (VideoSendStream* send_stream : thumbnail_send_streams_) |
| 1187 | send_stream->Stop(); |
| 1188 | } |
| 1189 | |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 1190 | std::unique_ptr<test::LayerFilteringTransport> |
| 1191 | VideoQualityTest::CreateSendTransport() { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1192 | std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr; |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1193 | if (injection_components_->sender_network == nullptr) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1194 | network_behavior = std::make_unique<SimulatedNetwork>(*params_.config); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1195 | } else { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1196 | network_behavior = std::move(injection_components_->sender_network); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1197 | } |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1198 | return std::make_unique<test::LayerFilteringTransport>( |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1199 | task_queue(), |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1200 | std::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)), |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 1201 | sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9, |
| 1202 | params_.video[0].selected_tl, params_.ss[0].selected_sl, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1203 | payload_type_map_, kVideoSendSsrcs[0], |
| 1204 | static_cast<uint32_t>(kVideoSendSsrcs[0] + params_.ss[0].streams.size() - |
| 1205 | 1)); |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | std::unique_ptr<test::DirectTransport> |
| 1209 | VideoQualityTest::CreateReceiveTransport() { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1210 | std::unique_ptr<NetworkBehaviorInterface> network_behavior = nullptr; |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1211 | if (injection_components_->receiver_network == nullptr) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1212 | network_behavior = std::make_unique<SimulatedNetwork>(*params_.config); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1213 | } else { |
Artem Titov | 8ea1e9d | 2018-10-04 14:46:31 +0200 | [diff] [blame] | 1214 | network_behavior = std::move(injection_components_->receiver_network); |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1215 | } |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1216 | return std::make_unique<test::DirectTransport>( |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1217 | task_queue(), |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1218 | std::make_unique<FakeNetworkPipe>(clock_, std::move(network_behavior)), |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 1219 | receiver_call_.get(), payload_type_map_); |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1222 | void VideoQualityTest::RunWithAnalyzer(const Params& params) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1223 | num_video_streams_ = params.call.dual_video ? 2 : 1; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1224 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 1225 | std::unique_ptr<test::DirectTransport> recv_transport; |
| 1226 | FILE* graph_data_output_file = nullptr; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1227 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1228 | params_ = params; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1229 | // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to |
| 1230 | // differentiate between the analyzer and the renderer case. |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1231 | CheckParamsAndInjectionComponents(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1232 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1233 | if (!params_.analyzer.graph_data_output_filename.empty()) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1234 | graph_data_output_file = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1235 | fopen(params_.analyzer.graph_data_output_filename.c_str(), "w"); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 1236 | RTC_CHECK(graph_data_output_file) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1237 | << "Can't open the file " << params_.analyzer.graph_data_output_filename |
| 1238 | << "!"; |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1239 | } |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1240 | |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1241 | if (!params.logging.rtc_event_log_name.empty()) { |
Danil Chapovalov | 304ea5f | 2019-04-11 15:18:18 +0200 | [diff] [blame] | 1242 | send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( |
| 1243 | RtcEventLog::EncodingType::Legacy); |
| 1244 | recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( |
| 1245 | RtcEventLog::EncodingType::Legacy); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1246 | std::unique_ptr<RtcEventLogOutputFile> send_output( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1247 | std::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1248 | params.logging.rtc_event_log_name + "_send", |
| 1249 | RtcEventLog::kUnlimitedOutput)); |
| 1250 | std::unique_ptr<RtcEventLogOutputFile> recv_output( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1251 | std::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1252 | params.logging.rtc_event_log_name + "_recv", |
| 1253 | RtcEventLog::kUnlimitedOutput)); |
| 1254 | bool event_log_started = |
| 1255 | send_event_log_->StartLogging(std::move(send_output), |
| 1256 | RtcEventLog::kImmediateOutput) && |
| 1257 | recv_event_log_->StartLogging(std::move(recv_output), |
| 1258 | RtcEventLog::kImmediateOutput); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1259 | RTC_DCHECK(event_log_started); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1260 | } else { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1261 | send_event_log_ = std::make_unique<RtcEventLogNull>(); |
| 1262 | recv_event_log_ = std::make_unique<RtcEventLogNull>(); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1265 | SendTask(RTC_FROM_HERE, task_queue(), |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 1266 | [this, ¶ms, &send_transport, &recv_transport]() { |
| 1267 | Call::Config send_call_config(send_event_log_.get()); |
| 1268 | Call::Config recv_call_config(recv_event_log_.get()); |
| 1269 | send_call_config.bitrate_config = params.call.call_bitrate_config; |
| 1270 | recv_call_config.bitrate_config = params.call.call_bitrate_config; |
| 1271 | if (params_.audio.enabled) |
| 1272 | InitializeAudioDevice(&send_call_config, &recv_call_config, |
| 1273 | params_.audio.use_real_adm); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1274 | |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 1275 | CreateCalls(send_call_config, recv_call_config); |
| 1276 | send_transport = CreateSendTransport(); |
| 1277 | recv_transport = CreateReceiveTransport(); |
| 1278 | }); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1279 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1280 | std::string graph_title = params_.analyzer.graph_title; |
| 1281 | if (graph_title.empty()) |
| 1282 | graph_title = VideoQualityTest::GenerateGraphTitle(); |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame] | 1283 | bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest"); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1284 | analyzer_ = std::make_unique<VideoAnalyzer>( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1285 | send_transport.get(), params_.analyzer.test_label, |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1286 | params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold, |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 1287 | is_quick_test_enabled |
| 1288 | ? kFramesSentInQuickTest |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1289 | : params_.analyzer.test_durations_secs * params_.video[0].fps, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1290 | graph_data_output_file, graph_title, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1291 | kVideoSendSsrcs[params_.ss[0].selected_stream], |
| 1292 | kSendRtxSsrcs[params_.ss[0].selected_stream], |
| 1293 | static_cast<size_t>(params_.ss[0].selected_stream), |
| 1294 | params.ss[0].selected_sl, params_.video[0].selected_tl, |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 1295 | is_quick_test_enabled, clock_, params_.logging.rtp_dump_name, |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1296 | task_queue()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1297 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1298 | SendTask(RTC_FROM_HERE, task_queue(), [&]() { |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1299 | analyzer_->SetCall(sender_call_.get()); |
| 1300 | analyzer_->SetReceiver(receiver_call_->Receiver()); |
| 1301 | send_transport->SetReceiver(analyzer_.get()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1302 | recv_transport->SetReceiver(sender_call_->Receiver()); |
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 | SetupVideo(analyzer_.get(), recv_transport.get()); |
| 1305 | SetupThumbnails(analyzer_.get(), recv_transport.get()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1306 | video_receive_configs_[params_.ss[0].selected_stream].renderer = |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1307 | analyzer_.get(); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 1308 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1309 | CreateFlexfecStreams(); |
| 1310 | CreateVideoStreams(); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1311 | analyzer_->SetSendStream(video_send_streams_[0]); |
Ilya Nikolaevskiy | d47d3eb | 2019-01-21 16:27:17 +0100 | [diff] [blame] | 1312 | analyzer_->SetReceiveStream( |
| 1313 | video_receive_streams_[params_.ss[0].selected_stream]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1314 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1315 | GetVideoSendStream()->SetSource(analyzer_->OutputInterface(), |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1316 | degradation_preference_); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1317 | SetupThumbnailCapturers(params_.call.num_thumbnails); |
| 1318 | for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) { |
| 1319 | thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(), |
| 1320 | degradation_preference_); |
| 1321 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1322 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1323 | CreateCapturers(); |
ivica | c1cc854 | 2015-10-08 03:44:06 -0700 | [diff] [blame] | 1324 | |
Stefan Holmer | 1f7a008 | 2019-01-11 15:39:08 +0100 | [diff] [blame] | 1325 | analyzer_->SetSource(video_sources_[0].get(), true); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1326 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1327 | 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] | 1328 | video_send_streams_[video_idx]->SetSource(video_sources_[video_idx].get(), |
| 1329 | degradation_preference_); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1332 | if (params_.audio.enabled) { |
| 1333 | SetupAudio(send_transport.get()); |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1334 | StartAudioStreams(); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1335 | analyzer_->SetAudioReceiveStream(audio_receive_streams_[0]); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1336 | } |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1337 | StartVideoStreams(); |
| 1338 | StartThumbnails(); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1339 | analyzer_->StartMeasuringCpuProcessTime(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1340 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1341 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1342 | analyzer_->Wait(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1343 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1344 | SendTask(RTC_FROM_HERE, task_queue(), [&]() { |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1345 | StopThumbnails(); |
| 1346 | Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1347 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1348 | DestroyStreams(); |
| 1349 | DestroyThumbnailStreams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1350 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1351 | if (graph_data_output_file) |
| 1352 | fclose(graph_data_output_file); |
| 1353 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1354 | send_transport.reset(); |
| 1355 | recv_transport.reset(); |
| 1356 | |
| 1357 | DestroyCalls(); |
| 1358 | }); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 1359 | analyzer_ = nullptr; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1362 | rtc::scoped_refptr<AudioDeviceModule> VideoQualityTest::CreateAudioDevice() { |
| 1363 | #ifdef WEBRTC_WIN |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1364 | RTC_LOG(INFO) << "Using latest version of ADM on Windows"; |
| 1365 | // We must initialize the COM library on a thread before we calling any of |
| 1366 | // the library functions. All COM functions in the ADM will return |
| 1367 | // CO_E_NOTINITIALIZED otherwise. The legacy ADM for Windows used internal |
| 1368 | // COM initialization but the new ADM requires COM to be initialized |
| 1369 | // externally. |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1370 | com_initializer_ = std::make_unique<webrtc_win::ScopedCOMInitializer>( |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1371 | webrtc_win::ScopedCOMInitializer::kMTA); |
| 1372 | RTC_CHECK(com_initializer_->Succeeded()); |
| 1373 | RTC_CHECK(webrtc_win::core_audio_utility::IsSupported()); |
| 1374 | RTC_CHECK(webrtc_win::core_audio_utility::IsMMCSSSupported()); |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 1375 | return CreateWindowsCoreAudioAudioDeviceModule(task_queue_factory_.get()); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1376 | #else |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1377 | // Use legacy factory method on all platforms except Windows. |
Danil Chapovalov | 1c41be6 | 2019-04-01 09:16:12 +0200 | [diff] [blame] | 1378 | return AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio, |
| 1379 | task_queue_factory_.get()); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1380 | #endif |
| 1381 | } |
| 1382 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1383 | void VideoQualityTest::InitializeAudioDevice(Call::Config* send_call_config, |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1384 | Call::Config* recv_call_config, |
| 1385 | bool use_real_adm) { |
| 1386 | rtc::scoped_refptr<AudioDeviceModule> audio_device; |
| 1387 | if (use_real_adm) { |
| 1388 | // Run test with real ADM (using default audio devices) if user has |
| 1389 | // explicitly set the --audio and --use_real_adm command-line flags. |
| 1390 | audio_device = CreateAudioDevice(); |
| 1391 | } else { |
| 1392 | // By default, create a test ADM which fakes audio. |
Danil Chapovalov | 08fa953 | 2019-06-12 11:49:17 +0000 | [diff] [blame] | 1393 | audio_device = TestAudioDeviceModule::Create( |
| 1394 | task_queue_factory_.get(), |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1395 | TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, 48000), |
| 1396 | TestAudioDeviceModule::CreateDiscardRenderer(48000), 1.f); |
| 1397 | } |
| 1398 | RTC_CHECK(audio_device); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1399 | |
| 1400 | AudioState::Config audio_state_config; |
| 1401 | audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
| 1402 | audio_state_config.audio_processing = AudioProcessingBuilder().Create(); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1403 | audio_state_config.audio_device_module = audio_device; |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1404 | send_call_config->audio_state = AudioState::Create(audio_state_config); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1405 | recv_call_config->audio_state = AudioState::Create(audio_state_config); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1406 | if (use_real_adm) { |
| 1407 | // The real ADM requires extra initialization: setting default devices, |
| 1408 | // setting up number of channels etc. Helper class also calls |
| 1409 | // AudioDeviceModule::Init(). |
| 1410 | webrtc::adm_helpers::Init(audio_device.get()); |
| 1411 | } else { |
| 1412 | audio_device->Init(); |
| 1413 | } |
| 1414 | // Always initialize the ADM before injecting a valid audio transport. |
| 1415 | RTC_CHECK(audio_device->RegisterAudioCallback( |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1416 | send_call_config->audio_state->audio_transport()) == 0); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1417 | } |
| 1418 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1419 | void VideoQualityTest::SetupAudio(Transport* transport) { |
Bjorn A Mellem | 7a9a092 | 2019-11-26 09:19:40 -0800 | [diff] [blame] | 1420 | AudioSendStream::Config audio_send_config(transport); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1421 | audio_send_config.rtp.ssrc = kAudioSendSsrc; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1422 | |
| 1423 | // Add extension to enable audio send side BWE, and allow audio bit rate |
| 1424 | // adaptation. |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1425 | audio_send_config.rtp.extensions.clear(); |
| 1426 | audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec( |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 1427 | kAudioSendPayloadType, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1428 | {"OPUS", |
| 1429 | 48000, |
| 1430 | 2, |
| 1431 | {{"usedtx", (params_.audio.dtx ? "1" : "0")}, {"stereo", "1"}}}); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1432 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1433 | if (params_.call.send_side_bwe) { |
| 1434 | audio_send_config.rtp.extensions.push_back( |
| 1435 | webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri, |
Elad Alon | d8d3248 | 2019-02-18 23:45:57 +0100 | [diff] [blame] | 1436 | kTransportSequenceNumberExtensionId)); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1437 | audio_send_config.min_bitrate_bps = kOpusMinBitrateBps; |
| 1438 | audio_send_config.max_bitrate_bps = kOpusBitrateFbBps; |
| 1439 | audio_send_config.send_codec_spec->transport_cc_enabled = true; |
Minyue Li | 455d27c | 2019-01-07 13:14:30 +0100 | [diff] [blame] | 1440 | // Only allow ANA when send-side BWE is enabled. |
| 1441 | audio_send_config.audio_network_adaptor_config = params_.audio.ana_config; |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1442 | } |
| 1443 | audio_send_config.encoder_factory = audio_encoder_factory_; |
| 1444 | SetAudioConfig(audio_send_config); |
| 1445 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1446 | std::string sync_group; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1447 | if (params_.video[0].enabled && params_.audio.sync_video) |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1448 | sync_group = kSyncGroup; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1449 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1450 | CreateMatchingAudioConfigs(transport, sync_group); |
| 1451 | CreateAudioStreams(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1454 | void VideoQualityTest::RunWithRenderers(const Params& params) { |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1455 | RTC_LOG(INFO) << __FUNCTION__; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1456 | num_video_streams_ = params.call.dual_video ? 2 : 1; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1457 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 1458 | std::unique_ptr<test::DirectTransport> recv_transport; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1459 | std::unique_ptr<test::VideoRenderer> local_preview; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1460 | std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers; |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1461 | |
| 1462 | if (!params.logging.rtc_event_log_name.empty()) { |
Danil Chapovalov | 304ea5f | 2019-04-11 15:18:18 +0200 | [diff] [blame] | 1463 | send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( |
| 1464 | RtcEventLog::EncodingType::Legacy); |
| 1465 | recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( |
| 1466 | RtcEventLog::EncodingType::Legacy); |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1467 | std::unique_ptr<RtcEventLogOutputFile> send_output( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1468 | std::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1469 | params.logging.rtc_event_log_name + "_send", |
| 1470 | RtcEventLog::kUnlimitedOutput)); |
| 1471 | std::unique_ptr<RtcEventLogOutputFile> recv_output( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1472 | std::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1473 | params.logging.rtc_event_log_name + "_recv", |
| 1474 | RtcEventLog::kUnlimitedOutput)); |
| 1475 | bool event_log_started = |
| 1476 | send_event_log_->StartLogging(std::move(send_output), |
| 1477 | /*output_period_ms=*/5000) && |
| 1478 | recv_event_log_->StartLogging(std::move(recv_output), |
| 1479 | /*output_period_ms=*/5000); |
| 1480 | RTC_DCHECK(event_log_started); |
| 1481 | } else { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1482 | send_event_log_ = std::make_unique<RtcEventLogNull>(); |
| 1483 | recv_event_log_ = std::make_unique<RtcEventLogNull>(); |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1484 | } |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1485 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1486 | SendTask(RTC_FROM_HERE, task_queue(), [&]() { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1487 | params_ = params; |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1488 | CheckParamsAndInjectionComponents(); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1489 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1490 | // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to |
| 1491 | // match the full stack tests. |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1492 | Call::Config send_call_config(send_event_log_.get()); |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1493 | send_call_config.bitrate_config = params_.call.call_bitrate_config; |
Ilya Nikolaevskiy | 42e7d9c | 2018-11-02 13:14:37 +0100 | [diff] [blame] | 1494 | Call::Config recv_call_config(recv_event_log_.get()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1495 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1496 | if (params_.audio.enabled) |
Benjamin Wright | 1f4173e | 2019-03-13 17:59:32 -0700 | [diff] [blame] | 1497 | InitializeAudioDevice(&send_call_config, &recv_call_config, |
| 1498 | params_.audio.use_real_adm); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1499 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1500 | CreateCalls(send_call_config, recv_call_config); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1501 | |
| 1502 | // TODO(minyue): consider if this is a good transport even for audio only |
| 1503 | // calls. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1504 | send_transport = CreateSendTransport(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1505 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1506 | recv_transport = CreateReceiveTransport(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1507 | |
| 1508 | // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at |
| 1509 | // least share as much code as possible. That way this test would also match |
| 1510 | // the full stack tests better. |
| 1511 | send_transport->SetReceiver(receiver_call_->Receiver()); |
| 1512 | recv_transport->SetReceiver(sender_call_->Receiver()); |
| 1513 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1514 | if (params_.video[0].enabled) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1515 | // Create video renderers. |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1516 | SetupVideo(send_transport.get(), recv_transport.get()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1517 | size_t num_streams_processed = 0; |
| 1518 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
| 1519 | const size_t selected_stream_id = params_.ss[video_idx].selected_stream; |
| 1520 | const size_t num_streams = params_.ss[video_idx].streams.size(); |
| 1521 | if (selected_stream_id == num_streams) { |
| 1522 | for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 1523 | rtc::StringBuilder oss; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1524 | oss << "Loopback Video #" << video_idx << " - Stream #" |
| 1525 | << static_cast<int>(stream_id); |
| 1526 | loopback_renderers.emplace_back(test::VideoRenderer::Create( |
| 1527 | oss.str().c_str(), |
| 1528 | params_.ss[video_idx].streams[stream_id].width, |
| 1529 | params_.ss[video_idx].streams[stream_id].height)); |
| 1530 | video_receive_configs_[stream_id + num_streams_processed].renderer = |
| 1531 | loopback_renderers.back().get(); |
| 1532 | if (params_.audio.enabled && params_.audio.sync_video) |
| 1533 | video_receive_configs_[stream_id + num_streams_processed] |
| 1534 | .sync_group = kSyncGroup; |
| 1535 | } |
| 1536 | } else { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 1537 | rtc::StringBuilder oss; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1538 | oss << "Loopback Video #" << video_idx; |
| 1539 | loopback_renderers.emplace_back(test::VideoRenderer::Create( |
| 1540 | oss.str().c_str(), |
| 1541 | params_.ss[video_idx].streams[selected_stream_id].width, |
| 1542 | params_.ss[video_idx].streams[selected_stream_id].height)); |
| 1543 | video_receive_configs_[selected_stream_id + num_streams_processed] |
| 1544 | .renderer = loopback_renderers.back().get(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1545 | if (params_.audio.enabled && params_.audio.sync_video) |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1546 | video_receive_configs_[num_streams_processed + selected_stream_id] |
| 1547 | .sync_group = kSyncGroup; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1548 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1549 | num_streams_processed += num_streams; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1550 | } |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1551 | CreateFlexfecStreams(); |
| 1552 | CreateVideoStreams(); |
| 1553 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1554 | CreateCapturers(); |
Niels Möller | 412d185 | 2019-01-02 09:42:54 +0100 | [diff] [blame] | 1555 | if (params_.video[0].enabled) { |
| 1556 | // Create local preview |
| 1557 | local_preview.reset(test::VideoRenderer::Create( |
| 1558 | "Local Preview", params_.video[0].width, params_.video[0].height)); |
| 1559 | |
| 1560 | video_sources_[0]->AddOrUpdateSink(local_preview.get(), |
| 1561 | rtc::VideoSinkWants()); |
| 1562 | } |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1563 | ConnectVideoSourcesToStreams(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | if (params_.audio.enabled) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1567 | SetupAudio(send_transport.get()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1570 | Start(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1571 | }); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1572 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1573 | test::PressEnterToContinue(task_queue()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1574 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 1575 | SendTask(RTC_FROM_HERE, task_queue(), [&]() { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1576 | Stop(); |
| 1577 | DestroyStreams(); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1578 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1579 | send_transport.reset(); |
| 1580 | recv_transport.reset(); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1581 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1582 | local_preview.reset(); |
| 1583 | loopback_renderers.clear(); |
| 1584 | |
| 1585 | DestroyCalls(); |
| 1586 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1589 | } // namespace webrtc |