| OLD | NEW |
| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const int kStartBitrateBps = 200000; | 85 const int kStartBitrateBps = 200000; |
| 86 const int kMaxBitrateBps = 300000; | 86 const int kMaxBitrateBps = 300000; |
| 87 | 87 |
| 88 const int kDefaultMinBitrateBps = 10000; | 88 const int kDefaultMinBitrateBps = 10000; |
| 89 const int kDefaultMaxBitrateBps = 1000000000; | 89 const int kDefaultMaxBitrateBps = 1000000000; |
| 90 | 90 |
| 91 webrtc::SimulatedClock clock_; | 91 webrtc::SimulatedClock clock_; |
| 92 TestBitrateObserver bitrate_observer_; | 92 TestBitrateObserver bitrate_observer_; |
| 93 BitrateController* controller_; | 93 BitrateController* controller_; |
| 94 RtcpBandwidthObserver* bandwidth_observer_; | 94 RtcpBandwidthObserver* bandwidth_observer_; |
| 95 webrtc::MockRtcEventLog event_log_; | 95 testing::NiceMock<webrtc::MockRtcEventLog> event_log_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { | 98 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { |
| 99 // Receive successively lower REMBs, verify the reserved bitrate is deducted. | 99 // Receive successively lower REMBs, verify the reserved bitrate is deducted. |
| 100 controller_->SetMinMaxBitrate(0, 0); | 100 controller_->SetMinMaxBitrate(0, 0); |
| 101 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); | 101 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
| 102 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); | 102 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); |
| 103 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_); | 103 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_); |
| 104 bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps); | 104 bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps); |
| 105 clock_.AdvanceTimeMilliseconds(1000); | 105 clock_.AdvanceTimeMilliseconds(1000); |
| 106 controller_->Process(); | 106 controller_->Process(); |
| 107 EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_); | 107 EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) { | 110 TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) { |
| 111 // First REMB applies immediately. | 111 // First REMB applies immediately. |
| 112 EXPECT_CALL(event_log_, LogBwePacketLossEvent(testing::Gt(0), 0, 0)).Times(8); | |
| 113 int64_t time_ms = 1001; | 112 int64_t time_ms = 1001; |
| 114 webrtc::ReportBlockList report_blocks; | 113 webrtc::ReportBlockList report_blocks; |
| 115 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); | 114 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); |
| 116 bandwidth_observer_->OnReceivedEstimatedBitrate(200000); | 115 bandwidth_observer_->OnReceivedEstimatedBitrate(200000); |
| 117 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); | 116 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
| 118 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); | 117 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 119 EXPECT_EQ(0, bitrate_observer_.last_rtt_); | 118 EXPECT_EQ(0, bitrate_observer_.last_rtt_); |
| 120 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); | 119 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
| 121 report_blocks.clear(); | 120 report_blocks.clear(); |
| 122 time_ms += 2000; | 121 time_ms += 2000; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); | 178 EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); |
| 180 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); | 179 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 181 EXPECT_EQ(50, bitrate_observer_.last_rtt_); | 180 EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
| 182 | 181 |
| 183 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); | 182 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); |
| 184 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 183 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
| 185 } | 184 } |
| 186 | 185 |
| 187 TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) { | 186 TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) { |
| 188 // REMBs during the first 2 seconds apply immediately. | 187 // REMBs during the first 2 seconds apply immediately. |
| 189 EXPECT_CALL(event_log_, LogBwePacketLossEvent(testing::Gt(0), 0, 0)).Times(9); | |
| 190 int64_t time_ms = 1; | 188 int64_t time_ms = 1; |
| 191 webrtc::ReportBlockList report_blocks; | 189 webrtc::ReportBlockList report_blocks; |
| 192 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); | 190 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); |
| 193 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); | 191 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
| 194 report_blocks.clear(); | 192 report_blocks.clear(); |
| 195 time_ms += 500; | 193 time_ms += 500; |
| 196 | 194 |
| 197 RtcpBandwidthObserver* second_bandwidth_observer = | 195 RtcpBandwidthObserver* second_bandwidth_observer = |
| 198 controller_->CreateRtcpBandwidthObserver(); | 196 controller_->CreateRtcpBandwidthObserver(); |
| 199 | 197 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); | 273 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 276 EXPECT_EQ(50, bitrate_observer_.last_rtt_); | 274 EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
| 277 | 275 |
| 278 // Min cap. | 276 // Min cap. |
| 279 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); | 277 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); |
| 280 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 278 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
| 281 delete second_bandwidth_observer; | 279 delete second_bandwidth_observer; |
| 282 } | 280 } |
| 283 | 281 |
| 284 TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) { | 282 TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) { |
| 285 testing::Expectation first_calls = | |
| 286 EXPECT_CALL(event_log_, LogBwePacketLossEvent(testing::Gt(0), 0, 0)) | |
| 287 .Times(7); | |
| 288 EXPECT_CALL(event_log_, | |
| 289 LogBwePacketLossEvent(testing::Gt(0), testing::Gt(0), 0)) | |
| 290 .Times(2) | |
| 291 .After(first_calls); | |
| 292 uint32_t sequence_number[2] = {0, 0xFF00}; | 283 uint32_t sequence_number[2] = {0, 0xFF00}; |
| 293 const int kStartBitrate = 200000; | 284 const int kStartBitrate = 200000; |
| 294 const int kMinBitrate = 100000; | 285 const int kMinBitrate = 100000; |
| 295 const int kMaxBitrate = 300000; | 286 const int kMaxBitrate = 300000; |
| 296 controller_->SetStartBitrate(kStartBitrate); | 287 controller_->SetStartBitrate(kStartBitrate); |
| 297 controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate); | 288 controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate); |
| 298 | 289 |
| 299 // REMBs during the first 2 seconds apply immediately. | 290 // REMBs during the first 2 seconds apply immediately. |
| 300 int64_t time_ms = 1001; | 291 int64_t time_ms = 1001; |
| 301 webrtc::ReportBlockList report_blocks; | 292 webrtc::ReportBlockList report_blocks; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); | 399 EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); |
| 409 controller_->SetReservedBitrate(50000); | 400 controller_->SetReservedBitrate(50000); |
| 410 bandwidth_observer_->OnReceivedEstimatedBitrate(120000); | 401 bandwidth_observer_->OnReceivedEstimatedBitrate(120000); |
| 411 // Limited by min bitrate. | 402 // Limited by min bitrate. |
| 412 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 403 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
| 413 | 404 |
| 414 controller_->SetReservedBitrate(10000); | 405 controller_->SetReservedBitrate(10000); |
| 415 bandwidth_observer_->OnReceivedEstimatedBitrate(1); | 406 bandwidth_observer_->OnReceivedEstimatedBitrate(1); |
| 416 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 407 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
| 417 } | 408 } |
| OLD | NEW |