Chromium Code Reviews| 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 <memory> | |
| 12 #include <utility> | |
| 13 | |
| 14 #include "webrtc/test/gmock.h" | |
| 15 #include "webrtc/test/gtest.h" | |
| 16 | |
| 17 #include "webrtc/base/test/mock_ratetracker.h" | |
| 11 #include "webrtc/modules/pacing/packet_router.h" | 18 #include "webrtc/modules/pacing/packet_router.h" |
| 12 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | 19 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
| 13 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 14 #include "webrtc/system_wrappers/include/clock.h" | 21 #include "webrtc/system_wrappers/include/clock.h" |
| 15 #include "webrtc/test/gmock.h" | |
| 16 #include "webrtc/test/gtest.h" | |
| 17 | 22 |
| 18 using ::testing::_; | 23 using ::testing::_; |
| 19 using ::testing::InSequence; | 24 using ::testing::InSequence; |
| 20 using ::testing::Invoke; | 25 using ::testing::Invoke; |
| 21 using ::testing::Return; | 26 using ::testing::Return; |
| 22 | 27 |
| 23 namespace webrtc { | 28 namespace webrtc { |
| 24 | 29 |
| 25 class MockPacketRouter : public PacketRouter { | 30 class MockPacketRouter : public PacketRouter { |
| 26 public: | 31 public: |
| 27 MOCK_METHOD1(SendFeedback, bool(rtcp::TransportFeedback* packet)); | 32 MOCK_METHOD1(SendFeedback, bool(rtcp::TransportFeedback* packet)); |
| 28 }; | 33 }; |
| 29 | 34 |
| 30 class RemoteEstimatorProxyTest : public ::testing::Test { | 35 class RemoteEstimatorProxyTest : public ::testing::Test { |
| 31 public: | 36 public: |
| 32 RemoteEstimatorProxyTest() : clock_(0), proxy_(&clock_, &router_) {} | 37 RemoteEstimatorProxyTest() |
| 38 : clock_(0), | |
| 39 received_bitrate_tracker_bps_( | |
| 40 new testing::NiceMock<rtc::MockRateTracker>()), | |
| 41 mock_received_bitrate_tracker_bps_(received_bitrate_tracker_bps_.get()), | |
| 42 proxy_(&clock_, &router_, std::move(received_bitrate_tracker_bps_)) {} | |
| 33 | 43 |
| 34 protected: | 44 protected: |
| 35 void IncomingPacket(uint16_t seq, int64_t time_ms) { | 45 void IncomingPacket(uint16_t seq, int64_t time_ms) { |
| 36 RTPHeader header; | 46 RTPHeader header; |
| 37 header.extension.hasTransportSequenceNumber = true; | 47 header.extension.hasTransportSequenceNumber = true; |
| 38 header.extension.transportSequenceNumber = seq; | 48 header.extension.transportSequenceNumber = seq; |
| 39 header.ssrc = kMediaSsrc; | 49 header.ssrc = kMediaSsrc; |
| 40 proxy_.IncomingPacket(time_ms, kDefaultPacketSize, header); | 50 proxy_.IncomingPacket(time_ms, kDefaultPacketSize, header); |
| 41 } | 51 } |
| 42 | 52 |
| 43 void Process() { | 53 void Process() { |
| 44 clock_.AdvanceTimeMilliseconds( | 54 clock_.AdvanceTimeMilliseconds( |
| 45 RemoteEstimatorProxy::kDefaultProcessIntervalMs); | 55 RemoteEstimatorProxy::kHighBitrateProcessIntervalMs); |
| 46 proxy_.Process(); | 56 proxy_.Process(); |
| 47 } | 57 } |
| 48 | 58 |
| 49 SimulatedClock clock_; | 59 SimulatedClock clock_; |
| 50 testing::StrictMock<MockPacketRouter> router_; | 60 testing::StrictMock<MockPacketRouter> router_; |
| 61 std::unique_ptr<testing::NiceMock<rtc::MockRateTracker>> | |
| 62 received_bitrate_tracker_bps_; | |
| 63 testing::NiceMock<rtc::MockRateTracker>* mock_received_bitrate_tracker_bps_; | |
|
stefan-webrtc
2016/10/17 18:55:21
Instead of using a mock I'd suggest that we call I
| |
| 64 | |
| 51 RemoteEstimatorProxy proxy_; | 65 RemoteEstimatorProxy proxy_; |
| 52 | 66 |
| 53 const size_t kDefaultPacketSize = 100; | 67 const size_t kDefaultPacketSize = 100; |
| 54 const uint32_t kMediaSsrc = 456; | 68 const uint32_t kMediaSsrc = 456; |
| 55 const uint16_t kBaseSeq = 10; | 69 const uint16_t kBaseSeq = 10; |
| 56 const int64_t kBaseTimeMs = 123; | 70 const int64_t kBaseTimeMs = 123; |
| 57 const int64_t kMaxSmallDeltaMs = | 71 const int64_t kMaxSmallDeltaMs = |
| 58 (rtcp::TransportFeedback::kDeltaScaleFactor * 0xFF) / 1000; | 72 (rtcp::TransportFeedback::kDeltaScaleFactor * 0xFF) / 1000; |
| 59 }; | 73 }; |
| 60 | 74 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 EXPECT_EQ(kBaseTimeMs - 1, | 357 EXPECT_EQ(kBaseTimeMs - 1, |
| 344 (packet->GetBaseTimeUs() + delta_vec[0]) / 1000); | 358 (packet->GetBaseTimeUs() + delta_vec[0]) / 1000); |
| 345 EXPECT_EQ(kTimeoutTimeMs - kBaseTimeMs, delta_vec[1] / 1000); | 359 EXPECT_EQ(kTimeoutTimeMs - kBaseTimeMs, delta_vec[1] / 1000); |
| 346 EXPECT_EQ(1, delta_vec[2] / 1000); | 360 EXPECT_EQ(1, delta_vec[2] / 1000); |
| 347 return true; | 361 return true; |
| 348 })); | 362 })); |
| 349 | 363 |
| 350 Process(); | 364 Process(); |
| 351 } | 365 } |
| 352 | 366 |
| 367 TEST_F(RemoteEstimatorProxyTest, AddPaketToIncomingBitrateTracker) { | |
| 368 EXPECT_CALL(*mock_received_bitrate_tracker_bps_, | |
| 369 AddSamples(kDefaultPacketSize * 8)); | |
| 370 IncomingPacket(kBaseSeq, kBaseTimeMs); | |
| 371 } | |
| 372 | |
| 373 TEST_F(RemoteEstimatorProxyTest, | |
| 374 TimeUntilNextProcessIsHightOnLowIncomingBitrate) { | |
| 375 EXPECT_CALL(*mock_received_bitrate_tracker_bps_, TotalSampleCount()) | |
| 376 .WillRepeatedly( | |
| 377 Return(RemoteEstimatorProxy::kMinPacketCountRecievedBitrate + 1)); | |
| 378 EXPECT_CALL(*mock_received_bitrate_tracker_bps_, ComputeRate()) | |
| 379 .WillRepeatedly( | |
| 380 Return(RemoteEstimatorProxy::kSwitchToLowBitrateProcessIntervalBps)); | |
| 381 Process(); | |
| 382 EXPECT_EQ(RemoteEstimatorProxy::kLowBitrateProcessIntervalMs, | |
| 383 proxy_.TimeUntilNextProcess()); | |
| 384 } | |
| 385 | |
| 386 TEST_F(RemoteEstimatorProxyTest, | |
| 387 TimeUntilNextProcessIsLowOnHightIncomingBitrate) { | |
| 388 EXPECT_CALL(*mock_received_bitrate_tracker_bps_, TotalSampleCount()) | |
| 389 .WillRepeatedly( | |
| 390 Return(RemoteEstimatorProxy::kMinPacketCountRecievedBitrate + 1)); | |
| 391 EXPECT_CALL(*mock_received_bitrate_tracker_bps_, ComputeRate()) | |
| 392 .WillRepeatedly( | |
| 393 Return(RemoteEstimatorProxy::kSwitchToHighBitrateProcessIntervalBps)); | |
| 394 Process(); | |
| 395 EXPECT_EQ(RemoteEstimatorProxy::kHighBitrateProcessIntervalMs, | |
| 396 proxy_.TimeUntilNextProcess()); | |
| 397 } | |
| 398 | |
| 353 } // namespace webrtc | 399 } // namespace webrtc |
| OLD | NEW |