OLD | NEW |
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 |
11 #include <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "webrtc/modules/pacing/packet_router.h" | 14 #include "webrtc/modules/pacing/packet_router.h" |
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
16 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" | 16 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
18 #include "webrtc/rtc_base/checks.h" | 18 #include "webrtc/rtc_base/checks.h" |
19 #include "webrtc/rtc_base/fakeclock.h" | 19 #include "webrtc/rtc_base/fakeclock.h" |
20 #include "webrtc/test/gmock.h" | 20 #include "webrtc/test/gmock.h" |
21 #include "webrtc/test/gtest.h" | 21 #include "webrtc/test/gtest.h" |
22 | 22 |
23 using ::testing::_; | |
24 using ::testing::AnyNumber; | |
25 using ::testing::Field; | |
26 using ::testing::NiceMock; | |
27 using ::testing::Return; | |
28 using ::testing::ReturnPointee; | |
29 using ::testing::SaveArg; | |
30 | |
31 namespace webrtc { | 23 namespace webrtc { |
32 | 24 |
33 // TODO(eladalon): Restructure and/or replace the existing monolithic tests | 25 // TODO(eladalon): Restructure and/or replace the existing monolithic tests |
34 // (only some of the test are monolithic) according to the new | 26 // (only some of the test are monolithic) according to the new |
35 // guidelines - small tests for one thing at a time. | 27 // guidelines - small tests for one thing at a time. |
36 // (I'm not removing any tests during CL, so as to demonstrate no regressions.) | 28 // (I'm not removing any tests during CL, so as to demonstrate no regressions.) |
37 | 29 |
38 namespace { | 30 namespace { |
| 31 |
| 32 using ::testing::_; |
| 33 using ::testing::AnyNumber; |
| 34 using ::testing::AtLeast; |
| 35 using ::testing::Field; |
| 36 using ::testing::Gt; |
| 37 using ::testing::Le; |
| 38 using ::testing::NiceMock; |
| 39 using ::testing::Return; |
| 40 using ::testing::ReturnPointee; |
| 41 using ::testing::SaveArg; |
| 42 |
39 constexpr int kProbeMinProbes = 5; | 43 constexpr int kProbeMinProbes = 5; |
40 constexpr int kProbeMinBytes = 1000; | 44 constexpr int kProbeMinBytes = 1000; |
41 | 45 |
42 class MockRtpRtcpWithRembTracking : public MockRtpRtcp { | 46 class MockRtpRtcpWithRembTracking : public MockRtpRtcp { |
43 public: | 47 public: |
44 MockRtpRtcpWithRembTracking() { | 48 MockRtpRtcpWithRembTracking() { |
45 ON_CALL(*this, SetREMBStatus(_)).WillByDefault(SaveArg<0>(&remb_)); | 49 ON_CALL(*this, SetREMBStatus(_)).WillByDefault(SaveArg<0>(&remb_)); |
46 ON_CALL(*this, REMB()).WillByDefault(ReturnPointee(&remb_)); | 50 ON_CALL(*this, REMB()).WillByDefault(ReturnPointee(&remb_)); |
47 } | 51 } |
48 | 52 |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 bitrate_estimate = bitrate_estimate - 100; | 559 bitrate_estimate = bitrate_estimate - 100; |
556 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 560 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
557 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 561 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
558 | 562 |
559 // Call OnReceiveBitrateChanged again, this should not trigger a new callback. | 563 // Call OnReceiveBitrateChanged again, this should not trigger a new callback. |
560 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); | 564 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
561 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 565 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
562 packet_router.RemoveSendRtpModule(&rtp); | 566 packet_router.RemoveSendRtpModule(&rtp); |
563 } | 567 } |
564 | 568 |
| 569 TEST(PacketRouterRembTest, SetMaxDesiredReceiveBitrateLimitsSetREMBData) { |
| 570 rtc::ScopedFakeClock clock; |
| 571 PacketRouter packet_router; |
| 572 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 573 NiceMock<MockRtpRtcpWithRembTracking> remb_sender; |
| 574 constexpr bool remb_candidate = true; |
| 575 packet_router.AddSendRtpModule(&remb_sender, remb_candidate); |
| 576 ASSERT_TRUE(remb_sender.REMB()); |
| 577 |
| 578 const uint32_t cap_bitrate = 100000; |
| 579 EXPECT_CALL(remb_sender, SetREMBData(Le(cap_bitrate), _)).Times(AtLeast(1)); |
| 580 EXPECT_CALL(remb_sender, SetREMBData(Gt(cap_bitrate), _)).Times(0); |
| 581 |
| 582 const std::vector<uint32_t> ssrcs = {1234}; |
| 583 packet_router.SetMaxDesiredReceiveBitrate(cap_bitrate); |
| 584 packet_router.OnReceiveBitrateChanged(ssrcs, cap_bitrate + 5000); |
| 585 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 586 packet_router.OnReceiveBitrateChanged(ssrcs, cap_bitrate - 5000); |
| 587 |
| 588 // Test tear-down. |
| 589 packet_router.RemoveSendRtpModule(&remb_sender); |
| 590 } |
| 591 |
| 592 TEST(PacketRouterRembTest, |
| 593 SetMaxDesiredReceiveBitrateTriggersRembWhenMoreRestrictive) { |
| 594 rtc::ScopedFakeClock clock; |
| 595 PacketRouter packet_router; |
| 596 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 597 NiceMock<MockRtpRtcpWithRembTracking> remb_sender; |
| 598 constexpr bool remb_candidate = true; |
| 599 packet_router.AddSendRtpModule(&remb_sender, remb_candidate); |
| 600 ASSERT_TRUE(remb_sender.REMB()); |
| 601 |
| 602 const uint32_t measured_bitrate_bps = 150000; |
| 603 const uint32_t cap_bitrate_bps = measured_bitrate_bps - 5000; |
| 604 const std::vector<uint32_t> ssrcs = {1234}; |
| 605 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _)); |
| 606 packet_router.OnReceiveBitrateChanged(ssrcs, measured_bitrate_bps); |
| 607 |
| 608 EXPECT_CALL(remb_sender, SetREMBData(cap_bitrate_bps, _)); |
| 609 packet_router.SetMaxDesiredReceiveBitrate(cap_bitrate_bps); |
| 610 |
| 611 // Test tear-down. |
| 612 packet_router.RemoveSendRtpModule(&remb_sender); |
| 613 } |
| 614 |
| 615 TEST(PacketRouterRembTest, |
| 616 SetMaxDesiredReceiveBitrateDoesNotTriggerRembWhenAsRestrictive) { |
| 617 rtc::ScopedFakeClock clock; |
| 618 PacketRouter packet_router; |
| 619 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 620 NiceMock<MockRtpRtcpWithRembTracking> remb_sender; |
| 621 constexpr bool remb_candidate = true; |
| 622 packet_router.AddSendRtpModule(&remb_sender, remb_candidate); |
| 623 ASSERT_TRUE(remb_sender.REMB()); |
| 624 |
| 625 const uint32_t measured_bitrate_bps = 150000; |
| 626 const uint32_t cap_bitrate_bps = measured_bitrate_bps; |
| 627 const std::vector<uint32_t> ssrcs = {1234}; |
| 628 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _)); |
| 629 packet_router.OnReceiveBitrateChanged(ssrcs, measured_bitrate_bps); |
| 630 |
| 631 EXPECT_CALL(remb_sender, SetREMBData(_, _)).Times(0); |
| 632 packet_router.SetMaxDesiredReceiveBitrate(cap_bitrate_bps); |
| 633 |
| 634 // Test tear-down. |
| 635 packet_router.RemoveSendRtpModule(&remb_sender); |
| 636 } |
| 637 |
| 638 TEST(PacketRouterRembTest, |
| 639 SetMaxDesiredReceiveBitrateDoesNotTriggerRembWhenLessRestrictive) { |
| 640 rtc::ScopedFakeClock clock; |
| 641 PacketRouter packet_router; |
| 642 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 643 NiceMock<MockRtpRtcpWithRembTracking> remb_sender; |
| 644 constexpr bool remb_candidate = true; |
| 645 packet_router.AddSendRtpModule(&remb_sender, remb_candidate); |
| 646 ASSERT_TRUE(remb_sender.REMB()); |
| 647 |
| 648 const uint32_t measured_bitrate_bps = 150000; |
| 649 const uint32_t cap_bitrate_bps = measured_bitrate_bps + 500; |
| 650 const std::vector<uint32_t> ssrcs = {1234}; |
| 651 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _)); |
| 652 packet_router.OnReceiveBitrateChanged(ssrcs, measured_bitrate_bps); |
| 653 |
| 654 EXPECT_CALL(remb_sender, SetREMBData(_, _)).Times(0); |
| 655 packet_router.SetMaxDesiredReceiveBitrate(cap_bitrate_bps); |
| 656 |
| 657 // Test tear-down. |
| 658 packet_router.RemoveSendRtpModule(&remb_sender); |
| 659 } |
| 660 |
| 661 TEST(PacketRouterRembTest, |
| 662 SetMaxDesiredReceiveBitrateTriggersRembWhenNoRecentMeasure) { |
| 663 rtc::ScopedFakeClock clock; |
| 664 PacketRouter packet_router; |
| 665 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 666 NiceMock<MockRtpRtcpWithRembTracking> remb_sender; |
| 667 constexpr bool remb_candidate = true; |
| 668 packet_router.AddSendRtpModule(&remb_sender, remb_candidate); |
| 669 ASSERT_TRUE(remb_sender.REMB()); |
| 670 |
| 671 const uint32_t measured_bitrate_bps = 150000; |
| 672 const uint32_t cap_bitrate_bps = measured_bitrate_bps + 5000; |
| 673 const std::vector<uint32_t> ssrcs = {1234}; |
| 674 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _)); |
| 675 packet_router.OnReceiveBitrateChanged(ssrcs, measured_bitrate_bps); |
| 676 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 677 |
| 678 EXPECT_CALL(remb_sender, SetREMBData(cap_bitrate_bps, _)); |
| 679 packet_router.SetMaxDesiredReceiveBitrate(cap_bitrate_bps); |
| 680 |
| 681 // Test tear-down. |
| 682 packet_router.RemoveSendRtpModule(&remb_sender); |
| 683 } |
| 684 |
| 685 TEST(PacketRouterRembTest, |
| 686 SetMaxDesiredReceiveBitrateTriggersRembWhenNoMeasures) { |
| 687 rtc::ScopedFakeClock clock; |
| 688 PacketRouter packet_router; |
| 689 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 690 NiceMock<MockRtpRtcpWithRembTracking> remb_sender; |
| 691 constexpr bool remb_candidate = true; |
| 692 packet_router.AddSendRtpModule(&remb_sender, remb_candidate); |
| 693 ASSERT_TRUE(remb_sender.REMB()); |
| 694 |
| 695 // Set cap. |
| 696 EXPECT_CALL(remb_sender, SetREMBData(100000, _)).Times(1); |
| 697 packet_router.SetMaxDesiredReceiveBitrate(100000); |
| 698 // Increase cap. |
| 699 EXPECT_CALL(remb_sender, SetREMBData(200000, _)).Times(1); |
| 700 packet_router.SetMaxDesiredReceiveBitrate(200000); |
| 701 // Decrease cap. |
| 702 EXPECT_CALL(remb_sender, SetREMBData(150000, _)).Times(1); |
| 703 packet_router.SetMaxDesiredReceiveBitrate(150000); |
| 704 |
| 705 // Test tear-down. |
| 706 packet_router.RemoveSendRtpModule(&remb_sender); |
| 707 } |
| 708 |
565 // Only register receiving modules and make sure we fallback to trigger a REMB | 709 // Only register receiving modules and make sure we fallback to trigger a REMB |
566 // packet on this one. | 710 // packet on this one. |
567 TEST(PacketRouterRembTest, NoSendingRtpModule) { | 711 TEST(PacketRouterRembTest, NoSendingRtpModule) { |
568 rtc::ScopedFakeClock clock; | 712 rtc::ScopedFakeClock clock; |
569 NiceMock<MockRtpRtcp> rtp; | 713 NiceMock<MockRtpRtcp> rtp; |
570 PacketRouter packet_router; | 714 PacketRouter packet_router; |
571 | 715 |
572 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); | 716 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); |
573 packet_router.AddReceiveRtpModule(&rtp, true); | 717 packet_router.AddReceiveRtpModule(&rtp, true); |
574 | 718 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 901 EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
758 | 902 |
759 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 903 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
760 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 904 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
761 | 905 |
762 // Test tear-down | 906 // Test tear-down |
763 packet_router.RemoveReceiveRtpModule(&receive_module); | 907 packet_router.RemoveReceiveRtpModule(&receive_module); |
764 } | 908 } |
765 | 909 |
766 } // namespace webrtc | 910 } // namespace webrtc |
OLD | NEW |