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 |
| 11 #include "webrtc/modules/pacing/alr_detector.h" | 11 #include "webrtc/modules/pacing/alr_detector.h" |
| 12 | 12 |
| 13 #include "webrtc/rtc_base/fakeclock.h" | |
|
philipel
2017/07/14 13:56:23
Used?
tschumi
2017/07/14 15:36:51
Removed
| |
| 13 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 constexpr int kEstimatedBitrateBps = 300000; | 18 constexpr int kEstimatedBitrateBps = 300000; |
| 19 // constexpr int64_t kAlrEndedTimeMs = 1234; | |
|
philipel
2017/07/14 13:56:23
remove
tschumi
2017/07/14 15:36:51
Done.
| |
| 18 | 20 |
| 19 } // namespace | 21 } // namespace |
| 20 | 22 |
| 21 namespace webrtc { | 23 namespace webrtc { |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 class SimulateOutgoingTrafficIn { | 26 class SimulateOutgoingTrafficIn { |
| 25 public: | 27 public: |
| 26 explicit SimulateOutgoingTrafficIn(AlrDetector* alr_detector) | 28 explicit SimulateOutgoingTrafficIn(AlrDetector* alr_detector) |
| 27 : alr_detector_(alr_detector) { | 29 : alr_detector_(alr_detector) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 81 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 80 | 82 |
| 81 // Stay in non-ALR state when usage is close to 100%. | 83 // Stay in non-ALR state when usage is close to 100%. |
| 82 SimulateOutgoingTrafficIn(&alr_detector_) | 84 SimulateOutgoingTrafficIn(&alr_detector_) |
| 83 .ForTimeMs(1000) | 85 .ForTimeMs(1000) |
| 84 .AtPercentOfEstimatedBitrate(90); | 86 .AtPercentOfEstimatedBitrate(90); |
| 85 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 87 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 86 | 88 |
| 87 // Verify that we ALR starts when bitrate drops below 20%. | 89 // Verify that we ALR starts when bitrate drops below 20%. |
| 88 SimulateOutgoingTrafficIn(&alr_detector_) | 90 SimulateOutgoingTrafficIn(&alr_detector_) |
| 89 .ForTimeMs(1000) | 91 .ForTimeMs(1500) |
| 90 .AtPercentOfEstimatedBitrate(20); | 92 .AtPercentOfEstimatedBitrate(20); |
| 91 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 93 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 92 | 94 |
| 93 // Verify that ALR ends when usage is above 65%. | 95 // Verify that ALR ends when usage is above 65%. |
| 94 SimulateOutgoingTrafficIn(&alr_detector_) | 96 SimulateOutgoingTrafficIn(&alr_detector_) |
| 95 .ForTimeMs(1000) | 97 .ForTimeMs(1000) |
| 96 .AtPercentOfEstimatedBitrate(100); | 98 .AtPercentOfEstimatedBitrate(100); |
| 97 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 99 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 98 } | 100 } |
| 99 | 101 |
| 100 TEST_F(AlrDetectorTest, ShortSpike) { | 102 TEST_F(AlrDetectorTest, ShortSpike) { |
| 101 // Start in non-ALR state. | 103 // Start in non-ALR state. |
| 102 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 104 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 103 | 105 |
| 104 // Verify that we ALR starts when bitrate drops below 20%. | 106 // Verify that we ALR starts when bitrate drops below 20%. |
| 105 SimulateOutgoingTrafficIn(&alr_detector_) | 107 SimulateOutgoingTrafficIn(&alr_detector_) |
| 106 .ForTimeMs(1000) | 108 .ForTimeMs(1000) |
| 107 .AtPercentOfEstimatedBitrate(20); | 109 .AtPercentOfEstimatedBitrate(20); |
| 108 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 110 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 109 | 111 |
| 110 // Verify that we stay in ALR region even after a short bitrate spike. | 112 // Verify that we stay in ALR region even after a short bitrate spike. |
| 111 SimulateOutgoingTrafficIn(&alr_detector_) | 113 SimulateOutgoingTrafficIn(&alr_detector_) |
| 112 .ForTimeMs(200) | 114 .ForTimeMs(100) |
| 113 .AtPercentOfEstimatedBitrate(150); | 115 .AtPercentOfEstimatedBitrate(150); |
| 114 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 116 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 115 | 117 |
| 116 // ALR ends when usage is above 65%. | 118 // ALR ends when usage is above 65%. |
| 117 SimulateOutgoingTrafficIn(&alr_detector_) | 119 SimulateOutgoingTrafficIn(&alr_detector_) |
| 118 .ForTimeMs(1000) | 120 .ForTimeMs(1000) |
| 119 .AtPercentOfEstimatedBitrate(100); | 121 .AtPercentOfEstimatedBitrate(100); |
| 120 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 122 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 121 } | 123 } |
| 122 | 124 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 135 // traffic. This is necessary to ensure that ProbeController can still react | 137 // traffic. This is necessary to ensure that ProbeController can still react |
| 136 // to the BWE drop by initiating a new probe. | 138 // to the BWE drop by initiating a new probe. |
| 137 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps / 5); | 139 alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps / 5); |
| 138 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 140 EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 139 SimulateOutgoingTrafficIn(&alr_detector_) | 141 SimulateOutgoingTrafficIn(&alr_detector_) |
| 140 .ForTimeMs(1000) | 142 .ForTimeMs(1000) |
| 141 .AtPercentOfEstimatedBitrate(50); | 143 .AtPercentOfEstimatedBitrate(50); |
| 142 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); | 144 EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime()); |
| 143 } | 145 } |
| 144 | 146 |
| 147 TEST(AlrStateTest, NotStateChangeWhenNoStartTimeProvided) { | |
| 148 AlrState alr_state; | |
| 149 EXPECT_FALSE(alr_state.HasChangedTo(AlrState::State::kNotInAlr)); | |
| 150 EXPECT_FALSE(alr_state.HasChangedTo(AlrState::State::kInAlr)); | |
| 151 } | |
| 152 | |
| 153 TEST(AlrStateTest, StateChangeToInAlr) { | |
| 154 AlrState alr_state; | |
| 155 alr_state.Update(rtc::Optional<int64_t>(10)); | |
| 156 EXPECT_FALSE(alr_state.HasChangedTo(AlrState::State::kNotInAlr)); | |
| 157 EXPECT_TRUE(alr_state.HasChangedTo(AlrState::State::kInAlr)); | |
| 158 } | |
| 159 | |
| 160 TEST(AlrStateTest, StateChangeToNotInAlr) { | |
| 161 AlrState alr_state; | |
| 162 alr_state.Update(rtc::Optional<int64_t>(10)); | |
| 163 alr_state.Update(rtc::Optional<int64_t>()); | |
| 164 EXPECT_TRUE(alr_state.HasChangedTo(AlrState::State::kNotInAlr)); | |
| 165 EXPECT_FALSE(alr_state.HasChangedTo(AlrState::State::kInAlr)); | |
| 166 } | |
| 167 | |
| 145 } // namespace webrtc | 168 } // namespace webrtc |
| OLD | NEW |