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
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include "absl/types/optional.h"
|
2019-04-15 15:42:25 +02:00
|
|
|
#include "api/transport/network_types.h"
|
2019-04-16 14:50:08 +02:00
|
|
|
#include "api/transport/webrtc_key_value_config.h"
|
2018-11-19 18:02:20 +01:00
|
|
|
#include "api/units/data_rate.h"
|
|
|
|
|
#include "api/units/timestamp.h"
|
2018-11-29 18:36:42 +01:00
|
|
|
#include "modules/congestion_controller/goog_cc/link_capacity_estimator.h"
|
|
|
|
|
#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
|
2019-03-27 16:18:39 +01:00
|
|
|
#include "rtc_base/experiments/field_trial_parser.h"
|
2018-11-19 18:02:20 +01:00
|
|
|
|
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:
|
2019-04-16 14:50:08 +02:00
|
|
|
explicit AimdRateControl(const WebRtcKeyValueConfig* key_value_config);
|
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;
|
2018-11-19 18:02:20 +01:00
|
|
|
void SetStartBitrate(DataRate start_bitrate);
|
|
|
|
|
void SetMinBitrate(DataRate min_bitrate);
|
|
|
|
|
TimeDelta 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-11-19 18:02:20 +01:00
|
|
|
bool TimeToReduceFurther(Timestamp at_time,
|
|
|
|
|
DataRate estimated_throughput) const;
|
2018-07-18 14:59:56 +02:00
|
|
|
// As above. To be used if overusing before we have measured a throughput.
|
2018-11-19 18:02:20 +01:00
|
|
|
bool InitialTimeToReduceFurther(Timestamp at_time) const;
|
2018-07-18 14:59:56 +02:00
|
|
|
|
2018-11-19 18:02:20 +01:00
|
|
|
DataRate LatestEstimate() const;
|
|
|
|
|
void SetRtt(TimeDelta rtt);
|
|
|
|
|
DataRate Update(const RateControlInput* input, Timestamp at_time);
|
|
|
|
|
void SetEstimate(DataRate bitrate, Timestamp at_time);
|
2019-04-15 15:42:25 +02:00
|
|
|
void SetNetworkStateEstimate(
|
|
|
|
|
const absl::optional<NetworkStateEstimate>& estimate);
|
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.
|
2018-11-19 18:02:20 +01:00
|
|
|
double GetNearMaxIncreaseRateBpsPerSecond() const;
|
2017-04-19 09:15:04 -07:00
|
|
|
// Returns the expected time between overuse signals (assuming steady state).
|
2018-11-19 18:02:20 +01:00
|
|
|
TimeDelta GetExpectedBandwidthPeriod() 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.
|
2018-11-19 18:02:20 +01:00
|
|
|
DataRate ChangeBitrate(DataRate current_bitrate,
|
2017-04-03 02:27:08 -07:00
|
|
|
const RateControlInput& input,
|
2018-11-19 18:02:20 +01:00
|
|
|
Timestamp at_time);
|
|
|
|
|
// Clamps new_bitrate 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.
|
2018-11-19 18:02:20 +01:00
|
|
|
DataRate ClampBitrate(DataRate new_bitrate,
|
|
|
|
|
DataRate estimated_throughput) const;
|
|
|
|
|
DataRate MultiplicativeRateIncrease(Timestamp at_time,
|
|
|
|
|
Timestamp last_ms,
|
|
|
|
|
DataRate current_bitrate) const;
|
|
|
|
|
DataRate AdditiveRateIncrease(Timestamp at_time, Timestamp last_time) const;
|
|
|
|
|
void UpdateChangePeriod(Timestamp at_time);
|
|
|
|
|
void ChangeState(const RateControlInput& input, Timestamp at_time);
|
2014-12-04 15:34:06 +00:00
|
|
|
|
2018-11-19 18:02:20 +01:00
|
|
|
DataRate min_configured_bitrate_;
|
|
|
|
|
DataRate max_configured_bitrate_;
|
|
|
|
|
DataRate current_bitrate_;
|
|
|
|
|
DataRate latest_estimated_throughput_;
|
2018-11-29 18:36:42 +01:00
|
|
|
LinkCapacityEstimator link_capacity_;
|
2019-04-15 15:42:25 +02:00
|
|
|
absl::optional<NetworkStateEstimate> network_estimate_;
|
2014-12-04 15:34:06 +00:00
|
|
|
RateControlState rate_control_state_;
|
2018-11-19 18:02:20 +01:00
|
|
|
Timestamp time_last_bitrate_change_;
|
|
|
|
|
Timestamp time_last_bitrate_decrease_;
|
|
|
|
|
Timestamp time_first_throughput_estimate_;
|
2014-12-04 15:34:06 +00:00
|
|
|
bool bitrate_is_initialized_;
|
2018-11-22 14:20:06 +01:00
|
|
|
double beta_;
|
2018-11-19 18:02:20 +01:00
|
|
|
TimeDelta rtt_;
|
2018-07-18 14:59:56 +02:00
|
|
|
const bool in_experiment_;
|
|
|
|
|
const bool smoothing_experiment_;
|
2018-11-19 18:02:20 +01:00
|
|
|
absl::optional<DataRate> last_decrease_;
|
2019-03-27 16:18:39 +01:00
|
|
|
FieldTrialOptional<TimeDelta> initial_backoff_interval_;
|
|
|
|
|
FieldTrialParameter<DataRate> low_throughput_threshold_;
|
2019-04-15 15:42:25 +02:00
|
|
|
FieldTrialOptional<double> capacity_deviation_ratio_threshold_;
|
|
|
|
|
FieldTrialParameter<double> cross_traffic_factor_;
|
|
|
|
|
FieldTrialOptional<double> capacity_limit_deviation_factor_;
|
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_
|