blob: de3206688a5e98bec0a833ab0480fa854430fec4 [file] [log] [blame]
Stefan Holmere5904162015-03-26 11:11:06 +01001/*
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>
kwiberg22feaa32016-03-17 09:17:43 -070012#include <memory>
Stefan Holmere5904162015-03-26 11:11:06 +010013
Henrik Kjellander0b9e29c2015-11-16 11:12:24 +010014#include "webrtc/modules/pacing/packet_router.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010015#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
Stefan Holmere5904162015-03-26 11:11:06 +010016#include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
stefanbba9dec2016-02-01 04:39:55 -080017#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020018#include "webrtc/rtc_base/checks.h"
19#include "webrtc/rtc_base/fakeclock.h"
kwibergac9f8762016-09-30 22:29:43 -070020#include "webrtc/test/gmock.h"
21#include "webrtc/test/gtest.h"
Stefan Holmere5904162015-03-26 11:11:06 +010022
23using ::testing::_;
24using ::testing::AnyNumber;
philipelc7bf32a2017-02-17 03:59:43 -080025using ::testing::Field;
Stefan Holmere5904162015-03-26 11:11:06 +010026using ::testing::NiceMock;
27using ::testing::Return;
eladalon822ff2b2017-08-01 06:30:28 -070028using ::testing::ReturnPointee;
29using ::testing::SaveArg;
Stefan Holmere5904162015-03-26 11:11:06 +010030
31namespace webrtc {
32
eladalon822ff2b2017-08-01 06:30:28 -070033// 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
eladalonb1338fe2017-08-01 09:36:19 -070038namespace {
39constexpr int kProbeMinProbes = 5;
40constexpr int kProbeMinBytes = 1000;
41
eladalon822ff2b2017-08-01 06:30:28 -070042class MockRtpRtcpWithRembTracking : public MockRtpRtcp {
43 public:
44 MockRtpRtcpWithRembTracking() {
45 ON_CALL(*this, SetREMBStatus(_)).WillByDefault(SaveArg<0>(&remb_));
46 ON_CALL(*this, REMB()).WillByDefault(ReturnPointee(&remb_));
47 }
48
49 private:
50 bool remb_ = false;
51};
eladalonb1338fe2017-08-01 09:36:19 -070052} // namespace
eladalon822ff2b2017-08-01 06:30:28 -070053
eladalon32040ef2017-08-02 06:29:00 -070054TEST(PacketRouterTest, Sanity_NoModuleRegistered_TimeToSendPacket) {
55 PacketRouter packet_router;
56
57 constexpr uint16_t ssrc = 1234;
58 constexpr uint16_t sequence_number = 17;
59 constexpr uint64_t timestamp = 7890;
60 constexpr bool retransmission = false;
61 const PacedPacketInfo paced_info(1, kProbeMinProbes, kProbeMinBytes);
62
63 // TODO(eladalon): TimeToSendPacket() returning true when nothing was
64 // sent, because no modules were registered, is sub-optimal.
65 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8052
66 EXPECT_TRUE(packet_router.TimeToSendPacket(ssrc, sequence_number, timestamp,
67 retransmission, paced_info));
68}
69
70TEST(PacketRouterTest, Sanity_NoModuleRegistered_TimeToSendPadding) {
71 PacketRouter packet_router;
72
73 constexpr size_t bytes = 300;
74 const PacedPacketInfo paced_info(1, kProbeMinProbes, kProbeMinBytes);
75
76 EXPECT_EQ(packet_router.TimeToSendPadding(bytes, paced_info), 0u);
77}
78
79TEST(PacketRouterTest, Sanity_NoModuleRegistered_OnReceiveBitrateChanged) {
80 PacketRouter packet_router;
81
82 const std::vector<uint32_t> ssrcs = {1, 2, 3};
83 constexpr uint32_t bitrate_bps = 10000;
84
85 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_bps);
86}
87
88TEST(PacketRouterTest, Sanity_NoModuleRegistered_SendRemb) {
89 PacketRouter packet_router;
90
91 const std::vector<uint32_t> ssrcs = {1, 2, 3};
92 constexpr uint32_t bitrate_bps = 10000;
93
94 EXPECT_FALSE(packet_router.SendRemb(bitrate_bps, ssrcs));
95}
96
97TEST(PacketRouterTest, Sanity_NoModuleRegistered_SendTransportFeedback) {
98 PacketRouter packet_router;
99
100 rtcp::TransportFeedback feedback;
101
102 EXPECT_FALSE(packet_router.SendTransportFeedback(&feedback));
103}
104
eladalonb1338fe2017-08-01 09:36:19 -0700105TEST(PacketRouterTest, TimeToSendPacket) {
106 PacketRouter packet_router;
eladalon6c9556e2017-07-10 03:33:00 -0700107 NiceMock<MockRtpRtcp> rtp_1;
108 NiceMock<MockRtpRtcp> rtp_2;
eladalonb1338fe2017-08-01 09:36:19 -0700109
110 packet_router.AddSendRtpModule(&rtp_1, false);
111 packet_router.AddSendRtpModule(&rtp_2, false);
Stefan Holmere5904162015-03-26 11:11:06 +0100112
113 const uint16_t kSsrc1 = 1234;
114 uint16_t sequence_number = 17;
115 uint64_t timestamp = 7890;
116 bool retransmission = false;
117
118 // Send on the first module by letting rtp_1 be sending with correct ssrc.
119 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true));
120 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1));
philipelc7bf32a2017-02-17 03:59:43 -0800121 EXPECT_CALL(rtp_1, TimeToSendPacket(
122 kSsrc1, sequence_number, timestamp, retransmission,
123 Field(&PacedPacketInfo::probe_cluster_id, 1)))
Stefan Holmere5904162015-03-26 11:11:06 +0100124 .Times(1)
125 .WillOnce(Return(true));
philipela1ed0b32016-06-01 06:31:17 -0700126 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0);
eladalonb1338fe2017-08-01 09:36:19 -0700127 EXPECT_TRUE(packet_router.TimeToSendPacket(
philipelc7bf32a2017-02-17 03:59:43 -0800128 kSsrc1, sequence_number, timestamp, retransmission,
129 PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100130
131 // Send on the second module by letting rtp_2 be sending, but not rtp_1.
132 ++sequence_number;
133 timestamp += 30;
134 retransmission = true;
135 const uint16_t kSsrc2 = 4567;
136 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false));
137 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true));
138 EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2));
philipela1ed0b32016-06-01 06:31:17 -0700139 EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0);
philipelc7bf32a2017-02-17 03:59:43 -0800140 EXPECT_CALL(rtp_2, TimeToSendPacket(
141 kSsrc2, sequence_number, timestamp, retransmission,
142 Field(&PacedPacketInfo::probe_cluster_id, 2)))
Stefan Holmere5904162015-03-26 11:11:06 +0100143 .Times(1)
144 .WillOnce(Return(true));
eladalonb1338fe2017-08-01 09:36:19 -0700145 EXPECT_TRUE(packet_router.TimeToSendPacket(
philipelc7bf32a2017-02-17 03:59:43 -0800146 kSsrc2, sequence_number, timestamp, retransmission,
147 PacedPacketInfo(2, kProbeMinProbes, kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100148
149 // No module is sending, hence no packet should be sent.
150 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false));
philipela1ed0b32016-06-01 06:31:17 -0700151 EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0);
Stefan Holmere5904162015-03-26 11:11:06 +0100152 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false));
philipela1ed0b32016-06-01 06:31:17 -0700153 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0);
eladalonb1338fe2017-08-01 09:36:19 -0700154 EXPECT_TRUE(packet_router.TimeToSendPacket(
philipelc7bf32a2017-02-17 03:59:43 -0800155 kSsrc1, sequence_number, timestamp, retransmission,
156 PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100157
158 // Add a packet with incorrect ssrc and test it's dropped in the router.
159 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true));
160 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1));
161 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true));
162 EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2));
philipela1ed0b32016-06-01 06:31:17 -0700163 EXPECT_CALL(rtp_1, TimeToSendPacket(_, _, _, _, _)).Times(0);
164 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0);
eladalonb1338fe2017-08-01 09:36:19 -0700165 EXPECT_TRUE(packet_router.TimeToSendPacket(
philipelc7bf32a2017-02-17 03:59:43 -0800166 kSsrc1 + kSsrc2, sequence_number, timestamp, retransmission,
167 PacedPacketInfo(1, kProbeMinProbes, kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100168
eladalonb1338fe2017-08-01 09:36:19 -0700169 packet_router.RemoveSendRtpModule(&rtp_1);
Stefan Holmere5904162015-03-26 11:11:06 +0100170
171 // rtp_1 has been removed, try sending a packet on that ssrc and make sure
172 // it is dropped as expected by not expecting any calls to rtp_1.
173 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true));
174 EXPECT_CALL(rtp_2, SSRC()).Times(1).WillOnce(Return(kSsrc2));
philipela1ed0b32016-06-01 06:31:17 -0700175 EXPECT_CALL(rtp_2, TimeToSendPacket(_, _, _, _, _)).Times(0);
eladalonb1338fe2017-08-01 09:36:19 -0700176 EXPECT_TRUE(packet_router.TimeToSendPacket(
philipelc7bf32a2017-02-17 03:59:43 -0800177 kSsrc1, sequence_number, timestamp, retransmission,
178 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes,
179 kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100180
eladalonb1338fe2017-08-01 09:36:19 -0700181 packet_router.RemoveSendRtpModule(&rtp_2);
Stefan Holmere5904162015-03-26 11:11:06 +0100182}
183
eladalonb1338fe2017-08-01 09:36:19 -0700184TEST(PacketRouterTest, TimeToSendPadding) {
185 PacketRouter packet_router;
186
sprang867fb522015-08-03 04:38:41 -0700187 const uint16_t kSsrc1 = 1234;
188 const uint16_t kSsrc2 = 4567;
189
eladalon6c9556e2017-07-10 03:33:00 -0700190 NiceMock<MockRtpRtcp> rtp_1;
stefan16b02212017-01-27 07:12:16 -0800191 EXPECT_CALL(rtp_1, RtxSendStatus()).WillOnce(Return(kRtxOff));
sprang867fb522015-08-03 04:38:41 -0700192 EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1));
eladalon6c9556e2017-07-10 03:33:00 -0700193 NiceMock<MockRtpRtcp> rtp_2;
stefan16b02212017-01-27 07:12:16 -0800194 // rtp_2 will be prioritized for padding.
195 EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads));
sprang867fb522015-08-03 04:38:41 -0700196 EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2));
eladalonb1338fe2017-08-01 09:36:19 -0700197 packet_router.AddSendRtpModule(&rtp_1, false);
198 packet_router.AddSendRtpModule(&rtp_2, false);
Stefan Holmere5904162015-03-26 11:11:06 +0100199
sprang867fb522015-08-03 04:38:41 -0700200 // Default configuration, sending padding on all modules sending media,
stefan16b02212017-01-27 07:12:16 -0800201 // ordered by priority (based on rtx mode).
Stefan Holmere5904162015-03-26 11:11:06 +0100202 const size_t requested_padding_bytes = 1000;
203 const size_t sent_padding_bytes = 890;
stefan16b02212017-01-27 07:12:16 -0800204 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true));
stefan53b6cc32017-02-03 08:13:57 -0800205 EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true));
philipelc7bf32a2017-02-17 03:59:43 -0800206 EXPECT_CALL(rtp_2,
207 TimeToSendPadding(requested_padding_bytes,
208 Field(&PacedPacketInfo::probe_cluster_id, 111)))
Stefan Holmere5904162015-03-26 11:11:06 +0100209 .Times(1)
210 .WillOnce(Return(sent_padding_bytes));
stefan16b02212017-01-27 07:12:16 -0800211 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true));
stefan53b6cc32017-02-03 08:13:57 -0800212 EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(true));
philipelc7bf32a2017-02-17 03:59:43 -0800213 EXPECT_CALL(rtp_1,
214 TimeToSendPadding(requested_padding_bytes - sent_padding_bytes,
215 Field(&PacedPacketInfo::probe_cluster_id, 111)))
sprang867fb522015-08-03 04:38:41 -0700216 .Times(1)
217 .WillOnce(Return(requested_padding_bytes - sent_padding_bytes));
218 EXPECT_EQ(requested_padding_bytes,
eladalonb1338fe2017-08-01 09:36:19 -0700219 packet_router.TimeToSendPadding(
philipelc7bf32a2017-02-17 03:59:43 -0800220 requested_padding_bytes,
221 PacedPacketInfo(111, kProbeMinBytes, kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100222
stefan16b02212017-01-27 07:12:16 -0800223 // Let only the lower priority module be sending and verify the padding
224 // request is routed there.
225 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false));
226 EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)).Times(0);
227 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true));
stefan53b6cc32017-02-03 08:13:57 -0800228 EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(true));
stefan16b02212017-01-27 07:12:16 -0800229 EXPECT_CALL(rtp_1, TimeToSendPadding(_, _))
Stefan Holmere5904162015-03-26 11:11:06 +0100230 .Times(1)
231 .WillOnce(Return(sent_padding_bytes));
232 EXPECT_EQ(sent_padding_bytes,
eladalonb1338fe2017-08-01 09:36:19 -0700233 packet_router.TimeToSendPadding(
philipelc7bf32a2017-02-17 03:59:43 -0800234 requested_padding_bytes,
235 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes,
236 kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100237
238 // No sending module at all.
239 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(false));
philipela1ed0b32016-06-01 06:31:17 -0700240 EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes, _)).Times(0);
Stefan Holmere5904162015-03-26 11:11:06 +0100241 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(false));
philipela1ed0b32016-06-01 06:31:17 -0700242 EXPECT_CALL(rtp_2, TimeToSendPadding(_, _)).Times(0);
philipelc7bf32a2017-02-17 03:59:43 -0800243 EXPECT_EQ(0u,
eladalonb1338fe2017-08-01 09:36:19 -0700244 packet_router.TimeToSendPadding(
philipelc7bf32a2017-02-17 03:59:43 -0800245 requested_padding_bytes,
246 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes,
247 kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100248
stefan53b6cc32017-02-03 08:13:57 -0800249 // Only one module has BWE extensions.
250 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true));
251 EXPECT_CALL(rtp_1, HasBweExtensions()).Times(1).WillOnce(Return(false));
252 EXPECT_CALL(rtp_1, TimeToSendPadding(requested_padding_bytes, _)).Times(0);
253 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true));
254 EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true));
255 EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _))
256 .Times(1)
257 .WillOnce(Return(sent_padding_bytes));
258 EXPECT_EQ(sent_padding_bytes,
eladalonb1338fe2017-08-01 09:36:19 -0700259 packet_router.TimeToSendPadding(
philipelc7bf32a2017-02-17 03:59:43 -0800260 requested_padding_bytes,
261 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes,
262 kProbeMinBytes)));
stefan53b6cc32017-02-03 08:13:57 -0800263
eladalonb1338fe2017-08-01 09:36:19 -0700264 packet_router.RemoveSendRtpModule(&rtp_1);
Stefan Holmere5904162015-03-26 11:11:06 +0100265
266 // rtp_1 has been removed, try sending padding and make sure rtp_1 isn't asked
267 // to send by not expecting any calls. Instead verify rtp_2 is called.
268 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true));
stefan53b6cc32017-02-03 08:13:57 -0800269 EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true));
philipela1ed0b32016-06-01 06:31:17 -0700270 EXPECT_CALL(rtp_2, TimeToSendPadding(requested_padding_bytes, _)).Times(1);
philipelc7bf32a2017-02-17 03:59:43 -0800271 EXPECT_EQ(0u,
eladalonb1338fe2017-08-01 09:36:19 -0700272 packet_router.TimeToSendPadding(
philipelc7bf32a2017-02-17 03:59:43 -0800273 requested_padding_bytes,
274 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes,
275 kProbeMinBytes)));
Stefan Holmere5904162015-03-26 11:11:06 +0100276
eladalonb1338fe2017-08-01 09:36:19 -0700277 packet_router.RemoveSendRtpModule(&rtp_2);
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100278}
279
eladalonb1338fe2017-08-01 09:36:19 -0700280TEST(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) {
281 PacketRouter packet_router;
eladalon6c9556e2017-07-10 03:33:00 -0700282 NiceMock<MockRtpRtcp> rtp;
eladalonb1338fe2017-08-01 09:36:19 -0700283 packet_router.AddSendRtpModule(&rtp, false);
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100284 static const uint16_t kSsrc = 1234;
285 EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc));
286 EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false));
287
288 // Verify that TimeToSendPacket does not end up in a receiver.
philipela1ed0b32016-06-01 06:31:17 -0700289 EXPECT_CALL(rtp, TimeToSendPacket(_, _, _, _, _)).Times(0);
eladalonb1338fe2017-08-01 09:36:19 -0700290 EXPECT_TRUE(packet_router.TimeToSendPacket(
philipelc7bf32a2017-02-17 03:59:43 -0800291 kSsrc, 1, 1, false, PacedPacketInfo(PacedPacketInfo::kNotAProbe,
292 kProbeMinBytes, kProbeMinBytes)));
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100293 // Verify that TimeToSendPadding does not end up in a receiver.
philipela1ed0b32016-06-01 06:31:17 -0700294 EXPECT_CALL(rtp, TimeToSendPadding(_, _)).Times(0);
philipelc7bf32a2017-02-17 03:59:43 -0800295 EXPECT_EQ(0u,
eladalonb1338fe2017-08-01 09:36:19 -0700296 packet_router.TimeToSendPadding(
philipelc7bf32a2017-02-17 03:59:43 -0800297 200, PacedPacketInfo(PacedPacketInfo::kNotAProbe,
298 kProbeMinBytes, kProbeMinBytes)));
Peter Boström3dd5d1d2016-02-25 16:56:48 +0100299
eladalonb1338fe2017-08-01 09:36:19 -0700300 packet_router.RemoveSendRtpModule(&rtp);
Stefan Holmere5904162015-03-26 11:11:06 +0100301}
sprang867fb522015-08-03 04:38:41 -0700302
eladalonb1338fe2017-08-01 09:36:19 -0700303TEST(PacketRouterTest, AllocateSequenceNumbers) {
304 PacketRouter packet_router;
305
sprang867fb522015-08-03 04:38:41 -0700306 const uint16_t kStartSeq = 0xFFF0;
307 const size_t kNumPackets = 32;
308
eladalonb1338fe2017-08-01 09:36:19 -0700309 packet_router.SetTransportWideSequenceNumber(kStartSeq - 1);
sprang867fb522015-08-03 04:38:41 -0700310
311 for (size_t i = 0; i < kNumPackets; ++i) {
eladalonb1338fe2017-08-01 09:36:19 -0700312 uint16_t seq = packet_router.AllocateSequenceNumber();
sprang867fb522015-08-03 04:38:41 -0700313 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i;
314 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq);
315 }
316}
stefanbba9dec2016-02-01 04:39:55 -0800317
eladalonb1338fe2017-08-01 09:36:19 -0700318TEST(PacketRouterTest, SendTransportFeedback) {
319 PacketRouter packet_router;
eladalon6c9556e2017-07-10 03:33:00 -0700320 NiceMock<MockRtpRtcp> rtp_1;
321 NiceMock<MockRtpRtcp> rtp_2;
eladalonb1338fe2017-08-01 09:36:19 -0700322
323 packet_router.AddSendRtpModule(&rtp_1, false);
324 packet_router.AddReceiveRtpModule(&rtp_2, false);
stefanbba9dec2016-02-01 04:39:55 -0800325
326 rtcp::TransportFeedback feedback;
nisse05843312017-04-18 23:38:35 -0700327 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true));
eladalonb1338fe2017-08-01 09:36:19 -0700328 packet_router.SendTransportFeedback(&feedback);
329 packet_router.RemoveSendRtpModule(&rtp_1);
nisse05843312017-04-18 23:38:35 -0700330 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true));
eladalonb1338fe2017-08-01 09:36:19 -0700331 packet_router.SendTransportFeedback(&feedback);
332 packet_router.RemoveReceiveRtpModule(&rtp_2);
stefanbba9dec2016-02-01 04:39:55 -0800333}
nisse05843312017-04-18 23:38:35 -0700334
eladalon822ff2b2017-08-01 06:30:28 -0700335#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
eladalonb1338fe2017-08-01 09:36:19 -0700336TEST(PacketRouterTest, DoubleRegistrationOfSendModuleDisallowed) {
337 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700338 NiceMock<MockRtpRtcp> module;
339
340 constexpr bool remb_candidate = false; // Value irrelevant.
eladalonb1338fe2017-08-01 09:36:19 -0700341 packet_router.AddSendRtpModule(&module, remb_candidate);
342 EXPECT_DEATH(packet_router.AddSendRtpModule(&module, remb_candidate), "");
eladalon822ff2b2017-08-01 06:30:28 -0700343
344 // Test tear-down
eladalonb1338fe2017-08-01 09:36:19 -0700345 packet_router.RemoveSendRtpModule(&module);
eladalon822ff2b2017-08-01 06:30:28 -0700346}
347
eladalonb1338fe2017-08-01 09:36:19 -0700348TEST(PacketRouterTest, DoubleRegistrationOfReceiveModuleDisallowed) {
349 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700350 NiceMock<MockRtpRtcp> module;
351
352 constexpr bool remb_candidate = false; // Value irrelevant.
eladalonb1338fe2017-08-01 09:36:19 -0700353 packet_router.AddReceiveRtpModule(&module, remb_candidate);
354 EXPECT_DEATH(packet_router.AddReceiveRtpModule(&module, remb_candidate), "");
eladalon822ff2b2017-08-01 06:30:28 -0700355
356 // Test tear-down
eladalonb1338fe2017-08-01 09:36:19 -0700357 packet_router.RemoveReceiveRtpModule(&module);
eladalon822ff2b2017-08-01 06:30:28 -0700358}
359
eladalonb1338fe2017-08-01 09:36:19 -0700360TEST(PacketRouterTest, RemovalOfNeverAddedSendModuleDisallowed) {
361 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700362 NiceMock<MockRtpRtcp> module;
363
eladalonb1338fe2017-08-01 09:36:19 -0700364 EXPECT_DEATH(packet_router.RemoveSendRtpModule(&module), "");
eladalon822ff2b2017-08-01 06:30:28 -0700365}
366
eladalonb1338fe2017-08-01 09:36:19 -0700367TEST(PacketRouterTest, RemovalOfNeverAddedReceiveModuleDisallowed) {
368 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700369 NiceMock<MockRtpRtcp> module;
370
eladalonb1338fe2017-08-01 09:36:19 -0700371 EXPECT_DEATH(packet_router.RemoveReceiveRtpModule(&module), "");
eladalon822ff2b2017-08-01 06:30:28 -0700372}
373#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
374
375// TODO(eladalon): Remove this test; it should be covered by:
376// 1. SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst
377// 2. SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst
378// 3. LowerEstimateToSendRemb
379// (Not removing in this CL to prove it doesn't break this test.)
nisse05843312017-04-18 23:38:35 -0700380TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) {
381 rtc::ScopedFakeClock clock;
eladalon822ff2b2017-08-01 06:30:28 -0700382 NiceMock<MockRtpRtcpWithRembTracking> rtp_recv;
383 NiceMock<MockRtpRtcpWithRembTracking> rtp_send;
nisse05843312017-04-18 23:38:35 -0700384 PacketRouter packet_router;
385
eladalon822ff2b2017-08-01 06:30:28 -0700386 packet_router.AddReceiveRtpModule(&rtp_recv, true);
387 ASSERT_TRUE(rtp_recv.REMB());
nisse05843312017-04-18 23:38:35 -0700388
389 const uint32_t bitrate_estimate = 456;
390 const std::vector<uint32_t> ssrcs = {1234};
391
nisse05843312017-04-18 23:38:35 -0700392 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
393
394 // Call OnReceiveBitrateChanged twice to get a first estimate.
395 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
396 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
397 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
398
399 // Add a send module, which should be preferred over the receive module.
eladalon822ff2b2017-08-01 06:30:28 -0700400 packet_router.AddSendRtpModule(&rtp_send, true);
401 EXPECT_FALSE(rtp_recv.REMB());
402 EXPECT_TRUE(rtp_send.REMB());
nisse05843312017-04-18 23:38:35 -0700403
404 // Lower bitrate to send another REMB packet.
405 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
406 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
407
nisse05843312017-04-18 23:38:35 -0700408 packet_router.RemoveSendRtpModule(&rtp_send);
eladalon822ff2b2017-08-01 06:30:28 -0700409 EXPECT_TRUE(rtp_recv.REMB());
410 EXPECT_FALSE(rtp_send.REMB());
411
nisse05843312017-04-18 23:38:35 -0700412 packet_router.RemoveReceiveRtpModule(&rtp_recv);
413}
414
415TEST(PacketRouterRembTest, LowerEstimateToSendRemb) {
416 rtc::ScopedFakeClock clock;
eladalon822ff2b2017-08-01 06:30:28 -0700417 NiceMock<MockRtpRtcpWithRembTracking> rtp;
nisse05843312017-04-18 23:38:35 -0700418 PacketRouter packet_router;
419
eladalon822ff2b2017-08-01 06:30:28 -0700420 packet_router.AddSendRtpModule(&rtp, true);
421 EXPECT_TRUE(rtp.REMB());
nisse05843312017-04-18 23:38:35 -0700422
423 uint32_t bitrate_estimate = 456;
424 const std::vector<uint32_t> ssrcs = {1234};
425
nisse05843312017-04-18 23:38:35 -0700426 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
427
428 // Call OnReceiveBitrateChanged twice to get a first estimate.
429 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
430 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
431 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
432
433 // Lower the estimate with more than 3% to trigger a call to SetREMBData right
434 // away.
435 bitrate_estimate = bitrate_estimate - 100;
436 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
437 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
438
nisse05843312017-04-18 23:38:35 -0700439 packet_router.RemoveSendRtpModule(&rtp);
eladalon822ff2b2017-08-01 06:30:28 -0700440 EXPECT_FALSE(rtp.REMB());
nisse05843312017-04-18 23:38:35 -0700441}
442
443TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) {
444 rtc::ScopedFakeClock clock;
eladalon6c9556e2017-07-10 03:33:00 -0700445 NiceMock<MockRtpRtcp> rtp;
nisse05843312017-04-18 23:38:35 -0700446 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700447 packet_router.AddSendRtpModule(&rtp, true);
nisse05843312017-04-18 23:38:35 -0700448
449 uint32_t bitrate_estimate[] = {456, 789};
450 std::vector<uint32_t> ssrcs = {1234, 5678};
451
452 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
453 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
454
455 // Call OnReceiveBitrateChanged twice to get a first estimate.
456 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1);
457 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
458 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
459
460 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100);
461
462 // Lower the estimate to trigger a callback.
463 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1);
464 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]);
465
466 packet_router.RemoveSendRtpModule(&rtp);
467}
468
469TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) {
470 rtc::ScopedFakeClock clock;
eladalon6c9556e2017-07-10 03:33:00 -0700471 NiceMock<MockRtpRtcp> rtp;
nisse05843312017-04-18 23:38:35 -0700472 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700473 packet_router.AddSendRtpModule(&rtp, true);
nisse05843312017-04-18 23:38:35 -0700474
475 uint32_t bitrate_estimate = 456;
476 std::vector<uint32_t> ssrcs = {1234, 5678};
477
478 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
479 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
480
481 // Call OnReceiveBitrateChanged twice to get a first estimate.
482 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
483 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
484 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
485
486 // Increased estimate shouldn't trigger a callback right away.
487 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
488 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1);
489
490 // Decreasing the estimate less than 3% shouldn't trigger a new callback.
491 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
492 int lower_estimate = bitrate_estimate * 98 / 100;
493 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate);
494
495 packet_router.RemoveSendRtpModule(&rtp);
496}
497
498TEST(PacketRouterRembTest, ChangeSendRtpModule) {
499 rtc::ScopedFakeClock clock;
eladalon6c9556e2017-07-10 03:33:00 -0700500 NiceMock<MockRtpRtcp> rtp_send;
501 NiceMock<MockRtpRtcp> rtp_recv;
nisse05843312017-04-18 23:38:35 -0700502 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700503 packet_router.AddSendRtpModule(&rtp_send, true);
504 packet_router.AddReceiveRtpModule(&rtp_recv, true);
nisse05843312017-04-18 23:38:35 -0700505
506 uint32_t bitrate_estimate = 456;
507 std::vector<uint32_t> ssrcs = {1234, 5678};
508
509 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
510 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
511
512 // Call OnReceiveBitrateChanged twice to get a first estimate.
513 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
514 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
515 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
516
517 // Decrease estimate to trigger a REMB.
518 bitrate_estimate = bitrate_estimate - 100;
519 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
520 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
521
522 // Remove the sending module -> should get remb on the second module.
523 packet_router.RemoveSendRtpModule(&rtp_send);
524
525 ON_CALL(rtp_send, REMB()).WillByDefault(Return(false));
526 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true));
527
528 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
529
530 bitrate_estimate = bitrate_estimate - 100;
531 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
532 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
533
534 packet_router.RemoveReceiveRtpModule(&rtp_recv);
535}
536
537TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) {
538 rtc::ScopedFakeClock clock;
eladalon6c9556e2017-07-10 03:33:00 -0700539 NiceMock<MockRtpRtcp> rtp;
nisse05843312017-04-18 23:38:35 -0700540 PacketRouter packet_router;
eladalon822ff2b2017-08-01 06:30:28 -0700541 packet_router.AddSendRtpModule(&rtp, true);
nisse05843312017-04-18 23:38:35 -0700542
543 uint32_t bitrate_estimate = 456;
544 const std::vector<uint32_t> ssrcs = {1234};
545
546 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
547 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
548
549 // Call OnReceiveBitrateChanged twice to get a first estimate.
550 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
551 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1);
552 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
553
554 // Lower the estimate, should trigger a call to SetREMBData right away.
555 bitrate_estimate = bitrate_estimate - 100;
556 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
557 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
558
559 // Call OnReceiveBitrateChanged again, this should not trigger a new callback.
560 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
561 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
562 packet_router.RemoveSendRtpModule(&rtp);
563}
564
565// Only register receiving modules and make sure we fallback to trigger a REMB
566// packet on this one.
567TEST(PacketRouterRembTest, NoSendingRtpModule) {
568 rtc::ScopedFakeClock clock;
eladalon6c9556e2017-07-10 03:33:00 -0700569 NiceMock<MockRtpRtcp> rtp;
nisse05843312017-04-18 23:38:35 -0700570 PacketRouter packet_router;
571
572 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
eladalon822ff2b2017-08-01 06:30:28 -0700573 packet_router.AddReceiveRtpModule(&rtp, true);
nisse05843312017-04-18 23:38:35 -0700574
575 uint32_t bitrate_estimate = 456;
576 const std::vector<uint32_t> ssrcs = {1234};
577
578 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
579 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
580
581 // Call OnReceiveBitrateChanged twice to get a first estimate.
582 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
583 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
584 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
585
586 // Lower the estimate to trigger a new packet REMB packet.
587 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
588 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
589
590 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
591 packet_router.RemoveReceiveRtpModule(&rtp);
592}
593
eladalon822ff2b2017-08-01 06:30:28 -0700594TEST(PacketRouterRembTest, NonCandidateSendRtpModuleNotUsedForRemb) {
595 rtc::ScopedFakeClock clock;
596 PacketRouter packet_router;
597 NiceMock<MockRtpRtcpWithRembTracking> module;
598
599 constexpr bool remb_candidate = false;
600
601 packet_router.AddSendRtpModule(&module, remb_candidate);
602 EXPECT_FALSE(module.REMB());
603
604 constexpr uint32_t bitrate_estimate = 456;
605 const std::vector<uint32_t> ssrcs = {1234};
606 EXPECT_CALL(module, SetREMBData(_, _)).Times(0);
607 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
608 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
609
610 // Test tear-down
611 packet_router.RemoveSendRtpModule(&module);
612}
613
614TEST(PacketRouterRembTest, CandidateSendRtpModuleUsedForRemb) {
615 rtc::ScopedFakeClock clock;
616 PacketRouter packet_router;
617 NiceMock<MockRtpRtcpWithRembTracking> module;
618
619 constexpr bool remb_candidate = true;
620
621 packet_router.AddSendRtpModule(&module, remb_candidate);
622 EXPECT_TRUE(module.REMB());
623
624 constexpr uint32_t bitrate_estimate = 456;
625 const std::vector<uint32_t> ssrcs = {1234};
626 EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
627 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
628 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
629
630 // Test tear-down
631 packet_router.RemoveSendRtpModule(&module);
632}
633
634TEST(PacketRouterRembTest, NonCandidateReceiveRtpModuleNotUsedForRemb) {
635 rtc::ScopedFakeClock clock;
636 PacketRouter packet_router;
637 NiceMock<MockRtpRtcpWithRembTracking> module;
638
639 constexpr bool remb_candidate = false;
640
641 packet_router.AddReceiveRtpModule(&module, remb_candidate);
642 ASSERT_FALSE(module.REMB());
643
644 constexpr uint32_t bitrate_estimate = 456;
645 const std::vector<uint32_t> ssrcs = {1234};
646 EXPECT_CALL(module, SetREMBData(_, _)).Times(0);
647 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
648 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
649
650 // Test tear-down
651 packet_router.RemoveReceiveRtpModule(&module);
652}
653
654TEST(PacketRouterRembTest, CandidateReceiveRtpModuleUsedForRemb) {
655 rtc::ScopedFakeClock clock;
656 PacketRouter packet_router;
657 NiceMock<MockRtpRtcpWithRembTracking> module;
658
659 constexpr bool remb_candidate = true;
660
661 packet_router.AddReceiveRtpModule(&module, remb_candidate);
662 EXPECT_TRUE(module.REMB());
663
664 constexpr uint32_t bitrate_estimate = 456;
665 const std::vector<uint32_t> ssrcs = {1234};
666 EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
667 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
668 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
669
670 // Test tear-down
671 packet_router.RemoveReceiveRtpModule(&module);
672}
673
674TEST(PacketRouterRembTest,
675 SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst) {
676 rtc::ScopedFakeClock clock;
677 PacketRouter packet_router;
678 NiceMock<MockRtpRtcpWithRembTracking> send_module;
679 NiceMock<MockRtpRtcpWithRembTracking> receive_module;
680
681 constexpr bool remb_candidate = true;
682
683 // Send module added - activated.
684 packet_router.AddSendRtpModule(&send_module, remb_candidate);
685 ASSERT_TRUE(send_module.REMB());
686
687 // Receive module added - the send module remains the active one.
688 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
689 EXPECT_TRUE(send_module.REMB());
690 EXPECT_FALSE(receive_module.REMB());
691
692 constexpr uint32_t bitrate_estimate = 456;
693 const std::vector<uint32_t> ssrcs = {1234};
694 EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
695 EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0);
696
697 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
698 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
699
700 // Test tear-down
701 packet_router.RemoveReceiveRtpModule(&receive_module);
702 packet_router.RemoveSendRtpModule(&send_module);
703}
704
705TEST(PacketRouterRembTest,
706 SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst) {
707 rtc::ScopedFakeClock clock;
708 PacketRouter packet_router;
709 NiceMock<MockRtpRtcpWithRembTracking> send_module;
710 NiceMock<MockRtpRtcpWithRembTracking> receive_module;
711
712 constexpr bool remb_candidate = true;
713
714 // Receive module added - activated.
715 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
716 ASSERT_TRUE(receive_module.REMB());
717
718 // Send module added - replaces receive module as active.
719 packet_router.AddSendRtpModule(&send_module, remb_candidate);
720 EXPECT_FALSE(receive_module.REMB());
721 EXPECT_TRUE(send_module.REMB());
722
723 constexpr uint32_t bitrate_estimate = 456;
724 const std::vector<uint32_t> ssrcs = {1234};
725 EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
726 EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0);
727
728 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
729 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
730
731 // Test tear-down
732 packet_router.RemoveReceiveRtpModule(&receive_module);
733 packet_router.RemoveSendRtpModule(&send_module);
734}
735
736TEST(PacketRouterRembTest, ReceiveModuleTakesOverWhenLastSendModuleRemoved) {
737 rtc::ScopedFakeClock clock;
738 PacketRouter packet_router;
739 NiceMock<MockRtpRtcpWithRembTracking> send_module;
740 NiceMock<MockRtpRtcpWithRembTracking> receive_module;
741
742 constexpr bool remb_candidate = true;
743
744 // Send module active, receive module inactive.
745 packet_router.AddSendRtpModule(&send_module, remb_candidate);
746 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
747 ASSERT_TRUE(send_module.REMB());
748 ASSERT_FALSE(receive_module.REMB());
749
750 // Send module removed - receive module becomes active.
751 packet_router.RemoveSendRtpModule(&send_module);
752 EXPECT_FALSE(send_module.REMB());
753 EXPECT_TRUE(receive_module.REMB());
754 constexpr uint32_t bitrate_estimate = 456;
755 const std::vector<uint32_t> ssrcs = {1234};
756 EXPECT_CALL(send_module, SetREMBData(_, _)).Times(0);
757 EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
758
759 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
760 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
761
762 // Test tear-down
763 packet_router.RemoveReceiveRtpModule(&receive_module);
764}
765
Stefan Holmere5904162015-03-26 11:11:06 +0100766} // namespace webrtc