| OLD | NEW |
| 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 <stdint.h> |
| 6 |
| 5 #include "base/test/simple_test_tick_clock.h" | 7 #include "base/test/simple_test_tick_clock.h" |
| 6 #include "media/cast/cast_defines.h" | 8 #include "media/cast/cast_defines.h" |
| 7 #include "media/cast/congestion_control/congestion_control.h" | 9 #include "media/cast/congestion_control/congestion_control.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 11 |
| 10 namespace media { | 12 namespace media { |
| 11 namespace cast { | 13 namespace cast { |
| 12 | 14 |
| 13 static const uint32 kMaxBitrateConfigured = 5000000; | 15 static const uint32 kMaxBitrateConfigured = 5000000; |
| 14 static const uint32 kMinBitrateConfigured = 500000; | 16 static const uint32 kMinBitrateConfigured = 500000; |
| 15 static const uint32 kStartBitrate = 2000000; | 17 static const uint32 kStartBitrate = 2000000; |
| 16 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); | 18 static const int64 kStartMillisecond = INT64_C(12345678900000); |
| 17 static const int64 kRttMs = 20; | 19 static const int64 kRttMs = 20; |
| 18 static const int64 kAckRateMs = 33; | 20 static const int64 kAckRateMs = 33; |
| 19 | 21 |
| 20 class CongestionControlTest : public ::testing::Test { | 22 class CongestionControlTest : public ::testing::Test { |
| 21 protected: | 23 protected: |
| 22 CongestionControlTest() | 24 CongestionControlTest() |
| 23 : congestion_control_(&testing_clock_, | 25 : congestion_control_(&testing_clock_, |
| 24 kDefaultCongestionControlBackOff, | 26 kDefaultCongestionControlBackOff, |
| 25 kMaxBitrateConfigured, | 27 kMaxBitrateConfigured, |
| 26 kMinBitrateConfigured, | 28 kMinBitrateConfigured, |
| 27 kStartBitrate) { | 29 kStartBitrate) { |
| 28 testing_clock_.Advance( | 30 testing_clock_.Advance( |
| 29 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 31 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
| 30 } | 32 } |
| 31 | 33 |
| 32 // Returns the last bitrate of the run. | 34 // Returns the last bitrate of the run. |
| 33 uint32 RunWithOneLossEventPerSecond(int fps, | 35 uint32 RunWithOneLossEventPerSecond(int fps, |
| 34 int rtt_ms, | 36 int rtt_ms, |
| 35 int runtime_in_seconds) { | 37 int runtime_in_seconds) { |
| 36 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(rtt_ms); | 38 const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(rtt_ms); |
| 37 const base::TimeDelta ack_rate = | 39 const base::TimeDelta ack_rate = |
| 38 base::TimeDelta::FromMilliseconds(GG_INT64_C(1000) / fps); | 40 base::TimeDelta::FromMilliseconds(INT64_C(1000) / fps); |
| 39 uint32 new_bitrate = 0; | 41 uint32 new_bitrate = 0; |
| 40 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); | 42 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); |
| 41 | 43 |
| 42 for (int seconds = 0; seconds < runtime_in_seconds; ++seconds) { | 44 for (int seconds = 0; seconds < runtime_in_seconds; ++seconds) { |
| 43 for (int i = 1; i < fps; ++i) { | 45 for (int i = 1; i < fps; ++i) { |
| 44 testing_clock_.Advance(ack_rate); | 46 testing_clock_.Advance(ack_rate); |
| 45 congestion_control_.OnAck(rtt, &new_bitrate); | 47 congestion_control_.OnAck(rtt, &new_bitrate); |
| 46 } | 48 } |
| 47 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); | 49 EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); |
| 48 } | 50 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(1)); | 155 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(1)); |
| 154 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); | 156 EXPECT_FALSE(congestion_control_.OnAck(rtt, &new_bitrate)); |
| 155 } | 157 } |
| 156 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(1)); | 158 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(1)); |
| 157 EXPECT_TRUE(congestion_control_.OnAck(rtt, &new_bitrate)); | 159 EXPECT_TRUE(congestion_control_.OnAck(rtt, &new_bitrate)); |
| 158 expected_bitrate += 1500 * 8 * 20 / kRttMs; | 160 expected_bitrate += 1500 * 8 * 20 / kRttMs; |
| 159 EXPECT_EQ(expected_bitrate, new_bitrate); | 161 EXPECT_EQ(expected_bitrate, new_bitrate); |
| 160 } | 162 } |
| 161 | 163 |
| 162 TEST_F(CongestionControlTest, Convergence24fps) { | 164 TEST_F(CongestionControlTest, Convergence24fps) { |
| 163 EXPECT_GE(RunWithOneLossEventPerSecond(24, kRttMs, 100), | 165 EXPECT_GE(RunWithOneLossEventPerSecond(24, kRttMs, 100), UINT32_C(3000000)); |
| 164 GG_UINT32_C(3000000)); | |
| 165 } | 166 } |
| 166 | 167 |
| 167 TEST_F(CongestionControlTest, Convergence24fpsLongRtt) { | 168 TEST_F(CongestionControlTest, Convergence24fpsLongRtt) { |
| 168 EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100), GG_UINT32_C(500000)); | 169 EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100), UINT32_C(500000)); |
| 169 } | 170 } |
| 170 | 171 |
| 171 TEST_F(CongestionControlTest, Convergence60fps) { | 172 TEST_F(CongestionControlTest, Convergence60fps) { |
| 172 EXPECT_GE(RunWithOneLossEventPerSecond(60, kRttMs, 100), | 173 EXPECT_GE(RunWithOneLossEventPerSecond(60, kRttMs, 100), UINT32_C(3500000)); |
| 173 GG_UINT32_C(3500000)); | |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST_F(CongestionControlTest, Convergence60fpsLongRtt) { | 176 TEST_F(CongestionControlTest, Convergence60fpsLongRtt) { |
| 177 EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100), GG_UINT32_C(500000)); | 177 EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100), UINT32_C(500000)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace cast | 180 } // namespace cast |
| 181 } // namespace media | 181 } // namespace media |
| OLD | NEW |