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

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

Issue 1219303002: Fix issue where the first audio packets significantly impacts initial BWE negatively. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed. Created 5 years, 5 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"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 uint32_t absolute_send_time = 0; 313 uint32_t absolute_send_time = 0;
314 std::vector<unsigned int> ssrcs; 314 std::vector<unsigned int> ssrcs;
315 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 315 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
316 EXPECT_EQ(0u, ssrcs.size()); 316 EXPECT_EQ(0u, ssrcs.size());
317 clock_.AdvanceTimeMilliseconds(1000); 317 clock_.AdvanceTimeMilliseconds(1000);
318 bitrate_estimator_->Process(); 318 bitrate_estimator_->Process();
319 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 319 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
320 EXPECT_FALSE(bitrate_observer_->updated()); 320 EXPECT_FALSE(bitrate_observer_->updated());
321 bitrate_observer_->Reset(); 321 bitrate_observer_->Reset();
322 clock_.AdvanceTimeMilliseconds(1000); 322 clock_.AdvanceTimeMilliseconds(1000);
323 // Inserting a packet. Still no valid estimate. We need to wait 1 second. 323 // Inserting a packet. Still no valid estimate. We need to wait 5 seconds.
324 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp, 324 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp,
325 absolute_send_time, true); 325 absolute_send_time, true);
326 bitrate_estimator_->Process(); 326 bitrate_estimator_->Process();
327 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 327 EXPECT_FALSE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
328 EXPECT_EQ(0u, ssrcs.size()); 328 EXPECT_EQ(0u, ssrcs.size());
329 EXPECT_FALSE(bitrate_observer_->updated()); 329 EXPECT_FALSE(bitrate_observer_->updated());
330 bitrate_observer_->Reset(); 330 bitrate_observer_->Reset();
331 // Inserting packets for one second to get a valid estimate. 331 // Inserting packets for 5 seconds to get a valid estimate.
332 for (int i = 0; i < kFramerate; ++i) { 332 for (int i = 0; i < 5 * kFramerate + 1; ++i) {
333 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp, 333 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp,
334 absolute_send_time, true); 334 absolute_send_time, true);
335 clock_.AdvanceTimeMilliseconds(1000 / kFramerate); 335 clock_.AdvanceTimeMilliseconds(1000 / kFramerate);
336 timestamp += 90 * kFrameIntervalMs; 336 timestamp += 90 * kFrameIntervalMs;
337 absolute_send_time = AddAbsSendTime(absolute_send_time, 337 absolute_send_time = AddAbsSendTime(absolute_send_time,
338 kFrameIntervalAbsSendTime); 338 kFrameIntervalAbsSendTime);
339 } 339 }
340 bitrate_estimator_->Process(); 340 bitrate_estimator_->Process();
341 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps)); 341 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_bps));
342 ASSERT_EQ(1u, ssrcs.size()); 342 ASSERT_EQ(1u, ssrcs.size());
(...skipping 13 matching lines...) Expand all
356 const int kFramerate = 50; // 50 fps to avoid rounding errors. 356 const int kFramerate = 50; // 50 fps to avoid rounding errors.
357 const int kFrameIntervalMs = 1000 / kFramerate; 357 const int kFrameIntervalMs = 1000 / kFramerate;
358 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate); 358 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate);
359 uint32_t timestamp = 0; 359 uint32_t timestamp = 0;
360 uint32_t absolute_send_time = 0; 360 uint32_t absolute_send_time = 0;
361 IncomingPacket(kDefaultSsrc, 1000, clock_.TimeInMilliseconds(), timestamp, 361 IncomingPacket(kDefaultSsrc, 1000, clock_.TimeInMilliseconds(), timestamp,
362 absolute_send_time, true); 362 absolute_send_time, true);
363 bitrate_estimator_->Process(); 363 bitrate_estimator_->Process();
364 EXPECT_FALSE(bitrate_observer_->updated()); // No valid estimate. 364 EXPECT_FALSE(bitrate_observer_->updated()); // No valid estimate.
365 // Inserting packets for one second to get a valid estimate. 365 // Inserting packets for one second to get a valid estimate.
366 for (int i = 0; i < kFramerate; ++i) { 366 for (int i = 0; i < 5 * kFramerate + 1; ++i) {
367 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp, 367 IncomingPacket(kDefaultSsrc, kMtu, clock_.TimeInMilliseconds(), timestamp,
368 absolute_send_time, true); 368 absolute_send_time, true);
369 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 369 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
370 timestamp += 90 * kFrameIntervalMs; 370 timestamp += 90 * kFrameIntervalMs;
371 absolute_send_time = AddAbsSendTime(absolute_send_time, 371 absolute_send_time = AddAbsSendTime(absolute_send_time,
372 kFrameIntervalAbsSendTime); 372 kFrameIntervalAbsSendTime);
373 } 373 }
374 bitrate_estimator_->Process(); 374 bitrate_estimator_->Process();
375 EXPECT_TRUE(bitrate_observer_->updated()); 375 EXPECT_TRUE(bitrate_observer_->updated());
376 EXPECT_NEAR(expected_bitrate_bps, 376 EXPECT_NEAR(expected_bitrate_bps,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 const int kMinExpectedBitrate = 800e3; 432 const int kMinExpectedBitrate = 800e3;
433 const int kMaxExpectedBitrate = 1100e3; 433 const int kMaxExpectedBitrate = 1100e3;
434 const unsigned int kInitialCapacityBps = 1000e3; 434 const unsigned int kInitialCapacityBps = 1000e3;
435 const unsigned int kReducedCapacityBps = 500e3; 435 const unsigned int kReducedCapacityBps = 500e3;
436 436
437 int steady_state_time = 0; 437 int steady_state_time = 0;
438 if (number_of_streams <= 1) { 438 if (number_of_streams <= 1) {
439 steady_state_time = 10; 439 steady_state_time = 10;
440 AddDefaultStream(); 440 AddDefaultStream();
441 } else { 441 } else {
442 steady_state_time = 8 * number_of_streams; 442 steady_state_time = 10 * number_of_streams;
443 int bitrate_sum = 0; 443 int bitrate_sum = 0;
444 int kBitrateDenom = number_of_streams * (number_of_streams - 1); 444 int kBitrateDenom = number_of_streams * (number_of_streams - 1);
445 for (int i = 0; i < number_of_streams; i++) { 445 for (int i = 0; i < number_of_streams; i++) {
446 // First stream gets half available bitrate, while the rest share the 446 // First stream gets half available bitrate, while the rest share the
447 // remaining half i.e.: 1/2 = Sum[n/(N*(N-1))] for n=1..N-1 (rounded up) 447 // remaining half i.e.: 1/2 = Sum[n/(N*(N-1))] for n=1..N-1 (rounded up)
448 int bitrate = kStartBitrate / 2; 448 int bitrate = kStartBitrate / 2;
449 if (i > 0) { 449 if (i > 0) {
450 bitrate = (kStartBitrate * i + kBitrateDenom / 2) / kBitrateDenom; 450 bitrate = (kStartBitrate * i + kBitrateDenom / 2) / kBitrateDenom;
451 } 451 }
452 stream_generator_->AddStream(new testing::RtpStream( 452 stream_generator_->AddStream(new testing::RtpStream(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (bitrate_observer_->updated()) { 486 if (bitrate_observer_->updated()) {
487 if (bitrate_drop_time == -1 && 487 if (bitrate_drop_time == -1 &&
488 bitrate_observer_->latest_bitrate() <= kReducedCapacityBps) { 488 bitrate_observer_->latest_bitrate() <= kReducedCapacityBps) {
489 bitrate_drop_time = clock_.TimeInMilliseconds(); 489 bitrate_drop_time = clock_.TimeInMilliseconds();
490 } 490 }
491 bitrate_bps = bitrate_observer_->latest_bitrate(); 491 bitrate_bps = bitrate_observer_->latest_bitrate();
492 bitrate_observer_->Reset(); 492 bitrate_observer_->Reset();
493 } 493 }
494 } 494 }
495 495
496 EXPECT_EQ(expected_bitrate_drop_delta, 496 EXPECT_NEAR(expected_bitrate_drop_delta,
497 bitrate_drop_time - overuse_start_time); 497 bitrate_drop_time - overuse_start_time, 33);
498 498
499 // Remove stream one by one. 499 // Remove stream one by one.
500 unsigned int latest_bps = 0; 500 unsigned int latest_bps = 0;
501 std::vector<unsigned int> ssrcs; 501 std::vector<unsigned int> ssrcs;
502 for (int i = 0; i < number_of_streams; i++) { 502 for (int i = 0; i < number_of_streams; i++) {
503 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &latest_bps)); 503 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &latest_bps));
504 EXPECT_EQ(number_of_streams - i, static_cast<int>(ssrcs.size())); 504 EXPECT_EQ(number_of_streams - i, static_cast<int>(ssrcs.size()));
505 EXPECT_EQ(bitrate_bps, latest_bps); 505 EXPECT_EQ(bitrate_bps, latest_bps);
506 for (int j = i; j < number_of_streams; j++) { 506 for (int j = i; j < number_of_streams; j++) {
507 EXPECT_EQ(kDefaultSsrc + j, ssrcs[j - i]); 507 EXPECT_EQ(kDefaultSsrc + j, ssrcs[j - i]);
508 } 508 }
509 bitrate_estimator_->RemoveStream(kDefaultSsrc + i); 509 bitrate_estimator_->RemoveStream(kDefaultSsrc + i);
510 } 510 }
511 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &latest_bps)); 511 EXPECT_TRUE(bitrate_estimator_->LatestEstimate(&ssrcs, &latest_bps));
512 EXPECT_EQ(0u, ssrcs.size()); 512 EXPECT_EQ(0u, ssrcs.size());
513 EXPECT_EQ(0u, latest_bps); 513 EXPECT_EQ(0u, latest_bps);
514 } 514 }
515 515
516 void RemoteBitrateEstimatorTest::TestTimestampGroupingTestHelper( 516 void RemoteBitrateEstimatorTest::TestTimestampGroupingTestHelper() {
517 uint32_t bitrate_bps) {
518 const int kFramerate = 50; // 50 fps to avoid rounding errors. 517 const int kFramerate = 50; // 50 fps to avoid rounding errors.
519 const int kFrameIntervalMs = 1000 / kFramerate; 518 const int kFrameIntervalMs = 1000 / kFramerate;
520 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate); 519 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate);
521 uint32_t timestamp = 0; 520 uint32_t timestamp = 0;
522 // Initialize absolute_send_time (24 bits) so that it will definitely wrap 521 // Initialize absolute_send_time (24 bits) so that it will definitely wrap
523 // during the test. 522 // during the test.
524 uint32_t absolute_send_time = 523 uint32_t absolute_send_time =
525 AddAbsSendTime((1 << 24), -int(50 * kFrameIntervalAbsSendTime)); 524 AddAbsSendTime((1 << 24), -int(50 * kFrameIntervalAbsSendTime));
526 // Initial set of frames to increase the bitrate. 525 // Initial set of frames to increase the bitrate. 6 seconds to have enough
527 for (int i = 0; i <= 100; ++i) { 526 // time for the first estimate to be generated and for Process() to be called.
527 for (int i = 0; i <= 6 * kFramerate; ++i) {
528 IncomingPacket(kDefaultSsrc, 1000, clock_.TimeInMilliseconds(), timestamp, 528 IncomingPacket(kDefaultSsrc, 1000, clock_.TimeInMilliseconds(), timestamp,
529 absolute_send_time, true); 529 absolute_send_time, true);
530 bitrate_estimator_->Process(); 530 bitrate_estimator_->Process();
531 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 531 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
532 timestamp += 90 * kFrameIntervalMs; 532 timestamp += 90 * kFrameIntervalMs;
533 absolute_send_time = AddAbsSendTime(absolute_send_time, 533 absolute_send_time = AddAbsSendTime(absolute_send_time,
534 kFrameIntervalAbsSendTime); 534 kFrameIntervalAbsSendTime);
535 } 535 }
536 EXPECT_TRUE(bitrate_observer_->updated()); 536 EXPECT_TRUE(bitrate_observer_->updated());
537 EXPECT_NEAR(470000u, bitrate_observer_->latest_bitrate(), 10000u); 537 EXPECT_GE(bitrate_observer_->latest_bitrate(), 400000u);
538 538
539 // Insert batches of frames which were sent very close in time. Also simulate 539 // Insert batches of frames which were sent very close in time. Also simulate
540 // capacity over-use to see that we back off correctly. 540 // capacity over-use to see that we back off correctly.
541 const int kTimestampGroupLength = 15; 541 const int kTimestampGroupLength = 15;
542 const uint32_t kTimestampGroupLengthAbsSendTime = 542 const uint32_t kTimestampGroupLengthAbsSendTime =
543 AbsSendTime(kTimestampGroupLength, 90000); 543 AbsSendTime(kTimestampGroupLength, 90000);
544 const uint32_t kSingleRtpTickAbsSendTime = AbsSendTime(1, 90000); 544 const uint32_t kSingleRtpTickAbsSendTime = AbsSendTime(1, 90000);
545 for (int i = 0; i < 100; ++i) { 545 for (int i = 0; i < 100; ++i) {
546 for (int j = 0; j < kTimestampGroupLength; ++j) { 546 for (int j = 0; j < kTimestampGroupLength; ++j) {
547 // Insert |kTimestampGroupLength| frames with just 1 timestamp ticks in 547 // Insert |kTimestampGroupLength| frames with just 1 timestamp ticks in
548 // between. Should be treated as part of the same group by the estimator. 548 // between. Should be treated as part of the same group by the estimator.
549 IncomingPacket(kDefaultSsrc, 100, clock_.TimeInMilliseconds(), timestamp, 549 IncomingPacket(kDefaultSsrc, 100, clock_.TimeInMilliseconds(), timestamp,
550 absolute_send_time, true); 550 absolute_send_time, true);
551 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs / kTimestampGroupLength); 551 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs / kTimestampGroupLength);
552 timestamp += 1; 552 timestamp += 1;
553 absolute_send_time = AddAbsSendTime(absolute_send_time, 553 absolute_send_time = AddAbsSendTime(absolute_send_time,
554 kSingleRtpTickAbsSendTime); 554 kSingleRtpTickAbsSendTime);
555 } 555 }
556 // Increase time until next batch to simulate over-use. 556 // Increase time until next batch to simulate over-use.
557 clock_.AdvanceTimeMilliseconds(10); 557 clock_.AdvanceTimeMilliseconds(10);
558 timestamp += 90 * kFrameIntervalMs - kTimestampGroupLength; 558 timestamp += 90 * kFrameIntervalMs - kTimestampGroupLength;
559 absolute_send_time = AddAbsSendTime(absolute_send_time, AddAbsSendTime( 559 absolute_send_time = AddAbsSendTime(absolute_send_time, AddAbsSendTime(
560 kFrameIntervalAbsSendTime, -int(kTimestampGroupLengthAbsSendTime))); 560 kFrameIntervalAbsSendTime, -int(kTimestampGroupLengthAbsSendTime)));
561 bitrate_estimator_->Process(); 561 bitrate_estimator_->Process();
562 } 562 }
563 EXPECT_TRUE(bitrate_observer_->updated()); 563 EXPECT_TRUE(bitrate_observer_->updated());
564 // Should have reduced the estimate. 564 // Should have reduced the estimate.
565 EXPECT_EQ(bitrate_bps, bitrate_observer_->latest_bitrate()); 565 EXPECT_LT(bitrate_observer_->latest_bitrate(), 400000u);
566 } 566 }
567 567
568 void RemoteBitrateEstimatorTest::TestGetStatsHelper() { 568 void RemoteBitrateEstimatorTest::TestGetStatsHelper() {
569 const int kFramerate = 100; 569 const int kFramerate = 100;
570 const int kFrameIntervalMs = 1000 / kFramerate; 570 const int kFrameIntervalMs = 1000 / kFramerate;
571 const int kBurstThresholdMs = 5; 571 const int kBurstThresholdMs = 5;
572 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate); 572 const uint32_t kFrameIntervalAbsSendTime = AbsSendTime(1, kFramerate);
573 uint32_t timestamp = 0; 573 uint32_t timestamp = 0;
574 // Initialize absolute_send_time (24 bits) so that it will definitely wrap 574 // Initialize absolute_send_time (24 bits) so that it will definitely wrap
575 // during the test. 575 // during the test.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs); 658 clock_.AdvanceTimeMilliseconds(2 * kFrameIntervalMs);
659 absolute_send_time = AddAbsSendTime(absolute_send_time, 659 absolute_send_time = AddAbsSendTime(absolute_send_time,
660 kFrameIntervalAbsSendTime); 660 kFrameIntervalAbsSendTime);
661 bitrate_estimator_->Process(); 661 bitrate_estimator_->Process();
662 } 662 }
663 unsigned int bitrate_after = 0; 663 unsigned int bitrate_after = 0;
664 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after); 664 bitrate_estimator_->LatestEstimate(&ssrcs, &bitrate_after);
665 EXPECT_LT(bitrate_after, bitrate_before); 665 EXPECT_LT(bitrate_after, bitrate_before);
666 } 666 }
667 } // namespace webrtc 667 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest_helper.h ('k') | webrtc/video/rampup_tests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698