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/call/mock/mock_rtc_event_log.h" | |
17 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
18 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" | 17 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" |
19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
20 | 19 |
21 using ::testing::Exactly; | 20 using ::testing::Exactly; |
22 using ::testing::Return; | 21 using ::testing::Return; |
23 | 22 |
24 using webrtc::BitrateController; | 23 using webrtc::BitrateController; |
25 using webrtc::BitrateObserver; | 24 using webrtc::BitrateObserver; |
26 using webrtc::PacedSender; | 25 using webrtc::PacedSender; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 uint8_t last_fraction_loss_; | 59 uint8_t last_fraction_loss_; |
61 int64_t last_rtt_; | 60 int64_t last_rtt_; |
62 }; | 61 }; |
63 | 62 |
64 class BitrateControllerTest : public ::testing::Test { | 63 class BitrateControllerTest : public ::testing::Test { |
65 protected: | 64 protected: |
66 BitrateControllerTest() : clock_(0) {} | 65 BitrateControllerTest() : clock_(0) {} |
67 ~BitrateControllerTest() {} | 66 ~BitrateControllerTest() {} |
68 | 67 |
69 virtual void SetUp() { | 68 virtual void SetUp() { |
70 controller_ = BitrateController::CreateBitrateController( | 69 controller_ = |
71 &clock_, &bitrate_observer_, &event_log_); | 70 BitrateController::CreateBitrateController(&clock_, &bitrate_observer_); |
72 controller_->SetStartBitrate(kStartBitrateBps); | 71 controller_->SetStartBitrate(kStartBitrateBps); |
73 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); | 72 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
74 controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); | 73 controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); |
75 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); | 74 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
76 bandwidth_observer_ = controller_->CreateRtcpBandwidthObserver(); | 75 bandwidth_observer_ = controller_->CreateRtcpBandwidthObserver(); |
77 } | 76 } |
78 | 77 |
79 virtual void TearDown() { | 78 virtual void TearDown() { |
80 delete bandwidth_observer_; | 79 delete bandwidth_observer_; |
81 delete controller_; | 80 delete controller_; |
82 } | 81 } |
83 | 82 |
84 const int kMinBitrateBps = 100000; | 83 const int kMinBitrateBps = 100000; |
85 const int kStartBitrateBps = 200000; | 84 const int kStartBitrateBps = 200000; |
86 const int kMaxBitrateBps = 300000; | 85 const int kMaxBitrateBps = 300000; |
87 | 86 |
88 const int kDefaultMinBitrateBps = 10000; | 87 const int kDefaultMinBitrateBps = 10000; |
89 const int kDefaultMaxBitrateBps = 1000000000; | 88 const int kDefaultMaxBitrateBps = 1000000000; |
90 | 89 |
91 webrtc::SimulatedClock clock_; | 90 webrtc::SimulatedClock clock_; |
92 TestBitrateObserver bitrate_observer_; | 91 TestBitrateObserver bitrate_observer_; |
93 BitrateController* controller_; | 92 BitrateController* controller_; |
94 RtcpBandwidthObserver* bandwidth_observer_; | 93 RtcpBandwidthObserver* bandwidth_observer_; |
95 webrtc::MockRtcEventLog event_log_; | |
96 }; | 94 }; |
97 | 95 |
98 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { | 96 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { |
99 // Receive successively lower REMBs, verify the reserved bitrate is deducted. | 97 // Receive successively lower REMBs, verify the reserved bitrate is deducted. |
100 controller_->SetMinMaxBitrate(0, 0); | 98 controller_->SetMinMaxBitrate(0, 0); |
101 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); | 99 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
102 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); | 100 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); |
103 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_); | 101 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_); |
104 bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps); | 102 bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps); |
105 clock_.AdvanceTimeMilliseconds(1000); | 103 clock_.AdvanceTimeMilliseconds(1000); |
106 controller_->Process(); | 104 controller_->Process(); |
107 EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_); | 105 EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_); |
108 } | 106 } |
109 | 107 |
110 TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) { | 108 TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) { |
111 // First REMB applies immediately. | 109 // First REMB applies immediately. |
112 EXPECT_CALL(event_log_, LogBwePacketLossEvent(testing::Gt(0), 0, 0)).Times(8); | |
113 int64_t time_ms = 1001; | 110 int64_t time_ms = 1001; |
114 webrtc::ReportBlockList report_blocks; | 111 webrtc::ReportBlockList report_blocks; |
115 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); | 112 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); |
116 bandwidth_observer_->OnReceivedEstimatedBitrate(200000); | 113 bandwidth_observer_->OnReceivedEstimatedBitrate(200000); |
117 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); | 114 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
118 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); | 115 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
119 EXPECT_EQ(0, bitrate_observer_.last_rtt_); | 116 EXPECT_EQ(0, bitrate_observer_.last_rtt_); |
120 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); | 117 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
121 report_blocks.clear(); | 118 report_blocks.clear(); |
122 time_ms += 2000; | 119 time_ms += 2000; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); | 176 EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); |
180 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); | 177 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
181 EXPECT_EQ(50, bitrate_observer_.last_rtt_); | 178 EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
182 | 179 |
183 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); | 180 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); |
184 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 181 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
185 } | 182 } |
186 | 183 |
187 TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) { | 184 TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) { |
188 // REMBs during the first 2 seconds apply immediately. | 185 // 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; | 186 int64_t time_ms = 1; |
191 webrtc::ReportBlockList report_blocks; | 187 webrtc::ReportBlockList report_blocks; |
192 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); | 188 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); |
193 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); | 189 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
194 report_blocks.clear(); | 190 report_blocks.clear(); |
195 time_ms += 500; | 191 time_ms += 500; |
196 | 192 |
197 RtcpBandwidthObserver* second_bandwidth_observer = | 193 RtcpBandwidthObserver* second_bandwidth_observer = |
198 controller_->CreateRtcpBandwidthObserver(); | 194 controller_->CreateRtcpBandwidthObserver(); |
199 | 195 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); | 271 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
276 EXPECT_EQ(50, bitrate_observer_.last_rtt_); | 272 EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
277 | 273 |
278 // Min cap. | 274 // Min cap. |
279 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); | 275 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); |
280 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 276 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
281 delete second_bandwidth_observer; | 277 delete second_bandwidth_observer; |
282 } | 278 } |
283 | 279 |
284 TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) { | 280 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}; | 281 uint32_t sequence_number[2] = {0, 0xFF00}; |
293 const int kStartBitrate = 200000; | 282 const int kStartBitrate = 200000; |
294 const int kMinBitrate = 100000; | 283 const int kMinBitrate = 100000; |
295 const int kMaxBitrate = 300000; | 284 const int kMaxBitrate = 300000; |
296 controller_->SetStartBitrate(kStartBitrate); | 285 controller_->SetStartBitrate(kStartBitrate); |
297 controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate); | 286 controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate); |
298 | 287 |
299 // REMBs during the first 2 seconds apply immediately. | 288 // REMBs during the first 2 seconds apply immediately. |
300 int64_t time_ms = 1001; | 289 int64_t time_ms = 1001; |
301 webrtc::ReportBlockList report_blocks; | 290 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_); | 397 EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); |
409 controller_->SetReservedBitrate(50000); | 398 controller_->SetReservedBitrate(50000); |
410 bandwidth_observer_->OnReceivedEstimatedBitrate(120000); | 399 bandwidth_observer_->OnReceivedEstimatedBitrate(120000); |
411 // Limited by min bitrate. | 400 // Limited by min bitrate. |
412 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 401 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
413 | 402 |
414 controller_->SetReservedBitrate(10000); | 403 controller_->SetReservedBitrate(10000); |
415 bandwidth_observer_->OnReceivedEstimatedBitrate(1); | 404 bandwidth_observer_->OnReceivedEstimatedBitrate(1); |
416 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); | 405 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
417 } | 406 } |
OLD | NEW |