2014-12-04 15:34:06 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_AIMD_RATE_CONTROL_H_
|
|
|
|
|
#define MODULES_REMOTE_BITRATE_ESTIMATOR_AIMD_RATE_CONTROL_H_
|
2014-12-04 15:34:06 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
|
|
|
|
|
#include "rtc_base/constructormagic.h"
|
2014-12-04 15:34:06 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-07-06 10:50:47 +02:00
|
|
|
// A rate control implementation based on additive increases of
|
2014-12-04 15:34:06 +00:00
|
|
|
// bitrate when no over-use is detected and multiplicative decreases when
|
|
|
|
|
// over-uses are detected. When we think the available bandwidth has changes or
|
|
|
|
|
// is unknown, we will switch to a "slow-start mode" where we increase
|
|
|
|
|
// multiplicatively.
|
2015-07-06 10:50:47 +02:00
|
|
|
class AimdRateControl {
|
2014-12-04 15:34:06 +00:00
|
|
|
public:
|
2015-09-28 03:57:14 -07:00
|
|
|
AimdRateControl();
|
2017-04-19 09:15:04 -07:00
|
|
|
~AimdRateControl();
|
2014-12-04 15:34:06 +00:00
|
|
|
|
2018-06-28 16:38:05 +02:00
|
|
|
// Returns true if the target bitrate has been initialized. This happens
|
|
|
|
|
// either if it has been explicitly set via SetStartBitrate/SetEstimate, or if
|
|
|
|
|
// we have measured a throughput.
|
2015-07-06 10:50:47 +02:00
|
|
|
bool ValidEstimate() const;
|
2017-01-27 06:43:18 -08:00
|
|
|
void SetStartBitrate(int start_bitrate_bps);
|
2018-05-18 07:12:15 +00:00
|
|
|
void SetMinBitrate(int min_bitrate_bps);
|
2015-07-06 10:50:47 +02:00
|
|
|
int64_t GetFeedbackInterval() const;
|
2018-07-18 14:59:56 +02:00
|
|
|
|
2014-12-04 15:34:06 +00:00
|
|
|
// Returns true if the bitrate estimate hasn't been changed for more than
|
2018-06-28 16:38:05 +02:00
|
|
|
// an RTT, or if the estimated_throughput is less than half of the current
|
2014-12-04 15:34:06 +00:00
|
|
|
// estimate. Should be used to decide if we should reduce the rate further
|
|
|
|
|
// when over-using.
|
2018-07-18 14:59:56 +02:00
|
|
|
bool TimeToReduceFurther(int64_t now_ms,
|
2018-06-28 16:38:05 +02:00
|
|
|
uint32_t estimated_throughput_bps) const;
|
2018-07-18 14:59:56 +02:00
|
|
|
// As above. To be used if overusing before we have measured a throughput.
|
|
|
|
|
bool InitialTimeToReduceFurther(int64_t now_ms) const;
|
|
|
|
|
|
2015-07-06 10:50:47 +02:00
|
|
|
uint32_t LatestEstimate() const;
|
|
|
|
|
void SetRtt(int64_t rtt);
|
2017-04-03 02:27:08 -07:00
|
|
|
uint32_t Update(const RateControlInput* input, int64_t now_ms);
|
2015-07-06 10:50:47 +02:00
|
|
|
void SetEstimate(int bitrate_bps, int64_t now_ms);
|
2014-12-04 15:34:06 +00:00
|
|
|
|
2017-04-19 09:15:04 -07:00
|
|
|
// Returns the increase rate when used bandwidth is near the link capacity.
|
|
|
|
|
int GetNearMaxIncreaseRateBps() const;
|
|
|
|
|
// Returns the expected time between overuse signals (assuming steady state).
|
|
|
|
|
int GetExpectedBandwidthPeriodMs() const;
|
2016-11-17 01:18:43 -08:00
|
|
|
|
2014-12-04 15:34:06 +00:00
|
|
|
private:
|
2018-09-04 18:55:14 +02:00
|
|
|
friend class GoogCcStatePrinter;
|
2018-06-28 16:38:05 +02:00
|
|
|
// Update the target bitrate based on, among other things, the current rate
|
|
|
|
|
// control state, the current target bitrate and the estimated throughput.
|
|
|
|
|
// When in the "increase" state the bitrate will be increased either
|
2014-12-04 15:34:06 +00:00
|
|
|
// additively or multiplicatively depending on the rate control region. When
|
|
|
|
|
// in the "decrease" state the bitrate will be decreased to slightly below the
|
2018-06-28 16:38:05 +02:00
|
|
|
// current throughput. When in the "hold" state the bitrate will be kept
|
2014-12-04 15:34:06 +00:00
|
|
|
// constant to allow built up queues to drain.
|
2017-02-13 09:08:22 -08:00
|
|
|
uint32_t ChangeBitrate(uint32_t current_bitrate,
|
2017-04-03 02:27:08 -07:00
|
|
|
const RateControlInput& input,
|
2014-12-04 15:34:06 +00:00
|
|
|
int64_t now_ms);
|
2017-02-13 09:08:22 -08:00
|
|
|
// Clamps new_bitrate_bps to within the configured min bitrate and a linear
|
2018-06-28 16:38:05 +02:00
|
|
|
// function of the throughput, so that the new bitrate can't grow too
|
2017-02-13 09:08:22 -08:00
|
|
|
// large compared to the bitrate actually being received by the other end.
|
|
|
|
|
uint32_t ClampBitrate(uint32_t new_bitrate_bps,
|
2018-06-28 16:38:05 +02:00
|
|
|
uint32_t estimated_throughput_bps) const;
|
2014-12-04 15:34:06 +00:00
|
|
|
uint32_t MultiplicativeRateIncrease(int64_t now_ms,
|
|
|
|
|
int64_t last_ms,
|
|
|
|
|
uint32_t current_bitrate_bps) const;
|
2016-11-17 01:18:43 -08:00
|
|
|
uint32_t AdditiveRateIncrease(int64_t now_ms, int64_t last_ms) const;
|
2014-12-04 15:34:06 +00:00
|
|
|
void UpdateChangePeriod(int64_t now_ms);
|
2018-06-28 16:38:05 +02:00
|
|
|
void UpdateMaxThroughputEstimate(float estimated_throughput_kbps);
|
2014-12-04 15:34:06 +00:00
|
|
|
void ChangeState(const RateControlInput& input, int64_t now_ms);
|
|
|
|
|
|
|
|
|
|
uint32_t min_configured_bitrate_bps_;
|
|
|
|
|
uint32_t max_configured_bitrate_bps_;
|
|
|
|
|
uint32_t current_bitrate_bps_;
|
2018-06-28 16:38:05 +02:00
|
|
|
uint32_t latest_estimated_throughput_bps_;
|
2014-12-04 15:34:06 +00:00
|
|
|
float avg_max_bitrate_kbps_;
|
|
|
|
|
float var_max_bitrate_kbps_;
|
|
|
|
|
RateControlState rate_control_state_;
|
|
|
|
|
RateControlRegion rate_control_region_;
|
|
|
|
|
int64_t time_last_bitrate_change_;
|
2018-07-18 14:59:56 +02:00
|
|
|
int64_t time_last_bitrate_decrease_;
|
2018-06-28 16:38:05 +02:00
|
|
|
int64_t time_first_throughput_estimate_;
|
2014-12-04 15:34:06 +00:00
|
|
|
bool bitrate_is_initialized_;
|
|
|
|
|
float beta_;
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t rtt_;
|
2018-07-18 14:59:56 +02:00
|
|
|
const bool in_experiment_;
|
|
|
|
|
const bool smoothing_experiment_;
|
|
|
|
|
const bool in_initial_backoff_interval_experiment_;
|
|
|
|
|
int64_t initial_backoff_interval_ms_;
|
2018-06-18 10:48:16 +02:00
|
|
|
absl::optional<int> last_decrease_;
|
2014-12-04 15:34:06 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_REMOTE_BITRATE_ESTIMATOR_AIMD_RATE_CONTROL_H_
|