Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <list> |
kwiberg | 22feaa3 | 2016-03-17 09:17:43 -0700 | [diff] [blame] | 12 | #include <memory> |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 13 | |
Henrik Kjellander | 0b9e29c | 2015-11-16 11:12:24 +0100 | [diff] [blame] | 14 | #include "webrtc/modules/pacing/packet_router.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 15 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 16 | #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 17 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 18 | #include "webrtc/rtc_base/checks.h" |
| 19 | #include "webrtc/rtc_base/fakeclock.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 20 | #include "webrtc/test/gmock.h" |
| 21 | #include "webrtc/test/gtest.h" |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 22 | |
| 23 | using ::testing::_; |
| 24 | using ::testing::AnyNumber; |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 25 | using ::testing::Field; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 26 | using ::testing::NiceMock; |
| 27 | using ::testing::Return; |
| 28 | |
| 29 | namespace webrtc { |
| 30 | |
| 31 | class PacketRouterTest : public ::testing::Test { |
| 32 | public: |
| 33 | PacketRouterTest() : packet_router_(new PacketRouter()) {} |
| 34 | protected: |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 35 | static const int kProbeMinProbes = 5; |
| 36 | static const int kProbeMinBytes = 1000; |
kwiberg | 22feaa3 | 2016-03-17 09:17:43 -0700 | [diff] [blame] | 37 | const std::unique_ptr<PacketRouter> packet_router_; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | TEST_F(PacketRouterTest, TimeToSendPacket) { |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 41 | NiceMock<MockRtpRtcp> rtp_1; |
| 42 | NiceMock<MockRtpRtcp> rtp_2; |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 43 | packet_router_->AddSendRtpModule(&rtp_1); |
| 44 | packet_router_->AddSendRtpModule(&rtp_2); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 45 | |
| 46 | const uint16_t kSsrc1 = 1234; |
| 47 | uint16_t sequence_number = 17; |
| 48 | uint64_t timestamp = 7890; |
| 49 | bool retransmission = false; |
| 50 | |
| 51 | // Send on the first module by letting rtp_1 be sending with correct ssrc. |
| 52 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 53 | EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 54 | EXPECT_CALL(rtp_1, TimeToSendPacket( |
| 55 | kSsrc1, sequence_number, timestamp, retransmission, |
| 56 | Field(&PacedPacketInfo::probe_cluster_id, 1))) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 57 | .Times(1) |
| 58 | .WillOnce(Return(true)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 59 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 60 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 61 | kSsrc1, sequence_number, timestamp, retransmission, |
| 62 | PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 63 | |
| 64 | // Send on the second module by letting rtp_2 be sending, but not rtp_1. |
| 65 | ++sequence_number; |
| 66 | timestamp += 30; |
| 67 | retransmission = true; |
| 68 | const uint16_t kSsrc2 = 4567; |
| 69 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); |
| 70 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 71 | EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 72 | EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 73 | EXPECT_CALL(rtp_2, TimeToSendPacket( |
| 74 | kSsrc2, sequence_number, timestamp, retransmission, |
| 75 | Field(&PacedPacketInfo::probe_cluster_id, 2))) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 76 | .Times(1) |
| 77 | .WillOnce(Return(true)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 78 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 79 | kSsrc2, sequence_number, timestamp, retransmission, |
| 80 | PacedPacketInfo(2, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 81 | |
| 82 | // No module is sending, hence no packet should be sent. |
| 83 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 84 | EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 85 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 86 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 87 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 88 | kSsrc1, sequence_number, timestamp, retransmission, |
| 89 | PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 90 | |
| 91 | // Add a packet with incorrect ssrc and test it's dropped in the router. |
| 92 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 93 | EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); |
| 94 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 95 | EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 96 | EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0); |
| 97 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 98 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 99 | kSsrc1 + kSsrc2, sequence_number, timestamp, retransmission, |
| 100 | PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 101 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 102 | packet_router_->RemoveSendRtpModule(&rtp_1); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 103 | |
| 104 | // rtp_1 has been removed, try sending a packet on that ssrc and make sure |
| 105 | // it is dropped as expected by not expecting any calls to rtp_1. |
| 106 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 107 | EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 108 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 109 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 110 | kSsrc1, sequence_number, timestamp, retransmission, |
| 111 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 112 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 113 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 114 | packet_router_->RemoveSendRtpModule(&rtp_2); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | TEST_F(PacketRouterTest, TimeToSendPadding) { |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 118 | const uint16_t kSsrc1 = 1234; |
| 119 | const uint16_t kSsrc2 = 4567; |
| 120 | |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 121 | NiceMock<MockRtpRtcp> rtp_1; |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 122 | EXPECT_CALL(rtp_1, RtxSendStatus()).WillOnce(Return(kRtxOff)); |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 123 | EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 124 | NiceMock<MockRtpRtcp> rtp_2; |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 125 | // rtp_2 will be prioritized for padding. |
| 126 | EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads)); |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 127 | EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 128 | packet_router_->AddSendRtpModule(&rtp_1); |
| 129 | packet_router_->AddSendRtpModule(&rtp_2); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 130 | |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 131 | // Default configuration, sending padding on all modules sending media, |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 132 | // ordered by priority (based on rtx mode). |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 133 | const size_t requested_padding_bytes = 1000; |
| 134 | const size_t sent_padding_bytes = 890; |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 135 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 136 | EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 137 | EXPECT_CALL(rtp_2, |
| 138 | TimeToSendPadding(requested_padding_bytes, |
| 139 | Field(&PacedPacketInfo::probe_cluster_id, 111))) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 140 | .Times(1) |
| 141 | .WillOnce(Return(sent_padding_bytes)); |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 142 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 143 | EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 144 | EXPECT_CALL(rtp_1, |
| 145 | TimeToSendPadding(requested_padding_bytes - sent_padding_bytes, |
| 146 | Field(&PacedPacketInfo::probe_cluster_id, 111))) |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 147 | .Times(1) |
| 148 | .WillOnce(Return(requested_padding_bytes - sent_padding_bytes)); |
| 149 | EXPECT_EQ(requested_padding_bytes, |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 150 | packet_router_->TimeToSendPadding( |
| 151 | requested_padding_bytes, |
| 152 | PacedPacketInfo(111, kProbeMinBytes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 153 | |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 154 | // Let only the lower priority module be sending and verify the padding |
| 155 | // request is routed there. |
| 156 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); |
| 157 | EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)).Times(0); |
| 158 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 159 | EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 160 | EXPECT_CALL(rtp_1, TimeToSendPadding(_, _)) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 161 | .Times(1) |
| 162 | .WillOnce(Return(sent_padding_bytes)); |
| 163 | EXPECT_EQ(sent_padding_bytes, |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 164 | packet_router_->TimeToSendPadding( |
| 165 | requested_padding_bytes, |
| 166 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 167 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 168 | |
| 169 | // No sending module at all. |
| 170 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 171 | EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes, _)).Times(0); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 172 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 173 | EXPECT_CALL(rtp_2, TimeToSendPadding(_, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 174 | EXPECT_EQ(0u, |
| 175 | packet_router_->TimeToSendPadding( |
| 176 | requested_padding_bytes, |
| 177 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 178 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 179 | |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 180 | // Only one module has BWE extensions. |
| 181 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 182 | EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(false)); |
| 183 | EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes, _)).Times(0); |
| 184 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 185 | EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
| 186 | EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)) |
| 187 | .Times(1) |
| 188 | .WillOnce(Return(sent_padding_bytes)); |
| 189 | EXPECT_EQ(sent_padding_bytes, |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 190 | packet_router_->TimeToSendPadding( |
| 191 | requested_padding_bytes, |
| 192 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 193 | kProbeMinBytes))); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 194 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 195 | packet_router_->RemoveSendRtpModule(&rtp_1); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 196 | |
| 197 | // rtp_1 has been removed, try sending padding and make sure rtp_1 isn't asked |
| 198 | // to send by not expecting any calls. Instead verify rtp_2 is called. |
| 199 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 200 | EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 201 | EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)).Times(1); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 202 | EXPECT_EQ(0u, |
| 203 | packet_router_->TimeToSendPadding( |
| 204 | requested_padding_bytes, |
| 205 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 206 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 207 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 208 | packet_router_->RemoveSendRtpModule(&rtp_2); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | TEST_F(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) { |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 212 | NiceMock<MockRtpRtcp> rtp; |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 213 | packet_router_->AddSendRtpModule(&rtp); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 214 | static const uint16_t kSsrc = 1234; |
| 215 | EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc)); |
| 216 | EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false)); |
| 217 | |
| 218 | // Verify that TimeToSendPacket does not end up in a receiver. |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 219 | EXPECT_CALL(rtp, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 220 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 221 | kSsrc, 1, 1, false, PacedPacketInfo(PacedPacketInfo::kNotAProbe, |
| 222 | kProbeMinBytes, kProbeMinBytes))); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 223 | // Verify that TimeToSendPadding does not end up in a receiver. |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 224 | EXPECT_CALL(rtp, TimeToSendPadding(_, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 225 | EXPECT_EQ(0u, |
| 226 | packet_router_->TimeToSendPadding( |
| 227 | 200, PacedPacketInfo(PacedPacketInfo::kNotAProbe, |
| 228 | kProbeMinBytes, kProbeMinBytes))); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 229 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 230 | packet_router_->RemoveSendRtpModule(&rtp); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 231 | } |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 232 | |
| 233 | TEST_F(PacketRouterTest, AllocateSequenceNumbers) { |
| 234 | const uint16_t kStartSeq = 0xFFF0; |
| 235 | const size_t kNumPackets = 32; |
| 236 | |
| 237 | packet_router_->SetTransportWideSequenceNumber(kStartSeq - 1); |
| 238 | |
| 239 | for (size_t i = 0; i < kNumPackets; ++i) { |
| 240 | uint16_t seq = packet_router_->AllocateSequenceNumber(); |
| 241 | uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; |
| 242 | EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); |
| 243 | } |
| 244 | } |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 245 | |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 246 | TEST_F(PacketRouterTest, SendTransportFeedback) { |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 247 | NiceMock<MockRtpRtcp> rtp_1; |
| 248 | NiceMock<MockRtpRtcp> rtp_2; |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 249 | packet_router_->AddSendRtpModule(&rtp_1); |
| 250 | packet_router_->AddReceiveRtpModule(&rtp_2); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 251 | |
| 252 | rtcp::TransportFeedback feedback; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 253 | EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); |
| 254 | packet_router_->SendTransportFeedback(&feedback); |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 255 | packet_router_->RemoveSendRtpModule(&rtp_1); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 256 | EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); |
| 257 | packet_router_->SendTransportFeedback(&feedback); |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 258 | packet_router_->RemoveReceiveRtpModule(&rtp_2); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 259 | } |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 260 | |
| 261 | TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) { |
| 262 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 263 | NiceMock<MockRtpRtcp> rtp_recv; |
| 264 | NiceMock<MockRtpRtcp> rtp_send; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 265 | PacketRouter packet_router; |
| 266 | |
| 267 | EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1); |
| 268 | packet_router.AddReceiveRtpModule(&rtp_recv); |
| 269 | |
| 270 | const uint32_t bitrate_estimate = 456; |
| 271 | const std::vector<uint32_t> ssrcs = {1234}; |
| 272 | |
| 273 | ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true)); |
| 274 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 275 | |
| 276 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 277 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 278 | EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 279 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 280 | |
| 281 | // Add a send module, which should be preferred over the receive module. |
| 282 | EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); |
| 283 | EXPECT_CALL(rtp_send, SetREMBStatus(true)).Times(1); |
| 284 | packet_router.AddSendRtpModule(&rtp_send); |
| 285 | ON_CALL(rtp_recv, REMB()).WillByDefault(Return(false)); |
| 286 | ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); |
| 287 | |
| 288 | // Lower bitrate to send another REMB packet. |
| 289 | EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); |
| 290 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); |
| 291 | |
| 292 | EXPECT_CALL(rtp_send, SetREMBStatus(false)).Times(1); |
| 293 | EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1); |
| 294 | packet_router.RemoveSendRtpModule(&rtp_send); |
| 295 | EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); |
| 296 | packet_router.RemoveReceiveRtpModule(&rtp_recv); |
| 297 | } |
| 298 | |
| 299 | TEST(PacketRouterRembTest, LowerEstimateToSendRemb) { |
| 300 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 301 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 302 | PacketRouter packet_router; |
| 303 | |
| 304 | EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); |
| 305 | packet_router.AddSendRtpModule(&rtp); |
| 306 | |
| 307 | uint32_t bitrate_estimate = 456; |
| 308 | const std::vector<uint32_t> ssrcs = {1234}; |
| 309 | |
| 310 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 311 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 312 | |
| 313 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 314 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 315 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 316 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 317 | |
| 318 | // Lower the estimate with more than 3% to trigger a call to SetREMBData right |
| 319 | // away. |
| 320 | bitrate_estimate = bitrate_estimate - 100; |
| 321 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 322 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 323 | |
| 324 | EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); |
| 325 | packet_router.RemoveSendRtpModule(&rtp); |
| 326 | } |
| 327 | |
| 328 | TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) { |
| 329 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 330 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 331 | PacketRouter packet_router; |
| 332 | packet_router.AddSendRtpModule(&rtp); |
| 333 | |
| 334 | uint32_t bitrate_estimate[] = {456, 789}; |
| 335 | std::vector<uint32_t> ssrcs = {1234, 5678}; |
| 336 | |
| 337 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 338 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); |
| 339 | |
| 340 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 341 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1); |
| 342 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 343 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); |
| 344 | |
| 345 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100); |
| 346 | |
| 347 | // Lower the estimate to trigger a callback. |
| 348 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1); |
| 349 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]); |
| 350 | |
| 351 | packet_router.RemoveSendRtpModule(&rtp); |
| 352 | } |
| 353 | |
| 354 | TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) { |
| 355 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 356 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 357 | PacketRouter packet_router; |
| 358 | packet_router.AddSendRtpModule(&rtp); |
| 359 | |
| 360 | uint32_t bitrate_estimate = 456; |
| 361 | std::vector<uint32_t> ssrcs = {1234, 5678}; |
| 362 | |
| 363 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 364 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 365 | |
| 366 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 367 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 368 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 369 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 370 | |
| 371 | // Increased estimate shouldn't trigger a callback right away. |
| 372 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| 373 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1); |
| 374 | |
| 375 | // Decreasing the estimate less than 3% shouldn't trigger a new callback. |
| 376 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| 377 | int lower_estimate = bitrate_estimate * 98 / 100; |
| 378 | packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate); |
| 379 | |
| 380 | packet_router.RemoveSendRtpModule(&rtp); |
| 381 | } |
| 382 | |
| 383 | TEST(PacketRouterRembTest, ChangeSendRtpModule) { |
| 384 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 385 | NiceMock<MockRtpRtcp> rtp_send; |
| 386 | NiceMock<MockRtpRtcp> rtp_recv; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 387 | PacketRouter packet_router; |
| 388 | packet_router.AddSendRtpModule(&rtp_send); |
| 389 | packet_router.AddReceiveRtpModule(&rtp_recv); |
| 390 | |
| 391 | uint32_t bitrate_estimate = 456; |
| 392 | std::vector<uint32_t> ssrcs = {1234, 5678}; |
| 393 | |
| 394 | ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); |
| 395 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 396 | |
| 397 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 398 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 399 | EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 400 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 401 | |
| 402 | // Decrease estimate to trigger a REMB. |
| 403 | bitrate_estimate = bitrate_estimate - 100; |
| 404 | EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 405 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 406 | |
| 407 | // Remove the sending module -> should get remb on the second module. |
| 408 | packet_router.RemoveSendRtpModule(&rtp_send); |
| 409 | |
| 410 | ON_CALL(rtp_send, REMB()).WillByDefault(Return(false)); |
| 411 | ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true)); |
| 412 | |
| 413 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 414 | |
| 415 | bitrate_estimate = bitrate_estimate - 100; |
| 416 | EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 417 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 418 | |
| 419 | packet_router.RemoveReceiveRtpModule(&rtp_recv); |
| 420 | } |
| 421 | |
| 422 | TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) { |
| 423 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 424 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 425 | PacketRouter packet_router; |
| 426 | packet_router.AddSendRtpModule(&rtp); |
| 427 | |
| 428 | uint32_t bitrate_estimate = 456; |
| 429 | const std::vector<uint32_t> ssrcs = {1234}; |
| 430 | |
| 431 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 432 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 433 | |
| 434 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 435 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 436 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1); |
| 437 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 438 | |
| 439 | // Lower the estimate, should trigger a call to SetREMBData right away. |
| 440 | bitrate_estimate = bitrate_estimate - 100; |
| 441 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 442 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 443 | |
| 444 | // Call OnReceiveBitrateChanged again, this should not trigger a new callback. |
| 445 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| 446 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 447 | packet_router.RemoveSendRtpModule(&rtp); |
| 448 | } |
| 449 | |
| 450 | // Only register receiving modules and make sure we fallback to trigger a REMB |
| 451 | // packet on this one. |
| 452 | TEST(PacketRouterRembTest, NoSendingRtpModule) { |
| 453 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame^] | 454 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 455 | PacketRouter packet_router; |
| 456 | |
| 457 | EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); |
| 458 | packet_router.AddReceiveRtpModule(&rtp); |
| 459 | |
| 460 | uint32_t bitrate_estimate = 456; |
| 461 | const std::vector<uint32_t> ssrcs = {1234}; |
| 462 | |
| 463 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 464 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 465 | |
| 466 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 467 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 468 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 469 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 470 | |
| 471 | // Lower the estimate to trigger a new packet REMB packet. |
| 472 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); |
| 473 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); |
| 474 | |
| 475 | EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); |
| 476 | packet_router.RemoveReceiveRtpModule(&rtp); |
| 477 | } |
| 478 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 479 | } // namespace webrtc |