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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 probe_controller_.reset(new ProbeController(&pacer_, &clock_)); | 42 probe_controller_.reset(new ProbeController(&pacer_, &clock_)); |
43 } | 43 } |
44 ~ProbeControllerTest() override {} | 44 ~ProbeControllerTest() override {} |
45 | 45 |
46 SimulatedClock clock_; | 46 SimulatedClock clock_; |
47 NiceMock<MockPacedSender> pacer_; | 47 NiceMock<MockPacedSender> pacer_; |
48 std::unique_ptr<ProbeController> probe_controller_; | 48 std::unique_ptr<ProbeController> probe_controller_; |
49 }; | 49 }; |
50 | 50 |
51 TEST_F(ProbeControllerTest, InitiatesProbingAtStart) { | 51 TEST_F(ProbeControllerTest, InitiatesProbingAtStart) { |
52 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(AtLeast(2)); | 52 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
53 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 53 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
54 kMaxBitrateBps); | 54 kMaxBitrateBps); |
55 } | 55 } |
56 | 56 |
57 TEST_F(ProbeControllerTest, ProbeOnlyWhenNetworkIsUp) { | 57 TEST_F(ProbeControllerTest, ProbeOnlyWhenNetworkIsUp) { |
58 probe_controller_->OnNetworkStateChanged(kNetworkDown); | 58 probe_controller_->OnNetworkStateChanged(kNetworkDown); |
59 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(0); | 59 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
60 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 60 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
61 kMaxBitrateBps); | 61 kMaxBitrateBps); |
62 | 62 |
63 testing::Mock::VerifyAndClearExpectations(&pacer_); | 63 testing::Mock::VerifyAndClearExpectations(&pacer_); |
64 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(AtLeast(2)); | 64 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
65 probe_controller_->OnNetworkStateChanged(kNetworkUp); | 65 probe_controller_->OnNetworkStateChanged(kNetworkUp); |
66 } | 66 } |
67 | 67 |
68 TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) { | 68 TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) { |
69 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(AtLeast(2)); | 69 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2)); |
70 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 70 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
71 kMaxBitrateBps); | 71 kMaxBitrateBps); |
72 // Long enough to time out exponential probing. | 72 // Long enough to time out exponential probing. |
73 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); | 73 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
74 probe_controller_->SetEstimatedBitrate(kStartBitrateBps); | 74 probe_controller_->SetEstimatedBitrate(kStartBitrateBps); |
75 probe_controller_->Process(); | 75 probe_controller_->Process(); |
76 | 76 |
77 EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100, _)); | 77 EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100)); |
78 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 78 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
79 kMaxBitrateBps + 100); | 79 kMaxBitrateBps + 100); |
80 } | 80 } |
81 | 81 |
82 TEST_F(ProbeControllerTest, TestExponentialProbing) { | 82 TEST_F(ProbeControllerTest, TestExponentialProbing) { |
83 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 83 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
84 kMaxBitrateBps); | 84 kMaxBitrateBps); |
85 | 85 |
86 // Repeated probe should only be sent when estimated bitrate climbs above | 86 // Repeated probe should only be sent when estimated bitrate climbs above |
87 // 0.7 * 6 * kStartBitrateBps = 1260. | 87 // 0.7 * 6 * kStartBitrateBps = 1260. |
88 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(0); | 88 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
89 probe_controller_->SetEstimatedBitrate(1000); | 89 probe_controller_->SetEstimatedBitrate(1000); |
90 testing::Mock::VerifyAndClearExpectations(&pacer_); | 90 testing::Mock::VerifyAndClearExpectations(&pacer_); |
91 | 91 |
92 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800, _)); | 92 EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800)); |
93 probe_controller_->SetEstimatedBitrate(1800); | 93 probe_controller_->SetEstimatedBitrate(1800); |
94 } | 94 } |
95 | 95 |
96 TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) { | 96 TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) { |
97 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 97 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
98 kMaxBitrateBps); | 98 kMaxBitrateBps); |
99 | 99 |
100 // Advance far enough to cause a time out in waiting for probing result. | 100 // Advance far enough to cause a time out in waiting for probing result. |
101 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); | 101 clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs); |
102 probe_controller_->Process(); | 102 probe_controller_->Process(); |
103 | 103 |
104 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(0); | 104 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
105 probe_controller_->SetEstimatedBitrate(1800); | 105 probe_controller_->SetEstimatedBitrate(1800); |
106 } | 106 } |
107 | 107 |
108 TEST_F(ProbeControllerTest, ProbeAfterEstimateDropInAlr) { | 108 TEST_F(ProbeControllerTest, ProbeAfterEstimateDropInAlr) { |
109 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(2); | 109 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
110 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 110 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
111 kMaxBitrateBps); | 111 kMaxBitrateBps); |
112 probe_controller_->SetEstimatedBitrate(500); | 112 probe_controller_->SetEstimatedBitrate(500); |
113 testing::Mock::VerifyAndClearExpectations(&pacer_); | 113 testing::Mock::VerifyAndClearExpectations(&pacer_); |
114 | 114 |
115 // When bandwidth estimate drops the controller should send a probe at the | 115 // When bandwidth estimate drops the controller should send a probe at the |
116 // previous bitrate. | 116 // previous bitrate. |
117 EXPECT_CALL(pacer_, CreateProbeCluster(500, _)).Times(1); | 117 EXPECT_CALL(pacer_, CreateProbeCluster(500)).Times(1); |
118 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) | 118 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
119 .WillRepeatedly( | 119 .WillRepeatedly( |
120 Return(rtc::Optional<int64_t>(clock_.TimeInMilliseconds()))); | 120 Return(rtc::Optional<int64_t>(clock_.TimeInMilliseconds()))); |
121 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); | 121 clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); |
122 probe_controller_->Process(); | 122 probe_controller_->Process(); |
123 probe_controller_->SetEstimatedBitrate(50); | 123 probe_controller_->SetEstimatedBitrate(50); |
124 } | 124 } |
125 | 125 |
126 TEST_F(ProbeControllerTest, PeriodicProbing) { | 126 TEST_F(ProbeControllerTest, PeriodicProbing) { |
127 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(2); | 127 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2); |
128 probe_controller_->EnablePeriodicAlrProbing(true); | 128 probe_controller_->EnablePeriodicAlrProbing(true); |
129 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, | 129 probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps, |
130 kMaxBitrateBps); | 130 kMaxBitrateBps); |
131 probe_controller_->SetEstimatedBitrate(500); | 131 probe_controller_->SetEstimatedBitrate(500); |
132 testing::Mock::VerifyAndClearExpectations(&pacer_); | 132 testing::Mock::VerifyAndClearExpectations(&pacer_); |
133 | 133 |
134 int64_t start_time = clock_.TimeInMilliseconds(); | 134 int64_t start_time = clock_.TimeInMilliseconds(); |
135 | 135 |
136 // Expect the controller to send a new probe after 5s has passed. | 136 // Expect the controller to send a new probe after 5s has passed. |
137 EXPECT_CALL(pacer_, CreateProbeCluster(1000, _)).Times(1); | 137 EXPECT_CALL(pacer_, CreateProbeCluster(1000)).Times(1); |
138 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) | 138 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
139 .WillRepeatedly(Return(rtc::Optional<int64_t>(start_time))); | 139 .WillRepeatedly(Return(rtc::Optional<int64_t>(start_time))); |
140 clock_.AdvanceTimeMilliseconds(5000); | 140 clock_.AdvanceTimeMilliseconds(5000); |
141 probe_controller_->Process(); | 141 probe_controller_->Process(); |
142 probe_controller_->SetEstimatedBitrate(500); | 142 probe_controller_->SetEstimatedBitrate(500); |
143 testing::Mock::VerifyAndClearExpectations(&pacer_); | 143 testing::Mock::VerifyAndClearExpectations(&pacer_); |
144 | 144 |
145 // The following probe should be sent at 10s into ALR. | 145 // The following probe should be sent at 10s into ALR. |
146 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(0); | 146 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
147 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) | 147 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
148 .WillRepeatedly(Return(rtc::Optional<int64_t>(start_time))); | 148 .WillRepeatedly(Return(rtc::Optional<int64_t>(start_time))); |
149 clock_.AdvanceTimeMilliseconds(4000); | 149 clock_.AdvanceTimeMilliseconds(4000); |
150 probe_controller_->Process(); | 150 probe_controller_->Process(); |
151 probe_controller_->SetEstimatedBitrate(500); | 151 probe_controller_->SetEstimatedBitrate(500); |
152 testing::Mock::VerifyAndClearExpectations(&pacer_); | 152 testing::Mock::VerifyAndClearExpectations(&pacer_); |
153 | 153 |
154 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(1); | 154 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(1); |
155 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) | 155 EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) |
156 .WillRepeatedly(Return(rtc::Optional<int64_t>(start_time))); | 156 .WillRepeatedly(Return(rtc::Optional<int64_t>(start_time))); |
157 clock_.AdvanceTimeMilliseconds(1000); | 157 clock_.AdvanceTimeMilliseconds(1000); |
158 probe_controller_->Process(); | 158 probe_controller_->Process(); |
159 probe_controller_->SetEstimatedBitrate(500); | 159 probe_controller_->SetEstimatedBitrate(500); |
160 testing::Mock::VerifyAndClearExpectations(&pacer_); | 160 testing::Mock::VerifyAndClearExpectations(&pacer_); |
161 } | 161 } |
162 | 162 |
163 TEST_F(ProbeControllerTest, TestExponentialProbingOverflow) { | 163 TEST_F(ProbeControllerTest, TestExponentialProbingOverflow) { |
164 const int64_t kMbpsMultiplier = 1000000; | 164 const int64_t kMbpsMultiplier = 1000000; |
165 probe_controller_->SetBitrates(kMinBitrateBps, 10 * kMbpsMultiplier, | 165 probe_controller_->SetBitrates(kMinBitrateBps, 10 * kMbpsMultiplier, |
166 100 * kMbpsMultiplier); | 166 100 * kMbpsMultiplier); |
167 | 167 |
168 // Verify that probe bitrate is capped at the specified max bitrate | 168 // Verify that probe bitrate is capped at the specified max bitrate |
169 EXPECT_CALL(pacer_, CreateProbeCluster(100 * kMbpsMultiplier, _)); | 169 EXPECT_CALL(pacer_, CreateProbeCluster(100 * kMbpsMultiplier)); |
170 probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier); | 170 probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier); |
171 testing::Mock::VerifyAndClearExpectations(&pacer_); | 171 testing::Mock::VerifyAndClearExpectations(&pacer_); |
172 | 172 |
173 // Verify that repeated probes aren't sent. | 173 // Verify that repeated probes aren't sent. |
174 EXPECT_CALL(pacer_, CreateProbeCluster(_, _)).Times(0); | 174 EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); |
175 probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier); | 175 probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier); |
176 } | 176 } |
177 | 177 |
178 } // namespace test | 178 } // namespace test |
179 } // namespace webrtc | 179 } // namespace webrtc |
OLD | NEW |