Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Side by Side Diff: webrtc/call/bitrate_allocator_unittest.cc

Issue 2705603002: Fixes a bug where a video stream can get stuck in the suspended state. (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 allocator_->OnNetworkChanged(4000000, 0, 0, kDefaultProbingIntervalMs); 91 allocator_->OnNetworkChanged(4000000, 0, 0, kDefaultProbingIntervalMs);
92 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer)); 92 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer));
93 93
94 // Expect |max_padding_bitrate_bps| to change to 0 if the observer is updated. 94 // Expect |max_padding_bitrate_bps| to change to 0 if the observer is updated.
95 EXPECT_CALL(limit_observer_, 95 EXPECT_CALL(limit_observer_,
96 OnAllocationLimitsChanged(kMinSendBitrateBps, 0)); 96 OnAllocationLimitsChanged(kMinSendBitrateBps, 0));
97 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 4000000, 0, 97 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 4000000, 0,
98 true); 98 true);
99 EXPECT_EQ(4000000, allocator_->GetStartBitrate(&bitrate_observer)); 99 EXPECT_EQ(4000000, allocator_->GetStartBitrate(&bitrate_observer));
100 100
101 EXPECT_CALL(limit_observer_,
102 OnAllocationLimitsChanged(kMinSendBitrateBps, 0));
103 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, 0, 101 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, 0,
104 true); 102 true);
105 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer)); 103 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer));
106 EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_bps_); 104 EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_bps_);
107 allocator_->OnNetworkChanged(1500000, 0, 0, kDefaultProbingIntervalMs); 105 allocator_->OnNetworkChanged(1500000, 0, 0, kDefaultProbingIntervalMs);
108 EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_bps_); 106 EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_bps_);
109 } 107 }
110 108
111 TEST_F(BitrateAllocatorTest, TwoBitrateObserversOneRtcpObserver) { 109 TEST_F(BitrateAllocatorTest, TwoBitrateObserversOneRtcpObserver) {
112 TestBitrateObserver bitrate_observer_1; 110 TestBitrateObserver bitrate_observer_1;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 NiceMock<MockLimitObserver> limit_observer_; 174 NiceMock<MockLimitObserver> limit_observer_;
177 std::unique_ptr<BitrateAllocator> allocator_; 175 std::unique_ptr<BitrateAllocator> allocator_;
178 }; 176 };
179 177
180 // The following three tests verify enforcing a minimum bitrate works as 178 // The following three tests verify enforcing a minimum bitrate works as
181 // intended. 179 // intended.
182 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) { 180 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) {
183 TestBitrateObserver bitrate_observer_1; 181 TestBitrateObserver bitrate_observer_1;
184 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since 182 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since
185 // AddObserver is called with |enforce_min_bitrate| = false. 183 // AddObserver is called with |enforce_min_bitrate| = false.
186 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); 184 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 120000));
187 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); 185 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false);
188 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); 186 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1));
189 187
190 // High BWE. 188 // High BWE.
191 allocator_->OnNetworkChanged(150000, 0, 0, kDefaultProbingIntervalMs); 189 allocator_->OnNetworkChanged(150000, 0, 0, kDefaultProbingIntervalMs);
192 EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_bps_); 190 EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_bps_);
193 191
194 // Low BWE. 192 // Low BWE.
195 allocator_->OnNetworkChanged(10000, 0, 0, kDefaultProbingIntervalMs); 193 allocator_->OnNetworkChanged(10000, 0, 0, kDefaultProbingIntervalMs);
196 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); 194 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 255
258 allocator_->RemoveObserver(&bitrate_observer_1); 256 allocator_->RemoveObserver(&bitrate_observer_1);
259 allocator_->RemoveObserver(&bitrate_observer_2); 257 allocator_->RemoveObserver(&bitrate_observer_2);
260 allocator_->RemoveObserver(&bitrate_observer_3); 258 allocator_->RemoveObserver(&bitrate_observer_3);
261 } 259 }
262 260
263 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserverWithPacketLoss) { 261 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserverWithPacketLoss) {
264 TestBitrateObserver bitrate_observer; 262 TestBitrateObserver bitrate_observer;
265 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since 263 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since
266 // AddObserver is called with |enforce_min_bitrate| = false. 264 // AddObserver is called with |enforce_min_bitrate| = false.
267 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); 265 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 168000));
268 allocator_->AddObserver( 266 allocator_->AddObserver(
269 &bitrate_observer, 100000, 400000, 0, false); 267 &bitrate_observer, 100000, 400000, 0, false);
270 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer)); 268 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer));
271 269
272 // High BWE. 270 // High BWE.
273 allocator_->OnNetworkChanged(150000, 0, 0, kDefaultProbingIntervalMs); 271 allocator_->OnNetworkChanged(150000, 0, 0, kDefaultProbingIntervalMs);
274 EXPECT_EQ(150000u, bitrate_observer.last_bitrate_bps_); 272 EXPECT_EQ(150000u, bitrate_observer.last_bitrate_bps_);
275 273
276 // Add loss and use a part of the bitrate for protection. 274 // Add loss and use a part of the bitrate for protection.
277 double protection_ratio = 0.4; 275 double protection_ratio = 0.4;
278 uint8_t fraction_loss = protection_ratio * 256; 276 uint8_t fraction_loss = protection_ratio * 256;
279 bitrate_observer.SetBitrateProtectionRatio(protection_ratio); 277 bitrate_observer.SetBitrateProtectionRatio(protection_ratio);
280 allocator_->OnNetworkChanged(200000, 0, fraction_loss, 278 allocator_->OnNetworkChanged(200000, 0, fraction_loss,
281 kDefaultProbingIntervalMs); 279 kDefaultProbingIntervalMs);
282 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_bps_); 280 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_bps_);
283 281
284 // Above the min threshold, but not enough given the protection used. 282 // Above the min threshold, but not enough given the protection used.
285 allocator_->OnNetworkChanged(139000, 0, fraction_loss, 283 allocator_->OnNetworkChanged(139000, 0, fraction_loss,
286 kDefaultProbingIntervalMs); 284 kDefaultProbingIntervalMs);
287 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_); 285 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_);
288 286
289 // Verify the hysteresis is added for the protection. 287 // Verify the hysteresis is added for the protection.
290 allocator_->OnNetworkChanged(150000, 0, fraction_loss, 288 allocator_->OnNetworkChanged(150000, 0, fraction_loss,
291 kDefaultProbingIntervalMs); 289 kDefaultProbingIntervalMs);
292 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_); 290 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_);
293 291
294 // Just enough to enable video again. 292 // Just enough to enable video again.
293 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0));
295 allocator_->OnNetworkChanged(168000, 0, fraction_loss, 294 allocator_->OnNetworkChanged(168000, 0, fraction_loss,
296 kDefaultProbingIntervalMs); 295 kDefaultProbingIntervalMs);
297 EXPECT_EQ(168000u, bitrate_observer.last_bitrate_bps_); 296 EXPECT_EQ(168000u, bitrate_observer.last_bitrate_bps_);
298 297
299 // Remove all protection and make sure video is not paused as earlier. 298 // Remove all protection and make sure video is not paused as earlier.
300 bitrate_observer.SetBitrateProtectionRatio(0.0); 299 bitrate_observer.SetBitrateProtectionRatio(0.0);
301 allocator_->OnNetworkChanged(140000, 0, 0, kDefaultProbingIntervalMs); 300 allocator_->OnNetworkChanged(140000, 0, 0, kDefaultProbingIntervalMs);
302 EXPECT_EQ(140000u, bitrate_observer.last_bitrate_bps_); 301 EXPECT_EQ(140000u, bitrate_observer.last_bitrate_bps_);
303 302
304 allocator_->OnNetworkChanged(139000, 0, 0, kDefaultProbingIntervalMs); 303 allocator_->OnNetworkChanged(139000, 0, 0, kDefaultProbingIntervalMs);
305 EXPECT_EQ(139000u, bitrate_observer.last_bitrate_bps_); 304 EXPECT_EQ(139000u, bitrate_observer.last_bitrate_bps_);
306 305
307 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0));
308 allocator_->RemoveObserver(&bitrate_observer); 306 allocator_->RemoveObserver(&bitrate_observer);
309 } 307 }
310 308
311 TEST_F(BitrateAllocatorTestNoEnforceMin, TwoBitrateObserverWithPacketLoss) { 309 TEST_F(BitrateAllocatorTestNoEnforceMin, TwoBitrateObserverWithPacketLoss) {
312 TestBitrateObserver bitrate_observer_1; 310 TestBitrateObserver bitrate_observer_1;
313 TestBitrateObserver bitrate_observer_2; 311 TestBitrateObserver bitrate_observer_2;
314 312
315 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); 313 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false);
316 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); 314 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1));
317 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, false); 315 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, false);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 allocator_->AddObserver(&observer, 300000, 600000, 0, false); 513 allocator_->AddObserver(&observer, 300000, 600000, 0, false);
516 EXPECT_EQ(300000, allocator_->GetStartBitrate(&observer)); 514 EXPECT_EQ(300000, allocator_->GetStartBitrate(&observer));
517 515
518 allocator_->OnNetworkChanged(300000, 0, 50, 5000); 516 allocator_->OnNetworkChanged(300000, 0, 50, 5000);
519 EXPECT_EQ(5000, observer.last_probing_interval_ms_); 517 EXPECT_EQ(5000, observer.last_probing_interval_ms_);
520 518
521 allocator_->RemoveObserver(&observer); 519 allocator_->RemoveObserver(&observer);
522 } 520 }
523 521
524 } // namespace webrtc 522 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698