Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "webrtc/test/gmock.h" | 21 #include "webrtc/test/gmock.h" |
| 22 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
| 23 | 23 |
| 24 using testing::_; | 24 using testing::_; |
| 25 using testing::AtLeast; | 25 using testing::AtLeast; |
| 26 using testing::NiceMock; | 26 using testing::NiceMock; |
| 27 using testing::Return; | 27 using testing::Return; |
| 28 using testing::SaveArg; | 28 using testing::SaveArg; |
| 29 using testing::StrictMock; | 29 using testing::StrictMock; |
| 30 | 30 |
| 31 namespace webrtc { | |
| 32 | |
| 31 namespace { | 33 namespace { |
| 32 const webrtc::PacedPacketInfo kPacingInfo0(0, 5, 2000); | 34 const webrtc::PacedPacketInfo kPacingInfo0(0, 5, 2000); |
| 33 const webrtc::PacedPacketInfo kPacingInfo1(1, 8, 4000); | 35 const webrtc::PacedPacketInfo kPacingInfo1(1, 8, 4000); |
| 34 | 36 |
| 35 // Helper to convert some time format to resolution used in absolute send time | 37 // Helper to convert some time format to resolution used in absolute send time |
| 36 // header extension, rounded upwards. |t| is the time to convert, in some | 38 // header extension, rounded upwards. |t| is the time to convert, in some |
| 37 // resolution. |denom| is the value to divide |t| by to get whole seconds, | 39 // resolution. |denom| is the value to divide |t| by to get whole seconds, |
| 38 // e.g. |denom| = 1000 if |t| is in milliseconds. | 40 // e.g. |denom| = 1000 if |t| is in milliseconds. |
| 39 uint32_t AbsSendTime(int64_t t, int64_t denom) { | 41 uint32_t AbsSendTime(int64_t t, int64_t denom) { |
| 40 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; | 42 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; |
| 41 } | 43 } |
| 42 | 44 |
| 45 class MockPacketRouter : public PacketRouter { | |
| 46 public: | |
| 47 MOCK_METHOD2(OnReceiveBitrateChanged, | |
| 48 void(const std::vector<uint32_t>& ssrcs, | |
| 49 uint32_t bitrate)); | |
| 50 }; | |
| 51 | |
| 52 const uint32_t kInitialBitrateBps = 60000; | |
| 53 | |
| 43 } // namespace | 54 } // namespace |
| 44 | 55 |
| 45 namespace webrtc { | |
| 46 namespace test { | 56 namespace test { |
| 47 | 57 |
| 48 class CongestionControllerTest : public ::testing::Test { | 58 class CongestionControllerTest : public ::testing::Test { |
| 49 protected: | 59 protected: |
| 50 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} | 60 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} |
| 51 ~CongestionControllerTest() override {} | 61 ~CongestionControllerTest() override {} |
| 52 | 62 |
| 53 void SetUp() override { | 63 void SetUp() override { |
| 54 pacer_ = new NiceMock<MockPacedSender>(); | 64 pacer_ = new NiceMock<MockPacedSender>(); |
| 55 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. | 65 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 | 146 |
| 137 SimulatedClock clock_; | 147 SimulatedClock clock_; |
| 138 StrictMock<MockCongestionObserver> observer_; | 148 StrictMock<MockCongestionObserver> observer_; |
| 139 TargetBitrateObserver target_bitrate_observer_; | 149 TargetBitrateObserver target_bitrate_observer_; |
| 140 NiceMock<MockPacedSender>* pacer_; | 150 NiceMock<MockPacedSender>* pacer_; |
| 141 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 151 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
| 142 NiceMock<MockRtcEventLog> event_log_; | 152 NiceMock<MockRtcEventLog> event_log_; |
| 143 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | 153 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
| 144 PacketRouter packet_router_; | 154 PacketRouter packet_router_; |
| 145 std::unique_ptr<CongestionController> controller_; | 155 std::unique_ptr<CongestionController> controller_; |
| 146 const uint32_t kInitialBitrateBps = 60000; | |
| 147 | 156 |
| 148 rtc::Optional<uint32_t> target_bitrate_bps_; | 157 rtc::Optional<uint32_t> target_bitrate_bps_; |
| 149 }; | 158 }; |
| 150 | 159 |
| 151 TEST_F(CongestionControllerTest, OnNetworkChanged) { | 160 TEST_F(CongestionControllerTest, OnNetworkChanged) { |
| 152 // Test no change. | 161 // Test no change. |
| 153 clock_.AdvanceTimeMilliseconds(25); | 162 clock_.AdvanceTimeMilliseconds(25); |
| 154 controller_->Process(); | 163 controller_->Process(); |
| 155 | 164 |
| 156 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); | 165 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 clock_.AdvanceTimeMilliseconds(25); | 337 clock_.AdvanceTimeMilliseconds(25); |
| 329 controller_->Process(); | 338 controller_->Process(); |
| 330 | 339 |
| 331 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); | 340 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); |
| 332 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); | 341 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); |
| 333 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 342 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 334 clock_.AdvanceTimeMilliseconds(25); | 343 clock_.AdvanceTimeMilliseconds(25); |
| 335 controller_->Process(); | 344 controller_->Process(); |
| 336 } | 345 } |
| 337 | 346 |
| 338 TEST_F(CongestionControllerTest, OnReceivedPacketWithAbsSendTime) { | 347 TEST(ReceiveSideCongestionControllerTest, OnReceivedPacketWithAbsSendTime) { |
|
nisse-webrtc
2017/04/03 11:32:35
This test works fine without a test fixture. At so
| |
| 339 NiceMock<MockCongestionObserver> observer; | 348 StrictMock<MockPacketRouter> packet_router; |
| 340 StrictMock<MockRemoteBitrateObserver> remote_bitrate_observer; | 349 SimulatedClock clock_(123456); |
| 341 std::unique_ptr<PacedSender> pacer(new NiceMock<MockPacedSender>()); | 350 |
| 342 controller_.reset( | 351 ReceiveSideCongestionController controller(&clock_, &packet_router); |
| 343 new CongestionController(&clock_, &observer, &remote_bitrate_observer, | |
| 344 &event_log_, &packet_router_, std::move(pacer))); | |
| 345 | 352 |
| 346 size_t payload_size = 1000; | 353 size_t payload_size = 1000; |
| 347 RTPHeader header; | 354 RTPHeader header; |
| 348 header.ssrc = 0x11eb21c; | 355 header.ssrc = 0x11eb21c; |
| 349 header.extension.hasAbsoluteSendTime = true; | 356 header.extension.hasAbsoluteSendTime = true; |
| 350 | 357 |
| 351 std::vector<unsigned int> ssrcs; | 358 std::vector<unsigned int> ssrcs; |
| 352 EXPECT_CALL(remote_bitrate_observer, OnReceiveBitrateChanged(_, _)) | 359 EXPECT_CALL(packet_router, OnReceiveBitrateChanged(_, _)) |
| 353 .WillRepeatedly(SaveArg<0>(&ssrcs)); | 360 .WillRepeatedly(SaveArg<0>(&ssrcs)); |
| 354 | 361 |
| 355 for (int i = 0; i < 10; ++i) { | 362 for (int i = 0; i < 10; ++i) { |
| 356 clock_.AdvanceTimeMilliseconds((1000 * payload_size) / kInitialBitrateBps); | 363 clock_.AdvanceTimeMilliseconds((1000 * payload_size) / kInitialBitrateBps); |
| 357 int64_t now_ms = clock_.TimeInMilliseconds(); | 364 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 358 header.extension.absoluteSendTime = AbsSendTime(now_ms, 1000); | 365 header.extension.absoluteSendTime = AbsSendTime(now_ms, 1000); |
| 359 controller_->OnReceivedPacket(now_ms, payload_size, header); | 366 controller.OnReceivedPacket(now_ms, payload_size, header); |
| 360 } | 367 } |
| 361 | 368 |
| 362 ASSERT_EQ(1u, ssrcs.size()); | 369 ASSERT_EQ(1u, ssrcs.size()); |
| 363 EXPECT_EQ(header.ssrc, ssrcs[0]); | 370 EXPECT_EQ(header.ssrc, ssrcs[0]); |
| 364 } | 371 } |
| 365 | 372 |
| 366 TEST_F(CongestionControllerTest, ProbeOnRouteChange) { | 373 TEST_F(CongestionControllerTest, ProbeOnRouteChange) { |
| 367 testing::Mock::VerifyAndClearExpectations(pacer_); | 374 testing::Mock::VerifyAndClearExpectations(pacer_); |
| 368 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); | 375 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); |
| 369 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); | 376 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 ASSERT_TRUE(target_bitrate_bps_); | 487 ASSERT_TRUE(target_bitrate_bps_); |
| 481 | 488 |
| 482 // Repeat, but this time with a building delay, and make sure that the | 489 // Repeat, but this time with a building delay, and make sure that the |
| 483 // estimation is adjusted downwards. | 490 // estimation is adjusted downwards. |
| 484 uint32_t bitrate_before_delay = *target_bitrate_bps_; | 491 uint32_t bitrate_before_delay = *target_bitrate_bps_; |
| 485 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); | 492 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); |
| 486 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); | 493 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); |
| 487 } | 494 } |
| 488 } // namespace test | 495 } // namespace test |
| 489 } // namespace webrtc | 496 } // namespace webrtc |
| OLD | NEW |