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

Side by Side Diff: media/cast/congestion_control/congestion_control_unittest.cc

Issue 149093008: Cast:Refactor CongestionControl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « media/cast/congestion_control/congestion_control.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/simple_test_tick_clock.h" 5 #include "base/test/simple_test_tick_clock.h"
6 #include "media/cast/cast_defines.h" 6 #include "media/cast/cast_defines.h"
7 #include "media/cast/congestion_control/congestion_control.h" 7 #include "media/cast/congestion_control/congestion_control.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 12 matching lines...) Expand all
23 : congestion_control_(&testing_clock_, 23 : congestion_control_(&testing_clock_,
24 kDefaultCongestionControlBackOff, 24 kDefaultCongestionControlBackOff,
25 kMaxBitrateConfigured, 25 kMaxBitrateConfigured,
26 kMinBitrateConfigured, 26 kMinBitrateConfigured,
27 kStartBitrate) { 27 kStartBitrate) {
28 testing_clock_.Advance( 28 testing_clock_.Advance(
29 base::TimeDelta::FromMilliseconds(kStartMillisecond)); 29 base::TimeDelta::FromMilliseconds(kStartMillisecond));
30 } 30 }
31 31
32 // Returns the last bitrate of the run. 32 // Returns the last bitrate of the run.
33 uint32 RunWithOneLossEventPerSecond(int fps, int rtt_ms, 33 uint32 RunWithOneLossEventPerSecond(int fps,
34 int rtt_ms,
34 int runtime_in_seconds) { 35 int runtime_in_seconds) {
35 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(rtt_ms); 36 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(rtt_ms);
36 const base::TimeDelta ack_rate = 37 const base::TimeDelta ack_rate =
37 base::TimeDelta::FromMilliseconds(GG_INT64_C(1000) / fps); 38 base::TimeDelta::FromMilliseconds(GG_INT64_C(1000) / fps);
38 uint32 new_bitrate = 0; 39 uint32 new_bitrate = 0;
39 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); 40 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate));
40 41
41 for (int seconds = 0; seconds < runtime_in_seconds; ++seconds) { 42 for (int seconds = 0; seconds < runtime_in_seconds; ++seconds) {
42 for (int i = 1; i < fps; ++i) { 43 for (int i = 1; i < fps; ++i) {
43 testing_clock_.Advance(ack_rate); 44 testing_clock_.Advance(ack_rate);
44 congestion_control_.OnAck(rtt, &new_bitrate); 45 congestion_control_.OnAck(rtt, &new_bitrate);
45 } 46 }
46 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); 47 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
47 } 48 }
48 return new_bitrate; 49 return new_bitrate;
49 } 50 }
50 51
51 base::SimpleTestTickClock testing_clock_; 52 base::SimpleTestTickClock testing_clock_;
52 CongestionControl congestion_control_; 53 CongestionControl congestion_control_;
54
55 DISALLOW_COPY_AND_ASSIGN(CongestionControlTest);
53 }; 56 };
54 57
55 TEST_F(CongestionControlTest, Max) { 58 TEST_F(CongestionControlTest, Max) {
56 uint32 new_bitrate = 0; 59 uint32 new_bitrate = 0;
57 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(kRttMs); 60 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(kRttMs);
58 const base::TimeDelta ack_rate = 61 const base::TimeDelta ack_rate =
59 base::TimeDelta::FromMilliseconds(kAckRateMs); 62 base::TimeDelta::FromMilliseconds(kAckRateMs);
60 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); 63 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate));
61 64
62 uint32 expected_increase_bitrate = 0; 65 uint32 expected_increase_bitrate = 0;
(...skipping 28 matching lines...) Expand all
91 EXPECT_EQ(expected_decrease_bitrate, new_bitrate); 94 EXPECT_EQ(expected_decrease_bitrate, new_bitrate);
92 } 95 }
93 testing_clock_.Advance(ack_rate); 96 testing_clock_.Advance(ack_rate);
94 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); 97 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
95 EXPECT_EQ(kMinBitrateConfigured, new_bitrate); 98 EXPECT_EQ(kMinBitrateConfigured, new_bitrate);
96 } 99 }
97 100
98 TEST_F(CongestionControlTest, Timing) { 101 TEST_F(CongestionControlTest, Timing) {
99 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(kRttMs); 102 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(kRttMs);
100 const base::TimeDelta ack_rate = 103 const base::TimeDelta ack_rate =
101 base::TimeDelta::FromMilliseconds(kAckRateMs); 104 base::TimeDelta::FromMilliseconds(kAckRateMs);
102 uint32 new_bitrate = 0; 105 uint32 new_bitrate = 0;
103 uint32 expected_bitrate = kStartBitrate; 106 uint32 expected_bitrate = kStartBitrate;
104 107
105 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); 108 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate));
106 109
107 testing_clock_.Advance(ack_rate); 110 testing_clock_.Advance(ack_rate);
108 EXPECT_TRUE(congestion_control_.OnAck(rtt, &new_bitrate)); 111 EXPECT_TRUE(congestion_control_.OnAck(rtt, &new_bitrate));
109 expected_bitrate += 1500 * 8 * kAckRateMs / kRttMs; 112 expected_bitrate += 1500 * 8 * kAckRateMs / kRttMs;
110 EXPECT_EQ(expected_bitrate, new_bitrate); 113 EXPECT_EQ(expected_bitrate, new_bitrate);
111 114
112 // We should back immediately. 115 // We should back immediately.
113 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); 116 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
114 expected_bitrate = static_cast<uint32>( 117 expected_bitrate =
115 expected_bitrate * kDefaultCongestionControlBackOff); 118 static_cast<uint32>(expected_bitrate * kDefaultCongestionControlBackOff);
116 EXPECT_EQ(expected_bitrate, new_bitrate); 119 EXPECT_EQ(expected_bitrate, new_bitrate);
117 120
118 // Less than one RTT have passed don't back again. 121 // Less than one RTT have passed don't back again.
119 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); 122 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
120 EXPECT_FALSE(congestion_control_.OnNack(rtt, &new_bitrate)); 123 EXPECT_FALSE(congestion_control_.OnNack(rtt, &new_bitrate));
121 124
122 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); 125 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
123 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); 126 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
124 expected_bitrate = static_cast<uint32>( 127 expected_bitrate =
125 expected_bitrate * kDefaultCongestionControlBackOff); 128 static_cast<uint32>(expected_bitrate * kDefaultCongestionControlBackOff);
126 EXPECT_EQ(expected_bitrate, new_bitrate); 129 EXPECT_EQ(expected_bitrate, new_bitrate);
127 130
128 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); 131 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
129 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); 132 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate));
130 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); 133 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
131 EXPECT_TRUE(congestion_control_.OnAck(rtt, &new_bitrate)); 134 EXPECT_TRUE(congestion_control_.OnAck(rtt, &new_bitrate));
132 expected_bitrate += 1500 * 8 * 20 / kRttMs; 135 expected_bitrate += 1500 * 8 * 20 / kRttMs;
133 EXPECT_EQ(expected_bitrate, new_bitrate); 136 EXPECT_EQ(expected_bitrate, new_bitrate);
134 137
135 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); 138 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
(...skipping 19 matching lines...) Expand all
155 expected_bitrate += 1500 * 8 * 20 / kRttMs; 158 expected_bitrate += 1500 * 8 * 20 / kRttMs;
156 EXPECT_EQ(expected_bitrate, new_bitrate); 159 EXPECT_EQ(expected_bitrate, new_bitrate);
157 } 160 }
158 161
159 TEST_F(CongestionControlTest, Convergence24fps) { 162 TEST_F(CongestionControlTest, Convergence24fps) {
160 EXPECT_GE(RunWithOneLossEventPerSecond(24, kRttMs, 100), 163 EXPECT_GE(RunWithOneLossEventPerSecond(24, kRttMs, 100),
161 GG_UINT32_C(3000000)); 164 GG_UINT32_C(3000000));
162 } 165 }
163 166
164 TEST_F(CongestionControlTest, Convergence24fpsLongRtt) { 167 TEST_F(CongestionControlTest, Convergence24fpsLongRtt) {
165 EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100), 168 EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100), GG_UINT32_C(500000));
166 GG_UINT32_C(500000));
167 } 169 }
168 170
169 TEST_F(CongestionControlTest, Convergence60fps) { 171 TEST_F(CongestionControlTest, Convergence60fps) {
170 EXPECT_GE(RunWithOneLossEventPerSecond(60, kRttMs, 100), 172 EXPECT_GE(RunWithOneLossEventPerSecond(60, kRttMs, 100),
171 GG_UINT32_C(3500000)); 173 GG_UINT32_C(3500000));
172 } 174 }
173 175
174 TEST_F(CongestionControlTest, Convergence60fpsLongRtt) { 176 TEST_F(CongestionControlTest, Convergence60fpsLongRtt) {
175 EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100), 177 EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100), GG_UINT32_C(500000));
176 GG_UINT32_C(500000));
177 } 178 }
178 179
179 } // namespace cast 180 } // namespace cast
180 } // namespace media 181 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/congestion_control/congestion_control.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698