Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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/balanced_degradation_settings.h" |
| 12 | |
| 13 | #include <limits> |
| 14 | |
| 15 | #include "rtc_base/gunit.h" |
| 16 | #include "test/field_trial.h" |
| 17 | #include "test/gmock.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | namespace { |
| 21 | |
| 22 | void VerifyIsDefault( |
| 23 | const std::vector<BalancedDegradationSettings::Config>& config) { |
| 24 | EXPECT_THAT(config, ::testing::ElementsAre( |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 25 | BalancedDegradationSettings::Config{ |
| 26 | 320 * 240, 7, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, |
| 27 | BalancedDegradationSettings::Config{ |
| 28 | 480 * 270, 10, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, |
| 29 | BalancedDegradationSettings::Config{ |
| 30 | 640 * 480, 15, {0, 0}, {0, 0}, {0, 0}, {0, 0}})); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 31 | } |
| 32 | } // namespace |
| 33 | |
| 34 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfNoList) { |
| 35 | webrtc::test::ScopedFieldTrials field_trials(""); |
| 36 | BalancedDegradationSettings settings; |
| 37 | VerifyIsDefault(settings.GetConfigs()); |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 38 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1)); |
| 39 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1)); |
| 40 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1)); |
| 41 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecGeneric, 1)); |
| 42 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecMultiplex, 1)); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | TEST(BalancedDegradationSettings, GetsConfig) { |
| 46 | webrtc::test::ScopedFieldTrials field_trials( |
| 47 | "WebRTC-Video-BalancedDegradationSettings/" |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 48 | "pixels:11|22|33,fps:5|15|25,other:4|5|6/"); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 49 | BalancedDegradationSettings settings; |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 50 | EXPECT_THAT(settings.GetConfigs(), |
| 51 | ::testing::ElementsAre( |
| 52 | BalancedDegradationSettings::Config{ |
| 53 | 11, 5, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, |
| 54 | BalancedDegradationSettings::Config{ |
| 55 | 22, 15, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, |
| 56 | BalancedDegradationSettings::Config{ |
| 57 | 33, 25, {0, 0}, {0, 0}, {0, 0}, {0, 0}})); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroFpsValue) { |
| 61 | webrtc::test::ScopedFieldTrials field_trials( |
| 62 | "WebRTC-Video-BalancedDegradationSettings/" |
| 63 | "pixels:1000|2000|3000,fps:0|15|25/"); |
| 64 | BalancedDegradationSettings settings; |
| 65 | VerifyIsDefault(settings.GetConfigs()); |
| 66 | } |
| 67 | |
| 68 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfPixelsDecreases) { |
| 69 | webrtc::test::ScopedFieldTrials field_trials( |
| 70 | "WebRTC-Video-BalancedDegradationSettings/" |
| 71 | "pixels:1000|999|3000,fps:5|15|25/"); |
| 72 | BalancedDegradationSettings settings; |
| 73 | VerifyIsDefault(settings.GetConfigs()); |
| 74 | } |
| 75 | |
| 76 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfFramerateDecreases) { |
| 77 | webrtc::test::ScopedFieldTrials field_trials( |
| 78 | "WebRTC-Video-BalancedDegradationSettings/" |
| 79 | "pixels:1000|2000|3000,fps:5|4|25/"); |
| 80 | BalancedDegradationSettings settings; |
| 81 | VerifyIsDefault(settings.GetConfigs()); |
| 82 | } |
| 83 | |
| 84 | TEST(BalancedDegradationSettings, GetsMinFps) { |
| 85 | webrtc::test::ScopedFieldTrials field_trials( |
| 86 | "WebRTC-Video-BalancedDegradationSettings/" |
| 87 | "pixels:1000|2000|3000,fps:5|15|25/"); |
| 88 | BalancedDegradationSettings settings; |
| 89 | EXPECT_EQ(5, settings.MinFps(1)); |
| 90 | EXPECT_EQ(5, settings.MinFps(1000)); |
| 91 | EXPECT_EQ(15, settings.MinFps(1000 + 1)); |
| 92 | EXPECT_EQ(15, settings.MinFps(2000)); |
| 93 | EXPECT_EQ(25, settings.MinFps(2000 + 1)); |
| 94 | EXPECT_EQ(25, settings.MinFps(3000)); |
| 95 | EXPECT_EQ(std::numeric_limits<int>::max(), settings.MinFps(3000 + 1)); |
| 96 | } |
| 97 | |
| 98 | TEST(BalancedDegradationSettings, GetsMaxFps) { |
| 99 | webrtc::test::ScopedFieldTrials field_trials( |
| 100 | "WebRTC-Video-BalancedDegradationSettings/" |
| 101 | "pixels:1000|2000|3000,fps:5|15|25/"); |
| 102 | BalancedDegradationSettings settings; |
| 103 | EXPECT_EQ(15, settings.MaxFps(1)); |
| 104 | EXPECT_EQ(15, settings.MaxFps(1000)); |
| 105 | EXPECT_EQ(25, settings.MaxFps(1000 + 1)); |
| 106 | EXPECT_EQ(25, settings.MaxFps(2000)); |
| 107 | EXPECT_EQ(std::numeric_limits<int>::max(), settings.MaxFps(2000 + 1)); |
| 108 | } |
| 109 | |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 110 | TEST(BalancedDegradationSettings, QpThresholdsNotSetByDefault) { |
| 111 | webrtc::test::ScopedFieldTrials field_trials( |
| 112 | "WebRTC-Video-BalancedDegradationSettings/" |
| 113 | "pixels:1000|2000|3000,fps:5|15|25/"); |
| 114 | BalancedDegradationSettings settings; |
| 115 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1)); |
| 116 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1)); |
| 117 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1)); |
| 118 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecGeneric, 1)); |
| 119 | } |
| 120 | |
| 121 | TEST(BalancedDegradationSettings, GetsConfigWithQpThresholds) { |
| 122 | webrtc::test::ScopedFieldTrials field_trials( |
| 123 | "WebRTC-Video-BalancedDegradationSettings/" |
| 124 | "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88," |
| 125 | "vp8_qp_high:90|91|92,vp9_qp_low:27|28|29,vp9_qp_high:120|130|140," |
| 126 | "h264_qp_low:12|13|14,h264_qp_high:20|30|40,generic_qp_low:7|6|5," |
| 127 | "generic_qp_high:22|23|24/"); |
| 128 | BalancedDegradationSettings settings; |
| 129 | EXPECT_THAT(settings.GetConfigs(), |
| 130 | ::testing::ElementsAre( |
| 131 | BalancedDegradationSettings::Config{ |
| 132 | 1000, 5, {89, 90}, {27, 120}, {12, 20}, {7, 22}}, |
| 133 | BalancedDegradationSettings::Config{ |
| 134 | 2000, 15, {90, 91}, {28, 130}, {13, 30}, {6, 23}}, |
| 135 | BalancedDegradationSettings::Config{ |
| 136 | 3000, 25, {88, 92}, {29, 140}, {14, 40}, {5, 24}})); |
| 137 | } |
| 138 | |
| 139 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasLowThreshold) { |
| 140 | webrtc::test::ScopedFieldTrials field_trials( |
| 141 | "WebRTC-Video-BalancedDegradationSettings/" |
| 142 | "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88/"); |
| 143 | BalancedDegradationSettings settings; |
| 144 | VerifyIsDefault(settings.GetConfigs()); |
| 145 | } |
| 146 | |
| 147 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasHighThreshold) { |
| 148 | webrtc::test::ScopedFieldTrials field_trials( |
| 149 | "WebRTC-Video-BalancedDegradationSettings/" |
| 150 | "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_high:90|91|92/"); |
| 151 | BalancedDegradationSettings settings; |
| 152 | VerifyIsDefault(settings.GetConfigs()); |
| 153 | } |
| 154 | |
| 155 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowEqualsHigh) { |
| 156 | webrtc::test::ScopedFieldTrials field_trials( |
| 157 | "WebRTC-Video-BalancedDegradationSettings/" |
| 158 | "pixels:1000|2000|3000,fps:5|15|25," |
| 159 | "vp8_qp_low:89|90|88,vp8_qp_high:90|91|88/"); |
| 160 | BalancedDegradationSettings settings; |
| 161 | VerifyIsDefault(settings.GetConfigs()); |
| 162 | } |
| 163 | |
| 164 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowGreaterThanHigh) { |
| 165 | webrtc::test::ScopedFieldTrials field_trials( |
| 166 | "WebRTC-Video-BalancedDegradationSettings/" |
| 167 | "pixels:1000|2000|3000,fps:5|15|25," |
| 168 | "vp8_qp_low:89|90|88,vp8_qp_high:90|91|87/"); |
| 169 | BalancedDegradationSettings settings; |
| 170 | VerifyIsDefault(settings.GetConfigs()); |
| 171 | } |
| 172 | |
| 173 | TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroQpValue) { |
| 174 | webrtc::test::ScopedFieldTrials field_trials( |
| 175 | "WebRTC-Video-BalancedDegradationSettings/" |
| 176 | "pixels:1000|2000|3000,fps:5|15|25," |
| 177 | "vp8_qp_low:89|0|88,vp8_qp_high:90|91|92/"); |
| 178 | BalancedDegradationSettings settings; |
| 179 | VerifyIsDefault(settings.GetConfigs()); |
| 180 | } |
| 181 | |
| 182 | TEST(BalancedDegradationSettings, GetsVp8QpThresholds) { |
| 183 | webrtc::test::ScopedFieldTrials field_trials( |
| 184 | "WebRTC-Video-BalancedDegradationSettings/" |
| 185 | "pixels:1000|2000|3000,fps:5|15|25," |
| 186 | "vp8_qp_low:89|90|88,vp8_qp_high:90|91|92/"); |
| 187 | BalancedDegradationSettings settings; |
| 188 | EXPECT_EQ(89, settings.GetQpThresholds(kVideoCodecVP8, 1)->low); |
| 189 | EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1)->high); |
| 190 | EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1000)->high); |
| 191 | EXPECT_EQ(91, settings.GetQpThresholds(kVideoCodecVP8, 1001)->high); |
| 192 | EXPECT_EQ(91, settings.GetQpThresholds(kVideoCodecVP8, 2000)->high); |
| 193 | EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 2001)->high); |
| 194 | EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 3000)->high); |
| 195 | EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 3001)->high); |
| 196 | } |
| 197 | |
| 198 | TEST(BalancedDegradationSettings, GetsVp9QpThresholds) { |
| 199 | webrtc::test::ScopedFieldTrials field_trials( |
| 200 | "WebRTC-Video-BalancedDegradationSettings/" |
| 201 | "pixels:1000|2000|3000,fps:5|15|25," |
| 202 | "vp9_qp_low:55|56|57,vp9_qp_high:155|156|157/"); |
| 203 | BalancedDegradationSettings settings; |
| 204 | const auto thresholds = settings.GetQpThresholds(kVideoCodecVP9, 1000); |
| 205 | EXPECT_TRUE(thresholds); |
| 206 | EXPECT_EQ(55, thresholds->low); |
| 207 | EXPECT_EQ(155, thresholds->high); |
| 208 | } |
| 209 | |
| 210 | TEST(BalancedDegradationSettings, GetsH264QpThresholds) { |
| 211 | webrtc::test::ScopedFieldTrials field_trials( |
| 212 | "WebRTC-Video-BalancedDegradationSettings/" |
| 213 | "pixels:1000|2000|3000,fps:5|15|25," |
| 214 | "h264_qp_low:21|22|23,h264_qp_high:41|43|42/"); |
| 215 | BalancedDegradationSettings settings; |
| 216 | const auto thresholds = settings.GetQpThresholds(kVideoCodecH264, 2000); |
| 217 | EXPECT_TRUE(thresholds); |
| 218 | EXPECT_EQ(22, thresholds->low); |
| 219 | EXPECT_EQ(43, thresholds->high); |
| 220 | } |
| 221 | |
| 222 | TEST(BalancedDegradationSettings, GetsGenericQpThresholds) { |
| 223 | webrtc::test::ScopedFieldTrials field_trials( |
| 224 | "WebRTC-Video-BalancedDegradationSettings/" |
| 225 | "pixels:1000|2000|3000,fps:5|15|25," |
| 226 | "generic_qp_low:2|3|4,generic_qp_high:22|23|24/"); |
| 227 | BalancedDegradationSettings settings; |
| 228 | const auto thresholds = settings.GetQpThresholds(kVideoCodecGeneric, 3000); |
| 229 | EXPECT_TRUE(thresholds); |
| 230 | EXPECT_EQ(4, thresholds->low); |
| 231 | EXPECT_EQ(24, thresholds->high); |
| 232 | } |
| 233 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 234 | } // namespace webrtc |