Chromium Code Reviews| Index: webrtc/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc |
| diff --git a/webrtc/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc b/webrtc/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22a63732eb841cf15ed6b75238b2b2b26948a673 |
| --- /dev/null |
| +++ b/webrtc/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc |
| @@ -0,0 +1,93 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| +#include <memory> |
| + |
| +#include "webrtc/modules/audio_coding/audio_network_adaptor/smoothing_filter.h" |
| +#include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
| +#include "webrtc/test/gtest.h" |
| + |
| +namespace webrtc { |
| +namespace { |
| + |
| +// constexpr int kTimeConstantMs = 1000; |
|
minyue-webrtc
2016/11/14 16:50:42
can we remove these commented lines
michaelt
2016/11/15 09:41:59
sure :)
|
| +// constexpr float kMaxAbsError = 0.0001f; |
| +constexpr int64_t kClockInitialTime = 123456; |
| + |
| +struct AimdRateControlStates { |
| + std::unique_ptr<AimdRateControl> aimd_rate_control; |
| + std::unique_ptr<SimulatedClock> simulated_clock; |
| +}; |
| + |
| +AimdRateControlStates CreateAimdRateControlStates() { |
| + AimdRateControlStates states; |
| + states.aimd_rate_control.reset(new AimdRateControl()); |
| + states.simulated_clock.reset(new SimulatedClock(kClockInitialTime)); |
| + return states; |
| +} |
| + |
| +void InitToBitrate(const AimdRateControlStates& states, |
|
minyue-webrtc
2016/11/14 16:50:42
InitBitrate?
michaelt
2016/11/15 09:41:59
Done.
|
| + int bitrate, |
| + int64_t now_ms) { |
| + // Reduce the bitrate by 1000 to compensate for the Update after SetEstimate. |
| + bitrate -= 1000; |
| + |
| + states.aimd_rate_control->SetEstimate(bitrate, now_ms); |
| +} |
| + |
| +void UpdateRateControl(const AimdRateControlStates& states, |
| + const BandwidthUsage& bandwidth_usage, |
| + int bitrate, |
| + int64_t now_ms) { |
| + RateControlInput input(bandwidth_usage, rtc::Optional<uint32_t>(bitrate), |
| + now_ms); |
| + states.aimd_rate_control->Update(&input, now_ms); |
| + states.aimd_rate_control->UpdateBandwidthEstimate(now_ms); |
| +} |
| + |
| +} // namespace |
| + |
| +TEST(AimdRateControlTest, MinNearMaxIncreaseRateOnLowBandwith) { |
| + auto states = CreateAimdRateControlStates(); |
| + constexpr int kBitrate = 30000; |
| + InitToBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); |
| + EXPECT_EQ(4000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); |
| +} |
| + |
| +TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn90kbpsAn200msRtt) { |
|
minyue-webrtc
2016/11/14 16:50:42
An->And
michaelt
2016/11/15 09:41:59
Done.
|
| + auto states = CreateAimdRateControlStates(); |
| + constexpr int kBitrate = 90000; |
| + InitToBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); |
| + EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); |
| +} |
| + |
| +TEST(AimdRateControlTest, NearMaxIncreaseRateIs5kbpsOn60kbpsAn100msRtt) { |
|
minyue-webrtc
2016/11/14 16:50:42
An->And
michaelt
2016/11/15 09:41:59
Done.
|
| + auto states = CreateAimdRateControlStates(); |
| + constexpr int kBitrate = 60000; |
| + InitToBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); |
| + states.aimd_rate_control->SetRtt(100); |
| + EXPECT_EQ(5000, states.aimd_rate_control->GetNearMaxIncreaseRateBps()); |
| +} |
| + |
| +TEST(AimdRateControlTest, UnknownDropHightBeforeFirstOveruse) { |
|
minyue-webrtc
2016/11/14 16:50:42
Hight -> Height or maybe even rename to "UnknownBi
michaelt
2016/11/15 09:41:59
Done.
|
| + auto states = CreateAimdRateControlStates(); |
| + EXPECT_EQ(rtc::Optional<int>(), states.aimd_rate_control->GetLastDecrease()); |
| +} |
| + |
| +TEST(AimdRateControlTest, GetLastBitrateDrop) { |
| + auto states = CreateAimdRateControlStates(); |
| + constexpr int kBitrate = 300000; |
| + InitToBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds()); |
| + UpdateRateControl(states, kBwOverusing, kBitrate - 2000, |
| + states.simulated_clock->TimeInMilliseconds()); |
| + EXPECT_EQ(rtc::Optional<int>(46700), |
| + states.aimd_rate_control->GetLastDecrease()); |
| +} |
| + |
| +} // namespace webrtc |