 Chromium Code Reviews
 Chromium Code Reviews Issue 2973363002:
  Explicitly inform PacketRouter which RTP-RTCP modules are REMB-candidates  (Closed)
    
  
    Issue 2973363002:
  Explicitly inform PacketRouter which RTP-RTCP modules are REMB-candidates  (Closed) 
  | OLD | NEW | 
|---|---|
| 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::Invoke; | |
| 26 using ::testing::NiceMock; | 27 using ::testing::NiceMock; | 
| 27 using ::testing::Return; | 28 using ::testing::Return; | 
| 28 | 29 | 
| 29 namespace webrtc { | 30 namespace webrtc { | 
| 30 | 31 | 
| 32 // TODO(eladalon): Restructure and/or replace the existing monolithic tests | |
| 33 // (only some of the test are monolithic) according to the new | |
| 34 // guidelines - small tests for one thing at a time. | |
| 35 // (I'm not removing any tests during CL, so as to demonstrate no regressions.) | |
| 36 | |
| 37 void ExpectSetREMBStatusAndSetRembAccordingly(MockRtpRtcp* mock_rtp_rtcp, | |
| 38 bool remb_state) { | |
| 39 EXPECT_CALL(*mock_rtp_rtcp, SetREMBStatus(remb_state)) | |
| 
danilchap
2017/07/28 11:35:04
EXPECT_CALL in helper complicates reading error me
 
eladalon
2017/07/28 15:47:11
Removed in favor of MockRtpRtcpRemb (under a diffe
 | |
| 40 .Times(1) | |
| 41 .WillOnce(Invoke([mock_rtp_rtcp](bool state) { | |
| 42 ON_CALL(*mock_rtp_rtcp, REMB()).WillByDefault(Return(state)); | |
| 43 })); | |
| 44 } | |
| 45 | |
| 46 // Same as the Expect* version, but without the expectation. Note that this | |
| 47 // does not mix well with Expect*. | |
| 48 void OnSetREMBStatusAndSetRembAccordingly(MockRtpRtcp* mock_rtp_rtcp) { | |
| 
danilchap
2017/07/28 11:35:04
probably cleaner to use different Mock instead of
 
eladalon
2017/07/28 15:47:11
MockRtpRtcpRemb - Good suggestions, I'll use that.
 | |
| 49 ON_CALL(*mock_rtp_rtcp, SetREMBStatus(_)) | |
| 50 .WillByDefault(Invoke([mock_rtp_rtcp](bool state) { | |
| 51 ON_CALL(*mock_rtp_rtcp, REMB()).WillByDefault(Return(state)); | |
| 52 })); | |
| 53 } | |
| 54 | |
| 31 class PacketRouterTest : public ::testing::Test { | 55 class PacketRouterTest : public ::testing::Test { | 
| 32 public: | 56 public: | 
| 33 PacketRouterTest() : packet_router_(new PacketRouter()) {} | 57 PacketRouterTest() : packet_router_(new PacketRouter()) {} | 
| 34 protected: | 58 protected: | 
| 35 static const int kProbeMinProbes = 5; | 59 static constexpr int kProbeMinProbes = 5; | 
| 36 static const int kProbeMinBytes = 1000; | 60 static constexpr int kProbeMinBytes = 1000; | 
| 37 const std::unique_ptr<PacketRouter> packet_router_; | 61 const std::unique_ptr<PacketRouter> packet_router_; | 
| 38 }; | 62 }; | 
| 39 | 63 | 
| 64 TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_TimeToSendPacket) { | |
| 
danilchap
2017/07/28 11:35:04
this questionable sanity checks looks unlrelated t
 
eladalon
2017/07/28 15:47:11
I'll move to its own CL (https://codereview.webrtc
 | |
| 65 PacketRouter packet_router; | |
| 66 | |
| 67 constexpr uint16_t ssrc = 1234; | |
| 68 constexpr uint16_t sequence_number = 17; | |
| 69 constexpr uint64_t timestamp = 7890; | |
| 70 constexpr bool retransmission = false; | |
| 71 const PacedPacketInfo paced_info(1, kProbeMinProbes, kProbeMinBytes); | |
| 72 | |
| 73 // TODO(eladalon): !!! Discuss with reviewers - it's interesting that this | |
| 74 // returns true even when no modules are found that match the SSRC. | |
| 
danilchap
2017/07/27 20:00:20
probably it mean that module for the packet was ju
 
eladalon
2017/07/27 21:30:53
PacedSender::SendPacket uses that, so even if we e
 | |
| 75 EXPECT_TRUE(packet_router.TimeToSendPacket(ssrc, sequence_number, timestamp, | |
| 76 retransmission, paced_info)); | |
| 77 } | |
| 78 | |
| 79 TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_TimeToSendPadding) { | |
| 80 PacketRouter packet_router; | |
| 81 | |
| 82 constexpr size_t bytes = 300; | |
| 83 const PacedPacketInfo paced_info(1, kProbeMinProbes, kProbeMinBytes); | |
| 84 | |
| 85 EXPECT_EQ(packet_router.TimeToSendPadding(bytes, paced_info), 0u); | |
| 86 } | |
| 87 | |
| 88 TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_OnReceiveBitrateChanged) { | |
| 89 PacketRouter packet_router; | |
| 90 | |
| 91 const std::vector<uint32_t> ssrcs = {1, 2, 3}; | |
| 92 constexpr uint32_t bitrate_bps = 10000; | |
| 93 | |
| 94 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_bps); | |
| 95 } | |
| 96 | |
| 97 TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_SendRemb) { | |
| 98 PacketRouter packet_router; | |
| 99 | |
| 100 const std::vector<uint32_t> ssrcs = {1, 2, 3}; | |
| 101 constexpr uint32_t bitrate_bps = 10000; | |
| 102 | |
| 103 EXPECT_FALSE(packet_router.SendRemb(bitrate_bps, ssrcs)); | |
| 104 } | |
| 105 | |
| 106 TEST_F(PacketRouterTest, Sanity_NoModuleRegistered_SendTransportFeedback) { | |
| 107 PacketRouter packet_router; | |
| 108 | |
| 109 rtcp::TransportFeedback feedback; | |
| 110 | |
| 111 EXPECT_FALSE(packet_router_->SendTransportFeedback(&feedback)); | |
| 112 } | |
| 113 | |
| 40 TEST_F(PacketRouterTest, TimeToSendPacket) { | 114 TEST_F(PacketRouterTest, TimeToSendPacket) { | 
| 41 NiceMock<MockRtpRtcp> rtp_1; | 115 NiceMock<MockRtpRtcp> rtp_1; | 
| 42 NiceMock<MockRtpRtcp> rtp_2; | 116 NiceMock<MockRtpRtcp> rtp_2; | 
| 43 packet_router_->AddSendRtpModule(&rtp_1); | 117 packet_router_->AddSendRtpModule(&rtp_1, false); | 
| 44 packet_router_->AddSendRtpModule(&rtp_2); | 118 packet_router_->AddSendRtpModule(&rtp_2, false); | 
| 45 | 119 | 
| 46 const uint16_t kSsrc1 = 1234; | 120 const uint16_t kSsrc1 = 1234; | 
| 47 uint16_t sequence_number = 17; | 121 uint16_t sequence_number = 17; | 
| 48 uint64_t timestamp = 7890; | 122 uint64_t timestamp = 7890; | 
| 49 bool retransmission = false; | 123 bool retransmission = false; | 
| 50 | 124 | 
| 51 // Send on the first module by letting rtp_1 be sending with correct ssrc. | 125 // 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)); | 126 EXPECT_CALL(rtp_1, SendingMedia()).Times(1).WillOnce(Return(true)); | 
| 53 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); | 127 EXPECT_CALL(rtp_1, SSRC()).Times(1).WillOnce(Return(kSsrc1)); | 
| 54 EXPECT_CALL(rtp_1, TimeToSendPacket( | 128 EXPECT_CALL(rtp_1, TimeToSendPacket( | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 const uint16_t kSsrc1 = 1234; | 192 const uint16_t kSsrc1 = 1234; | 
| 119 const uint16_t kSsrc2 = 4567; | 193 const uint16_t kSsrc2 = 4567; | 
| 120 | 194 | 
| 121 NiceMock<MockRtpRtcp> rtp_1; | 195 NiceMock<MockRtpRtcp> rtp_1; | 
| 122 EXPECT_CALL(rtp_1, RtxSendStatus()).WillOnce(Return(kRtxOff)); | 196 EXPECT_CALL(rtp_1, RtxSendStatus()).WillOnce(Return(kRtxOff)); | 
| 123 EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); | 197 EXPECT_CALL(rtp_1, SSRC()).WillRepeatedly(Return(kSsrc1)); | 
| 124 NiceMock<MockRtpRtcp> rtp_2; | 198 NiceMock<MockRtpRtcp> rtp_2; | 
| 125 // rtp_2 will be prioritized for padding. | 199 // rtp_2 will be prioritized for padding. | 
| 126 EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads)); | 200 EXPECT_CALL(rtp_2, RtxSendStatus()).WillOnce(Return(kRtxRedundantPayloads)); | 
| 127 EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); | 201 EXPECT_CALL(rtp_2, SSRC()).WillRepeatedly(Return(kSsrc2)); | 
| 128 packet_router_->AddSendRtpModule(&rtp_1); | 202 packet_router_->AddSendRtpModule(&rtp_1, false); | 
| 129 packet_router_->AddSendRtpModule(&rtp_2); | 203 packet_router_->AddSendRtpModule(&rtp_2, false); | 
| 130 | 204 | 
| 131 // Default configuration, sending padding on all modules sending media, | 205 // Default configuration, sending padding on all modules sending media, | 
| 132 // ordered by priority (based on rtx mode). | 206 // ordered by priority (based on rtx mode). | 
| 133 const size_t requested_padding_bytes = 1000; | 207 const size_t requested_padding_bytes = 1000; | 
| 134 const size_t sent_padding_bytes = 890; | 208 const size_t sent_padding_bytes = 890; | 
| 135 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 209 EXPECT_CALL(rtp_2, SendingMedia()).Times(1).WillOnce(Return(true)); | 
| 136 EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); | 210 EXPECT_CALL(rtp_2, HasBweExtensions()).Times(1).WillOnce(Return(true)); | 
| 137 EXPECT_CALL(rtp_2, | 211 EXPECT_CALL(rtp_2, | 
| 138 TimeToSendPadding(requested_padding_bytes, | 212 TimeToSendPadding(requested_padding_bytes, | 
| 139 Field(&PacedPacketInfo::probe_cluster_id, 111))) | 213 Field(&PacedPacketInfo::probe_cluster_id, 111))) | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 packet_router_->TimeToSendPadding( | 277 packet_router_->TimeToSendPadding( | 
| 204 requested_padding_bytes, | 278 requested_padding_bytes, | 
| 205 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, | 279 PacedPacketInfo(PacedPacketInfo::kNotAProbe, kProbeMinBytes, | 
| 206 kProbeMinBytes))); | 280 kProbeMinBytes))); | 
| 207 | 281 | 
| 208 packet_router_->RemoveSendRtpModule(&rtp_2); | 282 packet_router_->RemoveSendRtpModule(&rtp_2); | 
| 209 } | 283 } | 
| 210 | 284 | 
| 211 TEST_F(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) { | 285 TEST_F(PacketRouterTest, SenderOnlyFunctionsRespectSendingMedia) { | 
| 212 NiceMock<MockRtpRtcp> rtp; | 286 NiceMock<MockRtpRtcp> rtp; | 
| 213 packet_router_->AddSendRtpModule(&rtp); | 287 packet_router_->AddSendRtpModule(&rtp, false); | 
| 214 static const uint16_t kSsrc = 1234; | 288 static const uint16_t kSsrc = 1234; | 
| 215 EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc)); | 289 EXPECT_CALL(rtp, SSRC()).WillRepeatedly(Return(kSsrc)); | 
| 216 EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false)); | 290 EXPECT_CALL(rtp, SendingMedia()).WillRepeatedly(Return(false)); | 
| 217 | 291 | 
| 218 // Verify that TimeToSendPacket does not end up in a receiver. | 292 // Verify that TimeToSendPacket does not end up in a receiver. | 
| 219 EXPECT_CALL(rtp, TimeToSendPacket(_, _, _, _, _)).Times(0); | 293 EXPECT_CALL(rtp, TimeToSendPacket(_, _, _, _, _)).Times(0); | 
| 220 EXPECT_TRUE(packet_router_->TimeToSendPacket( | 294 EXPECT_TRUE(packet_router_->TimeToSendPacket( | 
| 221 kSsrc, 1, 1, false, PacedPacketInfo(PacedPacketInfo::kNotAProbe, | 295 kSsrc, 1, 1, false, PacedPacketInfo(PacedPacketInfo::kNotAProbe, | 
| 222 kProbeMinBytes, kProbeMinBytes))); | 296 kProbeMinBytes, kProbeMinBytes))); | 
| 223 // Verify that TimeToSendPadding does not end up in a receiver. | 297 // Verify that TimeToSendPadding does not end up in a receiver. | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 239 for (size_t i = 0; i < kNumPackets; ++i) { | 313 for (size_t i = 0; i < kNumPackets; ++i) { | 
| 240 uint16_t seq = packet_router_->AllocateSequenceNumber(); | 314 uint16_t seq = packet_router_->AllocateSequenceNumber(); | 
| 241 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; | 315 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; | 
| 242 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); | 316 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); | 
| 243 } | 317 } | 
| 244 } | 318 } | 
| 245 | 319 | 
| 246 TEST_F(PacketRouterTest, SendTransportFeedback) { | 320 TEST_F(PacketRouterTest, SendTransportFeedback) { | 
| 247 NiceMock<MockRtpRtcp> rtp_1; | 321 NiceMock<MockRtpRtcp> rtp_1; | 
| 248 NiceMock<MockRtpRtcp> rtp_2; | 322 NiceMock<MockRtpRtcp> rtp_2; | 
| 249 packet_router_->AddSendRtpModule(&rtp_1); | 323 packet_router_->AddSendRtpModule(&rtp_1, false); | 
| 250 packet_router_->AddReceiveRtpModule(&rtp_2); | 324 packet_router_->AddReceiveRtpModule(&rtp_2, false); | 
| 251 | 325 | 
| 252 rtcp::TransportFeedback feedback; | 326 rtcp::TransportFeedback feedback; | 
| 253 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); | 327 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); | 
| 254 packet_router_->SendTransportFeedback(&feedback); | 328 packet_router_->SendTransportFeedback(&feedback); | 
| 255 packet_router_->RemoveSendRtpModule(&rtp_1); | 329 packet_router_->RemoveSendRtpModule(&rtp_1); | 
| 256 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); | 330 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true)); | 
| 257 packet_router_->SendTransportFeedback(&feedback); | 331 packet_router_->SendTransportFeedback(&feedback); | 
| 258 packet_router_->RemoveReceiveRtpModule(&rtp_2); | 332 packet_router_->RemoveReceiveRtpModule(&rtp_2); | 
| 259 } | 333 } | 
| 260 | 334 | 
| 335 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | |
| 336 TEST_F(PacketRouterTest, DoubleRegistrationOfSendModuleDisallowed) { | |
| 337 PacketRouter packet_router; | |
| 338 | |
| 339 NiceMock<MockRtpRtcp> module; | |
| 340 OnSetREMBStatusAndSetRembAccordingly(&module); | |
| 341 | |
| 342 constexpr bool remb_candidate = false; // Value irrelevant. | |
| 343 packet_router.AddSendRtpModule(&module, remb_candidate); | |
| 344 EXPECT_DEATH(packet_router.AddSendRtpModule(&module, remb_candidate), ""); | |
| 345 | |
| 346 // Test tear-down | |
| 347 packet_router.RemoveSendRtpModule(&module); | |
| 348 } | |
| 349 | |
| 350 TEST_F(PacketRouterTest, DoubleRegistrationOfReceiveModuleDisallowed) { | |
| 351 PacketRouter packet_router; | |
| 352 | |
| 353 NiceMock<MockRtpRtcp> module; | |
| 354 OnSetREMBStatusAndSetRembAccordingly(&module); | |
| 355 | |
| 356 constexpr bool remb_candidate = false; // Value irrelevant. | |
| 357 packet_router.AddReceiveRtpModule(&module, remb_candidate); | |
| 358 EXPECT_DEATH(packet_router.AddReceiveRtpModule(&module, remb_candidate), ""); | |
| 359 | |
| 360 // Test tear-down | |
| 361 packet_router.RemoveReceiveRtpModule(&module); | |
| 362 } | |
| 363 | |
| 364 TEST_F(PacketRouterTest, RemovalOfNeverAddedSendModuleDisallowed) { | |
| 365 PacketRouter packet_router; | |
| 366 | |
| 367 NiceMock<MockRtpRtcp> module; | |
| 368 OnSetREMBStatusAndSetRembAccordingly(&module); | |
| 369 | |
| 370 EXPECT_DEATH(packet_router.RemoveSendRtpModule(&module), ""); | |
| 371 } | |
| 372 | |
| 373 TEST_F(PacketRouterTest, RemovalOfNeverAddedReceiveModuleDisallowed) { | |
| 374 PacketRouter packet_router; | |
| 375 | |
| 376 NiceMock<MockRtpRtcp> module; | |
| 377 OnSetREMBStatusAndSetRembAccordingly(&module); | |
| 378 | |
| 379 EXPECT_DEATH(packet_router.RemoveReceiveRtpModule(&module), ""); | |
| 380 } | |
| 381 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | |
| 382 | |
| 383 // TODO(eladalon): Remove this test; it should be covered by: | |
| 384 // 1. SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst | |
| 385 // 2. SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst | |
| 386 // 3. LowerEstimateToSendRemb | |
| 387 // (Not removing in this CL to prove it doesn't break this test.) | |
| 261 TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) { | 388 TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) { | 
| 262 rtc::ScopedFakeClock clock; | 389 rtc::ScopedFakeClock clock; | 
| 263 NiceMock<MockRtpRtcp> rtp_recv; | 390 NiceMock<MockRtpRtcp> rtp_recv; | 
| 264 NiceMock<MockRtpRtcp> rtp_send; | 391 NiceMock<MockRtpRtcp> rtp_send; | 
| 265 PacketRouter packet_router; | 392 PacketRouter packet_router; | 
| 266 | 393 | 
| 267 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1); | 394 ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, true); | 
| 268 packet_router.AddReceiveRtpModule(&rtp_recv); | 395 packet_router.AddReceiveRtpModule(&rtp_recv, true); | 
| 269 | 396 | 
| 270 const uint32_t bitrate_estimate = 456; | 397 const uint32_t bitrate_estimate = 456; | 
| 271 const std::vector<uint32_t> ssrcs = {1234}; | 398 const std::vector<uint32_t> ssrcs = {1234}; | 
| 272 | 399 | 
| 273 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true)); | |
| 274 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 400 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 275 | 401 | 
| 276 // Call OnReceiveBitrateChanged twice to get a first estimate. | 402 // Call OnReceiveBitrateChanged twice to get a first estimate. | 
| 277 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 403 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 
| 278 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 404 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 
| 279 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 405 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 280 | 406 | 
| 281 // Add a send module, which should be preferred over the receive module. | 407 // Add a send module, which should be preferred over the receive module. | 
| 282 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); | 408 ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, false); | 
| 283 EXPECT_CALL(rtp_send, SetREMBStatus(true)).Times(1); | 409 ExpectSetREMBStatusAndSetRembAccordingly(&rtp_send, true); | 
| 284 packet_router.AddSendRtpModule(&rtp_send); | 410 packet_router.AddSendRtpModule(&rtp_send, true); | 
| 285 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(false)); | |
| 286 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); | |
| 287 | 411 | 
| 288 // Lower bitrate to send another REMB packet. | 412 // Lower bitrate to send another REMB packet. | 
| 289 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); | 413 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); | 
| 290 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); | 414 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); | 
| 291 | 415 | 
| 292 EXPECT_CALL(rtp_send, SetREMBStatus(false)).Times(1); | 416 ExpectSetREMBStatusAndSetRembAccordingly(&rtp_send, false); | 
| 293 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1); | 417 ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, true); | 
| 294 packet_router.RemoveSendRtpModule(&rtp_send); | 418 packet_router.RemoveSendRtpModule(&rtp_send); | 
| 295 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1); | 419 | 
| 420 ExpectSetREMBStatusAndSetRembAccordingly(&rtp_recv, false); | |
| 296 packet_router.RemoveReceiveRtpModule(&rtp_recv); | 421 packet_router.RemoveReceiveRtpModule(&rtp_recv); | 
| 297 } | 422 } | 
| 298 | 423 | 
| 299 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) { | 424 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) { | 
| 300 rtc::ScopedFakeClock clock; | 425 rtc::ScopedFakeClock clock; | 
| 301 NiceMock<MockRtpRtcp> rtp; | 426 NiceMock<MockRtpRtcp> rtp; | 
| 302 PacketRouter packet_router; | 427 PacketRouter packet_router; | 
| 303 | 428 | 
| 304 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); | 429 ExpectSetREMBStatusAndSetRembAccordingly(&rtp, true); | 
| 305 packet_router.AddSendRtpModule(&rtp); | 430 packet_router.AddSendRtpModule(&rtp, true); | 
| 306 | 431 | 
| 307 uint32_t bitrate_estimate = 456; | 432 uint32_t bitrate_estimate = 456; | 
| 308 const std::vector<uint32_t> ssrcs = {1234}; | 433 const std::vector<uint32_t> ssrcs = {1234}; | 
| 309 | 434 | 
| 310 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | |
| 311 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 435 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 312 | 436 | 
| 313 // Call OnReceiveBitrateChanged twice to get a first estimate. | 437 // Call OnReceiveBitrateChanged twice to get a first estimate. | 
| 314 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 438 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 
| 315 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 439 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 
| 316 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 440 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 317 | 441 | 
| 318 // Lower the estimate with more than 3% to trigger a call to SetREMBData right | 442 // Lower the estimate with more than 3% to trigger a call to SetREMBData right | 
| 319 // away. | 443 // away. | 
| 320 bitrate_estimate = bitrate_estimate - 100; | 444 bitrate_estimate = bitrate_estimate - 100; | 
| 321 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 445 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 
| 322 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 446 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 323 | 447 | 
| 324 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); | 448 ExpectSetREMBStatusAndSetRembAccordingly(&rtp, false); | 
| 325 packet_router.RemoveSendRtpModule(&rtp); | 449 packet_router.RemoveSendRtpModule(&rtp); | 
| 326 } | 450 } | 
| 327 | 451 | 
| 328 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) { | 452 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) { | 
| 329 rtc::ScopedFakeClock clock; | 453 rtc::ScopedFakeClock clock; | 
| 330 NiceMock<MockRtpRtcp> rtp; | 454 NiceMock<MockRtpRtcp> rtp; | 
| 331 PacketRouter packet_router; | 455 PacketRouter packet_router; | 
| 332 packet_router.AddSendRtpModule(&rtp); | 456 packet_router.AddSendRtpModule(&rtp, true); | 
| 333 | 457 | 
| 334 uint32_t bitrate_estimate[] = {456, 789}; | 458 uint32_t bitrate_estimate[] = {456, 789}; | 
| 335 std::vector<uint32_t> ssrcs = {1234, 5678}; | 459 std::vector<uint32_t> ssrcs = {1234, 5678}; | 
| 336 | 460 | 
| 337 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 461 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 
| 338 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); | 462 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); | 
| 339 | 463 | 
| 340 // Call OnReceiveBitrateChanged twice to get a first estimate. | 464 // Call OnReceiveBitrateChanged twice to get a first estimate. | 
| 341 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1); | 465 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1); | 
| 342 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 466 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 
| 343 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); | 467 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]); | 
| 344 | 468 | 
| 345 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100); | 469 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100); | 
| 346 | 470 | 
| 347 // Lower the estimate to trigger a callback. | 471 // Lower the estimate to trigger a callback. | 
| 348 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1); | 472 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1); | 
| 349 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]); | 473 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]); | 
| 350 | 474 | 
| 351 packet_router.RemoveSendRtpModule(&rtp); | 475 packet_router.RemoveSendRtpModule(&rtp); | 
| 352 } | 476 } | 
| 353 | 477 | 
| 354 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) { | 478 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) { | 
| 355 rtc::ScopedFakeClock clock; | 479 rtc::ScopedFakeClock clock; | 
| 356 NiceMock<MockRtpRtcp> rtp; | 480 NiceMock<MockRtpRtcp> rtp; | 
| 357 PacketRouter packet_router; | 481 PacketRouter packet_router; | 
| 358 packet_router.AddSendRtpModule(&rtp); | 482 packet_router.AddSendRtpModule(&rtp, true); | 
| 359 | 483 | 
| 360 uint32_t bitrate_estimate = 456; | 484 uint32_t bitrate_estimate = 456; | 
| 361 std::vector<uint32_t> ssrcs = {1234, 5678}; | 485 std::vector<uint32_t> ssrcs = {1234, 5678}; | 
| 362 | 486 | 
| 363 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 487 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 
| 364 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 488 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 365 | 489 | 
| 366 // Call OnReceiveBitrateChanged twice to get a first estimate. | 490 // Call OnReceiveBitrateChanged twice to get a first estimate. | 
| 367 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 491 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 
| 368 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 492 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 
| 369 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 493 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 370 | 494 | 
| 371 // Increased estimate shouldn't trigger a callback right away. | 495 // Increased estimate shouldn't trigger a callback right away. | 
| 372 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); | 496 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); | 
| 373 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1); | 497 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1); | 
| 374 | 498 | 
| 375 // Decreasing the estimate less than 3% shouldn't trigger a new callback. | 499 // Decreasing the estimate less than 3% shouldn't trigger a new callback. | 
| 376 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); | 500 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0); | 
| 377 int lower_estimate = bitrate_estimate * 98 / 100; | 501 int lower_estimate = bitrate_estimate * 98 / 100; | 
| 378 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate); | 502 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate); | 
| 379 | 503 | 
| 380 packet_router.RemoveSendRtpModule(&rtp); | 504 packet_router.RemoveSendRtpModule(&rtp); | 
| 381 } | 505 } | 
| 382 | 506 | 
| 383 TEST(PacketRouterRembTest, ChangeSendRtpModule) { | 507 TEST(PacketRouterRembTest, ChangeSendRtpModule) { | 
| 384 rtc::ScopedFakeClock clock; | 508 rtc::ScopedFakeClock clock; | 
| 385 NiceMock<MockRtpRtcp> rtp_send; | 509 NiceMock<MockRtpRtcp> rtp_send; | 
| 386 NiceMock<MockRtpRtcp> rtp_recv; | 510 NiceMock<MockRtpRtcp> rtp_recv; | 
| 387 PacketRouter packet_router; | 511 PacketRouter packet_router; | 
| 388 packet_router.AddSendRtpModule(&rtp_send); | 512 packet_router.AddSendRtpModule(&rtp_send, true); | 
| 389 packet_router.AddReceiveRtpModule(&rtp_recv); | 513 packet_router.AddReceiveRtpModule(&rtp_recv, true); | 
| 390 | 514 | 
| 391 uint32_t bitrate_estimate = 456; | 515 uint32_t bitrate_estimate = 456; | 
| 392 std::vector<uint32_t> ssrcs = {1234, 5678}; | 516 std::vector<uint32_t> ssrcs = {1234, 5678}; | 
| 393 | 517 | 
| 394 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); | 518 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true)); | 
| 395 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 519 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 396 | 520 | 
| 397 // Call OnReceiveBitrateChanged twice to get a first estimate. | 521 // Call OnReceiveBitrateChanged twice to get a first estimate. | 
| 398 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 522 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 
| 399 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 523 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 416 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 540 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 
| 417 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 541 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 418 | 542 | 
| 419 packet_router.RemoveReceiveRtpModule(&rtp_recv); | 543 packet_router.RemoveReceiveRtpModule(&rtp_recv); | 
| 420 } | 544 } | 
| 421 | 545 | 
| 422 TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) { | 546 TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) { | 
| 423 rtc::ScopedFakeClock clock; | 547 rtc::ScopedFakeClock clock; | 
| 424 NiceMock<MockRtpRtcp> rtp; | 548 NiceMock<MockRtpRtcp> rtp; | 
| 425 PacketRouter packet_router; | 549 PacketRouter packet_router; | 
| 426 packet_router.AddSendRtpModule(&rtp); | 550 packet_router.AddSendRtpModule(&rtp, true); | 
| 427 | 551 | 
| 428 uint32_t bitrate_estimate = 456; | 552 uint32_t bitrate_estimate = 456; | 
| 429 const std::vector<uint32_t> ssrcs = {1234}; | 553 const std::vector<uint32_t> ssrcs = {1234}; | 
| 430 | 554 | 
| 431 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 555 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 
| 432 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 556 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 433 | 557 | 
| 434 // Call OnReceiveBitrateChanged twice to get a first estimate. | 558 // Call OnReceiveBitrateChanged twice to get a first estimate. | 
| 435 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 559 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 
| 436 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1); | 560 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1); | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 448 } | 572 } | 
| 449 | 573 | 
| 450 // Only register receiving modules and make sure we fallback to trigger a REMB | 574 // Only register receiving modules and make sure we fallback to trigger a REMB | 
| 451 // packet on this one. | 575 // packet on this one. | 
| 452 TEST(PacketRouterRembTest, NoSendingRtpModule) { | 576 TEST(PacketRouterRembTest, NoSendingRtpModule) { | 
| 453 rtc::ScopedFakeClock clock; | 577 rtc::ScopedFakeClock clock; | 
| 454 NiceMock<MockRtpRtcp> rtp; | 578 NiceMock<MockRtpRtcp> rtp; | 
| 455 PacketRouter packet_router; | 579 PacketRouter packet_router; | 
| 456 | 580 | 
| 457 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); | 581 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1); | 
| 458 packet_router.AddReceiveRtpModule(&rtp); | 582 packet_router.AddReceiveRtpModule(&rtp, true); | 
| 459 | 583 | 
| 460 uint32_t bitrate_estimate = 456; | 584 uint32_t bitrate_estimate = 456; | 
| 461 const std::vector<uint32_t> ssrcs = {1234}; | 585 const std::vector<uint32_t> ssrcs = {1234}; | 
| 462 | 586 | 
| 463 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 587 ON_CALL(rtp, REMB()).WillByDefault(Return(true)); | 
| 464 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 588 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 465 | 589 | 
| 466 // Call OnReceiveBitrateChanged twice to get a first estimate. | 590 // Call OnReceiveBitrateChanged twice to get a first estimate. | 
| 467 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 591 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | 
| 468 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 592 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | 
| 469 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 593 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | 
| 470 | 594 | 
| 471 // Lower the estimate to trigger a new packet REMB packet. | 595 // Lower the estimate to trigger a new packet REMB packet. | 
| 472 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); | 596 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1); | 
| 473 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); | 597 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100); | 
| 474 | 598 | 
| 475 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); | 599 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1); | 
| 476 packet_router.RemoveReceiveRtpModule(&rtp); | 600 packet_router.RemoveReceiveRtpModule(&rtp); | 
| 477 } | 601 } | 
| 478 | 602 | 
| 603 TEST(PacketRouterRembTest, NonCandidateSendRtpModuleNotUsedForRemb) { | |
| 604 rtc::ScopedFakeClock clock; | |
| 605 PacketRouter packet_router; | |
| 606 NiceMock<MockRtpRtcp> module; | |
| 607 | |
| 608 constexpr bool remb_candidate = false; | |
| 609 ON_CALL(module, REMB()).WillByDefault(Return(false)); | |
| 610 EXPECT_CALL(module, SetREMBStatus(_)).Times(0); | |
| 611 packet_router.AddSendRtpModule(&module, remb_candidate); | |
| 612 | |
| 613 constexpr uint32_t bitrate_estimate = 456; | |
| 614 const std::vector<uint32_t> ssrcs = {1234}; | |
| 615 EXPECT_CALL(module, SetREMBData(_, _)).Times(0); | |
| 616 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | |
| 
danilchap
2017/07/28 11:35:04
probably better to advance time after OnReceiveBit
 
eladalon
2017/07/28 15:47:11
What effect would moving the clock have on the pac
 
eladalon
2017/07/28 15:47:12
Done.
 
danilchap
2017/07/31 13:18:03
Hm, true, it shouldn't. until clock will learn to
 | |
| 617 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | |
| 618 | |
| 619 // Test tear-down | |
| 620 packet_router.RemoveSendRtpModule(&module); | |
| 621 } | |
| 622 | |
| 623 TEST(PacketRouterRembTest, CandidateSendRtpModuleUsedForRemb) { | |
| 624 rtc::ScopedFakeClock clock; | |
| 625 PacketRouter packet_router; | |
| 626 NiceMock<MockRtpRtcp> module; | |
| 627 | |
| 628 ExpectSetREMBStatusAndSetRembAccordingly(&module, true); | |
| 629 constexpr bool remb_candidate = true; | |
| 630 packet_router.AddSendRtpModule(&module, remb_candidate); | |
| 631 | |
| 632 constexpr uint32_t bitrate_estimate = 456; | |
| 633 const std::vector<uint32_t> ssrcs = {1234}; | |
| 634 EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | |
| 635 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | |
| 
danilchap
2017/07/28 11:35:04
either do not advance time at all (to stress remb
 
eladalon
2017/07/28 15:47:11
OnReceiveBitrateChanged() won't have the expected
 | |
| 636 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | |
| 637 | |
| 638 // Test tear-down | |
| 639 ExpectSetREMBStatusAndSetRembAccordingly(&module, false); | |
| 640 packet_router.RemoveSendRtpModule(&module); | |
| 641 } | |
| 642 | |
| 643 TEST(PacketRouterRembTest, NonCandidateReceiveRtpModuleNotUsedForRemb) { | |
| 644 rtc::ScopedFakeClock clock; | |
| 645 PacketRouter packet_router; | |
| 646 NiceMock<MockRtpRtcp> module; | |
| 647 | |
| 648 ON_CALL(module, REMB()).WillByDefault(Return(false)); | |
| 649 EXPECT_CALL(module, SetREMBStatus(_)).Times(0); | |
| 650 constexpr bool remb_candidate = false; | |
| 651 packet_router.AddReceiveRtpModule(&module, remb_candidate); | |
| 652 | |
| 653 constexpr uint32_t bitrate_estimate = 456; | |
| 654 const std::vector<uint32_t> ssrcs = {1234}; | |
| 655 EXPECT_CALL(module, SetREMBData(_, _)).Times(0); | |
| 656 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | |
| 657 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | |
| 658 | |
| 659 // Test tear-down | |
| 660 packet_router.RemoveReceiveRtpModule(&module); | |
| 661 } | |
| 662 | |
| 663 TEST(PacketRouterRembTest, CandidateReceiveRtpModuleUsedForRemb) { | |
| 664 rtc::ScopedFakeClock clock; | |
| 665 PacketRouter packet_router; | |
| 666 NiceMock<MockRtpRtcp> module; | |
| 667 | |
| 668 ExpectSetREMBStatusAndSetRembAccordingly(&module, true); | |
| 669 constexpr bool remb_candidate = true; | |
| 670 packet_router.AddReceiveRtpModule(&module, remb_candidate); | |
| 671 | |
| 672 constexpr uint32_t bitrate_estimate = 456; | |
| 673 const std::vector<uint32_t> ssrcs = {1234}; | |
| 674 EXPECT_CALL(module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | |
| 675 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | |
| 676 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | |
| 677 | |
| 678 // Test tear-down | |
| 679 ExpectSetREMBStatusAndSetRembAccordingly(&module, false); | |
| 680 packet_router.RemoveReceiveRtpModule(&module); | |
| 681 } | |
| 682 | |
| 683 TEST(PacketRouterRembTest, | |
| 684 SendCandidatePreferredOverReceiveCandidate_SendModuleAddedFirst) { | |
| 685 rtc::ScopedFakeClock clock; | |
| 686 PacketRouter packet_router; | |
| 687 NiceMock<MockRtpRtcp> send_module; | |
| 688 NiceMock<MockRtpRtcp> receive_module; | |
| 689 | |
| 690 constexpr bool remb_candidate = true; | |
| 691 | |
| 692 // Send module added - activated. | |
| 693 ExpectSetREMBStatusAndSetRembAccordingly(&send_module, true); | |
| 694 packet_router.AddSendRtpModule(&send_module, remb_candidate); | |
| 695 | |
| 696 // Receive module added - the send module remains the active one. | |
| 697 ON_CALL(receive_module, REMB()).WillByDefault(Return(false)); | |
| 698 EXPECT_CALL(receive_module, SetREMBStatus(true)).Times(0); | |
| 699 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate); | |
| 700 | |
| 701 constexpr uint32_t bitrate_estimate = 456; | |
| 702 const std::vector<uint32_t> ssrcs = {1234}; | |
| 703 EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | |
| 704 EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0); | |
| 705 | |
| 706 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | |
| 707 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | |
| 708 | |
| 709 // Test tear-down | |
| 710 packet_router.RemoveReceiveRtpModule(&receive_module); | |
| 711 ExpectSetREMBStatusAndSetRembAccordingly(&send_module, false); | |
| 712 packet_router.RemoveSendRtpModule(&send_module); | |
| 713 } | |
| 714 | |
| 715 TEST(PacketRouterRembTest, | |
| 716 SendCandidatePreferredOverReceiveCandidate_ReceiveModuleAddedFirst) { | |
| 717 rtc::ScopedFakeClock clock; | |
| 718 PacketRouter packet_router; | |
| 719 NiceMock<MockRtpRtcp> send_module; | |
| 720 NiceMock<MockRtpRtcp> receive_module; | |
| 721 | |
| 722 constexpr bool remb_candidate = true; | |
| 723 | |
| 724 // Receive module added - activated. | |
| 725 ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, true); | |
| 726 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate); | |
| 727 | |
| 728 // Send module added - replaces receive module as active. | |
| 729 ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, false); | |
| 730 ExpectSetREMBStatusAndSetRembAccordingly(&send_module, true); | |
| 731 packet_router.AddSendRtpModule(&send_module, remb_candidate); | |
| 732 | |
| 733 constexpr uint32_t bitrate_estimate = 456; | |
| 734 const std::vector<uint32_t> ssrcs = {1234}; | |
| 735 EXPECT_CALL(send_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | |
| 736 EXPECT_CALL(receive_module, SetREMBData(_, _)).Times(0); | |
| 737 | |
| 738 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | |
| 739 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | |
| 740 | |
| 741 // Test tear-down | |
| 742 packet_router.RemoveReceiveRtpModule(&receive_module); | |
| 743 ExpectSetREMBStatusAndSetRembAccordingly(&send_module, false); | |
| 744 packet_router.RemoveSendRtpModule(&send_module); | |
| 745 } | |
| 746 | |
| 747 TEST(PacketRouterRembTest, ReceiveModuleTakesOverWhenLastSendModuleRemoved) { | |
| 748 rtc::ScopedFakeClock clock; | |
| 749 PacketRouter packet_router; | |
| 750 NiceMock<MockRtpRtcp> send_module; | |
| 751 NiceMock<MockRtpRtcp> receive_module; | |
| 752 | |
| 753 constexpr bool remb_candidate = true; | |
| 754 | |
| 755 // Send module added - activated. | |
| 756 ExpectSetREMBStatusAndSetRembAccordingly(&send_module, true); | |
| 757 packet_router.AddSendRtpModule(&send_module, remb_candidate); | |
| 758 | |
| 759 // Receive module added - the send module remains the active one. | |
| 760 ON_CALL(receive_module, REMB()).WillByDefault(Return(false)); | |
| 761 EXPECT_CALL(receive_module, SetREMBStatus(true)).Times(0); | |
| 762 packet_router.AddReceiveRtpModule(&receive_module, remb_candidate); | |
| 763 | |
| 764 // Send module removed - receive module becomes active. | |
| 765 ExpectSetREMBStatusAndSetRembAccordingly(&send_module, false); | |
| 766 ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, true); | |
| 767 packet_router.RemoveSendRtpModule(&send_module); | |
| 768 | |
| 769 constexpr uint32_t bitrate_estimate = 456; | |
| 770 const std::vector<uint32_t> ssrcs = {1234}; | |
| 771 EXPECT_CALL(send_module, SetREMBData(_, _)).Times(0); | |
| 772 EXPECT_CALL(receive_module, SetREMBData(bitrate_estimate, ssrcs)).Times(1); | |
| 773 | |
| 774 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000)); | |
| 775 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate); | |
| 776 | |
| 777 // Test tear-down | |
| 778 ExpectSetREMBStatusAndSetRembAccordingly(&receive_module, false); | |
| 779 packet_router.RemoveReceiveRtpModule(&receive_module); | |
| 780 } | |
| 781 | |
| 782 // TODO(eladalon): Tests for a module which is both receive as well as send? | |
| 
danilchap
2017/07/27 20:00:20
do not think we have those modules. At least for v
 
eladalon
2017/07/27 21:30:54
Acknowledged; will remove this TODO with the next
 | |
| 783 | |
| 479 } // namespace webrtc | 784 } // namespace webrtc | 
| OLD | NEW |