From 9682f4be7dc325c3f0b9e99b974329abd3aff6f6 Mon Sep 17 00:00:00 2001 From: Diep Bui Date: Mon, 30 Oct 2023 13:55:26 +0000 Subject: [PATCH] Reset loss based BWE on route change. The change is under field trial use_in_start_phase. Bug: webrtc:12707 Change-Id: I2ba8245c5d126b3c8a2e54b826853d98aad6e4f9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/325184 Commit-Queue: Diep Bui Reviewed-by: Per Kjellander Cr-Commit-Position: refs/heads/main@{#41047} --- .../goog_cc/loss_based_bwe_v2.cc | 4 +++ .../goog_cc/loss_based_bwe_v2.h | 3 ++ .../goog_cc/send_side_bandwidth_estimation.cc | 30 +++++++++++-------- .../goog_cc/send_side_bandwidth_estimation.h | 4 ++- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/modules/congestion_controller/goog_cc/loss_based_bwe_v2.cc b/modules/congestion_controller/goog_cc/loss_based_bwe_v2.cc index ab8fbc2b12..1b112e9f7b 100644 --- a/modules/congestion_controller/goog_cc/loss_based_bwe_v2.cc +++ b/modules/congestion_controller/goog_cc/loss_based_bwe_v2.cc @@ -149,6 +149,10 @@ bool LossBasedBweV2::ReadyToUseInStartPhase() const { return IsReady() && config_->use_in_start_phase; } +bool LossBasedBweV2::UseInStartPhase() const { + return config_->use_in_start_phase; +} + LossBasedBweV2::Result LossBasedBweV2::GetLossBasedResult() const { if (!IsReady()) { if (!IsEnabled()) { diff --git a/modules/congestion_controller/goog_cc/loss_based_bwe_v2.h b/modules/congestion_controller/goog_cc/loss_based_bwe_v2.h index 425ca2a0c8..70da76d20a 100644 --- a/modules/congestion_controller/goog_cc/loss_based_bwe_v2.h +++ b/modules/congestion_controller/goog_cc/loss_based_bwe_v2.h @@ -62,6 +62,9 @@ class LossBasedBweV2 { // Returns true if loss based BWE is ready to be used in the start phase. bool ReadyToUseInStartPhase() const; + // Returns true if loss based BWE can be used in the start phase. + bool UseInStartPhase() const; + // Returns `DataRate::PlusInfinity` if no BWE can be calculated. Result GetLossBasedResult() const; diff --git a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc index b09cb22f49..22693d67e9 100644 --- a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc +++ b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc @@ -203,9 +203,9 @@ TimeDelta RttBasedBackoff::CorrectedRtt() const { RttBasedBackoff::~RttBasedBackoff() = default; SendSideBandwidthEstimation::SendSideBandwidthEstimation( - const FieldTrialsView* key_value_config, - RtcEventLog* event_log) - : rtt_backoff_(key_value_config), + const FieldTrialsView* key_value_config, RtcEventLog* event_log) + : key_value_config_(key_value_config), + rtt_backoff_(key_value_config), lost_packets_since_last_loss_update_(0), expected_packets_since_last_loss_update_(0), current_target_(DataRate::Zero()), @@ -234,7 +234,7 @@ SendSideBandwidthEstimation::SendSideBandwidthEstimation( high_loss_threshold_(kDefaultHighLossThreshold), bitrate_threshold_(kDefaultBitrateThreshold), loss_based_bandwidth_estimator_v1_(key_value_config), - loss_based_bandwidth_estimator_v2_(key_value_config), + loss_based_bandwidth_estimator_v2_(new LossBasedBweV2(key_value_config)), loss_based_state_(LossBasedState::kDelayBasedEstimate), disable_receiver_limit_caps_only_("Disabled") { RTC_DCHECK(event_log); @@ -252,7 +252,7 @@ SendSideBandwidthEstimation::SendSideBandwidthEstimation( ParseFieldTrial({&disable_receiver_limit_caps_only_}, key_value_config->Lookup("WebRTC-Bwe-ReceiverLimitCapsOnly")); if (LossBasedBandwidthEstimatorV2Enabled()) { - loss_based_bandwidth_estimator_v2_.SetMinMaxBitrate( + loss_based_bandwidth_estimator_v2_->SetMinMaxBitrate( min_bitrate_configured_, max_bitrate_configured_); } } @@ -281,6 +281,10 @@ void SendSideBandwidthEstimation::OnRouteChange() { uma_update_state_ = kNoUpdate; uma_rtt_state_ = kNoUpdate; last_rtc_event_log_ = Timestamp::MinusInfinity(); + if (loss_based_bandwidth_estimator_v2_->UseInStartPhase()) { + loss_based_bandwidth_estimator_v2_.reset( + new LossBasedBweV2(key_value_config_)); + } } void SendSideBandwidthEstimation::SetBitrates( @@ -315,8 +319,8 @@ void SendSideBandwidthEstimation::SetMinMaxBitrate(DataRate min_bitrate, } else { max_bitrate_configured_ = kDefaultMaxBitrate; } - loss_based_bandwidth_estimator_v2_.SetMinMaxBitrate(min_bitrate_configured_, - max_bitrate_configured_); + loss_based_bandwidth_estimator_v2_->SetMinMaxBitrate(min_bitrate_configured_, + max_bitrate_configured_); } int SendSideBandwidthEstimation::GetMinBitrate() const { @@ -371,7 +375,7 @@ void SendSideBandwidthEstimation::SetAcknowledgedRate( *acknowledged_rate, at_time); } if (LossBasedBandwidthEstimatorV2Enabled()) { - loss_based_bandwidth_estimator_v2_.SetAcknowledgedBitrate( + loss_based_bandwidth_estimator_v2_->SetAcknowledgedBitrate( *acknowledged_rate); } } @@ -386,7 +390,7 @@ void SendSideBandwidthEstimation::UpdateLossBasedEstimator( report.packet_feedbacks, report.feedback_time); } if (LossBasedBandwidthEstimatorV2Enabled()) { - loss_based_bandwidth_estimator_v2_.UpdateBandwidthEstimate( + loss_based_bandwidth_estimator_v2_->UpdateBandwidthEstimate( report.packet_feedbacks, delay_based_limit_, in_alr); UpdateEstimate(report.feedback_time); } @@ -492,7 +496,7 @@ void SendSideBandwidthEstimation::UpdateEstimate(Timestamp at_time) { // We trust the REMB and/or delay-based estimate during the first 2 seconds if // we haven't had any packet loss reported, to allow startup bitrate probing. if (last_fraction_loss_ == 0 && IsInStartPhase(at_time) && - !loss_based_bandwidth_estimator_v2_.ReadyToUseInStartPhase()) { + !loss_based_bandwidth_estimator_v2_->ReadyToUseInStartPhase()) { DataRate new_bitrate = current_target_; // TODO(srte): We should not allow the new_bitrate to be larger than the // receiver limit here. @@ -534,7 +538,7 @@ void SendSideBandwidthEstimation::UpdateEstimate(Timestamp at_time) { if (LossBasedBandwidthEstimatorV2ReadyForUse()) { LossBasedBweV2::Result result = - loss_based_bandwidth_estimator_v2_.GetLossBasedResult(); + loss_based_bandwidth_estimator_v2_->GetLossBasedResult(); loss_based_state_ = result.state; UpdateTargetBitrate(result.bandwidth_estimate, at_time); return; @@ -690,13 +694,13 @@ bool SendSideBandwidthEstimation::LossBasedBandwidthEstimatorV1ReadyForUse() } bool SendSideBandwidthEstimation::LossBasedBandwidthEstimatorV2Enabled() const { - return loss_based_bandwidth_estimator_v2_.IsEnabled(); + return loss_based_bandwidth_estimator_v2_->IsEnabled(); } bool SendSideBandwidthEstimation::LossBasedBandwidthEstimatorV2ReadyForUse() const { return LossBasedBandwidthEstimatorV2Enabled() && - loss_based_bandwidth_estimator_v2_.IsReady(); + loss_based_bandwidth_estimator_v2_->IsReady(); } } // namespace webrtc diff --git a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h index 3a4efc47c7..dd4d25a236 100644 --- a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h +++ b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -167,6 +168,7 @@ class SendSideBandwidthEstimation { bool LossBasedBandwidthEstimatorV1ReadyForUse() const; bool LossBasedBandwidthEstimatorV2ReadyForUse() const; + const FieldTrialsView* key_value_config_; RttBasedBackoff rtt_backoff_; LinkCapacityTracker link_capacity_; @@ -208,7 +210,7 @@ class SendSideBandwidthEstimation { float high_loss_threshold_; DataRate bitrate_threshold_; LossBasedBandwidthEstimation loss_based_bandwidth_estimator_v1_; - LossBasedBweV2 loss_based_bandwidth_estimator_v2_; + std::unique_ptr loss_based_bandwidth_estimator_v2_; LossBasedState loss_based_state_; FieldTrialFlag disable_receiver_limit_caps_only_; };