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

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
« no previous file with comments | « webrtc/modules/pacing/packet_router.cc ('k') | webrtc/video/rtp_video_stream_receiver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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.)
261 TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) { 321 TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) {
262 rtc::ScopedFakeClock clock; 322 rtc::ScopedFakeClock clock;
263 NiceMock<MockRtpRtcp> rtp_recv; 323 NiceMock<MockRtpRtcpWithRembTracking> rtp_recv;
264 NiceMock<MockRtpRtcp> rtp_send; 324 NiceMock<MockRtpRtcpWithRembTracking> rtp_send;
265 PacketRouter packet_router; 325 PacketRouter packet_router;
266 326
267 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1); 327 packet_router.AddReceiveRtpModule(&rtp_recv, true);
268 packet_router.AddReceiveRtpModule(&rtp_recv); 328 ASSERT_TRUE(rtp_recv.REMB());
269 329
270 const uint32_t bitrate_estimate = 456; 330 const uint32_t bitrate_estimate = 456;
271 const std::vector<uint32_t> ssrcs = {1234}; 331 const std::vector<uint32_t> ssrcs = {1234};
272 332
273 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true));
274 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 333 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
275 334
276 // Call OnReceiveBitrateChanged twice to get a first estimate. 335 // Call OnReceiveBitrateChanged twice to get a first estimate.
277 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 336 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
278 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 337 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
279 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 338 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
280 339
281 // Add a send module, which should be preferred over the receive module. 340 // Add a send module, which should be preferred over the receive module.
282 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); 341 packet_router.AddSendRtpModule(&rtp_send, true);
283 EXPECT_CALL(rtp_send, SetREMBStatus(true)).Times(1); 342 EXPECT_FALSE(rtp_recv.REMB());
284 packet_router.AddSendRtpModule(&rtp_send); 343 EXPECT_TRUE(rtp_send.REMB());
285 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(false));
286 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
287 344
288 // Lower bitrate to send another REMB packet. 345 // Lower bitrate to send another REMB packet.
289 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); 346 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
290 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); 347 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
291 348
292 EXPECT_CALL(rtp_send, SetREMBStatus(false)).Times(1);
293 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1);
294 packet_router.RemoveSendRtpModule(&rtp_send); 349 packet_router.RemoveSendRtpModule(&rtp_send);
295 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); 350 EXPECT_TRUE(rtp_recv.REMB());
351 EXPECT_FALSE(rtp_send.REMB());
352
296 packet_router.RemoveReceiveRtpModule(&rtp_recv); 353 packet_router.RemoveReceiveRtpModule(&rtp_recv);
297 } 354 }
298 355
299 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) { 356 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) {
300 rtc::ScopedFakeClock clock; 357 rtc::ScopedFakeClock clock;
301 NiceMock<MockRtpRtcp> rtp; 358 NiceMock<MockRtpRtcpWithRembTracking> rtp;
302 PacketRouter packet_router; 359 PacketRouter packet_router;
303 360
304 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); 361 packet_router.AddSendRtpModule(&rtp, true);
305 packet_router.AddSendRtpModule(&rtp); 362 EXPECT_TRUE(rtp.REMB());
306 363
307 uint32_t bitrate_estimate = 456; 364 uint32_t bitrate_estimate = 456;
308 const std::vector<uint32_t> ssrcs = {1234}; 365 const std::vector<uint32_t> ssrcs = {1234};
309 366
310 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
311 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 367 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
312 368
313 // Call OnReceiveBitrateChanged twice to get a first estimate. 369 // Call OnReceiveBitrateChanged twice to get a first estimate.
314 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 370 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
315 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 371 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
316 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 372 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
317 373
318 // Lower the estimate with more than 3% to trigger a call to SetREMBData right 374 // Lower the estimate with more than 3% to trigger a call to SetREMBData right
319 // away. 375 // away.
320 bitrate_estimate = bitrate_estimate - 100; 376 bitrate_estimate = bitrate_estimate - 100;
321 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 377 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
322 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 378 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
323 379
324 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
325 packet_router.RemoveSendRtpModule(&rtp); 380 packet_router.RemoveSendRtpModule(&rtp);
381 EXPECT_FALSE(rtp.REMB());
326 } 382 }
327 383
328 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) { 384 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) {
329 rtc::ScopedFakeClock clock; 385 rtc::ScopedFakeClock clock;
330 NiceMock<MockRtpRtcp> rtp; 386 NiceMock<MockRtpRtcp> rtp;
331 PacketRouter packet_router; 387 PacketRouter packet_router;
332 packet_router.AddSendRtpModule(&rtp); 388 packet_router.AddSendRtpModule(&rtp, true);
333 389
334 uint32_t bitrate_estimate[] = {456, 789}; 390 uint32_t bitrate_estimate[] = {456, 789};
335 std::vector<uint32_t> ssrcs = {1234, 5678}; 391 std::vector<uint32_t> ssrcs = {1234, 5678};
336 392
337 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 393 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
338 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); 394 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
339 395
340 // Call OnReceiveBitrateChanged twice to get a first estimate. 396 // Call OnReceiveBitrateChanged twice to get a first estimate.
341 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1); 397 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1);
342 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 398 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
343 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); 399 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
344 400
345 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100); 401 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100);
346 402
347 // Lower the estimate to trigger a callback. 403 // Lower the estimate to trigger a callback.
348 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1); 404 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1);
349 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]); 405 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]);
350 406
351 packet_router.RemoveSendRtpModule(&rtp); 407 packet_router.RemoveSendRtpModule(&rtp);
352 } 408 }
353 409
354 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) { 410 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) {
355 rtc::ScopedFakeClock clock; 411 rtc::ScopedFakeClock clock;
356 NiceMock<MockRtpRtcp> rtp; 412 NiceMock<MockRtpRtcp> rtp;
357 PacketRouter packet_router; 413 PacketRouter packet_router;
358 packet_router.AddSendRtpModule(&rtp); 414 packet_router.AddSendRtpModule(&rtp, true);
359 415
360 uint32_t bitrate_estimate = 456; 416 uint32_t bitrate_estimate = 456;
361 std::vector<uint32_t> ssrcs = {1234, 5678}; 417 std::vector<uint32_t> ssrcs = {1234, 5678};
362 418
363 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 419 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
364 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 420 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
365 421
366 // Call OnReceiveBitrateChanged twice to get a first estimate. 422 // Call OnReceiveBitrateChanged twice to get a first estimate.
367 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 423 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
368 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 424 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
369 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 425 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
370 426
371 // Increased estimate shouldn't trigger a callback right away. 427 // Increased estimate shouldn't trigger a callback right away.
372 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); 428 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
373 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1); 429 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1);
374 430
375 // Decreasing the estimate less than 3% shouldn't trigger a new callback. 431 // Decreasing the estimate less than 3% shouldn't trigger a new callback.
376 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); 432 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
377 int lower_estimate = bitrate_estimate * 98 / 100; 433 int lower_estimate = bitrate_estimate * 98 / 100;
378 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate); 434 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate);
379 435
380 packet_router.RemoveSendRtpModule(&rtp); 436 packet_router.RemoveSendRtpModule(&rtp);
381 } 437 }
382 438
383 TEST(PacketRouterRembTest, ChangeSendRtpModule) { 439 TEST(PacketRouterRembTest, ChangeSendRtpModule) {
384 rtc::ScopedFakeClock clock; 440 rtc::ScopedFakeClock clock;
385 NiceMock<MockRtpRtcp> rtp_send; 441 NiceMock<MockRtpRtcp> rtp_send;
386 NiceMock<MockRtpRtcp> rtp_recv; 442 NiceMock<MockRtpRtcp> rtp_recv;
387 PacketRouter packet_router; 443 PacketRouter packet_router;
388 packet_router.AddSendRtpModule(&rtp_send); 444 packet_router.AddSendRtpModule(&rtp_send, true);
389 packet_router.AddReceiveRtpModule(&rtp_recv); 445 packet_router.AddReceiveRtpModule(&rtp_recv, true);
390 446
391 uint32_t bitrate_estimate = 456; 447 uint32_t bitrate_estimate = 456;
392 std::vector<uint32_t> ssrcs = {1234, 5678}; 448 std::vector<uint32_t> ssrcs = {1234, 5678};
393 449
394 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); 450 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
395 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 451 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
396 452
397 // Call OnReceiveBitrateChanged twice to get a first estimate. 453 // Call OnReceiveBitrateChanged twice to get a first estimate.
398 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 454 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
399 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 455 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); 472 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
417 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 473 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
418 474
419 packet_router.RemoveReceiveRtpModule(&rtp_recv); 475 packet_router.RemoveReceiveRtpModule(&rtp_recv);
420 } 476 }
421 477
422 TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) { 478 TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) {
423 rtc::ScopedFakeClock clock; 479 rtc::ScopedFakeClock clock;
424 NiceMock<MockRtpRtcp> rtp; 480 NiceMock<MockRtpRtcp> rtp;
425 PacketRouter packet_router; 481 PacketRouter packet_router;
426 packet_router.AddSendRtpModule(&rtp); 482 packet_router.AddSendRtpModule(&rtp, true);
427 483
428 uint32_t bitrate_estimate = 456; 484 uint32_t bitrate_estimate = 456;
429 const std::vector<uint32_t> ssrcs = {1234}; 485 const std::vector<uint32_t> ssrcs = {1234};
430 486
431 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 487 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
432 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 488 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
433 489
434 // Call OnReceiveBitrateChanged twice to get a first estimate. 490 // Call OnReceiveBitrateChanged twice to get a first estimate.
435 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 491 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
436 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1); 492 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1);
(...skipping 11 matching lines...) Expand all
448 } 504 }
449 505
450 // Only register receiving modules and make sure we fallback to trigger a REMB 506 // Only register receiving modules and make sure we fallback to trigger a REMB
451 // packet on this one. 507 // packet on this one.
452 TEST(PacketRouterRembTest, NoSendingRtpModule) { 508 TEST(PacketRouterRembTest, NoSendingRtpModule) {
453 rtc::ScopedFakeClock clock; 509 rtc::ScopedFakeClock clock;
454 NiceMock<MockRtpRtcp> rtp; 510 NiceMock<MockRtpRtcp> rtp;
455 PacketRouter packet_router; 511 PacketRouter packet_router;
456 512
457 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); 513 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
458 packet_router.AddReceiveRtpModule(&rtp); 514 packet_router.AddReceiveRtpModule(&rtp, true);
459 515
460 uint32_t bitrate_estimate = 456; 516 uint32_t bitrate_estimate = 456;
461 const std::vector<uint32_t> ssrcs = {1234}; 517 const std::vector<uint32_t> ssrcs = {1234};
462 518
463 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); 519 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
464 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 520 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
465 521
466 // Call OnReceiveBitrateChanged twice to get a first estimate. 522 // Call OnReceiveBitrateChanged twice to get a first estimate.
467 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); 523 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
468 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); 524 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
469 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); 525 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
470 526
471 // Lower the estimate to trigger a new packet REMB packet. 527 // Lower the estimate to trigger a new packet REMB packet.
472 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); 528 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
473 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); 529 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
474 530
475 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); 531 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
476 packet_router.RemoveReceiveRtpModule(&rtp); 532 packet_router.RemoveReceiveRtpModule(&rtp);
477 } 533 }
478 534
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
479 } // namespace webrtc 707 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/packet_router.cc ('k') | webrtc/video/rtp_video_stream_receiver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698