OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 #include <memory> | 10 #include <memory> |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 constexpr int kMinBitrateBps = 100; | 29 constexpr int kMinBitrateBps = 100; |
30 constexpr int kStartBitrateBps = 300; | 30 constexpr int kStartBitrateBps = 300; |
31 constexpr int kMaxBitrateBps = 10000; | 31 constexpr int kMaxBitrateBps = 10000; |
32 | 32 |
33 constexpr int kExponentialProbingTimeoutMs = 5000; | 33 constexpr int kExponentialProbingTimeoutMs = 5000; |
34 | 34 |
35 constexpr int kAlrProbeInterval = 5000; | 35 constexpr int kAlrProbeInterval = 5000; |
| 36 constexpr int kAlrEndedTimeoutMs = 3000; |
| 37 constexpr int kBitrateDropTimeoutMs = 5000; |
36 | 38 |
37 } // namespace | 39 } // namespace |
38 | 40 |
39 class ProbeControllerTest : public ::testing::Test { | 41 class ProbeControllerTest : public ::testing::Test { |
40 protected: | 42 protected: |
41 ProbeControllerTest() : clock_(100000000L) { | 43 ProbeControllerTest() : clock_(100000000L) { |
42 probe_controller_.reset(new ProbeController(&pacer_, &clock_)); | 44 probe_controller_.reset(new ProbeController(&pacer_, &clock_)); |
43 } | 45 } |
44 ~ProbeControllerTest() override {} | 46 ~ProbeControllerTest() override {} |
45 | 47 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 kMaxBitrateBps); | 115 kMaxBitrateBps); |
114 | 116 |
115 // Advance far enough to cause a time out in waiting for probing result. | 117 // Advance far enough to cause a time out in waiting for probing result. |
116 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); | 118 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
117 probe_controller_->Process(); | 119 probe_controller_->Process(); |
118 | 120 |
119 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); | 121 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
120 probe_controller_->SetEstimatedBitrate(1800); | 122 probe_controller_->SetEstimatedBitrate(1800); |
121 } | 123 } |
122 | 124 |
123 TEST_F(ProbeControllerTest, ProbeAfterEstimateDropInAlr) { | 125 TEST_F(ProbeControllerTest, RequestProbeInAlr) { |
124 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); | 126 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
125 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 127 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
126 kMaxBitrateBps); | 128 kMaxBitrateBps); |
127 probe_controller_->SetEstimatedBitrate(500); | 129 probe_controller_->SetEstimatedBitrate(500); |
128 testing::Mock::VerifyAndClearExpectations(&pacer_); | 130 testing::Mock::VerifyAndClearExpectations(&pacer_); |
129 | 131 EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
130 // When bandwidth estimate drops the controller should send a probe at the | |
131 // previous bitrate. | |
132 EXPECT_CALL(pacer_, CreateProbeCluster(500)).Times(1); | |
133 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) | 132 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
134 .WillRepeatedly( | 133 .WillRepeatedly( |
135 Return(rtc::Optional<int64_t>(clock_.TimeInMilliseconds()))); | 134 Return(rtc::Optional<int64_t>(clock_.TimeInMilliseconds()))); |
136 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); | 135 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
137 probe_controller_->Process(); | 136 probe_controller_->Process(); |
138 probe_controller_->SetEstimatedBitrate(50); | 137 probe_controller_->SetEstimatedBitrate(250); |
| 138 probe_controller_->RequestProbe(); |
| 139 } |
| 140 |
| 141 TEST_F(ProbeControllerTest, RequestProbeWhenAlrEndedRecently) { |
| 142 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
| 143 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 144 kMaxBitrateBps); |
| 145 probe_controller_->SetEstimatedBitrate(500); |
| 146 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 147 EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); |
| 148 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 149 .WillRepeatedly(Return(rtc::Optional<int64_t>())); |
| 150 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
| 151 probe_controller_->Process(); |
| 152 probe_controller_->SetEstimatedBitrate(250); |
| 153 probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 154 clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs - 1); |
| 155 probe_controller_->RequestProbe(); |
| 156 } |
| 157 |
| 158 TEST_F(ProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) { |
| 159 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
| 160 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 161 kMaxBitrateBps); |
| 162 probe_controller_->SetEstimatedBitrate(500); |
| 163 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 164 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 165 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 166 .WillRepeatedly(Return(rtc::Optional<int64_t>())); |
| 167 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
| 168 probe_controller_->Process(); |
| 169 probe_controller_->SetEstimatedBitrate(250); |
| 170 probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds()); |
| 171 clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs + 1); |
| 172 probe_controller_->RequestProbe(); |
| 173 } |
| 174 |
| 175 TEST_F(ProbeControllerTest, RequestProbeWhenBweDropNotRecent) { |
| 176 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
| 177 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
| 178 kMaxBitrateBps); |
| 179 probe_controller_->SetEstimatedBitrate(500); |
| 180 testing::Mock::VerifyAndClearExpectations(&pacer_); |
| 181 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
| 182 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
| 183 .WillRepeatedly( |
| 184 Return(rtc::Optional<int64_t>(clock_.TimeInMilliseconds()))); |
| 185 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
| 186 probe_controller_->Process(); |
| 187 probe_controller_->SetEstimatedBitrate(250); |
| 188 clock_.AdvanceTimeMilliseconds(kBitrateDropTimeoutMs + 1); |
| 189 probe_controller_->RequestProbe(); |
139 } | 190 } |
140 | 191 |
141 TEST_F(ProbeControllerTest, PeriodicProbing) { | 192 TEST_F(ProbeControllerTest, PeriodicProbing) { |
142 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); | 193 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
143 probe_controller_->EnablePeriodicAlrProbing(true); | 194 probe_controller_->EnablePeriodicAlrProbing(true); |
144 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 195 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
145 kMaxBitrateBps); | 196 kMaxBitrateBps); |
146 probe_controller_->SetEstimatedBitrate(500); | 197 probe_controller_->SetEstimatedBitrate(500); |
147 testing::Mock::VerifyAndClearExpectations(&pacer_); | 198 testing::Mock::VerifyAndClearExpectations(&pacer_); |
148 | 199 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier); | 264 probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier); |
214 testing::Mock::VerifyAndClearExpectations(&pacer_); | 265 testing::Mock::VerifyAndClearExpectations(&pacer_); |
215 | 266 |
216 // Verify that repeated probes aren't sent. | 267 // Verify that repeated probes aren't sent. |
217 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); | 268 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
218 probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier); | 269 probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier); |
219 } | 270 } |
220 | 271 |
221 } // namespace test | 272 } // namespace test |
222 } // namespace webrtc | 273 } // namespace webrtc |
OLD | NEW |