From a73538828f1b8c4163cffe8bb6aa1c6e284072e9 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Fri, 13 Apr 2018 11:47:33 +0200 Subject: [PATCH] Fixes potential crash in GoogCcNetworkController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UpdatePacingRates required that a bandwidth estimate was available and would otherwise crash. This CL ensures that there is an initial bandwidth estimate available from the beginning. Bug: webrtc:8415 Change-Id: I20c3b444eac42326a78cfebee70b4c1aa370c867 Reviewed-on: https://webrtc-review.googlesource.com/69802 Reviewed-by: Björn Terelius Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#22857} --- .../goog_cc/goog_cc_network_control.cc | 16 +++++++--------- .../goog_cc/goog_cc_network_control.h | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/congestion_controller/goog_cc/goog_cc_network_control.cc b/modules/congestion_controller/goog_cc/goog_cc_network_control.cc index 6eff9d2ca2..733f667e41 100644 --- a/modules/congestion_controller/goog_cc/goog_cc_network_control.cc +++ b/modules/congestion_controller/goog_cc/goog_cc_network_control.cc @@ -113,6 +113,7 @@ GoogCcNetworkController::GoogCcNetworkController(RtcEventLog* event_log, delay_based_bwe_(new DelayBasedBwe(event_log_)), acknowledged_bitrate_estimator_( rtc::MakeUnique()), + last_bandwidth_(config.starting_bandwidth), pacing_factor_(kDefaultPaceMultiplier), min_pacing_rate_(DataRate::Zero()), max_padding_rate_(DataRate::Zero()), @@ -334,17 +335,16 @@ GoogCcNetworkController::MaybeUpdateCongestionWindow() { // we don't try to limit the outstanding packets. if (!min_feedback_rtt_ms_) return rtc::nullopt; - if (!last_estimate_.has_value()) - return rtc::nullopt; + const DataSize kMinCwnd = DataSize::bytes(2 * 1500); TimeDelta time_window = TimeDelta::ms(*min_feedback_rtt_ms_ + accepted_queue_ms_); - DataSize data_window = last_estimate_->bandwidth * time_window; + DataSize data_window = last_bandwidth_ * time_window; CongestionWindow msg; msg.enabled = true; msg.data_window = std::max(kMinCwnd, data_window); RTC_LOG(LS_INFO) << "Feedback rtt: " << *min_feedback_rtt_ms_ - << " Bitrate: " << last_estimate_->bandwidth.bps(); + << " Bitrate: " << last_bandwidth_.bps(); return msg; } @@ -367,7 +367,7 @@ NetworkControlUpdate GoogCcNetworkController::MaybeTriggerOnNetworkChanged( new_estimate.loss_rate_ratio = fraction_loss / 255.0f; new_estimate.bwe_period = bwe_period; new_estimate.changed = true; - last_estimate_ = new_estimate; + last_bandwidth_ = new_estimate.bandwidth; return OnNetworkEstimate(new_estimate); } return NetworkControlUpdate(); @@ -424,11 +424,9 @@ NetworkControlUpdate GoogCcNetworkController::OnNetworkEstimate( } PacerConfig GoogCcNetworkController::UpdatePacingRates(Timestamp at_time) { - RTC_DCHECK(last_estimate_); DataRate pacing_rate = - std::max(min_pacing_rate_, last_estimate_->bandwidth) * pacing_factor_; - DataRate padding_rate = - std::min(max_padding_rate_, last_estimate_->bandwidth); + std::max(min_pacing_rate_, last_bandwidth_) * pacing_factor_; + DataRate padding_rate = std::min(max_padding_rate_, last_bandwidth_); PacerConfig msg; msg.at_time = at_time; msg.time_window = TimeDelta::s(1); diff --git a/modules/congestion_controller/goog_cc/goog_cc_network_control.h b/modules/congestion_controller/goog_cc/goog_cc_network_control.h index 71b74986cd..ab13d2080e 100644 --- a/modules/congestion_controller/goog_cc/goog_cc_network_control.h +++ b/modules/congestion_controller/goog_cc/goog_cc_network_control.h @@ -73,7 +73,7 @@ class GoogCcNetworkController : public NetworkControllerInterface { std::deque feedback_rtts_; rtc::Optional min_feedback_rtt_ms_; - rtc::Optional last_estimate_; + DataRate last_bandwidth_; rtc::Optional last_target_rate_; int32_t last_estimated_bitrate_bps_ = 0;