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

Side by Side Diff: webrtc/modules/pacing/packet_router_unittest.cc

Issue 2994513002: Add PacketRouter::SetMaxDesiredReceiveBitrate for application limited receive bandwidth (Closed)
Patch Set: Created 3 years, 4 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
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::_;
eladalon 2017/08/03 12:59:02 Is this move meaningfull? We're inside of a .cc fi
danilchap 2017/08/03 14:16:19 yes, it is general policy, this style might help t
eladalon 2017/08/04 08:32:49 Acknowledged.
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
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, SetMaxEstimatedBandwidthLimitsSetREMBData) {
570 rtc::ScopedFakeClock clock;
571 PacketRouter packet_router;
572 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
573 NiceMock<MockRtpRtcpWithRembTracking> remb_sender;
574 packet_router.AddSendRtpModule(&remb_sender, /*remb_candidate=*/true);
eladalon 2017/08/03 12:59:02 nit: Prefer keeping files self-consistent, and eit
danilchap 2017/08/03 14:16:19 changed to keep old style for consistency, thanks.
575 ASSERT_TRUE(remb_sender.REMB());
576
577 const uint32_t cap_bitrate = 100000;
578 EXPECT_CALL(remb_sender, SetREMBData(Le(cap_bitrate), _)).Times(AtLeast(1));
579 EXPECT_CALL(remb_sender, SetREMBData(Gt(cap_bitrate), _)).Times(0);
eladalon 2017/08/03 12:59:02 On the one hand, you illuminate the intention of y
danilchap 2017/08/03 14:16:19 Acknowledged. I do that in test below, where there
580
581 const std::vector<uint32_t> ssrcs = {1234};
582 packet_router.SetMaxEstimatedBandwidth(cap_bitrate);
583 packet_router.OnReceiveBitrateChanged(ssrcs, cap_bitrate + 5000);
584 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
585 packet_router.OnReceiveBitrateChanged(ssrcs, cap_bitrate - 5000);
586 // Cleanup.
eladalon 2017/08/03 12:59:02 nit #1: Empty line before the cleanup block. nit #
danilchap 2017/08/03 14:16:19 Done.
587 packet_router.RemoveSendRtpModule(&remb_sender);
588 }
589
590 TEST(PacketRouterRembTest,
591 SetMaxEstimatedBandwidthTriggersRembWhenMoreRestrictive) {
592 rtc::ScopedFakeClock clock;
593 PacketRouter packet_router;
594 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
595 NiceMock<MockRtpRtcpWithRembTracking> remb_sender;
596 packet_router.AddSendRtpModule(&remb_sender, /*remb_candidate=*/true);
597 ASSERT_TRUE(remb_sender.REMB());
598
599 const std::vector<uint32_t> ssrcs = {1234};
600 EXPECT_CALL(remb_sender, SetREMBData(150000, _));
601 packet_router.OnReceiveBitrateChanged(ssrcs, 150000);
602
603 EXPECT_CALL(remb_sender, SetREMBData(100000, _));
604 packet_router.SetMaxEstimatedBandwidth(100000);
605 // Cleanup.
606 packet_router.RemoveSendRtpModule(&remb_sender);
607 }
608
609 TEST(PacketRouterRembTest,
610 SetMaxEstimatedBandwidthDoesNotTriggerRembWhenAsRestrictive) {
611 rtc::ScopedFakeClock clock;
612 PacketRouter packet_router;
613 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
614 NiceMock<MockRtpRtcpWithRembTracking> remb_sender;
615 packet_router.AddSendRtpModule(&remb_sender, /*remb_candidate=*/true);
616 ASSERT_TRUE(remb_sender.REMB());
617
618 const uint32_t measured_bitrate_bps = 150000;
eladalon 2017/08/03 12:59:02 nit: constexpr
danilchap 2017/08/03 14:16:19 not sure why is it better in this case, checked te
eladalon 2017/08/04 08:32:49 That could have been a good convention, but there
danilchap 2017/08/04 10:51:23 Acknowledged.
619 const std::vector<uint32_t> ssrcs = {1234};
620 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _));
621 packet_router.OnReceiveBitrateChanged(ssrcs, measured_bitrate_bps);
622
623 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _)).Times(0);
624 packet_router.SetMaxEstimatedBandwidth(measured_bitrate_bps);
eladalon 2017/08/03 12:59:02 Suggestion - if you created another const(expr), c
danilchap 2017/08/03 14:16:18 Done.
625 // Cleanup.
626 packet_router.RemoveSendRtpModule(&remb_sender);
627 }
628
629 TEST(PacketRouterRembTest,
630 SetMaxEstimatedBandwidthDoesNotTriggerRembWhenLessRestrictive) {
631 rtc::ScopedFakeClock clock;
632 PacketRouter packet_router;
633 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
634 NiceMock<MockRtpRtcpWithRembTracking> remb_sender;
635 packet_router.AddSendRtpModule(&remb_sender, /*remb_candidate=*/true);
636 ASSERT_TRUE(remb_sender.REMB());
637
638 const uint32_t measured_bitrate_bps = 150000;
639 const std::vector<uint32_t> ssrcs = {1234};
640 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _));
641 packet_router.OnReceiveBitrateChanged(ssrcs, measured_bitrate_bps);
642
643 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps + 500, _)).Times(0);
644 packet_router.SetMaxEstimatedBandwidth(measured_bitrate_bps + 500);
645 // Cleanup.
646 packet_router.RemoveSendRtpModule(&remb_sender);
647 }
648
649 TEST(PacketRouterRembTest,
650 SetMaxEstimatedBandwidthTriggersRembWhenNoRecentMeasure) {
651 rtc::ScopedFakeClock clock;
652 PacketRouter packet_router;
653 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
654 NiceMock<MockRtpRtcpWithRembTracking> remb_sender;
655 packet_router.AddSendRtpModule(&remb_sender, /*remb_candidate=*/true);
656 ASSERT_TRUE(remb_sender.REMB());
657
658 const uint32_t measured_bitrate_bps = 150000;
659 const std::vector<uint32_t> ssrcs = {1234};
660 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps, _));
661 packet_router.OnReceiveBitrateChanged(ssrcs, measured_bitrate_bps);
662 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
663
664 EXPECT_CALL(remb_sender, SetREMBData(measured_bitrate_bps + 500, _));
665 packet_router.SetMaxEstimatedBandwidth(measured_bitrate_bps + 500);
666 // Cleanup.
667 packet_router.RemoveSendRtpModule(&remb_sender);
668 }
669
670 TEST(PacketRouterRembTest, SetMaxEstimatedBandwidthTriggersRembWhenNoMeasures) {
eladalon 2017/08/03 12:59:02 So this is intentional? 1. Might be good to docume
danilchap 2017/08/03 14:16:18 1. It sort of implicit - if you set a limit how mu
eladalon 2017/08/04 08:32:49 Acknowledged. I've suggested a rephrasing next to
671 rtc::ScopedFakeClock clock;
672 PacketRouter packet_router;
673 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
674 NiceMock<MockRtpRtcpWithRembTracking> remb_sender;
675 packet_router.AddSendRtpModule(&remb_sender, /*remb_candidate=*/true);
676 ASSERT_TRUE(remb_sender.REMB());
677
678 // Set cap.
679 EXPECT_CALL(remb_sender, SetREMBData(100000, _)).Times(1);
680 packet_router.SetMaxEstimatedBandwidth(100000);
681 // Increase cap.
682 EXPECT_CALL(remb_sender, SetREMBData(200000, _)).Times(1);
683 packet_router.SetMaxEstimatedBandwidth(200000);
684 // Decrease cap.
685 EXPECT_CALL(remb_sender, SetREMBData(150000, _)).Times(1);
686 packet_router.SetMaxEstimatedBandwidth(150000);
687 // Cleanup.
688 packet_router.RemoveSendRtpModule(&remb_sender);
689 }
690
565 // Only register receiving modules and make sure we fallback to trigger a REMB 691 // Only register receiving modules and make sure we fallback to trigger a REMB
566 // packet on this one. 692 // packet on this one.
567 TEST(PacketRouterRembTest, NoSendingRtpModule) { 693 TEST(PacketRouterRembTest, NoSendingRtpModule) {
568 rtc::ScopedFakeClock clock; 694 rtc::ScopedFakeClock clock;
569 NiceMock<MockRtpRtcp> rtp; 695 NiceMock<MockRtpRtcp> rtp;
570 PacketRouter packet_router; 696 PacketRouter packet_router;
571 697
572 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); 698 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
573 packet_router.AddReceiveRtpModule(&rtp, true); 699 packet_router.AddReceiveRtpModule(&rtp, true);
574 700
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 883 EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
758 884
759 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 885 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
760 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 886 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
761 887
762 // Test tear-down 888 // Test tear-down
763 packet_router.RemoveReceiveRtpModule(&receive_module); 889 packet_router.RemoveReceiveRtpModule(&receive_module);
764 } 890 }
765 891
766 } // namespace webrtc 892 } // namespace webrtc
OLDNEW
« webrtc/modules/pacing/packet_router.cc ('K') | « webrtc/modules/pacing/packet_router.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698