Å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) { |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 24 | EXPECT_THAT(config, ::testing::ElementsAre( |
| 25 | BalancedDegradationSettings::Config{ |
| 26 | 320 * 240, |
| 27 | 7, |
| 28 | 0, |
| 29 | BalancedDegradationSettings::kNoFpsDiff, |
| 30 | {0, 0, 0}, |
| 31 | {0, 0, 0}, |
| 32 | {0, 0, 0}, |
| 33 | {0, 0, 0}}, |
| 34 | BalancedDegradationSettings::Config{ |
| 35 | 480 * 270, |
| 36 | 10, |
| 37 | 0, |
| 38 | BalancedDegradationSettings::kNoFpsDiff, |
| 39 | {0, 0, 0}, |
| 40 | {0, 0, 0}, |
| 41 | {0, 0, 0}, |
| 42 | {0, 0, 0}}, |
| 43 | BalancedDegradationSettings::Config{ |
| 44 | 640 * 480, |
| 45 | 15, |
| 46 | 0, |
| 47 | BalancedDegradationSettings::kNoFpsDiff, |
| 48 | {0, 0, 0}, |
| 49 | {0, 0, 0}, |
| 50 | {0, 0, 0}, |
| 51 | {0, 0, 0}})); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 52 | } |
| 53 | } // namespace |
| 54 | |
| 55 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfNoList) { |
| 56 | webrtc::test::ScopedFieldTrials field_trials(""); |
| 57 | BalancedDegradationSettings settings; |
| 58 | VerifyIsDefault(settings.GetConfigs()); |
Åsa Persson | 1b247f1 | 2019-08-14 17:26:39 +0200 | [diff] [blame] | 59 | EXPECT_FALSE(settings.NextHigherBitrateKbps(1)); |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 60 | EXPECT_FALSE(settings.MinFpsDiff(1)); |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 61 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1)); |
| 62 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1)); |
| 63 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1)); |
| 64 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecGeneric, 1)); |
| 65 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecMultiplex, 1)); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | TEST(BalancedDegradationSettings, GetsConfig) { |
| 69 | webrtc::test::ScopedFieldTrials field_trials( |
| 70 | "WebRTC-Video-BalancedDegradationSettings/" |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 71 | "pixels:11|22|33,fps:5|15|25,other:4|5|6/"); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 72 | BalancedDegradationSettings settings; |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 73 | EXPECT_THAT(settings.GetConfigs(), |
| 74 | ::testing::ElementsAre( |
| 75 | BalancedDegradationSettings::Config{ |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 76 | 11, |
| 77 | 5, |
| 78 | 0, |
| 79 | BalancedDegradationSettings::kNoFpsDiff, |
| 80 | {0, 0, 0}, |
| 81 | {0, 0, 0}, |
| 82 | {0, 0, 0}, |
| 83 | {0, 0, 0}}, |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 84 | BalancedDegradationSettings::Config{ |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 85 | 22, |
| 86 | 15, |
| 87 | 0, |
| 88 | BalancedDegradationSettings::kNoFpsDiff, |
| 89 | {0, 0, 0}, |
| 90 | {0, 0, 0}, |
| 91 | {0, 0, 0}, |
| 92 | {0, 0, 0}}, |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 93 | BalancedDegradationSettings::Config{ |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 94 | 33, |
| 95 | 25, |
| 96 | 0, |
| 97 | BalancedDegradationSettings::kNoFpsDiff, |
| 98 | {0, 0, 0}, |
| 99 | {0, 0, 0}, |
| 100 | {0, 0, 0}, |
| 101 | {0, 0, 0}})); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroFpsValue) { |
| 105 | webrtc::test::ScopedFieldTrials field_trials( |
| 106 | "WebRTC-Video-BalancedDegradationSettings/" |
| 107 | "pixels:1000|2000|3000,fps:0|15|25/"); |
| 108 | BalancedDegradationSettings settings; |
| 109 | VerifyIsDefault(settings.GetConfigs()); |
| 110 | } |
| 111 | |
| 112 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfPixelsDecreases) { |
| 113 | webrtc::test::ScopedFieldTrials field_trials( |
| 114 | "WebRTC-Video-BalancedDegradationSettings/" |
| 115 | "pixels:1000|999|3000,fps:5|15|25/"); |
| 116 | BalancedDegradationSettings settings; |
| 117 | VerifyIsDefault(settings.GetConfigs()); |
| 118 | } |
| 119 | |
| 120 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfFramerateDecreases) { |
| 121 | webrtc::test::ScopedFieldTrials field_trials( |
| 122 | "WebRTC-Video-BalancedDegradationSettings/" |
| 123 | "pixels:1000|2000|3000,fps:5|4|25/"); |
| 124 | BalancedDegradationSettings settings; |
| 125 | VerifyIsDefault(settings.GetConfigs()); |
| 126 | } |
| 127 | |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 128 | TEST(BalancedDegradationSettings, GetsConfigWithSpecificFps) { |
| 129 | webrtc::test::ScopedFieldTrials field_trials( |
| 130 | "WebRTC-Video-BalancedDegradationSettings/" |
| 131 | "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|8|9,vp9_fps:9|10|11," |
| 132 | "h264_fps:11|12|13,generic_fps:13|14|15/"); |
| 133 | BalancedDegradationSettings settings; |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 134 | EXPECT_THAT(settings.GetConfigs(), |
| 135 | ::testing::ElementsAre( |
| 136 | BalancedDegradationSettings::Config{ |
| 137 | 1000, |
| 138 | 5, |
| 139 | 0, |
| 140 | BalancedDegradationSettings::kNoFpsDiff, |
| 141 | {0, 0, 7}, |
| 142 | {0, 0, 9}, |
| 143 | {0, 0, 11}, |
| 144 | {0, 0, 13}}, |
| 145 | BalancedDegradationSettings::Config{ |
| 146 | 2000, |
| 147 | 15, |
| 148 | 0, |
| 149 | BalancedDegradationSettings::kNoFpsDiff, |
| 150 | {0, 0, 8}, |
| 151 | {0, 0, 10}, |
| 152 | {0, 0, 12}, |
| 153 | {0, 0, 14}}, |
| 154 | BalancedDegradationSettings::Config{ |
| 155 | 3000, |
| 156 | 25, |
| 157 | 0, |
| 158 | BalancedDegradationSettings::kNoFpsDiff, |
| 159 | {0, 0, 9}, |
| 160 | {0, 0, 11}, |
| 161 | {0, 0, 13}, |
| 162 | {0, 0, 15}})); |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroVp8FpsValue) { |
| 166 | webrtc::test::ScopedFieldTrials field_trials( |
| 167 | "WebRTC-Video-BalancedDegradationSettings/" |
| 168 | "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:0|15|25/"); |
| 169 | BalancedDegradationSettings settings; |
| 170 | VerifyIsDefault(settings.GetConfigs()); |
| 171 | } |
| 172 | |
| 173 | TEST(BalancedDegradationSettings, GetsDefaultConfigForInvalidFpsValue) { |
| 174 | webrtc::test::ScopedFieldTrials field_trials( |
| 175 | "WebRTC-Video-BalancedDegradationSettings/" |
| 176 | "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:10|15|2000/"); |
| 177 | BalancedDegradationSettings settings; |
| 178 | VerifyIsDefault(settings.GetConfigs()); |
| 179 | } |
| 180 | |
| 181 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfVp8FramerateDecreases) { |
| 182 | webrtc::test::ScopedFieldTrials field_trials( |
| 183 | "WebRTC-Video-BalancedDegradationSettings/" |
| 184 | "pixels:1000|2000|3000,fps:4|5|25,vp8_fps:5|4|25/"); |
| 185 | BalancedDegradationSettings settings; |
| 186 | VerifyIsDefault(settings.GetConfigs()); |
| 187 | } |
| 188 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 189 | TEST(BalancedDegradationSettings, GetsMinFps) { |
| 190 | webrtc::test::ScopedFieldTrials field_trials( |
| 191 | "WebRTC-Video-BalancedDegradationSettings/" |
| 192 | "pixels:1000|2000|3000,fps:5|15|25/"); |
| 193 | BalancedDegradationSettings settings; |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 194 | EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1)); |
| 195 | EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1000)); |
| 196 | EXPECT_EQ(15, settings.MinFps(kVideoCodecVP8, 1001)); |
| 197 | EXPECT_EQ(15, settings.MinFps(kVideoCodecVP8, 2000)); |
| 198 | EXPECT_EQ(25, settings.MinFps(kVideoCodecVP8, 2001)); |
| 199 | EXPECT_EQ(25, settings.MinFps(kVideoCodecVP8, 3000)); |
| 200 | EXPECT_EQ(std::numeric_limits<int>::max(), |
| 201 | settings.MinFps(kVideoCodecVP8, 3001)); |
| 202 | } |
| 203 | |
| 204 | TEST(BalancedDegradationSettings, GetsVp8MinFps) { |
| 205 | webrtc::test::ScopedFieldTrials field_trials( |
| 206 | "WebRTC-Video-BalancedDegradationSettings/" |
| 207 | "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/"); |
| 208 | BalancedDegradationSettings settings; |
| 209 | EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1)); |
| 210 | EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1000)); |
| 211 | EXPECT_EQ(10, settings.MinFps(kVideoCodecVP8, 1001)); |
| 212 | EXPECT_EQ(10, settings.MinFps(kVideoCodecVP8, 2000)); |
| 213 | EXPECT_EQ(12, settings.MinFps(kVideoCodecVP8, 2001)); |
| 214 | EXPECT_EQ(12, settings.MinFps(kVideoCodecVP8, 3000)); |
| 215 | EXPECT_EQ(std::numeric_limits<int>::max(), |
| 216 | settings.MinFps(kVideoCodecVP8, 3001)); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | TEST(BalancedDegradationSettings, GetsMaxFps) { |
| 220 | webrtc::test::ScopedFieldTrials field_trials( |
| 221 | "WebRTC-Video-BalancedDegradationSettings/" |
| 222 | "pixels:1000|2000|3000,fps:5|15|25/"); |
| 223 | BalancedDegradationSettings settings; |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 224 | EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1)); |
| 225 | EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1000)); |
| 226 | EXPECT_EQ(25, settings.MaxFps(kVideoCodecVP8, 1001)); |
| 227 | EXPECT_EQ(25, settings.MaxFps(kVideoCodecVP8, 2000)); |
| 228 | EXPECT_EQ(std::numeric_limits<int>::max(), |
| 229 | settings.MaxFps(kVideoCodecVP8, 2001)); |
| 230 | } |
| 231 | |
| 232 | TEST(BalancedDegradationSettings, GetsVp8MaxFps) { |
| 233 | webrtc::test::ScopedFieldTrials field_trials( |
| 234 | "WebRTC-Video-BalancedDegradationSettings/" |
| 235 | "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/"); |
| 236 | BalancedDegradationSettings settings; |
| 237 | EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1)); |
| 238 | EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1000)); |
| 239 | EXPECT_EQ(12, settings.MaxFps(kVideoCodecVP8, 1001)); |
| 240 | EXPECT_EQ(12, settings.MaxFps(kVideoCodecVP8, 2000)); |
| 241 | EXPECT_EQ(std::numeric_limits<int>::max(), |
| 242 | settings.MaxFps(kVideoCodecVP8, 2001)); |
| 243 | } |
| 244 | |
| 245 | TEST(BalancedDegradationSettings, GetsVp9Fps) { |
| 246 | webrtc::test::ScopedFieldTrials field_trials( |
| 247 | "WebRTC-Video-BalancedDegradationSettings/" |
| 248 | "pixels:1000|2000|3000,fps:5|15|25,vp9_fps:7|10|12/"); |
| 249 | BalancedDegradationSettings settings; |
| 250 | EXPECT_EQ(7, settings.MinFps(kVideoCodecVP9, 1000)); |
| 251 | EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP9, 1000)); |
| 252 | } |
| 253 | |
| 254 | TEST(BalancedDegradationSettings, GetsH264Fps) { |
| 255 | webrtc::test::ScopedFieldTrials field_trials( |
| 256 | "WebRTC-Video-BalancedDegradationSettings/" |
| 257 | "pixels:1000|2000|3000,fps:5|15|25,h264_fps:8|11|13/"); |
| 258 | BalancedDegradationSettings settings; |
| 259 | EXPECT_EQ(11, settings.MinFps(kVideoCodecH264, 2000)); |
| 260 | EXPECT_EQ(13, settings.MaxFps(kVideoCodecH264, 2000)); |
| 261 | } |
| 262 | |
| 263 | TEST(BalancedDegradationSettings, GetsGenericFps) { |
| 264 | webrtc::test::ScopedFieldTrials field_trials( |
| 265 | "WebRTC-Video-BalancedDegradationSettings/" |
| 266 | "pixels:1000|2000|3000,fps:5|15|25,generic_fps:9|12|14/"); |
| 267 | BalancedDegradationSettings settings; |
| 268 | EXPECT_EQ(14, settings.MinFps(kVideoCodecGeneric, 3000)); |
| 269 | EXPECT_EQ(std::numeric_limits<int>::max(), |
| 270 | settings.MaxFps(kVideoCodecGeneric, 3000)); |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Åsa Persson | 0c38a86 | 2019-08-14 10:10:12 +0200 | [diff] [blame] | 273 | TEST(BalancedDegradationSettings, GetsUnlimitedForMaxValidFps) { |
| 274 | webrtc::test::ScopedFieldTrials field_trials( |
| 275 | "WebRTC-Video-BalancedDegradationSettings/" |
| 276 | "pixels:1000|2000|3000,fps:5|15|100,vp8_fps:30|100|100/"); |
| 277 | const int kUnlimitedFps = std::numeric_limits<int>::max(); |
| 278 | BalancedDegradationSettings settings; |
| 279 | EXPECT_EQ(15, settings.MinFps(kVideoCodecH264, 2000)); |
| 280 | EXPECT_EQ(kUnlimitedFps, settings.MinFps(kVideoCodecH264, 2001)); |
| 281 | EXPECT_EQ(30, settings.MinFps(kVideoCodecVP8, 1000)); |
| 282 | EXPECT_EQ(kUnlimitedFps, settings.MinFps(kVideoCodecVP8, 1001)); |
| 283 | } |
| 284 | |
Åsa Persson | 1b247f1 | 2019-08-14 17:26:39 +0200 | [diff] [blame] | 285 | TEST(BalancedDegradationSettings, GetsConfigWithBitrate) { |
| 286 | webrtc::test::ScopedFieldTrials field_trials( |
| 287 | "WebRTC-Video-BalancedDegradationSettings/" |
| 288 | "pixels:11|22|33,fps:5|15|25,kbps:44|88|99/"); |
| 289 | BalancedDegradationSettings settings; |
| 290 | EXPECT_THAT(settings.GetConfigs(), |
| 291 | ::testing::ElementsAre( |
| 292 | BalancedDegradationSettings::Config{ |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 293 | 11, |
| 294 | 5, |
| 295 | 44, |
| 296 | BalancedDegradationSettings::kNoFpsDiff, |
| 297 | {0, 0, 0}, |
| 298 | {0, 0, 0}, |
| 299 | {0, 0, 0}, |
| 300 | {0, 0, 0}}, |
Åsa Persson | 1b247f1 | 2019-08-14 17:26:39 +0200 | [diff] [blame] | 301 | BalancedDegradationSettings::Config{ |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 302 | 22, |
| 303 | 15, |
| 304 | 88, |
| 305 | BalancedDegradationSettings::kNoFpsDiff, |
| 306 | {0, 0, 0}, |
| 307 | {0, 0, 0}, |
| 308 | {0, 0, 0}, |
| 309 | {0, 0, 0}}, |
Åsa Persson | 1b247f1 | 2019-08-14 17:26:39 +0200 | [diff] [blame] | 310 | BalancedDegradationSettings::Config{ |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 311 | 33, |
| 312 | 25, |
| 313 | 99, |
| 314 | BalancedDegradationSettings::kNoFpsDiff, |
| 315 | {0, 0, 0}, |
| 316 | {0, 0, 0}, |
| 317 | {0, 0, 0}, |
| 318 | {0, 0, 0}})); |
Åsa Persson | 1b247f1 | 2019-08-14 17:26:39 +0200 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfBitrateDecreases) { |
| 322 | webrtc::test::ScopedFieldTrials field_trials( |
| 323 | "WebRTC-Video-BalancedDegradationSettings/" |
| 324 | "pixels:11|22|33,fps:5|15|25,kbps:44|43|99/"); |
| 325 | BalancedDegradationSettings settings; |
| 326 | VerifyIsDefault(settings.GetConfigs()); |
| 327 | } |
| 328 | |
| 329 | TEST(BalancedDegradationSettings, |
| 330 | GetsDefaultConfigIfBitrateDecreasesWithUnsetValue) { |
| 331 | webrtc::test::ScopedFieldTrials field_trials( |
| 332 | "WebRTC-Video-BalancedDegradationSettings/" |
| 333 | "pixels:11|22|33,fps:5|15|25,kbps:44|0|43/"); |
| 334 | BalancedDegradationSettings settings; |
| 335 | VerifyIsDefault(settings.GetConfigs()); |
| 336 | } |
| 337 | |
| 338 | TEST(BalancedDegradationSettings, GetsNextHigherBitrate) { |
| 339 | webrtc::test::ScopedFieldTrials field_trials( |
| 340 | "WebRTC-Video-BalancedDegradationSettings/" |
| 341 | "pixels:1000|2000|3000,fps:5|15|25,kbps:44|88|99/"); |
| 342 | BalancedDegradationSettings settings; |
| 343 | EXPECT_EQ(88, settings.NextHigherBitrateKbps(1)); |
| 344 | EXPECT_EQ(88, settings.NextHigherBitrateKbps(1000)); |
| 345 | EXPECT_EQ(99, settings.NextHigherBitrateKbps(1001)); |
| 346 | EXPECT_EQ(99, settings.NextHigherBitrateKbps(2000)); |
| 347 | EXPECT_FALSE(settings.NextHigherBitrateKbps(2001)); |
| 348 | } |
| 349 | |
| 350 | TEST(BalancedDegradationSettings, GetsNextHigherBitrateWithUnsetValue) { |
| 351 | webrtc::test::ScopedFieldTrials field_trials( |
| 352 | "WebRTC-Video-BalancedDegradationSettings/" |
| 353 | "pixels:1000|2000|3000,fps:5|15|25,kbps:10|0|20/"); |
| 354 | BalancedDegradationSettings settings; |
| 355 | EXPECT_FALSE(settings.NextHigherBitrateKbps(1)); |
| 356 | EXPECT_FALSE(settings.NextHigherBitrateKbps(1000)); |
| 357 | EXPECT_EQ(20, settings.NextHigherBitrateKbps(1001)); |
| 358 | EXPECT_EQ(20, settings.NextHigherBitrateKbps(2000)); |
| 359 | EXPECT_FALSE(settings.NextHigherBitrateKbps(2001)); |
| 360 | } |
| 361 | |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 362 | TEST(BalancedDegradationSettings, GetsFpsDiff) { |
| 363 | webrtc::test::ScopedFieldTrials field_trials( |
| 364 | "WebRTC-Video-BalancedDegradationSettings/" |
| 365 | "pixels:1000|2000|3000,fps:5|15|25,fps_diff:0|-2|3/"); |
| 366 | BalancedDegradationSettings settings; |
| 367 | EXPECT_EQ(0, settings.MinFpsDiff(1)); |
| 368 | EXPECT_EQ(0, settings.MinFpsDiff(1000)); |
| 369 | EXPECT_EQ(-2, settings.MinFpsDiff(1001)); |
| 370 | EXPECT_EQ(-2, settings.MinFpsDiff(2000)); |
| 371 | EXPECT_EQ(3, settings.MinFpsDiff(2001)); |
| 372 | EXPECT_EQ(3, settings.MinFpsDiff(3000)); |
| 373 | EXPECT_FALSE(settings.MinFpsDiff(3001)); |
| 374 | } |
| 375 | |
| 376 | TEST(BalancedDegradationSettings, GetsNoFpsDiffIfValueBelowMinSetting) { |
| 377 | webrtc::test::ScopedFieldTrials field_trials( |
| 378 | "WebRTC-Video-BalancedDegradationSettings/" |
| 379 | "pixels:1000|2000|3000,fps:5|15|25,fps_diff:-100|-99|-101/"); |
| 380 | // Min valid fps_diff setting: -99. |
| 381 | BalancedDegradationSettings settings; |
| 382 | EXPECT_FALSE(settings.MinFpsDiff(1000)); |
| 383 | EXPECT_EQ(-99, settings.MinFpsDiff(2000)); |
| 384 | EXPECT_FALSE(settings.MinFpsDiff(3000)); |
| 385 | } |
| 386 | |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 387 | TEST(BalancedDegradationSettings, QpThresholdsNotSetByDefault) { |
| 388 | webrtc::test::ScopedFieldTrials field_trials( |
| 389 | "WebRTC-Video-BalancedDegradationSettings/" |
| 390 | "pixels:1000|2000|3000,fps:5|15|25/"); |
| 391 | BalancedDegradationSettings settings; |
| 392 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1)); |
| 393 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1)); |
| 394 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1)); |
| 395 | EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecGeneric, 1)); |
| 396 | } |
| 397 | |
| 398 | TEST(BalancedDegradationSettings, GetsConfigWithQpThresholds) { |
| 399 | webrtc::test::ScopedFieldTrials field_trials( |
| 400 | "WebRTC-Video-BalancedDegradationSettings/" |
| 401 | "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88," |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 402 | "vp8_qp_high:90|91|92,vp9_qp_low:27|28|29,vp9_qp_high:120|130|140," |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 403 | "h264_qp_low:12|13|14,h264_qp_high:20|30|40,generic_qp_low:7|6|5," |
| 404 | "generic_qp_high:22|23|24/"); |
| 405 | BalancedDegradationSettings settings; |
Åsa Persson | f5e5d25 | 2019-08-16 17:24:59 +0200 | [diff] [blame^] | 406 | EXPECT_THAT(settings.GetConfigs(), |
| 407 | ::testing::ElementsAre( |
| 408 | BalancedDegradationSettings::Config{ |
| 409 | 1000, |
| 410 | 5, |
| 411 | 0, |
| 412 | BalancedDegradationSettings::kNoFpsDiff, |
| 413 | {89, 90, 0}, |
| 414 | {27, 120, 0}, |
| 415 | {12, 20, 0}, |
| 416 | {7, 22, 0}}, |
| 417 | BalancedDegradationSettings::Config{ |
| 418 | 2000, |
| 419 | 15, |
| 420 | 0, |
| 421 | BalancedDegradationSettings::kNoFpsDiff, |
| 422 | {90, 91, 0}, |
| 423 | {28, 130, 0}, |
| 424 | {13, 30, 0}, |
| 425 | {6, 23, 0}}, |
| 426 | BalancedDegradationSettings::Config{ |
| 427 | 3000, |
| 428 | 25, |
| 429 | 0, |
| 430 | BalancedDegradationSettings::kNoFpsDiff, |
| 431 | {88, 92, 0}, |
| 432 | {29, 140, 0}, |
| 433 | {14, 40, 0}, |
| 434 | {5, 24, 0}})); |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasLowThreshold) { |
| 438 | webrtc::test::ScopedFieldTrials field_trials( |
| 439 | "WebRTC-Video-BalancedDegradationSettings/" |
| 440 | "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88/"); |
| 441 | BalancedDegradationSettings settings; |
| 442 | VerifyIsDefault(settings.GetConfigs()); |
| 443 | } |
| 444 | |
| 445 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasHighThreshold) { |
| 446 | webrtc::test::ScopedFieldTrials field_trials( |
| 447 | "WebRTC-Video-BalancedDegradationSettings/" |
| 448 | "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_high:90|91|92/"); |
| 449 | BalancedDegradationSettings settings; |
| 450 | VerifyIsDefault(settings.GetConfigs()); |
| 451 | } |
| 452 | |
| 453 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowEqualsHigh) { |
| 454 | webrtc::test::ScopedFieldTrials field_trials( |
| 455 | "WebRTC-Video-BalancedDegradationSettings/" |
| 456 | "pixels:1000|2000|3000,fps:5|15|25," |
| 457 | "vp8_qp_low:89|90|88,vp8_qp_high:90|91|88/"); |
| 458 | BalancedDegradationSettings settings; |
| 459 | VerifyIsDefault(settings.GetConfigs()); |
| 460 | } |
| 461 | |
| 462 | TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowGreaterThanHigh) { |
| 463 | webrtc::test::ScopedFieldTrials field_trials( |
| 464 | "WebRTC-Video-BalancedDegradationSettings/" |
| 465 | "pixels:1000|2000|3000,fps:5|15|25," |
| 466 | "vp8_qp_low:89|90|88,vp8_qp_high:90|91|87/"); |
| 467 | BalancedDegradationSettings settings; |
| 468 | VerifyIsDefault(settings.GetConfigs()); |
| 469 | } |
| 470 | |
| 471 | TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroQpValue) { |
| 472 | webrtc::test::ScopedFieldTrials field_trials( |
| 473 | "WebRTC-Video-BalancedDegradationSettings/" |
| 474 | "pixels:1000|2000|3000,fps:5|15|25," |
| 475 | "vp8_qp_low:89|0|88,vp8_qp_high:90|91|92/"); |
| 476 | BalancedDegradationSettings settings; |
| 477 | VerifyIsDefault(settings.GetConfigs()); |
| 478 | } |
| 479 | |
| 480 | TEST(BalancedDegradationSettings, GetsVp8QpThresholds) { |
| 481 | webrtc::test::ScopedFieldTrials field_trials( |
| 482 | "WebRTC-Video-BalancedDegradationSettings/" |
| 483 | "pixels:1000|2000|3000,fps:5|15|25," |
| 484 | "vp8_qp_low:89|90|88,vp8_qp_high:90|91|92/"); |
| 485 | BalancedDegradationSettings settings; |
| 486 | EXPECT_EQ(89, settings.GetQpThresholds(kVideoCodecVP8, 1)->low); |
| 487 | EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1)->high); |
| 488 | EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1000)->high); |
| 489 | EXPECT_EQ(91, settings.GetQpThresholds(kVideoCodecVP8, 1001)->high); |
| 490 | EXPECT_EQ(91, settings.GetQpThresholds(kVideoCodecVP8, 2000)->high); |
| 491 | EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 2001)->high); |
| 492 | EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 3000)->high); |
| 493 | EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 3001)->high); |
| 494 | } |
| 495 | |
| 496 | TEST(BalancedDegradationSettings, GetsVp9QpThresholds) { |
| 497 | webrtc::test::ScopedFieldTrials field_trials( |
| 498 | "WebRTC-Video-BalancedDegradationSettings/" |
| 499 | "pixels:1000|2000|3000,fps:5|15|25," |
| 500 | "vp9_qp_low:55|56|57,vp9_qp_high:155|156|157/"); |
| 501 | BalancedDegradationSettings settings; |
| 502 | const auto thresholds = settings.GetQpThresholds(kVideoCodecVP9, 1000); |
| 503 | EXPECT_TRUE(thresholds); |
| 504 | EXPECT_EQ(55, thresholds->low); |
| 505 | EXPECT_EQ(155, thresholds->high); |
| 506 | } |
| 507 | |
| 508 | TEST(BalancedDegradationSettings, GetsH264QpThresholds) { |
| 509 | webrtc::test::ScopedFieldTrials field_trials( |
| 510 | "WebRTC-Video-BalancedDegradationSettings/" |
| 511 | "pixels:1000|2000|3000,fps:5|15|25," |
| 512 | "h264_qp_low:21|22|23,h264_qp_high:41|43|42/"); |
| 513 | BalancedDegradationSettings settings; |
| 514 | const auto thresholds = settings.GetQpThresholds(kVideoCodecH264, 2000); |
| 515 | EXPECT_TRUE(thresholds); |
| 516 | EXPECT_EQ(22, thresholds->low); |
| 517 | EXPECT_EQ(43, thresholds->high); |
| 518 | } |
| 519 | |
| 520 | TEST(BalancedDegradationSettings, GetsGenericQpThresholds) { |
| 521 | webrtc::test::ScopedFieldTrials field_trials( |
| 522 | "WebRTC-Video-BalancedDegradationSettings/" |
| 523 | "pixels:1000|2000|3000,fps:5|15|25," |
| 524 | "generic_qp_low:2|3|4,generic_qp_high:22|23|24/"); |
| 525 | BalancedDegradationSettings settings; |
| 526 | const auto thresholds = settings.GetQpThresholds(kVideoCodecGeneric, 3000); |
| 527 | EXPECT_TRUE(thresholds); |
| 528 | EXPECT_EQ(4, thresholds->low); |
| 529 | EXPECT_EQ(24, thresholds->high); |
| 530 | } |
| 531 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 532 | } // namespace webrtc |