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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 void(uint32_t min_send_bitrate_bps, | 27 void(uint32_t min_send_bitrate_bps, |
28 uint32_t max_padding_bitrate_bps)); | 28 uint32_t max_padding_bitrate_bps)); |
29 }; | 29 }; |
30 | 30 |
31 class TestBitrateObserver : public BitrateAllocatorObserver { | 31 class TestBitrateObserver : public BitrateAllocatorObserver { |
32 public: | 32 public: |
33 TestBitrateObserver() | 33 TestBitrateObserver() |
34 : last_bitrate_bps_(0), | 34 : last_bitrate_bps_(0), |
35 last_fraction_loss_(0), | 35 last_fraction_loss_(0), |
36 last_rtt_ms_(0), | 36 last_rtt_ms_(0), |
37 last_probing_interval_ms_(0), | |
38 protection_ratio_(0.0) {} | 37 protection_ratio_(0.0) {} |
39 | 38 |
40 void SetBitrateProtectionRatio(double protection_ratio) { | 39 void SetBitrateProtectionRatio(double protection_ratio) { |
41 protection_ratio_ = protection_ratio; | 40 protection_ratio_ = protection_ratio; |
42 } | 41 } |
43 | 42 |
44 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, | 43 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, |
45 uint8_t fraction_loss, | 44 uint8_t fraction_loss, |
46 int64_t rtt, | 45 int64_t rtt) override { |
47 int64_t probing_interval_ms) override { | |
48 last_bitrate_bps_ = bitrate_bps; | 46 last_bitrate_bps_ = bitrate_bps; |
49 last_fraction_loss_ = fraction_loss; | 47 last_fraction_loss_ = fraction_loss; |
50 last_rtt_ms_ = rtt; | 48 last_rtt_ms_ = rtt; |
51 last_probing_interval_ms_ = probing_interval_ms; | |
52 return bitrate_bps * protection_ratio_; | 49 return bitrate_bps * protection_ratio_; |
53 } | 50 } |
54 uint32_t last_bitrate_bps_; | 51 uint32_t last_bitrate_bps_; |
55 uint8_t last_fraction_loss_; | 52 uint8_t last_fraction_loss_; |
56 int64_t last_rtt_ms_; | 53 int64_t last_rtt_ms_; |
57 int last_probing_interval_ms_; | |
58 double protection_ratio_; | 54 double protection_ratio_; |
59 }; | 55 }; |
60 | 56 |
61 namespace { | |
62 constexpr int64_t kDefaultProbingIntervalMs = 3000; | |
63 } | |
64 | |
65 class BitrateAllocatorTest : public ::testing::Test { | 57 class BitrateAllocatorTest : public ::testing::Test { |
66 protected: | 58 protected: |
67 BitrateAllocatorTest() : allocator_(new BitrateAllocator(&limit_observer_)) { | 59 BitrateAllocatorTest() : allocator_(new BitrateAllocator(&limit_observer_)) { |
68 allocator_->OnNetworkChanged(300000u, 0, 0, kDefaultProbingIntervalMs); | 60 allocator_->OnNetworkChanged(300000u, 0, 0); |
69 } | 61 } |
70 ~BitrateAllocatorTest() {} | 62 ~BitrateAllocatorTest() {} |
71 | 63 |
72 NiceMock<MockLimitObserver> limit_observer_; | 64 NiceMock<MockLimitObserver> limit_observer_; |
73 std::unique_ptr<BitrateAllocator> allocator_; | 65 std::unique_ptr<BitrateAllocator> allocator_; |
74 }; | 66 }; |
75 | 67 |
76 TEST_F(BitrateAllocatorTest, UpdatingBitrateObserver) { | 68 TEST_F(BitrateAllocatorTest, UpdatingBitrateObserver) { |
77 TestBitrateObserver bitrate_observer; | 69 TestBitrateObserver bitrate_observer; |
78 const uint32_t kMinSendBitrateBps = 100000; | 70 const uint32_t kMinSendBitrateBps = 100000; |
79 const uint32_t kPadUpToBitrateBps = 50000; | 71 const uint32_t kPadUpToBitrateBps = 50000; |
80 | 72 |
81 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(kMinSendBitrateBps, | 73 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(kMinSendBitrateBps, |
82 kPadUpToBitrateBps)); | 74 kPadUpToBitrateBps)); |
83 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, | 75 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, |
84 kPadUpToBitrateBps, true); | 76 kPadUpToBitrateBps, true); |
85 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer)); | 77 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer)); |
86 allocator_->OnNetworkChanged(200000, 0, 0, kDefaultProbingIntervalMs); | 78 allocator_->OnNetworkChanged(200000, 0, 0); |
87 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer)); | 79 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer)); |
88 | 80 |
89 // TODO(pbos): Expect capping to 1.5M instead of 3M when not boosting the max | 81 // TODO(pbos): Expect capping to 1.5M instead of 3M when not boosting the max |
90 // bitrate for FEC/retransmissions (see todo in BitrateAllocator). | 82 // bitrate for FEC/retransmissions (see todo in BitrateAllocator). |
91 allocator_->OnNetworkChanged(4000000, 0, 0, kDefaultProbingIntervalMs); | 83 allocator_->OnNetworkChanged(4000000, 0, 0); |
92 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer)); | 84 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer)); |
93 | 85 |
94 // Expect |max_padding_bitrate_bps| to change to 0 if the observer is updated. | 86 // Expect |max_padding_bitrate_bps| to change to 0 if the observer is updated. |
95 EXPECT_CALL(limit_observer_, | 87 EXPECT_CALL(limit_observer_, |
96 OnAllocationLimitsChanged(kMinSendBitrateBps, 0)); | 88 OnAllocationLimitsChanged(kMinSendBitrateBps, 0)); |
97 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 4000000, 0, | 89 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 4000000, 0, |
98 true); | 90 true); |
99 EXPECT_EQ(4000000, allocator_->GetStartBitrate(&bitrate_observer)); | 91 EXPECT_EQ(4000000, allocator_->GetStartBitrate(&bitrate_observer)); |
100 | 92 |
101 EXPECT_CALL(limit_observer_, | 93 EXPECT_CALL(limit_observer_, |
102 OnAllocationLimitsChanged(kMinSendBitrateBps, 0)); | 94 OnAllocationLimitsChanged(kMinSendBitrateBps, 0)); |
103 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, 0, | 95 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, 0, |
104 true); | 96 true); |
105 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer)); | 97 EXPECT_EQ(3000000, allocator_->GetStartBitrate(&bitrate_observer)); |
106 EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_bps_); | 98 EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_bps_); |
107 allocator_->OnNetworkChanged(1500000, 0, 0, kDefaultProbingIntervalMs); | 99 allocator_->OnNetworkChanged(1500000, 0, 0); |
108 EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_bps_); | 100 EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_bps_); |
109 } | 101 } |
110 | 102 |
111 TEST_F(BitrateAllocatorTest, TwoBitrateObserversOneRtcpObserver) { | 103 TEST_F(BitrateAllocatorTest, TwoBitrateObserversOneRtcpObserver) { |
112 TestBitrateObserver bitrate_observer_1; | 104 TestBitrateObserver bitrate_observer_1; |
113 TestBitrateObserver bitrate_observer_2; | 105 TestBitrateObserver bitrate_observer_2; |
114 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(100000, 0)); | 106 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(100000, 0)); |
115 allocator_->AddObserver(&bitrate_observer_1, 100000, 300000, 0, true); | 107 allocator_->AddObserver(&bitrate_observer_1, 100000, 300000, 0, true); |
116 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); | 108 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); |
117 EXPECT_CALL(limit_observer_, | 109 EXPECT_CALL(limit_observer_, |
118 OnAllocationLimitsChanged(100000 + 200000, 0)); | 110 OnAllocationLimitsChanged(100000 + 200000, 0)); |
119 allocator_->AddObserver(&bitrate_observer_2, 200000, 300000, 0, true); | 111 allocator_->AddObserver(&bitrate_observer_2, 200000, 300000, 0, true); |
120 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); | 112 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); |
121 | 113 |
122 // Test too low start bitrate, hence lower than sum of min. Min bitrates | 114 // Test too low start bitrate, hence lower than sum of min. Min bitrates |
123 // will | 115 // will |
124 // be allocated to all observers. | 116 // be allocated to all observers. |
125 allocator_->OnNetworkChanged(200000, 0, 50, kDefaultProbingIntervalMs); | 117 allocator_->OnNetworkChanged(200000, 0, 50); |
126 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 118 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
127 EXPECT_EQ(0, bitrate_observer_1.last_fraction_loss_); | 119 EXPECT_EQ(0, bitrate_observer_1.last_fraction_loss_); |
128 EXPECT_EQ(50, bitrate_observer_1.last_rtt_ms_); | 120 EXPECT_EQ(50, bitrate_observer_1.last_rtt_ms_); |
129 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); | 121 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); |
130 EXPECT_EQ(0, bitrate_observer_2.last_fraction_loss_); | 122 EXPECT_EQ(0, bitrate_observer_2.last_fraction_loss_); |
131 EXPECT_EQ(50, bitrate_observer_2.last_rtt_ms_); | 123 EXPECT_EQ(50, bitrate_observer_2.last_rtt_ms_); |
132 | 124 |
133 // Test a bitrate which should be distributed equally. | 125 // Test a bitrate which should be distributed equally. |
134 allocator_->OnNetworkChanged(500000, 0, 50, kDefaultProbingIntervalMs); | 126 allocator_->OnNetworkChanged(500000, 0, 50); |
135 const uint32_t kBitrateToShare = 500000 - 200000 - 100000; | 127 const uint32_t kBitrateToShare = 500000 - 200000 - 100000; |
136 EXPECT_EQ(100000u + kBitrateToShare / 2, | 128 EXPECT_EQ(100000u + kBitrateToShare / 2, |
137 bitrate_observer_1.last_bitrate_bps_); | 129 bitrate_observer_1.last_bitrate_bps_); |
138 EXPECT_EQ(200000u + kBitrateToShare / 2, | 130 EXPECT_EQ(200000u + kBitrateToShare / 2, |
139 bitrate_observer_2.last_bitrate_bps_); | 131 bitrate_observer_2.last_bitrate_bps_); |
140 | 132 |
141 // Limited by 2x max bitrates since we leave room for FEC and | 133 // Limited by 2x max bitrates since we leave room for FEC and |
142 // retransmissions. | 134 // retransmissions. |
143 allocator_->OnNetworkChanged(1500000, 0, 50, kDefaultProbingIntervalMs); | 135 allocator_->OnNetworkChanged(1500000, 0, 50); |
144 EXPECT_EQ(600000u, bitrate_observer_1.last_bitrate_bps_); | 136 EXPECT_EQ(600000u, bitrate_observer_1.last_bitrate_bps_); |
145 EXPECT_EQ(600000u, bitrate_observer_2.last_bitrate_bps_); | 137 EXPECT_EQ(600000u, bitrate_observer_2.last_bitrate_bps_); |
146 | 138 |
147 // Verify that if the bandwidth estimate is set to zero, the allocated | 139 // Verify that if the bandwidth estimate is set to zero, the allocated |
148 // rate is | 140 // rate is |
149 // zero. | 141 // zero. |
150 allocator_->OnNetworkChanged(0, 0, 50, kDefaultProbingIntervalMs); | 142 allocator_->OnNetworkChanged(0, 0, 50); |
151 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 143 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
152 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 144 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
153 } | 145 } |
154 | 146 |
155 TEST_F(BitrateAllocatorTest, RemoveObserverTriggersLimitObserver) { | 147 TEST_F(BitrateAllocatorTest, RemoveObserverTriggersLimitObserver) { |
156 TestBitrateObserver bitrate_observer; | 148 TestBitrateObserver bitrate_observer; |
157 const uint32_t kMinSendBitrateBps = 100000; | 149 const uint32_t kMinSendBitrateBps = 100000; |
158 const uint32_t kPadUpToBitrateBps = 50000; | 150 const uint32_t kPadUpToBitrateBps = 50000; |
159 | 151 |
160 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(kMinSendBitrateBps, | 152 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(kMinSendBitrateBps, |
161 kPadUpToBitrateBps)); | 153 kPadUpToBitrateBps)); |
162 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, | 154 allocator_->AddObserver(&bitrate_observer, kMinSendBitrateBps, 1500000, |
163 kPadUpToBitrateBps, true); | 155 kPadUpToBitrateBps, true); |
164 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); | 156 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); |
165 allocator_->RemoveObserver(&bitrate_observer); | 157 allocator_->RemoveObserver(&bitrate_observer); |
166 } | 158 } |
167 | 159 |
168 class BitrateAllocatorTestNoEnforceMin : public ::testing::Test { | 160 class BitrateAllocatorTestNoEnforceMin : public ::testing::Test { |
169 protected: | 161 protected: |
170 BitrateAllocatorTestNoEnforceMin() | 162 BitrateAllocatorTestNoEnforceMin() |
171 : allocator_(new BitrateAllocator(&limit_observer_)) { | 163 : allocator_(new BitrateAllocator(&limit_observer_)) { |
172 allocator_->OnNetworkChanged(300000u, 0, 0, kDefaultProbingIntervalMs); | 164 allocator_->OnNetworkChanged(300000u, 0, 0); |
173 } | 165 } |
174 ~BitrateAllocatorTestNoEnforceMin() {} | 166 ~BitrateAllocatorTestNoEnforceMin() {} |
175 | 167 |
176 NiceMock<MockLimitObserver> limit_observer_; | 168 NiceMock<MockLimitObserver> limit_observer_; |
177 std::unique_ptr<BitrateAllocator> allocator_; | 169 std::unique_ptr<BitrateAllocator> allocator_; |
178 }; | 170 }; |
179 | 171 |
180 // The following three tests verify enforcing a minimum bitrate works as | 172 // The following three tests verify enforcing a minimum bitrate works as |
181 // intended. | 173 // intended. |
182 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) { | 174 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) { |
183 TestBitrateObserver bitrate_observer_1; | 175 TestBitrateObserver bitrate_observer_1; |
184 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since | 176 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since |
185 // AddObserver is called with |enforce_min_bitrate| = false. | 177 // AddObserver is called with |enforce_min_bitrate| = false. |
186 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); | 178 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); |
187 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); | 179 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); |
188 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); | 180 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); |
189 | 181 |
190 // High BWE. | 182 // High BWE. |
191 allocator_->OnNetworkChanged(150000, 0, 0, kDefaultProbingIntervalMs); | 183 allocator_->OnNetworkChanged(150000, 0, 0); |
192 EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_bps_); | 184 EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_bps_); |
193 | 185 |
194 // Low BWE. | 186 // Low BWE. |
195 allocator_->OnNetworkChanged(10000, 0, 0, kDefaultProbingIntervalMs); | 187 allocator_->OnNetworkChanged(10000, 0, 0); |
196 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 188 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
197 | 189 |
198 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); | 190 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); |
199 allocator_->RemoveObserver(&bitrate_observer_1); | 191 allocator_->RemoveObserver(&bitrate_observer_1); |
200 } | 192 } |
201 | 193 |
202 TEST_F(BitrateAllocatorTestNoEnforceMin, ThreeBitrateObservers) { | 194 TEST_F(BitrateAllocatorTestNoEnforceMin, ThreeBitrateObservers) { |
203 TestBitrateObserver bitrate_observer_1; | 195 TestBitrateObserver bitrate_observer_1; |
204 TestBitrateObserver bitrate_observer_2; | 196 TestBitrateObserver bitrate_observer_2; |
205 TestBitrateObserver bitrate_observer_3; | 197 TestBitrateObserver bitrate_observer_3; |
206 // Set up the observers with min bitrates at 100000, 200000, and 300000. | 198 // Set up the observers with min bitrates at 100000, 200000, and 300000. |
207 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); | 199 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); |
208 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); | 200 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); |
209 | 201 |
210 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, false); | 202 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, false); |
211 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); | 203 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); |
212 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 204 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
213 | 205 |
214 allocator_->AddObserver(&bitrate_observer_3, 300000, 400000, 0, false); | 206 allocator_->AddObserver(&bitrate_observer_3, 300000, 400000, 0, false); |
215 EXPECT_EQ(0, allocator_->GetStartBitrate(&bitrate_observer_3)); | 207 EXPECT_EQ(0, allocator_->GetStartBitrate(&bitrate_observer_3)); |
216 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 208 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
217 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); | 209 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); |
218 | 210 |
219 // High BWE. Make sure the controllers get a fair share of the surplus (i.e., | 211 // High BWE. Make sure the controllers get a fair share of the surplus (i.e., |
220 // what is left after each controller gets its min rate). | 212 // what is left after each controller gets its min rate). |
221 allocator_->OnNetworkChanged(690000, 0, 0, kDefaultProbingIntervalMs); | 213 allocator_->OnNetworkChanged(690000, 0, 0); |
222 // Verify that each observer gets its min rate (sum of min rates is 600000), | 214 // Verify that each observer gets its min rate (sum of min rates is 600000), |
223 // and that the remaining 90000 is divided equally among the three. | 215 // and that the remaining 90000 is divided equally among the three. |
224 uint32_t bitrate_to_share = 690000u - 100000u - 200000u - 300000u; | 216 uint32_t bitrate_to_share = 690000u - 100000u - 200000u - 300000u; |
225 EXPECT_EQ(100000u + bitrate_to_share / 3, | 217 EXPECT_EQ(100000u + bitrate_to_share / 3, |
226 bitrate_observer_1.last_bitrate_bps_); | 218 bitrate_observer_1.last_bitrate_bps_); |
227 EXPECT_EQ(200000u + bitrate_to_share / 3, | 219 EXPECT_EQ(200000u + bitrate_to_share / 3, |
228 bitrate_observer_2.last_bitrate_bps_); | 220 bitrate_observer_2.last_bitrate_bps_); |
229 EXPECT_EQ(300000u + bitrate_to_share / 3, | 221 EXPECT_EQ(300000u + bitrate_to_share / 3, |
230 bitrate_observer_3.last_bitrate_bps_); | 222 bitrate_observer_3.last_bitrate_bps_); |
231 | 223 |
232 // BWE below the sum of observer's min bitrate. | 224 // BWE below the sum of observer's min bitrate. |
233 allocator_->OnNetworkChanged(300000, 0, 0, kDefaultProbingIntervalMs); | 225 allocator_->OnNetworkChanged(300000, 0, 0); |
234 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); // Min bitrate. | 226 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); // Min bitrate. |
235 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); // Min bitrate. | 227 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); // Min bitrate. |
236 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); // Nothing. | 228 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); // Nothing. |
237 | 229 |
238 // Increased BWE, but still below the sum of configured min bitrates for all | 230 // Increased BWE, but still below the sum of configured min bitrates for all |
239 // observers and too little for observer 3. 1 and 2 will share the rest. | 231 // observers and too little for observer 3. 1 and 2 will share the rest. |
240 allocator_->OnNetworkChanged(500000, 0, 0, kDefaultProbingIntervalMs); | 232 allocator_->OnNetworkChanged(500000, 0, 0); |
241 EXPECT_EQ(200000u, bitrate_observer_1.last_bitrate_bps_); // Min + split. | 233 EXPECT_EQ(200000u, bitrate_observer_1.last_bitrate_bps_); // Min + split. |
242 EXPECT_EQ(300000u, bitrate_observer_2.last_bitrate_bps_); // Min + split. | 234 EXPECT_EQ(300000u, bitrate_observer_2.last_bitrate_bps_); // Min + split. |
243 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); // Nothing. | 235 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); // Nothing. |
244 | 236 |
245 // Below min for all. | 237 // Below min for all. |
246 allocator_->OnNetworkChanged(10000, 0, 0, kDefaultProbingIntervalMs); | 238 allocator_->OnNetworkChanged(10000, 0, 0); |
247 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 239 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
248 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 240 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
249 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); | 241 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); |
250 | 242 |
251 // Verify that zero estimated bandwidth, means that that all gets zero, | 243 // Verify that zero estimated bandwidth, means that that all gets zero, |
252 // regardless of set min bitrate. | 244 // regardless of set min bitrate. |
253 allocator_->OnNetworkChanged(0, 0, 0, kDefaultProbingIntervalMs); | 245 allocator_->OnNetworkChanged(0, 0, 0); |
254 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 246 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
255 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 247 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
256 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); | 248 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_bps_); |
257 | 249 |
258 allocator_->RemoveObserver(&bitrate_observer_1); | 250 allocator_->RemoveObserver(&bitrate_observer_1); |
259 allocator_->RemoveObserver(&bitrate_observer_2); | 251 allocator_->RemoveObserver(&bitrate_observer_2); |
260 allocator_->RemoveObserver(&bitrate_observer_3); | 252 allocator_->RemoveObserver(&bitrate_observer_3); |
261 } | 253 } |
262 | 254 |
263 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserverWithPacketLoss) { | 255 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserverWithPacketLoss) { |
264 TestBitrateObserver bitrate_observer; | 256 TestBitrateObserver bitrate_observer; |
265 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since | 257 // Expect OnAllocationLimitsChanged with |min_send_bitrate_bps| = 0 since |
266 // AddObserver is called with |enforce_min_bitrate| = false. | 258 // AddObserver is called with |enforce_min_bitrate| = false. |
267 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); | 259 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); |
268 allocator_->AddObserver( | 260 allocator_->AddObserver( |
269 &bitrate_observer, 100000, 400000, 0, false); | 261 &bitrate_observer, 100000, 400000, 0, false); |
270 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer)); | 262 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer)); |
271 | 263 |
272 // High BWE. | 264 // High BWE. |
273 allocator_->OnNetworkChanged(150000, 0, 0, kDefaultProbingIntervalMs); | 265 allocator_->OnNetworkChanged(150000, 0, 0); |
274 EXPECT_EQ(150000u, bitrate_observer.last_bitrate_bps_); | 266 EXPECT_EQ(150000u, bitrate_observer.last_bitrate_bps_); |
275 | 267 |
276 // Add loss and use a part of the bitrate for protection. | 268 // Add loss and use a part of the bitrate for protection. |
277 double protection_ratio = 0.4; | 269 double protection_ratio = 0.4; |
278 uint8_t fraction_loss = protection_ratio * 256; | 270 uint8_t fraction_loss = protection_ratio * 256; |
279 bitrate_observer.SetBitrateProtectionRatio(protection_ratio); | 271 bitrate_observer.SetBitrateProtectionRatio(protection_ratio); |
280 allocator_->OnNetworkChanged(200000, 0, fraction_loss, | 272 allocator_->OnNetworkChanged(200000, 0, fraction_loss); |
281 kDefaultProbingIntervalMs); | |
282 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_bps_); | 273 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_bps_); |
283 | 274 |
284 // Above the min threshold, but not enough given the protection used. | 275 // Above the min threshold, but not enough given the protection used. |
285 allocator_->OnNetworkChanged(139000, 0, fraction_loss, | 276 allocator_->OnNetworkChanged(139000, 0, fraction_loss); |
286 kDefaultProbingIntervalMs); | |
287 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_); | 277 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_); |
288 | 278 |
289 // Verify the hysteresis is added for the protection. | 279 // Verify the hysteresis is added for the protection. |
290 allocator_->OnNetworkChanged(150000, 0, fraction_loss, | 280 allocator_->OnNetworkChanged(150000, 0, fraction_loss); |
291 kDefaultProbingIntervalMs); | |
292 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_); | 281 EXPECT_EQ(0u, bitrate_observer.last_bitrate_bps_); |
293 | 282 |
294 // Just enough to enable video again. | 283 // Just enough to enable video again. |
295 allocator_->OnNetworkChanged(168000, 0, fraction_loss, | 284 allocator_->OnNetworkChanged(168000, 0, fraction_loss); |
296 kDefaultProbingIntervalMs); | |
297 EXPECT_EQ(168000u, bitrate_observer.last_bitrate_bps_); | 285 EXPECT_EQ(168000u, bitrate_observer.last_bitrate_bps_); |
298 | 286 |
299 // Remove all protection and make sure video is not paused as earlier. | 287 // Remove all protection and make sure video is not paused as earlier. |
300 bitrate_observer.SetBitrateProtectionRatio(0.0); | 288 bitrate_observer.SetBitrateProtectionRatio(0.0); |
301 allocator_->OnNetworkChanged(140000, 0, 0, kDefaultProbingIntervalMs); | 289 allocator_->OnNetworkChanged(140000, 0, 0); |
302 EXPECT_EQ(140000u, bitrate_observer.last_bitrate_bps_); | 290 EXPECT_EQ(140000u, bitrate_observer.last_bitrate_bps_); |
303 | 291 |
304 allocator_->OnNetworkChanged(139000, 0, 0, kDefaultProbingIntervalMs); | 292 allocator_->OnNetworkChanged(139000, 0, 0); |
305 EXPECT_EQ(139000u, bitrate_observer.last_bitrate_bps_); | 293 EXPECT_EQ(139000u, bitrate_observer.last_bitrate_bps_); |
306 | 294 |
307 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); | 295 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(0, 0)); |
308 allocator_->RemoveObserver(&bitrate_observer); | 296 allocator_->RemoveObserver(&bitrate_observer); |
309 } | 297 } |
310 | 298 |
311 TEST_F(BitrateAllocatorTestNoEnforceMin, TwoBitrateObserverWithPacketLoss) { | 299 TEST_F(BitrateAllocatorTestNoEnforceMin, TwoBitrateObserverWithPacketLoss) { |
312 TestBitrateObserver bitrate_observer_1; | 300 TestBitrateObserver bitrate_observer_1; |
313 TestBitrateObserver bitrate_observer_2; | 301 TestBitrateObserver bitrate_observer_2; |
314 | 302 |
315 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); | 303 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, false); |
316 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); | 304 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); |
317 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, false); | 305 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, false); |
318 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); | 306 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); |
319 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 307 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
320 | 308 |
321 // Enough bitrate for both. | 309 // Enough bitrate for both. |
322 bitrate_observer_2.SetBitrateProtectionRatio(0.5); | 310 bitrate_observer_2.SetBitrateProtectionRatio(0.5); |
323 allocator_->OnNetworkChanged(300000, 0, 0, kDefaultProbingIntervalMs); | 311 allocator_->OnNetworkChanged(300000, 0, 0); |
324 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 312 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
325 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); | 313 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); |
326 | 314 |
327 // Above min for observer 2, but too little given the protection used. | 315 // Above min for observer 2, but too little given the protection used. |
328 allocator_->OnNetworkChanged(330000, 0, 0, kDefaultProbingIntervalMs); | 316 allocator_->OnNetworkChanged(330000, 0, 0); |
329 EXPECT_EQ(330000u, bitrate_observer_1.last_bitrate_bps_); | 317 EXPECT_EQ(330000u, bitrate_observer_1.last_bitrate_bps_); |
330 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 318 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
331 | 319 |
332 allocator_->OnNetworkChanged(100000, 0, 0, kDefaultProbingIntervalMs); | 320 allocator_->OnNetworkChanged(100000, 0, 0); |
333 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 321 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
334 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 322 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
335 | 323 |
336 allocator_->OnNetworkChanged(99999, 0, 0, kDefaultProbingIntervalMs); | 324 allocator_->OnNetworkChanged(99999, 0, 0); |
337 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 325 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
338 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 326 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
339 | 327 |
340 allocator_->OnNetworkChanged(119000, 0, 0, kDefaultProbingIntervalMs); | 328 allocator_->OnNetworkChanged(119000, 0, 0); |
341 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 329 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
342 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 330 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
343 | 331 |
344 allocator_->OnNetworkChanged(120000, 0, 0, kDefaultProbingIntervalMs); | 332 allocator_->OnNetworkChanged(120000, 0, 0); |
345 EXPECT_EQ(120000u, bitrate_observer_1.last_bitrate_bps_); | 333 EXPECT_EQ(120000u, bitrate_observer_1.last_bitrate_bps_); |
346 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 334 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
347 | 335 |
348 // Verify the protection is accounted for before resuming observer 2. | 336 // Verify the protection is accounted for before resuming observer 2. |
349 allocator_->OnNetworkChanged(429000, 0, 0, kDefaultProbingIntervalMs); | 337 allocator_->OnNetworkChanged(429000, 0, 0); |
350 EXPECT_EQ(400000u, bitrate_observer_1.last_bitrate_bps_); | 338 EXPECT_EQ(400000u, bitrate_observer_1.last_bitrate_bps_); |
351 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 339 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
352 | 340 |
353 allocator_->OnNetworkChanged(430000, 0, 0, kDefaultProbingIntervalMs); | 341 allocator_->OnNetworkChanged(430000, 0, 0); |
354 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 342 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
355 EXPECT_EQ(330000u, bitrate_observer_2.last_bitrate_bps_); | 343 EXPECT_EQ(330000u, bitrate_observer_2.last_bitrate_bps_); |
356 | 344 |
357 allocator_->RemoveObserver(&bitrate_observer_1); | 345 allocator_->RemoveObserver(&bitrate_observer_1); |
358 allocator_->RemoveObserver(&bitrate_observer_2); | 346 allocator_->RemoveObserver(&bitrate_observer_2); |
359 } | 347 } |
360 | 348 |
361 TEST_F(BitrateAllocatorTest, ThreeBitrateObserversLowBweEnforceMin) { | 349 TEST_F(BitrateAllocatorTest, ThreeBitrateObserversLowBweEnforceMin) { |
362 TestBitrateObserver bitrate_observer_1; | 350 TestBitrateObserver bitrate_observer_1; |
363 TestBitrateObserver bitrate_observer_2; | 351 TestBitrateObserver bitrate_observer_2; |
364 TestBitrateObserver bitrate_observer_3; | 352 TestBitrateObserver bitrate_observer_3; |
365 | 353 |
366 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, true); | 354 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000, 0, true); |
367 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); | 355 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); |
368 | 356 |
369 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, true); | 357 allocator_->AddObserver(&bitrate_observer_2, 200000, 400000, 0, true); |
370 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); | 358 EXPECT_EQ(200000, allocator_->GetStartBitrate(&bitrate_observer_2)); |
371 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); | 359 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); |
372 | 360 |
373 allocator_->AddObserver(&bitrate_observer_3, 300000, 400000, 0, true); | 361 allocator_->AddObserver(&bitrate_observer_3, 300000, 400000, 0, true); |
374 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_3)); | 362 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_3)); |
375 EXPECT_EQ(100000, static_cast<int>(bitrate_observer_1.last_bitrate_bps_)); | 363 EXPECT_EQ(100000, static_cast<int>(bitrate_observer_1.last_bitrate_bps_)); |
376 EXPECT_EQ(200000, static_cast<int>(bitrate_observer_2.last_bitrate_bps_)); | 364 EXPECT_EQ(200000, static_cast<int>(bitrate_observer_2.last_bitrate_bps_)); |
377 | 365 |
378 // Low BWE. Verify that all observers still get their respective min | 366 // Low BWE. Verify that all observers still get their respective min |
379 // bitrate. | 367 // bitrate. |
380 allocator_->OnNetworkChanged(1000, 0, 0, kDefaultProbingIntervalMs); | 368 allocator_->OnNetworkChanged(1000, 0, 0); |
381 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); // Min cap. | 369 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_bps_); // Min cap. |
382 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); // Min cap. | 370 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_bps_); // Min cap. |
383 EXPECT_EQ(300000u, bitrate_observer_3.last_bitrate_bps_); // Min cap. | 371 EXPECT_EQ(300000u, bitrate_observer_3.last_bitrate_bps_); // Min cap. |
384 | 372 |
385 allocator_->RemoveObserver(&bitrate_observer_1); | 373 allocator_->RemoveObserver(&bitrate_observer_1); |
386 allocator_->RemoveObserver(&bitrate_observer_2); | 374 allocator_->RemoveObserver(&bitrate_observer_2); |
387 allocator_->RemoveObserver(&bitrate_observer_3); | 375 allocator_->RemoveObserver(&bitrate_observer_3); |
388 } | 376 } |
389 | 377 |
390 TEST_F(BitrateAllocatorTest, AddObserverWhileNetworkDown) { | 378 TEST_F(BitrateAllocatorTest, AddObserverWhileNetworkDown) { |
391 TestBitrateObserver bitrate_observer_1; | 379 TestBitrateObserver bitrate_observer_1; |
392 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(50000, 0)); | 380 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(50000, 0)); |
393 | 381 |
394 allocator_->AddObserver(&bitrate_observer_1, 50000, 400000, 0, true); | 382 allocator_->AddObserver(&bitrate_observer_1, 50000, 400000, 0, true); |
395 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); | 383 EXPECT_EQ(300000, allocator_->GetStartBitrate(&bitrate_observer_1)); |
396 | 384 |
397 // Set network down, ie, no available bitrate. | 385 // Set network down, ie, no available bitrate. |
398 allocator_->OnNetworkChanged(0, 0, 0, kDefaultProbingIntervalMs); | 386 allocator_->OnNetworkChanged(0, 0, 0); |
399 | 387 |
400 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 388 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
401 | 389 |
402 TestBitrateObserver bitrate_observer_2; | 390 TestBitrateObserver bitrate_observer_2; |
403 // Adding an observer while the network is down should not affect the limits. | 391 // Adding an observer while the network is down should not affect the limits. |
404 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(50000 + 50000, 0)); | 392 EXPECT_CALL(limit_observer_, OnAllocationLimitsChanged(50000 + 50000, 0)); |
405 allocator_->AddObserver(&bitrate_observer_2, 50000, 400000, 0, true); | 393 allocator_->AddObserver(&bitrate_observer_2, 50000, 400000, 0, true); |
406 | 394 |
407 // Expect the start_bitrate to be set as if the network was still up but that | 395 // Expect the start_bitrate to be set as if the network was still up but that |
408 // the new observer have been notified that the network is down. | 396 // the new observer have been notified that the network is down. |
409 EXPECT_EQ(300000 / 2, allocator_->GetStartBitrate(&bitrate_observer_2)); | 397 EXPECT_EQ(300000 / 2, allocator_->GetStartBitrate(&bitrate_observer_2)); |
410 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); | 398 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_bps_); |
411 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); | 399 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_bps_); |
412 | 400 |
413 // Set network back up. | 401 // Set network back up. |
414 allocator_->OnNetworkChanged(1500000, 0, 50, kDefaultProbingIntervalMs); | 402 allocator_->OnNetworkChanged(1500000, 0, 50); |
415 EXPECT_EQ(750000u, bitrate_observer_1.last_bitrate_bps_); | 403 EXPECT_EQ(750000u, bitrate_observer_1.last_bitrate_bps_); |
416 EXPECT_EQ(750000u, bitrate_observer_2.last_bitrate_bps_); | 404 EXPECT_EQ(750000u, bitrate_observer_2.last_bitrate_bps_); |
417 } | 405 } |
418 | 406 |
419 TEST_F(BitrateAllocatorTest, MixedEnforecedConfigs) { | 407 TEST_F(BitrateAllocatorTest, MixedEnforecedConfigs) { |
420 TestBitrateObserver enforced_observer; | 408 TestBitrateObserver enforced_observer; |
421 allocator_->AddObserver(&enforced_observer, 6000, 30000, 0, true); | 409 allocator_->AddObserver(&enforced_observer, 6000, 30000, 0, true); |
422 EXPECT_EQ(60000, allocator_->GetStartBitrate(&enforced_observer)); | 410 EXPECT_EQ(60000, allocator_->GetStartBitrate(&enforced_observer)); |
423 | 411 |
424 TestBitrateObserver not_enforced_observer; | 412 TestBitrateObserver not_enforced_observer; |
425 allocator_->AddObserver(¬_enforced_observer, 30000, 2500000, 0, false); | 413 allocator_->AddObserver(¬_enforced_observer, 30000, 2500000, 0, false); |
426 EXPECT_EQ(270000, allocator_->GetStartBitrate(¬_enforced_observer)); | 414 EXPECT_EQ(270000, allocator_->GetStartBitrate(¬_enforced_observer)); |
427 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); | 415 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); |
428 | 416 |
429 allocator_->OnNetworkChanged(36000, 0, 50, kDefaultProbingIntervalMs); | 417 allocator_->OnNetworkChanged(36000, 0, 50); |
430 EXPECT_EQ(6000u, enforced_observer.last_bitrate_bps_); | 418 EXPECT_EQ(6000u, enforced_observer.last_bitrate_bps_); |
431 EXPECT_EQ(30000u, not_enforced_observer.last_bitrate_bps_); | 419 EXPECT_EQ(30000u, not_enforced_observer.last_bitrate_bps_); |
432 | 420 |
433 allocator_->OnNetworkChanged(35000, 0, 50, kDefaultProbingIntervalMs); | 421 allocator_->OnNetworkChanged(35000, 0, 50); |
434 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); | 422 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); |
435 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); | 423 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); |
436 | 424 |
437 allocator_->OnNetworkChanged(5000, 0, 50, kDefaultProbingIntervalMs); | 425 allocator_->OnNetworkChanged(5000, 0, 50); |
438 EXPECT_EQ(6000u, enforced_observer.last_bitrate_bps_); | 426 EXPECT_EQ(6000u, enforced_observer.last_bitrate_bps_); |
439 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); | 427 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); |
440 | 428 |
441 allocator_->OnNetworkChanged(36000, 0, 50, kDefaultProbingIntervalMs); | 429 allocator_->OnNetworkChanged(36000, 0, 50); |
442 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); | 430 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); |
443 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); | 431 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); |
444 | 432 |
445 allocator_->OnNetworkChanged(55000, 0, 50, kDefaultProbingIntervalMs); | 433 allocator_->OnNetworkChanged(55000, 0, 50); |
446 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); | 434 EXPECT_EQ(30000u, enforced_observer.last_bitrate_bps_); |
447 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); | 435 EXPECT_EQ(0u, not_enforced_observer.last_bitrate_bps_); |
448 | 436 |
449 allocator_->OnNetworkChanged(56000, 0, 50, kDefaultProbingIntervalMs); | 437 allocator_->OnNetworkChanged(56000, 0, 50); |
450 EXPECT_EQ(6000u, enforced_observer.last_bitrate_bps_); | 438 EXPECT_EQ(6000u, enforced_observer.last_bitrate_bps_); |
451 EXPECT_EQ(50000u, not_enforced_observer.last_bitrate_bps_); | 439 EXPECT_EQ(50000u, not_enforced_observer.last_bitrate_bps_); |
452 | 440 |
453 allocator_->OnNetworkChanged(56000, 0, 50, kDefaultProbingIntervalMs); | 441 allocator_->OnNetworkChanged(56000, 0, 50); |
454 EXPECT_EQ(16000u, enforced_observer.last_bitrate_bps_); | 442 EXPECT_EQ(16000u, enforced_observer.last_bitrate_bps_); |
455 EXPECT_EQ(40000u, not_enforced_observer.last_bitrate_bps_); | 443 EXPECT_EQ(40000u, not_enforced_observer.last_bitrate_bps_); |
456 | 444 |
457 allocator_->RemoveObserver(&enforced_observer); | 445 allocator_->RemoveObserver(&enforced_observer); |
458 allocator_->RemoveObserver(¬_enforced_observer); | 446 allocator_->RemoveObserver(¬_enforced_observer); |
459 } | 447 } |
460 | 448 |
461 TEST_F(BitrateAllocatorTest, AvoidToggleAbsolute) { | 449 TEST_F(BitrateAllocatorTest, AvoidToggleAbsolute) { |
462 TestBitrateObserver observer; | 450 TestBitrateObserver observer; |
463 allocator_->AddObserver(&observer, 30000, 300000, 0, false); | 451 allocator_->AddObserver(&observer, 30000, 300000, 0, false); |
464 EXPECT_EQ(300000, allocator_->GetStartBitrate(&observer)); | 452 EXPECT_EQ(300000, allocator_->GetStartBitrate(&observer)); |
465 | 453 |
466 allocator_->OnNetworkChanged(30000, 0, 50, kDefaultProbingIntervalMs); | 454 allocator_->OnNetworkChanged(30000, 0, 50); |
467 EXPECT_EQ(30000u, observer.last_bitrate_bps_); | 455 EXPECT_EQ(30000u, observer.last_bitrate_bps_); |
468 | 456 |
469 allocator_->OnNetworkChanged(20000, 0, 50, kDefaultProbingIntervalMs); | 457 allocator_->OnNetworkChanged(20000, 0, 50); |
470 EXPECT_EQ(0u, observer.last_bitrate_bps_); | 458 EXPECT_EQ(0u, observer.last_bitrate_bps_); |
471 | 459 |
472 allocator_->OnNetworkChanged(30000, 0, 50, kDefaultProbingIntervalMs); | 460 allocator_->OnNetworkChanged(30000, 0, 50); |
473 EXPECT_EQ(0u, observer.last_bitrate_bps_); | 461 EXPECT_EQ(0u, observer.last_bitrate_bps_); |
474 | 462 |
475 allocator_->OnNetworkChanged(49000, 0, 50, kDefaultProbingIntervalMs); | 463 allocator_->OnNetworkChanged(49000, 0, 50); |
476 EXPECT_EQ(0u, observer.last_bitrate_bps_); | 464 EXPECT_EQ(0u, observer.last_bitrate_bps_); |
477 | 465 |
478 allocator_->OnNetworkChanged(50000, 0, 50, kDefaultProbingIntervalMs); | 466 allocator_->OnNetworkChanged(50000, 0, 50); |
479 EXPECT_EQ(50000u, observer.last_bitrate_bps_); | 467 EXPECT_EQ(50000u, observer.last_bitrate_bps_); |
480 | 468 |
481 allocator_->OnNetworkChanged(30000, 0, 50, kDefaultProbingIntervalMs); | 469 allocator_->OnNetworkChanged(30000, 0, 50); |
482 EXPECT_EQ(30000u, observer.last_bitrate_bps_); | 470 EXPECT_EQ(30000u, observer.last_bitrate_bps_); |
483 | 471 |
484 allocator_->RemoveObserver(&observer); | 472 allocator_->RemoveObserver(&observer); |
485 } | 473 } |
486 | 474 |
487 TEST_F(BitrateAllocatorTest, AvoidTogglePercent) { | 475 TEST_F(BitrateAllocatorTest, AvoidTogglePercent) { |
488 TestBitrateObserver observer; | 476 TestBitrateObserver observer; |
489 allocator_->AddObserver(&observer, 300000, 600000, 0, false); | 477 allocator_->AddObserver(&observer, 300000, 600000, 0, false); |
490 EXPECT_EQ(300000, allocator_->GetStartBitrate(&observer)); | 478 EXPECT_EQ(300000, allocator_->GetStartBitrate(&observer)); |
491 | 479 |
492 allocator_->OnNetworkChanged(300000, 0, 50, kDefaultProbingIntervalMs); | 480 allocator_->OnNetworkChanged(300000, 0, 50); |
493 EXPECT_EQ(300000u, observer.last_bitrate_bps_); | 481 EXPECT_EQ(300000u, observer.last_bitrate_bps_); |
494 | 482 |
495 allocator_->OnNetworkChanged(200000, 0, 50, kDefaultProbingIntervalMs); | 483 allocator_->OnNetworkChanged(200000, 0, 50); |
496 EXPECT_EQ(0u, observer.last_bitrate_bps_); | 484 EXPECT_EQ(0u, observer.last_bitrate_bps_); |
497 | 485 |
498 allocator_->OnNetworkChanged(300000, 0, 50, kDefaultProbingIntervalMs); | 486 allocator_->OnNetworkChanged(300000, 0, 50); |
499 EXPECT_EQ(0u, observer.last_bitrate_bps_); | 487 EXPECT_EQ(0u, observer.last_bitrate_bps_); |
500 | 488 |
501 allocator_->OnNetworkChanged(329000, 0, 50, kDefaultProbingIntervalMs); | 489 allocator_->OnNetworkChanged(329000, 0, 50); |
502 EXPECT_EQ(0u, observer.last_bitrate_bps_); | 490 EXPECT_EQ(0u, observer.last_bitrate_bps_); |
503 | 491 |
504 allocator_->OnNetworkChanged(330000, 0, 50, kDefaultProbingIntervalMs); | 492 allocator_->OnNetworkChanged(330000, 0, 50); |
505 EXPECT_EQ(330000u, observer.last_bitrate_bps_); | 493 EXPECT_EQ(330000u, observer.last_bitrate_bps_); |
506 | 494 |
507 allocator_->OnNetworkChanged(300000, 0, 50, kDefaultProbingIntervalMs); | 495 allocator_->OnNetworkChanged(300000, 0, 50); |
508 EXPECT_EQ(300000u, observer.last_bitrate_bps_); | 496 EXPECT_EQ(300000u, observer.last_bitrate_bps_); |
509 | 497 |
510 allocator_->RemoveObserver(&observer); | 498 allocator_->RemoveObserver(&observer); |
511 } | 499 } |
512 | 500 |
513 TEST_F(BitrateAllocatorTest, PassProbingInterval) { | |
514 TestBitrateObserver observer; | |
515 allocator_->AddObserver(&observer, 300000, 600000, 0, false); | |
516 EXPECT_EQ(300000, allocator_->GetStartBitrate(&observer)); | |
517 | |
518 allocator_->OnNetworkChanged(300000, 0, 50, 5000); | |
519 EXPECT_EQ(5000, observer.last_probing_interval_ms_); | |
520 | |
521 allocator_->RemoveObserver(&observer); | |
522 } | |
523 | |
524 } // namespace webrtc | 501 } // namespace webrtc |
OLD | NEW |