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 be28bf1dbe65bb705036d96a25a5eb6a7058832b..28fea1ddc4b9ffb3a4c2ed23ddb40755a47c254f 100644 |
| --- a/webrtc/modules/pacing/packet_router_unittest.cc |
| +++ b/webrtc/modules/pacing/packet_router_unittest.cc |
| @@ -12,6 +12,7 @@ |
| #include <memory> |
| #include "webrtc/base/checks.h" |
| +#include "webrtc/base/fakeclock.h" |
| #include "webrtc/modules/pacing/packet_router.h" |
| #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
| @@ -242,18 +243,237 @@ TEST_F(PacketRouterTest, AllocateSequenceNumbers) { |
| } |
| } |
| -TEST_F(PacketRouterTest, SendFeedback) { |
| +TEST_F(PacketRouterTest, SendTransportFeedback) { |
| MockRtpRtcp rtp_1; |
| MockRtpRtcp rtp_2; |
| packet_router_->AddSendRtpModule(&rtp_1); |
| packet_router_->AddReceiveRtpModule(&rtp_2); |
| rtcp::TransportFeedback feedback; |
| - EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1); |
| - packet_router_->SendFeedback(&feedback); |
| + EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); |
|
nisse-webrtc
2017/04/18 11:57:38
This check seems to have fixed the failure on the
|
| + packet_router_->SendTransportFeedback(&feedback); |
| packet_router_->RemoveSendRtpModule(&rtp_1); |
| - EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1); |
| - packet_router_->SendFeedback(&feedback); |
| + EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); |
| + packet_router_->SendTransportFeedback(&feedback); |
| packet_router_->RemoveReceiveRtpModule(&rtp_2); |
| } |
| + |
| +TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) { |
| + rtc::ScopedFakeClock clock; |
| + MockRtpRtcp rtp_recv; |
| + MockRtpRtcp rtp_send; |
| + PacketRouter packet_router; |
| + |
| + EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1); |
| + packet_router.AddReceiveRtpModule(&rtp_recv); |
| + |
| + 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. |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| + EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + 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)); |
| + |
| + // 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); |
| + packet_router.RemoveSendRtpModule(&rtp_send); |
| + EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); |
| + packet_router.RemoveReceiveRtpModule(&rtp_recv); |
| +} |
| + |
| +TEST(PacketRouterRembTest, LowerEstimateToSendRemb) { |
| + rtc::ScopedFakeClock clock; |
| + MockRtpRtcp rtp; |
| + PacketRouter packet_router; |
| + |
| + EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); |
| + packet_router.AddSendRtpModule(&rtp); |
| + |
| + 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. |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Lower the estimate with more than 3% to trigger a call to SetREMBData right |
| + // away. |
| + bitrate_estimate = bitrate_estimate - 100; |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); |
| + packet_router.RemoveSendRtpModule(&rtp); |
| +} |
| + |
| +TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) { |
| + rtc::ScopedFakeClock clock; |
| + MockRtpRtcp rtp; |
| + PacketRouter packet_router; |
| + packet_router.AddSendRtpModule(&rtp); |
| + |
| + uint32_t bitrate_estimate[] = {456, 789}; |
| + std::vector<uint32_t> ssrcs = {1234, 5678}; |
| + |
| + ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); |
| + |
| + // Call OnReceiveBitrateChanged twice to get a first estimate. |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1); |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); |
| + |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100); |
| + |
| + // Lower the estimate to trigger a callback. |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]); |
| + |
| + packet_router.RemoveSendRtpModule(&rtp); |
| +} |
| + |
| +TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) { |
| + rtc::ScopedFakeClock clock; |
| + MockRtpRtcp rtp; |
| + PacketRouter packet_router; |
| + packet_router.AddSendRtpModule(&rtp); |
| + |
| + uint32_t bitrate_estimate = 456; |
| + std::vector<uint32_t> ssrcs = {1234, 5678}; |
| + |
| + ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Call OnReceiveBitrateChanged twice to get a first estimate. |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Increased estimate shouldn't trigger a callback right away. |
| + EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1); |
| + |
| + // Decreasing the estimate less than 3% shouldn't trigger a new callback. |
| + EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| + int lower_estimate = bitrate_estimate * 98 / 100; |
| + packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate); |
| + |
| + packet_router.RemoveSendRtpModule(&rtp); |
| +} |
| + |
| +TEST(PacketRouterRembTest, ChangeSendRtpModule) { |
| + rtc::ScopedFakeClock clock; |
| + MockRtpRtcp rtp_send; |
| + MockRtpRtcp rtp_recv; |
| + PacketRouter packet_router; |
| + packet_router.AddSendRtpModule(&rtp_send); |
| + packet_router.AddReceiveRtpModule(&rtp_recv); |
| + |
| + uint32_t bitrate_estimate = 456; |
| + std::vector<uint32_t> ssrcs = {1234, 5678}; |
| + |
| + ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Call OnReceiveBitrateChanged twice to get a first estimate. |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| + EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Decrease estimate to trigger a REMB. |
| + bitrate_estimate = bitrate_estimate - 100; |
| + EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Remove the sending module -> should get remb on the second module. |
| + packet_router.RemoveSendRtpModule(&rtp_send); |
| + |
| + ON_CALL(rtp_send, REMB()).WillByDefault(Return(false)); |
| + ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true)); |
| + |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + bitrate_estimate = bitrate_estimate - 100; |
| + EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + packet_router.RemoveReceiveRtpModule(&rtp_recv); |
| +} |
| + |
| +TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) { |
| + rtc::ScopedFakeClock clock; |
| + MockRtpRtcp rtp; |
| + PacketRouter packet_router; |
| + packet_router.AddSendRtpModule(&rtp); |
| + |
| + 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. |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| + EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Lower the estimate, should trigger a call to SetREMBData right away. |
| + bitrate_estimate = bitrate_estimate - 100; |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Call OnReceiveBitrateChanged again, this should not trigger a new callback. |
| + EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + packet_router.RemoveSendRtpModule(&rtp); |
| +} |
| + |
| +// Only register receiving modules and make sure we fallback to trigger a REMB |
| +// packet on this one. |
| +TEST(PacketRouterRembTest, NoSendingRtpModule) { |
| + rtc::ScopedFakeClock clock; |
| + MockRtpRtcp rtp; |
| + PacketRouter packet_router; |
| + |
| + EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); |
| + packet_router.AddReceiveRtpModule(&rtp); |
| + |
| + 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. |
| + clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| + |
| + // Lower the estimate to trigger a new packet REMB packet. |
| + EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); |
| + packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); |
| + |
| + EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); |
| + packet_router.RemoveReceiveRtpModule(&rtp); |
| +} |
| + |
| } // namespace webrtc |