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