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 |
11 #include <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "webrtc/modules/congestion_controller/probing_interval_estimator.h" | 14 #include "webrtc/modules/congestion_controller/probing_interval_estimator.h" |
15 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_aimd_rate_co
ntrol.h" | 15 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_aimd_rate_co
ntrol.h" |
16 #include "webrtc/test/gmock.h" | 16 #include "webrtc/test/gmock.h" |
17 #include "webrtc/test/gtest.h" | 17 #include "webrtc/test/gtest.h" |
18 | 18 |
19 using ::testing::Return; | 19 using ::testing::Return; |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 constexpr int kMinIntervalMs = 2000; | 25 constexpr int kMinIntervalMs = 2000; |
26 constexpr int kMaxIntervalMs = 50000; | 26 constexpr int kMaxIntervalMs = 50000; |
| 27 constexpr int kDefaultIntervalMs = 3000; |
27 | 28 |
28 struct ProbingIntervalEstimatorStates { | 29 struct ProbingIntervalEstimatorStates { |
29 std::unique_ptr<ProbingIntervalEstimator> probing_interval_estimator; | 30 std::unique_ptr<ProbingIntervalEstimator> probing_interval_estimator; |
30 std::unique_ptr<MockAimdRateControl> aimd_rate_control; | 31 std::unique_ptr<MockAimdRateControl> aimd_rate_control; |
31 }; | 32 }; |
32 | 33 |
33 ProbingIntervalEstimatorStates CreateProbingIntervalEstimatorStates() { | 34 ProbingIntervalEstimatorStates CreateProbingIntervalEstimatorStates() { |
34 ProbingIntervalEstimatorStates states; | 35 ProbingIntervalEstimatorStates states; |
35 states.aimd_rate_control.reset(new MockAimdRateControl()); | 36 states.aimd_rate_control.reset(new MockAimdRateControl()); |
36 states.probing_interval_estimator.reset(new ProbingIntervalEstimator( | 37 states.probing_interval_estimator.reset(new ProbingIntervalEstimator( |
37 kMinIntervalMs, kMaxIntervalMs, states.aimd_rate_control.get())); | 38 kMinIntervalMs, kMaxIntervalMs, kDefaultIntervalMs, |
| 39 states.aimd_rate_control.get())); |
38 return states; | 40 return states; |
39 } | 41 } |
40 } // namespace | 42 } // namespace |
41 | 43 |
42 TEST(ProbingIntervalEstimatorTest, NoIntervalUntillWeHaveDrop) { | 44 TEST(ProbingIntervalEstimatorTest, DefaultIntervalUntillWeHaveDrop) { |
43 auto states = CreateProbingIntervalEstimatorStates(); | 45 auto states = CreateProbingIntervalEstimatorStates(); |
44 | 46 |
45 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) | 47 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) |
46 .WillOnce(Return(rtc::Optional<int>())) | 48 .WillOnce(Return(rtc::Optional<int>())) |
47 .WillOnce(Return(rtc::Optional<int>(5000))); | 49 .WillOnce(Return(rtc::Optional<int>(5000))); |
48 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) | 50 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) |
49 .WillOnce(Return(4000)) | 51 .WillOnce(Return(4000)) |
50 .WillOnce(Return(4000)); | 52 .WillOnce(Return(4000)); |
51 | 53 |
52 EXPECT_EQ(rtc::Optional<int>(), | 54 EXPECT_EQ(kDefaultIntervalMs, |
53 states.probing_interval_estimator->GetIntervalMs()); | 55 states.probing_interval_estimator->GetIntervalMs()); |
54 EXPECT_NE(rtc::Optional<int>(), | 56 EXPECT_NE(kDefaultIntervalMs, |
55 states.probing_interval_estimator->GetIntervalMs()); | 57 states.probing_interval_estimator->GetIntervalMs()); |
56 } | 58 } |
57 | 59 |
58 TEST(ProbingIntervalEstimatorTest, CalcInterval) { | 60 TEST(ProbingIntervalEstimatorTest, CalcInterval) { |
59 auto states = CreateProbingIntervalEstimatorStates(); | 61 auto states = CreateProbingIntervalEstimatorStates(); |
60 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) | 62 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) |
61 .WillOnce(Return(rtc::Optional<int>(20000))); | 63 .WillOnce(Return(rtc::Optional<int>(20000))); |
62 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) | 64 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) |
63 .WillOnce(Return(5000)); | 65 .WillOnce(Return(5000)); |
64 EXPECT_EQ(rtc::Optional<int>(4000), | 66 EXPECT_EQ(4000, states.probing_interval_estimator->GetIntervalMs()); |
65 states.probing_interval_estimator->GetIntervalMs()); | |
66 } | 67 } |
67 | 68 |
68 TEST(ProbingIntervalEstimatorTest, IntervalDoesNotExceedMin) { | 69 TEST(ProbingIntervalEstimatorTest, IntervalDoesNotExceedMin) { |
69 auto states = CreateProbingIntervalEstimatorStates(); | 70 auto states = CreateProbingIntervalEstimatorStates(); |
70 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) | 71 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) |
71 .WillOnce(Return(rtc::Optional<int>(1000))); | 72 .WillOnce(Return(rtc::Optional<int>(1000))); |
72 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) | 73 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) |
73 .WillOnce(Return(5000)); | 74 .WillOnce(Return(5000)); |
74 EXPECT_EQ(rtc::Optional<int>(kMinIntervalMs), | 75 EXPECT_EQ(kMinIntervalMs, states.probing_interval_estimator->GetIntervalMs()); |
75 states.probing_interval_estimator->GetIntervalMs()); | |
76 } | 76 } |
77 | 77 |
78 TEST(ProbingIntervalEstimatorTest, IntervalDoesNotExceedMax) { | 78 TEST(ProbingIntervalEstimatorTest, IntervalDoesNotExceedMax) { |
79 auto states = CreateProbingIntervalEstimatorStates(); | 79 auto states = CreateProbingIntervalEstimatorStates(); |
80 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) | 80 EXPECT_CALL(*states.aimd_rate_control, GetLastBitrateDecreaseBps()) |
81 .WillOnce(Return(rtc::Optional<int>(50000))); | 81 .WillOnce(Return(rtc::Optional<int>(50000))); |
82 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) | 82 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRateBps()) |
83 .WillOnce(Return(100)); | 83 .WillOnce(Return(100)); |
84 EXPECT_EQ(rtc::Optional<int>(kMaxIntervalMs), | 84 EXPECT_EQ(kMaxIntervalMs, states.probing_interval_estimator->GetIntervalMs()); |
85 states.probing_interval_estimator->GetIntervalMs()); | |
86 } | 85 } |
87 } // namespace webrtc | 86 } // namespace webrtc |
OLD | NEW |