| 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 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 17 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" |
| 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 18 | 19 |
| 20 using ::testing::Exactly; |
| 21 using ::testing::Return; |
| 22 |
| 23 using webrtc::BitrateController; |
| 24 using webrtc::BitrateObserver; |
| 25 using webrtc::PacedSender; |
| 19 using webrtc::RtcpBandwidthObserver; | 26 using webrtc::RtcpBandwidthObserver; |
| 20 using webrtc::BitrateObserver; | |
| 21 using webrtc::BitrateController; | |
| 22 | 27 |
| 23 uint8_t WeightedLoss(int num_packets1, uint8_t fraction_loss1, | 28 uint8_t WeightedLoss(int num_packets1, uint8_t fraction_loss1, |
| 24 int num_packets2, uint8_t fraction_loss2) { | 29 int num_packets2, uint8_t fraction_loss2) { |
| 25 int weighted_sum = num_packets1 * fraction_loss1 + | 30 int weighted_sum = num_packets1 * fraction_loss1 + |
| 26 num_packets2 * fraction_loss2; | 31 num_packets2 * fraction_loss2; |
| 27 int total_num_packets = num_packets1 + num_packets2; | 32 int total_num_packets = num_packets1 + num_packets2; |
| 28 return (weighted_sum + total_num_packets / 2) / total_num_packets; | 33 return (weighted_sum + total_num_packets / 2) / total_num_packets; |
| 29 } | 34 } |
| 30 | 35 |
| 31 webrtc::RTCPReportBlock CreateReportBlock( | 36 webrtc::RTCPReportBlock CreateReportBlock( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 54 uint8_t last_fraction_loss_; | 59 uint8_t last_fraction_loss_; |
| 55 int64_t last_rtt_; | 60 int64_t last_rtt_; |
| 56 }; | 61 }; |
| 57 | 62 |
| 58 class BitrateControllerTest : public ::testing::Test { | 63 class BitrateControllerTest : public ::testing::Test { |
| 59 protected: | 64 protected: |
| 60 BitrateControllerTest() : clock_(0) {} | 65 BitrateControllerTest() : clock_(0) {} |
| 61 ~BitrateControllerTest() {} | 66 ~BitrateControllerTest() {} |
| 62 | 67 |
| 63 virtual void SetUp() { | 68 virtual void SetUp() { |
| 64 controller_ = | 69 controller_ = BitrateController::CreateBitrateController( |
| 65 BitrateController::CreateBitrateController(&clock_, &bitrate_observer_); | 70 &clock_, &bitrate_observer_, &pacer_); |
| 66 controller_->SetStartBitrate(kStartBitrateBps); | 71 controller_->SetStartBitrate(kStartBitrateBps); |
| 67 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); | 72 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
| 68 controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); | 73 controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); |
| 69 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); | 74 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
| 70 bandwidth_observer_ = controller_->CreateRtcpBandwidthObserver(); | 75 bandwidth_observer_ = controller_->CreateRtcpBandwidthObserver(); |
| 71 } | 76 } |
| 72 | 77 |
| 73 virtual void TearDown() { | 78 virtual void TearDown() { |
| 74 delete bandwidth_observer_; | 79 delete bandwidth_observer_; |
| 75 delete controller_; | 80 delete controller_; |
| 76 } | 81 } |
| 77 | 82 |
| 78 const int kMinBitrateBps = 100000; | 83 const int kMinBitrateBps = 100000; |
| 79 const int kStartBitrateBps = 200000; | 84 const int kStartBitrateBps = 200000; |
| 80 const int kMaxBitrateBps = 300000; | 85 const int kMaxBitrateBps = 300000; |
| 81 | 86 |
| 82 const int kDefaultMinBitrateBps = 10000; | 87 const int kDefaultMinBitrateBps = 10000; |
| 83 const int kDefaultMaxBitrateBps = 1000000000; | 88 const int kDefaultMaxBitrateBps = 1000000000; |
| 84 | 89 |
| 85 webrtc::SimulatedClock clock_; | 90 webrtc::SimulatedClock clock_; |
| 86 TestBitrateObserver bitrate_observer_; | 91 TestBitrateObserver bitrate_observer_; |
| 92 testing::NiceMock<webrtc::MockPacedSender> pacer_; |
| 87 BitrateController* controller_; | 93 BitrateController* controller_; |
| 88 RtcpBandwidthObserver* bandwidth_observer_; | 94 RtcpBandwidthObserver* bandwidth_observer_; |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { | 97 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { |
| 92 // Receive successively lower REMBs, verify the reserved bitrate is deducted. | 98 // Receive successively lower REMBs, verify the reserved bitrate is deducted. |
| 93 controller_->SetMinMaxBitrate(0, 0); | 99 controller_->SetMinMaxBitrate(0, 0); |
| 94 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); | 100 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
| 95 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); | 101 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); |
| 96 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_); | 102 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); | 398 EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); |
| 393 controller_->SetReservedBitrate(50000); | 399 controller_->SetReservedBitrate(50000); |
| 394 bandwidth_observer_->OnReceivedEstimatedBitrate(120000); | 400 bandwidth_observer_->OnReceivedEstimatedBitrate(120000); |
| 395 // Limited by min bitrate. | 401 // Limited by min bitrate. |
| 396 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 402 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
| 397 | 403 |
| 398 controller_->SetReservedBitrate(10000); | 404 controller_->SetReservedBitrate(10000); |
| 399 bandwidth_observer_->OnReceivedEstimatedBitrate(1); | 405 bandwidth_observer_->OnReceivedEstimatedBitrate(1); |
| 400 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 406 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
| 401 } | 407 } |
| 408 |
| 409 TEST_F(BitrateControllerTest, OnSendQueueFull) { |
| 410 bandwidth_observer_->OnReceivedEstimatedBitrate(200000); |
| 411 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
| 412 // Let the pacer be full next time the controller checks. |
| 413 EXPECT_CALL(pacer_, ExpectedQueueTimeMs()) |
| 414 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); |
| 415 clock_.AdvanceTimeMilliseconds(25); |
| 416 controller_->Process(); |
| 417 EXPECT_EQ(0, bitrate_observer_.last_bitrate_); |
| 418 // Let the pacer not be full next time the controller checks. |
| 419 EXPECT_CALL(pacer_, ExpectedQueueTimeMs()) |
| 420 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
| 421 clock_.AdvanceTimeMilliseconds(25); |
| 422 controller_->Process(); |
| 423 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
| 424 } |
| OLD | NEW |