ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "video/video_quality_test.h" |
perkj | 9fdbda6 | 2016-09-15 09:19:20 -0700 | [diff] [blame] | 11 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 12 | #include <stdio.h> |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | #include <deque> |
| 15 | #include <map> |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 16 | #include <sstream> |
mflodman | d1590b2 | 2015-12-09 07:07:59 -0800 | [diff] [blame] | 17 | #include <string> |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 20 | #include "call/fake_network_pipe.h" |
| 21 | #include "call/simulated_network.h" |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 22 | #include "logging/rtc_event_log/output/rtc_event_log_output_file.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 23 | #include "media/engine/adm_helpers.h" |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 24 | #include "media/engine/internalencoderfactory.h" |
Niels Möller | 19a68d4 | 2018-04-13 13:37:52 +0200 | [diff] [blame] | 25 | #include "media/engine/vp8_encoder_simulcast_proxy.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "media/engine/webrtcvideoengine.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 27 | #include "modules/audio_device/include/audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "modules/audio_mixer/audio_mixer_impl.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "modules/video_coding/codecs/h264/include/h264.h" |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 30 | #include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h" |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 31 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "modules/video_coding/codecs/vp9/include/vp9.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "test/run_loop.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "test/testsupport/fileutils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 35 | #include "test/video_renderer.h" |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 36 | #include "video/video_analyzer.h" |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 37 | #ifdef WEBRTC_WIN |
| 38 | #include "modules/audio_device/include/audio_device_factory.h" |
| 39 | #endif |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 40 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 41 | namespace { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 42 | constexpr char kSyncGroup[] = "av_sync"; |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 43 | constexpr int kOpusMinBitrateBps = 6000; |
| 44 | constexpr int kOpusBitrateFbBps = 32000; |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 45 | constexpr int kFramesSentInQuickTest = 1; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 46 | constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000; |
| 47 | constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 48 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 49 | constexpr int kDefaultMaxQp = cricket::WebRtcVideoChannel::kDefaultQpMax; |
| 50 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 51 | class VideoStreamFactory |
| 52 | : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface { |
| 53 | public: |
| 54 | explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams) |
| 55 | : streams_(streams) {} |
| 56 | |
| 57 | private: |
| 58 | std::vector<webrtc::VideoStream> CreateEncoderStreams( |
| 59 | int width, |
| 60 | int height, |
| 61 | const webrtc::VideoEncoderConfig& encoder_config) override { |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 62 | // The highest layer must match the incoming resolution. |
| 63 | std::vector<webrtc::VideoStream> streams = streams_; |
| 64 | streams[streams_.size() - 1].height = height; |
| 65 | streams[streams_.size() - 1].width = width; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 66 | |
| 67 | streams[0].bitrate_priority = encoder_config.bitrate_priority; |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 68 | return streams; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | std::vector<webrtc::VideoStream> streams_; |
| 72 | }; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 73 | } // namespace |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 74 | |
| 75 | namespace webrtc { |
| 76 | |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 77 | std::unique_ptr<VideoEncoder> VideoQualityTest::CreateVideoEncoder( |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 78 | const SdpVideoFormat& format) { |
| 79 | if (format.name == "VP8") { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 80 | return absl::make_unique<VP8EncoderSimulcastProxy>( |
| 81 | &internal_encoder_factory_, format); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 82 | } else if (format.name == "multiplex") { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 83 | return absl::make_unique<MultiplexEncoderAdapter>( |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 84 | &internal_encoder_factory_, SdpVideoFormat(cricket::kVp9CodecName)); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 85 | } |
Emircan Uysaler | 0823eec | 2018-07-13 17:10:00 -0700 | [diff] [blame] | 86 | return internal_encoder_factory_.CreateVideoEncoder(format); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 89 | VideoQualityTest::VideoQualityTest( |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 90 | std::unique_ptr<InjectionComponents> injection_components) |
Sebastian Jansson | e6d7c3e | 2018-07-11 15:00:41 +0200 | [diff] [blame] | 91 | : clock_(Clock::GetRealTimeClock()), |
| 92 | video_encoder_factory_([this](const SdpVideoFormat& format) { |
| 93 | return this->CreateVideoEncoder(format); |
| 94 | }), |
| 95 | receive_logs_(0), |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 96 | send_logs_(0), |
| 97 | injection_components_(std::move(injection_components)) { |
| 98 | if (injection_components_ == nullptr) { |
| 99 | injection_components_ = absl::make_unique<InjectionComponents>(); |
| 100 | } |
| 101 | |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 102 | payload_type_map_ = test::CallTest::payload_type_map_; |
| 103 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeH264) == |
| 104 | payload_type_map_.end()); |
| 105 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP8) == |
| 106 | payload_type_map_.end()); |
| 107 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP9) == |
| 108 | payload_type_map_.end()); |
| 109 | payload_type_map_[kPayloadTypeH264] = webrtc::MediaType::VIDEO; |
| 110 | payload_type_map_[kPayloadTypeVP8] = webrtc::MediaType::VIDEO; |
| 111 | payload_type_map_[kPayloadTypeVP9] = webrtc::MediaType::VIDEO; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 112 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 113 | fec_controller_factory_ = |
| 114 | std::move(injection_components_->fec_controller_factory); |
Ying Wang | 3b790f3 | 2018-01-19 17:58:57 +0100 | [diff] [blame] | 115 | } |
| 116 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 117 | VideoQualityTest::Params::Params() |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 118 | : call({false, BitrateConstraints(), 0}), |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 119 | video{{false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false, |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 120 | false, false, ""}, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 121 | {false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false, |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 122 | false, false, ""}}, |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 123 | audio({false, false, false, false}), |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 124 | screenshare{{false, false, 10, 0}, {false, false, 10, 0}}, |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 125 | analyzer({"", 0.0, 0.0, 0, "", ""}), |
| 126 | pipe(), |
Artem Titov | f18b352 | 2018-08-28 16:54:24 +0200 | [diff] [blame] | 127 | config(absl::nullopt), |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 128 | ss{{std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn, |
| 129 | std::vector<SpatialLayer>()}, |
| 130 | {std::vector<VideoStream>(), 0, 0, -1, InterLayerPredMode::kOn, |
| 131 | std::vector<SpatialLayer>()}}, |
Mirko Bonadei | 45a4c41 | 2018-07-31 15:07:28 +0200 | [diff] [blame] | 132 | logging({"", "", ""}) {} |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 133 | |
| 134 | VideoQualityTest::Params::~Params() = default; |
| 135 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 136 | VideoQualityTest::InjectionComponents::InjectionComponents() = default; |
| 137 | |
| 138 | VideoQualityTest::InjectionComponents::~InjectionComponents() = default; |
| 139 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 140 | void VideoQualityTest::TestBody() {} |
| 141 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 142 | std::string VideoQualityTest::GenerateGraphTitle() const { |
| 143 | std::stringstream ss; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 144 | ss << params_.video[0].codec; |
| 145 | ss << " (" << params_.video[0].target_bitrate_bps / 1000 << "kbps"; |
| 146 | ss << ", " << params_.video[0].fps << " FPS"; |
| 147 | if (params_.screenshare[0].scroll_duration) |
| 148 | ss << ", " << params_.screenshare[0].scroll_duration << "s scroll"; |
| 149 | if (params_.ss[0].streams.size() > 1) |
| 150 | ss << ", Stream #" << params_.ss[0].selected_stream; |
| 151 | if (params_.ss[0].num_spatial_layers > 1) |
| 152 | ss << ", Layer #" << params_.ss[0].selected_sl; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 153 | ss << ")"; |
| 154 | return ss.str(); |
| 155 | } |
| 156 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 157 | void VideoQualityTest::CheckParamsAndInjectionComponents() { |
| 158 | if (injection_components_ == nullptr) { |
| 159 | injection_components_ = absl::make_unique<InjectionComponents>(); |
| 160 | } |
| 161 | if (!params_.config && injection_components_->sender_network == nullptr && |
| 162 | injection_components_->receiver_network == nullptr) { |
Artem Titov | f18b352 | 2018-08-28 16:54:24 +0200 | [diff] [blame] | 163 | // TODO(titovartem) replace with default config creation when removing |
| 164 | // pipe. |
| 165 | params_.config = params_.pipe; |
| 166 | } |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 167 | RTC_CHECK( |
| 168 | (params_.config && injection_components_->sender_network == nullptr && |
| 169 | injection_components_->receiver_network == nullptr) || |
| 170 | (!params_.config && injection_components_->sender_network != nullptr && |
| 171 | injection_components_->receiver_network != nullptr)); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 172 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
| 173 | // Iterate over primary and secondary video streams. |
| 174 | if (!params_.video[video_idx].enabled) |
| 175 | return; |
| 176 | // Add a default stream in none specified. |
| 177 | if (params_.ss[video_idx].streams.empty()) |
| 178 | params_.ss[video_idx].streams.push_back( |
| 179 | VideoQualityTest::DefaultVideoStream(params_, video_idx)); |
| 180 | if (params_.ss[video_idx].num_spatial_layers == 0) |
| 181 | params_.ss[video_idx].num_spatial_layers = 1; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 182 | |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 183 | if (params_.config) { |
| 184 | if (params_.config->loss_percent != 0 || |
| 185 | params_.config->queue_length_packets != 0) { |
| 186 | // Since LayerFilteringTransport changes the sequence numbers, we can't |
| 187 | // use that feature with pack loss, since the NACK request would end up |
| 188 | // retransmitting the wrong packets. |
| 189 | RTC_CHECK(params_.ss[video_idx].selected_sl == -1 || |
| 190 | params_.ss[video_idx].selected_sl == |
| 191 | params_.ss[video_idx].num_spatial_layers - 1); |
| 192 | RTC_CHECK(params_.video[video_idx].selected_tl == -1 || |
| 193 | params_.video[video_idx].selected_tl == |
| 194 | params_.video[video_idx].num_temporal_layers - 1); |
| 195 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 196 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 197 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 198 | // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as |
| 199 | // it does in some parts of the code? |
| 200 | RTC_CHECK_GE(params_.video[video_idx].max_bitrate_bps, |
| 201 | params_.video[video_idx].target_bitrate_bps); |
| 202 | RTC_CHECK_GE(params_.video[video_idx].target_bitrate_bps, |
| 203 | params_.video[video_idx].min_bitrate_bps); |
| 204 | RTC_CHECK_LT(params_.video[video_idx].selected_tl, |
| 205 | params_.video[video_idx].num_temporal_layers); |
| 206 | RTC_CHECK_LE(params_.ss[video_idx].selected_stream, |
| 207 | params_.ss[video_idx].streams.size()); |
| 208 | for (const VideoStream& stream : params_.ss[video_idx].streams) { |
| 209 | RTC_CHECK_GE(stream.min_bitrate_bps, 0); |
| 210 | RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps); |
| 211 | RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps); |
| 212 | } |
| 213 | // TODO(ivica): Should we check if the sum of all streams/layers is equal to |
| 214 | // the total bitrate? We anyway have to update them in the case bitrate |
| 215 | // estimator changes the total bitrates. |
| 216 | RTC_CHECK_GE(params_.ss[video_idx].num_spatial_layers, 1); |
| 217 | RTC_CHECK_LE(params_.ss[video_idx].selected_sl, |
| 218 | params_.ss[video_idx].num_spatial_layers); |
| 219 | RTC_CHECK( |
| 220 | params_.ss[video_idx].spatial_layers.empty() || |
| 221 | params_.ss[video_idx].spatial_layers.size() == |
| 222 | static_cast<size_t>(params_.ss[video_idx].num_spatial_layers)); |
| 223 | if (params_.video[video_idx].codec == "VP8") { |
| 224 | RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1); |
| 225 | } else if (params_.video[video_idx].codec == "VP9") { |
| 226 | RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 1); |
| 227 | } |
| 228 | RTC_CHECK_GE(params_.call.num_thumbnails, 0); |
| 229 | if (params_.call.num_thumbnails > 0) { |
| 230 | RTC_CHECK_EQ(params_.ss[video_idx].num_spatial_layers, 1); |
| 231 | RTC_CHECK_EQ(params_.ss[video_idx].streams.size(), 3); |
| 232 | RTC_CHECK_EQ(params_.video[video_idx].num_temporal_layers, 3); |
| 233 | RTC_CHECK_EQ(params_.video[video_idx].codec, "VP8"); |
| 234 | } |
| 235 | // Dual streams with FEC not supported in tests yet. |
| 236 | RTC_CHECK(!params_.video[video_idx].flexfec || num_video_streams_ == 1); |
| 237 | RTC_CHECK(!params_.video[video_idx].ulpfec || num_video_streams_ == 1); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 238 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | // Static. |
| 242 | std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) { |
| 243 | // Parse comma separated nonnegative integers, where some elements may be |
| 244 | // empty. The empty values are replaced with -1. |
| 245 | // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40} |
| 246 | // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1} |
| 247 | std::vector<int> result; |
| 248 | if (str.empty()) |
| 249 | return result; |
| 250 | |
| 251 | const char* p = str.c_str(); |
| 252 | int value = -1; |
| 253 | int pos; |
| 254 | while (*p) { |
| 255 | if (*p == ',') { |
| 256 | result.push_back(value); |
| 257 | value = -1; |
| 258 | ++p; |
| 259 | continue; |
| 260 | } |
| 261 | RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1) |
| 262 | << "Unexpected non-number value."; |
| 263 | p += pos; |
| 264 | } |
| 265 | result.push_back(value); |
| 266 | return result; |
| 267 | } |
| 268 | |
| 269 | // Static. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 270 | VideoStream VideoQualityTest::DefaultVideoStream(const Params& params, |
| 271 | size_t video_idx) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 272 | VideoStream stream; |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 273 | stream.width = params.video[video_idx].width; |
| 274 | stream.height = params.video[video_idx].height; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 275 | stream.max_framerate = params.video[video_idx].fps; |
| 276 | stream.min_bitrate_bps = params.video[video_idx].min_bitrate_bps; |
| 277 | stream.target_bitrate_bps = params.video[video_idx].target_bitrate_bps; |
| 278 | stream.max_bitrate_bps = params.video[video_idx].max_bitrate_bps; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 279 | stream.max_qp = kDefaultMaxQp; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 280 | stream.num_temporal_layers = params.video[video_idx].num_temporal_layers; |
Seth Hampson | 46e31ba | 2018-01-18 10:39:54 -0800 | [diff] [blame] | 281 | stream.active = true; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 282 | return stream; |
| 283 | } |
| 284 | |
| 285 | // Static. |
| 286 | VideoStream VideoQualityTest::DefaultThumbnailStream() { |
| 287 | VideoStream stream; |
| 288 | stream.width = 320; |
| 289 | stream.height = 180; |
| 290 | stream.max_framerate = 7; |
| 291 | stream.min_bitrate_bps = 7500; |
| 292 | stream.target_bitrate_bps = 37500; |
| 293 | stream.max_bitrate_bps = 50000; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 294 | stream.max_qp = kDefaultMaxQp; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 295 | return stream; |
| 296 | } |
| 297 | |
| 298 | // Static. |
| 299 | void VideoQualityTest::FillScalabilitySettings( |
| 300 | Params* params, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 301 | size_t video_idx, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 302 | const std::vector<std::string>& stream_descriptors, |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 303 | int num_streams, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 304 | size_t selected_stream, |
| 305 | int num_spatial_layers, |
| 306 | int selected_sl, |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 307 | InterLayerPredMode inter_layer_pred, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 308 | const std::vector<std::string>& sl_descriptors) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 309 | if (params->ss[video_idx].streams.empty() && |
| 310 | params->ss[video_idx].infer_streams) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 311 | webrtc::VideoEncoderConfig encoder_config; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 312 | encoder_config.codec_type = |
| 313 | PayloadStringToCodecType(params->video[video_idx].codec); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 314 | encoder_config.content_type = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 315 | params->screenshare[video_idx].enabled |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 316 | ? webrtc::VideoEncoderConfig::ContentType::kScreen |
| 317 | : webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 318 | encoder_config.max_bitrate_bps = params->video[video_idx].max_bitrate_bps; |
| 319 | encoder_config.min_transmit_bitrate_bps = |
| 320 | params->video[video_idx].min_transmit_bps; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 321 | encoder_config.number_of_streams = num_streams; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 322 | encoder_config.spatial_layers = params->ss[video_idx].spatial_layers; |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 323 | encoder_config.simulcast_layers = std::vector<VideoStream>(num_streams); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 324 | encoder_config.video_stream_factory = |
| 325 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 326 | params->video[video_idx].codec, kDefaultMaxQp, |
Mirko Bonadei | 948b7e3 | 2018-08-14 07:23:21 +0000 | [diff] [blame] | 327 | params->video[video_idx].fps, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 328 | params->screenshare[video_idx].enabled, true); |
| 329 | params->ss[video_idx].streams = |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 330 | encoder_config.video_stream_factory->CreateEncoderStreams( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 331 | static_cast<int>(params->video[video_idx].width), |
| 332 | static_cast<int>(params->video[video_idx].height), encoder_config); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 333 | } else { |
| 334 | // Read VideoStream and SpatialLayer elements from a list of comma separated |
| 335 | // lists. To use a default value for an element, use -1 or leave empty. |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 336 | // Validity checks performed in CheckParamsAndInjectionComponents. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 337 | RTC_CHECK(params->ss[video_idx].streams.empty()); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 338 | for (auto descriptor : stream_descriptors) { |
| 339 | if (descriptor.empty()) |
| 340 | continue; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 341 | VideoStream stream = |
| 342 | VideoQualityTest::DefaultVideoStream(*params, video_idx); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 343 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 344 | if (v[0] != -1) |
| 345 | stream.width = static_cast<size_t>(v[0]); |
| 346 | if (v[1] != -1) |
| 347 | stream.height = static_cast<size_t>(v[1]); |
| 348 | if (v[2] != -1) |
| 349 | stream.max_framerate = v[2]; |
| 350 | if (v[3] != -1) |
| 351 | stream.min_bitrate_bps = v[3]; |
| 352 | if (v[4] != -1) |
| 353 | stream.target_bitrate_bps = v[4]; |
| 354 | if (v[5] != -1) |
| 355 | stream.max_bitrate_bps = v[5]; |
| 356 | if (v.size() > 6 && v[6] != -1) |
| 357 | stream.max_qp = v[6]; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 358 | if (v.size() > 7 && v[7] != -1) { |
| 359 | stream.num_temporal_layers = v[7]; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 360 | } else { |
| 361 | // Automatic TL thresholds for more than two layers not supported. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 362 | RTC_CHECK_LE(params->video[video_idx].num_temporal_layers, 2); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 363 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 364 | params->ss[video_idx].streams.push_back(stream); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 365 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 366 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 367 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 368 | params->ss[video_idx].num_spatial_layers = std::max(1, num_spatial_layers); |
| 369 | params->ss[video_idx].selected_stream = selected_stream; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 370 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 371 | params->ss[video_idx].selected_sl = selected_sl; |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 372 | params->ss[video_idx].inter_layer_pred = inter_layer_pred; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 373 | RTC_CHECK(params->ss[video_idx].spatial_layers.empty()); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 374 | for (auto descriptor : sl_descriptors) { |
| 375 | if (descriptor.empty()) |
| 376 | continue; |
| 377 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 378 | RTC_CHECK_EQ(v.size(), 7); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 379 | |
Sergey Silkin | 13e7434 | 2018-03-02 12:28:00 +0100 | [diff] [blame] | 380 | SpatialLayer layer = {0}; |
| 381 | layer.width = v[0]; |
| 382 | layer.height = v[1]; |
| 383 | layer.numberOfTemporalLayers = v[2]; |
| 384 | layer.maxBitrate = v[3]; |
| 385 | layer.minBitrate = v[4]; |
| 386 | layer.targetBitrate = v[5]; |
| 387 | layer.qpMax = v[6]; |
| 388 | layer.active = true; |
| 389 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 390 | params->ss[video_idx].spatial_layers.push_back(layer); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 394 | void VideoQualityTest::SetupVideo(Transport* send_transport, |
| 395 | Transport* recv_transport) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 396 | size_t total_streams_used = 0; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 397 | video_receive_configs_.clear(); |
| 398 | video_send_configs_.clear(); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 399 | video_encoder_configs_.clear(); |
| 400 | allocated_decoders_.clear(); |
| 401 | bool decode_all_receive_streams = true; |
| 402 | size_t num_video_substreams = params_.ss[0].streams.size(); |
| 403 | RTC_CHECK(num_video_streams_ > 0); |
| 404 | video_encoder_configs_.resize(num_video_streams_); |
| 405 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
| 406 | video_send_configs_.push_back(VideoSendStream::Config(send_transport)); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 407 | video_encoder_configs_.push_back(VideoEncoderConfig()); |
| 408 | num_video_substreams = params_.ss[video_idx].streams.size(); |
| 409 | RTC_CHECK_GT(num_video_substreams, 0); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 410 | for (size_t i = 0; i < num_video_substreams; ++i) |
| 411 | video_send_configs_[video_idx].rtp.ssrcs.push_back( |
| 412 | kVideoSendSsrcs[total_streams_used + i]); |
Qingsi Wang | 2d82ade | 2018-07-11 06:04:44 +0000 | [diff] [blame] | 413 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 414 | int payload_type; |
| 415 | if (params_.video[video_idx].codec == "H264") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 416 | payload_type = kPayloadTypeH264; |
| 417 | } else if (params_.video[video_idx].codec == "VP8") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 418 | payload_type = kPayloadTypeVP8; |
| 419 | } else if (params_.video[video_idx].codec == "VP9") { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 420 | payload_type = kPayloadTypeVP9; |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 421 | } else if (params_.video[video_idx].codec == "multiplex") { |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 422 | payload_type = kPayloadTypeVP9; |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 423 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 424 | RTC_NOTREACHED() << "Codec not supported!"; |
| 425 | return; |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 426 | } |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 427 | video_send_configs_[video_idx].encoder_settings.encoder_factory = |
| 428 | &video_encoder_factory_; |
| 429 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 430 | video_send_configs_[video_idx].rtp.payload_name = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 431 | params_.video[video_idx].codec; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 432 | video_send_configs_[video_idx].rtp.payload_type = payload_type; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 433 | video_send_configs_[video_idx].rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 434 | video_send_configs_[video_idx].rtp.rtx.payload_type = kSendRtxPayloadType; |
| 435 | for (size_t i = 0; i < num_video_substreams; ++i) { |
| 436 | video_send_configs_[video_idx].rtp.rtx.ssrcs.push_back( |
| 437 | kSendRtxSsrcs[i + total_streams_used]); |
ilnik | 9fd9f6c | 2017-03-02 08:10:10 -0800 | [diff] [blame] | 438 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 439 | video_send_configs_[video_idx].rtp.extensions.clear(); |
| 440 | if (params_.call.send_side_bwe) { |
| 441 | video_send_configs_[video_idx].rtp.extensions.push_back( |
| 442 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 443 | test::kTransportSequenceNumberExtensionId)); |
| 444 | } else { |
| 445 | video_send_configs_[video_idx].rtp.extensions.push_back(RtpExtension( |
| 446 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
| 447 | } |
| 448 | video_send_configs_[video_idx].rtp.extensions.push_back( |
| 449 | RtpExtension(RtpExtension::kVideoContentTypeUri, |
| 450 | test::kVideoContentTypeExtensionId)); |
| 451 | video_send_configs_[video_idx].rtp.extensions.push_back(RtpExtension( |
| 452 | RtpExtension::kVideoTimingUri, test::kVideoTimingExtensionId)); |
| 453 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 454 | video_encoder_configs_[video_idx].video_format.name = |
| 455 | params_.video[video_idx].codec; |
| 456 | |
Emircan Uysaler | 0823eec | 2018-07-13 17:10:00 -0700 | [diff] [blame] | 457 | video_encoder_configs_[video_idx].video_format.parameters = |
| 458 | params_.video[video_idx].sdp_params; |
| 459 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 460 | video_encoder_configs_[video_idx].codec_type = |
| 461 | PayloadStringToCodecType(params_.video[video_idx].codec); |
| 462 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 463 | video_encoder_configs_[video_idx].min_transmit_bitrate_bps = |
| 464 | params_.video[video_idx].min_transmit_bps; |
| 465 | |
| 466 | video_send_configs_[video_idx].suspend_below_min_bitrate = |
| 467 | params_.video[video_idx].suspend_below_min_bitrate; |
| 468 | |
| 469 | video_encoder_configs_[video_idx].number_of_streams = |
| 470 | params_.ss[video_idx].streams.size(); |
| 471 | video_encoder_configs_[video_idx].max_bitrate_bps = 0; |
| 472 | for (size_t i = 0; i < params_.ss[video_idx].streams.size(); ++i) { |
| 473 | video_encoder_configs_[video_idx].max_bitrate_bps += |
| 474 | params_.ss[video_idx].streams[i].max_bitrate_bps; |
| 475 | } |
| 476 | if (params_.ss[video_idx].infer_streams) { |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 477 | video_encoder_configs_[video_idx].simulcast_layers = |
| 478 | std::vector<VideoStream>(params_.ss[video_idx].streams.size()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 479 | video_encoder_configs_[video_idx].video_stream_factory = |
| 480 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
| 481 | params_.video[video_idx].codec, |
| 482 | params_.ss[video_idx].streams[0].max_qp, |
Mirko Bonadei | 948b7e3 | 2018-08-14 07:23:21 +0000 | [diff] [blame] | 483 | params_.video[video_idx].fps, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 484 | params_.screenshare[video_idx].enabled, true); |
| 485 | } else { |
| 486 | video_encoder_configs_[video_idx].video_stream_factory = |
| 487 | new rtc::RefCountedObject<VideoStreamFactory>( |
| 488 | params_.ss[video_idx].streams); |
| 489 | } |
| 490 | |
| 491 | video_encoder_configs_[video_idx].spatial_layers = |
| 492 | params_.ss[video_idx].spatial_layers; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 493 | decode_all_receive_streams = params_.ss[video_idx].selected_stream == |
| 494 | params_.ss[video_idx].streams.size(); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 495 | absl::optional<int> decode_sub_stream; |
| 496 | if (!decode_all_receive_streams) |
| 497 | decode_sub_stream = params_.ss[video_idx].selected_stream; |
| 498 | CreateMatchingVideoReceiveConfigs( |
| 499 | video_send_configs_[video_idx], recv_transport, |
| 500 | params_.call.send_side_bwe, decode_sub_stream, true, kNackRtpHistoryMs); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 501 | |
| 502 | if (params_.screenshare[video_idx].enabled) { |
| 503 | // Fill out codec settings. |
| 504 | video_encoder_configs_[video_idx].content_type = |
| 505 | VideoEncoderConfig::ContentType::kScreen; |
Taylor Brandstetter | 49fcc10 | 2018-05-16 14:20:41 -0700 | [diff] [blame] | 506 | degradation_preference_ = DegradationPreference::MAINTAIN_RESOLUTION; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 507 | if (params_.video[video_idx].codec == "VP8") { |
| 508 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 509 | vp8_settings.denoisingOn = false; |
| 510 | vp8_settings.frameDroppingOn = false; |
| 511 | vp8_settings.numberOfTemporalLayers = static_cast<unsigned char>( |
| 512 | params_.video[video_idx].num_temporal_layers); |
| 513 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 514 | new rtc::RefCountedObject< |
| 515 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
| 516 | } else if (params_.video[video_idx].codec == "VP9") { |
| 517 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 518 | vp9_settings.denoisingOn = false; |
| 519 | vp9_settings.frameDroppingOn = false; |
| 520 | vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>( |
| 521 | params_.video[video_idx].num_temporal_layers); |
| 522 | vp9_settings.numberOfSpatialLayers = static_cast<unsigned char>( |
| 523 | params_.ss[video_idx].num_spatial_layers); |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 524 | vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 525 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 526 | new rtc::RefCountedObject< |
| 527 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
| 528 | } |
| 529 | } else if (params_.ss[video_idx].num_spatial_layers > 1) { |
| 530 | // If SVC mode without screenshare, still need to set codec specifics. |
| 531 | RTC_CHECK(params_.video[video_idx].codec == "VP9"); |
| 532 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 533 | vp9_settings.numberOfTemporalLayers = static_cast<unsigned char>( |
| 534 | params_.video[video_idx].num_temporal_layers); |
| 535 | vp9_settings.numberOfSpatialLayers = |
| 536 | static_cast<unsigned char>(params_.ss[video_idx].num_spatial_layers); |
Sergey Silkin | 5702736 | 2018-05-15 09:12:05 +0200 | [diff] [blame] | 537 | vp9_settings.interLayerPred = params_.ss[video_idx].inter_layer_pred; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 538 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 539 | new rtc::RefCountedObject< |
| 540 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 541 | } else if (params_.video[video_idx].automatic_scaling) { |
| 542 | if (params_.video[video_idx].codec == "VP8") { |
| 543 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 544 | vp8_settings.automaticResizeOn = true; |
| 545 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 546 | new rtc::RefCountedObject< |
| 547 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
| 548 | } else if (params_.video[video_idx].codec == "VP9") { |
| 549 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 550 | vp9_settings.automaticResizeOn = true; |
| 551 | video_encoder_configs_[video_idx].encoder_specific_settings = |
| 552 | new rtc::RefCountedObject< |
| 553 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
| 554 | } else { |
| 555 | RTC_NOTREACHED() << "Automatic scaling not supported for codec " |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 556 | << params_.video[video_idx].codec << ", stream " |
| 557 | << video_idx; |
Niels Möller | 6aa415e | 2018-06-07 11:14:13 +0200 | [diff] [blame] | 558 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 559 | } |
| 560 | total_streams_used += num_video_substreams; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 561 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 562 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 563 | // FEC supported only for single video stream mode yet. |
| 564 | if (params_.video[0].flexfec) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 565 | if (decode_all_receive_streams) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 566 | SetSendFecConfig(GetVideoSendConfig()->rtp.ssrcs); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 567 | } else { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 568 | SetSendFecConfig({kVideoSendSsrcs[params_.ss[0].selected_stream]}); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 569 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 570 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 571 | CreateMatchingFecConfig(recv_transport, *GetVideoSendConfig()); |
| 572 | GetFlexFecConfig()->transport_cc = params_.call.send_side_bwe; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 573 | if (params_.call.send_side_bwe) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 574 | GetFlexFecConfig()->rtp_header_extensions.push_back( |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 575 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 576 | test::kTransportSequenceNumberExtensionId)); |
| 577 | } else { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 578 | GetFlexFecConfig()->rtp_header_extensions.push_back(RtpExtension( |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 579 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
| 580 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 583 | if (params_.video[0].ulpfec) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 584 | SetSendUlpFecConfig(GetVideoSendConfig()); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 585 | if (decode_all_receive_streams) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 586 | for (auto& receive_config : video_receive_configs_) { |
| 587 | SetReceiveUlpFecConfig(&receive_config); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 588 | } |
| 589 | } else { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 590 | SetReceiveUlpFecConfig( |
| 591 | &video_receive_configs_[params_.ss[0].selected_stream]); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 592 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 593 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 594 | } |
| 595 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 596 | void VideoQualityTest::SetupThumbnails(Transport* send_transport, |
| 597 | Transport* recv_transport) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 598 | for (int i = 0; i < params_.call.num_thumbnails; ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 599 | // Thumbnails will be send in the other way: from receiver_call to |
| 600 | // sender_call. |
| 601 | VideoSendStream::Config thumbnail_send_config(recv_transport); |
| 602 | thumbnail_send_config.rtp.ssrcs.push_back(kThumbnailSendSsrcStart + i); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 603 | // TODO(nisse): Could use a simpler VP8-only encoder factory. |
| 604 | thumbnail_send_config.encoder_settings.encoder_factory = |
| 605 | &video_encoder_factory_; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 606 | thumbnail_send_config.rtp.payload_name = params_.video[0].codec; |
| 607 | thumbnail_send_config.rtp.payload_type = kPayloadTypeVP8; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 608 | thumbnail_send_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 609 | thumbnail_send_config.rtp.rtx.payload_type = kSendRtxPayloadType; |
| 610 | thumbnail_send_config.rtp.rtx.ssrcs.push_back(kThumbnailRtxSsrcStart + i); |
| 611 | thumbnail_send_config.rtp.extensions.clear(); |
| 612 | if (params_.call.send_side_bwe) { |
| 613 | thumbnail_send_config.rtp.extensions.push_back( |
| 614 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 615 | test::kTransportSequenceNumberExtensionId)); |
| 616 | } else { |
| 617 | thumbnail_send_config.rtp.extensions.push_back(RtpExtension( |
| 618 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
| 619 | } |
| 620 | |
| 621 | VideoEncoderConfig thumbnail_encoder_config; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 622 | thumbnail_encoder_config.codec_type = kVideoCodecVP8; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 623 | thumbnail_encoder_config.video_format.name = "VP8"; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 624 | thumbnail_encoder_config.min_transmit_bitrate_bps = 7500; |
| 625 | thumbnail_send_config.suspend_below_min_bitrate = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 626 | params_.video[0].suspend_below_min_bitrate; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 627 | thumbnail_encoder_config.number_of_streams = 1; |
| 628 | thumbnail_encoder_config.max_bitrate_bps = 50000; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 629 | if (params_.ss[0].infer_streams) { |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 630 | thumbnail_encoder_config.video_stream_factory = |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 631 | new rtc::RefCountedObject<VideoStreamFactory>(params_.ss[0].streams); |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 632 | } else { |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 633 | thumbnail_encoder_config.simulcast_layers = std::vector<VideoStream>(1); |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 634 | thumbnail_encoder_config.video_stream_factory = |
| 635 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 636 | params_.video[0].codec, params_.ss[0].streams[0].max_qp, |
Mirko Bonadei | 948b7e3 | 2018-08-14 07:23:21 +0000 | [diff] [blame] | 637 | params_.video[0].fps, params_.screenshare[0].enabled, true); |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 638 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 639 | thumbnail_encoder_config.spatial_layers = params_.ss[0].spatial_layers; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 640 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 641 | thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy()); |
| 642 | thumbnail_send_configs_.push_back(thumbnail_send_config.Copy()); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 643 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 644 | AddMatchingVideoReceiveConfigs( |
| 645 | &thumbnail_receive_configs_, thumbnail_send_config, send_transport, |
| 646 | params_.call.send_side_bwe, absl::nullopt, false, kNackRtpHistoryMs); |
| 647 | } |
| 648 | for (size_t i = 0; i < thumbnail_send_configs_.size(); ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 649 | thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream( |
| 650 | thumbnail_send_configs_[i].Copy(), |
| 651 | thumbnail_encoder_configs_[i].Copy())); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 652 | } |
| 653 | for (size_t i = 0; i < thumbnail_receive_configs_.size(); ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 654 | thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream( |
| 655 | thumbnail_receive_configs_[i].Copy())); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | void VideoQualityTest::DestroyThumbnailStreams() { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 660 | for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 661 | receiver_call_->DestroyVideoSendStream(thumbnail_send_stream); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 662 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 663 | thumbnail_send_streams_.clear(); |
| 664 | for (VideoReceiveStream* thumbnail_receive_stream : |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 665 | thumbnail_receive_streams_) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 666 | sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 667 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 668 | thumbnail_send_streams_.clear(); |
| 669 | thumbnail_receive_streams_.clear(); |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 670 | for (std::unique_ptr<test::TestVideoCapturer>& video_caputurer : |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 671 | thumbnail_capturers_) { |
| 672 | video_caputurer.reset(); |
| 673 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 674 | } |
| 675 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 676 | void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) { |
| 677 | VideoStream thumbnail = DefaultThumbnailStream(); |
| 678 | for (size_t i = 0; i < num_thumbnail_streams; ++i) { |
| 679 | thumbnail_capturers_.emplace_back(test::FrameGeneratorCapturer::Create( |
| 680 | static_cast<int>(thumbnail.width), static_cast<int>(thumbnail.height), |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 681 | absl::nullopt, absl::nullopt, thumbnail.max_framerate, clock_)); |
ilnik | f89a738 | 2017-03-07 06:15:27 -0800 | [diff] [blame] | 682 | RTC_DCHECK(thumbnail_capturers_.back()); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 686 | std::unique_ptr<test::FrameGenerator> VideoQualityTest::CreateFrameGenerator( |
| 687 | size_t video_idx) { |
| 688 | // Setup frame generator. |
| 689 | const size_t kWidth = 1850; |
| 690 | const size_t kHeight = 1110; |
| 691 | std::unique_ptr<test::FrameGenerator> frame_generator; |
| 692 | if (params_.screenshare[video_idx].generate_slides) { |
| 693 | frame_generator = test::FrameGenerator::CreateSlideGenerator( |
| 694 | kWidth, kHeight, |
| 695 | params_.screenshare[video_idx].slide_change_interval * |
| 696 | params_.video[video_idx].fps); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 697 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 698 | std::vector<std::string> slides = params_.screenshare[video_idx].slides; |
| 699 | if (slides.size() == 0) { |
| 700 | slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); |
| 701 | slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); |
| 702 | slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); |
| 703 | slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); |
| 704 | } |
| 705 | if (params_.screenshare[video_idx].scroll_duration == 0) { |
| 706 | // Cycle image every slide_change_interval seconds. |
| 707 | frame_generator = test::FrameGenerator::CreateFromYuvFile( |
| 708 | slides, kWidth, kHeight, |
| 709 | params_.screenshare[video_idx].slide_change_interval * |
| 710 | params_.video[video_idx].fps); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 711 | } else { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 712 | RTC_CHECK_LE(params_.video[video_idx].width, kWidth); |
| 713 | RTC_CHECK_LE(params_.video[video_idx].height, kHeight); |
| 714 | RTC_CHECK_GT(params_.screenshare[video_idx].slide_change_interval, 0); |
| 715 | const int kPauseDurationMs = |
| 716 | (params_.screenshare[video_idx].slide_change_interval - |
| 717 | params_.screenshare[video_idx].scroll_duration) * |
| 718 | 1000; |
| 719 | RTC_CHECK_LE(params_.screenshare[video_idx].scroll_duration, |
| 720 | params_.screenshare[video_idx].slide_change_interval); |
| 721 | |
| 722 | frame_generator = test::FrameGenerator::CreateScrollingInputFromYuvFiles( |
| 723 | clock_, slides, kWidth, kHeight, params_.video[video_idx].width, |
| 724 | params_.video[video_idx].height, |
| 725 | params_.screenshare[video_idx].scroll_duration * 1000, |
| 726 | kPauseDurationMs); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 729 | return frame_generator; |
| 730 | } |
| 731 | |
| 732 | void VideoQualityTest::CreateCapturers() { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 733 | RTC_DCHECK(video_sources_.empty()); |
| 734 | RTC_DCHECK(video_capturers_.empty()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 735 | video_capturers_.resize(num_video_streams_); |
| 736 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
| 737 | if (params_.screenshare[video_idx].enabled) { |
| 738 | std::unique_ptr<test::FrameGenerator> frame_generator = |
| 739 | CreateFrameGenerator(video_idx); |
| 740 | test::FrameGeneratorCapturer* frame_generator_capturer = |
| 741 | new test::FrameGeneratorCapturer(clock_, std::move(frame_generator), |
| 742 | params_.video[video_idx].fps); |
| 743 | EXPECT_TRUE(frame_generator_capturer->Init()); |
| 744 | video_capturers_[video_idx].reset(frame_generator_capturer); |
| 745 | } else { |
| 746 | if (params_.video[video_idx].clip_name == "Generator") { |
| 747 | video_capturers_[video_idx].reset(test::FrameGeneratorCapturer::Create( |
| 748 | static_cast<int>(params_.video[video_idx].width), |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 749 | static_cast<int>(params_.video[video_idx].height), absl::nullopt, |
| 750 | absl::nullopt, params_.video[video_idx].fps, clock_)); |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 751 | } else if (params_.video[video_idx].clip_name == "GeneratorI420A") { |
| 752 | video_capturers_[video_idx].reset(test::FrameGeneratorCapturer::Create( |
| 753 | static_cast<int>(params_.video[video_idx].width), |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 754 | static_cast<int>(params_.video[video_idx].height), |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 755 | test::FrameGenerator::OutputType::I420A, absl::nullopt, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 756 | params_.video[video_idx].fps, clock_)); |
Emircan Uysaler | 0823eec | 2018-07-13 17:10:00 -0700 | [diff] [blame] | 757 | } else if (params_.video[video_idx].clip_name == "GeneratorI010") { |
| 758 | video_capturers_[video_idx].reset(test::FrameGeneratorCapturer::Create( |
| 759 | static_cast<int>(params_.video[video_idx].width), |
| 760 | static_cast<int>(params_.video[video_idx].height), |
| 761 | test::FrameGenerator::OutputType::I010, absl::nullopt, |
| 762 | params_.video[video_idx].fps, clock_)); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 763 | } else if (params_.video[video_idx].clip_name.empty()) { |
| 764 | video_capturers_[video_idx].reset(test::VcmCapturer::Create( |
| 765 | params_.video[video_idx].width, params_.video[video_idx].height, |
| 766 | params_.video[video_idx].fps, |
| 767 | params_.video[video_idx].capture_device_index)); |
| 768 | if (!video_capturers_[video_idx]) { |
| 769 | // Failed to get actual camera, use chroma generator as backup. |
| 770 | video_capturers_[video_idx].reset( |
| 771 | test::FrameGeneratorCapturer::Create( |
| 772 | static_cast<int>(params_.video[video_idx].width), |
| 773 | static_cast<int>(params_.video[video_idx].height), |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 774 | absl::nullopt, absl::nullopt, params_.video[video_idx].fps, |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 775 | clock_)); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 776 | } |
| 777 | } else { |
| 778 | video_capturers_[video_idx].reset( |
| 779 | test::FrameGeneratorCapturer::CreateFromYuvFile( |
| 780 | test::ResourcePath(params_.video[video_idx].clip_name, "yuv"), |
| 781 | params_.video[video_idx].width, params_.video[video_idx].height, |
| 782 | params_.video[video_idx].fps, clock_)); |
| 783 | ASSERT_TRUE(video_capturers_[video_idx]) |
| 784 | << "Could not create capturer for " |
| 785 | << params_.video[video_idx].clip_name |
| 786 | << ".yuv. Is this resource file present?"; |
| 787 | } |
| 788 | } |
| 789 | RTC_DCHECK(video_capturers_[video_idx].get()); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 790 | video_sources_.push_back(video_capturers_[video_idx].get()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 791 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 794 | void VideoQualityTest::StartAudioStreams() { |
| 795 | audio_send_stream_->Start(); |
| 796 | for (AudioReceiveStream* audio_recv_stream : audio_receive_streams_) |
| 797 | audio_recv_stream->Start(); |
| 798 | } |
| 799 | |
| 800 | void VideoQualityTest::StartThumbnailCapture() { |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 801 | for (std::unique_ptr<test::TestVideoCapturer>& capturer : |
| 802 | thumbnail_capturers_) |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 803 | capturer->Start(); |
| 804 | } |
| 805 | |
| 806 | void VideoQualityTest::StopThumbnailCapture() { |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 807 | for (std::unique_ptr<test::TestVideoCapturer>& capturer : |
| 808 | thumbnail_capturers_) |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 809 | capturer->Stop(); |
| 810 | } |
| 811 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 812 | void VideoQualityTest::StartThumbnails() { |
| 813 | for (VideoSendStream* send_stream : thumbnail_send_streams_) |
| 814 | send_stream->Start(); |
| 815 | for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_) |
| 816 | receive_stream->Start(); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | void VideoQualityTest::StopThumbnails() { |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 820 | for (VideoReceiveStream* receive_stream : thumbnail_receive_streams_) |
| 821 | receive_stream->Stop(); |
| 822 | for (VideoSendStream* send_stream : thumbnail_send_streams_) |
| 823 | send_stream->Stop(); |
| 824 | } |
| 825 | |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 826 | std::unique_ptr<test::LayerFilteringTransport> |
| 827 | VideoQualityTest::CreateSendTransport() { |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 828 | std::unique_ptr<NetworkSimulationInterface> simulated_network = nullptr; |
| 829 | if (injection_components_->sender_network == nullptr) { |
| 830 | simulated_network = absl::make_unique<SimulatedNetwork>(*params_.config); |
| 831 | } else { |
| 832 | simulated_network = std::move(injection_components_->sender_network); |
| 833 | } |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 834 | return absl::make_unique<test::LayerFilteringTransport>( |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 835 | &task_queue_, |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 836 | absl::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(), |
| 837 | std::move(simulated_network)), |
Artem Titov | 4e199e9 | 2018-08-20 13:30:39 +0200 | [diff] [blame] | 838 | sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9, |
| 839 | params_.video[0].selected_tl, params_.ss[0].selected_sl, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 840 | payload_type_map_, kVideoSendSsrcs[0], |
| 841 | static_cast<uint32_t>(kVideoSendSsrcs[0] + params_.ss[0].streams.size() - |
| 842 | 1)); |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | std::unique_ptr<test::DirectTransport> |
| 846 | VideoQualityTest::CreateReceiveTransport() { |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 847 | std::unique_ptr<NetworkSimulationInterface> simulated_network = nullptr; |
| 848 | if (injection_components_->receiver_network == nullptr) { |
| 849 | simulated_network = absl::make_unique<SimulatedNetwork>(*params_.config); |
| 850 | } else { |
| 851 | simulated_network = std::move(injection_components_->receiver_network); |
| 852 | } |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 853 | return absl::make_unique<test::DirectTransport>( |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 854 | &task_queue_, |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 855 | absl::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(), |
| 856 | std::move(simulated_network)), |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 857 | receiver_call_.get(), payload_type_map_); |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 858 | } |
| 859 | |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 860 | void VideoQualityTest::RunWithAnalyzer(const Params& params) { |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 861 | num_video_streams_ = params.call.dual_video ? 2 : 1; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 862 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 863 | std::unique_ptr<test::DirectTransport> recv_transport; |
| 864 | FILE* graph_data_output_file = nullptr; |
| 865 | std::unique_ptr<VideoAnalyzer> analyzer; |
| 866 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 867 | params_ = params; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 868 | // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to |
| 869 | // differentiate between the analyzer and the renderer case. |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 870 | CheckParamsAndInjectionComponents(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 871 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 872 | if (!params_.analyzer.graph_data_output_filename.empty()) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 873 | graph_data_output_file = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 874 | fopen(params_.analyzer.graph_data_output_filename.c_str(), "w"); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 875 | RTC_CHECK(graph_data_output_file) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 876 | << "Can't open the file " << params_.analyzer.graph_data_output_filename |
| 877 | << "!"; |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 878 | } |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 879 | |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 880 | if (!params.logging.rtc_event_log_name.empty()) { |
Bjorn Terelius | 0a6a2b7 | 2018-01-19 17:52:38 +0100 | [diff] [blame] | 881 | send_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy); |
| 882 | recv_event_log_ = RtcEventLog::Create(RtcEventLog::EncodingType::Legacy); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 883 | std::unique_ptr<RtcEventLogOutputFile> send_output( |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 884 | absl::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 885 | params.logging.rtc_event_log_name + "_send", |
| 886 | RtcEventLog::kUnlimitedOutput)); |
| 887 | std::unique_ptr<RtcEventLogOutputFile> recv_output( |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 888 | absl::make_unique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 889 | params.logging.rtc_event_log_name + "_recv", |
| 890 | RtcEventLog::kUnlimitedOutput)); |
| 891 | bool event_log_started = |
| 892 | send_event_log_->StartLogging(std::move(send_output), |
| 893 | RtcEventLog::kImmediateOutput) && |
| 894 | recv_event_log_->StartLogging(std::move(recv_output), |
| 895 | RtcEventLog::kImmediateOutput); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 896 | RTC_DCHECK(event_log_started); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 897 | } else { |
| 898 | send_event_log_ = RtcEventLog::CreateNull(); |
| 899 | recv_event_log_ = RtcEventLog::CreateNull(); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 902 | Call::Config send_call_config(send_event_log_.get()); |
| 903 | Call::Config recv_call_config(recv_event_log_.get()); |
| 904 | send_call_config.bitrate_config = params.call.call_bitrate_config; |
| 905 | recv_call_config.bitrate_config = params.call.call_bitrate_config; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 906 | |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 907 | task_queue_.SendTask([this, &send_call_config, &recv_call_config, |
| 908 | &send_transport, &recv_transport]() { |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 909 | if (params_.audio.enabled) |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 910 | InitializeAudioDevice( |
| 911 | &send_call_config, &recv_call_config, params_.audio.use_real_adm); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 912 | |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 913 | CreateCalls(send_call_config, recv_call_config); |
| 914 | send_transport = CreateSendTransport(); |
| 915 | recv_transport = CreateReceiveTransport(); |
| 916 | }); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 917 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 918 | std::string graph_title = params_.analyzer.graph_title; |
| 919 | if (graph_title.empty()) |
| 920 | graph_title = VideoQualityTest::GenerateGraphTitle(); |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame] | 921 | bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest"); |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 922 | analyzer = absl::make_unique<VideoAnalyzer>( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 923 | send_transport.get(), params_.analyzer.test_label, |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 924 | params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold, |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 925 | is_quick_test_enabled |
| 926 | ? kFramesSentInQuickTest |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 927 | : params_.analyzer.test_durations_secs * params_.video[0].fps, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 928 | graph_data_output_file, graph_title, |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 929 | kVideoSendSsrcs[params_.ss[0].selected_stream], |
| 930 | kSendRtxSsrcs[params_.ss[0].selected_stream], |
| 931 | static_cast<size_t>(params_.ss[0].selected_stream), |
| 932 | params.ss[0].selected_sl, params_.video[0].selected_tl, |
| 933 | is_quick_test_enabled, clock_, params_.logging.rtp_dump_name); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 934 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 935 | task_queue_.SendTask([&]() { |
| 936 | analyzer->SetCall(sender_call_.get()); |
| 937 | analyzer->SetReceiver(receiver_call_->Receiver()); |
| 938 | send_transport->SetReceiver(analyzer.get()); |
| 939 | recv_transport->SetReceiver(sender_call_->Receiver()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 940 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 941 | SetupVideo(analyzer.get(), recv_transport.get()); |
| 942 | SetupThumbnails(analyzer.get(), recv_transport.get()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 943 | video_receive_configs_[params_.ss[0].selected_stream].renderer = |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 944 | analyzer.get(); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 945 | GetVideoSendConfig()->pre_encode_callback = analyzer->pre_encode_proxy(); |
| 946 | RTC_DCHECK(!GetVideoSendConfig()->post_encode_callback); |
| 947 | GetVideoSendConfig()->post_encode_callback = analyzer.get(); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 948 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 949 | CreateFlexfecStreams(); |
| 950 | CreateVideoStreams(); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 951 | analyzer->SetSendStream(video_send_streams_[0]); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 952 | if (video_receive_streams_.size() == 1) |
| 953 | analyzer->SetReceiveStream(video_receive_streams_[0]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 954 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 955 | GetVideoSendStream()->SetSource(analyzer->OutputInterface(), |
| 956 | degradation_preference_); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 957 | SetupThumbnailCapturers(params_.call.num_thumbnails); |
| 958 | for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) { |
| 959 | thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(), |
| 960 | degradation_preference_); |
| 961 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 962 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 963 | CreateCapturers(); |
ivica | c1cc854 | 2015-10-08 03:44:06 -0700 | [diff] [blame] | 964 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 965 | analyzer->SetSource(video_capturers_[0].get(), params_.ss[0].infer_streams); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 966 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 967 | for (size_t video_idx = 1; video_idx < num_video_streams_; ++video_idx) { |
| 968 | video_send_streams_[video_idx]->SetSource( |
| 969 | video_capturers_[video_idx].get(), degradation_preference_); |
| 970 | } |
| 971 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 972 | StartEncodedFrameLogs(GetVideoSendStream()); |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 973 | StartEncodedFrameLogs( |
| 974 | video_receive_streams_[params_.ss[0].selected_stream]); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 975 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 976 | if (params_.audio.enabled) { |
| 977 | SetupAudio(send_transport.get()); |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 978 | StartAudioStreams(); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 979 | analyzer->SetAudioReceiveStream(audio_receive_streams_[0]); |
| 980 | } |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 981 | StartVideoStreams(); |
| 982 | StartThumbnails(); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 983 | analyzer->StartMeasuringCpuProcessTime(); |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 984 | StartVideoCapture(); |
| 985 | StartThumbnailCapture(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 986 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 987 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 988 | analyzer->Wait(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 989 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 990 | task_queue_.SendTask([&]() { |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 991 | StopThumbnailCapture(); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 992 | StopThumbnails(); |
| 993 | Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 994 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 995 | DestroyStreams(); |
| 996 | DestroyThumbnailStreams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 997 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 998 | if (graph_data_output_file) |
| 999 | fclose(graph_data_output_file); |
| 1000 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1001 | video_capturers_.clear(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1002 | send_transport.reset(); |
| 1003 | recv_transport.reset(); |
| 1004 | |
| 1005 | DestroyCalls(); |
| 1006 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1009 | rtc::scoped_refptr<AudioDeviceModule> VideoQualityTest::CreateAudioDevice() { |
| 1010 | #ifdef WEBRTC_WIN |
| 1011 | RTC_LOG(INFO) << "Using latest version of ADM on Windows"; |
| 1012 | // We must initialize the COM library on a thread before we calling any of |
| 1013 | // the library functions. All COM functions in the ADM will return |
| 1014 | // CO_E_NOTINITIALIZED otherwise. The legacy ADM for Windows used internal |
| 1015 | // COM initialization but the new ADM requires COM to be initialized |
| 1016 | // externally. |
| 1017 | com_initializer_ = absl::make_unique<webrtc_win::ScopedCOMInitializer>( |
| 1018 | webrtc_win::ScopedCOMInitializer::kMTA); |
| 1019 | RTC_CHECK(com_initializer_->Succeeded()); |
| 1020 | RTC_CHECK(webrtc_win::core_audio_utility::IsSupported()); |
| 1021 | RTC_CHECK(webrtc_win::core_audio_utility::IsMMCSSSupported()); |
| 1022 | return CreateWindowsCoreAudioAudioDeviceModule(); |
| 1023 | #else |
| 1024 | // Use legacy factory method on all platforms except Windows. |
| 1025 | return AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio); |
| 1026 | #endif |
| 1027 | } |
| 1028 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1029 | void VideoQualityTest::InitializeAudioDevice(Call::Config* send_call_config, |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1030 | Call::Config* recv_call_config, |
| 1031 | bool use_real_adm) { |
| 1032 | rtc::scoped_refptr<AudioDeviceModule> audio_device; |
| 1033 | if (use_real_adm) { |
| 1034 | // Run test with real ADM (using default audio devices) if user has |
| 1035 | // explicitly set the --audio and --use_real_adm command-line flags. |
| 1036 | audio_device = CreateAudioDevice(); |
| 1037 | } else { |
| 1038 | // By default, create a test ADM which fakes audio. |
| 1039 | audio_device = TestAudioDeviceModule::CreateTestAudioDeviceModule( |
| 1040 | TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, 48000), |
| 1041 | TestAudioDeviceModule::CreateDiscardRenderer(48000), 1.f); |
| 1042 | } |
| 1043 | RTC_CHECK(audio_device); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1044 | |
| 1045 | AudioState::Config audio_state_config; |
| 1046 | audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
| 1047 | audio_state_config.audio_processing = AudioProcessingBuilder().Create(); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1048 | audio_state_config.audio_device_module = audio_device; |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1049 | send_call_config->audio_state = AudioState::Create(audio_state_config); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1050 | recv_call_config->audio_state = AudioState::Create(audio_state_config); |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1051 | if (use_real_adm) { |
| 1052 | // The real ADM requires extra initialization: setting default devices, |
| 1053 | // setting up number of channels etc. Helper class also calls |
| 1054 | // AudioDeviceModule::Init(). |
| 1055 | webrtc::adm_helpers::Init(audio_device.get()); |
| 1056 | } else { |
| 1057 | audio_device->Init(); |
| 1058 | } |
| 1059 | // Always initialize the ADM before injecting a valid audio transport. |
| 1060 | RTC_CHECK(audio_device->RegisterAudioCallback( |
| 1061 | send_call_config->audio_state->audio_transport()) == 0); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1064 | void VideoQualityTest::SetupAudio(Transport* transport) { |
| 1065 | AudioSendStream::Config audio_send_config(transport); |
| 1066 | audio_send_config.rtp.ssrc = kAudioSendSsrc; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1067 | |
| 1068 | // Add extension to enable audio send side BWE, and allow audio bit rate |
| 1069 | // adaptation. |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1070 | audio_send_config.rtp.extensions.clear(); |
| 1071 | audio_send_config.send_codec_spec = AudioSendStream::Config::SendCodecSpec( |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 1072 | kAudioSendPayloadType, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1073 | {"OPUS", |
| 1074 | 48000, |
| 1075 | 2, |
| 1076 | {{"usedtx", (params_.audio.dtx ? "1" : "0")}, {"stereo", "1"}}}); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1077 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1078 | if (params_.call.send_side_bwe) { |
| 1079 | audio_send_config.rtp.extensions.push_back( |
| 1080 | webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri, |
| 1081 | test::kTransportSequenceNumberExtensionId)); |
| 1082 | audio_send_config.min_bitrate_bps = kOpusMinBitrateBps; |
| 1083 | audio_send_config.max_bitrate_bps = kOpusBitrateFbBps; |
| 1084 | audio_send_config.send_codec_spec->transport_cc_enabled = true; |
| 1085 | } |
| 1086 | audio_send_config.encoder_factory = audio_encoder_factory_; |
| 1087 | SetAudioConfig(audio_send_config); |
| 1088 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1089 | std::string sync_group; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1090 | if (params_.video[0].enabled && params_.audio.sync_video) |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1091 | sync_group = kSyncGroup; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1092 | |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1093 | CreateMatchingAudioConfigs(transport, sync_group); |
| 1094 | CreateAudioStreams(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1097 | void VideoQualityTest::RunWithRenderers(const Params& params) { |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1098 | RTC_LOG(INFO) << __FUNCTION__; |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1099 | num_video_streams_ = params.call.dual_video ? 2 : 1; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1100 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 1101 | std::unique_ptr<test::DirectTransport> recv_transport; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1102 | std::unique_ptr<test::VideoRenderer> local_preview; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1103 | std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers; |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 1104 | RtcEventLogNullImpl null_event_log; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1105 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1106 | task_queue_.SendTask([&]() { |
| 1107 | params_ = params; |
Artem Titov | e269cb4 | 2018-08-29 09:59:23 +0200 | [diff] [blame] | 1108 | CheckParamsAndInjectionComponents(); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1109 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1110 | // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to |
| 1111 | // match the full stack tests. |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1112 | Call::Config send_call_config(&null_event_log); |
| 1113 | send_call_config.bitrate_config = params_.call.call_bitrate_config; |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 1114 | Call::Config recv_call_config(&null_event_log); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1115 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1116 | if (params_.audio.enabled) |
henrika | 255750b | 2018-08-27 16:13:37 +0200 | [diff] [blame] | 1117 | InitializeAudioDevice( |
| 1118 | &send_call_config, &recv_call_config, params_.audio.use_real_adm); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1119 | |
Christoffer Rodbro | 39a44b2 | 2018-08-07 17:07:24 +0200 | [diff] [blame] | 1120 | CreateCalls(send_call_config, recv_call_config); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1121 | |
| 1122 | // TODO(minyue): consider if this is a good transport even for audio only |
| 1123 | // calls. |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1124 | send_transport = CreateSendTransport(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1125 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1126 | recv_transport = CreateReceiveTransport(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1127 | |
| 1128 | // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at |
| 1129 | // least share as much code as possible. That way this test would also match |
| 1130 | // the full stack tests better. |
| 1131 | send_transport->SetReceiver(receiver_call_->Receiver()); |
| 1132 | recv_transport->SetReceiver(sender_call_->Receiver()); |
| 1133 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1134 | if (params_.video[0].enabled) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1135 | // Create video renderers. |
| 1136 | local_preview.reset(test::VideoRenderer::Create( |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1137 | "Local Preview", params_.video[0].width, params_.video[0].height)); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1138 | |
| 1139 | SetupVideo(send_transport.get(), recv_transport.get()); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1140 | GetVideoSendConfig()->pre_encode_callback = local_preview.get(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1141 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1142 | size_t num_streams_processed = 0; |
| 1143 | for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) { |
| 1144 | const size_t selected_stream_id = params_.ss[video_idx].selected_stream; |
| 1145 | const size_t num_streams = params_.ss[video_idx].streams.size(); |
| 1146 | if (selected_stream_id == num_streams) { |
| 1147 | for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) { |
| 1148 | std::ostringstream oss; |
| 1149 | oss << "Loopback Video #" << video_idx << " - Stream #" |
| 1150 | << static_cast<int>(stream_id); |
| 1151 | loopback_renderers.emplace_back(test::VideoRenderer::Create( |
| 1152 | oss.str().c_str(), |
| 1153 | params_.ss[video_idx].streams[stream_id].width, |
| 1154 | params_.ss[video_idx].streams[stream_id].height)); |
| 1155 | video_receive_configs_[stream_id + num_streams_processed].renderer = |
| 1156 | loopback_renderers.back().get(); |
| 1157 | if (params_.audio.enabled && params_.audio.sync_video) |
| 1158 | video_receive_configs_[stream_id + num_streams_processed] |
| 1159 | .sync_group = kSyncGroup; |
| 1160 | } |
| 1161 | } else { |
| 1162 | std::ostringstream oss; |
| 1163 | oss << "Loopback Video #" << video_idx; |
| 1164 | loopback_renderers.emplace_back(test::VideoRenderer::Create( |
| 1165 | oss.str().c_str(), |
| 1166 | params_.ss[video_idx].streams[selected_stream_id].width, |
| 1167 | params_.ss[video_idx].streams[selected_stream_id].height)); |
| 1168 | video_receive_configs_[selected_stream_id + num_streams_processed] |
| 1169 | .renderer = loopback_renderers.back().get(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1170 | if (params_.audio.enabled && params_.audio.sync_video) |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1171 | video_receive_configs_[num_streams_processed + selected_stream_id] |
| 1172 | .sync_group = kSyncGroup; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1173 | } |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1174 | num_streams_processed += num_streams; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1175 | } |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1176 | CreateFlexfecStreams(); |
| 1177 | CreateVideoStreams(); |
| 1178 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1179 | CreateCapturers(); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1180 | ConnectVideoSourcesToStreams(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | if (params_.audio.enabled) { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1184 | SetupAudio(send_transport.get()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 1188 | StartEncodedFrameLogs(receive_stream); |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1189 | StartEncodedFrameLogs(GetVideoSendStream()); |
| 1190 | Start(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1191 | }); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1192 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1193 | test::PressEnterToContinue(); |
| 1194 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1195 | task_queue_.SendTask([&]() { |
Sebastian Jansson | 3bd2c79 | 2018-07-13 13:29:03 +0200 | [diff] [blame] | 1196 | Stop(); |
| 1197 | DestroyStreams(); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1198 | |
Ilya Nikolaevskiy | 255d1cd | 2017-12-21 18:02:59 +0100 | [diff] [blame] | 1199 | video_capturers_.clear(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1200 | send_transport.reset(); |
| 1201 | recv_transport.reset(); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1202 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1203 | local_preview.reset(); |
| 1204 | loopback_renderers.clear(); |
| 1205 | |
| 1206 | DestroyCalls(); |
| 1207 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1210 | void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1211 | if (!params_.logging.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1212 | std::ostringstream str; |
| 1213 | str << send_logs_++; |
| 1214 | std::string prefix = |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1215 | params_.logging.encoded_frame_base_path + "." + str.str() + ".send."; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1216 | stream->EnableEncodedFrameRecording( |
| 1217 | std::vector<rtc::PlatformFile>( |
| 1218 | {rtc::CreatePlatformFile(prefix + "1.ivf"), |
| 1219 | rtc::CreatePlatformFile(prefix + "2.ivf"), |
| 1220 | rtc::CreatePlatformFile(prefix + "3.ivf")}), |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1221 | 100000000); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1222 | } |
| 1223 | } |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 1224 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1225 | void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1226 | if (!params_.logging.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1227 | std::ostringstream str; |
| 1228 | str << receive_logs_++; |
| 1229 | std::string path = |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1230 | params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1231 | stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1232 | 100000000); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1233 | } |
| 1234 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1235 | } // namespace webrtc |