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/min_video_bitrate_experiment.h"
12
13 #include "absl/types/optional.h"
14 #include "api/units/data_rate.h"
15 #include "api/video/video_codec_type.h"
16 #include "test/field_trial.h"
17 #include "test/gtest.h"
18
19 namespace webrtc {
20 namespace {
21
TEST(GetExperimentalMinVideoBitrateTest,NulloptForAllCodecsIfFieldTrialUndefined)22 TEST(GetExperimentalMinVideoBitrateTest,
23 NulloptForAllCodecsIfFieldTrialUndefined) {
24 test::ScopedFieldTrials field_trials("");
25
26 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecGeneric),
27 absl::nullopt);
28 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP8),
29 absl::nullopt);
30 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP9),
31 absl::nullopt);
32 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecH264),
33 absl::nullopt);
34 EXPECT_EQ(
35 GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecMultiplex),
36 absl::nullopt);
37 }
38
TEST(GetExperimentalMinVideoBitrateTest,NulloptForAllCodecsIfFieldTrialDisabled)39 TEST(GetExperimentalMinVideoBitrateTest,
40 NulloptForAllCodecsIfFieldTrialDisabled) {
41 test::ScopedFieldTrials field_trials(
42 "WebRTC-Video-MinVideoBitrate/Disabled,br:123kbps/");
43
44 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecGeneric),
45 absl::nullopt);
46 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP8),
47 absl::nullopt);
48 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP9),
49 absl::nullopt);
50 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecH264),
51 absl::nullopt);
52 EXPECT_EQ(
53 GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecMultiplex),
54 absl::nullopt);
55 }
56
TEST(GetExperimentalMinVideoBitrateTest,BrForAllCodecsIfDefined)57 TEST(GetExperimentalMinVideoBitrateTest, BrForAllCodecsIfDefined) {
58 test::ScopedFieldTrials field_trials(
59 "WebRTC-Video-MinVideoBitrate/Enabled,br:123kbps/");
60
61 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecGeneric),
62 absl::make_optional(DataRate::KilobitsPerSec(123)));
63 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP8),
64 absl::make_optional(DataRate::KilobitsPerSec(123)));
65 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP9),
66 absl::make_optional(DataRate::KilobitsPerSec(123)));
67 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecH264),
68 absl::make_optional(DataRate::KilobitsPerSec(123)));
69 EXPECT_EQ(
70 GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecMultiplex),
71 absl::make_optional(DataRate::KilobitsPerSec(123)));
72 }
73
TEST(GetExperimentalMinVideoBitrateTest,BrTrumpsSpecificCodecConfigs)74 TEST(GetExperimentalMinVideoBitrateTest, BrTrumpsSpecificCodecConfigs) {
75 test::ScopedFieldTrials field_trials(
76 "WebRTC-Video-MinVideoBitrate/"
77 "Enabled,br:123kbps,vp8_br:100kbps,vp9_br:200kbps,h264_br:300kbps/");
78
79 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecGeneric),
80 absl::make_optional(DataRate::KilobitsPerSec(123)));
81 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP8),
82 absl::make_optional(DataRate::KilobitsPerSec(123)));
83 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP9),
84 absl::make_optional(DataRate::KilobitsPerSec(123)));
85 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecH264),
86 absl::make_optional(DataRate::KilobitsPerSec(123)));
87 EXPECT_EQ(
88 GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecMultiplex),
89 absl::make_optional(DataRate::KilobitsPerSec(123)));
90 }
91
TEST(GetExperimentalMinVideoBitrateTest,SpecificCodecConfigsIgnoredIfExpDisabled)92 TEST(GetExperimentalMinVideoBitrateTest,
93 SpecificCodecConfigsIgnoredIfExpDisabled) {
94 test::ScopedFieldTrials field_trials(
95 "WebRTC-Video-MinVideoBitrate/"
96 "Disabled,vp8_br:100kbps,vp9_br:200kbps,h264_br:300kbps/");
97
98 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecGeneric),
99 absl::nullopt);
100 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP8),
101 absl::nullopt);
102 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP9),
103 absl::nullopt);
104 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecH264),
105 absl::nullopt);
106 EXPECT_EQ(
107 GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecMultiplex),
108 absl::nullopt);
109 }
110
TEST(GetExperimentalMinVideoBitrateTest,SpecificCodecConfigsUsedIfExpEnabled)111 TEST(GetExperimentalMinVideoBitrateTest, SpecificCodecConfigsUsedIfExpEnabled) {
112 test::ScopedFieldTrials field_trials(
113 "WebRTC-Video-MinVideoBitrate/"
114 "Enabled,vp8_br:100kbps,vp9_br:200kbps,h264_br:300kbps/");
115
116 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecGeneric),
117 absl::nullopt);
118 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP8),
119 absl::make_optional(DataRate::KilobitsPerSec(100)));
120 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP9),
121 absl::make_optional(DataRate::KilobitsPerSec(200)));
122 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecH264),
123 absl::make_optional(DataRate::KilobitsPerSec(300)));
124 EXPECT_EQ(
125 GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecMultiplex),
126 absl::nullopt);
127 }
128
TEST(GetExperimentalMinVideoBitrateTest,Vp8BitrateValueTakenFromFallbackIfAvailable)129 TEST(GetExperimentalMinVideoBitrateTest,
130 Vp8BitrateValueTakenFromFallbackIfAvailable) {
131 test::ScopedFieldTrials field_trials(
132 "WebRTC-Video-MinVideoBitrate/"
133 "Enabled,vp8_br:100kbps,vp9_br:200kbps,h264_br:300kbps/"
134 "WebRTC-VP8-Forced-Fallback-Encoder-v2/"
135 "Enabled-444444,555555,666666/");
136
137 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP8),
138 absl::make_optional(DataRate::BitsPerSec(666666)));
139 }
140
TEST(GetExperimentalMinVideoBitrateTest,NonVp8BitrateValuesTakenFromMinVideoBitrate)141 TEST(GetExperimentalMinVideoBitrateTest,
142 NonVp8BitrateValuesTakenFromMinVideoBitrate) {
143 test::ScopedFieldTrials field_trials(
144 "WebRTC-Video-MinVideoBitrate/"
145 "Enabled,vp8_br:100kbps,vp9_br:200kbps,h264_br:300kbps/"
146 "WebRTC-VP8-Forced-Fallback-Encoder-v2/"
147 "Enabled-444444,555555,666666/");
148
149 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecGeneric),
150 absl::nullopt);
151 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecVP9),
152 absl::make_optional(DataRate::KilobitsPerSec(200)));
153 EXPECT_EQ(GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecH264),
154 absl::make_optional(DataRate::KilobitsPerSec(300)));
155 EXPECT_EQ(
156 GetExperimentalMinVideoBitrate(VideoCodecType::kVideoCodecMultiplex),
157 absl::nullopt);
158 }
159
160 } // namespace
161 } // namespace webrtc
162