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 {
private:
AudioSender* audio_sender_;
DISALLOW_IMPLICIT_CONSTRUCTORS(LocalRtcpAudioSenderFeedback);
};
class LocalRtpSenderStatistics : public RtpSenderStatistics {
......
......@@ -37,8 +37,7 @@ CongestionControl::CongestionControl(base::TickClock* clock,
DCHECK_GE(start_bitrate, min_bitrate_configured) << "Invalid config";
}
CongestionControl::~CongestionControl() {
}
CongestionControl::~CongestionControl() {}
bool CongestionControl::OnAck(base::TimeDelta rtt, uint32* new_bitrate) {
base::TimeTicks now = clock_->NowTicks();
......@@ -50,31 +49,36 @@ bool CongestionControl::OnAck(base::TimeDelta rtt, uint32* new_bitrate) {
return false;
}
// 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.
rtt = std::max(rtt, base::TimeDelta::FromMilliseconds(1));
base::TimeDelta elapsed_time = std::min(now - time_last_increase_,
base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs));
base::TimeDelta change_interval = std::max(rtt,
base::TimeDelta elapsed_time =
std::min(now - time_last_increase_,
base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs));
base::TimeDelta change_interval = std::max(
rtt,
base::TimeDelta::FromMilliseconds(kCongestionControlMinChangeIntervalMs));
change_interval = std::min(change_interval,
change_interval = std::min(
change_interval,
base::TimeDelta::FromMilliseconds(kCongestionControlMaxChangeIntervalMs));
// Have enough time have passed?
if (elapsed_time < change_interval) return false;
if (elapsed_time < change_interval)
return false;
time_last_increase_ = now;
// One packet per RTT multiplied by the elapsed time fraction.
// 1500 * 8 * (1000 / rtt_ms) * (elapsed_time_ms / 1000) =>
// 1500 * 8 * elapsed_time_ms / rtt_ms.
uint32 bitrate_increase = (1500 * 8 * elapsed_time.InMilliseconds()) /
rtt.InMilliseconds();
uint32 bitrate_increase =
(1500 * 8 * elapsed_time.InMilliseconds()) / rtt.InMilliseconds();
uint32 max_bitrate_increase =
kCongestionControlMaxBitrateIncreasePerMillisecond *
elapsed_time.InMilliseconds();
elapsed_time.InMilliseconds();
bitrate_increase = std::min(max_bitrate_increase, bitrate_increase);
*new_bitrate = std::min(bitrate_increase + bitrate_, max_bitrate_configured_);
bitrate_ = *new_bitrate;
......@@ -90,22 +94,26 @@ bool CongestionControl::OnNack(base::TimeDelta rtt, uint32* new_bitrate) {
time_last_decrease_ = now;
return false;
}
base::TimeDelta elapsed_time = std::min(now - time_last_decrease_,
base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs));
base::TimeDelta change_interval = std::max(rtt,
base::TimeDelta elapsed_time =
std::min(now - time_last_decrease_,
base::TimeDelta::FromMilliseconds(kMaxElapsedTimeMs));
base::TimeDelta change_interval = std::max(
rtt,
base::TimeDelta::FromMilliseconds(kCongestionControlMinChangeIntervalMs));
change_interval = std::min(change_interval,
change_interval = std::min(
change_interval,
base::TimeDelta::FromMilliseconds(kCongestionControlMaxChangeIntervalMs));
// 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_increase_ = now;
*new_bitrate = std::max(
static_cast<uint32>(bitrate_ * congestion_control_back_off_),
min_bitrate_configured_);
*new_bitrate =
std::max(static_cast<uint32>(bitrate_ * congestion_control_back_off_),
min_bitrate_configured_);
bitrate_ = *new_bitrate;
return true;
......
......@@ -30,7 +30,6 @@ class CongestionControl {
// Returns true if the bitrate have changed.
bool OnNack(base::TimeDelta rtt_ms, uint32* new_bitrate);
private:
base::TickClock* const clock_; // Not owned by this class.
const float congestion_control_back_off_;
......
......@@ -30,7 +30,8 @@ class CongestionControlTest : public ::testing::Test {
}
// 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) {
const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(rtt_ms);
const base::TimeDelta ack_rate =
......@@ -50,6 +51,8 @@ class CongestionControlTest : public ::testing::Test {
base::SimpleTestTickClock testing_clock_;
CongestionControl congestion_control_;
DISALLOW_COPY_AND_ASSIGN(CongestionControlTest);
};
TEST_F(CongestionControlTest, Max) {
......@@ -98,7 +101,7 @@ TEST_F(CongestionControlTest, Min) {
TEST_F(CongestionControlTest, Timing) {
const base::TimeDelta rtt = base::TimeDelta::FromMilliseconds(kRttMs);
const base::TimeDelta ack_rate =
base::TimeDelta::FromMilliseconds(kAckRateMs);
base::TimeDelta::FromMilliseconds(kAckRateMs);
uint32 new_bitrate = 0;
uint32 expected_bitrate = kStartBitrate;
......@@ -111,8 +114,8 @@ TEST_F(CongestionControlTest, Timing) {
// We should back immediately.
EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
expected_bitrate = static_cast<uint32>(
expected_bitrate * kDefaultCongestionControlBackOff);
expected_bitrate =
static_cast<uint32>(expected_bitrate * kDefaultCongestionControlBackOff);
EXPECT_EQ(expected_bitrate, new_bitrate);
// Less than one RTT have passed don't back again.
......@@ -121,8 +124,8 @@ TEST_F(CongestionControlTest, Timing) {
testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
EXPECT_TRUE(congestion_control_.OnNack(rtt, &new_bitrate));
expected_bitrate = static_cast<uint32>(
expected_bitrate * kDefaultCongestionControlBackOff);
expected_bitrate =
static_cast<uint32>(expected_bitrate * kDefaultCongestionControlBackOff);
EXPECT_EQ(expected_bitrate, new_bitrate);
testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
......@@ -162,8 +165,7 @@ TEST_F(CongestionControlTest, Convergence24fps) {
}
TEST_F(CongestionControlTest, Convergence24fpsLongRtt) {
EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100),
GG_UINT32_C(500000));
EXPECT_GE(RunWithOneLossEventPerSecond(24, 100, 100), GG_UINT32_C(500000));
}
TEST_F(CongestionControlTest, Convergence60fps) {
......@@ -172,8 +174,7 @@ TEST_F(CongestionControlTest, Convergence60fps) {
}
TEST_F(CongestionControlTest, Convergence60fpsLongRtt) {
EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100),
GG_UINT32_C(500000));
EXPECT_GE(RunWithOneLossEventPerSecond(60, 100, 100), GG_UINT32_C(500000));
}
} // 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