Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 1 | /* |
| 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 Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include "test/gtest.h" |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 14 | #include "test/scoped_key_value_config.h" |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | namespace { |
| 18 | void 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 | |
| 33 | void 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 Nikolaevskiy | 483b31c | 2021-02-03 16:19:31 | [diff] [blame] | 41 | #if !defined(WEBRTC_IOS) |
| 42 | // TODO(bugs.webrtc.org/12401): investigate why QualityScaler kicks in on iOS. |
| 43 | TEST(QualityScalingExperimentTest, DefaultEnabledWithoutFieldTrial) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 44 | webrtc::test::ScopedKeyValueConfig field_trials(""); |
| 45 | EXPECT_TRUE(QualityScalingExperiment::Enabled(field_trials)); |
Ilya Nikolaevskiy | 483b31c | 2021-02-03 16:19:31 | [diff] [blame] | 46 | } |
| 47 | #else |
| 48 | TEST(QualityScalingExperimentTest, DefaultDisabledWithoutFieldTrialIOS) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 49 | webrtc::test::ScopedKeyValueConfig field_trials(""); |
| 50 | EXPECT_FALSE(QualityScalingExperiment::Enabled(field_trials)); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 51 | } |
Ilya Nikolaevskiy | 483b31c | 2021-02-03 16:19:31 | [diff] [blame] | 52 | #endif |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 53 | |
| 54 | TEST(QualityScalingExperimentTest, EnabledWithFieldTrial) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 55 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 56 | "WebRTC-Video-QualityScaling/Enabled/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 57 | EXPECT_TRUE(QualityScalingExperiment::Enabled(field_trials)); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TEST(QualityScalingExperimentTest, ParseSettings) { |
| 61 | const QualityScalingExperiment::Settings kExpected = {1, 2, 3, 4, 5, 6, |
| 62 | 7, 8, 0.9f, 0.99f, 1}; |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 63 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 64 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.9,0.99,1/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 65 | const auto settings = QualityScalingExperiment::ParseSettings(field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 66 | EXPECT_TRUE(settings); |
| 67 | ExpectEqualSettings(kExpected, *settings); |
| 68 | } |
| 69 | |
Ilya Nikolaevskiy | 483b31c | 2021-02-03 16:19:31 | [diff] [blame] | 70 | #if !defined(WEBRTC_IOS) |
| 71 | // TODO(bugs.webrtc.org/12401): investigate why QualityScaler kicks in on iOS. |
| 72 | TEST(QualityScalingExperimentTest, ParseSettingsUsesDefaultsWithoutFieldTrial) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 73 | webrtc::test::ScopedKeyValueConfig field_trials(""); |
Ilya Nikolaevskiy | 483b31c | 2021-02-03 16:19:31 | [diff] [blame] | 74 | // Uses some default hard coded values. |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 75 | EXPECT_TRUE(QualityScalingExperiment::ParseSettings(field_trials)); |
Ilya Nikolaevskiy | 483b31c | 2021-02-03 16:19:31 | [diff] [blame] | 76 | } |
| 77 | #else |
Ilya Nikolaevskiy | d6604df | 2021-02-01 12:01:06 | [diff] [blame] | 78 | TEST(QualityScalingExperimentTest, ParseSettingsFailsWithoutFieldTrial) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 79 | webrtc::test::ScopedKeyValueConfig field_trials(""); |
| 80 | EXPECT_FALSE(QualityScalingExperiment::ParseSettings(field_trials)); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 81 | } |
Ilya Nikolaevskiy | 483b31c | 2021-02-03 16:19:31 | [diff] [blame] | 82 | #endif |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 83 | |
| 84 | TEST(QualityScalingExperimentTest, ParseSettingsFailsWithInvalidFieldTrial) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 85 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 86 | "WebRTC-Video-QualityScaling/Enabled-invalid/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 87 | EXPECT_FALSE(QualityScalingExperiment::ParseSettings(field_trials)); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | TEST(QualityScalingExperimentTest, GetConfig) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 91 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 92 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.9,0.99,0/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 93 | const auto config = QualityScalingExperiment::GetConfig(field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 94 | 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 | |
| 99 | TEST(QualityScalingExperimentTest, GetsDefaultConfigForInvalidFieldTrial) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 100 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 101 | "WebRTC-Video-QualityScaling/Enabled-invalid/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 102 | const auto config = QualityScalingExperiment::GetConfig(field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 103 | ExpectEqualConfig(config, QualityScalingExperiment::Config()); |
| 104 | } |
| 105 | |
| 106 | TEST(QualityScalingExperimentTest, GetsDefaultAlphaForInvalidValue) { |
| 107 | QualityScalingExperiment::Config expected_config; |
| 108 | expected_config.use_all_drop_reasons = true; |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 109 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 110 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.99,0.9,1/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 111 | const auto config = QualityScalingExperiment::GetConfig(field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 112 | ExpectEqualConfig(config, expected_config); |
| 113 | } |
| 114 | |
| 115 | TEST(QualityScalingExperimentTest, GetVp8Thresholds) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 116 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 117 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/"); |
| 118 | const auto thresholds = |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 119 | QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 120 | EXPECT_TRUE(thresholds); |
| 121 | EXPECT_EQ(1, thresholds->low); |
| 122 | EXPECT_EQ(2, thresholds->high); |
| 123 | } |
| 124 | |
| 125 | TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp8Value) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 126 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 127 | "WebRTC-Video-QualityScaling/Enabled-0,0,3,4,5,6,7,8,0.9,0.99,1/"); |
| 128 | const auto thresholds = |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 129 | QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 130 | EXPECT_FALSE(thresholds); |
| 131 | } |
| 132 | |
| 133 | TEST(QualityScalingExperimentTest, GetVp9Thresholds) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 134 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 135 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/"); |
| 136 | const auto thresholds = |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 137 | QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 138 | EXPECT_TRUE(thresholds); |
| 139 | EXPECT_EQ(3, thresholds->low); |
| 140 | EXPECT_EQ(4, thresholds->high); |
| 141 | } |
| 142 | |
| 143 | TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp9Value) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 144 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 145 | "WebRTC-Video-QualityScaling/Enabled-1,2,0,0,5,6,7,8,0.9,0.99,1/"); |
| 146 | const auto thresholds = |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 147 | QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 148 | EXPECT_FALSE(thresholds); |
| 149 | } |
| 150 | |
| 151 | TEST(QualityScalingExperimentTest, GetH264Thresholds) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 152 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 153 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/"); |
| 154 | const auto thresholds = |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 155 | QualityScalingExperiment::GetQpThresholds(kVideoCodecH264, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 156 | EXPECT_TRUE(thresholds); |
| 157 | EXPECT_EQ(5, thresholds->low); |
| 158 | EXPECT_EQ(6, thresholds->high); |
| 159 | } |
| 160 | |
| 161 | TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidH264Value) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 162 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 163 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/"); |
| 164 | const auto thresholds = |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 165 | QualityScalingExperiment::GetQpThresholds(kVideoCodecH264, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 166 | EXPECT_FALSE(thresholds); |
| 167 | } |
| 168 | |
| 169 | TEST(QualityScalingExperimentTest, GetGenericThresholds) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 170 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 171 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 172 | const auto thresholds = QualityScalingExperiment::GetQpThresholds( |
| 173 | kVideoCodecGeneric, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 174 | EXPECT_TRUE(thresholds); |
| 175 | EXPECT_EQ(7, thresholds->low); |
| 176 | EXPECT_EQ(8, thresholds->high); |
| 177 | } |
| 178 | |
| 179 | TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidGenericValue) { |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 180 | webrtc::test::ScopedKeyValueConfig field_trials( |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 181 | "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/"); |
Jeremy Leconte | 1a8d529 | 2023-10-10 13:21:29 | [diff] [blame] | 182 | const auto thresholds = QualityScalingExperiment::GetQpThresholds( |
| 183 | kVideoCodecGeneric, field_trials); |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 184 | EXPECT_FALSE(thresholds); |
| 185 | } |
| 186 | } // namespace webrtc |