Merge UpdateBandwidthEstimate with Update in AimdRateControl.

(The two functions are always called together anyway.)

BUG=None

Review-Url: https://codereview.webrtc.org/2784333005
Cr-Commit-Position: refs/heads/master@{#17502}
This commit is contained in:
terelius 2017-04-03 02:27:08 -07:00 committed by Commit bot
parent 97a7fb0eb7
commit d1b0e0e6db
6 changed files with 21 additions and 48 deletions

View File

@ -322,8 +322,7 @@ bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms,
// TODO(terelius): RateControlInput::noise_var is deprecated and will be
// removed. In the meantime, we set it to zero.
const RateControlInput input(detector_.State(), acked_bitrate_bps, 0);
rate_control_.Update(&input, now_ms);
*target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms);
*target_bitrate_bps = rate_control_.Update(&input, now_ms);
return rate_control_.ValidEstimate();
}

View File

@ -35,8 +35,6 @@ AimdRateControl::AimdRateControl()
rate_control_state_(kRcHold),
rate_control_region_(kRcMaxUnknown),
time_last_bitrate_change_(-1),
current_input_(kBwNormal, rtc::Optional<uint32_t>(), 1.0),
updated_(false),
time_first_incoming_estimate_(-1),
bitrate_is_initialized_(false),
beta_(0.85f),
@ -90,18 +88,12 @@ uint32_t AimdRateControl::LatestEstimate() const {
return current_bitrate_bps_;
}
uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t now_ms) {
current_bitrate_bps_ = ChangeBitrate(
current_bitrate_bps_,
current_input_.incoming_bitrate.value_or(current_bitrate_bps_), now_ms);
return current_bitrate_bps_;
}
void AimdRateControl::SetRtt(int64_t rtt) {
rtt_ = rtt;
}
void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) {
uint32_t AimdRateControl::Update(const RateControlInput* input,
int64_t now_ms) {
RTC_CHECK(input);
// Set the initial bit rate value to what we're receiving the first half
@ -119,19 +111,11 @@ void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) {
}
}
if (updated_ && current_input_.bw_state == kBwOverusing) {
// Only update delay factor and incoming bit rate. We always want to react
// on an over-use.
current_input_.noise_var = input->noise_var;
current_input_.incoming_bitrate = input->incoming_bitrate;
} else {
updated_ = true;
current_input_ = *input;
}
current_bitrate_bps_ = ChangeBitrate(current_bitrate_bps_, *input, now_ms);
return current_bitrate_bps_;
}
void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) {
updated_ = true;
bitrate_is_initialized_ = true;
current_bitrate_bps_ = ClampBitrate(bitrate_bps, bitrate_bps);
time_last_bitrate_change_ = now_ms;
@ -155,18 +139,18 @@ rtc::Optional<int> AimdRateControl::GetLastBitrateDecreaseBps() const {
}
uint32_t AimdRateControl::ChangeBitrate(uint32_t new_bitrate_bps,
uint32_t incoming_bitrate_bps,
const RateControlInput& input,
int64_t now_ms) {
if (!updated_) {
return current_bitrate_bps_;
}
uint32_t incoming_bitrate_bps =
input.incoming_bitrate.value_or(current_bitrate_bps_);
// An over-use should always trigger us to reduce the bitrate, even though
// we have not yet established our first estimate. By acting on the over-use,
// we will end up with a valid estimate.
if (!bitrate_is_initialized_ && current_input_.bw_state != kBwOverusing)
if (!bitrate_is_initialized_ && input.bw_state != kBwOverusing)
return current_bitrate_bps_;
updated_ = false;
ChangeState(current_input_, now_ms);
ChangeState(input, now_ms);
// Calculated here because it's used in multiple places.
const float incoming_bitrate_kbps = incoming_bitrate_bps / 1000.0f;
// Calculate the max bit rate std dev given the normalized
@ -224,7 +208,7 @@ uint32_t AimdRateControl::ChangeBitrate(uint32_t new_bitrate_bps,
UpdateMaxBitRateEstimate(incoming_bitrate_kbps);
// Stay on hold until the pipes are cleared.
ChangeState(kRcHold);
rate_control_state_ = kRcHold;
time_last_bitrate_change_ = now_ms;
break;
@ -294,20 +278,20 @@ void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) {
void AimdRateControl::ChangeState(const RateControlInput& input,
int64_t now_ms) {
switch (current_input_.bw_state) {
switch (input.bw_state) {
case kBwNormal:
if (rate_control_state_ == kRcHold) {
time_last_bitrate_change_ = now_ms;
ChangeState(kRcIncrease);
rate_control_state_ = kRcIncrease;
}
break;
case kBwOverusing:
if (rate_control_state_ != kRcDecrease) {
ChangeState(kRcDecrease);
rate_control_state_ = kRcDecrease;
}
break;
case kBwUnderusing:
ChangeState(kRcHold);
rate_control_state_ = kRcHold;
break;
default:
assert(false);
@ -318,7 +302,4 @@ void AimdRateControl::ChangeRegion(RateControlRegion region) {
rate_control_region_ = region;
}
void AimdRateControl::ChangeState(RateControlState new_state) {
rate_control_state_ = new_state;
}
} // namespace webrtc

View File

@ -39,9 +39,8 @@ class AimdRateControl {
bool TimeToReduceFurther(int64_t time_now,
uint32_t incoming_bitrate_bps) const;
uint32_t LatestEstimate() const;
uint32_t UpdateBandwidthEstimate(int64_t now_ms);
void SetRtt(int64_t rtt);
void Update(const RateControlInput* input, int64_t now_ms);
uint32_t Update(const RateControlInput* input, int64_t now_ms);
void SetEstimate(int bitrate_bps, int64_t now_ms);
// Returns the increase rate which is used when used bandwidth is near the
@ -59,7 +58,7 @@ class AimdRateControl {
// incoming bitrate. When in the "hold" state the bitrate will be kept
// constant to allow built up queues to drain.
uint32_t ChangeBitrate(uint32_t current_bitrate,
uint32_t incoming_bitrate,
const RateControlInput& input,
int64_t now_ms);
// Clamps new_bitrate_bps to within the configured min bitrate and a linear
// function of the incoming bitrate, so that the new bitrate can't grow too
@ -72,7 +71,6 @@ class AimdRateControl {
void UpdateChangePeriod(int64_t now_ms);
void UpdateMaxBitRateEstimate(float incoming_bit_rate_kbps);
void ChangeState(const RateControlInput& input, int64_t now_ms);
void ChangeState(RateControlState new_state);
void ChangeRegion(RateControlRegion region);
uint32_t min_configured_bitrate_bps_;
@ -83,8 +81,6 @@ class AimdRateControl {
RateControlState rate_control_state_;
RateControlRegion rate_control_region_;
int64_t time_last_bitrate_change_;
RateControlInput current_input_;
bool updated_;
int64_t time_first_incoming_estimate_;
bool bitrate_is_initialized_;
float beta_;

View File

@ -37,7 +37,6 @@ void UpdateRateControl(const AimdRateControlStates& states,
RateControlInput input(bandwidth_usage, rtc::Optional<uint32_t>(bitrate),
now_ms);
states.aimd_rate_control->Update(&input, now_ms);
states.aimd_rate_control->UpdateBandwidthEstimate(now_ms);
}
} // namespace

View File

@ -332,8 +332,7 @@ void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo(
const RateControlInput input(detector_.State(),
incoming_bitrate_.Rate(arrival_time_ms),
estimator_->var_noise());
remote_rate_.Update(&input, now_ms);
target_bitrate_bps = remote_rate_.UpdateBandwidthEstimate(now_ms);
target_bitrate_bps = remote_rate_.Update(&input, now_ms);
update_estimate = remote_rate_.ValidEstimate();
ssrcs = Keys(ssrcs_);
}

View File

@ -191,8 +191,7 @@ void RemoteBitrateEstimatorSingleStream::UpdateEstimate(int64_t now_ms) {
const RateControlInput input(bw_state,
incoming_bitrate_.Rate(now_ms),
mean_noise_var);
remote_rate->Update(&input, now_ms);
uint32_t target_bitrate = remote_rate->UpdateBandwidthEstimate(now_ms);
uint32_t target_bitrate = remote_rate->Update(&input, now_ms);
if (remote_rate->ValidEstimate()) {
process_interval_ms_ = remote_rate->GetFeedbackInterval();
RTC_DCHECK_GT(process_interval_ms_, 0);