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/quality_scaler_settings.h"
12
13 #include "test/field_trial.h"
14 #include "test/gtest.h"
15
16 namespace webrtc {
17 namespace {
18
TEST(QualityScalerSettingsTest,ValuesNotSetByDefault)19 TEST(QualityScalerSettingsTest, ValuesNotSetByDefault) {
20 const auto settings = QualityScalerSettings::ParseFromFieldTrials();
21 EXPECT_FALSE(settings.MinFrames());
22 EXPECT_FALSE(settings.InitialScaleFactor());
23 EXPECT_FALSE(settings.ScaleFactor());
24 EXPECT_FALSE(settings.InitialBitrateIntervalMs());
25 EXPECT_FALSE(settings.InitialBitrateFactor());
26 }
27
TEST(QualityScalerSettingsTest,ParseMinFrames)28 TEST(QualityScalerSettingsTest, ParseMinFrames) {
29 test::ScopedFieldTrials field_trials(
30 "WebRTC-Video-QualityScalerSettings/min_frames:100/");
31 EXPECT_EQ(100, QualityScalerSettings::ParseFromFieldTrials().MinFrames());
32 }
33
TEST(QualityScalerSettingsTest,ParseInitialScaleFactor)34 TEST(QualityScalerSettingsTest, ParseInitialScaleFactor) {
35 test::ScopedFieldTrials field_trials(
36 "WebRTC-Video-QualityScalerSettings/initial_scale_factor:1.5/");
37 EXPECT_EQ(1.5,
38 QualityScalerSettings::ParseFromFieldTrials().InitialScaleFactor());
39 }
40
TEST(QualityScalerSettingsTest,ParseScaleFactor)41 TEST(QualityScalerSettingsTest, ParseScaleFactor) {
42 test::ScopedFieldTrials field_trials(
43 "WebRTC-Video-QualityScalerSettings/scale_factor:1.1/");
44 EXPECT_EQ(1.1, QualityScalerSettings::ParseFromFieldTrials().ScaleFactor());
45 }
46
TEST(QualityScalerSettingsTest,ParseInitialBitrateInterval)47 TEST(QualityScalerSettingsTest, ParseInitialBitrateInterval) {
48 test::ScopedFieldTrials field_trials(
49 "WebRTC-Video-QualityScalerSettings/initial_bitrate_interval_ms:1000/");
50 EXPECT_EQ(
51 1000,
52 QualityScalerSettings::ParseFromFieldTrials().InitialBitrateIntervalMs());
53 }
54
TEST(QualityScalerSettingsTest,ParseInitialBitrateFactor)55 TEST(QualityScalerSettingsTest, ParseInitialBitrateFactor) {
56 test::ScopedFieldTrials field_trials(
57 "WebRTC-Video-QualityScalerSettings/initial_bitrate_factor:0.75/");
58 EXPECT_EQ(
59 0.75,
60 QualityScalerSettings::ParseFromFieldTrials().InitialBitrateFactor());
61 }
62
TEST(QualityScalerSettingsTest,ParseAll)63 TEST(QualityScalerSettingsTest, ParseAll) {
64 test::ScopedFieldTrials field_trials(
65 "WebRTC-Video-QualityScalerSettings/"
66 "min_frames:100,initial_scale_factor:1.5,scale_factor:0.9,"
67 "initial_bitrate_interval_ms:5500,initial_bitrate_factor:0.7/");
68 const auto settings = QualityScalerSettings::ParseFromFieldTrials();
69 EXPECT_EQ(100, settings.MinFrames());
70 EXPECT_EQ(1.5, settings.InitialScaleFactor());
71 EXPECT_EQ(0.9, settings.ScaleFactor());
72 EXPECT_EQ(5500, settings.InitialBitrateIntervalMs());
73 EXPECT_EQ(0.7, settings.InitialBitrateFactor());
74 }
75
TEST(QualityScalerSettingsTest,DoesNotParseIncorrectValue)76 TEST(QualityScalerSettingsTest, DoesNotParseIncorrectValue) {
77 test::ScopedFieldTrials field_trials(
78 "WebRTC-Video-QualityScalerSettings/"
79 "min_frames:a,initial_scale_factor:b,scale_factor:c,"
80 "initial_bitrate_interval_ms:d,initial_bitrate_factor:e/");
81 const auto settings = QualityScalerSettings::ParseFromFieldTrials();
82 EXPECT_FALSE(settings.MinFrames());
83 EXPECT_FALSE(settings.InitialScaleFactor());
84 EXPECT_FALSE(settings.ScaleFactor());
85 EXPECT_FALSE(settings.InitialBitrateIntervalMs());
86 EXPECT_FALSE(settings.InitialBitrateFactor());
87 }
88
TEST(QualityScalerSettingsTest,DoesNotReturnTooSmallValue)89 TEST(QualityScalerSettingsTest, DoesNotReturnTooSmallValue) {
90 test::ScopedFieldTrials field_trials(
91 "WebRTC-Video-QualityScalerSettings/"
92 "min_frames:0,initial_scale_factor:0.0,scale_factor:0.0,"
93 "initial_bitrate_interval_ms:-1,initial_bitrate_factor:0.0/");
94 const auto settings = QualityScalerSettings::ParseFromFieldTrials();
95 EXPECT_FALSE(settings.MinFrames());
96 EXPECT_FALSE(settings.InitialScaleFactor());
97 EXPECT_FALSE(settings.ScaleFactor());
98 EXPECT_FALSE(settings.InitialBitrateIntervalMs());
99 EXPECT_FALSE(settings.InitialBitrateFactor());
100 }
101
102 } // namespace
103 } // namespace webrtc
104