Commit 72bf30c4 authored by mikhal@chromium.org's avatar mikhal@chromium.org

Cast: Refactor CongestionControl to Clang format

This cl is pure style-targeted refactoring. 
No functional changes were made. 

BUG=339176

Review URL: https://codereview.chromium.org/149093008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247909 0039d316-1c4b-4281-b951-d872f2087c98
parent c09161c6
...@@ -31,6 +31,8 @@ class LocalRtcpAudioSenderFeedback : public RtcpSenderFeedback { ...@@ -31,6 +31,8 @@ class LocalRtcpAudioSenderFeedback : public RtcpSenderFeedback {
private: private:
AudioSender* audio_sender_; AudioSender* audio_sender_;
DISALLOW_IMPLICIT_CONSTRUCTORS(LocalRtcpAudioSenderFeedback);
}; };
class LocalRtpSenderStatistics : public RtpSenderStatistics { class LocalRtpSenderStatistics : public RtpSenderStatistics {
......
...@@ -37,8 +37,7 @@ CongestionControl::CongestionControl(base::TickClock* clock, ...@@ -37,8 +37,7 @@ CongestionControl::CongestionControl(base::TickClock* clock,
DCHECK_GE(start_bitrate, min_bitrate_configured) << "Invalid config"; DCHECK_GE(start_bitrate, min_bitrate_configured) << "Invalid config";
} }
CongestionControl::~CongestionControl() { CongestionControl::~CongestionControl() {}
}
bool CongestionControl::OnAck(base::TimeDelta rtt, uint32* new_bitrate) { bool CongestionControl::OnAck(base::TimeDelta rtt, uint32* new_bitrate) {
base::TimeTicks now = clock_->NowTicks(); base::TimeTicks now = clock_->NowTicks();
...@@ -50,31 +49,36 @@ bool CongestionControl::OnAck(base::TimeDelta rtt, uint32* new_bitrate) { ...@@ -50,31 +49,36 @@ bool CongestionControl::OnAck(base::TimeDelta rtt, uint32* new_bitrate) {
return false; return false;
} }
// Are we at the max bitrate? // Are we at the max bitrate?
if (max_bitrate_configured_ == bitrate_) return false; if (max_bitrate_configured_ == bitrate_)
return false;
// Make sure RTT is never less than 1 ms. // Make sure RTT is never less than 1 ms.
rtt = std::max(rtt, base::TimeDelta::FromMilliseconds(1)); rtt = std::max(rtt, base::TimeDelta::FromMilliseconds(1));
base::TimeDelta elapsed_time = std::min(now - time_last_increase_, base::TimeDelta elapsed_time =
base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs)); std::min(now - time_last_increase_,
base::TimeDelta change_interval = std::max(rtt, base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs));
base::TimeDelta change_interval = std::max(
rtt,
base::TimeDelta::FromMilliseconds(kCongestionControlMinChangeIntervalMs)); base::TimeDelta::FromMilliseconds(kCongestionControlMinChangeIntervalMs));
change_interval = std::min(change_interval, change_interval = std::min(
change_interval,
base::TimeDelta::FromMilliseconds(kCongestionControlMaxChangeIntervalMs)); base::TimeDelta::FromMilliseconds(kCongestionControlMaxChangeIntervalMs));
// Have enough time have passed? // Have enough time have passed?
if (elapsed_time < change_interval) return false; if (elapsed_time < change_interval)
return false;
time_last_increase_ = now; time_last_increase_ = now;
// One packet per RTT multiplied by the elapsed time fraction. // One packet per RTT multiplied by the elapsed time fraction.
// 1500 * 8 * (1000 / rtt_ms) * (elapsed_time_ms / 1000) => // 1500 * 8 * (1000 / rtt_ms) * (elapsed_time_ms / 1000) =>
// 1500 * 8 * elapsed_time_ms / rtt_ms. // 1500 * 8 * elapsed_time_ms / rtt_ms.
uint32 bitrate_increase = (1500 * 8 * elapsed_time.InMilliseconds()) / uint32 bitrate_increase =
rtt.InMilliseconds(); (1500 * 8 * elapsed_time.InMilliseconds()) / rtt.InMilliseconds();
uint32 max_bitrate_increase = uint32 max_bitrate_increase =
kCongestionControlMaxBitrateIncreasePerMillisecond * kCongestionControlMaxBitrateIncreasePerMillisecond *
elapsed_time.InMilliseconds(); elapsed_time.InMilliseconds();
bitrate_increase = std::min(max_bitrate_increase, bitrate_increase); bitrate_increase = std::min(max_bitrate_increase, bitrate_increase);
*new_bitrate = std::min(bitrate_increase + bitrate_, max_bitrate_configured_); *new_bitrate = std::min(bitrate_increase + bitrate_, max_bitrate_configured_);
bitrate_ = *new_bitrate; bitrate_ = *new_bitrate;
...@@ -90,22 +94,26 @@ bool CongestionControl::OnNack(base::TimeDelta rtt, uint32* new_bitrate) { ...@@ -90,22 +94,26 @@ bool CongestionControl::OnNack(base::TimeDelta rtt, uint32* new_bitrate) {
time_last_decrease_ = now; time_last_decrease_ = now;
return false; return false;
} }
base::TimeDelta elapsed_time = std::min(now - time_last_decrease_, base::TimeDelta elapsed_time =
base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs)); std::min(now - time_last_decrease_,
base::TimeDelta change_interval = std::max(rtt, base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs));
base::TimeDelta change_interval = std::max(
rtt,
base::TimeDelta::FromMilliseconds(kCongestionControlMinChangeIntervalMs)); base::TimeDelta::FromMilliseconds(kCongestionControlMinChangeIntervalMs));
change_interval = std::min(change_interval, change_interval = std::min(
change_interval,
base::TimeDelta::FromMilliseconds(kCongestionControlMaxChangeIntervalMs)); base::TimeDelta::FromMilliseconds(kCongestionControlMaxChangeIntervalMs));
// Have enough time have passed? // Have enough time have passed?
if (elapsed_time < change_interval) return false; if (elapsed_time < change_interval)
return false;
time_last_decrease_ = now; time_last_decrease_ = now;
time_last_increase_ = now; time_last_increase_ = now;
*new_bitrate = std::max( *new_bitrate =
static_cast<uint32>(bitrate_ * congestion_control_back_off_), std::max(static_cast<uint32>(bitrate_ * congestion_control_back_off_),
min_bitrate_configured_); min_bitrate_configured_);
bitrate_ = *new_bitrate; bitrate_ = *new_bitrate;
return true; return true;
......
...@@ -30,7 +30,6 @@ class CongestionControl { ...@@ -30,7 +30,6 @@ class CongestionControl {
// Returns true if the bitrate have changed. // Returns true if the bitrate have changed.
bool OnNack(base::TimeDelta rtt_ms, uint32* new_bitrate); bool OnNack(base::TimeDelta rtt_ms, uint32* new_bitrate);
private: private:
base::TickClock* const clock_; // Not owned by this class. base::TickClock* const clock_; // Not owned by this class.
const float congestion_control_back_off_; const float congestion_control_back_off_;
......
...@@ -30,7 +30,8 @@ class CongestionControlTest : public ::testing::Test { ...@@ -30,7 +30,8 @@ class CongestionControlTest : public ::testing::Test {
} }
// Returns the last bitrate of the run. // Returns the last bitrate of the run.
uint32 RunWithOneLossEventPerSecond(int fps, int rtt_ms, uint32 RunWithOneLossEventPerSecond(int fps,
int rtt_ms,
int runtime_in_seconds) { int runtime_in_seconds) {
const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(rtt_ms); const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(rtt_ms);
const base::TimeDelta ack_rate = const base::TimeDelta ack_rate =
...@@ -50,6 +51,8 @@ class CongestionControlTest : public ::testing::Test { ...@@ -50,6 +51,8 @@ class CongestionControlTest : public ::testing::Test {
base::SimpleTestTickClock testing_clock_; base::SimpleTestTickClock testing_clock_;
CongestionControl congestion_control_; CongestionControl congestion_control_;
DISALLOW_COPY_AND_ASSIGN(CongestionControlTest);
}; };
TEST_F(CongestionControlTest, Max) { TEST_F(CongestionControlTest, Max) {
...@@ -98,7 +101,7 @@ TEST_F(CongestionControlTest, Min) { ...@@ -98,7 +101,7 @@ TEST_F(CongestionControlTest, Min) {
TEST_F(CongestionControlTest, Timing) { TEST_F(CongestionControlTest, Timing) {
const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(kRttMs); const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(kRttMs);
const base::TimeDelta ack_rate = const base::TimeDelta ack_rate =
base::TimeDelta::FromMilliseconds(kAckRateMs); base::TimeDelta::FromMilliseconds(kAckRateMs);
uint32 new_bitrate = 0; uint32 new_bitrate = 0;
uint32 expected_bitrate = kStartBitrate; uint32 expected_bitrate = kStartBitrate;
...@@ -111,8 +114,8 @@ TEST_F(CongestionControlTest, Timing) { ...@@ -111,8 +114,8 @@ TEST_F(CongestionControlTest, Timing) {
// We should back immediately. // We should back immediately.
EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
expected_bitrate = static_cast<uint32>( expected_bitrate =
expected_bitrate * kDefaultCongestionControlBackOff); static_cast<uint32>(expected_bitrate * kDefaultCongestionControlBackOff);
EXPECT_EQ(expected_bitrate, new_bitrate); EXPECT_EQ(expected_bitrate, new_bitrate);
// Less than one RTT have passed don't back again. // Less than one RTT have passed don't back again.
...@@ -121,8 +124,8 @@ TEST_F(CongestionControlTest, Timing) { ...@@ -121,8 +124,8 @@ TEST_F(CongestionControlTest, Timing) {
testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate)); EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
expected_bitrate = static_cast<uint32>( expected_bitrate =
expected_bitrate * kDefaultCongestionControlBackOff); static_cast<uint32>(expected_bitrate * kDefaultCongestionControlBackOff);
EXPECT_EQ(expected_bitrate, new_bitrate); EXPECT_EQ(expected_bitrate, new_bitrate);
testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
...@@ -162,8 +165,7 @@ TEST_F(CongestionControlTest, Convergence24fps) { ...@@ -162,8 +165,7 @@ TEST_F(CongestionControlTest, Convergence24fps) {
} }
TEST_F(CongestionControlTest, Convergence24fpsLongRtt) { TEST_F(CongestionControlTest, Convergence24fpsLongRtt) {
EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100), EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100), GG_UINT32_C(500000));
GG_UINT32_C(500000));
} }
TEST_F(CongestionControlTest, Convergence60fps) { TEST_F(CongestionControlTest, Convergence60fps) {
...@@ -172,8 +174,7 @@ TEST_F(CongestionControlTest, Convergence60fps) { ...@@ -172,8 +174,7 @@ TEST_F(CongestionControlTest, Convergence60fps) {
} }
TEST_F(CongestionControlTest, Convergence60fpsLongRtt) { TEST_F(CongestionControlTest, Convergence60fpsLongRtt) {
EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100), EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100), GG_UINT32_C(500000));
GG_UINT32_C(500000));
} }
} // namespace cast } // namespace cast
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment