OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | 11 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 #include <memory> | 14 #include <memory> |
| 15 #include <utility> |
| 16 #include <vector> |
15 | 17 |
16 #include "webrtc/test/gtest.h" | 18 #include "webrtc/test/gtest.h" |
17 | 19 |
18 namespace webrtc { | 20 namespace webrtc { |
19 namespace { | 21 namespace { |
20 constexpr uint32_t kMinBitrate = 50; | 22 constexpr uint32_t kMinBitrateKbps = 50; |
21 constexpr uint32_t kTargetBitrate = 100; | 23 constexpr uint32_t kTargetBitrateKbps = 100; |
22 constexpr uint32_t kMaxBitrate = 1000; | 24 constexpr uint32_t kMaxBitrateKbps = 1000; |
| 25 constexpr uint32_t kFramerateFps = 5; |
23 } // namespace | 26 } // namespace |
24 | 27 |
25 class SimulcastRateAllocatorTest : public ::testing::Test { | 28 class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> { |
26 public: | 29 public: |
27 SimulcastRateAllocatorTest() { | 30 SimulcastRateAllocatorTest() { |
28 memset(&codec_, 0, sizeof(VideoCodec)); | 31 memset(&codec_, 0, sizeof(VideoCodec)); |
29 codec_.minBitrate = kMinBitrate; | 32 codec_.minBitrate = kMinBitrateKbps; |
30 codec_.targetBitrate = kTargetBitrate; | 33 codec_.targetBitrate = kTargetBitrateKbps; |
31 codec_.maxBitrate = kMaxBitrate; | 34 codec_.maxBitrate = kMaxBitrateKbps; |
32 CreateAllocator(); | 35 CreateAllocator(); |
33 } | 36 } |
34 virtual ~SimulcastRateAllocatorTest() {} | 37 virtual ~SimulcastRateAllocatorTest() {} |
35 | 38 |
36 template <size_t S> | 39 template <size_t S> |
37 void ExpectEqual(uint32_t (&expected)[S], | 40 void ExpectEqual(uint32_t (&expected)[S], |
38 const std::vector<uint32_t>& actual) { | 41 const std::vector<uint32_t>& actual) { |
39 EXPECT_EQ(S, actual.size()); | 42 EXPECT_EQ(S, actual.size()); |
40 for (size_t i = 0; i < S; ++i) | 43 for (size_t i = 0; i < S; ++i) |
41 EXPECT_EQ(expected[i], actual[i]) << "Mismatch at index " << i; | 44 EXPECT_EQ(expected[i], actual[i]) << "Mismatch at index " << i; |
42 } | 45 } |
43 | 46 |
| 47 template <size_t S> |
| 48 void ExpectEqual(uint32_t (&expected)[S], const BitrateAllocation& actual) { |
| 49 // EXPECT_EQ(S, actual.size()); |
| 50 uint32_t sum = 0; |
| 51 for (size_t i = 0; i < S; ++i) { |
| 52 uint32_t layer_bitrate = actual.GetSpatialLayerSum(i); |
| 53 EXPECT_EQ(expected[i] * 1000U, layer_bitrate) << "Mismatch at index " |
| 54 << i; |
| 55 sum += layer_bitrate; |
| 56 } |
| 57 EXPECT_EQ(sum, actual.get_sum_bps()); |
| 58 } |
| 59 |
44 void CreateAllocator() { | 60 void CreateAllocator() { |
45 allocator_.reset(new SimulcastRateAllocator(codec_)); | 61 std::unique_ptr<TemporalLayersFactory> tl_factory(GetTlFactory()); |
| 62 codec_.VP8()->tl_factory = tl_factory.get(); |
| 63 allocator_.reset(new SimulcastRateAllocator(codec_, std::move(tl_factory))); |
| 64 |
| 65 // Simulate InitEncode(). |
| 66 tl_factories_.clear(); |
| 67 if (codec_.numberOfSimulcastStreams == 0) { |
| 68 tl_factories_.push_back( |
| 69 std::unique_ptr<TemporalLayers>(codec_.VP8()->tl_factory->Create( |
| 70 0, codec_.VP8()->numberOfTemporalLayers, 0))); |
| 71 } else { |
| 72 for (uint32_t i = 0; i < codec_.numberOfSimulcastStreams; ++i) { |
| 73 tl_factories_.push_back( |
| 74 std::unique_ptr<TemporalLayers>(codec_.VP8()->tl_factory->Create( |
| 75 i, codec_.simulcastStream[i].numberOfTemporalLayers, 0))); |
| 76 } |
| 77 } |
| 78 } |
| 79 |
| 80 virtual std::unique_ptr<TemporalLayersFactory> GetTlFactory() { |
| 81 return std::unique_ptr<TemporalLayersFactory>(new TemporalLayersFactory()); |
| 82 } |
| 83 |
| 84 BitrateAllocation GetAllocation(uint32_t target_bitrate) { |
| 85 return allocator_->GetAllocation(target_bitrate * 1000U, kDefaultFrameRate); |
46 } | 86 } |
47 | 87 |
48 protected: | 88 protected: |
| 89 static const int kDefaultFrameRate = 30; |
49 VideoCodec codec_; | 90 VideoCodec codec_; |
50 std::unique_ptr<SimulcastRateAllocator> allocator_; | 91 std::unique_ptr<SimulcastRateAllocator> allocator_; |
| 92 std::vector<std::unique_ptr<TemporalLayers>> tl_factories_; |
51 }; | 93 }; |
52 | 94 |
53 TEST_F(SimulcastRateAllocatorTest, NoSimulcastBelowMin) { | 95 TEST_F(SimulcastRateAllocatorTest, NoSimulcastBelowMin) { |
54 uint32_t expected[] = {codec_.minBitrate}; | 96 uint32_t expected[] = {codec_.minBitrate}; |
55 ExpectEqual(expected, allocator_->GetAllocation(codec_.minBitrate - 1)); | 97 ExpectEqual(expected, GetAllocation(codec_.minBitrate - 1)); |
56 ExpectEqual(expected, allocator_->GetAllocation(1)); | 98 ExpectEqual(expected, GetAllocation(1)); |
57 ExpectEqual(expected, allocator_->GetAllocation(0)); | 99 ExpectEqual(expected, GetAllocation(0)); |
58 } | 100 } |
59 | 101 |
60 TEST_F(SimulcastRateAllocatorTest, NoSimulcastAboveMax) { | 102 TEST_F(SimulcastRateAllocatorTest, NoSimulcastAboveMax) { |
61 uint32_t expected[] = {codec_.maxBitrate}; | 103 uint32_t expected[] = {codec_.maxBitrate}; |
62 ExpectEqual(expected, allocator_->GetAllocation(codec_.maxBitrate + 1)); | 104 ExpectEqual(expected, GetAllocation(codec_.maxBitrate + 1)); |
63 ExpectEqual(expected, | 105 ExpectEqual(expected, GetAllocation(std::numeric_limits<uint32_t>::max())); |
64 allocator_->GetAllocation(std::numeric_limits<uint32_t>::max())); | |
65 } | 106 } |
66 | 107 |
67 TEST_F(SimulcastRateAllocatorTest, NoSimulcastNoMax) { | 108 TEST_F(SimulcastRateAllocatorTest, NoSimulcastNoMax) { |
68 constexpr uint32_t kMax = std::numeric_limits<uint32_t>::max(); | 109 const uint32_t kMax = BitrateAllocation::kMaxBitrateBps / 1000; |
69 codec_.maxBitrate = 0; | 110 codec_.maxBitrate = 0; |
70 CreateAllocator(); | 111 CreateAllocator(); |
71 | 112 |
72 uint32_t expected[] = {kMax}; | 113 uint32_t expected[] = {kMax}; |
73 ExpectEqual(expected, allocator_->GetAllocation(kMax)); | 114 ExpectEqual(expected, GetAllocation(kMax)); |
74 } | 115 } |
75 | 116 |
76 TEST_F(SimulcastRateAllocatorTest, NoSimulcastWithinLimits) { | 117 TEST_F(SimulcastRateAllocatorTest, NoSimulcastWithinLimits) { |
77 for (uint32_t bitrate = codec_.minBitrate; bitrate <= codec_.maxBitrate; | 118 for (uint32_t bitrate = codec_.minBitrate; bitrate <= codec_.maxBitrate; |
78 ++bitrate) { | 119 ++bitrate) { |
79 uint32_t expected[] = {bitrate}; | 120 uint32_t expected[] = {bitrate}; |
80 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 121 ExpectEqual(expected, GetAllocation(bitrate)); |
81 } | 122 } |
82 } | 123 } |
83 | 124 |
84 TEST_F(SimulcastRateAllocatorTest, SingleSimulcastBelowMin) { | 125 TEST_F(SimulcastRateAllocatorTest, SingleSimulcastBelowMin) { |
85 // With simulcast, use the min bitrate from the ss spec instead of the global. | 126 // With simulcast, use the min bitrate from the ss spec instead of the global. |
86 codec_.numberOfSimulcastStreams = 1; | 127 codec_.numberOfSimulcastStreams = 1; |
87 const uint32_t kMin = codec_.minBitrate - 10; | 128 const uint32_t kMin = codec_.minBitrate - 10; |
88 codec_.simulcastStream[0].minBitrate = kMin; | 129 codec_.simulcastStream[0].minBitrate = kMin; |
89 codec_.simulcastStream[0].targetBitrate = kTargetBitrate; | 130 codec_.simulcastStream[0].targetBitrate = kTargetBitrateKbps; |
90 CreateAllocator(); | 131 CreateAllocator(); |
91 | 132 |
92 uint32_t expected[] = {kMin}; | 133 uint32_t expected[] = {kMin}; |
93 ExpectEqual(expected, allocator_->GetAllocation(kMin - 1)); | 134 ExpectEqual(expected, GetAllocation(kMin - 1)); |
94 ExpectEqual(expected, allocator_->GetAllocation(1)); | 135 ExpectEqual(expected, GetAllocation(1)); |
95 ExpectEqual(expected, allocator_->GetAllocation(0)); | 136 ExpectEqual(expected, GetAllocation(0)); |
96 } | 137 } |
97 | 138 |
98 TEST_F(SimulcastRateAllocatorTest, SingleSimulcastAboveMax) { | 139 TEST_F(SimulcastRateAllocatorTest, SingleSimulcastAboveMax) { |
99 codec_.numberOfSimulcastStreams = 1; | 140 codec_.numberOfSimulcastStreams = 1; |
100 codec_.simulcastStream[0].minBitrate = kMinBitrate; | 141 codec_.simulcastStream[0].minBitrate = kMinBitrateKbps; |
101 const uint32_t kMax = codec_.simulcastStream[0].maxBitrate + 1000; | 142 const uint32_t kMax = codec_.simulcastStream[0].maxBitrate + 1000; |
102 codec_.simulcastStream[0].maxBitrate = kMax; | 143 codec_.simulcastStream[0].maxBitrate = kMax; |
103 CreateAllocator(); | 144 CreateAllocator(); |
104 | 145 |
105 uint32_t expected[] = {kMax}; | 146 uint32_t expected[] = {kMax}; |
106 ExpectEqual(expected, allocator_->GetAllocation(kMax + 1)); | 147 ExpectEqual(expected, GetAllocation(kMax)); |
107 ExpectEqual(expected, | 148 ExpectEqual(expected, GetAllocation(kMax + 1)); |
108 allocator_->GetAllocation(std::numeric_limits<uint32_t>::max())); | 149 ExpectEqual(expected, GetAllocation(std::numeric_limits<uint32_t>::max())); |
109 } | 150 } |
110 | 151 |
111 TEST_F(SimulcastRateAllocatorTest, SingleSimulcastWithinLimits) { | 152 TEST_F(SimulcastRateAllocatorTest, SingleSimulcastWithinLimits) { |
112 codec_.numberOfSimulcastStreams = 1; | 153 codec_.numberOfSimulcastStreams = 1; |
113 codec_.simulcastStream[0].minBitrate = kMinBitrate; | 154 codec_.simulcastStream[0].minBitrate = kMinBitrateKbps; |
114 codec_.simulcastStream[0].targetBitrate = kTargetBitrate; | 155 codec_.simulcastStream[0].targetBitrate = kTargetBitrateKbps; |
115 codec_.simulcastStream[0].maxBitrate = kMaxBitrate; | 156 codec_.simulcastStream[0].maxBitrate = kMaxBitrateKbps; |
116 CreateAllocator(); | 157 CreateAllocator(); |
117 | 158 |
118 for (uint32_t bitrate = kMinBitrate; bitrate <= kMaxBitrate; ++bitrate) { | 159 for (uint32_t bitrate = kMinBitrateKbps; bitrate <= kMaxBitrateKbps; |
| 160 ++bitrate) { |
119 uint32_t expected[] = {bitrate}; | 161 uint32_t expected[] = {bitrate}; |
120 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 162 ExpectEqual(expected, GetAllocation(bitrate)); |
121 } | 163 } |
122 } | 164 } |
123 | 165 |
124 TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) { | 166 TEST_F(SimulcastRateAllocatorTest, OneToThreeStreams) { |
125 codec_.numberOfSimulcastStreams = 3; | 167 codec_.numberOfSimulcastStreams = 3; |
126 codec_.maxBitrate = 0; | 168 codec_.maxBitrate = 0; |
127 codec_.simulcastStream[0].minBitrate = 10; | 169 codec_.simulcastStream[0].minBitrate = 10; |
128 codec_.simulcastStream[0].targetBitrate = 100; | 170 codec_.simulcastStream[0].targetBitrate = 100; |
129 codec_.simulcastStream[0].maxBitrate = 500; | 171 codec_.simulcastStream[0].maxBitrate = 500; |
130 codec_.simulcastStream[1].minBitrate = 50; | 172 codec_.simulcastStream[1].minBitrate = 50; |
131 codec_.simulcastStream[1].targetBitrate = 500; | 173 codec_.simulcastStream[1].targetBitrate = 500; |
132 codec_.simulcastStream[1].maxBitrate = 1000; | 174 codec_.simulcastStream[1].maxBitrate = 1000; |
133 codec_.simulcastStream[2].minBitrate = 2000; | 175 codec_.simulcastStream[2].minBitrate = 2000; |
134 codec_.simulcastStream[2].targetBitrate = 3000; | 176 codec_.simulcastStream[2].targetBitrate = 3000; |
135 codec_.simulcastStream[2].maxBitrate = 4000; | 177 codec_.simulcastStream[2].maxBitrate = 4000; |
136 CreateAllocator(); | 178 CreateAllocator(); |
137 | 179 |
138 { | 180 { |
139 // Single stream, min bitrate. | 181 // Single stream, min bitrate. |
140 const uint32_t bitrate = codec_.simulcastStream[0].minBitrate; | 182 const uint32_t bitrate = codec_.simulcastStream[0].minBitrate; |
141 uint32_t expected[] = {bitrate, 0, 0}; | 183 uint32_t expected[] = {bitrate, 0, 0}; |
142 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 184 ExpectEqual(expected, GetAllocation(bitrate)); |
143 } | 185 } |
144 | 186 |
145 { | 187 { |
146 // Single stream at target bitrate. | 188 // Single stream at target bitrate. |
147 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate; | 189 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate; |
148 uint32_t expected[] = {bitrate, 0, 0}; | 190 uint32_t expected[] = {bitrate, 0, 0}; |
149 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 191 ExpectEqual(expected, GetAllocation(bitrate)); |
150 } | 192 } |
151 | 193 |
152 { | 194 { |
153 // Bitrate above target for first stream, but below min for the next one. | 195 // Bitrate above target for first stream, but below min for the next one. |
154 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + | 196 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + |
155 codec_.simulcastStream[1].minBitrate - 1; | 197 codec_.simulcastStream[1].minBitrate - 1; |
156 uint32_t expected[] = {bitrate, 0, 0}; | 198 uint32_t expected[] = {bitrate, 0, 0}; |
157 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 199 ExpectEqual(expected, GetAllocation(bitrate)); |
158 } | 200 } |
159 | 201 |
160 { | 202 { |
161 // Just enough for two streams. | 203 // Just enough for two streams. |
162 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + | 204 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + |
163 codec_.simulcastStream[1].minBitrate; | 205 codec_.simulcastStream[1].minBitrate; |
164 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, | 206 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, |
165 codec_.simulcastStream[1].minBitrate, 0}; | 207 codec_.simulcastStream[1].minBitrate, 0}; |
166 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 208 ExpectEqual(expected, GetAllocation(bitrate)); |
167 } | 209 } |
168 | 210 |
169 { | 211 { |
170 // Second stream maxed out, but not enough for third. | 212 // Second stream maxed out, but not enough for third. |
171 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + | 213 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + |
172 codec_.simulcastStream[1].maxBitrate; | 214 codec_.simulcastStream[1].maxBitrate; |
173 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, | 215 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, |
174 codec_.simulcastStream[1].maxBitrate, 0}; | 216 codec_.simulcastStream[1].maxBitrate, 0}; |
175 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 217 ExpectEqual(expected, GetAllocation(bitrate)); |
176 } | 218 } |
177 | 219 |
178 { | 220 { |
179 // First two streams maxed out, but not enough for third. Nowhere to put | 221 // First two streams maxed out, but not enough for third. Nowhere to put |
180 // remaining bits. | 222 // remaining bits. |
181 const uint32_t bitrate = codec_.simulcastStream[0].maxBitrate + | 223 const uint32_t bitrate = codec_.simulcastStream[0].maxBitrate + |
182 codec_.simulcastStream[1].maxBitrate + 499; | 224 codec_.simulcastStream[1].maxBitrate + 499; |
183 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, | 225 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, |
184 codec_.simulcastStream[1].maxBitrate, 0}; | 226 codec_.simulcastStream[1].maxBitrate, 0}; |
185 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 227 ExpectEqual(expected, GetAllocation(bitrate)); |
186 } | 228 } |
187 | 229 |
188 { | 230 { |
189 // Just enough for all three streams. | 231 // Just enough for all three streams. |
190 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + | 232 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + |
191 codec_.simulcastStream[1].targetBitrate + | 233 codec_.simulcastStream[1].targetBitrate + |
192 codec_.simulcastStream[2].minBitrate; | 234 codec_.simulcastStream[2].minBitrate; |
193 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, | 235 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, |
194 codec_.simulcastStream[1].targetBitrate, | 236 codec_.simulcastStream[1].targetBitrate, |
195 codec_.simulcastStream[2].minBitrate}; | 237 codec_.simulcastStream[2].minBitrate}; |
196 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 238 ExpectEqual(expected, GetAllocation(bitrate)); |
197 } | 239 } |
198 | 240 |
199 { | 241 { |
200 // Third maxed out. | 242 // Third maxed out. |
201 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + | 243 const uint32_t bitrate = codec_.simulcastStream[0].targetBitrate + |
202 codec_.simulcastStream[1].targetBitrate + | 244 codec_.simulcastStream[1].targetBitrate + |
203 codec_.simulcastStream[2].maxBitrate; | 245 codec_.simulcastStream[2].maxBitrate; |
204 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, | 246 uint32_t expected[] = {codec_.simulcastStream[0].targetBitrate, |
205 codec_.simulcastStream[1].targetBitrate, | 247 codec_.simulcastStream[1].targetBitrate, |
206 codec_.simulcastStream[2].maxBitrate}; | 248 codec_.simulcastStream[2].maxBitrate}; |
207 ExpectEqual(expected, allocator_->GetAllocation(bitrate)); | 249 ExpectEqual(expected, GetAllocation(bitrate)); |
208 } | 250 } |
209 } | 251 } |
210 | 252 |
211 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrate) { | 253 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateBps) { |
212 EXPECT_EQ(codec_.maxBitrate, allocator_->GetPreferedBitrate()); | 254 EXPECT_EQ(codec_.maxBitrate * 1000, |
| 255 allocator_->GetPreferredBitrateBps(codec_.maxFramerate)); |
213 } | 256 } |
214 | 257 |
215 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateSimulcast) { | 258 TEST_F(SimulcastRateAllocatorTest, GetPreferredBitrateSimulcast) { |
216 codec_.numberOfSimulcastStreams = 3; | 259 codec_.numberOfSimulcastStreams = 3; |
217 codec_.maxBitrate = 999999; | 260 codec_.maxBitrate = 999999; |
218 codec_.simulcastStream[0].minBitrate = 10; | 261 codec_.simulcastStream[0].minBitrate = 10; |
219 codec_.simulcastStream[0].targetBitrate = 100; | 262 codec_.simulcastStream[0].targetBitrate = 100; |
220 | 263 |
221 codec_.simulcastStream[0].maxBitrate = 500; | 264 codec_.simulcastStream[0].maxBitrate = 500; |
222 codec_.simulcastStream[1].minBitrate = 50; | 265 codec_.simulcastStream[1].minBitrate = 50; |
223 codec_.simulcastStream[1].targetBitrate = 500; | 266 codec_.simulcastStream[1].targetBitrate = 500; |
224 codec_.simulcastStream[1].maxBitrate = 1000; | 267 codec_.simulcastStream[1].maxBitrate = 1000; |
225 | 268 |
226 codec_.simulcastStream[2].minBitrate = 2000; | 269 codec_.simulcastStream[2].minBitrate = 2000; |
227 codec_.simulcastStream[2].targetBitrate = 3000; | 270 codec_.simulcastStream[2].targetBitrate = 3000; |
228 codec_.simulcastStream[2].maxBitrate = 4000; | 271 codec_.simulcastStream[2].maxBitrate = 4000; |
229 CreateAllocator(); | 272 CreateAllocator(); |
230 | 273 |
231 uint32_t preferred_bitrate; | 274 uint32_t preferred_bitrate_kbps; |
232 preferred_bitrate = codec_.simulcastStream[0].targetBitrate; | 275 preferred_bitrate_kbps = codec_.simulcastStream[0].targetBitrate; |
233 preferred_bitrate += codec_.simulcastStream[1].targetBitrate; | 276 preferred_bitrate_kbps += codec_.simulcastStream[1].targetBitrate; |
234 preferred_bitrate += codec_.simulcastStream[2].maxBitrate; | 277 preferred_bitrate_kbps += codec_.simulcastStream[2].maxBitrate; |
235 | 278 |
236 EXPECT_EQ(preferred_bitrate, allocator_->GetPreferedBitrate()); | 279 EXPECT_EQ(preferred_bitrate_kbps * 1000, |
| 280 allocator_->GetPreferredBitrateBps(codec_.maxFramerate)); |
| 281 } |
| 282 |
| 283 class ScreenshareRateAllocationTest : public SimulcastRateAllocatorTest { |
| 284 public: |
| 285 void SetupConferenceScreenshare(bool use_simulcast) { |
| 286 codec_.mode = VideoCodecMode::kScreensharing; |
| 287 codec_.minBitrate = kMinBitrateKbps; |
| 288 codec_.maxBitrate = kMaxBitrateKbps; |
| 289 if (use_simulcast) { |
| 290 codec_.numberOfSimulcastStreams = 1; |
| 291 codec_.simulcastStream[0].minBitrate = kMinBitrateKbps; |
| 292 codec_.simulcastStream[0].targetBitrate = kTargetBitrateKbps; |
| 293 codec_.simulcastStream[0].maxBitrate = kMaxBitrateKbps; |
| 294 codec_.simulcastStream[0].numberOfTemporalLayers = 2; |
| 295 } else { |
| 296 codec_.numberOfSimulcastStreams = 0; |
| 297 codec_.targetBitrate = kTargetBitrateKbps; |
| 298 codec_.VP8()->numberOfTemporalLayers = 2; |
| 299 } |
| 300 } |
| 301 |
| 302 std::unique_ptr<TemporalLayersFactory> GetTlFactory() override { |
| 303 return std::unique_ptr<TemporalLayersFactory>( |
| 304 new ScreenshareTemporalLayersFactory()); |
| 305 } |
| 306 }; |
| 307 |
| 308 INSTANTIATE_TEST_CASE_P(ScreenshareTest, |
| 309 ScreenshareRateAllocationTest, |
| 310 ::testing::Bool()); |
| 311 |
| 312 TEST_P(ScreenshareRateAllocationTest, BitrateBelowTl0) { |
| 313 SetupConferenceScreenshare(GetParam()); |
| 314 CreateAllocator(); |
| 315 |
| 316 BitrateAllocation allocation = |
| 317 allocator_->GetAllocation(kTargetBitrateKbps * 1000, kFramerateFps); |
| 318 |
| 319 // All allocation should go in TL0. |
| 320 EXPECT_EQ(kTargetBitrateKbps, allocation.get_sum_kbps()); |
| 321 EXPECT_EQ(kTargetBitrateKbps, allocation.GetBitrate(0, 0) / 1000); |
| 322 } |
| 323 |
| 324 TEST_P(ScreenshareRateAllocationTest, BitrateAboveTl0) { |
| 325 SetupConferenceScreenshare(GetParam()); |
| 326 CreateAllocator(); |
| 327 |
| 328 uint32_t target_bitrate_kbps = (kTargetBitrateKbps + kMaxBitrateKbps) / 2; |
| 329 BitrateAllocation allocation = |
| 330 allocator_->GetAllocation(target_bitrate_kbps * 1000, kFramerateFps); |
| 331 |
| 332 // Fill TL0, then put the rest in TL1. |
| 333 EXPECT_EQ(target_bitrate_kbps, allocation.get_sum_kbps()); |
| 334 EXPECT_EQ(kTargetBitrateKbps, allocation.GetBitrate(0, 0) / 1000); |
| 335 EXPECT_EQ(target_bitrate_kbps - kTargetBitrateKbps, |
| 336 allocation.GetBitrate(0, 1) / 1000); |
| 337 } |
| 338 |
| 339 TEST_P(ScreenshareRateAllocationTest, BitrateAboveTl1) { |
| 340 SetupConferenceScreenshare(GetParam()); |
| 341 CreateAllocator(); |
| 342 |
| 343 BitrateAllocation allocation = |
| 344 allocator_->GetAllocation(kMaxBitrateKbps * 2000, kFramerateFps); |
| 345 |
| 346 // Fill both TL0 and TL1, but no more. |
| 347 EXPECT_EQ(kMaxBitrateKbps, allocation.get_sum_kbps()); |
| 348 EXPECT_EQ(kTargetBitrateKbps, allocation.GetBitrate(0, 0) / 1000); |
| 349 EXPECT_EQ(kMaxBitrateKbps - kTargetBitrateKbps, |
| 350 allocation.GetBitrate(0, 1) / 1000); |
237 } | 351 } |
238 | 352 |
239 } // namespace webrtc | 353 } // namespace webrtc |
OLD | NEW |