blob: c604b554f0cc360cb31e44a5aabc518dc4b5be38 [file] [log] [blame]
Åsa Perssonf3d828e2019-05-06 12:22:49 +02001/*
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
19namespace webrtc {
20namespace {
21
22void VerifyIsDefault(
23 const std::vector<BalancedDegradationSettings::Config>& config) {
Åsa Persson48284b82019-07-08 10:01:12 +020024 EXPECT_THAT(
25 config,
26 ::testing::ElementsAre(
27 BalancedDegradationSettings::Config{
28 320 * 240, 7, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
29 BalancedDegradationSettings::Config{
30 480 * 270, 10, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
31 BalancedDegradationSettings::Config{
32 640 * 480, 15, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}));
Åsa Perssonf3d828e2019-05-06 12:22:49 +020033}
34} // namespace
35
36TEST(BalancedDegradationSettings, GetsDefaultConfigIfNoList) {
37 webrtc::test::ScopedFieldTrials field_trials("");
38 BalancedDegradationSettings settings;
39 VerifyIsDefault(settings.GetConfigs());
Åsa Persson12314192019-06-20 15:45:07 +020040 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1));
41 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1));
42 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1));
43 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecGeneric, 1));
44 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecMultiplex, 1));
Åsa Perssonf3d828e2019-05-06 12:22:49 +020045}
46
47TEST(BalancedDegradationSettings, GetsConfig) {
48 webrtc::test::ScopedFieldTrials field_trials(
49 "WebRTC-Video-BalancedDegradationSettings/"
Åsa Persson12314192019-06-20 15:45:07 +020050 "pixels:11|22|33,fps:5|15|25,other:4|5|6/");
Åsa Perssonf3d828e2019-05-06 12:22:49 +020051 BalancedDegradationSettings settings;
Åsa Persson12314192019-06-20 15:45:07 +020052 EXPECT_THAT(settings.GetConfigs(),
53 ::testing::ElementsAre(
54 BalancedDegradationSettings::Config{
Åsa Persson48284b82019-07-08 10:01:12 +020055 11, 5, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
Åsa Persson12314192019-06-20 15:45:07 +020056 BalancedDegradationSettings::Config{
Åsa Persson48284b82019-07-08 10:01:12 +020057 22, 15, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
Åsa Persson12314192019-06-20 15:45:07 +020058 BalancedDegradationSettings::Config{
Åsa Persson48284b82019-07-08 10:01:12 +020059 33, 25, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}));
Åsa Perssonf3d828e2019-05-06 12:22:49 +020060}
61
62TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroFpsValue) {
63 webrtc::test::ScopedFieldTrials field_trials(
64 "WebRTC-Video-BalancedDegradationSettings/"
65 "pixels:1000|2000|3000,fps:0|15|25/");
66 BalancedDegradationSettings settings;
67 VerifyIsDefault(settings.GetConfigs());
68}
69
70TEST(BalancedDegradationSettings, GetsDefaultConfigIfPixelsDecreases) {
71 webrtc::test::ScopedFieldTrials field_trials(
72 "WebRTC-Video-BalancedDegradationSettings/"
73 "pixels:1000|999|3000,fps:5|15|25/");
74 BalancedDegradationSettings settings;
75 VerifyIsDefault(settings.GetConfigs());
76}
77
78TEST(BalancedDegradationSettings, GetsDefaultConfigIfFramerateDecreases) {
79 webrtc::test::ScopedFieldTrials field_trials(
80 "WebRTC-Video-BalancedDegradationSettings/"
81 "pixels:1000|2000|3000,fps:5|4|25/");
82 BalancedDegradationSettings settings;
83 VerifyIsDefault(settings.GetConfigs());
84}
85
Åsa Persson48284b82019-07-08 10:01:12 +020086TEST(BalancedDegradationSettings, GetsConfigWithSpecificFps) {
87 webrtc::test::ScopedFieldTrials field_trials(
88 "WebRTC-Video-BalancedDegradationSettings/"
89 "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|8|9,vp9_fps:9|10|11,"
90 "h264_fps:11|12|13,generic_fps:13|14|15/");
91 BalancedDegradationSettings settings;
92 EXPECT_THAT(
93 settings.GetConfigs(),
94 ::testing::ElementsAre(
95 BalancedDegradationSettings::Config{
96 1000, 5, {0, 0, 7}, {0, 0, 9}, {0, 0, 11}, {0, 0, 13}},
97 BalancedDegradationSettings::Config{
98 2000, 15, {0, 0, 8}, {0, 0, 10}, {0, 0, 12}, {0, 0, 14}},
99 BalancedDegradationSettings::Config{
100 3000, 25, {0, 0, 9}, {0, 0, 11}, {0, 0, 13}, {0, 0, 15}}));
101}
102
103TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroVp8FpsValue) {
104 webrtc::test::ScopedFieldTrials field_trials(
105 "WebRTC-Video-BalancedDegradationSettings/"
106 "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:0|15|25/");
107 BalancedDegradationSettings settings;
108 VerifyIsDefault(settings.GetConfigs());
109}
110
111TEST(BalancedDegradationSettings, GetsDefaultConfigForInvalidFpsValue) {
112 webrtc::test::ScopedFieldTrials field_trials(
113 "WebRTC-Video-BalancedDegradationSettings/"
114 "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:10|15|2000/");
115 BalancedDegradationSettings settings;
116 VerifyIsDefault(settings.GetConfigs());
117}
118
119TEST(BalancedDegradationSettings, GetsDefaultConfigIfVp8FramerateDecreases) {
120 webrtc::test::ScopedFieldTrials field_trials(
121 "WebRTC-Video-BalancedDegradationSettings/"
122 "pixels:1000|2000|3000,fps:4|5|25,vp8_fps:5|4|25/");
123 BalancedDegradationSettings settings;
124 VerifyIsDefault(settings.GetConfigs());
125}
126
Åsa Perssonf3d828e2019-05-06 12:22:49 +0200127TEST(BalancedDegradationSettings, GetsMinFps) {
128 webrtc::test::ScopedFieldTrials field_trials(
129 "WebRTC-Video-BalancedDegradationSettings/"
130 "pixels:1000|2000|3000,fps:5|15|25/");
131 BalancedDegradationSettings settings;
Åsa Persson48284b82019-07-08 10:01:12 +0200132 EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1));
133 EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1000));
134 EXPECT_EQ(15, settings.MinFps(kVideoCodecVP8, 1001));
135 EXPECT_EQ(15, settings.MinFps(kVideoCodecVP8, 2000));
136 EXPECT_EQ(25, settings.MinFps(kVideoCodecVP8, 2001));
137 EXPECT_EQ(25, settings.MinFps(kVideoCodecVP8, 3000));
138 EXPECT_EQ(std::numeric_limits<int>::max(),
139 settings.MinFps(kVideoCodecVP8, 3001));
140}
141
142TEST(BalancedDegradationSettings, GetsVp8MinFps) {
143 webrtc::test::ScopedFieldTrials field_trials(
144 "WebRTC-Video-BalancedDegradationSettings/"
145 "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/");
146 BalancedDegradationSettings settings;
147 EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1));
148 EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1000));
149 EXPECT_EQ(10, settings.MinFps(kVideoCodecVP8, 1001));
150 EXPECT_EQ(10, settings.MinFps(kVideoCodecVP8, 2000));
151 EXPECT_EQ(12, settings.MinFps(kVideoCodecVP8, 2001));
152 EXPECT_EQ(12, settings.MinFps(kVideoCodecVP8, 3000));
153 EXPECT_EQ(std::numeric_limits<int>::max(),
154 settings.MinFps(kVideoCodecVP8, 3001));
Åsa Perssonf3d828e2019-05-06 12:22:49 +0200155}
156
157TEST(BalancedDegradationSettings, GetsMaxFps) {
158 webrtc::test::ScopedFieldTrials field_trials(
159 "WebRTC-Video-BalancedDegradationSettings/"
160 "pixels:1000|2000|3000,fps:5|15|25/");
161 BalancedDegradationSettings settings;
Åsa Persson48284b82019-07-08 10:01:12 +0200162 EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1));
163 EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1000));
164 EXPECT_EQ(25, settings.MaxFps(kVideoCodecVP8, 1001));
165 EXPECT_EQ(25, settings.MaxFps(kVideoCodecVP8, 2000));
166 EXPECT_EQ(std::numeric_limits<int>::max(),
167 settings.MaxFps(kVideoCodecVP8, 2001));
168}
169
170TEST(BalancedDegradationSettings, GetsVp8MaxFps) {
171 webrtc::test::ScopedFieldTrials field_trials(
172 "WebRTC-Video-BalancedDegradationSettings/"
173 "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/");
174 BalancedDegradationSettings settings;
175 EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1));
176 EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1000));
177 EXPECT_EQ(12, settings.MaxFps(kVideoCodecVP8, 1001));
178 EXPECT_EQ(12, settings.MaxFps(kVideoCodecVP8, 2000));
179 EXPECT_EQ(std::numeric_limits<int>::max(),
180 settings.MaxFps(kVideoCodecVP8, 2001));
181}
182
183TEST(BalancedDegradationSettings, GetsVp9Fps) {
184 webrtc::test::ScopedFieldTrials field_trials(
185 "WebRTC-Video-BalancedDegradationSettings/"
186 "pixels:1000|2000|3000,fps:5|15|25,vp9_fps:7|10|12/");
187 BalancedDegradationSettings settings;
188 EXPECT_EQ(7, settings.MinFps(kVideoCodecVP9, 1000));
189 EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP9, 1000));
190}
191
192TEST(BalancedDegradationSettings, GetsH264Fps) {
193 webrtc::test::ScopedFieldTrials field_trials(
194 "WebRTC-Video-BalancedDegradationSettings/"
195 "pixels:1000|2000|3000,fps:5|15|25,h264_fps:8|11|13/");
196 BalancedDegradationSettings settings;
197 EXPECT_EQ(11, settings.MinFps(kVideoCodecH264, 2000));
198 EXPECT_EQ(13, settings.MaxFps(kVideoCodecH264, 2000));
199}
200
201TEST(BalancedDegradationSettings, GetsGenericFps) {
202 webrtc::test::ScopedFieldTrials field_trials(
203 "WebRTC-Video-BalancedDegradationSettings/"
204 "pixels:1000|2000|3000,fps:5|15|25,generic_fps:9|12|14/");
205 BalancedDegradationSettings settings;
206 EXPECT_EQ(14, settings.MinFps(kVideoCodecGeneric, 3000));
207 EXPECT_EQ(std::numeric_limits<int>::max(),
208 settings.MaxFps(kVideoCodecGeneric, 3000));
Åsa Perssonf3d828e2019-05-06 12:22:49 +0200209}
210
Åsa Persson12314192019-06-20 15:45:07 +0200211TEST(BalancedDegradationSettings, QpThresholdsNotSetByDefault) {
212 webrtc::test::ScopedFieldTrials field_trials(
213 "WebRTC-Video-BalancedDegradationSettings/"
214 "pixels:1000|2000|3000,fps:5|15|25/");
215 BalancedDegradationSettings settings;
216 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1));
217 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1));
218 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1));
219 EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecGeneric, 1));
220}
221
222TEST(BalancedDegradationSettings, GetsConfigWithQpThresholds) {
223 webrtc::test::ScopedFieldTrials field_trials(
224 "WebRTC-Video-BalancedDegradationSettings/"
225 "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88,"
226 "vp8_qp_high:90|91|92,vp9_qp_low:27|28|29,vp9_qp_high:120|130|140,"
227 "h264_qp_low:12|13|14,h264_qp_high:20|30|40,generic_qp_low:7|6|5,"
228 "generic_qp_high:22|23|24/");
229 BalancedDegradationSettings settings;
Åsa Persson48284b82019-07-08 10:01:12 +0200230 EXPECT_THAT(
231 settings.GetConfigs(),
232 ::testing::ElementsAre(
233 BalancedDegradationSettings::Config{
234 1000, 5, {89, 90, 0}, {27, 120, 0}, {12, 20, 0}, {7, 22, 0}},
235 BalancedDegradationSettings::Config{
236 2000, 15, {90, 91, 0}, {28, 130, 0}, {13, 30, 0}, {6, 23, 0}},
237 BalancedDegradationSettings::Config{
238 3000, 25, {88, 92, 0}, {29, 140, 0}, {14, 40, 0}, {5, 24, 0}}));
Åsa Persson12314192019-06-20 15:45:07 +0200239}
240
241TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasLowThreshold) {
242 webrtc::test::ScopedFieldTrials field_trials(
243 "WebRTC-Video-BalancedDegradationSettings/"
244 "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88/");
245 BalancedDegradationSettings settings;
246 VerifyIsDefault(settings.GetConfigs());
247}
248
249TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasHighThreshold) {
250 webrtc::test::ScopedFieldTrials field_trials(
251 "WebRTC-Video-BalancedDegradationSettings/"
252 "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_high:90|91|92/");
253 BalancedDegradationSettings settings;
254 VerifyIsDefault(settings.GetConfigs());
255}
256
257TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowEqualsHigh) {
258 webrtc::test::ScopedFieldTrials field_trials(
259 "WebRTC-Video-BalancedDegradationSettings/"
260 "pixels:1000|2000|3000,fps:5|15|25,"
261 "vp8_qp_low:89|90|88,vp8_qp_high:90|91|88/");
262 BalancedDegradationSettings settings;
263 VerifyIsDefault(settings.GetConfigs());
264}
265
266TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowGreaterThanHigh) {
267 webrtc::test::ScopedFieldTrials field_trials(
268 "WebRTC-Video-BalancedDegradationSettings/"
269 "pixels:1000|2000|3000,fps:5|15|25,"
270 "vp8_qp_low:89|90|88,vp8_qp_high:90|91|87/");
271 BalancedDegradationSettings settings;
272 VerifyIsDefault(settings.GetConfigs());
273}
274
275TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroQpValue) {
276 webrtc::test::ScopedFieldTrials field_trials(
277 "WebRTC-Video-BalancedDegradationSettings/"
278 "pixels:1000|2000|3000,fps:5|15|25,"
279 "vp8_qp_low:89|0|88,vp8_qp_high:90|91|92/");
280 BalancedDegradationSettings settings;
281 VerifyIsDefault(settings.GetConfigs());
282}
283
284TEST(BalancedDegradationSettings, GetsVp8QpThresholds) {
285 webrtc::test::ScopedFieldTrials field_trials(
286 "WebRTC-Video-BalancedDegradationSettings/"
287 "pixels:1000|2000|3000,fps:5|15|25,"
288 "vp8_qp_low:89|90|88,vp8_qp_high:90|91|92/");
289 BalancedDegradationSettings settings;
290 EXPECT_EQ(89, settings.GetQpThresholds(kVideoCodecVP8, 1)->low);
291 EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1)->high);
292 EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1000)->high);
293 EXPECT_EQ(91, settings.GetQpThresholds(kVideoCodecVP8, 1001)->high);
294 EXPECT_EQ(91, settings.GetQpThresholds(kVideoCodecVP8, 2000)->high);
295 EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 2001)->high);
296 EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 3000)->high);
297 EXPECT_EQ(92, settings.GetQpThresholds(kVideoCodecVP8, 3001)->high);
298}
299
300TEST(BalancedDegradationSettings, GetsVp9QpThresholds) {
301 webrtc::test::ScopedFieldTrials field_trials(
302 "WebRTC-Video-BalancedDegradationSettings/"
303 "pixels:1000|2000|3000,fps:5|15|25,"
304 "vp9_qp_low:55|56|57,vp9_qp_high:155|156|157/");
305 BalancedDegradationSettings settings;
306 const auto thresholds = settings.GetQpThresholds(kVideoCodecVP9, 1000);
307 EXPECT_TRUE(thresholds);
308 EXPECT_EQ(55, thresholds->low);
309 EXPECT_EQ(155, thresholds->high);
310}
311
312TEST(BalancedDegradationSettings, GetsH264QpThresholds) {
313 webrtc::test::ScopedFieldTrials field_trials(
314 "WebRTC-Video-BalancedDegradationSettings/"
315 "pixels:1000|2000|3000,fps:5|15|25,"
316 "h264_qp_low:21|22|23,h264_qp_high:41|43|42/");
317 BalancedDegradationSettings settings;
318 const auto thresholds = settings.GetQpThresholds(kVideoCodecH264, 2000);
319 EXPECT_TRUE(thresholds);
320 EXPECT_EQ(22, thresholds->low);
321 EXPECT_EQ(43, thresholds->high);
322}
323
324TEST(BalancedDegradationSettings, GetsGenericQpThresholds) {
325 webrtc::test::ScopedFieldTrials field_trials(
326 "WebRTC-Video-BalancedDegradationSettings/"
327 "pixels:1000|2000|3000,fps:5|15|25,"
328 "generic_qp_low:2|3|4,generic_qp_high:22|23|24/");
329 BalancedDegradationSettings settings;
330 const auto thresholds = settings.GetQpThresholds(kVideoCodecGeneric, 3000);
331 EXPECT_TRUE(thresholds);
332 EXPECT_EQ(4, thresholds->low);
333 EXPECT_EQ(24, thresholds->high);
334}
335
Åsa Perssonf3d828e2019-05-06 12:22:49 +0200336} // namespace webrtc