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

Side by Side Diff: webrtc/call/call_unittest.cc

Issue 2888303005: Add PeerConnectionInterface::UpdateCallBitrate. (Closed)
Patch Set: Implement SetBitrate in PeerConnectionInterface to avoid breaking chromium mock. Created 3 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 EXPECT_NE(stream, nullptr); 313 EXPECT_NE(stream, nullptr);
314 streams.push_back(stream); 314 streams.push_back(stream);
315 315
316 for (auto s : streams) { 316 for (auto s : streams) {
317 call->DestroyFlexfecReceiveStream(s); 317 call->DestroyFlexfecReceiveStream(s);
318 } 318 }
319 } 319 }
320 320
321 namespace { 321 namespace {
322 struct CallBitrateHelper { 322 struct CallBitrateHelper {
323 CallBitrateHelper() : CallBitrateHelper(Call::Config(&event_log_)) {} 323 CallBitrateHelper() : CallBitrateHelper(Call::Config::BitrateConfig()) {}
324 324
325 explicit CallBitrateHelper(const Call::Config& config) 325 explicit CallBitrateHelper(const Call::Config::BitrateConfig& bitrate_config)
326 : mock_cc_(Clock::GetRealTimeClock(), &event_log_, &packet_router_), 326 : mock_cc_(Clock::GetRealTimeClock(), &event_log_, &packet_router_) {
327 call_(Call::Create( 327 Call::Config config(&event_log_);
328 config, 328 config.bitrate_config = bitrate_config;
329 rtc::MakeUnique<FakeRtpTransportControllerSend>(&packet_router_, 329 call_.reset(
330 &mock_cc_))) {} 330 Call::Create(config, rtc::MakeUnique<FakeRtpTransportControllerSend>(
331 &packet_router_, &mock_cc_)));
332 }
331 333
332 webrtc::Call* operator->() { return call_.get(); } 334 webrtc::Call* operator->() { return call_.get(); }
333 testing::NiceMock<test::MockSendSideCongestionController>& mock_cc() { 335 testing::NiceMock<test::MockSendSideCongestionController>& mock_cc() {
334 return mock_cc_; 336 return mock_cc_;
335 } 337 }
336 338
337 private: 339 private:
338 webrtc::RtcEventLogNullImpl event_log_; 340 webrtc::RtcEventLogNullImpl event_log_;
339 PacketRouter packet_router_; 341 PacketRouter packet_router_;
340 testing::NiceMock<test::MockSendSideCongestionController> mock_cc_; 342 testing::NiceMock<test::MockSendSideCongestionController> mock_cc_;
(...skipping 16 matching lines...) Expand all
357 TEST(CallBitrateTest, SetBitrateConfigWithDifferentMinCallsSetBweBitrates) { 359 TEST(CallBitrateTest, SetBitrateConfigWithDifferentMinCallsSetBweBitrates) {
358 CallBitrateHelper call; 360 CallBitrateHelper call;
359 361
360 Call::Config::BitrateConfig bitrate_config; 362 Call::Config::BitrateConfig bitrate_config;
361 bitrate_config.min_bitrate_bps = 10; 363 bitrate_config.min_bitrate_bps = 10;
362 bitrate_config.start_bitrate_bps = 20; 364 bitrate_config.start_bitrate_bps = 20;
363 bitrate_config.max_bitrate_bps = 30; 365 bitrate_config.max_bitrate_bps = 30;
364 call->SetBitrateConfig(bitrate_config); 366 call->SetBitrateConfig(bitrate_config);
365 367
366 bitrate_config.min_bitrate_bps = 11; 368 bitrate_config.min_bitrate_bps = 11;
367 EXPECT_CALL(call.mock_cc(), SetBweBitrates(11, 20, 30)); 369 EXPECT_CALL(call.mock_cc(), SetBweBitrates(11, -1, 30));
368 call->SetBitrateConfig(bitrate_config); 370 call->SetBitrateConfig(bitrate_config);
369 } 371 }
370 372
371 TEST(CallBitrateTest, SetBitrateConfigWithDifferentStartCallsSetBweBitrates) { 373 TEST(CallBitrateTest, SetBitrateConfigWithDifferentStartCallsSetBweBitrates) {
372 CallBitrateHelper call; 374 CallBitrateHelper call;
373 375
374 Call::Config::BitrateConfig bitrate_config; 376 Call::Config::BitrateConfig bitrate_config;
375 bitrate_config.min_bitrate_bps = 10; 377 bitrate_config.min_bitrate_bps = 10;
376 bitrate_config.start_bitrate_bps = 20; 378 bitrate_config.start_bitrate_bps = 20;
377 bitrate_config.max_bitrate_bps = 30; 379 bitrate_config.max_bitrate_bps = 30;
378 call->SetBitrateConfig(bitrate_config); 380 call->SetBitrateConfig(bitrate_config);
379 381
380 bitrate_config.start_bitrate_bps = 21; 382 bitrate_config.start_bitrate_bps = 21;
381 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, 21, 30)); 383 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, 21, 30));
382 call->SetBitrateConfig(bitrate_config); 384 call->SetBitrateConfig(bitrate_config);
383 } 385 }
384 386
385 TEST(CallBitrateTest, SetBitrateConfigWithDifferentMaxCallsSetBweBitrates) { 387 TEST(CallBitrateTest, SetBitrateConfigWithDifferentMaxCallsSetBweBitrates) {
386 CallBitrateHelper call; 388 CallBitrateHelper call;
387 389
388 Call::Config::BitrateConfig bitrate_config; 390 Call::Config::BitrateConfig bitrate_config;
389 bitrate_config.min_bitrate_bps = 10; 391 bitrate_config.min_bitrate_bps = 10;
390 bitrate_config.start_bitrate_bps = 20; 392 bitrate_config.start_bitrate_bps = 20;
391 bitrate_config.max_bitrate_bps = 30; 393 bitrate_config.max_bitrate_bps = 30;
392 call->SetBitrateConfig(bitrate_config); 394 call->SetBitrateConfig(bitrate_config);
393 395
394 bitrate_config.max_bitrate_bps = 31; 396 bitrate_config.max_bitrate_bps = 31;
395 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, 20, 31)); 397 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, -1, 31));
396 call->SetBitrateConfig(bitrate_config); 398 call->SetBitrateConfig(bitrate_config);
397 } 399 }
398 400
399 TEST(CallBitrateTest, SetBitrateConfigWithSameConfigElidesSecondCall) { 401 TEST(CallBitrateTest, SetBitrateConfigWithSameConfigElidesSecondCall) {
400 CallBitrateHelper call; 402 CallBitrateHelper call;
401
402 Call::Config::BitrateConfig bitrate_config; 403 Call::Config::BitrateConfig bitrate_config;
403 bitrate_config.min_bitrate_bps = 1; 404 bitrate_config.min_bitrate_bps = 1;
404 bitrate_config.start_bitrate_bps = 2; 405 bitrate_config.start_bitrate_bps = 2;
405 bitrate_config.max_bitrate_bps = 3; 406 bitrate_config.max_bitrate_bps = 3;
406 407
407 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1); 408 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1);
408 call->SetBitrateConfig(bitrate_config); 409 call->SetBitrateConfig(bitrate_config);
409 call->SetBitrateConfig(bitrate_config); 410 call->SetBitrateConfig(bitrate_config);
410 } 411 }
411 412
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC); 483 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC);
483 484
484 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number); 485 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number);
485 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp); 486 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp);
486 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp); 487 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp);
487 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms); 488 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms);
488 EXPECT_EQ(rtp_state1.last_timestamp_time_ms, 489 EXPECT_EQ(rtp_state1.last_timestamp_time_ms,
489 rtp_state2.last_timestamp_time_ms); 490 rtp_state2.last_timestamp_time_ms);
490 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent); 491 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent);
491 } 492 }
493 TEST(CallBitrateTest, BiggerMaskMinUsed) {
494 CallBitrateHelper call;
495 Call::Config::BitrateConfigMask mask;
496 mask.min_bitrate_bps = rtc::Optional<int>(1234);
497
498 EXPECT_CALL(call.mock_cc(),
499 SetBweBitrates(*mask.min_bitrate_bps, testing::_, testing::_));
500 call->SetBitrateConfigMask(mask);
501 }
502
503 TEST(CallBitrateTest, BiggerConfigMinUsed) {
504 CallBitrateHelper call;
505 Call::Config::BitrateConfigMask mask;
506 mask.min_bitrate_bps = rtc::Optional<int>(1000);
507 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, testing::_));
508 call->SetBitrateConfigMask(mask);
509
510 Call::Config::BitrateConfig config;
511 config.min_bitrate_bps = 1234;
512
513 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1234, testing::_, testing::_));
514 call->SetBitrateConfig(config);
515 }
516
517 // The last call to set start should be used.
518 TEST(CallBitrateTest, LatestStartMaskPreferred) {
519 CallBitrateHelper call;
520 Call::Config::BitrateConfigMask mask;
521 mask.start_bitrate_bps = rtc::Optional<int>(1300);
522
523 EXPECT_CALL(call.mock_cc(),
524 SetBweBitrates(testing::_, *mask.start_bitrate_bps, testing::_));
525 call->SetBitrateConfigMask(mask);
526
527 Call::Config::BitrateConfig bitrate_config;
528 bitrate_config.start_bitrate_bps = 1200;
529
530 EXPECT_CALL(
531 call.mock_cc(),
532 SetBweBitrates(testing::_, bitrate_config.start_bitrate_bps, testing::_));
533 call->SetBitrateConfig(bitrate_config);
534 }
535
536 TEST(CallBitrateTest, SmallerMaskMaxUsed) {
537 Call::Config::BitrateConfig bitrate_config;
538 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 2000;
539 CallBitrateHelper call(bitrate_config);
540
541 Call::Config::BitrateConfigMask mask;
542 mask.max_bitrate_bps =
543 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 1000);
544
545 EXPECT_CALL(call.mock_cc(),
546 SetBweBitrates(testing::_, testing::_, *mask.max_bitrate_bps));
547 call->SetBitrateConfigMask(mask);
548 }
549
550 TEST(CallBitrateTest, SmallerConfigMaxUsed) {
551 Call::Config::BitrateConfig bitrate_config;
552 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 1000;
553 CallBitrateHelper call(bitrate_config);
554
555 Call::Config::BitrateConfigMask mask;
556 mask.max_bitrate_bps =
557 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 2000);
558
559 // Expect no calls because nothing changes
560 EXPECT_CALL(call.mock_cc(),
561 SetBweBitrates(testing::_, testing::_, testing::_))
562 .Times(0);
563 call->SetBitrateConfigMask(mask);
564 }
565
566 TEST(CallBitrateTest, MaskStartLessThanConfigMinClamped) {
567 Call::Config::BitrateConfig bitrate_config;
568 bitrate_config.min_bitrate_bps = 2000;
569 CallBitrateHelper call(bitrate_config);
570
571 Call::Config::BitrateConfigMask mask;
572 mask.start_bitrate_bps = rtc::Optional<int>(1000);
573
574 EXPECT_CALL(call.mock_cc(), SetBweBitrates(2000, 2000, testing::_));
575 call->SetBitrateConfigMask(mask);
576 }
577
578 TEST(CallBitrateTest, MaskStartGreaterThanConfigMaxClamped) {
579 Call::Config::BitrateConfig bitrate_config;
580 bitrate_config.start_bitrate_bps = 2000;
581 CallBitrateHelper call(bitrate_config);
582
583 Call::Config::BitrateConfigMask mask;
584 mask.max_bitrate_bps = rtc::Optional<int>(1000);
585
586 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, -1, 1000));
587 call->SetBitrateConfigMask(mask);
588 }
589
590 TEST(CallBitrateTest, MaskMinGreaterThanConfigMaxClamped) {
591 Call::Config::BitrateConfig bitrate_config;
592 bitrate_config.min_bitrate_bps = 2000;
593 CallBitrateHelper call(bitrate_config);
594
595 Call::Config::BitrateConfigMask mask;
596 mask.max_bitrate_bps = rtc::Optional<int>(1000);
597
598 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, 1000));
599 call->SetBitrateConfigMask(mask);
600 }
601
602 TEST(CallBitrateTest, SettingMaskStartForcesUpdate) {
603 CallBitrateHelper call;
604
605 Call::Config::BitrateConfigMask mask;
606 mask.start_bitrate_bps = rtc::Optional<int>(1000);
607
608 // SetBweBitrates should be called twice with the same params since
609 // start_bitrate_bps is set.
610 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, 1000, testing::_))
611 .Times(2);
612 call->SetBitrateConfigMask(mask);
613 call->SetBitrateConfigMask(mask);
614 }
615
616 TEST(CallBitrateTest, SetBitrateConfigWithNoChangesDoesNotCallSetBweBitrates) {
617 CallBitrateHelper call;
618
619 Call::Config::BitrateConfig config1;
620 config1.min_bitrate_bps = 0;
621 config1.start_bitrate_bps = 1000;
622 config1.max_bitrate_bps = -1;
623
624 Call::Config::BitrateConfig config2;
625 config2.min_bitrate_bps = 0;
626 config2.start_bitrate_bps = -1;
627 config2.max_bitrate_bps = -1;
628
629 // The second call should not call SetBweBitrates because it doesn't
630 // change any values.
631 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
632 call->SetBitrateConfig(config1);
633 call->SetBitrateConfig(config2);
634 }
635
636 // If SetBitrateConfig changes the max, but not the effective max,
637 // SetBweBitrates shouldn't be called, to avoid unnecessary encoder
638 // reconfigurations.
639 TEST(CallBitrateTest, SetBweBitratesNotCalledWhenEffectiveMaxUnchanged) {
640 CallBitrateHelper call;
641
642 Call::Config::BitrateConfig config;
643 config.min_bitrate_bps = 0;
644 config.start_bitrate_bps = -1;
645 config.max_bitrate_bps = 2000;
646 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 2000));
647 call->SetBitrateConfig(config);
648
649 // Reduce effective max to 1000 with the mask.
650 Call::Config::BitrateConfigMask mask;
651 mask.max_bitrate_bps = rtc::Optional<int>(1000);
652 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 1000));
653 call->SetBitrateConfigMask(mask);
654
655 // This leaves the effective max unchanged, so SetBweBitrates shouldn't be
656 // called again.
657 config.max_bitrate_bps = 1000;
658 call->SetBitrateConfig(config);
659 }
660
661 // When the "start bitrate" mask is removed, SetBweBitrates shouldn't be called
662 // again, since nothing's changing.
663 TEST(CallBitrateTest, SetBweBitratesNotCalledWhenStartMaskRemoved) {
664 CallBitrateHelper call;
665
666 Call::Config::BitrateConfigMask mask;
667 mask.start_bitrate_bps = rtc::Optional<int>(1000);
668 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
669 call->SetBitrateConfigMask(mask);
670
671 mask.start_bitrate_bps.reset();
672 call->SetBitrateConfigMask(mask);
673 }
674
675 // Test that if SetBitrateConfig is called after SetBitrateConfigMask applies a
676 // "start" value, the SetBitrateConfig call won't apply that start value a
677 // second time.
678 TEST(CallBitrateTest, SetBitrateConfigAfterSetBitrateConfigMaskWithStart) {
679 CallBitrateHelper call;
680
681 Call::Config::BitrateConfigMask mask;
682 mask.start_bitrate_bps = rtc::Optional<int>(1000);
683 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
684 call->SetBitrateConfigMask(mask);
685
686 Call::Config::BitrateConfig config;
687 config.min_bitrate_bps = 0;
688 config.start_bitrate_bps = -1;
689 config.max_bitrate_bps = 5000;
690 // The start value isn't changing, so SetBweBitrates should be called with
691 // -1.
692 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, -1, 5000));
693 call->SetBitrateConfig(config);
694 }
695
696 TEST(CallBitrateTest, SetBweBitratesNotCalledWhenClampedMinUnchanged) {
697 Call::Config::BitrateConfig bitrate_config;
698 bitrate_config.start_bitrate_bps = 500;
699 bitrate_config.max_bitrate_bps = 1000;
700 CallBitrateHelper call(bitrate_config);
701
702 // Set min to 2000; it is clamped to the max (1000).
703 Call::Config::BitrateConfigMask mask;
704 mask.min_bitrate_bps = rtc::Optional<int>(2000);
705 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, -1, 1000));
706 call->SetBitrateConfigMask(mask);
707
708 // Set min to 3000; the clamped value stays the same so nothing happens.
709 mask.min_bitrate_bps = rtc::Optional<int>(3000);
710 call->SetBitrateConfigMask(mask);
711 }
492 712
493 } // namespace webrtc 713 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698