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 "webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h
" | 10 #include "webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h
" |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <limits> | 13 #include <limits> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | 17 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 const size_t kMtu = 1200; | 21 constexpr size_t kMtu = 1200; |
22 const uint32_t kAcceptedBitrateErrorBps = 50000; | 22 constexpr uint32_t kAcceptedBitrateErrorBps = 50000; |
23 | 23 |
24 // Number of packets needed before we have a valid estimate. | 24 // Number of packets needed before we have a valid estimate. |
25 const int kNumInitialPackets = 2; | 25 constexpr int kNumInitialPackets = 2; |
| 26 |
| 27 constexpr int kInitialProbingPackets = 5; |
26 | 28 |
27 namespace test { | 29 namespace test { |
28 | 30 |
29 void TestBitrateObserver::OnReceiveBitrateChanged( | 31 void TestBitrateObserver::OnReceiveBitrateChanged( |
30 const std::vector<uint32_t>& ssrcs, | 32 const std::vector<uint32_t>& ssrcs, |
31 uint32_t bitrate) { | 33 uint32_t bitrate) { |
32 latest_bitrate_ = bitrate; | 34 latest_bitrate_ = bitrate; |
33 updated_ = true; | 35 updated_ = true; |
34 } | 36 } |
35 | 37 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 stream_generator_->AddStream(new test::RtpStream(30, 3e5)); | 163 stream_generator_->AddStream(new test::RtpStream(30, 3e5)); |
162 } | 164 } |
163 | 165 |
164 const uint32_t DelayBasedBweTest::kDefaultSsrc = 0; | 166 const uint32_t DelayBasedBweTest::kDefaultSsrc = 0; |
165 | 167 |
166 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms, | 168 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms, |
167 int64_t send_time_ms, | 169 int64_t send_time_ms, |
168 uint16_t sequence_number, | 170 uint16_t sequence_number, |
169 size_t payload_size) { | 171 size_t payload_size) { |
170 IncomingFeedback(arrival_time_ms, send_time_ms, sequence_number, payload_size, | 172 IncomingFeedback(arrival_time_ms, send_time_ms, sequence_number, payload_size, |
171 0); | 173 PacketInfo::kNotAProbe); |
172 } | 174 } |
173 | 175 |
174 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms, | 176 void DelayBasedBweTest::IncomingFeedback(int64_t arrival_time_ms, |
175 int64_t send_time_ms, | 177 int64_t send_time_ms, |
176 uint16_t sequence_number, | 178 uint16_t sequence_number, |
177 size_t payload_size, | 179 size_t payload_size, |
178 int probe_cluster_id) { | 180 int probe_cluster_id) { |
179 RTC_CHECK_GE(arrival_time_ms + arrival_time_offset_ms_, 0); | 181 RTC_CHECK_GE(arrival_time_ms + arrival_time_offset_ms_, 0); |
180 PacketInfo packet(arrival_time_ms + arrival_time_offset_ms_, send_time_ms, | 182 PacketInfo packet(arrival_time_ms + arrival_time_offset_ms_, send_time_ms, |
181 sequence_number, payload_size, probe_cluster_id); | 183 sequence_number, payload_size, probe_cluster_id); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); | 263 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); |
262 EXPECT_EQ(0u, ssrcs.size()); | 264 EXPECT_EQ(0u, ssrcs.size()); |
263 clock_.AdvanceTimeMilliseconds(1000); | 265 clock_.AdvanceTimeMilliseconds(1000); |
264 bitrate_estimator_->Process(); | 266 bitrate_estimator_->Process(); |
265 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); | 267 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); |
266 EXPECT_FALSE(bitrate_observer_->updated()); | 268 EXPECT_FALSE(bitrate_observer_->updated()); |
267 bitrate_observer_->Reset(); | 269 bitrate_observer_->Reset(); |
268 clock_.AdvanceTimeMilliseconds(1000); | 270 clock_.AdvanceTimeMilliseconds(1000); |
269 // Inserting packets for 5 seconds to get a valid estimate. | 271 // Inserting packets for 5 seconds to get a valid estimate. |
270 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) { | 272 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) { |
| 273 // NOTE!!! If the following line is moved under the if case then this test |
| 274 // wont work on windows realease bots. |
| 275 int cluster_id = i < kInitialProbingPackets ? 0 : PacketInfo::kNotAProbe; |
| 276 |
271 if (i == kNumInitialPackets) { | 277 if (i == kNumInitialPackets) { |
272 bitrate_estimator_->Process(); | 278 bitrate_estimator_->Process(); |
273 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); | 279 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); |
274 EXPECT_EQ(0u, ssrcs.size()); | 280 EXPECT_EQ(0u, ssrcs.size()); |
275 EXPECT_FALSE(bitrate_observer_->updated()); | 281 EXPECT_FALSE(bitrate_observer_->updated()); |
276 bitrate_observer_->Reset(); | 282 bitrate_observer_->Reset(); |
277 } | 283 } |
278 | |
279 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, | 284 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, |
280 sequence_number++, kMtu); | 285 sequence_number++, kMtu, cluster_id); |
281 clock_.AdvanceTimeMilliseconds(1000 / kFramerate); | 286 clock_.AdvanceTimeMilliseconds(1000 / kFramerate); |
282 send_time_ms += kFrameIntervalMs; | 287 send_time_ms += kFrameIntervalMs; |
283 } | 288 } |
284 bitrate_estimator_->Process(); | 289 bitrate_estimator_->Process(); |
285 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); | 290 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); |
286 ASSERT_EQ(1u, ssrcs.size()); | 291 ASSERT_EQ(1u, ssrcs.size()); |
287 EXPECT_EQ(kDefaultSsrc, ssrcs.front()); | 292 EXPECT_EQ(kDefaultSsrc, ssrcs.front()); |
288 EXPECT_NEAR(expected_converge_bitrate, bitrate_bps, kAcceptedBitrateErrorBps); | 293 EXPECT_NEAR(expected_converge_bitrate, bitrate_bps, kAcceptedBitrateErrorBps); |
289 EXPECT_TRUE(bitrate_observer_->updated()); | 294 EXPECT_TRUE(bitrate_observer_->updated()); |
290 bitrate_observer_->Reset(); | 295 bitrate_observer_->Reset(); |
291 EXPECT_EQ(bitrate_observer_->latest_bitrate(), bitrate_bps); | 296 EXPECT_EQ(bitrate_observer_->latest_bitrate(), bitrate_bps); |
292 bitrate_estimator_->RemoveStream(kDefaultSsrc); | |
293 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); | |
294 ASSERT_EQ(0u, ssrcs.size()); | |
295 EXPECT_EQ(0u, bitrate_bps); | |
296 } | 297 } |
297 | 298 |
298 void DelayBasedBweTest::RateIncreaseReorderingTestHelper( | 299 void DelayBasedBweTest::RateIncreaseReorderingTestHelper( |
299 uint32_t expected_bitrate_bps) { | 300 uint32_t expected_bitrate_bps) { |
300 const int kFramerate = 50; // 50 fps to avoid rounding errors. | 301 const int kFramerate = 50; // 50 fps to avoid rounding errors. |
301 const int kFrameIntervalMs = 1000 / kFramerate; | 302 const int kFrameIntervalMs = 1000 / kFramerate; |
302 int64_t send_time_ms = 0; | 303 int64_t send_time_ms = 0; |
303 uint16_t sequence_number = 0; | 304 uint16_t sequence_number = 0; |
304 // Inserting packets for five seconds to get a valid estimate. | 305 // Inserting packets for five seconds to get a valid estimate. |
305 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) { | 306 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) { |
| 307 // NOTE!!! If the following line is moved under the if case then this test |
| 308 // wont work on windows realease bots. |
| 309 int cluster_id = i < kInitialProbingPackets ? 0 : PacketInfo::kNotAProbe; |
| 310 |
306 // TODO(sprang): Remove this hack once the single stream estimator is gone, | 311 // TODO(sprang): Remove this hack once the single stream estimator is gone, |
307 // as it doesn't do anything in Process(). | 312 // as it doesn't do anything in Process(). |
308 if (i == kNumInitialPackets) { | 313 if (i == kNumInitialPackets) { |
309 // Process after we have enough frames to get a valid input rate estimate. | 314 // Process after we have enough frames to get a valid input rate estimate. |
310 bitrate_estimator_->Process(); | 315 bitrate_estimator_->Process(); |
311 EXPECT_FALSE(bitrate_observer_->updated()); // No valid estimate. | 316 EXPECT_FALSE(bitrate_observer_->updated()); // No valid estimate. |
312 } | 317 } |
313 | |
314 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, | 318 IncomingFeedback(clock_.TimeInMilliseconds(), send_time_ms, |
315 sequence_number++, kMtu); | 319 sequence_number++, kMtu, cluster_id); |
316 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); | 320 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); |
317 send_time_ms += kFrameIntervalMs; | 321 send_time_ms += kFrameIntervalMs; |
318 } | 322 } |
319 bitrate_estimator_->Process(); | 323 bitrate_estimator_->Process(); |
320 EXPECT_TRUE(bitrate_observer_->updated()); | 324 EXPECT_TRUE(bitrate_observer_->updated()); |
321 EXPECT_NEAR(expected_bitrate_bps, bitrate_observer_->latest_bitrate(), | 325 EXPECT_NEAR(expected_bitrate_bps, bitrate_observer_->latest_bitrate(), |
322 kAcceptedBitrateErrorBps); | 326 kAcceptedBitrateErrorBps); |
323 for (int i = 0; i < 10; ++i) { | 327 for (int i = 0; i < 10; ++i) { |
324 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); | 328 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); |
325 send_time_ms += 2 * kFrameIntervalMs; | 329 send_time_ms += 2 * kFrameIntervalMs; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 sequence_number++, 1000); | 495 sequence_number++, 1000); |
492 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); | 496 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); |
493 send_time_ms += kFrameIntervalMs; | 497 send_time_ms += kFrameIntervalMs; |
494 bitrate_estimator_->Process(); | 498 bitrate_estimator_->Process(); |
495 } | 499 } |
496 uint32_t bitrate_after = 0; | 500 uint32_t bitrate_after = 0; |
497 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after); | 501 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after); |
498 EXPECT_LT(bitrate_after, bitrate_before); | 502 EXPECT_LT(bitrate_after, bitrate_before); |
499 } | 503 } |
500 } // namespace webrtc | 504 } // namespace webrtc |
OLD | NEW |