Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(849)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest_helper.cc

Issue 2029593002: Update RateStatistics to handle too-little-data case. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comment Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_unitt est_helper.h" 10 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_unitt est_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 namespace webrtc { 16 namespace webrtc {
17 17
18 const size_t kMtu = 1200; 18 const size_t kMtu = 1200;
19 const uint32_t kAcceptedBitrateErrorBps = 50000; 19 const uint32_t kAcceptedBitrateErrorBps = 50000;
20 20
21 // Number of packets needed before we have a valid estimate.
22 const int kNumInitialPackets = 2;
23
21 namespace testing { 24 namespace testing {
22 25
23 void TestBitrateObserver::OnReceiveBitrateChanged( 26 void TestBitrateObserver::OnReceiveBitrateChanged(
24 const std::vector<uint32_t>& ssrcs, 27 const std::vector<uint32_t>& ssrcs,
25 uint32_t bitrate) { 28 uint32_t bitrate) {
26 latest_bitrate_ = bitrate; 29 latest_bitrate_ = bitrate;
27 updated_ = true; 30 updated_ = true;
28 } 31 }
29 32
30 RtpStream::RtpStream(int fps, 33 RtpStream::RtpStream(int fps,
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 uint32_t absolute_send_time = 0; 313 uint32_t absolute_send_time = 0;
311 std::vector<uint32_t> ssrcs; 314 std::vector<uint32_t> ssrcs;
312 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 315 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
313 EXPECT_EQ(0u, ssrcs.size()); 316 EXPECT_EQ(0u, ssrcs.size());
314 clock_.AdvanceTimeMilliseconds(1000); 317 clock_.AdvanceTimeMilliseconds(1000);
315 bitrate_estimator_->Process(); 318 bitrate_estimator_->Process();
316 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 319 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
317 EXPECT_FALSE(bitrate_observer_->updated()); 320 EXPECT_FALSE(bitrate_observer_->updated());
318 bitrate_observer_->Reset(); 321 bitrate_observer_->Reset();
319 clock_.AdvanceTimeMilliseconds(1000); 322 clock_.AdvanceTimeMilliseconds(1000);
320 // Inserting a packet. Still no valid estimate. We need to wait 5 seconds.
321 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp,
322 absolute_send_time, true);
323 bitrate_estimator_->Process();
324 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
325 EXPECT_EQ(0u, ssrcs.size());
326 EXPECT_FALSE(bitrate_observer_->updated());
327 bitrate_observer_->Reset();
328 // Inserting packets for 5 seconds to get a valid estimate. 323 // Inserting packets for 5 seconds to get a valid estimate.
329 for (int i = 0; i < 5 * kFramerate + 1; ++i) { 324 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) {
325 if (i == kNumInitialPackets) {
326 bitrate_estimator_->Process();
327 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
328 EXPECT_EQ(0u, ssrcs.size());
329 EXPECT_FALSE(bitrate_observer_->updated());
330 bitrate_observer_->Reset();
331 }
332
330 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp, 333 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp,
331 absolute_send_time, true); 334 absolute_send_time, true);
332 clock_.AdvanceTimeMilliseconds(1000 / kFramerate); 335 clock_.AdvanceTimeMilliseconds(1000 / kFramerate);
333 timestamp += 90 * kFrameIntervalMs; 336 timestamp += 90 * kFrameIntervalMs;
334 absolute_send_time = AddAbsSendTime(absolute_send_time, 337 absolute_send_time = AddAbsSendTime(absolute_send_time,
335 kFrameIntervalAbsSendTime); 338 kFrameIntervalAbsSendTime);
336 } 339 }
337 bitrate_estimator_->Process(); 340 bitrate_estimator_->Process();
338 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 341 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
339 ASSERT_EQ(1u, ssrcs.size()); 342 ASSERT_EQ(1u, ssrcs.size());
340 EXPECT_EQ(kDefaultSsrc, ssrcs.front()); 343 EXPECT_EQ(kDefaultSsrc, ssrcs.front());
341 EXPECT_NEAR(expected_converge_bitrate, bitrate_bps, kAcceptedBitrateErrorBps); 344 EXPECT_NEAR(expected_converge_bitrate, bitrate_bps, kAcceptedBitrateErrorBps);
342 EXPECT_TRUE(bitrate_observer_->updated()); 345 EXPECT_TRUE(bitrate_observer_->updated());
343 bitrate_observer_->Reset(); 346 bitrate_observer_->Reset();
344 EXPECT_EQ(bitrate_observer_->latest_bitrate(), bitrate_bps); 347 EXPECT_EQ(bitrate_observer_->latest_bitrate(), bitrate_bps);
345 bitrate_estimator_->RemoveStream(kDefaultSsrc); 348 bitrate_estimator_->RemoveStream(kDefaultSsrc);
346 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 349 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
347 ASSERT_EQ(0u, ssrcs.size()); 350 ASSERT_EQ(0u, ssrcs.size());
348 EXPECT_EQ(0u, bitrate_bps); 351 EXPECT_EQ(0u, bitrate_bps);
349 } 352 }
350 353
351 void RemoteBitrateEstimatorTest::RateIncreaseReorderingTestHelper( 354 void RemoteBitrateEstimatorTest::RateIncreaseReorderingTestHelper(
352 uint32_t expected_bitrate_bps) { 355 uint32_t expected_bitrate_bps) {
353 const int kFramerate = 50; // 50 fps to avoid rounding errors. 356 const int kFramerate = 50; // 50 fps to avoid rounding errors.
354 const int kFrameIntervalMs = 1000 / kFramerate; 357 const int kFrameIntervalMs = 1000 / kFramerate;
355 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate); 358 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate);
356 uint32_t timestamp = 0; 359 uint32_t timestamp = 0;
357 uint32_t absolute_send_time = 0; 360 uint32_t absolute_send_time = 0;
358 IncomingPacket(kDefaultSsrc, 1000, clock_.TimeInMilliseconds(), timestamp, 361 // Inserting packets for five seconds to get a valid estimate.
359 absolute_send_time, true); 362 for (int i = 0; i < 5 * kFramerate + 1 + kNumInitialPackets; ++i) {
360 bitrate_estimator_->Process(); 363 // TODO(sprang): Remove this hack once the single stream estimator is gone,
361 EXPECT_FALSE(bitrate_observer_->updated()); // No valid estimate. 364 // as it doesn't do anything in Process().
362 // Inserting packets for one second to get a valid estimate. 365 if (i == kNumInitialPackets) {
363 for (int i = 0; i < 5 * kFramerate + 1; ++i) { 366 // Process after we have enough frames to get a valid input rate estimate.
367 bitrate_estimator_->Process();
368 EXPECT_FALSE(bitrate_observer_->updated()); // No valid estimate.
369 }
370
364 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp, 371 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp,
365 absolute_send_time, true); 372 absolute_send_time, true);
366 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 373 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
367 timestamp += 90 * kFrameIntervalMs; 374 timestamp += 90 * kFrameIntervalMs;
368 absolute_send_time = AddAbsSendTime(absolute_send_time, 375 absolute_send_time = AddAbsSendTime(absolute_send_time,
369 kFrameIntervalAbsSendTime); 376 kFrameIntervalAbsSendTime);
370 } 377 }
371 bitrate_estimator_->Process(); 378 bitrate_estimator_->Process();
372 EXPECT_TRUE(bitrate_observer_->updated()); 379 EXPECT_TRUE(bitrate_observer_->updated());
373 EXPECT_NEAR(expected_bitrate_bps, 380 EXPECT_NEAR(expected_bitrate_bps,
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); 597 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs);
591 absolute_send_time = AddAbsSendTime(absolute_send_time, 598 absolute_send_time = AddAbsSendTime(absolute_send_time,
592 kFrameIntervalAbsSendTime); 599 kFrameIntervalAbsSendTime);
593 bitrate_estimator_->Process(); 600 bitrate_estimator_->Process();
594 } 601 }
595 uint32_t bitrate_after = 0; 602 uint32_t bitrate_after = 0;
596 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after); 603 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after);
597 EXPECT_LT(bitrate_after, bitrate_before); 604 EXPECT_LT(bitrate_after, bitrate_before);
598 } 605 }
599 } // namespace webrtc 606 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698