Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(942)

Side by Side Diff: webrtc/modules/pacing/packet_router_unittest.cc

Issue 2973363002: Explicitly inform PacketRouter which RTP-RTCP modules are REMB-candidates (Closed)
Patch Set: . Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <list> 11 #include <list>
12 #include <memory> 12 #include <memory>
13 13
14 #include "webrtc/modules/pacing/packet_router.h" 14 #include "webrtc/modules/pacing/packet_router.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
16 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" 16 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
18 #include "webrtc/rtc_base/checks.h" 18 #include "webrtc/rtc_base/checks.h"
19 #include "webrtc/rtc_base/fakeclock.h" 19 #include "webrtc/rtc_base/fakeclock.h"
20 #include "webrtc/test/gmock.h" 20 #include "webrtc/test/gmock.h"
21 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
22 22
23 using ::testing::_; 23 using ::testing::_;
24 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
25 using ::testing::Field; 25 using ::testing::Field;
26 using ::testing::NiceMock; 26 using ::testing::NiceMock;
27 using ::testing::Return; 27 using ::testing::Return;
28 using ::testing::ReturnPointee;
29 using ::testing::SaveArg;
28 30
29 namespace webrtc { 31 namespace webrtc {
30 32
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
31 class PacketRouterTest : public ::testing::Test { 49 class PacketRouterTest : public ::testing::Test {
32 public: 50 public:
33 PacketRouterTest() : packet_router_(new PacketRouter()) {} 51 PacketRouterTest() : packet_router_(new PacketRouter()) {}
34 protected: 52 protected:
35 static const int kProbeMinProbes = 5; 53 static constexpr int kProbeMinProbes = 5;
36 static const int kProbeMinBytes = 1000; 54 static constexpr int kProbeMinBytes = 1000;
37 const std::unique_ptr<PacketRouter> packet_router_; 55 const std::unique_ptr<PacketRouter> packet_router_;
38 }; 56 };
39 57
40 TEST_F(PacketRouterTest, TimeToSendPacket) { 58 TEST_F(PacketRouterTest, TimeToSendPacket) {
41 NiceMock<MockRtpRtcp> rtp_1; 59 NiceMock<MockRtpRtcp> rtp_1;
42 NiceMock<MockRtpRtcp> rtp_2; 60 NiceMock<MockRtpRtcp> rtp_2;
43 packet_router_->AddSendRtpModule(&rtp_1); 61 packet_router_->AddSendRtpModule(&rtp_1, false);
44 packet_router_->AddSendRtpModule(&rtp_2); 62 packet_router_->AddSendRtpModule(&rtp_2, false);
45 63
46 const uint16_t kSsrc1 = 1234; 64 const uint16_t kSsrc1 = 1234;
47 uint16_t sequence_number = 17; 65 uint16_t sequence_number = 17;
48 uint64_t timestamp = 7890; 66 uint64_t timestamp = 7890;
49 bool retransmission = false; 67 bool retransmission = false;
50 68
51 // Send on the first module by letting rtp_1 be sending with correct ssrc. 69 // 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)); 70 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true));
53 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); 71 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1));
54 EXPECT_CALL(rtp_1, TimeToSendPacket( 72 EXPECT_CALL(rtp_1, TimeToSendPacket(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const uint16_t kSsrc1 = 1234; 136 const uint16_t kSsrc1 = 1234;
119 const uint16_t kSsrc2 = 4567; 137 const uint16_t kSsrc2 = 4567;
120 138
121 NiceMock<MockRtpRtcp> rtp_1; 139 NiceMock<MockRtpRtcp> rtp_1;
122 EXPECT_CALL(rtp_1, RtxSendStatus()).WillOnce(Return(kRtxOff)); 140 EXPECT_CALL(rtp_1, RtxSendStatus()).WillOnce(Return(kRtxOff));
123 EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); 141 EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1));
124 NiceMock<MockRtpRtcp> rtp_2; 142 NiceMock<MockRtpRtcp> rtp_2;
125 // rtp_2 will be prioritized for padding. 143 // rtp_2 will be prioritized for padding.
126 EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads)); 144 EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads));
127 EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); 145 EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2));
128 packet_router_->AddSendRtpModule(&rtp_1); 146 packet_router_->AddSendRtpModule(&rtp_1, false);
129 packet_router_->AddSendRtpModule(&rtp_2); 147 packet_router_->AddSendRtpModule(&rtp_2, false);
130 148
131 // Default configuration, sending padding on all modules sending media, 149 // Default configuration, sending padding on all modules sending media,
132 // ordered by priority (based on rtx mode). 150 // ordered by priority (based on rtx mode).
133 const size_t requested_padding_bytes = 1000; 151 const size_t requested_padding_bytes = 1000;
134 const size_t sent_padding_bytes = 890; 152 const size_t sent_padding_bytes = 890;
135 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); 153 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true));
136 EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); 154 EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true));
137 EXPECT_CALL(rtp_2, 155 EXPECT_CALL(rtp_2,
138 TimeToSendPadding(requested_padding_bytes, 156 TimeToSendPadding(requested_padding_bytes,
139 Field(&PacedPacketInfo::probe_cluster_id, 111))) 157 Field(&PacedPacketInfo::probe_cluster_id, 111)))
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 packet_router_->TimeToSendPadding( 221 packet_router_->TimeToSendPadding(
204 requested_padding_bytes, 222 requested_padding_bytes,
205 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, 223 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes,
206 kProbeMinBytes))); 224 kProbeMinBytes)));
207 225
208 packet_router_->RemoveSendRtpModule(&rtp_2); 226 packet_router_->RemoveSendRtpModule(&rtp_2);
209 } 227 }
210 228
211 TEST_F(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) { 229 TEST_F(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) {
212 NiceMock<MockRtpRtcp> rtp; 230 NiceMock<MockRtpRtcp> rtp;
213 packet_router_->AddSendRtpModule(&rtp); 231 packet_router_->AddSendRtpModule(&rtp, false);
214 static const uint16_t kSsrc = 1234; 232 static const uint16_t kSsrc = 1234;
215 EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc)); 233 EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc));
216 EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false)); 234 EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false));
217 235
218 // Verify that TimeToSendPacket does not end up in a receiver. 236 // Verify that TimeToSendPacket does not end up in a receiver.
219 EXPECT_CALL(rtp, TimeToSendPacket(_, _, _, _, _)).Times(0); 237 EXPECT_CALL(rtp, TimeToSendPacket(_, _, _, _, _)).Times(0);
220 EXPECT_TRUE(packet_router_->TimeToSendPacket( 238 EXPECT_TRUE(packet_router_->TimeToSendPacket(
221 kSsrc, 1, 1, false, PacedPacketInfo(PacedPacketInfo::kNotAProbe, 239 kSsrc, 1, 1, false, PacedPacketInfo(PacedPacketInfo::kNotAProbe,
222 kProbeMinBytes, kProbeMinBytes))); 240 kProbeMinBytes, kProbeMinBytes)));
223 // Verify that TimeToSendPadding does not end up in a receiver. 241 // Verify that TimeToSendPadding does not end up in a receiver.
(...skipping 15 matching lines...) Expand all
239 for (size_t i = 0; i < kNumPackets; ++i) { 257 for (size_t i = 0; i < kNumPackets; ++i) {
240 uint16_t seq = packet_router_->AllocateSequenceNumber(); 258 uint16_t seq = packet_router_->AllocateSequenceNumber();
241 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; 259 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i;
242 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); 260 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq);
243 } 261 }
244 } 262 }
245 263
246 TEST_F(PacketRouterTest, SendTransportFeedback) { 264 TEST_F(PacketRouterTest, SendTransportFeedback) {
247 NiceMock<MockRtpRtcp> rtp_1; 265 NiceMock<MockRtpRtcp> rtp_1;
248 NiceMock<MockRtpRtcp> rtp_2; 266 NiceMock<MockRtpRtcp> rtp_2;
249 packet_router_->AddSendRtpModule(&rtp_1); 267 packet_router_->AddSendRtpModule(&rtp_1, false);
250 packet_router_->AddReceiveRtpModule(&rtp_2); 268 packet_router_->AddReceiveRtpModule(&rtp_2, false);
251 269
252 rtcp::TransportFeedback feedback; 270 rtcp::TransportFeedback feedback;
253 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); 271 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true));
254 packet_router_->SendTransportFeedback(&feedback); 272 packet_router_->SendTransportFeedback(&feedback);
255 packet_router_->RemoveSendRtpModule(&rtp_1); 273 packet_router_->RemoveSendRtpModule(&rtp_1);
256 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); 274 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true));
257 packet_router_->SendTransportFeedback(&feedback); 275 packet_router_->SendTransportFeedback(&feedback);
258 packet_router_->RemoveReceiveRtpModule(&rtp_2); 276 packet_router_->RemoveReceiveRtpModule(&rtp_2);
259 } 277 }
260 278
279 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
280 TEST_F(PacketRouterTest, DoubleRegistrationOfSendModuleDisallowed) {
281 PacketRouter packet_router;
282
283 NiceMock<MockRtpRtcp> module;
284
285 constexpr bool remb_candidate = false; // Value irrelevant.
286 packet_router.AddSendRtpModule(&module, remb_candidate);
287 EXPECT_DEATH(packet_router.AddSendRtpModule(&module, remb_candidate), "");
288
289 // Test tear-down
290 packet_router.RemoveSendRtpModule(&module);
danilchap 2017/07/31 13:18:04 may be use packet_router_ or do not use fixture, e
eladalon 2017/07/31 14:08:26 Let's land as-is, and I'll push a CL on top of thi
eladalon 2017/07/31 14:10:21 (I've changed in some places, but I didn't think i
291 }
292
293 TEST_F(PacketRouterTest, DoubleRegistrationOfReceiveModuleDisallowed) {
294 PacketRouter packet_router;
295
296 NiceMock<MockRtpRtcp> module;
297
298 constexpr bool remb_candidate = false; // Value irrelevant.
299 packet_router.AddReceiveRtpModule(&module, remb_candidate);
300 EXPECT_DEATH(packet_router.AddReceiveRtpModule(&module, remb_candidate), "");
301
302 // Test tear-down
303 packet_router.RemoveReceiveRtpModule(&module);
304 }
305
306 TEST_F(PacketRouterTest, RemovalOfNeverAddedSendModuleDisallowed) {
307 PacketRouter packet_router;
308
309 NiceMock<MockRtpRtcp> module;
310
311 EXPECT_DEATH(packet_router.RemoveSendRtpModule(&module), "");
312 }
313
314 TEST_F(PacketRouterTest, RemovalOfNeverAddedReceiveModuleDisallowed) {
315 PacketRouter packet_router;
316
317 NiceMock<MockRtpRtcp> module;
318
319 EXPECT_DEATH(packet_router.RemoveReceiveRtpModule(&module), "");
320 }
321 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
322
323 // TODO(eladalon): Remove this test; it should be covered by:
324 // 1. SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst
325 // 2. SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst
326 // 3. LowerEstimateToSendRemb
327 // (Not removing in this CL to prove it doesn't break this test.)
261 TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) { 328 TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) {
262 rtc::ScopedFakeClock clock; 329 rtc::ScopedFakeClock clock;
263 NiceMock<MockRtpRtcp> rtp_recv; 330 NiceMock<MockRtpRtcpWithRembTracking> rtp_recv;
264 NiceMock<MockRtpRtcp> rtp_send; 331 NiceMock<MockRtpRtcpWithRembTracking> rtp_send;
265 PacketRouter packet_router; 332 PacketRouter packet_router;
266 333
267 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1); 334 packet_router.AddReceiveRtpModule(&rtp_recv, true);
268 packet_router.AddReceiveRtpModule(&rtp_recv); 335 ASSERT_TRUE(rtp_recv.REMB());
269 336
270 const uint32_t bitrate_estimate = 456; 337 const uint32_t bitrate_estimate = 456;
271 const std::vector<uint32_t> ssrcs = {1234}; 338 const std::vector<uint32_t> ssrcs = {1234};
272 339
273 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true));
274 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 340 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
275 341
276 // Call OnReceiveBitrateChanged twice to get a first estimate. 342 // Call OnReceiveBitrateChanged twice to get a first estimate.
277 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 343 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
278 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 344 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
279 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 345 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
280 346
281 // Add a send module, which should be preferred over the receive module. 347 // Add a send module, which should be preferred over the receive module.
282 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); 348 packet_router.AddSendRtpModule(&rtp_send, true);
283 EXPECT_CALL(rtp_send, SetREMBStatus(true)).Times(1); 349 EXPECT_FALSE(rtp_recv.REMB());
284 packet_router.AddSendRtpModule(&rtp_send); 350 EXPECT_TRUE(rtp_send.REMB());
285 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(false));
286 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
287 351
288 // Lower bitrate to send another REMB packet. 352 // Lower bitrate to send another REMB packet.
289 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); 353 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
290 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); 354 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
291 355
292 EXPECT_CALL(rtp_send, SetREMBStatus(false)).Times(1);
293 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1);
294 packet_router.RemoveSendRtpModule(&rtp_send); 356 packet_router.RemoveSendRtpModule(&rtp_send);
295 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); 357 EXPECT_TRUE(rtp_recv.REMB());
358 EXPECT_FALSE(rtp_send.REMB());
359
296 packet_router.RemoveReceiveRtpModule(&rtp_recv); 360 packet_router.RemoveReceiveRtpModule(&rtp_recv);
297 } 361 }
298 362
299 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) { 363 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) {
300 rtc::ScopedFakeClock clock; 364 rtc::ScopedFakeClock clock;
301 NiceMock<MockRtpRtcp> rtp; 365 NiceMock<MockRtpRtcpWithRembTracking> rtp;
302 PacketRouter packet_router; 366 PacketRouter packet_router;
303 367
304 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); 368 packet_router.AddSendRtpModule(&rtp, true);
305 packet_router.AddSendRtpModule(&rtp); 369 EXPECT_TRUE(rtp.REMB());
306 370
307 uint32_t bitrate_estimate = 456; 371 uint32_t bitrate_estimate = 456;
308 const std::vector<uint32_t> ssrcs = {1234}; 372 const std::vector<uint32_t> ssrcs = {1234};
309 373
310 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
311 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 374 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
312 375
313 // Call OnReceiveBitrateChanged twice to get a first estimate. 376 // Call OnReceiveBitrateChanged twice to get a first estimate.
314 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 377 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
315 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 378 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
316 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 379 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
317 380
318 // Lower the estimate with more than 3% to trigger a call to SetREMBData right 381 // Lower the estimate with more than 3% to trigger a call to SetREMBData right
319 // away. 382 // away.
320 bitrate_estimate = bitrate_estimate - 100; 383 bitrate_estimate = bitrate_estimate - 100;
321 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 384 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
322 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 385 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
323 386
324 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
325 packet_router.RemoveSendRtpModule(&rtp); 387 packet_router.RemoveSendRtpModule(&rtp);
388 EXPECT_FALSE(rtp.REMB());
326 } 389 }
327 390
328 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) { 391 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) {
329 rtc::ScopedFakeClock clock; 392 rtc::ScopedFakeClock clock;
330 NiceMock<MockRtpRtcp> rtp; 393 NiceMock<MockRtpRtcp> rtp;
331 PacketRouter packet_router; 394 PacketRouter packet_router;
332 packet_router.AddSendRtpModule(&rtp); 395 packet_router.AddSendRtpModule(&rtp, true);
333 396
334 uint32_t bitrate_estimate[] = {456, 789}; 397 uint32_t bitrate_estimate[] = {456, 789};
335 std::vector<uint32_t> ssrcs = {1234, 5678}; 398 std::vector<uint32_t> ssrcs = {1234, 5678};
336 399
337 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 400 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
338 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); 401 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
339 402
340 // Call OnReceiveBitrateChanged twice to get a first estimate. 403 // Call OnReceiveBitrateChanged twice to get a first estimate.
341 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1); 404 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1);
342 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 405 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
343 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); 406 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
344 407
345 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100); 408 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100);
346 409
347 // Lower the estimate to trigger a callback. 410 // Lower the estimate to trigger a callback.
348 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1); 411 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1);
349 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]); 412 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]);
350 413
351 packet_router.RemoveSendRtpModule(&rtp); 414 packet_router.RemoveSendRtpModule(&rtp);
352 } 415 }
353 416
354 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) { 417 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) {
355 rtc::ScopedFakeClock clock; 418 rtc::ScopedFakeClock clock;
356 NiceMock<MockRtpRtcp> rtp; 419 NiceMock<MockRtpRtcp> rtp;
357 PacketRouter packet_router; 420 PacketRouter packet_router;
358 packet_router.AddSendRtpModule(&rtp); 421 packet_router.AddSendRtpModule(&rtp, true);
359 422
360 uint32_t bitrate_estimate = 456; 423 uint32_t bitrate_estimate = 456;
361 std::vector<uint32_t> ssrcs = {1234, 5678}; 424 std::vector<uint32_t> ssrcs = {1234, 5678};
362 425
363 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 426 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
364 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 427 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
365 428
366 // Call OnReceiveBitrateChanged twice to get a first estimate. 429 // Call OnReceiveBitrateChanged twice to get a first estimate.
367 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 430 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
368 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 431 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
369 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 432 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
370 433
371 // Increased estimate shouldn't trigger a callback right away. 434 // Increased estimate shouldn't trigger a callback right away.
372 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); 435 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
373 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1); 436 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1);
374 437
375 // Decreasing the estimate less than 3% shouldn't trigger a new callback. 438 // Decreasing the estimate less than 3% shouldn't trigger a new callback.
376 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); 439 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
377 int lower_estimate = bitrate_estimate * 98 / 100; 440 int lower_estimate = bitrate_estimate * 98 / 100;
378 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate); 441 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate);
379 442
380 packet_router.RemoveSendRtpModule(&rtp); 443 packet_router.RemoveSendRtpModule(&rtp);
381 } 444 }
382 445
383 TEST(PacketRouterRembTest, ChangeSendRtpModule) { 446 TEST(PacketRouterRembTest, ChangeSendRtpModule) {
384 rtc::ScopedFakeClock clock; 447 rtc::ScopedFakeClock clock;
385 NiceMock<MockRtpRtcp> rtp_send; 448 NiceMock<MockRtpRtcp> rtp_send;
386 NiceMock<MockRtpRtcp> rtp_recv; 449 NiceMock<MockRtpRtcp> rtp_recv;
387 PacketRouter packet_router; 450 PacketRouter packet_router;
388 packet_router.AddSendRtpModule(&rtp_send); 451 packet_router.AddSendRtpModule(&rtp_send, true);
389 packet_router.AddReceiveRtpModule(&rtp_recv); 452 packet_router.AddReceiveRtpModule(&rtp_recv, true);
390 453
391 uint32_t bitrate_estimate = 456; 454 uint32_t bitrate_estimate = 456;
392 std::vector<uint32_t> ssrcs = {1234, 5678}; 455 std::vector<uint32_t> ssrcs = {1234, 5678};
393 456
394 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); 457 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
395 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 458 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
396 459
397 // Call OnReceiveBitrateChanged twice to get a first estimate. 460 // Call OnReceiveBitrateChanged twice to get a first estimate.
398 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 461 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
399 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 462 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
(...skipping 16 matching lines...) Expand all
416 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 479 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
417 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 480 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
418 481
419 packet_router.RemoveReceiveRtpModule(&rtp_recv); 482 packet_router.RemoveReceiveRtpModule(&rtp_recv);
420 } 483 }
421 484
422 TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) { 485 TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) {
423 rtc::ScopedFakeClock clock; 486 rtc::ScopedFakeClock clock;
424 NiceMock<MockRtpRtcp> rtp; 487 NiceMock<MockRtpRtcp> rtp;
425 PacketRouter packet_router; 488 PacketRouter packet_router;
426 packet_router.AddSendRtpModule(&rtp); 489 packet_router.AddSendRtpModule(&rtp, true);
427 490
428 uint32_t bitrate_estimate = 456; 491 uint32_t bitrate_estimate = 456;
429 const std::vector<uint32_t> ssrcs = {1234}; 492 const std::vector<uint32_t> ssrcs = {1234};
430 493
431 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 494 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
432 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 495 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
433 496
434 // Call OnReceiveBitrateChanged twice to get a first estimate. 497 // Call OnReceiveBitrateChanged twice to get a first estimate.
435 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 498 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
436 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1); 499 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1);
(...skipping 11 matching lines...) Expand all
448 } 511 }
449 512
450 // Only register receiving modules and make sure we fallback to trigger a REMB 513 // Only register receiving modules and make sure we fallback to trigger a REMB
451 // packet on this one. 514 // packet on this one.
452 TEST(PacketRouterRembTest, NoSendingRtpModule) { 515 TEST(PacketRouterRembTest, NoSendingRtpModule) {
453 rtc::ScopedFakeClock clock; 516 rtc::ScopedFakeClock clock;
454 NiceMock<MockRtpRtcp> rtp; 517 NiceMock<MockRtpRtcp> rtp;
455 PacketRouter packet_router; 518 PacketRouter packet_router;
456 519
457 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); 520 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
458 packet_router.AddReceiveRtpModule(&rtp); 521 packet_router.AddReceiveRtpModule(&rtp, true);
459 522
460 uint32_t bitrate_estimate = 456; 523 uint32_t bitrate_estimate = 456;
461 const std::vector<uint32_t> ssrcs = {1234}; 524 const std::vector<uint32_t> ssrcs = {1234};
462 525
463 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 526 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
464 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 527 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
465 528
466 // Call OnReceiveBitrateChanged twice to get a first estimate. 529 // Call OnReceiveBitrateChanged twice to get a first estimate.
467 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 530 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
468 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 531 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
469 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 532 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
470 533
471 // Lower the estimate to trigger a new packet REMB packet. 534 // Lower the estimate to trigger a new packet REMB packet.
472 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); 535 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
473 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); 536 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
474 537
475 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); 538 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
476 packet_router.RemoveReceiveRtpModule(&rtp); 539 packet_router.RemoveReceiveRtpModule(&rtp);
477 } 540 }
478 541
542 TEST(PacketRouterRembTest, NonCandidateSendRtpModuleNotUsedForRemb) {
543 rtc::ScopedFakeClock clock;
544 PacketRouter packet_router;
545 NiceMock<MockRtpRtcpWithRembTracking> module;
546
547 constexpr bool remb_candidate = false;
548
549 packet_router.AddSendRtpModule(&module, remb_candidate);
550 EXPECT_FALSE(module.REMB());
551
552 constexpr uint32_t bitrate_estimate = 456;
553 const std::vector<uint32_t> ssrcs = {1234};
554 EXPECT_CALL(module, SetREMBData(_, _)).Times(0);
555 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
556 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
557
558 // Test tear-down
559 packet_router.RemoveSendRtpModule(&module);
560 }
561
562 TEST(PacketRouterRembTest, CandidateSendRtpModuleUsedForRemb) {
563 rtc::ScopedFakeClock clock;
564 PacketRouter packet_router;
565 NiceMock<MockRtpRtcpWithRembTracking> module;
566
567 constexpr bool remb_candidate = true;
568
569 packet_router.AddSendRtpModule(&module, remb_candidate);
570 EXPECT_TRUE(module.REMB());
571
572 constexpr uint32_t bitrate_estimate = 456;
573 const std::vector<uint32_t> ssrcs = {1234};
574 EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
575 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
576 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
577
578 // Test tear-down
579 packet_router.RemoveSendRtpModule(&module);
580 }
581
582 TEST(PacketRouterRembTest, NonCandidateReceiveRtpModuleNotUsedForRemb) {
583 rtc::ScopedFakeClock clock;
584 PacketRouter packet_router;
585 NiceMock<MockRtpRtcpWithRembTracking> module;
586
587 constexpr bool remb_candidate = false;
588
589 packet_router.AddReceiveRtpModule(&module, remb_candidate);
590 ASSERT_FALSE(module.REMB());
591
592 constexpr uint32_t bitrate_estimate = 456;
593 const std::vector<uint32_t> ssrcs = {1234};
594 EXPECT_CALL(module, SetREMBData(_, _)).Times(0);
595 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
596 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
597
598 // Test tear-down
599 packet_router.RemoveReceiveRtpModule(&module);
600 }
601
602 TEST(PacketRouterRembTest, CandidateReceiveRtpModuleUsedForRemb) {
603 rtc::ScopedFakeClock clock;
604 PacketRouter packet_router;
605 NiceMock<MockRtpRtcpWithRembTracking> module;
606
607 constexpr bool remb_candidate = true;
608
609 packet_router.AddReceiveRtpModule(&module, remb_candidate);
610 EXPECT_TRUE(module.REMB());
611
612 constexpr uint32_t bitrate_estimate = 456;
613 const std::vector<uint32_t> ssrcs = {1234};
614 EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
615 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
616 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
617
618 // Test tear-down
619 packet_router.RemoveReceiveRtpModule(&module);
620 }
621
622 TEST(PacketRouterRembTest,
623 SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst) {
624 rtc::ScopedFakeClock clock;
625 PacketRouter packet_router;
626 NiceMock<MockRtpRtcpWithRembTracking> send_module;
627 NiceMock<MockRtpRtcpWithRembTracking> receive_module;
628
629 constexpr bool remb_candidate = true;
630
631 // Send module added - activated.
632 packet_router.AddSendRtpModule(&send_module, remb_candidate);
633 ASSERT_TRUE(send_module.REMB());
634
635 // Receive module added - the send module remains the active one.
636 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
637 EXPECT_TRUE(send_module.REMB());
638 EXPECT_FALSE(receive_module.REMB());
639
640 constexpr uint32_t bitrate_estimate = 456;
641 const std::vector<uint32_t> ssrcs = {1234};
642 EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
643 EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0);
644
645 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
646 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
647
648 // Test tear-down
649 packet_router.RemoveReceiveRtpModule(&receive_module);
650 packet_router.RemoveSendRtpModule(&send_module);
651 }
652
653 TEST(PacketRouterRembTest,
654 SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst) {
655 rtc::ScopedFakeClock clock;
656 PacketRouter packet_router;
657 NiceMock<MockRtpRtcpWithRembTracking> send_module;
658 NiceMock<MockRtpRtcpWithRembTracking> receive_module;
659
660 constexpr bool remb_candidate = true;
661
662 // Receive module added - activated.
663 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
664 ASSERT_TRUE(receive_module.REMB());
665
666 // Send module added - replaces receive module as active.
667 packet_router.AddSendRtpModule(&send_module, remb_candidate);
668 EXPECT_FALSE(receive_module.REMB());
669 EXPECT_TRUE(send_module.REMB());
670
671 constexpr uint32_t bitrate_estimate = 456;
672 const std::vector<uint32_t> ssrcs = {1234};
673 EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
674 EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0);
675
676 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
677 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
678
679 // Test tear-down
680 packet_router.RemoveReceiveRtpModule(&receive_module);
681 packet_router.RemoveSendRtpModule(&send_module);
682 }
683
684 TEST(PacketRouterRembTest, ReceiveModuleTakesOverWhenLastSendModuleRemoved) {
685 rtc::ScopedFakeClock clock;
686 PacketRouter packet_router;
687 NiceMock<MockRtpRtcpWithRembTracking> send_module;
688 NiceMock<MockRtpRtcpWithRembTracking> receive_module;
689
690 constexpr bool remb_candidate = true;
691
692 // Send module active, receive module inactive.
693 packet_router.AddSendRtpModule(&send_module, remb_candidate);
694 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate);
695 ASSERT_TRUE(send_module.REMB());
696 ASSERT_FALSE(receive_module.REMB());
697
698 // Send module removed - receive module becomes active.
699 packet_router.RemoveSendRtpModule(&send_module);
700 EXPECT_FALSE(send_module.REMB());
701 EXPECT_TRUE(receive_module.REMB());
702 constexpr uint32_t bitrate_estimate = 456;
703 const std::vector<uint32_t> ssrcs = {1234};
704 EXPECT_CALL(send_module, SetREMBData(_, _)).Times(0);
705 EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
706
707 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
708 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
709
710 // Test tear-down
711 packet_router.RemoveReceiveRtpModule(&receive_module);
712 }
713
479 } // namespace webrtc 714 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698