blob: 2ecdd7c49e5e8b860df53fb0141676b37ab9bd86 [file] [log] [blame]
Åsa Perssona945aee2018-04-24 16:53:25 +02001/*
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
Åsa Perssona945aee2018-04-24 16:53:25 +020013#include "test/field_trial.h"
Yves Gerey3e707812018-11-28 16:47:49 +010014#include "test/gtest.h"
Åsa Perssona945aee2018-04-24 16:53:25 +020015
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 Nikolaevskiy066b5b62021-01-28 14:58:24 +010041TEST(QualityScalingExperimentTest, DefaultEnabledWithoutFieldTrial) {
Åsa Perssona945aee2018-04-24 16:53:25 +020042 webrtc::test::ScopedFieldTrials field_trials("");
Ilya Nikolaevskiy066b5b62021-01-28 14:58:24 +010043 EXPECT_TRUE(QualityScalingExperiment::Enabled());
Åsa Perssona945aee2018-04-24 16:53:25 +020044}
45
46TEST(QualityScalingExperimentTest, EnabledWithFieldTrial) {
47 webrtc::test::ScopedFieldTrials field_trials(
48 "WebRTC-Video-QualityScaling/Enabled/");
49 EXPECT_TRUE(QualityScalingExperiment::Enabled());
50}
51
52TEST(QualityScalingExperimentTest, ParseSettings) {
53 const QualityScalingExperiment::Settings kExpected = {1, 2, 3, 4, 5, 6,
54 7, 8, 0.9f, 0.99f, 1};
55 webrtc::test::ScopedFieldTrials field_trials(
56 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.9,0.99,1/");
57 const auto settings = QualityScalingExperiment::ParseSettings();
58 EXPECT_TRUE(settings);
59 ExpectEqualSettings(kExpected, *settings);
60}
61
Ilya Nikolaevskiy066b5b62021-01-28 14:58:24 +010062TEST(QualityScalingExperimentTest, ParseSettingsUsesDefaultsWithoutFieldTrial) {
Åsa Perssona945aee2018-04-24 16:53:25 +020063 webrtc::test::ScopedFieldTrials field_trials("");
Ilya Nikolaevskiy066b5b62021-01-28 14:58:24 +010064 // Uses some default hard coded values.
65 EXPECT_TRUE(QualityScalingExperiment::ParseSettings());
Åsa Perssona945aee2018-04-24 16:53:25 +020066}
67
68TEST(QualityScalingExperimentTest, ParseSettingsFailsWithInvalidFieldTrial) {
69 webrtc::test::ScopedFieldTrials field_trials(
70 "WebRTC-Video-QualityScaling/Enabled-invalid/");
71 EXPECT_FALSE(QualityScalingExperiment::ParseSettings());
72}
73
74TEST(QualityScalingExperimentTest, GetConfig) {
75 webrtc::test::ScopedFieldTrials field_trials(
76 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.9,0.99,0/");
77 const auto config = QualityScalingExperiment::GetConfig();
78 EXPECT_EQ(0.9f, config.alpha_high);
79 EXPECT_EQ(0.99f, config.alpha_low);
80 EXPECT_FALSE(config.use_all_drop_reasons);
81}
82
83TEST(QualityScalingExperimentTest, GetsDefaultConfigForInvalidFieldTrial) {
84 webrtc::test::ScopedFieldTrials field_trials(
85 "WebRTC-Video-QualityScaling/Enabled-invalid/");
86 const auto config = QualityScalingExperiment::GetConfig();
87 ExpectEqualConfig(config, QualityScalingExperiment::Config());
88}
89
90TEST(QualityScalingExperimentTest, GetsDefaultAlphaForInvalidValue) {
91 QualityScalingExperiment::Config expected_config;
92 expected_config.use_all_drop_reasons = true;
93 webrtc::test::ScopedFieldTrials field_trials(
94 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.99,0.9,1/");
95 const auto config = QualityScalingExperiment::GetConfig();
96 ExpectEqualConfig(config, expected_config);
97}
98
99TEST(QualityScalingExperimentTest, GetVp8Thresholds) {
100 webrtc::test::ScopedFieldTrials field_trials(
101 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
102 const auto thresholds =
103 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8);
104 EXPECT_TRUE(thresholds);
105 EXPECT_EQ(1, thresholds->low);
106 EXPECT_EQ(2, thresholds->high);
107}
108
109TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp8Value) {
110 webrtc::test::ScopedFieldTrials field_trials(
111 "WebRTC-Video-QualityScaling/Enabled-0,0,3,4,5,6,7,8,0.9,0.99,1/");
112 const auto thresholds =
113 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8);
114 EXPECT_FALSE(thresholds);
115}
116
117TEST(QualityScalingExperimentTest, GetVp9Thresholds) {
118 webrtc::test::ScopedFieldTrials field_trials(
119 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
120 const auto thresholds =
121 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9);
122 EXPECT_TRUE(thresholds);
123 EXPECT_EQ(3, thresholds->low);
124 EXPECT_EQ(4, thresholds->high);
125}
126
127TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp9Value) {
128 webrtc::test::ScopedFieldTrials field_trials(
129 "WebRTC-Video-QualityScaling/Enabled-1,2,0,0,5,6,7,8,0.9,0.99,1/");
130 const auto thresholds =
131 QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9);
132 EXPECT_FALSE(thresholds);
133}
134
135TEST(QualityScalingExperimentTest, GetH264Thresholds) {
136 webrtc::test::ScopedFieldTrials field_trials(
137 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
138 const auto thresholds =
139 QualityScalingExperiment::GetQpThresholds(kVideoCodecH264);
140 EXPECT_TRUE(thresholds);
141 EXPECT_EQ(5, thresholds->low);
142 EXPECT_EQ(6, thresholds->high);
143}
144
145TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidH264Value) {
146 webrtc::test::ScopedFieldTrials field_trials(
147 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/");
148 const auto thresholds =
149 QualityScalingExperiment::GetQpThresholds(kVideoCodecH264);
150 EXPECT_FALSE(thresholds);
151}
152
153TEST(QualityScalingExperimentTest, GetGenericThresholds) {
154 webrtc::test::ScopedFieldTrials field_trials(
155 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/");
156 const auto thresholds =
157 QualityScalingExperiment::GetQpThresholds(kVideoCodecGeneric);
158 EXPECT_TRUE(thresholds);
159 EXPECT_EQ(7, thresholds->low);
160 EXPECT_EQ(8, thresholds->high);
161}
162
163TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidGenericValue) {
164 webrtc::test::ScopedFieldTrials field_trials(
165 "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
166 const auto thresholds =
167 QualityScalingExperiment::GetQpThresholds(kVideoCodecGeneric);
168 EXPECT_FALSE(thresholds);
169}
170} // namespace webrtc