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" |
| 18 #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller
.h" |
11 #include "webrtc/modules/pacing/packet_router.h" | 19 #include "webrtc/modules/pacing/packet_router.h" |
12 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | 20 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
13 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
14 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
15 #include "webrtc/test/gmock.h" | |
16 #include "webrtc/test/gtest.h" | |
17 | 23 |
18 using ::testing::_; | 24 using ::testing::_; |
19 using ::testing::InSequence; | 25 using ::testing::InSequence; |
20 using ::testing::Invoke; | 26 using ::testing::Invoke; |
21 using ::testing::Return; | 27 using ::testing::Return; |
22 | 28 |
23 namespace webrtc { | 29 namespace webrtc { |
24 | 30 |
25 class MockPacketRouter : public PacketRouter { | 31 class MockPacketRouter : public PacketRouter { |
26 public: | 32 public: |
27 MOCK_METHOD1(SendFeedback, bool(rtcp::TransportFeedback* packet)); | 33 MOCK_METHOD1(SendFeedback, bool(rtcp::TransportFeedback* packet)); |
28 }; | 34 }; |
29 | 35 |
30 class RemoteEstimatorProxyTest : public ::testing::Test { | 36 class RemoteEstimatorProxyTest : public ::testing::Test { |
31 public: | 37 public: |
32 RemoteEstimatorProxyTest() : clock_(0), proxy_(&clock_, &router_) {} | 38 RemoteEstimatorProxyTest() |
| 39 : clock_(0), proxy_(&clock_, &router_, &bitrate_controller_) {} |
33 | 40 |
34 protected: | 41 protected: |
35 void IncomingPacket(uint16_t seq, int64_t time_ms) { | 42 void IncomingPacket(uint16_t seq, int64_t time_ms) { |
36 RTPHeader header; | 43 RTPHeader header; |
37 header.extension.hasTransportSequenceNumber = true; | 44 header.extension.hasTransportSequenceNumber = true; |
38 header.extension.transportSequenceNumber = seq; | 45 header.extension.transportSequenceNumber = seq; |
39 header.ssrc = kMediaSsrc; | 46 header.ssrc = kMediaSsrc; |
40 proxy_.IncomingPacket(time_ms, kDefaultPacketSize, header); | 47 proxy_.IncomingPacket(time_ms, kDefaultPacketSize, header); |
41 } | 48 } |
42 | 49 |
43 void Process() { | 50 void Process() { |
44 clock_.AdvanceTimeMilliseconds( | 51 clock_.AdvanceTimeMilliseconds(50); |
45 RemoteEstimatorProxy::kDefaultProcessIntervalMs); | |
46 proxy_.Process(); | 52 proxy_.Process(); |
47 } | 53 } |
48 | 54 |
49 SimulatedClock clock_; | 55 SimulatedClock clock_; |
50 testing::StrictMock<MockPacketRouter> router_; | 56 testing::StrictMock<MockPacketRouter> router_; |
| 57 testing::StrictMock<test::MockBitrateController> bitrate_controller_; |
51 RemoteEstimatorProxy proxy_; | 58 RemoteEstimatorProxy proxy_; |
52 | 59 |
53 const size_t kDefaultPacketSize = 100; | 60 const size_t kDefaultPacketSize = 100; |
54 const uint32_t kMediaSsrc = 456; | 61 const uint32_t kMediaSsrc = 456; |
55 const uint16_t kBaseSeq = 10; | 62 const uint16_t kBaseSeq = 10; |
56 const int64_t kBaseTimeMs = 123; | 63 const int64_t kBaseTimeMs = 123; |
57 const int64_t kMaxSmallDeltaMs = | 64 const int64_t kMaxSmallDeltaMs = |
58 (rtcp::TransportFeedback::kDeltaScaleFactor * 0xFF) / 1000; | 65 (rtcp::TransportFeedback::kDeltaScaleFactor * 0xFF) / 1000; |
59 }; | 66 }; |
60 | 67 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 EXPECT_EQ(kBaseTimeMs - 1, | 350 EXPECT_EQ(kBaseTimeMs - 1, |
344 (packet->GetBaseTimeUs() + delta_vec[0]) / 1000); | 351 (packet->GetBaseTimeUs() + delta_vec[0]) / 1000); |
345 EXPECT_EQ(kTimeoutTimeMs - kBaseTimeMs, delta_vec[1] / 1000); | 352 EXPECT_EQ(kTimeoutTimeMs - kBaseTimeMs, delta_vec[1] / 1000); |
346 EXPECT_EQ(1, delta_vec[2] / 1000); | 353 EXPECT_EQ(1, delta_vec[2] / 1000); |
347 return true; | 354 return true; |
348 })); | 355 })); |
349 | 356 |
350 Process(); | 357 Process(); |
351 } | 358 } |
352 | 359 |
| 360 TEST_F(RemoteEstimatorProxyTest, TimeUntilNextProcessIsZeroBeforeFirstProcess) { |
| 361 EXPECT_EQ(0, proxy_.TimeUntilNextProcess()); |
| 362 } |
| 363 |
| 364 TEST_F(RemoteEstimatorProxyTest, TimeUntilNextProcessIsMinIntervalOn300kbps) { |
| 365 EXPECT_CALL(bitrate_controller_, AvailableBandwidth(testing::NotNull())) |
| 366 .Times(1) |
| 367 .WillOnce(Invoke([](uint32_t* bitrate) { |
| 368 *bitrate = 300000; |
| 369 return false; |
| 370 })); |
| 371 |
| 372 Process(); |
| 373 EXPECT_EQ(RemoteEstimatorProxy::kMinSendIntervalMs, |
| 374 proxy_.TimeUntilNextProcess()); |
| 375 } |
| 376 |
| 377 TEST_F(RemoteEstimatorProxyTest, TimeUntilNextProcessIsMaxIntervalOn20kbps) { |
| 378 EXPECT_CALL(bitrate_controller_, AvailableBandwidth(testing::NotNull())) |
| 379 .Times(1) |
| 380 .WillOnce(Invoke([](uint32_t* bitrate) { |
| 381 *bitrate = 20000; |
| 382 return false; |
| 383 })); |
| 384 |
| 385 Process(); |
| 386 EXPECT_EQ(RemoteEstimatorProxy::kMaxSendIntervalMs, |
| 387 proxy_.TimeUntilNextProcess()); |
| 388 } |
| 389 |
| 390 TEST_F(RemoteEstimatorProxyTest, TwccReportsUse5PercentOfAvailableBandwidth) { |
| 391 EXPECT_CALL(bitrate_controller_, AvailableBandwidth(testing::NotNull())) |
| 392 .Times(1) |
| 393 .WillOnce(Invoke([](uint32_t* bitrate) { |
| 394 *bitrate = 80000; |
| 395 return false; |
| 396 })); |
| 397 Process(); |
| 398 // 80kbps * 0.05 = TwccReportSize(52B * 8b/B) * 1000ms / SendInterval(104ms) |
| 399 EXPECT_EQ(104, proxy_.TimeUntilNextProcess()); |
| 400 } |
| 401 |
353 } // namespace webrtc | 402 } // namespace webrtc |
OLD | NEW |