blob: c8ac2f163e9f68c8b956b70a83596a9886be85e2 [file] [log] [blame]
Åsa Persson2027b662018-05-02 18:08:06 +02001/*
2 * Copyright (c) 2018 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 */
10
11#include <string>
12
Danil Chapovalov99b71df2018-10-26 15:57:48 +020013#include "api/test/video/function_video_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080014#include "media/engine/internal_encoder_factory.h"
Åsa Persson2027b662018-05-02 18:08:06 +020015#include "modules/video_coding/codecs/h264/include/h264.h"
16#include "modules/video_coding/codecs/vp8/include/vp8.h"
17#include "modules/video_coding/codecs/vp9/include/vp9.h"
Åsa Persson258e9892021-02-25 10:39:51 +010018#include "rtc_base/experiments/encoder_info_settings.h"
Åsa Persson2027b662018-05-02 18:08:06 +020019#include "test/call_test.h"
20#include "test/field_trial.h"
21#include "test/frame_generator_capturer.h"
Åsa Persson2027b662018-05-02 18:08:06 +020022
23namespace webrtc {
24namespace {
Åsa Persson4e609372021-05-17 10:37:28 +020025constexpr int kInitialWidth = 1280;
26constexpr int kInitialHeight = 720;
Åsa Persson2027b662018-05-02 18:08:06 +020027constexpr int kLowStartBps = 100000;
Åsa Persson258e9892021-02-25 10:39:51 +010028constexpr int kHighStartBps = 1000000;
Åsa Persson4e609372021-05-17 10:37:28 +020029constexpr int kDefaultVgaMinStartBps = 500000; // From video_stream_encoder.cc
30constexpr int kTimeoutMs = 10000; // Some tests are expected to time out.
Åsa Persson2027b662018-05-02 18:08:06 +020031
32void SetEncoderSpecific(VideoEncoderConfig* encoder_config,
33 VideoCodecType type,
Åsa Persson2c8d9292021-02-15 17:49:37 +010034 bool automatic_resize,
35 size_t num_spatial_layers) {
Åsa Persson2027b662018-05-02 18:08:06 +020036 if (type == kVideoCodecVP8) {
37 VideoCodecVP8 vp8 = VideoEncoder::GetDefaultVp8Settings();
38 vp8.automaticResizeOn = automatic_resize;
Tomas Gunnarssonc1d58912021-04-22 19:21:43 +020039 encoder_config->encoder_specific_settings =
40 rtc::make_ref_counted<VideoEncoderConfig::Vp8EncoderSpecificSettings>(
41 vp8);
Åsa Persson2027b662018-05-02 18:08:06 +020042 } else if (type == kVideoCodecVP9) {
43 VideoCodecVP9 vp9 = VideoEncoder::GetDefaultVp9Settings();
44 vp9.automaticResizeOn = automatic_resize;
Åsa Persson2c8d9292021-02-15 17:49:37 +010045 vp9.numberOfSpatialLayers = num_spatial_layers;
Tomas Gunnarssonc1d58912021-04-22 19:21:43 +020046 encoder_config->encoder_specific_settings =
47 rtc::make_ref_counted<VideoEncoderConfig::Vp9EncoderSpecificSettings>(
48 vp9);
Åsa Persson2027b662018-05-02 18:08:06 +020049 }
50}
51} // namespace
52
53class QualityScalingTest : public test::CallTest {
54 protected:
Åsa Persson2027b662018-05-02 18:08:06 +020055 const std::string kPrefix = "WebRTC-Video-QualityScaling/Enabled-";
56 const std::string kEnd = ",0,0,0.9995,0.9999,1/";
Åsa Persson258e9892021-02-25 10:39:51 +010057 const absl::optional<VideoEncoder::ResolutionBitrateLimits>
Sergey Silkina86b29b2021-03-05 13:29:19 +010058 kSinglecastLimits720pVp8 =
Åsa Persson258e9892021-02-25 10:39:51 +010059 EncoderInfoSettings::GetDefaultSinglecastBitrateLimitsForResolution(
Sergey Silkina86b29b2021-03-05 13:29:19 +010060 kVideoCodecVP8,
Åsa Persson258e9892021-02-25 10:39:51 +010061 1280 * 720);
Sergey Silkina86b29b2021-03-05 13:29:19 +010062 const absl::optional<VideoEncoder::ResolutionBitrateLimits>
63 kSinglecastLimits360pVp9 =
64 EncoderInfoSettings::GetDefaultSinglecastBitrateLimitsForResolution(
65 kVideoCodecVP9,
66 640 * 360);
Asa Persson2ee3e4d2022-05-20 14:22:27 +020067 const absl::optional<VideoEncoder::ResolutionBitrateLimits>
68 kSinglecastLimits720pVp9 =
69 EncoderInfoSettings::GetDefaultSinglecastBitrateLimitsForResolution(
70 kVideoCodecVP9,
71 1280 * 720);
Åsa Persson2027b662018-05-02 18:08:06 +020072};
73
Åsa Persson4e609372021-05-17 10:37:28 +020074class ScalingObserver : public test::SendTest {
75 protected:
Asa Persson2ee3e4d2022-05-20 14:22:27 +020076 struct TestParams {
77 bool active;
78 absl::optional<ScalabilityMode> scalability_mode;
79 };
Åsa Persson4e609372021-05-17 10:37:28 +020080 ScalingObserver(const std::string& payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +020081 const std::vector<TestParams>& test_params,
Åsa Persson4e609372021-05-17 10:37:28 +020082 int start_bps,
83 bool automatic_resize,
84 bool expect_scaling)
85 : SendTest(expect_scaling ? kTimeoutMs * 4 : kTimeoutMs),
86 encoder_factory_(
87 [](const SdpVideoFormat& format) -> std::unique_ptr<VideoEncoder> {
88 if (format.name == "VP8")
89 return VP8Encoder::Create();
90 if (format.name == "VP9")
91 return VP9Encoder::Create();
92 if (format.name == "H264")
93 return H264Encoder::Create(cricket::VideoCodec("H264"));
Artem Titovd3251962021-11-15 16:57:07 +010094 RTC_DCHECK_NOTREACHED() << format.name;
Åsa Persson4e609372021-05-17 10:37:28 +020095 return nullptr;
96 }),
97 payload_name_(payload_name),
Asa Persson2ee3e4d2022-05-20 14:22:27 +020098 test_params_(test_params),
Åsa Persson4e609372021-05-17 10:37:28 +020099 start_bps_(start_bps),
100 automatic_resize_(automatic_resize),
101 expect_scaling_(expect_scaling) {}
102
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200103 DegradationPreference degradation_preference_ =
104 DegradationPreference::MAINTAIN_FRAMERATE;
105
Åsa Persson4e609372021-05-17 10:37:28 +0200106 private:
107 void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override {
108 bitrate_config->start_bitrate_bps = start_bps_;
109 }
110
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200111 void ModifyVideoDegradationPreference(
112 DegradationPreference* degradation_preference) override {
113 *degradation_preference = degradation_preference_;
114 }
115
Åsa Persson4e609372021-05-17 10:37:28 +0200116 size_t GetNumVideoStreams() const override {
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200117 return (payload_name_ == "VP9") ? 1 : test_params_.size();
Åsa Persson4e609372021-05-17 10:37:28 +0200118 }
119
120 void ModifyVideoConfigs(
121 VideoSendStream::Config* send_config,
122 std::vector<VideoReceiveStream::Config>* receive_configs,
123 VideoEncoderConfig* encoder_config) override {
124 send_config->encoder_settings.encoder_factory = &encoder_factory_;
125 send_config->rtp.payload_name = payload_name_;
126 send_config->rtp.payload_type = test::CallTest::kVideoSendPayloadType;
127 encoder_config->video_format.name = payload_name_;
128 const VideoCodecType codec_type = PayloadStringToCodecType(payload_name_);
129 encoder_config->codec_type = codec_type;
130 encoder_config->max_bitrate_bps =
131 std::max(start_bps_, encoder_config->max_bitrate_bps);
132 if (payload_name_ == "VP9") {
133 // Simulcast layers indicates which spatial layers are active.
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200134 encoder_config->simulcast_layers.resize(test_params_.size());
Åsa Persson4e609372021-05-17 10:37:28 +0200135 encoder_config->simulcast_layers[0].max_bitrate_bps =
136 encoder_config->max_bitrate_bps;
137 }
138 double scale_factor = 1.0;
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200139 for (int i = test_params_.size() - 1; i >= 0; --i) {
Åsa Persson4e609372021-05-17 10:37:28 +0200140 VideoStream& stream = encoder_config->simulcast_layers[i];
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200141 stream.active = test_params_[i].active;
142 stream.scalability_mode = test_params_[i].scalability_mode;
Åsa Persson4e609372021-05-17 10:37:28 +0200143 stream.scale_resolution_down_by = scale_factor;
144 scale_factor *= (payload_name_ == "VP9") ? 1.0 : 2.0;
145 }
Niels Möller807328f2022-05-12 16:16:39 +0200146 encoder_config->frame_drop_enabled = true;
Åsa Persson4e609372021-05-17 10:37:28 +0200147 SetEncoderSpecific(encoder_config, codec_type, automatic_resize_,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200148 test_params_.size());
Åsa Persson4e609372021-05-17 10:37:28 +0200149 }
150
151 void PerformTest() override { EXPECT_EQ(expect_scaling_, Wait()); }
152
153 test::FunctionVideoEncoderFactory encoder_factory_;
154 const std::string payload_name_;
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200155 const std::vector<TestParams> test_params_;
Åsa Persson4e609372021-05-17 10:37:28 +0200156 const int start_bps_;
157 const bool automatic_resize_;
158 const bool expect_scaling_;
159};
160
161class DownscalingObserver
162 : public ScalingObserver,
163 public test::FrameGeneratorCapturer::SinkWantsObserver {
164 public:
165 DownscalingObserver(const std::string& payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200166 const std::vector<TestParams>& test_params,
Åsa Persson4e609372021-05-17 10:37:28 +0200167 int start_bps,
168 bool automatic_resize,
169 bool expect_downscale)
170 : ScalingObserver(payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200171 test_params,
Åsa Persson4e609372021-05-17 10:37:28 +0200172 start_bps,
173 automatic_resize,
174 expect_downscale) {}
175
176 private:
177 void OnFrameGeneratorCapturerCreated(
178 test::FrameGeneratorCapturer* frame_generator_capturer) override {
179 frame_generator_capturer->SetSinkWantsObserver(this);
180 frame_generator_capturer->ChangeResolution(kInitialWidth, kInitialHeight);
181 }
182
183 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
184 const rtc::VideoSinkWants& wants) override {
185 if (wants.max_pixel_count < kInitialWidth * kInitialHeight)
186 observation_complete_.Set();
187 }
188};
189
190class UpscalingObserver
191 : public ScalingObserver,
192 public test::FrameGeneratorCapturer::SinkWantsObserver {
193 public:
194 UpscalingObserver(const std::string& payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200195 const std::vector<TestParams>& test_params,
Åsa Persson2027b662018-05-02 18:08:06 +0200196 int start_bps,
197 bool automatic_resize,
Åsa Persson4e609372021-05-17 10:37:28 +0200198 bool expect_upscale)
199 : ScalingObserver(payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200200 test_params,
Åsa Persson4e609372021-05-17 10:37:28 +0200201 start_bps,
202 automatic_resize,
203 expect_upscale) {}
Åsa Persson2027b662018-05-02 18:08:06 +0200204
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200205 void SetDegradationPreference(DegradationPreference preference) {
206 degradation_preference_ = preference;
207 }
208
Åsa Persson4e609372021-05-17 10:37:28 +0200209 private:
210 void OnFrameGeneratorCapturerCreated(
211 test::FrameGeneratorCapturer* frame_generator_capturer) override {
212 frame_generator_capturer->SetSinkWantsObserver(this);
213 frame_generator_capturer->ChangeResolution(kInitialWidth, kInitialHeight);
214 }
Åsa Persson2027b662018-05-02 18:08:06 +0200215
Åsa Persson4e609372021-05-17 10:37:28 +0200216 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
217 const rtc::VideoSinkWants& wants) override {
218 if (wants.max_pixel_count > last_wants_.max_pixel_count) {
219 if (wants.max_pixel_count == std::numeric_limits<int>::max())
Åsa Persson8c1bf952018-09-13 10:42:19 +0200220 observation_complete_.Set();
Åsa Persson2027b662018-05-02 18:08:06 +0200221 }
Åsa Persson4e609372021-05-17 10:37:28 +0200222 last_wants_ = wants;
223 }
Åsa Persson2027b662018-05-02 18:08:06 +0200224
Åsa Persson4e609372021-05-17 10:37:28 +0200225 rtc::VideoSinkWants last_wants_;
226};
Åsa Persson2027b662018-05-02 18:08:06 +0200227
228TEST_F(QualityScalingTest, AdaptsDownForHighQp_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100229 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100230 test::ScopedKeyValueConfig field_trials(field_trials_,
231 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200232
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200233 DownscalingObserver test("VP8", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200234 /*automatic_resize=*/true,
235 /*expect_downscale=*/true);
236 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200237}
238
Åsa Persson2c8d9292021-02-15 17:49:37 +0100239TEST_F(QualityScalingTest, NoAdaptDownForHighQpIfScalingOff_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100240 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100241 test::ScopedKeyValueConfig field_trials(field_trials_,
242 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200243
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200244 DownscalingObserver test("VP8", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200245 /*automatic_resize=*/false,
246 /*expect_downscale=*/false);
247 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200248}
249
250TEST_F(QualityScalingTest, NoAdaptDownForNormalQp_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100251 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100252 test::ScopedKeyValueConfig field_trials(field_trials_,
253 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200254
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200255 DownscalingObserver test("VP8", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200256 /*automatic_resize=*/true,
257 /*expect_downscale=*/false);
258 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200259}
260
Åsa Persson2c8d9292021-02-15 17:49:37 +0100261TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrate_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100262 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100263 test::ScopedKeyValueConfig field_trials(field_trials_,
264 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200265
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200266 DownscalingObserver test("VP8", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200267 /*automatic_resize=*/true,
268 /*expect_downscale=*/true);
269 RunBaseTest(&test);
270}
271
272TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrateAndThenUp) {
273 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100274 test::ScopedKeyValueConfig field_trials(
275 field_trials_,
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200276 kPrefix + "127,127,0,0,0,0" + kEnd +
Jonas Oreland8ca06132022-03-14 12:52:48 +0100277 "WebRTC-Video-BalancedDegradationSettings/"
278 "pixels:230400|921600,fps:20|30,kbps:300|500/"); // should not affect
Åsa Persson4e609372021-05-17 10:37:28 +0200279
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200280 UpscalingObserver test("VP8", {{.active = true}}, kDefaultVgaMinStartBps - 1,
Åsa Persson4e609372021-05-17 10:37:28 +0200281 /*automatic_resize=*/true, /*expect_upscale=*/true);
282 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200283}
284
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200285TEST_F(QualityScalingTest, AdaptsDownAndThenUpWithBalanced) {
286 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100287 test::ScopedKeyValueConfig field_trials(
288 field_trials_, kPrefix + "127,127,0,0,0,0" + kEnd +
289 "WebRTC-Video-BalancedDegradationSettings/"
290 "pixels:230400|921600,fps:20|30,kbps:300|499/");
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200291
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200292 UpscalingObserver test("VP8", {{.active = true}}, kDefaultVgaMinStartBps - 1,
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200293 /*automatic_resize=*/true, /*expect_upscale=*/true);
294 test.SetDegradationPreference(DegradationPreference::BALANCED);
295 RunBaseTest(&test);
296}
297
298TEST_F(QualityScalingTest, AdaptsDownButNotUpWithBalancedIfBitrateNotEnough) {
299 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100300 test::ScopedKeyValueConfig field_trials(
301 field_trials_, kPrefix + "127,127,0,0,0,0" + kEnd +
302 "WebRTC-Video-BalancedDegradationSettings/"
303 "pixels:230400|921600,fps:20|30,kbps:300|500/");
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200304
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200305 UpscalingObserver test("VP8", {{.active = true}}, kDefaultVgaMinStartBps - 1,
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200306 /*automatic_resize=*/true, /*expect_upscale=*/false);
307 test.SetDegradationPreference(DegradationPreference::BALANCED);
308 RunBaseTest(&test);
309}
310
Åsa Perssonf46723c2020-11-20 15:45:44 +0100311TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrate_Simulcast) {
Åsa Persson453a1252021-02-14 15:16:27 +0100312 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100313 test::ScopedKeyValueConfig field_trials(field_trials_,
314 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100315
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200316 DownscalingObserver test("VP8", {{.active = true}, {.active = true}},
317 kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200318 /*automatic_resize=*/false,
319 /*expect_downscale=*/false);
320 RunBaseTest(&test);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100321}
322
Åsa Persson1dd94a02021-02-18 14:20:03 +0100323TEST_F(QualityScalingTest, AdaptsDownForHighQp_HighestStreamActive_Vp8) {
324 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100325 test::ScopedKeyValueConfig field_trials(field_trials_,
326 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100327
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200328 DownscalingObserver test(
329 "VP8", {{.active = false}, {.active = false}, {.active = true}},
330 kHighStartBps,
331 /*automatic_resize=*/true,
332 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200333 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100334}
335
Åsa Perssonf46723c2020-11-20 15:45:44 +0100336TEST_F(QualityScalingTest,
Åsa Persson2c8d9292021-02-15 17:49:37 +0100337 AdaptsDownForLowStartBitrate_HighestStreamActive_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100338 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100339 test::ScopedKeyValueConfig field_trials(field_trials_,
340 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100341
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200342 DownscalingObserver test(
343 "VP8", {{.active = false}, {.active = false}, {.active = true}},
344 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
345 /*automatic_resize=*/true,
346 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200347 RunBaseTest(&test);
348}
349
350TEST_F(QualityScalingTest, AdaptsDownButNotUpWithMinStartBitrateLimit) {
351 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100352 test::ScopedKeyValueConfig field_trials(field_trials_,
353 kPrefix + "127,127,0,0,0,0" + kEnd);
Åsa Persson4e609372021-05-17 10:37:28 +0200354
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200355 UpscalingObserver test("VP8", {{.active = false}, {.active = true}},
Åsa Persson4e609372021-05-17 10:37:28 +0200356 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
357 /*automatic_resize=*/true, /*expect_upscale=*/false);
358 RunBaseTest(&test);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100359}
360
Åsa Persson258e9892021-02-25 10:39:51 +0100361TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrateIfBitrateEnough_Vp8) {
362 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100363 test::ScopedKeyValueConfig field_trials(field_trials_,
364 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson258e9892021-02-25 10:39:51 +0100365
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200366 DownscalingObserver test(
367 "VP8", {{.active = false}, {.active = false}, {.active = true}},
368 kSinglecastLimits720pVp8->min_start_bitrate_bps,
369 /*automatic_resize=*/true,
370 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200371 RunBaseTest(&test);
Åsa Persson258e9892021-02-25 10:39:51 +0100372}
373
374TEST_F(QualityScalingTest,
375 NoAdaptDownForLowStartBitrateIfDefaultLimitsDisabled_Vp8) {
376 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100377 test::ScopedKeyValueConfig field_trials(
378 field_trials_, kPrefix + "1,127,0,0,0,0" + kEnd +
379 "WebRTC-DefaultBitrateLimitsKillSwitch/Enabled/");
Åsa Persson258e9892021-02-25 10:39:51 +0100380
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200381 DownscalingObserver test(
382 "VP8", {{.active = false}, {.active = false}, {.active = true}},
383 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
384 /*automatic_resize=*/true,
385 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200386 RunBaseTest(&test);
Åsa Persson258e9892021-02-25 10:39:51 +0100387}
388
389TEST_F(QualityScalingTest,
390 NoAdaptDownForLowStartBitrate_OneStreamSinglecastLimitsNotUsed_Vp8) {
391 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100392 test::ScopedKeyValueConfig field_trials(field_trials_,
393 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson258e9892021-02-25 10:39:51 +0100394
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200395 DownscalingObserver test("VP8", {{.active = true}},
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200396 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
397 /*automatic_resize=*/true,
398 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200399 RunBaseTest(&test);
Åsa Persson258e9892021-02-25 10:39:51 +0100400}
401
Åsa Persson1dd94a02021-02-18 14:20:03 +0100402TEST_F(QualityScalingTest, NoAdaptDownForHighQp_LowestStreamActive_Vp8) {
403 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100404 test::ScopedKeyValueConfig field_trials(field_trials_,
405 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100406
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200407 DownscalingObserver test(
408 "VP8", {{.active = true}, {.active = false}, {.active = false}},
409 kHighStartBps,
410 /*automatic_resize=*/true,
411 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200412 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100413}
414
Åsa Perssonf46723c2020-11-20 15:45:44 +0100415TEST_F(QualityScalingTest,
Åsa Persson2c8d9292021-02-15 17:49:37 +0100416 NoAdaptDownForLowStartBitrate_LowestStreamActive_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100417 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100418 test::ScopedKeyValueConfig field_trials(field_trials_,
419 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100420
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200421 DownscalingObserver test(
422 "VP8", {{.active = true}, {.active = false}, {.active = false}},
423 kLowStartBps,
424 /*automatic_resize=*/true,
425 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200426 RunBaseTest(&test);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100427}
428
Åsa Persson2c8d9292021-02-15 17:49:37 +0100429TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrateIfScalingOff_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100430 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100431 test::ScopedKeyValueConfig field_trials(field_trials_,
432 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200433
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200434 DownscalingObserver test("VP8", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200435 /*automatic_resize=*/false,
436 /*expect_downscale=*/false);
437 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200438}
439
Åsa Persson2c8d9292021-02-15 17:49:37 +0100440TEST_F(QualityScalingTest, AdaptsDownForHighQp_Vp9) {
441 // qp_low:1, qp_high:1 -> kHighQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200442 test::ScopedKeyValueConfig field_trials(field_trials_,
443 kPrefix + "0,0,1,1,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100444
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200445 DownscalingObserver test("VP9", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200446 /*automatic_resize=*/true,
447 /*expect_downscale=*/true);
448 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100449}
450
451TEST_F(QualityScalingTest, NoAdaptDownForHighQpIfScalingOff_Vp9) {
Åsa Persson453a1252021-02-14 15:16:27 +0100452 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100453 test::ScopedKeyValueConfig field_trials(
454 field_trials_,
455 kPrefix + "0,0,1,1,0,0" + kEnd + "WebRTC-VP9QualityScaler/Disabled/");
Åsa Persson2027b662018-05-02 18:08:06 +0200456
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200457 DownscalingObserver test("VP9", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200458 /*automatic_resize=*/true,
459 /*expect_downscale=*/false);
460 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200461}
462
Åsa Persson2c8d9292021-02-15 17:49:37 +0100463TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrate_Vp9) {
464 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200465 test::ScopedKeyValueConfig field_trials(field_trials_,
466 kPrefix + "0,0,1,255,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100467
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200468 DownscalingObserver test("VP9", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200469 /*automatic_resize=*/true,
470 /*expect_downscale=*/true);
471 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100472}
473
Åsa Persson1dd94a02021-02-18 14:20:03 +0100474TEST_F(QualityScalingTest, NoAdaptDownForHighQp_LowestStreamActive_Vp9) {
475 // qp_low:1, qp_high:1 -> kHighQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200476 test::ScopedKeyValueConfig field_trials(field_trials_,
477 kPrefix + "0,0,1,1,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100478
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200479 DownscalingObserver test(
480 "VP9", {{.active = true}, {.active = false}, {.active = false}},
481 kHighStartBps,
482 /*automatic_resize=*/true,
483 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200484 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100485}
486
Åsa Persson2c8d9292021-02-15 17:49:37 +0100487TEST_F(QualityScalingTest,
488 NoAdaptDownForLowStartBitrate_LowestStreamActive_Vp9) {
489 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200490 test::ScopedKeyValueConfig field_trials(field_trials_,
491 kPrefix + "0,0,1,255,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100492
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200493 DownscalingObserver test(
494 "VP9", {{.active = true}, {.active = false}, {.active = false}},
495 kLowStartBps,
496 /*automatic_resize=*/true,
497 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200498 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100499}
500
Åsa Persson1dd94a02021-02-18 14:20:03 +0100501TEST_F(QualityScalingTest, AdaptsDownForHighQp_MiddleStreamActive_Vp9) {
502 // qp_low:1, qp_high:1 -> kHighQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200503 test::ScopedKeyValueConfig field_trials(field_trials_,
504 kPrefix + "0,0,1,1,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100505
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200506 DownscalingObserver test(
507 "VP9", {{.active = false}, {.active = true}, {.active = false}},
508 kHighStartBps,
509 /*automatic_resize=*/true,
510 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200511 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100512}
513
Åsa Persson2c8d9292021-02-15 17:49:37 +0100514TEST_F(QualityScalingTest,
515 AdaptsDownForLowStartBitrate_MiddleStreamActive_Vp9) {
516 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200517 test::ScopedKeyValueConfig field_trials(field_trials_,
518 kPrefix + "0,0,1,255,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100519
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200520 DownscalingObserver test(
521 "VP9", {{.active = false}, {.active = true}, {.active = false}},
522 kSinglecastLimits360pVp9->min_start_bitrate_bps - 1,
523 /*automatic_resize=*/true,
524 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200525 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100526}
527
Sergey Silkina86b29b2021-03-05 13:29:19 +0100528TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrateIfBitrateEnough_Vp9) {
529 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200530 test::ScopedKeyValueConfig field_trials(field_trials_,
531 kPrefix + "0,0,1,255,0,0" + kEnd);
Sergey Silkina86b29b2021-03-05 13:29:19 +0100532
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200533 DownscalingObserver test(
534 "VP9", {{.active = false}, {.active = true}, {.active = false}},
535 kSinglecastLimits360pVp9->min_start_bitrate_bps,
536 /*automatic_resize=*/true,
537 /*expect_downscale=*/false);
538 RunBaseTest(&test);
539}
540
541TEST_F(QualityScalingTest,
542 AdaptsDownButNotUpWithMinStartBitrateLimitWithScalabilityMode_VP9) {
543 // qp_low:255, qp_high:255 -> kLowQp
544 test::ScopedKeyValueConfig field_trials(field_trials_,
545 kPrefix + "0,0,255,255,0,0" + kEnd);
546
547 UpscalingObserver test(
548 "VP9",
549 {{.active = true, .scalability_mode = ScalabilityMode::kL1T3},
550 {.active = false}},
551 kSinglecastLimits720pVp9->min_start_bitrate_bps - 1,
552 /*automatic_resize=*/true, /*expect_upscale=*/false);
553 RunBaseTest(&test);
554}
555
556TEST_F(QualityScalingTest,
557 NoAdaptDownForLowStartBitrateIfBitrateEnoughWithScalabilityMode_Vp9) {
558 // qp_low:1, qp_high:255 -> kNormalQp
559 test::ScopedKeyValueConfig field_trials(field_trials_,
560 kPrefix + "0,0,1,255,0,0" + kEnd);
561
562 DownscalingObserver test(
563 "VP9",
564 {{.active = true, .scalability_mode = ScalabilityMode::kL1T3},
565 {.active = false},
566 {.active = false}},
567 kSinglecastLimits720pVp9->min_start_bitrate_bps,
568 /*automatic_resize=*/true,
569 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200570 RunBaseTest(&test);
Sergey Silkina86b29b2021-03-05 13:29:19 +0100571}
572
Åsa Persson2027b662018-05-02 18:08:06 +0200573#if defined(WEBRTC_USE_H264)
574TEST_F(QualityScalingTest, AdaptsDownForHighQp_H264) {
Åsa Persson453a1252021-02-14 15:16:27 +0100575 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100576 test::ScopedKeyValueConfig field_trials(field_trials_,
577 kPrefix + "0,0,0,0,1,1" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200578
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200579 DownscalingObserver test("H264", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200580 /*automatic_resize=*/true,
581 /*expect_downscale=*/true);
582 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200583}
Åsa Persson2c8d9292021-02-15 17:49:37 +0100584
585TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrate_H264) {
586 // qp_low:1, qp_high:51 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100587 test::ScopedKeyValueConfig field_trials(field_trials_,
588 kPrefix + "0,0,0,0,1,51" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100589
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200590 DownscalingObserver test("H264", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200591 /*automatic_resize=*/true,
592 /*expect_downscale=*/true);
593 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100594}
Åsa Persson2027b662018-05-02 18:08:06 +0200595#endif // defined(WEBRTC_USE_H264)
596
597} // namespace webrtc