blob: 7eaf14831b38eb9cc6b3cc6600e4dad1a7ffbf7c [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 Persson0f51bf72022-10-03 09:10:55 +020022#include "video/config/encoder_stream_factory.h"
Åsa Persson2027b662018-05-02 18:08:06 +020023
24namespace webrtc {
25namespace {
Åsa Persson4e609372021-05-17 10:37:28 +020026constexpr int kInitialWidth = 1280;
27constexpr int kInitialHeight = 720;
Åsa Persson2027b662018-05-02 18:08:06 +020028constexpr int kLowStartBps = 100000;
Åsa Persson258e9892021-02-25 10:39:51 +010029constexpr int kHighStartBps = 1000000;
Åsa Persson4e609372021-05-17 10:37:28 +020030constexpr int kDefaultVgaMinStartBps = 500000; // From video_stream_encoder.cc
Markus Handellf4f22872022-08-16 11:02:45 +000031constexpr TimeDelta kTimeout =
32 TimeDelta::Seconds(10); // Some tests are expected to time out.
Åsa Persson2027b662018-05-02 18:08:06 +020033
34void SetEncoderSpecific(VideoEncoderConfig* encoder_config,
35 VideoCodecType type,
Åsa Persson2c8d9292021-02-15 17:49:37 +010036 bool automatic_resize,
37 size_t num_spatial_layers) {
Åsa Persson2027b662018-05-02 18:08:06 +020038 if (type == kVideoCodecVP8) {
39 VideoCodecVP8 vp8 = VideoEncoder::GetDefaultVp8Settings();
40 vp8.automaticResizeOn = automatic_resize;
Tomas Gunnarssonc1d58912021-04-22 19:21:43 +020041 encoder_config->encoder_specific_settings =
42 rtc::make_ref_counted<VideoEncoderConfig::Vp8EncoderSpecificSettings>(
43 vp8);
Åsa Persson2027b662018-05-02 18:08:06 +020044 } else if (type == kVideoCodecVP9) {
45 VideoCodecVP9 vp9 = VideoEncoder::GetDefaultVp9Settings();
46 vp9.automaticResizeOn = automatic_resize;
Åsa Persson2c8d9292021-02-15 17:49:37 +010047 vp9.numberOfSpatialLayers = num_spatial_layers;
Tomas Gunnarssonc1d58912021-04-22 19:21:43 +020048 encoder_config->encoder_specific_settings =
49 rtc::make_ref_counted<VideoEncoderConfig::Vp9EncoderSpecificSettings>(
50 vp9);
Åsa Persson2027b662018-05-02 18:08:06 +020051 }
52}
53} // namespace
54
55class QualityScalingTest : public test::CallTest {
56 protected:
Åsa Persson2027b662018-05-02 18:08:06 +020057 const std::string kPrefix = "WebRTC-Video-QualityScaling/Enabled-";
58 const std::string kEnd = ",0,0,0.9995,0.9999,1/";
Åsa Persson258e9892021-02-25 10:39:51 +010059 const absl::optional<VideoEncoder::ResolutionBitrateLimits>
Sergey Silkina86b29b2021-03-05 13:29:19 +010060 kSinglecastLimits720pVp8 =
Åsa Persson258e9892021-02-25 10:39:51 +010061 EncoderInfoSettings::GetDefaultSinglecastBitrateLimitsForResolution(
Sergey Silkina86b29b2021-03-05 13:29:19 +010062 kVideoCodecVP8,
Åsa Persson258e9892021-02-25 10:39:51 +010063 1280 * 720);
Sergey Silkina86b29b2021-03-05 13:29:19 +010064 const absl::optional<VideoEncoder::ResolutionBitrateLimits>
65 kSinglecastLimits360pVp9 =
66 EncoderInfoSettings::GetDefaultSinglecastBitrateLimitsForResolution(
67 kVideoCodecVP9,
68 640 * 360);
Asa Persson2ee3e4d2022-05-20 14:22:27 +020069 const absl::optional<VideoEncoder::ResolutionBitrateLimits>
70 kSinglecastLimits720pVp9 =
71 EncoderInfoSettings::GetDefaultSinglecastBitrateLimitsForResolution(
72 kVideoCodecVP9,
73 1280 * 720);
Åsa Persson2027b662018-05-02 18:08:06 +020074};
75
Åsa Persson4e609372021-05-17 10:37:28 +020076class ScalingObserver : public test::SendTest {
77 protected:
Asa Persson2ee3e4d2022-05-20 14:22:27 +020078 struct TestParams {
79 bool active;
80 absl::optional<ScalabilityMode> scalability_mode;
81 };
Åsa Persson4e609372021-05-17 10:37:28 +020082 ScalingObserver(const std::string& payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +020083 const std::vector<TestParams>& test_params,
Åsa Persson4e609372021-05-17 10:37:28 +020084 int start_bps,
85 bool automatic_resize,
86 bool expect_scaling)
Markus Handellf4f22872022-08-16 11:02:45 +000087 : SendTest(expect_scaling ? kTimeout * 4 : kTimeout),
Åsa Persson4e609372021-05-17 10:37:28 +020088 encoder_factory_(
89 [](const SdpVideoFormat& format) -> std::unique_ptr<VideoEncoder> {
90 if (format.name == "VP8")
91 return VP8Encoder::Create();
92 if (format.name == "VP9")
93 return VP9Encoder::Create();
94 if (format.name == "H264")
95 return H264Encoder::Create(cricket::VideoCodec("H264"));
Artem Titovd3251962021-11-15 16:57:07 +010096 RTC_DCHECK_NOTREACHED() << format.name;
Åsa Persson4e609372021-05-17 10:37:28 +020097 return nullptr;
98 }),
99 payload_name_(payload_name),
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200100 test_params_(test_params),
Åsa Persson4e609372021-05-17 10:37:28 +0200101 start_bps_(start_bps),
102 automatic_resize_(automatic_resize),
103 expect_scaling_(expect_scaling) {}
104
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200105 DegradationPreference degradation_preference_ =
106 DegradationPreference::MAINTAIN_FRAMERATE;
107
Åsa Persson4e609372021-05-17 10:37:28 +0200108 private:
109 void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override {
110 bitrate_config->start_bitrate_bps = start_bps_;
111 }
112
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200113 void ModifyVideoDegradationPreference(
114 DegradationPreference* degradation_preference) override {
115 *degradation_preference = degradation_preference_;
116 }
117
Åsa Persson4e609372021-05-17 10:37:28 +0200118 size_t GetNumVideoStreams() const override {
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200119 return (payload_name_ == "VP9") ? 1 : test_params_.size();
Åsa Persson4e609372021-05-17 10:37:28 +0200120 }
121
122 void ModifyVideoConfigs(
123 VideoSendStream::Config* send_config,
Tommif6f45432022-05-20 15:21:20 +0200124 std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
Åsa Persson4e609372021-05-17 10:37:28 +0200125 VideoEncoderConfig* encoder_config) override {
Åsa Persson0f51bf72022-10-03 09:10:55 +0200126 VideoEncoder::EncoderInfo encoder_info;
Åsa Persson4e609372021-05-17 10:37:28 +0200127 send_config->encoder_settings.encoder_factory = &encoder_factory_;
128 send_config->rtp.payload_name = payload_name_;
129 send_config->rtp.payload_type = test::CallTest::kVideoSendPayloadType;
130 encoder_config->video_format.name = payload_name_;
131 const VideoCodecType codec_type = PayloadStringToCodecType(payload_name_);
132 encoder_config->codec_type = codec_type;
Åsa Persson0f51bf72022-10-03 09:10:55 +0200133 encoder_config->video_stream_factory =
134 rtc::make_ref_counted<cricket::EncoderStreamFactory>(
135 payload_name_, /*max_qp=*/0, /*is_screenshare=*/false,
136 /*conference_mode=*/false, encoder_info);
Åsa Persson4e609372021-05-17 10:37:28 +0200137 encoder_config->max_bitrate_bps =
138 std::max(start_bps_, encoder_config->max_bitrate_bps);
139 if (payload_name_ == "VP9") {
140 // Simulcast layers indicates which spatial layers are active.
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200141 encoder_config->simulcast_layers.resize(test_params_.size());
Åsa Persson4e609372021-05-17 10:37:28 +0200142 encoder_config->simulcast_layers[0].max_bitrate_bps =
143 encoder_config->max_bitrate_bps;
144 }
145 double scale_factor = 1.0;
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200146 for (int i = test_params_.size() - 1; i >= 0; --i) {
Åsa Persson4e609372021-05-17 10:37:28 +0200147 VideoStream& stream = encoder_config->simulcast_layers[i];
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200148 stream.active = test_params_[i].active;
149 stream.scalability_mode = test_params_[i].scalability_mode;
Åsa Persson4e609372021-05-17 10:37:28 +0200150 stream.scale_resolution_down_by = scale_factor;
151 scale_factor *= (payload_name_ == "VP9") ? 1.0 : 2.0;
152 }
Niels Möller807328f2022-05-12 16:16:39 +0200153 encoder_config->frame_drop_enabled = true;
Åsa Persson4e609372021-05-17 10:37:28 +0200154 SetEncoderSpecific(encoder_config, codec_type, automatic_resize_,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200155 test_params_.size());
Åsa Persson4e609372021-05-17 10:37:28 +0200156 }
157
158 void PerformTest() override { EXPECT_EQ(expect_scaling_, Wait()); }
159
160 test::FunctionVideoEncoderFactory encoder_factory_;
161 const std::string payload_name_;
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200162 const std::vector<TestParams> test_params_;
Åsa Persson4e609372021-05-17 10:37:28 +0200163 const int start_bps_;
164 const bool automatic_resize_;
165 const bool expect_scaling_;
166};
167
168class DownscalingObserver
169 : public ScalingObserver,
170 public test::FrameGeneratorCapturer::SinkWantsObserver {
171 public:
172 DownscalingObserver(const std::string& payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200173 const std::vector<TestParams>& test_params,
Åsa Persson4e609372021-05-17 10:37:28 +0200174 int start_bps,
175 bool automatic_resize,
176 bool expect_downscale)
177 : ScalingObserver(payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200178 test_params,
Åsa Persson4e609372021-05-17 10:37:28 +0200179 start_bps,
180 automatic_resize,
181 expect_downscale) {}
182
183 private:
184 void OnFrameGeneratorCapturerCreated(
185 test::FrameGeneratorCapturer* frame_generator_capturer) override {
186 frame_generator_capturer->SetSinkWantsObserver(this);
187 frame_generator_capturer->ChangeResolution(kInitialWidth, kInitialHeight);
188 }
189
190 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
191 const rtc::VideoSinkWants& wants) override {
192 if (wants.max_pixel_count < kInitialWidth * kInitialHeight)
193 observation_complete_.Set();
194 }
195};
196
197class UpscalingObserver
198 : public ScalingObserver,
199 public test::FrameGeneratorCapturer::SinkWantsObserver {
200 public:
201 UpscalingObserver(const std::string& payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200202 const std::vector<TestParams>& test_params,
Åsa Persson2027b662018-05-02 18:08:06 +0200203 int start_bps,
204 bool automatic_resize,
Åsa Persson4e609372021-05-17 10:37:28 +0200205 bool expect_upscale)
206 : ScalingObserver(payload_name,
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200207 test_params,
Åsa Persson4e609372021-05-17 10:37:28 +0200208 start_bps,
209 automatic_resize,
210 expect_upscale) {}
Åsa Persson2027b662018-05-02 18:08:06 +0200211
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200212 void SetDegradationPreference(DegradationPreference preference) {
213 degradation_preference_ = preference;
214 }
215
Åsa Persson4e609372021-05-17 10:37:28 +0200216 private:
217 void OnFrameGeneratorCapturerCreated(
218 test::FrameGeneratorCapturer* frame_generator_capturer) override {
219 frame_generator_capturer->SetSinkWantsObserver(this);
220 frame_generator_capturer->ChangeResolution(kInitialWidth, kInitialHeight);
221 }
Åsa Persson2027b662018-05-02 18:08:06 +0200222
Åsa Persson4e609372021-05-17 10:37:28 +0200223 void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
224 const rtc::VideoSinkWants& wants) override {
225 if (wants.max_pixel_count > last_wants_.max_pixel_count) {
226 if (wants.max_pixel_count == std::numeric_limits<int>::max())
Åsa Persson8c1bf952018-09-13 10:42:19 +0200227 observation_complete_.Set();
Åsa Persson2027b662018-05-02 18:08:06 +0200228 }
Åsa Persson4e609372021-05-17 10:37:28 +0200229 last_wants_ = wants;
230 }
Åsa Persson2027b662018-05-02 18:08:06 +0200231
Åsa Persson4e609372021-05-17 10:37:28 +0200232 rtc::VideoSinkWants last_wants_;
233};
Åsa Persson2027b662018-05-02 18:08:06 +0200234
235TEST_F(QualityScalingTest, AdaptsDownForHighQp_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100236 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100237 test::ScopedKeyValueConfig field_trials(field_trials_,
238 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200239
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200240 DownscalingObserver test("VP8", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200241 /*automatic_resize=*/true,
242 /*expect_downscale=*/true);
243 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200244}
245
Åsa Persson2c8d9292021-02-15 17:49:37 +0100246TEST_F(QualityScalingTest, NoAdaptDownForHighQpIfScalingOff_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100247 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100248 test::ScopedKeyValueConfig field_trials(field_trials_,
249 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200250
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200251 DownscalingObserver test("VP8", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200252 /*automatic_resize=*/false,
253 /*expect_downscale=*/false);
254 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200255}
256
257TEST_F(QualityScalingTest, NoAdaptDownForNormalQp_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100258 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100259 test::ScopedKeyValueConfig field_trials(field_trials_,
260 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200261
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200262 DownscalingObserver test("VP8", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200263 /*automatic_resize=*/true,
264 /*expect_downscale=*/false);
265 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200266}
267
Åsa Persson2c8d9292021-02-15 17:49:37 +0100268TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrate_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100269 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100270 test::ScopedKeyValueConfig field_trials(field_trials_,
271 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200272
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200273 DownscalingObserver test("VP8", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200274 /*automatic_resize=*/true,
275 /*expect_downscale=*/true);
276 RunBaseTest(&test);
277}
278
279TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrateAndThenUp) {
280 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100281 test::ScopedKeyValueConfig field_trials(
282 field_trials_,
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200283 kPrefix + "127,127,0,0,0,0" + kEnd +
Jonas Oreland8ca06132022-03-14 12:52:48 +0100284 "WebRTC-Video-BalancedDegradationSettings/"
285 "pixels:230400|921600,fps:20|30,kbps:300|500/"); // should not affect
Åsa Persson4e609372021-05-17 10:37:28 +0200286
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200287 UpscalingObserver test("VP8", {{.active = true}}, kDefaultVgaMinStartBps - 1,
Åsa Persson4e609372021-05-17 10:37:28 +0200288 /*automatic_resize=*/true, /*expect_upscale=*/true);
289 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200290}
291
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200292TEST_F(QualityScalingTest, AdaptsDownAndThenUpWithBalanced) {
293 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100294 test::ScopedKeyValueConfig field_trials(
295 field_trials_, kPrefix + "127,127,0,0,0,0" + kEnd +
296 "WebRTC-Video-BalancedDegradationSettings/"
297 "pixels:230400|921600,fps:20|30,kbps:300|499/");
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200298
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200299 UpscalingObserver test("VP8", {{.active = true}}, kDefaultVgaMinStartBps - 1,
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200300 /*automatic_resize=*/true, /*expect_upscale=*/true);
301 test.SetDegradationPreference(DegradationPreference::BALANCED);
302 RunBaseTest(&test);
303}
304
305TEST_F(QualityScalingTest, AdaptsDownButNotUpWithBalancedIfBitrateNotEnough) {
306 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100307 test::ScopedKeyValueConfig field_trials(
308 field_trials_, kPrefix + "127,127,0,0,0,0" + kEnd +
309 "WebRTC-Video-BalancedDegradationSettings/"
310 "pixels:230400|921600,fps:20|30,kbps:300|500/");
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200311
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200312 UpscalingObserver test("VP8", {{.active = true}}, kDefaultVgaMinStartBps - 1,
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200313 /*automatic_resize=*/true, /*expect_upscale=*/false);
314 test.SetDegradationPreference(DegradationPreference::BALANCED);
315 RunBaseTest(&test);
316}
317
Åsa Perssonf46723c2020-11-20 15:45:44 +0100318TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrate_Simulcast) {
Åsa Persson453a1252021-02-14 15:16:27 +0100319 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100320 test::ScopedKeyValueConfig field_trials(field_trials_,
321 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100322
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200323 DownscalingObserver test("VP8", {{.active = true}, {.active = true}},
324 kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200325 /*automatic_resize=*/false,
326 /*expect_downscale=*/false);
327 RunBaseTest(&test);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100328}
329
Åsa Persson1dd94a02021-02-18 14:20:03 +0100330TEST_F(QualityScalingTest, AdaptsDownForHighQp_HighestStreamActive_Vp8) {
331 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100332 test::ScopedKeyValueConfig field_trials(field_trials_,
333 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100334
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200335 DownscalingObserver test(
336 "VP8", {{.active = false}, {.active = false}, {.active = true}},
337 kHighStartBps,
338 /*automatic_resize=*/true,
339 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200340 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100341}
342
Åsa Perssonf46723c2020-11-20 15:45:44 +0100343TEST_F(QualityScalingTest,
Åsa Persson2c8d9292021-02-15 17:49:37 +0100344 AdaptsDownForLowStartBitrate_HighestStreamActive_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100345 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100346 test::ScopedKeyValueConfig field_trials(field_trials_,
347 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100348
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200349 DownscalingObserver test(
350 "VP8", {{.active = false}, {.active = false}, {.active = true}},
351 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
352 /*automatic_resize=*/true,
353 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200354 RunBaseTest(&test);
355}
356
357TEST_F(QualityScalingTest, AdaptsDownButNotUpWithMinStartBitrateLimit) {
358 // qp_low:127, qp_high:127 -> kLowQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100359 test::ScopedKeyValueConfig field_trials(field_trials_,
360 kPrefix + "127,127,0,0,0,0" + kEnd);
Åsa Persson4e609372021-05-17 10:37:28 +0200361
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200362 UpscalingObserver test("VP8", {{.active = false}, {.active = true}},
Åsa Persson4e609372021-05-17 10:37:28 +0200363 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
364 /*automatic_resize=*/true, /*expect_upscale=*/false);
365 RunBaseTest(&test);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100366}
367
Åsa Persson258e9892021-02-25 10:39:51 +0100368TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrateIfBitrateEnough_Vp8) {
369 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100370 test::ScopedKeyValueConfig field_trials(field_trials_,
371 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson258e9892021-02-25 10:39:51 +0100372
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200373 DownscalingObserver test(
374 "VP8", {{.active = false}, {.active = false}, {.active = true}},
375 kSinglecastLimits720pVp8->min_start_bitrate_bps,
376 /*automatic_resize=*/true,
377 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200378 RunBaseTest(&test);
Åsa Persson258e9892021-02-25 10:39:51 +0100379}
380
381TEST_F(QualityScalingTest,
382 NoAdaptDownForLowStartBitrateIfDefaultLimitsDisabled_Vp8) {
383 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100384 test::ScopedKeyValueConfig field_trials(
385 field_trials_, kPrefix + "1,127,0,0,0,0" + kEnd +
386 "WebRTC-DefaultBitrateLimitsKillSwitch/Enabled/");
Åsa Persson258e9892021-02-25 10:39:51 +0100387
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200388 DownscalingObserver test(
389 "VP8", {{.active = false}, {.active = false}, {.active = true}},
390 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
391 /*automatic_resize=*/true,
392 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200393 RunBaseTest(&test);
Åsa Persson258e9892021-02-25 10:39:51 +0100394}
395
396TEST_F(QualityScalingTest,
397 NoAdaptDownForLowStartBitrate_OneStreamSinglecastLimitsNotUsed_Vp8) {
398 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100399 test::ScopedKeyValueConfig field_trials(field_trials_,
400 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson258e9892021-02-25 10:39:51 +0100401
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200402 DownscalingObserver test("VP8", {{.active = true}},
Åsa Persson1d2b22e2021-06-03 09:28:47 +0200403 kSinglecastLimits720pVp8->min_start_bitrate_bps - 1,
404 /*automatic_resize=*/true,
405 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200406 RunBaseTest(&test);
Åsa Persson258e9892021-02-25 10:39:51 +0100407}
408
Åsa Persson1dd94a02021-02-18 14:20:03 +0100409TEST_F(QualityScalingTest, NoAdaptDownForHighQp_LowestStreamActive_Vp8) {
410 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100411 test::ScopedKeyValueConfig field_trials(field_trials_,
412 kPrefix + "1,1,0,0,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100413
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200414 DownscalingObserver test(
415 "VP8", {{.active = true}, {.active = false}, {.active = false}},
416 kHighStartBps,
417 /*automatic_resize=*/true,
418 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200419 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100420}
421
Åsa Perssonf46723c2020-11-20 15:45:44 +0100422TEST_F(QualityScalingTest,
Åsa Persson2c8d9292021-02-15 17:49:37 +0100423 NoAdaptDownForLowStartBitrate_LowestStreamActive_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100424 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100425 test::ScopedKeyValueConfig field_trials(field_trials_,
426 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100427
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200428 DownscalingObserver test(
429 "VP8", {{.active = true}, {.active = false}, {.active = false}},
430 kLowStartBps,
431 /*automatic_resize=*/true,
432 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200433 RunBaseTest(&test);
Åsa Perssonf46723c2020-11-20 15:45:44 +0100434}
435
Åsa Persson2c8d9292021-02-15 17:49:37 +0100436TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrateIfScalingOff_Vp8) {
Åsa Persson453a1252021-02-14 15:16:27 +0100437 // qp_low:1, qp_high:127 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100438 test::ScopedKeyValueConfig field_trials(field_trials_,
439 kPrefix + "1,127,0,0,0,0" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200440
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200441 DownscalingObserver test("VP8", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200442 /*automatic_resize=*/false,
443 /*expect_downscale=*/false);
444 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200445}
446
Åsa Persson2c8d9292021-02-15 17:49:37 +0100447TEST_F(QualityScalingTest, AdaptsDownForHighQp_Vp9) {
448 // qp_low:1, qp_high:1 -> kHighQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200449 test::ScopedKeyValueConfig field_trials(field_trials_,
450 kPrefix + "0,0,1,1,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100451
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200452 DownscalingObserver test("VP9", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200453 /*automatic_resize=*/true,
454 /*expect_downscale=*/true);
455 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100456}
457
458TEST_F(QualityScalingTest, NoAdaptDownForHighQpIfScalingOff_Vp9) {
Åsa Persson453a1252021-02-14 15:16:27 +0100459 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100460 test::ScopedKeyValueConfig field_trials(
461 field_trials_,
462 kPrefix + "0,0,1,1,0,0" + kEnd + "WebRTC-VP9QualityScaler/Disabled/");
Åsa Persson2027b662018-05-02 18:08:06 +0200463
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200464 DownscalingObserver test("VP9", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200465 /*automatic_resize=*/true,
466 /*expect_downscale=*/false);
467 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200468}
469
Åsa Persson2c8d9292021-02-15 17:49:37 +0100470TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrate_Vp9) {
471 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200472 test::ScopedKeyValueConfig field_trials(field_trials_,
473 kPrefix + "0,0,1,255,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100474
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200475 DownscalingObserver test("VP9", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200476 /*automatic_resize=*/true,
477 /*expect_downscale=*/true);
478 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100479}
480
Åsa Persson0f51bf72022-10-03 09:10:55 +0200481TEST_F(QualityScalingTest, NoAdaptDownForHighStartBitrate_Vp9) {
482 DownscalingObserver test(
483 "VP9", {{.active = false}, {.active = false}, {.active = true}},
484 kHighStartBps,
485 /*automatic_resize=*/true,
486 /*expect_downscale=*/false);
487 RunBaseTest(&test);
488}
489
Åsa Persson1dd94a02021-02-18 14:20:03 +0100490TEST_F(QualityScalingTest, NoAdaptDownForHighQp_LowestStreamActive_Vp9) {
491 // qp_low:1, qp_high:1 -> kHighQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200492 test::ScopedKeyValueConfig field_trials(field_trials_,
493 kPrefix + "0,0,1,1,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100494
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200495 DownscalingObserver test(
496 "VP9", {{.active = true}, {.active = false}, {.active = false}},
497 kHighStartBps,
498 /*automatic_resize=*/true,
499 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200500 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100501}
502
Åsa Persson2c8d9292021-02-15 17:49:37 +0100503TEST_F(QualityScalingTest,
504 NoAdaptDownForLowStartBitrate_LowestStreamActive_Vp9) {
505 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200506 test::ScopedKeyValueConfig field_trials(field_trials_,
507 kPrefix + "0,0,1,255,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100508
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200509 DownscalingObserver test(
510 "VP9", {{.active = true}, {.active = false}, {.active = false}},
511 kLowStartBps,
512 /*automatic_resize=*/true,
513 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200514 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100515}
516
Åsa Persson1dd94a02021-02-18 14:20:03 +0100517TEST_F(QualityScalingTest, AdaptsDownForHighQp_MiddleStreamActive_Vp9) {
518 // qp_low:1, qp_high:1 -> kHighQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200519 test::ScopedKeyValueConfig field_trials(field_trials_,
520 kPrefix + "0,0,1,1,0,0" + kEnd);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100521
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200522 DownscalingObserver test(
523 "VP9", {{.active = false}, {.active = true}, {.active = false}},
524 kHighStartBps,
525 /*automatic_resize=*/true,
526 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200527 RunBaseTest(&test);
Åsa Persson1dd94a02021-02-18 14:20:03 +0100528}
529
Åsa Persson2c8d9292021-02-15 17:49:37 +0100530TEST_F(QualityScalingTest,
531 AdaptsDownForLowStartBitrate_MiddleStreamActive_Vp9) {
532 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200533 test::ScopedKeyValueConfig field_trials(field_trials_,
534 kPrefix + "0,0,1,255,0,0" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100535
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200536 DownscalingObserver test(
537 "VP9", {{.active = false}, {.active = true}, {.active = false}},
538 kSinglecastLimits360pVp9->min_start_bitrate_bps - 1,
539 /*automatic_resize=*/true,
540 /*expect_downscale=*/true);
Åsa Persson4e609372021-05-17 10:37:28 +0200541 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100542}
543
Sergey Silkina86b29b2021-03-05 13:29:19 +0100544TEST_F(QualityScalingTest, NoAdaptDownForLowStartBitrateIfBitrateEnough_Vp9) {
545 // qp_low:1, qp_high:255 -> kNormalQp
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200546 test::ScopedKeyValueConfig field_trials(field_trials_,
547 kPrefix + "0,0,1,255,0,0" + kEnd);
Sergey Silkina86b29b2021-03-05 13:29:19 +0100548
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200549 DownscalingObserver test(
550 "VP9", {{.active = false}, {.active = true}, {.active = false}},
551 kSinglecastLimits360pVp9->min_start_bitrate_bps,
552 /*automatic_resize=*/true,
553 /*expect_downscale=*/false);
554 RunBaseTest(&test);
555}
556
557TEST_F(QualityScalingTest,
558 AdaptsDownButNotUpWithMinStartBitrateLimitWithScalabilityMode_VP9) {
559 // qp_low:255, qp_high:255 -> kLowQp
560 test::ScopedKeyValueConfig field_trials(field_trials_,
561 kPrefix + "0,0,255,255,0,0" + kEnd);
562
563 UpscalingObserver test(
564 "VP9",
565 {{.active = true, .scalability_mode = ScalabilityMode::kL1T3},
566 {.active = false}},
567 kSinglecastLimits720pVp9->min_start_bitrate_bps - 1,
568 /*automatic_resize=*/true, /*expect_upscale=*/false);
569 RunBaseTest(&test);
570}
571
572TEST_F(QualityScalingTest,
573 NoAdaptDownForLowStartBitrateIfBitrateEnoughWithScalabilityMode_Vp9) {
574 // qp_low:1, qp_high:255 -> kNormalQp
575 test::ScopedKeyValueConfig field_trials(field_trials_,
576 kPrefix + "0,0,1,255,0,0" + kEnd);
577
578 DownscalingObserver test(
579 "VP9",
580 {{.active = true, .scalability_mode = ScalabilityMode::kL1T3},
581 {.active = false},
582 {.active = false}},
583 kSinglecastLimits720pVp9->min_start_bitrate_bps,
584 /*automatic_resize=*/true,
585 /*expect_downscale=*/false);
Åsa Persson4e609372021-05-17 10:37:28 +0200586 RunBaseTest(&test);
Sergey Silkina86b29b2021-03-05 13:29:19 +0100587}
588
Åsa Persson2027b662018-05-02 18:08:06 +0200589#if defined(WEBRTC_USE_H264)
590TEST_F(QualityScalingTest, AdaptsDownForHighQp_H264) {
Åsa Persson453a1252021-02-14 15:16:27 +0100591 // qp_low:1, qp_high:1 -> kHighQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100592 test::ScopedKeyValueConfig field_trials(field_trials_,
593 kPrefix + "0,0,0,0,1,1" + kEnd);
Åsa Persson2027b662018-05-02 18:08:06 +0200594
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200595 DownscalingObserver test("H264", {{.active = true}}, kHighStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200596 /*automatic_resize=*/true,
597 /*expect_downscale=*/true);
598 RunBaseTest(&test);
Åsa Persson2027b662018-05-02 18:08:06 +0200599}
Åsa Persson2c8d9292021-02-15 17:49:37 +0100600
601TEST_F(QualityScalingTest, AdaptsDownForLowStartBitrate_H264) {
602 // qp_low:1, qp_high:51 -> kNormalQp
Jonas Oreland8ca06132022-03-14 12:52:48 +0100603 test::ScopedKeyValueConfig field_trials(field_trials_,
604 kPrefix + "0,0,0,0,1,51" + kEnd);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100605
Asa Persson2ee3e4d2022-05-20 14:22:27 +0200606 DownscalingObserver test("H264", {{.active = true}}, kLowStartBps,
Åsa Persson4e609372021-05-17 10:37:28 +0200607 /*automatic_resize=*/true,
608 /*expect_downscale=*/true);
609 RunBaseTest(&test);
Åsa Persson2c8d9292021-02-15 17:49:37 +0100610}
Åsa Persson2027b662018-05-02 18:08:06 +0200611#endif // defined(WEBRTC_USE_H264)
612
613} // namespace webrtc