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; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 28 | using ::testing::ReturnPointee; |
| 29 | using ::testing::SaveArg; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
| 32 | |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 33 | // TODO(eladalon): Restructure and/or replace the existing monolithic tests |
| 34 | // (only some of the test are monolithic) according to the new |
| 35 | // guidelines - small tests for one thing at a time. |
| 36 | // (I'm not removing any tests during CL, so as to demonstrate no regressions.) |
| 37 | |
| 38 | class MockRtpRtcpWithRembTracking : public MockRtpRtcp { |
| 39 | public: |
| 40 | MockRtpRtcpWithRembTracking() { |
| 41 | ON_CALL(*this, SetREMBStatus(_)).WillByDefault(SaveArg<0>(&remb_)); |
| 42 | ON_CALL(*this, REMB()).WillByDefault(ReturnPointee(&remb_)); |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | bool remb_ = false; |
| 47 | }; |
| 48 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 49 | class PacketRouterTest : public ::testing::Test { |
| 50 | public: |
| 51 | PacketRouterTest() : packet_router_(new PacketRouter()) {} |
| 52 | protected: |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 53 | static constexpr int kProbeMinProbes = 5; |
| 54 | static constexpr int kProbeMinBytes = 1000; |
kwiberg | 22feaa3 | 2016-03-17 09:17:43 -0700 | [diff] [blame] | 55 | const std::unique_ptr<PacketRouter> packet_router_; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | TEST_F(PacketRouterTest, TimeToSendPacket) { |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 59 | NiceMock<MockRtpRtcp> rtp_1; |
| 60 | NiceMock<MockRtpRtcp> rtp_2; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 61 | packet_router_->AddSendRtpModule(&rtp_1, false); |
| 62 | packet_router_->AddSendRtpModule(&rtp_2, false); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 63 | |
| 64 | const uint16_t kSsrc1 = 1234; |
| 65 | uint16_t sequence_number = 17; |
| 66 | uint64_t timestamp = 7890; |
| 67 | bool retransmission = false; |
| 68 | |
| 69 | // Send on the first module by letting rtp_1 be sending with correct ssrc. |
| 70 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 71 | EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 72 | EXPECT_CALL(rtp_1, TimeToSendPacket( |
| 73 | kSsrc1, sequence_number, timestamp, retransmission, |
| 74 | Field(&PacedPacketInfo::probe_cluster_id, 1))) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 75 | .Times(1) |
| 76 | .WillOnce(Return(true)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 77 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 78 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 79 | kSsrc1, sequence_number, timestamp, retransmission, |
| 80 | PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 81 | |
| 82 | // Send on the second module by letting rtp_2 be sending, but not rtp_1. |
| 83 | ++sequence_number; |
| 84 | timestamp += 30; |
| 85 | retransmission = true; |
| 86 | const uint16_t kSsrc2 = 4567; |
| 87 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); |
| 88 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 89 | EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 90 | EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 91 | EXPECT_CALL(rtp_2, TimeToSendPacket( |
| 92 | kSsrc2, sequence_number, timestamp, retransmission, |
| 93 | Field(&PacedPacketInfo::probe_cluster_id, 2))) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 94 | .Times(1) |
| 95 | .WillOnce(Return(true)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 96 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 97 | kSsrc2, sequence_number, timestamp, retransmission, |
| 98 | PacedPacketInfo(2, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 99 | |
| 100 | // No module is sending, hence no packet should be sent. |
| 101 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 102 | EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 103 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 104 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 105 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 106 | kSsrc1, sequence_number, timestamp, retransmission, |
| 107 | PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 108 | |
| 109 | // Add a packet with incorrect ssrc and test it's dropped in the router. |
| 110 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 111 | EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); |
| 112 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 113 | EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 114 | EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0); |
| 115 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 116 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 117 | kSsrc1 + kSsrc2, sequence_number, timestamp, retransmission, |
| 118 | PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 119 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 120 | packet_router_->RemoveSendRtpModule(&rtp_1); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 121 | |
| 122 | // rtp_1 has been removed, try sending a packet on that ssrc and make sure |
| 123 | // it is dropped as expected by not expecting any calls to rtp_1. |
| 124 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 125 | EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 126 | EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 127 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 128 | kSsrc1, sequence_number, timestamp, retransmission, |
| 129 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 130 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 131 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 132 | packet_router_->RemoveSendRtpModule(&rtp_2); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | TEST_F(PacketRouterTest, TimeToSendPadding) { |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 136 | const uint16_t kSsrc1 = 1234; |
| 137 | const uint16_t kSsrc2 = 4567; |
| 138 | |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 139 | NiceMock<MockRtpRtcp> rtp_1; |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 140 | EXPECT_CALL(rtp_1, RtxSendStatus()).WillOnce(Return(kRtxOff)); |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 141 | EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 142 | NiceMock<MockRtpRtcp> rtp_2; |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 143 | // rtp_2 will be prioritized for padding. |
| 144 | EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads)); |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 145 | EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 146 | packet_router_->AddSendRtpModule(&rtp_1, false); |
| 147 | packet_router_->AddSendRtpModule(&rtp_2, false); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 148 | |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 149 | // Default configuration, sending padding on all modules sending media, |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 150 | // ordered by priority (based on rtx mode). |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 151 | const size_t requested_padding_bytes = 1000; |
| 152 | const size_t sent_padding_bytes = 890; |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 153 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 154 | EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 155 | EXPECT_CALL(rtp_2, |
| 156 | TimeToSendPadding(requested_padding_bytes, |
| 157 | Field(&PacedPacketInfo::probe_cluster_id, 111))) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 158 | .Times(1) |
| 159 | .WillOnce(Return(sent_padding_bytes)); |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 160 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 161 | EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 162 | EXPECT_CALL(rtp_1, |
| 163 | TimeToSendPadding(requested_padding_bytes - sent_padding_bytes, |
| 164 | Field(&PacedPacketInfo::probe_cluster_id, 111))) |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 165 | .Times(1) |
| 166 | .WillOnce(Return(requested_padding_bytes - sent_padding_bytes)); |
| 167 | EXPECT_EQ(requested_padding_bytes, |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 168 | packet_router_->TimeToSendPadding( |
| 169 | requested_padding_bytes, |
| 170 | PacedPacketInfo(111, kProbeMinBytes, kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 171 | |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 172 | // Let only the lower priority module be sending and verify the padding |
| 173 | // request is routed there. |
| 174 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); |
| 175 | EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)).Times(0); |
| 176 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 177 | EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
stefan | 16b0221 | 2017-01-27 07:12:16 -0800 | [diff] [blame] | 178 | EXPECT_CALL(rtp_1, TimeToSendPadding(_, _)) |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 179 | .Times(1) |
| 180 | .WillOnce(Return(sent_padding_bytes)); |
| 181 | EXPECT_EQ(sent_padding_bytes, |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 182 | packet_router_->TimeToSendPadding( |
| 183 | requested_padding_bytes, |
| 184 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 185 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 186 | |
| 187 | // No sending module at all. |
| 188 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 189 | EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes, _)).Times(0); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 190 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 191 | EXPECT_CALL(rtp_2, TimeToSendPadding(_, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 192 | EXPECT_EQ(0u, |
| 193 | packet_router_->TimeToSendPadding( |
| 194 | requested_padding_bytes, |
| 195 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 196 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 197 | |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 198 | // Only one module has BWE extensions. |
| 199 | EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 200 | EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(false)); |
| 201 | EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes, _)).Times(0); |
| 202 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
| 203 | EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
| 204 | EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)) |
| 205 | .Times(1) |
| 206 | .WillOnce(Return(sent_padding_bytes)); |
| 207 | EXPECT_EQ(sent_padding_bytes, |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 208 | packet_router_->TimeToSendPadding( |
| 209 | requested_padding_bytes, |
| 210 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 211 | kProbeMinBytes))); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 212 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 213 | packet_router_->RemoveSendRtpModule(&rtp_1); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 214 | |
| 215 | // rtp_1 has been removed, try sending padding and make sure rtp_1 isn't asked |
| 216 | // to send by not expecting any calls. Instead verify rtp_2 is called. |
| 217 | EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); |
stefan | 53b6cc3 | 2017-02-03 08:13:57 -0800 | [diff] [blame] | 218 | EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 219 | EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)).Times(1); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 220 | EXPECT_EQ(0u, |
| 221 | packet_router_->TimeToSendPadding( |
| 222 | requested_padding_bytes, |
| 223 | PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, |
| 224 | kProbeMinBytes))); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 225 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 226 | packet_router_->RemoveSendRtpModule(&rtp_2); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | TEST_F(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) { |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 230 | NiceMock<MockRtpRtcp> rtp; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 231 | packet_router_->AddSendRtpModule(&rtp, false); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 232 | static const uint16_t kSsrc = 1234; |
| 233 | EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc)); |
| 234 | EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false)); |
| 235 | |
| 236 | // Verify that TimeToSendPacket does not end up in a receiver. |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 237 | EXPECT_CALL(rtp, TimeToSendPacket(_, _, _, _, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 238 | EXPECT_TRUE(packet_router_->TimeToSendPacket( |
| 239 | kSsrc, 1, 1, false, PacedPacketInfo(PacedPacketInfo::kNotAProbe, |
| 240 | kProbeMinBytes, kProbeMinBytes))); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 241 | // Verify that TimeToSendPadding does not end up in a receiver. |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 242 | EXPECT_CALL(rtp, TimeToSendPadding(_, _)).Times(0); |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 243 | EXPECT_EQ(0u, |
| 244 | packet_router_->TimeToSendPadding( |
| 245 | 200, PacedPacketInfo(PacedPacketInfo::kNotAProbe, |
| 246 | kProbeMinBytes, kProbeMinBytes))); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 247 | |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 248 | packet_router_->RemoveSendRtpModule(&rtp); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 249 | } |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 250 | |
| 251 | TEST_F(PacketRouterTest, AllocateSequenceNumbers) { |
| 252 | const uint16_t kStartSeq = 0xFFF0; |
| 253 | const size_t kNumPackets = 32; |
| 254 | |
| 255 | packet_router_->SetTransportWideSequenceNumber(kStartSeq - 1); |
| 256 | |
| 257 | for (size_t i = 0; i < kNumPackets; ++i) { |
| 258 | uint16_t seq = packet_router_->AllocateSequenceNumber(); |
| 259 | uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; |
| 260 | EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); |
| 261 | } |
| 262 | } |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 263 | |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 264 | TEST_F(PacketRouterTest, SendTransportFeedback) { |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 265 | NiceMock<MockRtpRtcp> rtp_1; |
| 266 | NiceMock<MockRtpRtcp> rtp_2; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 267 | packet_router_->AddSendRtpModule(&rtp_1, false); |
| 268 | packet_router_->AddReceiveRtpModule(&rtp_2, false); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 269 | |
| 270 | rtcp::TransportFeedback feedback; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 271 | EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); |
| 272 | packet_router_->SendTransportFeedback(&feedback); |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 273 | packet_router_->RemoveSendRtpModule(&rtp_1); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 274 | EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); |
| 275 | packet_router_->SendTransportFeedback(&feedback); |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 276 | packet_router_->RemoveReceiveRtpModule(&rtp_2); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 277 | } |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 278 | |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 279 | #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 280 | TEST_F(PacketRouterTest, DoubleRegistrationOfSendModuleDisallowed) { |
| 281 | NiceMock<MockRtpRtcp> module; |
| 282 | |
| 283 | constexpr bool remb_candidate = false; // Value irrelevant. |
| 284 | packet_router_->AddSendRtpModule(&module, remb_candidate); |
| 285 | EXPECT_DEATH(packet_router_->AddSendRtpModule(&module, remb_candidate), ""); |
| 286 | |
| 287 | // Test tear-down |
| 288 | packet_router_->RemoveSendRtpModule(&module); |
| 289 | } |
| 290 | |
| 291 | TEST_F(PacketRouterTest, DoubleRegistrationOfReceiveModuleDisallowed) { |
| 292 | NiceMock<MockRtpRtcp> module; |
| 293 | |
| 294 | constexpr bool remb_candidate = false; // Value irrelevant. |
| 295 | packet_router_->AddReceiveRtpModule(&module, remb_candidate); |
| 296 | EXPECT_DEATH(packet_router_->AddReceiveRtpModule(&module, remb_candidate), |
| 297 | ""); |
| 298 | |
| 299 | // Test tear-down |
| 300 | packet_router_->RemoveReceiveRtpModule(&module); |
| 301 | } |
| 302 | |
| 303 | TEST_F(PacketRouterTest, RemovalOfNeverAddedSendModuleDisallowed) { |
| 304 | NiceMock<MockRtpRtcp> module; |
| 305 | |
| 306 | EXPECT_DEATH(packet_router_->RemoveSendRtpModule(&module), ""); |
| 307 | } |
| 308 | |
| 309 | TEST_F(PacketRouterTest, RemovalOfNeverAddedReceiveModuleDisallowed) { |
| 310 | NiceMock<MockRtpRtcp> module; |
| 311 | |
| 312 | EXPECT_DEATH(packet_router_->RemoveReceiveRtpModule(&module), ""); |
| 313 | } |
| 314 | #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 315 | |
| 316 | // TODO(eladalon): Remove this test; it should be covered by: |
| 317 | // 1. SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst |
| 318 | // 2. SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst |
| 319 | // 3. LowerEstimateToSendRemb |
| 320 | // (Not removing in this CL to prove it doesn't break this test.) |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 321 | TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) { |
| 322 | rtc::ScopedFakeClock clock; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 323 | NiceMock<MockRtpRtcpWithRembTracking> rtp_recv; |
| 324 | NiceMock<MockRtpRtcpWithRembTracking> rtp_send; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 325 | PacketRouter packet_router; |
| 326 | |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 327 | packet_router.AddReceiveRtpModule(&rtp_recv, true); |
| 328 | ASSERT_TRUE(rtp_recv.REMB()); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 329 | |
| 330 | const uint32_t bitrate_estimate = 456; |
| 331 | const std::vector<uint32_t> ssrcs = {1234}; |
| 332 | |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 333 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 334 | |
| 335 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 336 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 337 | EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 338 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 339 | |
| 340 | // Add a send module, which should be preferred over the receive module. |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 341 | packet_router.AddSendRtpModule(&rtp_send, true); |
| 342 | EXPECT_FALSE(rtp_recv.REMB()); |
| 343 | EXPECT_TRUE(rtp_send.REMB()); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 344 | |
| 345 | // Lower bitrate to send another REMB packet. |
| 346 | EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); |
| 347 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); |
| 348 | |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 349 | packet_router.RemoveSendRtpModule(&rtp_send); |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 350 | EXPECT_TRUE(rtp_recv.REMB()); |
| 351 | EXPECT_FALSE(rtp_send.REMB()); |
| 352 | |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 353 | packet_router.RemoveReceiveRtpModule(&rtp_recv); |
| 354 | } |
| 355 | |
| 356 | TEST(PacketRouterRembTest, LowerEstimateToSendRemb) { |
| 357 | rtc::ScopedFakeClock clock; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 358 | NiceMock<MockRtpRtcpWithRembTracking> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 359 | PacketRouter packet_router; |
| 360 | |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 361 | packet_router.AddSendRtpModule(&rtp, true); |
| 362 | EXPECT_TRUE(rtp.REMB()); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 363 | |
| 364 | uint32_t bitrate_estimate = 456; |
| 365 | const std::vector<uint32_t> ssrcs = {1234}; |
| 366 | |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 367 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 368 | |
| 369 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 370 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 371 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 372 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 373 | |
| 374 | // Lower the estimate with more than 3% to trigger a call to SetREMBData right |
| 375 | // away. |
| 376 | bitrate_estimate = bitrate_estimate - 100; |
| 377 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 378 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 379 | |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 380 | packet_router.RemoveSendRtpModule(&rtp); |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 381 | EXPECT_FALSE(rtp.REMB()); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) { |
| 385 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 386 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 387 | PacketRouter packet_router; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 388 | packet_router.AddSendRtpModule(&rtp, true); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 389 | |
| 390 | uint32_t bitrate_estimate[] = {456, 789}; |
| 391 | std::vector<uint32_t> ssrcs = {1234, 5678}; |
| 392 | |
| 393 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 394 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); |
| 395 | |
| 396 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 397 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1); |
| 398 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 399 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); |
| 400 | |
| 401 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100); |
| 402 | |
| 403 | // Lower the estimate to trigger a callback. |
| 404 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1); |
| 405 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]); |
| 406 | |
| 407 | packet_router.RemoveSendRtpModule(&rtp); |
| 408 | } |
| 409 | |
| 410 | TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) { |
| 411 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 412 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 413 | PacketRouter packet_router; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 414 | packet_router.AddSendRtpModule(&rtp, true); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 415 | |
| 416 | uint32_t bitrate_estimate = 456; |
| 417 | std::vector<uint32_t> ssrcs = {1234, 5678}; |
| 418 | |
| 419 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 420 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 421 | |
| 422 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 423 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 424 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 425 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 426 | |
| 427 | // Increased estimate shouldn't trigger a callback right away. |
| 428 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| 429 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1); |
| 430 | |
| 431 | // Decreasing the estimate less than 3% shouldn't trigger a new callback. |
| 432 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| 433 | int lower_estimate = bitrate_estimate * 98 / 100; |
| 434 | packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate); |
| 435 | |
| 436 | packet_router.RemoveSendRtpModule(&rtp); |
| 437 | } |
| 438 | |
| 439 | TEST(PacketRouterRembTest, ChangeSendRtpModule) { |
| 440 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 441 | NiceMock<MockRtpRtcp> rtp_send; |
| 442 | NiceMock<MockRtpRtcp> rtp_recv; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 443 | PacketRouter packet_router; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 444 | packet_router.AddSendRtpModule(&rtp_send, true); |
| 445 | packet_router.AddReceiveRtpModule(&rtp_recv, true); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 446 | |
| 447 | uint32_t bitrate_estimate = 456; |
| 448 | std::vector<uint32_t> ssrcs = {1234, 5678}; |
| 449 | |
| 450 | ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); |
| 451 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 452 | |
| 453 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 454 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 455 | EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 456 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 457 | |
| 458 | // Decrease estimate to trigger a REMB. |
| 459 | bitrate_estimate = bitrate_estimate - 100; |
| 460 | EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 461 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 462 | |
| 463 | // Remove the sending module -> should get remb on the second module. |
| 464 | packet_router.RemoveSendRtpModule(&rtp_send); |
| 465 | |
| 466 | ON_CALL(rtp_send, REMB()).WillByDefault(Return(false)); |
| 467 | ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true)); |
| 468 | |
| 469 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 470 | |
| 471 | bitrate_estimate = bitrate_estimate - 100; |
| 472 | EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 473 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 474 | |
| 475 | packet_router.RemoveReceiveRtpModule(&rtp_recv); |
| 476 | } |
| 477 | |
| 478 | TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) { |
| 479 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 480 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 481 | PacketRouter packet_router; |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 482 | packet_router.AddSendRtpModule(&rtp, true); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 483 | |
| 484 | uint32_t bitrate_estimate = 456; |
| 485 | const std::vector<uint32_t> ssrcs = {1234}; |
| 486 | |
| 487 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 488 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 489 | |
| 490 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 491 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 492 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1); |
| 493 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 494 | |
| 495 | // Lower the estimate, should trigger a call to SetREMBData right away. |
| 496 | bitrate_estimate = bitrate_estimate - 100; |
| 497 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 498 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 499 | |
| 500 | // Call OnReceiveBitrateChanged again, this should not trigger a new callback. |
| 501 | EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); |
| 502 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 503 | packet_router.RemoveSendRtpModule(&rtp); |
| 504 | } |
| 505 | |
| 506 | // Only register receiving modules and make sure we fallback to trigger a REMB |
| 507 | // packet on this one. |
| 508 | TEST(PacketRouterRembTest, NoSendingRtpModule) { |
| 509 | rtc::ScopedFakeClock clock; |
eladalon | 6c9556e | 2017-07-10 03:33:00 -0700 | [diff] [blame] | 510 | NiceMock<MockRtpRtcp> rtp; |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 511 | PacketRouter packet_router; |
| 512 | |
| 513 | EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 514 | packet_router.AddReceiveRtpModule(&rtp, true); |
nisse | 0584331 | 2017-04-18 23:38:35 -0700 | [diff] [blame] | 515 | |
| 516 | uint32_t bitrate_estimate = 456; |
| 517 | const std::vector<uint32_t> ssrcs = {1234}; |
| 518 | |
| 519 | ON_CALL(rtp, REMB()).WillByDefault(Return(true)); |
| 520 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 521 | |
| 522 | // Call OnReceiveBitrateChanged twice to get a first estimate. |
| 523 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 524 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 525 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 526 | |
| 527 | // Lower the estimate to trigger a new packet REMB packet. |
| 528 | EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); |
| 529 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); |
| 530 | |
| 531 | EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); |
| 532 | packet_router.RemoveReceiveRtpModule(&rtp); |
| 533 | } |
| 534 | |
eladalon | 822ff2b | 2017-08-01 06:30:28 -0700 | [diff] [blame] | 535 | TEST(PacketRouterRembTest, NonCandidateSendRtpModuleNotUsedForRemb) { |
| 536 | rtc::ScopedFakeClock clock; |
| 537 | PacketRouter packet_router; |
| 538 | NiceMock<MockRtpRtcpWithRembTracking> module; |
| 539 | |
| 540 | constexpr bool remb_candidate = false; |
| 541 | |
| 542 | packet_router.AddSendRtpModule(&module, remb_candidate); |
| 543 | EXPECT_FALSE(module.REMB()); |
| 544 | |
| 545 | constexpr uint32_t bitrate_estimate = 456; |
| 546 | const std::vector<uint32_t> ssrcs = {1234}; |
| 547 | EXPECT_CALL(module, SetREMBData(_, _)).Times(0); |
| 548 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 549 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 550 | |
| 551 | // Test tear-down |
| 552 | packet_router.RemoveSendRtpModule(&module); |
| 553 | } |
| 554 | |
| 555 | TEST(PacketRouterRembTest, CandidateSendRtpModuleUsedForRemb) { |
| 556 | rtc::ScopedFakeClock clock; |
| 557 | PacketRouter packet_router; |
| 558 | NiceMock<MockRtpRtcpWithRembTracking> module; |
| 559 | |
| 560 | constexpr bool remb_candidate = true; |
| 561 | |
| 562 | packet_router.AddSendRtpModule(&module, remb_candidate); |
| 563 | EXPECT_TRUE(module.REMB()); |
| 564 | |
| 565 | constexpr uint32_t bitrate_estimate = 456; |
| 566 | const std::vector<uint32_t> ssrcs = {1234}; |
| 567 | EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 568 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 569 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 570 | |
| 571 | // Test tear-down |
| 572 | packet_router.RemoveSendRtpModule(&module); |
| 573 | } |
| 574 | |
| 575 | TEST(PacketRouterRembTest, NonCandidateReceiveRtpModuleNotUsedForRemb) { |
| 576 | rtc::ScopedFakeClock clock; |
| 577 | PacketRouter packet_router; |
| 578 | NiceMock<MockRtpRtcpWithRembTracking> module; |
| 579 | |
| 580 | constexpr bool remb_candidate = false; |
| 581 | |
| 582 | packet_router.AddReceiveRtpModule(&module, remb_candidate); |
| 583 | ASSERT_FALSE(module.REMB()); |
| 584 | |
| 585 | constexpr uint32_t bitrate_estimate = 456; |
| 586 | const std::vector<uint32_t> ssrcs = {1234}; |
| 587 | EXPECT_CALL(module, SetREMBData(_, _)).Times(0); |
| 588 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 589 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 590 | |
| 591 | // Test tear-down |
| 592 | packet_router.RemoveReceiveRtpModule(&module); |
| 593 | } |
| 594 | |
| 595 | TEST(PacketRouterRembTest, CandidateReceiveRtpModuleUsedForRemb) { |
| 596 | rtc::ScopedFakeClock clock; |
| 597 | PacketRouter packet_router; |
| 598 | NiceMock<MockRtpRtcpWithRembTracking> module; |
| 599 | |
| 600 | constexpr bool remb_candidate = true; |
| 601 | |
| 602 | packet_router.AddReceiveRtpModule(&module, remb_candidate); |
| 603 | EXPECT_TRUE(module.REMB()); |
| 604 | |
| 605 | constexpr uint32_t bitrate_estimate = 456; |
| 606 | const std::vector<uint32_t> ssrcs = {1234}; |
| 607 | EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 608 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 609 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 610 | |
| 611 | // Test tear-down |
| 612 | packet_router.RemoveReceiveRtpModule(&module); |
| 613 | } |
| 614 | |
| 615 | TEST(PacketRouterRembTest, |
| 616 | SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst) { |
| 617 | rtc::ScopedFakeClock clock; |
| 618 | PacketRouter packet_router; |
| 619 | NiceMock<MockRtpRtcpWithRembTracking> send_module; |
| 620 | NiceMock<MockRtpRtcpWithRembTracking> receive_module; |
| 621 | |
| 622 | constexpr bool remb_candidate = true; |
| 623 | |
| 624 | // Send module added - activated. |
| 625 | packet_router.AddSendRtpModule(&send_module, remb_candidate); |
| 626 | ASSERT_TRUE(send_module.REMB()); |
| 627 | |
| 628 | // Receive module added - the send module remains the active one. |
| 629 | packet_router.AddReceiveRtpModule(&receive_module, remb_candidate); |
| 630 | EXPECT_TRUE(send_module.REMB()); |
| 631 | EXPECT_FALSE(receive_module.REMB()); |
| 632 | |
| 633 | constexpr uint32_t bitrate_estimate = 456; |
| 634 | const std::vector<uint32_t> ssrcs = {1234}; |
| 635 | EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 636 | EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0); |
| 637 | |
| 638 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 639 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 640 | |
| 641 | // Test tear-down |
| 642 | packet_router.RemoveReceiveRtpModule(&receive_module); |
| 643 | packet_router.RemoveSendRtpModule(&send_module); |
| 644 | } |
| 645 | |
| 646 | TEST(PacketRouterRembTest, |
| 647 | SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst) { |
| 648 | rtc::ScopedFakeClock clock; |
| 649 | PacketRouter packet_router; |
| 650 | NiceMock<MockRtpRtcpWithRembTracking> send_module; |
| 651 | NiceMock<MockRtpRtcpWithRembTracking> receive_module; |
| 652 | |
| 653 | constexpr bool remb_candidate = true; |
| 654 | |
| 655 | // Receive module added - activated. |
| 656 | packet_router.AddReceiveRtpModule(&receive_module, remb_candidate); |
| 657 | ASSERT_TRUE(receive_module.REMB()); |
| 658 | |
| 659 | // Send module added - replaces receive module as active. |
| 660 | packet_router.AddSendRtpModule(&send_module, remb_candidate); |
| 661 | EXPECT_FALSE(receive_module.REMB()); |
| 662 | EXPECT_TRUE(send_module.REMB()); |
| 663 | |
| 664 | constexpr uint32_t bitrate_estimate = 456; |
| 665 | const std::vector<uint32_t> ssrcs = {1234}; |
| 666 | EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 667 | EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0); |
| 668 | |
| 669 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 670 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 671 | |
| 672 | // Test tear-down |
| 673 | packet_router.RemoveReceiveRtpModule(&receive_module); |
| 674 | packet_router.RemoveSendRtpModule(&send_module); |
| 675 | } |
| 676 | |
| 677 | TEST(PacketRouterRembTest, ReceiveModuleTakesOverWhenLastSendModuleRemoved) { |
| 678 | rtc::ScopedFakeClock clock; |
| 679 | PacketRouter packet_router; |
| 680 | NiceMock<MockRtpRtcpWithRembTracking> send_module; |
| 681 | NiceMock<MockRtpRtcpWithRembTracking> receive_module; |
| 682 | |
| 683 | constexpr bool remb_candidate = true; |
| 684 | |
| 685 | // Send module active, receive module inactive. |
| 686 | packet_router.AddSendRtpModule(&send_module, remb_candidate); |
| 687 | packet_router.AddReceiveRtpModule(&receive_module, remb_candidate); |
| 688 | ASSERT_TRUE(send_module.REMB()); |
| 689 | ASSERT_FALSE(receive_module.REMB()); |
| 690 | |
| 691 | // Send module removed - receive module becomes active. |
| 692 | packet_router.RemoveSendRtpModule(&send_module); |
| 693 | EXPECT_FALSE(send_module.REMB()); |
| 694 | EXPECT_TRUE(receive_module.REMB()); |
| 695 | constexpr uint32_t bitrate_estimate = 456; |
| 696 | const std::vector<uint32_t> ssrcs = {1234}; |
| 697 | EXPECT_CALL(send_module, SetREMBData(_, _)).Times(0); |
| 698 | EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); |
| 699 | |
| 700 | clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); |
| 701 | packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); |
| 702 | |
| 703 | // Test tear-down |
| 704 | packet_router.RemoveReceiveRtpModule(&receive_module); |
| 705 | } |
| 706 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 707 | } // namespace webrtc |