Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport changes to congestion control from libwebrtc #922

Draft
wants to merge 81 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
fa10437
Initial commit, backport main component.
Oct 10, 2022
44088eb
Initial commit, backport main component.
Oct 10, 2022
f01bd51
First failed attempt to backport Pacer, save to preserve.
Nov 14, 2022
fe738e3
Revert "First failed attempt to backport Pacer, save to preserve."
Nov 14, 2022
a43e06e
Enable Loss v2
Nov 14, 2022
60a446b
Merge branch 'v3' into bwe_backport
sarumjanuch Nov 16, 2022
f498894
Sync with latest Loss v2 changes.
Nov 17, 2022
f5ec63d
Merge remote-tracking branch 'origin/bwe_backport' into bwe_backport
Nov 17, 2022
676b92e
Sync with latest Loss v2 changes. Fix Periodic ALR when we suddenly h…
Nov 22, 2022
011731b
Revert "Sync with latest Loss v2 changes. Fix Periodic ALR when we su…
Nov 24, 2022
c8c6944
Revert "Sync with latest Loss v2 changes."
Nov 24, 2022
45b5d5c
Fix instant loss calculation when sending at high bitrates.
Nov 24, 2022
a468c21
Fix issue when no periodic ALR probing when sudden drop in BW, and th…
Nov 24, 2022
6e6f640
Increase InstantUpperBoundLossOffset slightly, because we don't have …
Nov 24, 2022
2dc6ad7
Increase InstantUpperBoundLossOffset slightly, because we don't have …
Nov 24, 2022
e7ee174
Increase InstantUpperBoundLossOffset. Fix issue when cc colpases and …
Nov 28, 2022
ad21541
Merge branch 'v3' into bwe_backport
Nov 28, 2022
e4b7bf8
clean
Nov 28, 2022
1647d07
Add BW balance multiplication to have a meaningful backoff.
Nov 30, 2022
07bea0f
Fix BW balance calculation. Adjust loss settings.
Nov 30, 2022
f613ad2
Revert to default coefficients
Nov 30, 2022
4c0202f
Apply suggestions from code review
ibc Dec 1, 2022
c4b007c
Fix default coefficients
Dec 1, 2022
2c4994f
Use sending rate instead of estimate in BW balance calculation, when …
Dec 2, 2022
036b9fd
Merge remote-tracking branch 'origin/v3' into bwe_backport
Dec 2, 2022
e545675
Update default libwebrtc fieldTrial string.
Dec 2, 2022
c5bfc17
format
Dec 2, 2022
b9a1161
Fix testing change.
Dec 2, 2022
0d99863
`Backport changes from aimd rate control, plus minor fixes.
Dec 2, 2022
619361a
`Backport changes from aimd rate control, plus minor fixes.
Dec 2, 2022
252d568
Fix log
Dec 5, 2022
0c7eef0
Backport latest changes from libwebrtc.
Dec 5, 2022
66deb26
Backport latest changes from libwebrtc.
Dec 5, 2022
23a3204
Backport latest changes from libwebrtc.
Dec 5, 2022
beb4d1d
Backport more changes. Rework trend-line estimator to produce R-squar…
Dec 7, 2022
e001c75
Adjust settings in delay bwe, add debounce in loss estimator with bac…
Dec 8, 2022
b988f54
Debounce instant loss, adjust default filed trial string
Dec 13, 2022
64c00cb
try fix maxlen
Dec 13, 2022
18f012c
Merge remote-tracking branch 'origin/v3' into bwe_backport
Dec 13, 2022
71f9459
Try update to C++14
Dec 13, 2022
9a61385
Fix Lint for long field trial string
Dec 13, 2022
a71c289
Add EventEmitter migrate to c++14
Dec 13, 2022
86a423f
Fix maxlen for fieldtrial string commnet
Dec 13, 2022
af18922
Merge remote-tracking branch 'origin/bwe_backport' into bwe_backport
Dec 13, 2022
965a5c1
Fix maxlen for field trial string comment
Dec 13, 2022
42f1bda
Merge remote-tracking branch 'origin/bwe_backport' into bwe_backport
Dec 13, 2022
96ddaa4
Fix maxlen for field trial string comment
Dec 13, 2022
b2daa7f
Fix EventEmitter
Dec 13, 2022
db290fc
Merge remote-tracking branch 'origin/c++14_EventEmitter' into c++14_E…
Dec 13, 2022
064d26e
Merge branch 'c++14_EventEmitter' into bwe_backport
Dec 13, 2022
e76b9fd
Remove old event emitter
Dec 13, 2022
e261944
test c++17
Dec 14, 2022
becaef1
remain c++14
Dec 14, 2022
4b86b18
Revert to remain on C++ 11.
Dec 19, 2022
e1333f8
Cosmetic constants.
Dec 19, 2022
6aa0b03
Add comment that explains what we are doing with R^2
Dec 19, 2022
09a4b4c
Get rid of EventEmitter.
Dec 19, 2022
47657fb
More C++ 14 cleanup.
Dec 19, 2022
fc46a65
Backport most recent libwebrtc changes, also fix some issues iwth cac…
Dec 23, 2022
a040b27
fix std -> absl
Dec 23, 2022
9f4093c
Be more resilient to bursts fixes here and there.
Dec 26, 2022
91b6923
Be more resilient to bursts fixes here and there.
Dec 26, 2022
a61ea7d
Reduce trendline window size to faster react to changes, push only va…
Jan 2, 2023
97d61ce
Adjust coefficients, enable robust estimator as acknowledged estimato…
Jan 2, 2023
4c0e7e1
Adjust coefficients more
Jan 2, 2023
ec9be0d
Refactor instant loss debounce mechanism. Add overuse counter for R s…
Jan 5, 2023
a175c36
Adjust coefficients, create separate counter for R squared overuse
Jan 9, 2023
ff76084
Adjust coefficients
Jan 9, 2023
3c2ff4b
Merge remote-tracking branch 'origin/v3' into bwe_backport
Jan 9, 2023
545a910
Limit probation rate by loss estimate rate, and don't probe when dela…
Jan 9, 2023
2594fd7
return smooth coefficient to 0.9, increase upper bound of R squared l…
Jan 10, 2023
4081d00
Pass inner estimators states to mediasoup land.
Jan 10, 2023
eef19db
format
Jan 10, 2023
eac1e6f
Add probe bitrate estimator to stats.
Jan 10, 2023
05cfade
Pass stats to nodejs land via trace event bweStats
Jan 11, 2023
f5acf13
Refactor. Add missing fields.
Jan 11, 2023
81f724d
Add typing for bweStats info, add sending rate field.
Jan 11, 2023
edb3af6
Add dot in the end of comment.
Jan 11, 2023
8c12a70
Make linter happy
Jan 11, 2023
16f67a8
Fixes here and there, try to recover bitrate when recovered from inst…
Jan 24, 2023
148a20b
Merge branch 'v3' into bwe_backport
ibc Mar 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions node/src/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ export type WorkerSettings =
* certificate is dynamically created.
*/
dtlsPrivateKeyFile?: string;

/* eslint-disable max-len */
ibc marked this conversation as resolved.
Show resolved Hide resolved
/**
* Field trials for libwebrtc.
* @private
*
* NOTE: For advanced users only. An invalid value will make the worker crash.
* Default value is
* "WebRTC-Bwe-AlrLimitedBackoff/Enabled/".
* "WebRTC-Bwe-AlrLimitedBackoff/Enabled/WebRTC-Bwe-LossBasedBweV2/Enabled:true,CandidateFactors:1.02|1.0|0.95,DelayBasedCandidate:true,HigherBwBiasFactor:0.0002,HigherLogBwBiasFactor:0.02,ObservationDurationLowerBound:250ms,InstantUpperBoundBwBalance:75kbps,BwRampupUpperBoundFactor:1000000.0,InstantUpperBoundTemporalWeightFactor:0.9,TemporalWeightFactor:0.9,MaxIncreaseFactor:1.3,NewtonStepSize:0.75,InherentLossUpperBoundBwBalance:75kbps,LossThresholdOfHighBandwidthPreference:0.15,NotIncreaseIfInherentLossLessThanAverageLoss:true,TrendlineIntegrationEnabled:true,SendingRateSmoothingFactor:0.6/".
*/
libwebrtcFieldTrials?: string;
/* eslint-enable max-len */

/**
* Custom application data.
Expand Down
2 changes: 1 addition & 1 deletion rust/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub struct WorkerSettings {
///
/// NOTE: For advanced users only. An invalid value will make the worker crash.
/// Default value is
/// "WebRTC-Bwe-AlrLimitedBackoff/Enabled/".
/// "WebRTC-Bwe-AlrLimitedBackoff/Enabled/WebRTC-Bwe-LossBasedBweV2/Enabled:true,CandidateFactors:1.02|1.0|0.95,DelayBasedCandidate:true,HigherBwBiasFactor:0.0002,HigherLogBwBiasFactor:0.02,ObservationDurationLowerBound:250ms,InstantUpperBoundBwBalance:75kbps,BwRampupUpperBoundFactor:1000000.0,InstantUpperBoundTemporalWeightFactor:0.9,TemporalWeightFactor:0.9,MaxIncreaseFactor:1.3,NewtonStepSize:0.75,InherentLossUpperBoundBwBalance:75kbps,LossThresholdOfHighBandwidthPreference:0.15,NotIncreaseIfInherentLossLessThanAverageLoss:true,TrendlineIntegrationEnabled:true,SendingRateSmoothingFactor:0.6/".
#[doc(hidden)]
pub libwebrtc_field_trials: Option<String>,
/// Function that will be called under worker thread before worker starts, can be used for
Expand Down
2 changes: 0 additions & 2 deletions worker/deps/libwebrtc/libwebrtc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
'libwebrtc/modules/congestion_controller/goog_cc/link_capacity_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc',
'libwebrtc/modules/congestion_controller/goog_cc/probe_controller.cc',
'libwebrtc/modules/congestion_controller/goog_cc/median_slope_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/bitrate_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/trendline_estimator.cc',
'libwebrtc/modules/congestion_controller/goog_cc/delay_based_bwe.cc',
Expand Down Expand Up @@ -110,7 +109,6 @@
'libwebrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h',
'libwebrtc/modules/congestion_controller/goog_cc/bitrate_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/link_capacity_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/median_slope_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/probe_controller.h',
'libwebrtc/modules/congestion_controller/goog_cc/trendline_estimator.h',
'libwebrtc/modules/congestion_controller/goog_cc/goog_cc_network_control.h',
Expand Down
10 changes: 9 additions & 1 deletion worker/deps/libwebrtc/libwebrtc/api/transport/network_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class NetworkControllerInterface {
// Called round trip time has been calculated by protocol specific mechanisms.
virtual NetworkControlUpdate OnRoundTripTimeUpdate(RoundTripTimeUpdate) = 0;
// Called when a packet is sent on the network.
virtual NetworkControlUpdate OnSentPacket(SentPacket) = 0;
virtual NetworkControlUpdate OnSentPacket(
SentPacket) = 0;
// Called when a packet is received from the remote client.
virtual NetworkControlUpdate OnReceivedPacket(
ReceivedPacket) = 0;
// Called when the stream specific configuration has been updated.
virtual NetworkControlUpdate OnStreamsConfig(StreamsConfig) = 0;
// Called when target transfer rate constraints has been changed.
Expand Down Expand Up @@ -108,7 +112,11 @@ class NetworkStateEstimator {
// Gets the current best estimate according to the estimator.
virtual absl::optional<NetworkStateEstimate> GetCurrentEstimate() = 0;
// Called with per packet feedback regarding receive time.
// Used when the NetworkStateEstimator runs in the sending endpoint.
virtual void OnTransportPacketsFeedback(const TransportPacketsFeedback&) = 0;
// Called with per packet feedback regarding receive time.
// Used when the NetworkStateEstimator runs in the receiving endpoint.
virtual void OnReceivedPacket(const PacketResult&) {}
// Called when the receiving or sending endpoint changes address.
virtual void OnRouteChange(const NetworkRouteChange&) = 0;
virtual ~NetworkStateEstimator() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <algorithm>

namespace webrtc {
// TODO(srte): Revert to using default after removing union member.
StreamsConfig::StreamsConfig() {}
StreamsConfig::StreamsConfig() = default;
StreamsConfig::StreamsConfig(const StreamsConfig&) = default;
StreamsConfig::~StreamsConfig() = default;

Expand Down Expand Up @@ -49,7 +48,7 @@ std::vector<PacketResult> TransportPacketsFeedback::ReceivedWithSendInfo()
const {
std::vector<PacketResult> res;
for (const PacketResult& fb : packet_feedbacks) {
if (fb.receive_time.IsFinite()) {
if (fb.IsReceived()) {
res.push_back(fb);
}
}
Expand All @@ -59,7 +58,7 @@ std::vector<PacketResult> TransportPacketsFeedback::ReceivedWithSendInfo()
std::vector<PacketResult> TransportPacketsFeedback::LostWithSendInfo() const {
std::vector<PacketResult> res;
for (const PacketResult& fb : packet_feedbacks) {
if (fb.receive_time.IsPlusInfinity()) {
if (!fb.IsReceived()) {
res.push_back(fb);
}
}
Expand All @@ -75,7 +74,7 @@ std::vector<PacketResult> TransportPacketsFeedback::SortedByReceiveTime()
const {
std::vector<PacketResult> res;
for (const PacketResult& fb : packet_feedbacks) {
if (fb.receive_time.IsFinite()) {
if (fb.IsReceived()) {
res.push_back(fb);
}
}
Expand Down
31 changes: 28 additions & 3 deletions worker/deps/libwebrtc/libwebrtc/api/transport/network_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ namespace webrtc {

// Configuration

// Represents constraints and rates related to the currently enabled streams.
// This is used as input to the congestion controller via the StreamsConfig
// struct.
struct BitrateAllocationLimits {
// The total minimum send bitrate required by all sending streams.
DataRate min_allocatable_rate = DataRate::Zero();
// The total maximum allocatable bitrate for all currently available streams.
DataRate max_allocatable_rate = DataRate::Zero();
// The max bitrate to use for padding. The sum of the per-stream max padding
// rate.
DataRate max_padding_rate = DataRate::Zero();
};

// Use StreamsConfig for information about streams that is required for specific
// adjustments to the algorithms in network controllers. Especially useful
// for experiments.
Expand All @@ -34,9 +47,9 @@ struct StreamsConfig {
Timestamp at_time = Timestamp::PlusInfinity();
absl::optional<bool> requests_alr_probing;
absl::optional<double> pacing_factor;
union {
absl::optional<DataRate> min_total_allocated_bitrate = absl::nullopt;
};

// TODO: (srte) Use BitrateAllocationLimits here.
absl::optional<DataRate> min_total_allocated_bitrate;
absl::optional<DataRate> max_padding_rate;
absl::optional<DataRate> max_total_allocated_bitrate;
};
Expand Down Expand Up @@ -84,13 +97,20 @@ struct PacedPacketInfo {
int probe_cluster_id = kNotAProbe;
int probe_cluster_min_probes = -1;
int probe_cluster_min_bytes = -1;
int probe_cluster_bytes_sent = 0;
};

struct SentPacket {
Timestamp send_time = Timestamp::PlusInfinity();
// Size of packet with overhead up to IP layer.
DataSize size = DataSize::Zero();
// Size of preceeding packets that are not part of feedback.
DataSize prior_unacked_data = DataSize::Zero();
// Probe cluster id and parameters including bitrate, number of packets and
// number of bytes.
PacedPacketInfo pacing_info;
// True if the packet is an audio packet, false for video, padding, RTX etc.
bool audio = false;
// Transport independent sequence number, any tracked packet should have a
// sequence number that is unique over the whole call and increasing by 1 for
// each packet.
Expand Down Expand Up @@ -138,6 +158,8 @@ struct PacketResult {
PacketResult(const PacketResult&);
~PacketResult();

inline bool IsReceived() const { return !receive_time.IsPlusInfinity(); }

SentPacket sent_packet;
Timestamp receive_time = Timestamp::PlusInfinity();
};
Expand Down Expand Up @@ -166,6 +188,7 @@ struct TransportPacketsFeedback {

struct NetworkEstimate {
Timestamp at_time = Timestamp::PlusInfinity();
// Deprecated, use TargetTransferRate::target_rate instead.
DataRate bandwidth = DataRate::Infinity();
TimeDelta round_trip_time = TimeDelta::PlusInfinity();
TimeDelta bwe_period = TimeDelta::PlusInfinity();
Expand Down Expand Up @@ -199,6 +222,8 @@ struct TargetTransferRate {
// The estimate on which the target rate is based on.
NetworkEstimate network_estimate;
DataRate target_rate = DataRate::Zero();
DataRate stable_target_rate = DataRate::Zero();
double cwnd_reduce_ratio = 0;
};

// Contains updates of network controller comand state. Using optionals to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/

#include "absl/strings/match.h"
#include "modules/bitrate_controller/loss_based_bandwidth_estimation.h"
#include "api/transport/webrtc_key_value_config.h"
#include "api/units/data_rate.h"
#include "api/units/time_delta.h"
#include "system_wrappers/source/field_trial.h"

#include <algorithm>
#include <string>
Expand All @@ -21,6 +22,10 @@ namespace webrtc {
namespace {
const char kBweLossBasedControl[] = "WebRTC-Bwe-LossBasedControl";

// Expecting RTCP feedback to be sent with roughly 1s intervals, a 5s gap
// indicates a channel outage.
constexpr TimeDelta kMaxRtcpFeedbackInterval = TimeDelta::Millis<5000>();

// Increase slower when RTT is high.
double GetIncreaseFactor(const LossBasedControlConfig& config, TimeDelta rtt) {
// Clamp the RTT
Expand Down Expand Up @@ -70,10 +75,16 @@ double ExponentialUpdate(TimeDelta window, TimeDelta interval) {
return 1.0f - exp(interval / window * -1.0);
}

bool IsEnabled(const WebRtcKeyValueConfig* key_value_config,
absl::string_view name) {
return key_value_config->Lookup(name).find("Enabled") == 0;
}

} // namespace

LossBasedControlConfig::LossBasedControlConfig()
: enabled(field_trial::IsEnabled(kBweLossBasedControl)),
LossBasedControlConfig::LossBasedControlConfig(
const WebRtcKeyValueConfig* key_value_config)
: enabled(IsEnabled(key_value_config, kBweLossBasedControl)),
min_increase_factor("min_incr", 1.02),
max_increase_factor("max_incr", 1.08),
increase_low_rtt("incr_low_rtt", TimeDelta::ms(200)),
Expand All @@ -85,26 +96,27 @@ LossBasedControlConfig::LossBasedControlConfig()
increase_offset("incr_offset", DataRate::bps(1000)),
loss_bandwidth_balance_increase("balance_incr", DataRate::kbps(0.5)),
loss_bandwidth_balance_decrease("balance_decr", DataRate::kbps(4)),
loss_bandwidth_balance_reset("balance_reset", DataRate::kbps(0.1)),
loss_bandwidth_balance_exponent("exponent", 0.5),
allow_resets("resets", false),
decrease_interval("decr_intvl", TimeDelta::ms(300)),
loss_report_timeout("timeout", TimeDelta::ms(6000)) {
std::string trial_string = field_trial::FindFullName(kBweLossBasedControl);
ParseFieldTrial(
{&min_increase_factor, &max_increase_factor, &increase_low_rtt,
&increase_high_rtt, &decrease_factor, &loss_window, &loss_max_window,
&acknowledged_rate_max_window, &increase_offset,
&loss_bandwidth_balance_increase, &loss_bandwidth_balance_decrease,
&loss_bandwidth_balance_exponent, &allow_resets, &decrease_interval,
&loss_report_timeout},
trial_string);
&loss_bandwidth_balance_reset, &loss_bandwidth_balance_exponent,
&allow_resets, &decrease_interval, &loss_report_timeout},
key_value_config->Lookup(kBweLossBasedControl));
}
LossBasedControlConfig::LossBasedControlConfig(const LossBasedControlConfig&) =
default;
LossBasedControlConfig::~LossBasedControlConfig() = default;

LossBasedBandwidthEstimation::LossBasedBandwidthEstimation()
: config_(LossBasedControlConfig()),
LossBasedBandwidthEstimation::LossBasedBandwidthEstimation(
const WebRtcKeyValueConfig* key_value_config)
: config_(key_value_config),
average_loss_(0),
average_loss_max_(0),
loss_based_bitrate_(DataRate::Zero()),
Expand Down Expand Up @@ -161,9 +173,14 @@ void LossBasedBandwidthEstimation::UpdateAcknowledgedBitrate(
}
}

void LossBasedBandwidthEstimation::Update(Timestamp at_time,
DataRate min_bitrate,
TimeDelta last_round_trip_time) {
DataRate LossBasedBandwidthEstimation::Update(Timestamp at_time,
DataRate min_bitrate,
DataRate wanted_bitrate,
TimeDelta last_round_trip_time) {
if (loss_based_bitrate_.IsZero()) {
loss_based_bitrate_ = wanted_bitrate;
}

// Only increase if loss has been low for some time.
const double loss_estimate_for_increase = average_loss_max_;
// Avoid multiple decreases from averaging over one loss spike.
Expand All @@ -173,8 +190,15 @@ void LossBasedBandwidthEstimation::Update(Timestamp at_time,
!has_decreased_since_last_loss_report_ &&
(at_time - time_last_decrease_ >=
last_round_trip_time + config_.decrease_interval);
// If packet lost reports are too old, dont increase bitrate.
const bool loss_report_valid =
at_time - last_loss_packet_report_ < 1.2 * kMaxRtcpFeedbackInterval;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how the RTCP feedback calculated in mediaosup? If I remember RFC3550 calculate based on assumed bw. If we calculate based on that assumption, and the bw suddenly drop because of congestion collapse than the interval will increase massively which makes this loss_report_valid false. at this moment the interpretation collides with the behaviour of the rest of the code, so right now it does not cause any problem and only beauty suggestion is to add a debug log if loss_report_valid is false, so if we search something related to it in the future we might have a chance to find it easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is old attempt of loss based BW estimate. It is disabled by default and is not used. Can be turned on by field trial. So we have:

  • Loss v1 BW estimator:
    I have tested it and it was producing bad values.
  • Loss v2 BW estimator:
    The one we are trying to use. It does not use RR RTC feedback. I relies only on TWCC RTCP feedback. When enabled, default estimator is ignored.
    - Default Loss estimation:
    Too simple to be used, as it odes not differentiate between random and burst, and has not very meaningful boundaries.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so I am lost in the code a bit. Does this mean it won't have any effect because another estimator is used after this PR? In this case should this code marked somehow as deprecated?


if (loss_estimate_for_increase < loss_increase_threshold()) {
if (loss_report_valid && config_.allow_resets &&
loss_estimate_for_increase < loss_reset_threshold()) {
loss_based_bitrate_ = wanted_bitrate;
} else if (loss_report_valid &&
loss_estimate_for_increase < loss_increase_threshold()) {
// Increase bitrate by RTT-adaptive ratio.
DataRate new_increased_bitrate =
min_bitrate * GetIncreaseFactor(config_, last_round_trip_time) +
Expand All @@ -200,14 +224,21 @@ void LossBasedBandwidthEstimation::Update(Timestamp at_time,
loss_based_bitrate_ = new_decreased_bitrate;
}
}
return loss_based_bitrate_;
}

void LossBasedBandwidthEstimation::Reset(DataRate bitrate) {
void LossBasedBandwidthEstimation::Initialize(DataRate bitrate) {
loss_based_bitrate_ = bitrate;
average_loss_ = 0;
average_loss_max_ = 0;
}

double LossBasedBandwidthEstimation::loss_reset_threshold() const {
return LossFromBitrate(loss_based_bitrate_,
config_.loss_bandwidth_balance_reset,
config_.loss_bandwidth_balance_exponent);
}

double LossBasedBandwidthEstimation::loss_increase_threshold() const {
return LossFromBitrate(loss_based_bitrate_,
config_.loss_bandwidth_balance_increase,
Expand All @@ -223,14 +254,4 @@ double LossBasedBandwidthEstimation::loss_decrease_threshold() const {
DataRate LossBasedBandwidthEstimation::decreased_bitrate() const {
return config_.decrease_factor * acknowledged_bitrate_max_;
}

void LossBasedBandwidthEstimation::MaybeReset(DataRate bitrate) {
if (config_.allow_resets)
Reset(bitrate);
}

void LossBasedBandwidthEstimation::SetInitialBitrate(DataRate bitrate) {
Reset(bitrate);
}

} // namespace webrtc