blob: 0c1450557ab5fd9ea60e16d103c6d70f37e65c22 [file] [log] [blame]
Åsa Perssona945aee2018-04-24 14:53:251/*
2 * Copyright 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 "rtc_base/experiments/quality_scaling_experiment.h"
12
Yves Gerey3e707812018-11-28 15:47:4913#include "test/gtest.h"
Jeremy Leconte1a8d5292023-10-10 13:21:2914#include "test/scoped_key_value_config.h"
Åsa Perssona945aee2018-04-24 14:53:2515
16namespace webrtc {
17namespace {
18void ExpectEqualSettings(QualityScalingExperiment::Settings a,
19 QualityScalingExperiment::Settings b) {
20 EXPECT_EQ(a.vp8_low, b.vp8_low);
21 EXPECT_EQ(a.vp8_high, b.vp8_high);
22 EXPECT_EQ(a.vp9_low, b.vp9_low);
23 EXPECT_EQ(a.vp9_high, b.vp9_high);
24 EXPECT_EQ(a.h264_low, b.h264_low);
25 EXPECT_EQ(a.h264_high, b.h264_high);
26 EXPECT_EQ(a.generic_low, b.generic_low);
27 EXPECT_EQ(a.generic_high, b.generic_high);
28 EXPECT_EQ(a.alpha_high, b.alpha_high);
29 EXPECT_EQ(a.alpha_low, b.alpha_low);
30 EXPECT_EQ(a.drop, b.drop);
31}
32
33void ExpectEqualConfig(QualityScalingExperiment::Config a,
34 QualityScalingExperiment::Config b) {
35 EXPECT_EQ(a.alpha_high, b.alpha_high);
36 EXPECT_EQ(a.alpha_low, b.alpha_low);
37 EXPECT_EQ(a.use_all_drop_reasons, b.use_all_drop_reasons);
38}
39} // namespace
40
Ilya Nikolaevskiy483b31c2021-02-03 16:19:3141#if !defined(WEBRTC_IOS)
42// TODO(bugs.webrtc.org/12401): investigate why QualityScaler kicks in on iOS.
43TEST(QualityScalingExperimentTest, DefaultEnabledWithoutFieldTrial) {
Jeremy Leconte1a8d5292023-10-10 13:21:2944 webrtc::test::ScopedKeyValueConfig field_trials("");
45 EXPECT_TRUE(QualityScalingExperiment::Enabled(field_trials));
Ilya Nikolaevskiy483b31c2021-02-03 16:19:3146}
47#else
48TEST(QualityScalingExperimentTest, DefaultDisabledWithoutFieldTrialIOS) {
Jeremy Leconte1a8d5292023-10-10 13:21:2949 webrtc::test::ScopedKeyValueConfig field_trials("");
50 EXPECT_FALSE(QualityScalingExperiment::Enabled(field_trials));
Åsa Perssona945aee2018-04-24 14:53:2551}
Ilya Nikolaevskiy483b31c2021-02-03 16:19:3152#endif
Åsa Perssona945aee2018-04-24 14:53:2553
54TEST(QualityScalingExperimentTest, EnabledWithFieldTrial) {
Jeremy Leconte1a8d5292023-10-10 13:21:2955 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:2556 "WebRTC-Video-QualityScaling/Enabled/");
Jeremy Leconte1a8d5292023-10-10 13:21:2957 EXPECT_TRUE(QualityScalingExperiment::Enabled(field_trials));
Åsa Perssona945aee2018-04-24 14:53:2558}
59
60TEST(QualityScalingExperimentTest, ParseSettings) {
61 const QualityScalingExperiment::Settings kExpected = {1, 2, 3, 4, 5, 6,
62 7, 8, 0.9f, 0.99f, 1};
Jeremy Leconte1a8d5292023-10-10 13:21:2963 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:2564 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.9,0.99,1/");
Jeremy Leconte1a8d5292023-10-10 13:21:2965 const auto settings = QualityScalingExperiment::ParseSettings(field_trials);
Åsa Perssona945aee2018-04-24 14:53:2566 EXPECT_TRUE(settings);
67 ExpectEqualSettings(kExpected, *settings);
68}
69
Ilya Nikolaevskiy483b31c2021-02-03 16:19:3170#if !defined(WEBRTC_IOS)
71// TODO(bugs.webrtc.org/12401): investigate why QualityScaler kicks in on iOS.
72TEST(QualityScalingExperimentTest, ParseSettingsUsesDefaultsWithoutFieldTrial) {
Jeremy Leconte1a8d5292023-10-10 13:21:2973 webrtc::test::ScopedKeyValueConfig field_trials("");
Ilya Nikolaevskiy483b31c2021-02-03 16:19:3174 // Uses some default hard coded values.
Jeremy Leconte1a8d5292023-10-10 13:21:2975 EXPECT_TRUE(QualityScalingExperiment::ParseSettings(field_trials));
Ilya Nikolaevskiy483b31c2021-02-03 16:19:3176}
77#else
Ilya Nikolaevskiyd6604df2021-02-01 12:01:0678TEST(QualityScalingExperimentTest, ParseSettingsFailsWithoutFieldTrial) {
Jeremy Leconte1a8d5292023-10-10 13:21:2979 webrtc::test::ScopedKeyValueConfig field_trials("");
80 EXPECT_FALSE(QualityScalingExperiment::ParseSettings(field_trials));
Åsa Perssona945aee2018-04-24 14:53:2581}
Ilya Nikolaevskiy483b31c2021-02-03 16:19:3182#endif
Åsa Perssona945aee2018-04-24 14:53:2583
84TEST(QualityScalingExperimentTest, ParseSettingsFailsWithInvalidFieldTrial) {
Jeremy Leconte1a8d5292023-10-10 13:21:2985 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:2586 "WebRTC-Video-QualityScaling/Enabled-invalid/");
Jeremy Leconte1a8d5292023-10-10 13:21:2987 EXPECT_FALSE(QualityScalingExperiment::ParseSettings(field_trials));
Åsa Perssona945aee2018-04-24 14:53:2588}
89
90TEST(QualityScalingExperimentTest, GetConfig) {
Jeremy Leconte1a8d5292023-10-10 13:21:2991 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:2592 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.9,0.99,0/");
Jeremy Leconte1a8d5292023-10-10 13:21:2993 const auto config = QualityScalingExperiment::GetConfig(field_trials);
Åsa Perssona945aee2018-04-24 14:53:2594 EXPECT_EQ(0.9f, config.alpha_high);
95 EXPECT_EQ(0.99f, config.alpha_low);
96 EXPECT_FALSE(config.use_all_drop_reasons);
97}
98
99TEST(QualityScalingExperimentTest, GetsDefaultConfigForInvalidFieldTrial) {
Jeremy Leconte1a8d5292023-10-10 13:21:29100 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25101 "WebRTC-Video-QualityScaling/Enabled-invalid/");
Jeremy Leconte1a8d5292023-10-10 13:21:29102 const auto config = QualityScalingExperiment::GetConfig(field_trials);
Åsa Perssona945aee2018-04-24 14:53:25103 ExpectEqualConfig(config, QualityScalingExperiment::Config());
104}
105
106TEST(QualityScalingExperimentTest, GetsDefaultAlphaForInvalidValue) {
107 QualityScalingExperiment::Config expected_config;
108 expected_config.use_all_drop_reasons = true;
Jeremy Leconte1a8d5292023-10-10 13:21:29109 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25110 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.99,0.9,1/");
Jeremy Leconte1a8d5292023-10-10 13:21:29111 const auto config = QualityScalingExperiment::GetConfig(field_trials);
Åsa Perssona945aee2018-04-24 14:53:25112 ExpectEqualConfig(config, expected_config);
113}
114
115TEST(QualityScalingExperimentTest, GetVp8Thresholds) {
Jeremy Leconte1a8d5292023-10-10 13:21:29116 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25117 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
118 const auto thresholds =
Jeremy Leconte1a8d5292023-10-10 13:21:29119 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25120 EXPECT_TRUE(thresholds);
121 EXPECT_EQ(1, thresholds->low);
122 EXPECT_EQ(2, thresholds->high);
123}
124
125TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp8Value) {
Jeremy Leconte1a8d5292023-10-10 13:21:29126 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25127 "WebRTC-Video-QualityScaling/Enabled-0,0,3,4,5,6,7,8,0.9,0.99,1/");
128 const auto thresholds =
Jeremy Leconte1a8d5292023-10-10 13:21:29129 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25130 EXPECT_FALSE(thresholds);
131}
132
133TEST(QualityScalingExperimentTest, GetVp9Thresholds) {
Jeremy Leconte1a8d5292023-10-10 13:21:29134 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25135 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
136 const auto thresholds =
Jeremy Leconte1a8d5292023-10-10 13:21:29137 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25138 EXPECT_TRUE(thresholds);
139 EXPECT_EQ(3, thresholds->low);
140 EXPECT_EQ(4, thresholds->high);
141}
142
143TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp9Value) {
Jeremy Leconte1a8d5292023-10-10 13:21:29144 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25145 "WebRTC-Video-QualityScaling/Enabled-1,2,0,0,5,6,7,8,0.9,0.99,1/");
146 const auto thresholds =
Jeremy Leconte1a8d5292023-10-10 13:21:29147 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25148 EXPECT_FALSE(thresholds);
149}
150
151TEST(QualityScalingExperimentTest, GetH264Thresholds) {
Jeremy Leconte1a8d5292023-10-10 13:21:29152 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25153 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
154 const auto thresholds =
Jeremy Leconte1a8d5292023-10-10 13:21:29155 QualityScalingExperiment::GetQpThresholds(kVideoCodecH264, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25156 EXPECT_TRUE(thresholds);
157 EXPECT_EQ(5, thresholds->low);
158 EXPECT_EQ(6, thresholds->high);
159}
160
161TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidH264Value) {
Jeremy Leconte1a8d5292023-10-10 13:21:29162 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25163 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/");
164 const auto thresholds =
Jeremy Leconte1a8d5292023-10-10 13:21:29165 QualityScalingExperiment::GetQpThresholds(kVideoCodecH264, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25166 EXPECT_FALSE(thresholds);
167}
168
169TEST(QualityScalingExperimentTest, GetGenericThresholds) {
Jeremy Leconte1a8d5292023-10-10 13:21:29170 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25171 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/");
Jeremy Leconte1a8d5292023-10-10 13:21:29172 const auto thresholds = QualityScalingExperiment::GetQpThresholds(
173 kVideoCodecGeneric, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25174 EXPECT_TRUE(thresholds);
175 EXPECT_EQ(7, thresholds->low);
176 EXPECT_EQ(8, thresholds->high);
177}
178
179TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidGenericValue) {
Jeremy Leconte1a8d5292023-10-10 13:21:29180 webrtc::test::ScopedKeyValueConfig field_trials(
Åsa Perssona945aee2018-04-24 14:53:25181 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
Jeremy Leconte1a8d5292023-10-10 13:21:29182 const auto thresholds = QualityScalingExperiment::GetQpThresholds(
183 kVideoCodecGeneric, field_trials);
Åsa Perssona945aee2018-04-24 14:53:25184 EXPECT_FALSE(thresholds);
185}
186} // namespace webrtc