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..f6783e473feaf57cec21250622b2cebaf1d67ce1 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,7 +243,7 @@ TEST_F(PacketRouterTest, AllocateSequenceNumbers) { |
} |
} |
-TEST_F(PacketRouterTest, SendFeedback) { |
+TEST_F(PacketRouterTest, SendTransportFeedback) { |
MockRtpRtcp rtp_1; |
MockRtpRtcp rtp_2; |
packet_router_->AddSendRtpModule(&rtp_1); |
@@ -250,10 +251,232 @@ TEST_F(PacketRouterTest, SendFeedback) { |
rtcp::TransportFeedback feedback; |
EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1); |
- packet_router_->SendFeedback(&feedback); |
+ packet_router_->SendTransportFeedback(&feedback); |
packet_router_->RemoveSendRtpModule(&rtp_1); |
EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1); |
- packet_router_->SendFeedback(&feedback); |
+ 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; |
danilchap
2017/04/13 12:27:46
may be
either remove const, or change variable nam
nisse-webrtc
2017/04/18 09:51:16
I prefer to not change. |bitrate_estimate| is the
danilchap
2017/04/18 10:13:56
You right, for local variables it is not required.
|
+ const std::vector<uint32_t> ssrcs { 1234 }; |
danilchap
2017/04/13 12:27:46
add = between declaration and the init value.
http
nisse-webrtc
2017/04/18 09:51:16
Done. (In several places).
|
+ |
+ 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}; |
+ uint32_t ssrc[] = {1234, 5678}; |
danilchap
2017/04/13 12:27:46
is this value needed for anything other than initi
nisse-webrtc
2017/04/18 09:51:16
No, I'm moving the list to the initializer for ssr
|
+ std::vector<uint32_t> ssrcs(ssrc, ssrc + sizeof(ssrc) / sizeof(ssrc[0])); |
+ |
+ 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; |
+ uint32_t ssrc[] = {1234, 5678}; |
+ std::vector<uint32_t> ssrcs(ssrc, ssrc + sizeof(ssrc) / sizeof(ssrc[0])); |
+ |
+ 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; |
+ uint32_t ssrc[] = {1234, 5678}; |
+ std::vector<uint32_t> ssrcs(ssrc, ssrc + sizeof(ssrc) / sizeof(ssrc[0])); |
+ |
+ 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 |