Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/aimd_rate_control_unittest.cc

Issue 2380883003: Add interval estimator to remote bitrate estimator (Closed)
Patch Set: Simplify probing estimator. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10 #include <memory>
11
12 #include "webrtc/modules/audio_coding/audio_network_adaptor/smoothing_filter.h"
13 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h"
14 #include "webrtc/test/gtest.h"
15
16 namespace webrtc {
17 namespace {
18
19 // constexpr int kTimeConstantMs = 1000;
20 // constexpr float kMaxAbsError = 0.0001f;
21 constexpr int64_t kClockInitialTime = 123456;
22
23 struct AimdRateControlStates {
24 std::unique_ptr<AimdRateControl> aimd_rate_control;
25 std::unique_ptr<SimulatedClock> simulated_clock;
26 };
27
28 AimdRateControlStates CreateAimdRateControlStates() {
29 AimdRateControlStates states;
30 states.aimd_rate_control.reset(new AimdRateControl());
31 states.simulated_clock.reset(new SimulatedClock(kClockInitialTime));
32 return states;
33 }
34
35 void InitToBitrate(const AimdRateControlStates& states,
36 int bitrate,
37 int64_t now_ms) {
38 states.aimd_rate_control->SetEstimate(bitrate, now_ms);
39 }
40
41 void UpdateRateControl(const AimdRateControlStates& states,
42 const BandwidthUsage& bandwidth_usage,
43 int bitrate,
44 int64_t now_ms) {
45 RateControlInput input(bandwidth_usage, rtc::Optional<uint32_t>(bitrate),
46 now_ms);
47 states.aimd_rate_control->Update(&input, now_ms);
48 states.aimd_rate_control->UpdateBandwidthEstimate(now_ms);
49 }
50
51 } // namespace
52
53 TEST(AimdRateControlTest, UnknownNearMaxIncreaseRateBeforeFirstOveruse) {
54 auto aimd_rate_control_states = CreateAimdRateControlStates();
55 EXPECT_EQ(
56 rtc::Optional<int>(),
57 aimd_rate_control_states.aimd_rate_control->GetNearMaxIncreaseRate());
58 }
59
60 TEST(AimdRateControlTest, NearMaxIncreaseRateOnIntervalOf200ms) {
61 auto states = CreateAimdRateControlStates();
62 constexpr int kBitrate = 300000;
63 InitToBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds());
64 UpdateRateControl(states, kBwOverusing, kBitrate,
65 states.simulated_clock->TimeInMilliseconds());
66 UpdateRateControl(states, kBwNormal, kBitrate,
67 states.simulated_clock->TimeInMilliseconds());
68 states.simulated_clock->AdvanceTimeMilliseconds(200);
69 UpdateRateControl(states, kBwNormal, kBitrate,
70 states.simulated_clock->TimeInMilliseconds());
71 EXPECT_EQ(rtc::Optional<int>(14220),
72 states.aimd_rate_control->GetNearMaxIncreaseRate());
73 }
74
75 TEST(AimdRateControlTest,
76 DontUpdateNearMaxIncreaseRateWhenLastStateWasNotNearMax) {
77 auto states = CreateAimdRateControlStates();
78 constexpr int kBitrate = 300000;
79 InitToBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds());
80 UpdateRateControl(states, kBwOverusing, kBitrate,
81 states.simulated_clock->TimeInMilliseconds());
82 UpdateRateControl(states, kBwNormal, kBitrate,
83 states.simulated_clock->TimeInMilliseconds());
84 states.simulated_clock->AdvanceTimeMilliseconds(200);
85 UpdateRateControl(states, kBwNormal, kBitrate,
86 states.simulated_clock->TimeInMilliseconds());
87 UpdateRateControl(states, kBwOverusing, kBitrate,
88 states.simulated_clock->TimeInMilliseconds());
89 UpdateRateControl(states, kBwNormal, kBitrate - 200000,
90 states.simulated_clock->TimeInMilliseconds());
91 EXPECT_EQ(rtc::Optional<int>(14220),
92 states.aimd_rate_control->GetNearMaxIncreaseRate());
93 }
94
95 TEST(AimdRateControlTest, UnknownDropHightBeforeFirstOveruse) {
96 auto states = CreateAimdRateControlStates();
97 EXPECT_EQ(rtc::Optional<int>(), states.aimd_rate_control->GetLastDecrease());
98 }
99
100 TEST(AimdRateControlTest, GetLastBitrateDrop) {
101 auto states = CreateAimdRateControlStates();
102 constexpr int kBitrate = 300000;
103 InitToBitrate(states, kBitrate, states.simulated_clock->TimeInMilliseconds());
104 UpdateRateControl(states, kBwOverusing, kBitrate,
105 states.simulated_clock->TimeInMilliseconds());
106 EXPECT_EQ(rtc::Optional<int>(46000),
107 states.aimd_rate_control->GetLastDecrease());
108 }
109
110 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698