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