| Index: webrtc/modules/pacing/packet_router_unittest.cc
|
| diff --git a/webrtc/modules/pacing/packet_router_unittest.cc b/webrtc/modules/pacing/packet_router_unittest.cc
|
| index e7f08ca9b5b51684e898a34ab611bcf9519dac3d..f9943cee015c4bcd59f4773fc7b2acb48051534f 100644
|
| --- a/webrtc/modules/pacing/packet_router_unittest.cc
|
| +++ b/webrtc/modules/pacing/packet_router_unittest.cc
|
| @@ -23,25 +23,99 @@
|
| using ::testing::_;
|
| using ::testing::AnyNumber;
|
| using ::testing::Field;
|
| +using ::testing::Invoke;
|
| using ::testing::NiceMock;
|
| using ::testing::Return;
|
|
|
| namespace webrtc {
|
|
|
| +// TODO(eladalon): Restructure and/or replace the existing monolithic tests
|
| +// (only some of the test are monolithic) according to the new
|
| +// guidelines - small tests for one thing at a time.
|
| +// (I'm not removing any tests during CL, so as to demonstrate no regressions.)
|
| +
|
| +void ExpectSetREMBStatusAndSetRembAccordingly(MockRtpRtcp* mock_rtp_rtcp,
|
| + bool remb_state) {
|
| + EXPECT_CALL(*mock_rtp_rtcp, SetREMBStatus(remb_state))
|
| + .Times(1)
|
| + .WillOnce(Invoke([mock_rtp_rtcp](bool state) {
|
| + ON_CALL(*mock_rtp_rtcp, REMB()).WillByDefault(Return(state));
|
| + }));
|
| +}
|
| +
|
| +// Same as the Expect* version, but without the expectation. Note that this
|
| +// does not mix well with Expect*.
|
| +void OnSetREMBStatusAndSetRembAccordingly(MockRtpRtcp* mock_rtp_rtcp) {
|
| + ON_CALL(*mock_rtp_rtcp, SetREMBStatus(_))
|
| + .WillByDefault(Invoke([mock_rtp_rtcp](bool state) {
|
| + ON_CALL(*mock_rtp_rtcp, REMB()).WillByDefault(Return(state));
|
| + }));
|
| +}
|
| +
|
| class PacketRouterTest : public ::testing::Test {
|
| public:
|
| PacketRouterTest() : packet_router_(new PacketRouter()) {}
|
| protected:
|
| - static const int kProbeMinProbes = 5;
|
| - static const int kProbeMinBytes = 1000;
|
| + static constexpr int kProbeMinProbes = 5;
|
| + static constexpr int kProbeMinBytes = 1000;
|
| const std::unique_ptr<PacketRouter> packet_router_;
|
| };
|
|
|
| +TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_TimeToSendPacket) {
|
| + PacketRouter packet_router;
|
| +
|
| + constexpr uint16_t ssrc = 1234;
|
| + constexpr uint16_t sequence_number = 17;
|
| + constexpr uint64_t timestamp = 7890;
|
| + constexpr bool retransmission = false;
|
| + const PacedPacketInfo paced_info(1, kProbeMinProbes, kProbeMinBytes);
|
| +
|
| + // TODO(eladalon): !!! Discuss with reviewers - it's interesting that this
|
| + // returns true even when no modules are found that match the SSRC.
|
| + EXPECT_TRUE(packet_router.TimeToSendPacket(ssrc, sequence_number, timestamp,
|
| + retransmission, paced_info));
|
| +}
|
| +
|
| +TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_TimeToSendPadding) {
|
| + PacketRouter packet_router;
|
| +
|
| + constexpr size_t bytes = 300;
|
| + const PacedPacketInfo paced_info(1, kProbeMinProbes, kProbeMinBytes);
|
| +
|
| + EXPECT_EQ(packet_router.TimeToSendPadding(bytes, paced_info), 0u);
|
| +}
|
| +
|
| +TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_OnReceiveBitrateChanged) {
|
| + PacketRouter packet_router;
|
| +
|
| + const std::vector<uint32_t> ssrcs = {1, 2, 3};
|
| + constexpr uint32_t bitrate_bps = 10000;
|
| +
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_bps);
|
| +}
|
| +
|
| +TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_SendRemb) {
|
| + PacketRouter packet_router;
|
| +
|
| + const std::vector<uint32_t> ssrcs = {1, 2, 3};
|
| + constexpr uint32_t bitrate_bps = 10000;
|
| +
|
| + EXPECT_FALSE(packet_router.SendRemb(bitrate_bps, ssrcs));
|
| +}
|
| +
|
| +TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_SendTransportFeedback) {
|
| + PacketRouter packet_router;
|
| +
|
| + rtcp::TransportFeedback feedback;
|
| +
|
| + EXPECT_FALSE(packet_router_->SendTransportFeedback(&feedback));
|
| +}
|
| +
|
| TEST_F(PacketRouterTest, TimeToSendPacket) {
|
| NiceMock<MockRtpRtcp> rtp_1;
|
| NiceMock<MockRtpRtcp> rtp_2;
|
| - packet_router_->AddSendRtpModule(&rtp_1);
|
| - packet_router_->AddSendRtpModule(&rtp_2);
|
| + packet_router_->AddSendRtpModule(&rtp_1, false);
|
| + packet_router_->AddSendRtpModule(&rtp_2, false);
|
|
|
| const uint16_t kSsrc1 = 1234;
|
| uint16_t sequence_number = 17;
|
| @@ -125,8 +199,8 @@ TEST_F(PacketRouterTest, TimeToSendPadding) {
|
| // rtp_2 will be prioritized for padding.
|
| EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads));
|
| EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2));
|
| - packet_router_->AddSendRtpModule(&rtp_1);
|
| - packet_router_->AddSendRtpModule(&rtp_2);
|
| + packet_router_->AddSendRtpModule(&rtp_1, false);
|
| + packet_router_->AddSendRtpModule(&rtp_2, false);
|
|
|
| // Default configuration, sending padding on all modules sending media,
|
| // ordered by priority (based on rtx mode).
|
| @@ -210,7 +284,7 @@ TEST_F(PacketRouterTest, TimeToSendPadding) {
|
|
|
| TEST_F(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) {
|
| NiceMock<MockRtpRtcp> rtp;
|
| - packet_router_->AddSendRtpModule(&rtp);
|
| + packet_router_->AddSendRtpModule(&rtp, false);
|
| static const uint16_t kSsrc = 1234;
|
| EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc));
|
| EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false));
|
| @@ -246,8 +320,8 @@ TEST_F(PacketRouterTest, AllocateSequenceNumbers) {
|
| TEST_F(PacketRouterTest, SendTransportFeedback) {
|
| NiceMock<MockRtpRtcp> rtp_1;
|
| NiceMock<MockRtpRtcp> rtp_2;
|
| - packet_router_->AddSendRtpModule(&rtp_1);
|
| - packet_router_->AddReceiveRtpModule(&rtp_2);
|
| + packet_router_->AddSendRtpModule(&rtp_1, false);
|
| + packet_router_->AddReceiveRtpModule(&rtp_2, false);
|
|
|
| rtcp::TransportFeedback feedback;
|
| EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true));
|
| @@ -258,19 +332,71 @@ TEST_F(PacketRouterTest, SendTransportFeedback) {
|
| packet_router_->RemoveReceiveRtpModule(&rtp_2);
|
| }
|
|
|
| +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
|
| +TEST_F(PacketRouterTest, DoubleRegistrationOfSendModuleDisallowed) {
|
| + PacketRouter packet_router;
|
| +
|
| + NiceMock<MockRtpRtcp> module;
|
| + OnSetREMBStatusAndSetRembAccordingly(&module);
|
| +
|
| + constexpr bool remb_candidate = false; // Value irrelevant.
|
| + packet_router.AddSendRtpModule(&module, remb_candidate);
|
| + EXPECT_DEATH(packet_router.AddSendRtpModule(&module, remb_candidate), "");
|
| +
|
| + // Test tear-down
|
| + packet_router.RemoveSendRtpModule(&module);
|
| +}
|
| +
|
| +TEST_F(PacketRouterTest, DoubleRegistrationOfReceiveModuleDisallowed) {
|
| + PacketRouter packet_router;
|
| +
|
| + NiceMock<MockRtpRtcp> module;
|
| + OnSetREMBStatusAndSetRembAccordingly(&module);
|
| +
|
| + constexpr bool remb_candidate = false; // Value irrelevant.
|
| + packet_router.AddReceiveRtpModule(&module, remb_candidate);
|
| + EXPECT_DEATH(packet_router.AddReceiveRtpModule(&module, remb_candidate), "");
|
| +
|
| + // Test tear-down
|
| + packet_router.RemoveReceiveRtpModule(&module);
|
| +}
|
| +
|
| +TEST_F(PacketRouterTest, RemovalOfNeverAddedSendModuleDisallowed) {
|
| + PacketRouter packet_router;
|
| +
|
| + NiceMock<MockRtpRtcp> module;
|
| + OnSetREMBStatusAndSetRembAccordingly(&module);
|
| +
|
| + EXPECT_DEATH(packet_router.RemoveSendRtpModule(&module), "");
|
| +}
|
| +
|
| +TEST_F(PacketRouterTest, RemovalOfNeverAddedReceiveModuleDisallowed) {
|
| + PacketRouter packet_router;
|
| +
|
| + NiceMock<MockRtpRtcp> module;
|
| + OnSetREMBStatusAndSetRembAccordingly(&module);
|
| +
|
| + EXPECT_DEATH(packet_router.RemoveReceiveRtpModule(&module), "");
|
| +}
|
| +#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
|
| +
|
| +// TODO(eladalon): Remove this test; it should be covered by:
|
| +// 1. SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst
|
| +// 2. SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst
|
| +// 3. LowerEstimateToSendRemb
|
| +// (Not removing in this CL to prove it doesn't break this test.)
|
| TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) {
|
| rtc::ScopedFakeClock clock;
|
| NiceMock<MockRtpRtcp> rtp_recv;
|
| NiceMock<MockRtpRtcp> rtp_send;
|
| PacketRouter packet_router;
|
|
|
| - EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1);
|
| - packet_router.AddReceiveRtpModule(&rtp_recv);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, true);
|
| + packet_router.AddReceiveRtpModule(&rtp_recv, true);
|
|
|
| const uint32_t bitrate_estimate = 456;
|
| const std::vector<uint32_t> ssrcs = {1234};
|
|
|
| - ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true));
|
| packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
|
|
| // Call OnReceiveBitrateChanged twice to get a first estimate.
|
| @@ -279,20 +405,19 @@ TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) {
|
| packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
|
|
| // Add a send module, which should be preferred over the receive module.
|
| - EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1);
|
| - EXPECT_CALL(rtp_send, SetREMBStatus(true)).Times(1);
|
| - packet_router.AddSendRtpModule(&rtp_send);
|
| - ON_CALL(rtp_recv, REMB()).WillByDefault(Return(false));
|
| - ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, false);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp_send, true);
|
| + packet_router.AddSendRtpModule(&rtp_send, true);
|
|
|
| // Lower bitrate to send another REMB packet.
|
| EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
|
| packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
|
|
|
| - EXPECT_CALL(rtp_send, SetREMBStatus(false)).Times(1);
|
| - EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp_send, false);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, true);
|
| packet_router.RemoveSendRtpModule(&rtp_send);
|
| - EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1);
|
| +
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, false);
|
| packet_router.RemoveReceiveRtpModule(&rtp_recv);
|
| }
|
|
|
| @@ -301,13 +426,12 @@ TEST(PacketRouterRembTest, LowerEstimateToSendRemb) {
|
| NiceMock<MockRtpRtcp> rtp;
|
| PacketRouter packet_router;
|
|
|
| - EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
|
| - packet_router.AddSendRtpModule(&rtp);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp, true);
|
| + packet_router.AddSendRtpModule(&rtp, true);
|
|
|
| uint32_t bitrate_estimate = 456;
|
| const std::vector<uint32_t> ssrcs = {1234};
|
|
|
| - ON_CALL(rtp, REMB()).WillByDefault(Return(true));
|
| packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
|
|
| // Call OnReceiveBitrateChanged twice to get a first estimate.
|
| @@ -321,7 +445,7 @@ TEST(PacketRouterRembTest, LowerEstimateToSendRemb) {
|
| EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
|
| packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
|
|
| - EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&rtp, false);
|
| packet_router.RemoveSendRtpModule(&rtp);
|
| }
|
|
|
| @@ -329,7 +453,7 @@ TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) {
|
| rtc::ScopedFakeClock clock;
|
| NiceMock<MockRtpRtcp> rtp;
|
| PacketRouter packet_router;
|
| - packet_router.AddSendRtpModule(&rtp);
|
| + packet_router.AddSendRtpModule(&rtp, true);
|
|
|
| uint32_t bitrate_estimate[] = {456, 789};
|
| std::vector<uint32_t> ssrcs = {1234, 5678};
|
| @@ -355,7 +479,7 @@ TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) {
|
| rtc::ScopedFakeClock clock;
|
| NiceMock<MockRtpRtcp> rtp;
|
| PacketRouter packet_router;
|
| - packet_router.AddSendRtpModule(&rtp);
|
| + packet_router.AddSendRtpModule(&rtp, true);
|
|
|
| uint32_t bitrate_estimate = 456;
|
| std::vector<uint32_t> ssrcs = {1234, 5678};
|
| @@ -385,8 +509,8 @@ TEST(PacketRouterRembTest, ChangeSendRtpModule) {
|
| NiceMock<MockRtpRtcp> rtp_send;
|
| NiceMock<MockRtpRtcp> rtp_recv;
|
| PacketRouter packet_router;
|
| - packet_router.AddSendRtpModule(&rtp_send);
|
| - packet_router.AddReceiveRtpModule(&rtp_recv);
|
| + packet_router.AddSendRtpModule(&rtp_send, true);
|
| + packet_router.AddReceiveRtpModule(&rtp_recv, true);
|
|
|
| uint32_t bitrate_estimate = 456;
|
| std::vector<uint32_t> ssrcs = {1234, 5678};
|
| @@ -423,7 +547,7 @@ TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) {
|
| rtc::ScopedFakeClock clock;
|
| NiceMock<MockRtpRtcp> rtp;
|
| PacketRouter packet_router;
|
| - packet_router.AddSendRtpModule(&rtp);
|
| + packet_router.AddSendRtpModule(&rtp, true);
|
|
|
| uint32_t bitrate_estimate = 456;
|
| const std::vector<uint32_t> ssrcs = {1234};
|
| @@ -455,7 +579,7 @@ TEST(PacketRouterRembTest, NoSendingRtpModule) {
|
| PacketRouter packet_router;
|
|
|
| EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
|
| - packet_router.AddReceiveRtpModule(&rtp);
|
| + packet_router.AddReceiveRtpModule(&rtp, true);
|
|
|
| uint32_t bitrate_estimate = 456;
|
| const std::vector<uint32_t> ssrcs = {1234};
|
| @@ -476,4 +600,185 @@ TEST(PacketRouterRembTest, NoSendingRtpModule) {
|
| packet_router.RemoveReceiveRtpModule(&rtp);
|
| }
|
|
|
| +TEST(PacketRouterRembTest, NonCandidateSendRtpModuleNotUsedForRemb) {
|
| + rtc::ScopedFakeClock clock;
|
| + PacketRouter packet_router;
|
| + NiceMock<MockRtpRtcp> module;
|
| +
|
| + constexpr bool remb_candidate = false;
|
| + ON_CALL(module, REMB()).WillByDefault(Return(false));
|
| + EXPECT_CALL(module, SetREMBStatus(_)).Times(0);
|
| + packet_router.AddSendRtpModule(&module, remb_candidate);
|
| +
|
| + constexpr uint32_t bitrate_estimate = 456;
|
| + const std::vector<uint32_t> ssrcs = {1234};
|
| + EXPECT_CALL(module, SetREMBData(_, _)).Times(0);
|
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
| +
|
| + // Test tear-down
|
| + packet_router.RemoveSendRtpModule(&module);
|
| +}
|
| +
|
| +TEST(PacketRouterRembTest, CandidateSendRtpModuleUsedForRemb) {
|
| + rtc::ScopedFakeClock clock;
|
| + PacketRouter packet_router;
|
| + NiceMock<MockRtpRtcp> module;
|
| +
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&module, true);
|
| + constexpr bool remb_candidate = true;
|
| + packet_router.AddSendRtpModule(&module, remb_candidate);
|
| +
|
| + constexpr uint32_t bitrate_estimate = 456;
|
| + const std::vector<uint32_t> ssrcs = {1234};
|
| + EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
|
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
| +
|
| + // Test tear-down
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&module, false);
|
| + packet_router.RemoveSendRtpModule(&module);
|
| +}
|
| +
|
| +TEST(PacketRouterRembTest, NonCandidateReceiveRtpModuleNotUsedForRemb) {
|
| + rtc::ScopedFakeClock clock;
|
| + PacketRouter packet_router;
|
| + NiceMock<MockRtpRtcp> module;
|
| +
|
| + ON_CALL(module, REMB()).WillByDefault(Return(false));
|
| + EXPECT_CALL(module, SetREMBStatus(_)).Times(0);
|
| + constexpr bool remb_candidate = false;
|
| + packet_router.AddReceiveRtpModule(&module, remb_candidate);
|
| +
|
| + constexpr uint32_t bitrate_estimate = 456;
|
| + const std::vector<uint32_t> ssrcs = {1234};
|
| + EXPECT_CALL(module, SetREMBData(_, _)).Times(0);
|
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
| +
|
| + // Test tear-down
|
| + packet_router.RemoveReceiveRtpModule(&module);
|
| +}
|
| +
|
| +TEST(PacketRouterRembTest, CandidateReceiveRtpModuleUsedForRemb) {
|
| + rtc::ScopedFakeClock clock;
|
| + PacketRouter packet_router;
|
| + NiceMock<MockRtpRtcp> module;
|
| +
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&module, true);
|
| + constexpr bool remb_candidate = true;
|
| + packet_router.AddReceiveRtpModule(&module, remb_candidate);
|
| +
|
| + constexpr uint32_t bitrate_estimate = 456;
|
| + const std::vector<uint32_t> ssrcs = {1234};
|
| + EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
|
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
| +
|
| + // Test tear-down
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&module, false);
|
| + packet_router.RemoveReceiveRtpModule(&module);
|
| +}
|
| +
|
| +TEST(PacketRouterRembTest,
|
| + SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst) {
|
| + rtc::ScopedFakeClock clock;
|
| + PacketRouter packet_router;
|
| + NiceMock<MockRtpRtcp> send_module;
|
| + NiceMock<MockRtpRtcp> receive_module;
|
| +
|
| + constexpr bool remb_candidate = true;
|
| +
|
| + // Send module added - activated.
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&send_module, true);
|
| + packet_router.AddSendRtpModule(&send_module, remb_candidate);
|
| +
|
| + // Receive module added - the send module remains the active one.
|
| + ON_CALL(receive_module, REMB()).WillByDefault(Return(false));
|
| + EXPECT_CALL(receive_module, SetREMBStatus(true)).Times(0);
|
| + packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
|
| +
|
| + constexpr uint32_t bitrate_estimate = 456;
|
| + const std::vector<uint32_t> ssrcs = {1234};
|
| + EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
|
| + EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0);
|
| +
|
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
| +
|
| + // Test tear-down
|
| + packet_router.RemoveReceiveRtpModule(&receive_module);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&send_module, false);
|
| + packet_router.RemoveSendRtpModule(&send_module);
|
| +}
|
| +
|
| +TEST(PacketRouterRembTest,
|
| + SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst) {
|
| + rtc::ScopedFakeClock clock;
|
| + PacketRouter packet_router;
|
| + NiceMock<MockRtpRtcp> send_module;
|
| + NiceMock<MockRtpRtcp> receive_module;
|
| +
|
| + constexpr bool remb_candidate = true;
|
| +
|
| + // Receive module added - activated.
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, true);
|
| + packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
|
| +
|
| + // Send module added - replaces receive module as active.
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, false);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&send_module, true);
|
| + packet_router.AddSendRtpModule(&send_module, remb_candidate);
|
| +
|
| + constexpr uint32_t bitrate_estimate = 456;
|
| + const std::vector<uint32_t> ssrcs = {1234};
|
| + EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
|
| + EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0);
|
| +
|
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
| +
|
| + // Test tear-down
|
| + packet_router.RemoveReceiveRtpModule(&receive_module);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&send_module, false);
|
| + packet_router.RemoveSendRtpModule(&send_module);
|
| +}
|
| +
|
| +TEST(PacketRouterRembTest, ReceiveModuleTakesOverWhenLastSendModuleRemoved) {
|
| + rtc::ScopedFakeClock clock;
|
| + PacketRouter packet_router;
|
| + NiceMock<MockRtpRtcp> send_module;
|
| + NiceMock<MockRtpRtcp> receive_module;
|
| +
|
| + constexpr bool remb_candidate = true;
|
| +
|
| + // Send module added - activated.
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&send_module, true);
|
| + packet_router.AddSendRtpModule(&send_module, remb_candidate);
|
| +
|
| + // Receive module added - the send module remains the active one.
|
| + ON_CALL(receive_module, REMB()).WillByDefault(Return(false));
|
| + EXPECT_CALL(receive_module, SetREMBStatus(true)).Times(0);
|
| + packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
|
| +
|
| + // Send module removed - receive module becomes active.
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&send_module, false);
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, true);
|
| + packet_router.RemoveSendRtpModule(&send_module);
|
| +
|
| + constexpr uint32_t bitrate_estimate = 456;
|
| + const std::vector<uint32_t> ssrcs = {1234};
|
| + EXPECT_CALL(send_module, SetREMBData(_, _)).Times(0);
|
| + EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
|
| +
|
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
|
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
|
| +
|
| + // Test tear-down
|
| + ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, false);
|
| + packet_router.RemoveReceiveRtpModule(&receive_module);
|
| +}
|
| +
|
| +// TODO(eladalon): Tests for a module which is both receive as well as send?
|
| +
|
| } // namespace webrtc
|
|
|