Chromium Code Reviews| 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)) |
|
danilchap
2017/07/28 11:35:04
EXPECT_CALL in helper complicates reading error me
eladalon
2017/07/28 15:47:11
Removed in favor of MockRtpRtcpRemb (under a diffe
|
| + .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) { |
|
danilchap
2017/07/28 11:35:04
probably cleaner to use different Mock instead of
eladalon
2017/07/28 15:47:11
MockRtpRtcpRemb - Good suggestions, I'll use that.
|
| + 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) { |
|
danilchap
2017/07/28 11:35:04
this questionable sanity checks looks unlrelated t
eladalon
2017/07/28 15:47:11
I'll move to its own CL (https://codereview.webrtc
|
| + 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. |
|
danilchap
2017/07/27 20:00:20
probably it mean that module for the packet was ju
eladalon
2017/07/27 21:30:53
PacedSender::SendPacket uses that, so even if we e
|
| + 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)); |
|
danilchap
2017/07/28 11:35:04
probably better to advance time after OnReceiveBit
eladalon
2017/07/28 15:47:11
What effect would moving the clock have on the pac
eladalon
2017/07/28 15:47:12
Done.
danilchap
2017/07/31 13:18:03
Hm, true, it shouldn't. until clock will learn to
|
| + 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)); |
|
danilchap
2017/07/28 11:35:04
either do not advance time at all (to stress remb
eladalon
2017/07/28 15:47:11
OnReceiveBitrateChanged() won't have the expected
|
| + 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? |
|
danilchap
2017/07/27 20:00:20
do not think we have those modules. At least for v
eladalon
2017/07/27 21:30:54
Acknowledged; will remove this TODO with the next
|
| + |
| } // namespace webrtc |