Extracts LinkCapacityEstimator from AimdRateControl.

This prepares for future refactoring of rate controller.

Bug: webrtc:9718
Change-Id: I425c8c547399bda98b4271a0d24a0bb7ee06bc13
Reviewed-on: https://webrtc-review.googlesource.com/c/112420
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25846}
This commit is contained in:
Sebastian Jansson
2018-11-29 18:36:42 +01:00
parent cfe36ca3b3
commit 051251f598
7 changed files with 137 additions and 67 deletions

View File

@ -52,6 +52,18 @@ rtc_static_library("goog_cc") {
]
}
rtc_source_set("link_capacity_estimator") {
sources = [
"link_capacity_estimator.cc",
"link_capacity_estimator.h",
]
deps = [
"../../../api/units:data_rate",
"../../../rtc_base:safe_minmax",
"//third_party/abseil-cpp/absl/types:optional",
]
}
rtc_source_set("pushback_controller") {
sources = [
"congestion_window_pushback_controller.cc",

View File

@ -0,0 +1,71 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/congestion_controller/goog_cc/link_capacity_estimator.h"
#include <algorithm>
#include "rtc_base/numerics/safe_minmax.h"
namespace webrtc {
LinkCapacityEstimator::LinkCapacityEstimator() {}
DataRate LinkCapacityEstimator::UpperBound() const {
if (estimate_kbps_.has_value())
return DataRate::kbps(estimate_kbps_.value() +
3 * deviation_estimate_kbps());
return DataRate::Infinity();
}
DataRate LinkCapacityEstimator::LowerBound() const {
if (estimate_kbps_.has_value())
return DataRate::kbps(estimate_kbps_.value() -
3 * deviation_estimate_kbps());
return DataRate::Zero();
}
void LinkCapacityEstimator::Reset() {
estimate_kbps_.reset();
}
void LinkCapacityEstimator::OnOveruseDetected(DataRate acknowledged_rate) {
double ack_rate_kbps = acknowledged_rate.kbps();
const float alpha = 0.05f;
if (!estimate_kbps_.has_value()) {
estimate_kbps_ = ack_rate_kbps;
} else {
estimate_kbps_ =
(1 - alpha) * estimate_kbps_.value() + alpha * ack_rate_kbps;
}
// Estimate the variance of the link capacity estimate and normalize the
// variance with the link capacity estimate.
const double norm = std::max(estimate_kbps_.value(), 1.0);
double error_kbps = estimate_kbps_.value() - ack_rate_kbps;
deviation_kbps_ =
(1 - alpha) * deviation_kbps_ + alpha * error_kbps * error_kbps / norm;
// 0.4 ~= 14 kbit/s at 500 kbit/s
// 2.5f ~= 35 kbit/s at 500 kbit/s
deviation_kbps_ = rtc::SafeClamp(deviation_kbps_, 0.4f, 2.5f);
}
bool LinkCapacityEstimator::has_estimate() const {
return estimate_kbps_.has_value();
}
DataRate LinkCapacityEstimator::estimate() const {
return DataRate::kbps(*estimate_kbps_);
}
double LinkCapacityEstimator::deviation_estimate_kbps() const {
// Calculate the max bit rate std dev given the normalized
// variance and the current throughput bitrate. The standard deviation will
// only be used if estimate_kbps_ has a value.
return sqrt(deviation_kbps_ * estimate_kbps_.value());
}
} // namespace webrtc

View File

@ -0,0 +1,36 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_LINK_CAPACITY_ESTIMATOR_H_
#define MODULES_CONGESTION_CONTROLLER_GOOG_CC_LINK_CAPACITY_ESTIMATOR_H_
#include "absl/types/optional.h"
#include "api/units/data_rate.h"
namespace webrtc {
class LinkCapacityEstimator {
public:
LinkCapacityEstimator();
DataRate UpperBound() const;
DataRate LowerBound() const;
void Reset();
void OnOveruseDetected(DataRate acknowledged_rate);
bool has_estimate() const;
DataRate estimate() const;
private:
friend class GoogCcStatePrinter;
double deviation_estimate_kbps() const;
absl::optional<double> estimate_kbps_;
double deviation_kbps_ = 0.4;
};
} // namespace webrtc
#endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_LINK_CAPACITY_ESTIMATOR_H_

View File

@ -43,8 +43,8 @@ void GoogCcStatePrinter::PrintValues(FILE* out) {
auto* trendline_estimator = reinterpret_cast<TrendlineEstimator*>(detector);
fprintf(out, "%i %f %i %.6lf %.6lf %.6lf",
controller_->delay_based_bwe_->rate_control_.rate_control_state_,
controller_->delay_based_bwe_->rate_control_
.link_capacity_estimate_kbps_.value_or(NAN) *
controller_->delay_based_bwe_->rate_control_.link_capacity_
.estimate_kbps_.value_or(NAN) *
1000 / 8,
controller_->alr_detector_->alr_started_time_ms_.has_value(),
trendline_estimator->prev_trend_,