• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #include "test/field_trial.h"
14 #include "test/gtest.h"
15 
16 namespace webrtc {
17 namespace {
ExpectEqualSettings(QualityScalingExperiment::Settings a,QualityScalingExperiment::Settings b)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 
ExpectEqualConfig(QualityScalingExperiment::Config a,QualityScalingExperiment::Config b)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 
TEST(QualityScalingExperimentTest,DisabledWithoutFieldTrial)41 TEST(QualityScalingExperimentTest, DisabledWithoutFieldTrial) {
42   webrtc::test::ScopedFieldTrials field_trials("");
43   EXPECT_FALSE(QualityScalingExperiment::Enabled());
44 }
45 
TEST(QualityScalingExperimentTest,EnabledWithFieldTrial)46 TEST(QualityScalingExperimentTest, EnabledWithFieldTrial) {
47   webrtc::test::ScopedFieldTrials field_trials(
48       "WebRTC-Video-QualityScaling/Enabled/");
49   EXPECT_TRUE(QualityScalingExperiment::Enabled());
50 }
51 
TEST(QualityScalingExperimentTest,ParseSettings)52 TEST(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 
TEST(QualityScalingExperimentTest,ParseSettingsFailsWithoutFieldTrial)62 TEST(QualityScalingExperimentTest, ParseSettingsFailsWithoutFieldTrial) {
63   webrtc::test::ScopedFieldTrials field_trials("");
64   EXPECT_FALSE(QualityScalingExperiment::ParseSettings());
65 }
66 
TEST(QualityScalingExperimentTest,ParseSettingsFailsWithInvalidFieldTrial)67 TEST(QualityScalingExperimentTest, ParseSettingsFailsWithInvalidFieldTrial) {
68   webrtc::test::ScopedFieldTrials field_trials(
69       "WebRTC-Video-QualityScaling/Enabled-invalid/");
70   EXPECT_FALSE(QualityScalingExperiment::ParseSettings());
71 }
72 
TEST(QualityScalingExperimentTest,GetConfig)73 TEST(QualityScalingExperimentTest, GetConfig) {
74   webrtc::test::ScopedFieldTrials field_trials(
75       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.9,0.99,0/");
76   const auto config = QualityScalingExperiment::GetConfig();
77   EXPECT_EQ(0.9f, config.alpha_high);
78   EXPECT_EQ(0.99f, config.alpha_low);
79   EXPECT_FALSE(config.use_all_drop_reasons);
80 }
81 
TEST(QualityScalingExperimentTest,GetsDefaultConfigForInvalidFieldTrial)82 TEST(QualityScalingExperimentTest, GetsDefaultConfigForInvalidFieldTrial) {
83   webrtc::test::ScopedFieldTrials field_trials(
84       "WebRTC-Video-QualityScaling/Enabled-invalid/");
85   const auto config = QualityScalingExperiment::GetConfig();
86   ExpectEqualConfig(config, QualityScalingExperiment::Config());
87 }
88 
TEST(QualityScalingExperimentTest,GetsDefaultAlphaForInvalidValue)89 TEST(QualityScalingExperimentTest, GetsDefaultAlphaForInvalidValue) {
90   QualityScalingExperiment::Config expected_config;
91   expected_config.use_all_drop_reasons = true;
92   webrtc::test::ScopedFieldTrials field_trials(
93       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,7,8,0.99,0.9,1/");
94   const auto config = QualityScalingExperiment::GetConfig();
95   ExpectEqualConfig(config, expected_config);
96 }
97 
TEST(QualityScalingExperimentTest,GetVp8Thresholds)98 TEST(QualityScalingExperimentTest, GetVp8Thresholds) {
99   webrtc::test::ScopedFieldTrials field_trials(
100       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
101   const auto thresholds =
102       QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8);
103   EXPECT_TRUE(thresholds);
104   EXPECT_EQ(1, thresholds->low);
105   EXPECT_EQ(2, thresholds->high);
106 }
107 
TEST(QualityScalingExperimentTest,GetThresholdsFailsForInvalidVp8Value)108 TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp8Value) {
109   webrtc::test::ScopedFieldTrials field_trials(
110       "WebRTC-Video-QualityScaling/Enabled-0,0,3,4,5,6,7,8,0.9,0.99,1/");
111   const auto thresholds =
112       QualityScalingExperiment::GetQpThresholds(kVideoCodecVP8);
113   EXPECT_FALSE(thresholds);
114 }
115 
TEST(QualityScalingExperimentTest,GetVp9Thresholds)116 TEST(QualityScalingExperimentTest, GetVp9Thresholds) {
117   webrtc::test::ScopedFieldTrials field_trials(
118       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
119   const auto thresholds =
120       QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9);
121   EXPECT_TRUE(thresholds);
122   EXPECT_EQ(3, thresholds->low);
123   EXPECT_EQ(4, thresholds->high);
124 }
125 
TEST(QualityScalingExperimentTest,GetThresholdsFailsForInvalidVp9Value)126 TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidVp9Value) {
127   webrtc::test::ScopedFieldTrials field_trials(
128       "WebRTC-Video-QualityScaling/Enabled-1,2,0,0,5,6,7,8,0.9,0.99,1/");
129   const auto thresholds =
130       QualityScalingExperiment::GetQpThresholds(kVideoCodecVP9);
131   EXPECT_FALSE(thresholds);
132 }
133 
TEST(QualityScalingExperimentTest,GetH264Thresholds)134 TEST(QualityScalingExperimentTest, GetH264Thresholds) {
135   webrtc::test::ScopedFieldTrials field_trials(
136       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
137   const auto thresholds =
138       QualityScalingExperiment::GetQpThresholds(kVideoCodecH264);
139   EXPECT_TRUE(thresholds);
140   EXPECT_EQ(5, thresholds->low);
141   EXPECT_EQ(6, thresholds->high);
142 }
143 
TEST(QualityScalingExperimentTest,GetThresholdsFailsForInvalidH264Value)144 TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidH264Value) {
145   webrtc::test::ScopedFieldTrials field_trials(
146       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/");
147   const auto thresholds =
148       QualityScalingExperiment::GetQpThresholds(kVideoCodecH264);
149   EXPECT_FALSE(thresholds);
150 }
151 
TEST(QualityScalingExperimentTest,GetGenericThresholds)152 TEST(QualityScalingExperimentTest, GetGenericThresholds) {
153   webrtc::test::ScopedFieldTrials field_trials(
154       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,0,0,7,8,0.9,0.99,1/");
155   const auto thresholds =
156       QualityScalingExperiment::GetQpThresholds(kVideoCodecGeneric);
157   EXPECT_TRUE(thresholds);
158   EXPECT_EQ(7, thresholds->low);
159   EXPECT_EQ(8, thresholds->high);
160 }
161 
TEST(QualityScalingExperimentTest,GetThresholdsFailsForInvalidGenericValue)162 TEST(QualityScalingExperimentTest, GetThresholdsFailsForInvalidGenericValue) {
163   webrtc::test::ScopedFieldTrials field_trials(
164       "WebRTC-Video-QualityScaling/Enabled-1,2,3,4,5,6,0,0,0.9,0.99,1/");
165   const auto thresholds =
166       QualityScalingExperiment::GetQpThresholds(kVideoCodecGeneric);
167   EXPECT_FALSE(thresholds);
168 }
169 }  // namespace webrtc
170