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"
|
2022-03-29 11:04:48 +02:00
|
|
|
#include "api/field_trials_view.h"
|
2019-04-15 15:42:25 +02:00
|
|
|
#include "api/transport/network_types.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:
|
2023-03-28 13:17:57 +02:00
|
|
|
explicit AimdRateControl(const FieldTrialsView& key_value_config);
|
|
|
|
|
AimdRateControl(const FieldTrialsView& key_value_config, bool send_side);
|
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);
|
2023-03-28 13:17:57 +02:00
|
|
|
DataRate Update(const RateControlInput& input, Timestamp at_time);
|
2019-04-17 12:53:23 +02:00
|
|
|
void SetInApplicationLimitedRegion(bool in_alr);
|
2018-11-19 18:02:20 +01:00
|
|
|
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:
|
2020-11-24 17:50:31 +01:00
|
|
|
enum class RateControlState { kRcHold, kRcIncrease, kRcDecrease };
|
|
|
|
|
|
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.
|
2020-03-06 14:55:10 +01:00
|
|
|
void ChangeBitrate(const RateControlInput& input, Timestamp at_time);
|
|
|
|
|
|
|
|
|
|
DataRate ClampBitrate(DataRate new_bitrate) const;
|
2018-11-19 18:02:20 +01:00
|
|
|
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_;
|
2019-04-17 12:53:23 +02:00
|
|
|
bool in_alr_;
|
2018-11-19 18:02:20 +01:00
|
|
|
TimeDelta rtt_;
|
2019-04-17 12:53:23 +02:00
|
|
|
const bool send_side_;
|
|
|
|
|
// Allow the delay based estimate to only increase as long as application
|
|
|
|
|
// limited region (alr) is not detected.
|
|
|
|
|
const bool no_bitrate_increase_in_alr_;
|
2023-09-27 14:10:08 +02:00
|
|
|
// If true, subtract an additional 5kbps when backing off.
|
|
|
|
|
const bool subtract_additional_backoff_term_;
|
2023-04-03 15:44:20 +02:00
|
|
|
// If "Disabled", estimated link capacity is not used as upper bound.
|
2022-02-24 17:10:30 +01:00
|
|
|
FieldTrialFlag disable_estimate_bounded_increase_{"Disabled"};
|
2023-08-25 14:18:47 +02:00
|
|
|
FieldTrialParameter<bool> use_current_estimate_as_min_upper_bound_{"c_upper",
|
|
|
|
|
false};
|
2018-11-19 18:02:20 +01:00
|
|
|
absl::optional<DataRate> 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_
|