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 00b6810941..c1abeb322b 100644 --- a/modules/congestion_controller/goog_cc/goog_cc_network_control.cc +++ b/modules/congestion_controller/goog_cc/goog_cc_network_control.cc @@ -335,12 +335,13 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback( feedback_max_rtt = std::max(feedback_max_rtt, rtt); max_recv_time = std::max(max_recv_time, packet_feedback.receive_time); } + absl::optional min_feedback_max_rtt_ms; if (feedback_max_rtt.IsFinite()) { feedback_max_rtts_.push_back(feedback_max_rtt.ms()); const size_t kMaxFeedbackRttWindow = 32; if (feedback_max_rtts_.size() > kMaxFeedbackRttWindow) feedback_max_rtts_.pop_front(); - min_feedback_max_rtt_ms_.emplace(*std::min_element( + min_feedback_max_rtt_ms.emplace(*std::min_element( feedback_max_rtts_.begin(), feedback_max_rtts_.end())); } if (packet_feedback_only_) { @@ -416,7 +417,26 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback( update.probe_cluster_configs.insert(update.probe_cluster_configs.end(), probes.begin(), probes.end()); } - update.congestion_window = MaybeUpdateCongestionWindow(); + + // No valid RTT could be because send-side BWE isn't used, in which case + // we don't try to limit the outstanding packets. + if (in_cwnd_experiment_ && min_feedback_max_rtt_ms) { + const DataSize kMinCwnd = DataSize::bytes(2 * 1500); + TimeDelta time_window = + TimeDelta::ms(*min_feedback_max_rtt_ms + accepted_queue_ms_); + DataSize data_window = last_bandwidth_ * time_window; + if (current_data_window_) { + data_window = + std::max(kMinCwnd, (data_window + current_data_window_.value()) / 2); + } else { + data_window = std::max(kMinCwnd, data_window); + } + current_data_window_ = data_window; + RTC_LOG(LS_INFO) << "Feedback rtt: " << *min_feedback_max_rtt_ms + << " Bitrate: " << last_bandwidth_.bps(); + } + update.congestion_window = current_data_window_; + return update; } @@ -440,30 +460,6 @@ NetworkControlUpdate GoogCcNetworkController::GetNetworkState( return update; } -absl::optional -GoogCcNetworkController::MaybeUpdateCongestionWindow() { - if (!in_cwnd_experiment_) - return absl::nullopt; - // No valid RTT. Could be because send-side BWE isn't used, in which case - // we don't try to limit the outstanding packets. - if (!min_feedback_max_rtt_ms_) - return absl::nullopt; - - const DataSize kMinCwnd = DataSize::bytes(2 * 1500); - TimeDelta time_window = - TimeDelta::ms(*min_feedback_max_rtt_ms_ + accepted_queue_ms_); - DataSize data_window = last_bandwidth_ * time_window; - if (current_data_window_) { - data_window = - std::max(kMinCwnd, (data_window + current_data_window_.value()) / 2); - } else { - data_window = std::max(kMinCwnd, data_window); - } - current_data_window_ = data_window; - RTC_LOG(LS_INFO) << "Feedback rtt: " << *min_feedback_max_rtt_ms_ - << " Bitrate: " << last_bandwidth_.bps(); - return data_window; -} void GoogCcNetworkController::MaybeTriggerOnNetworkChanged( NetworkControlUpdate* update, @@ -471,10 +467,25 @@ void GoogCcNetworkController::MaybeTriggerOnNetworkChanged( int32_t estimated_bitrate_bps; uint8_t fraction_loss; int64_t rtt_ms; + bandwidth_estimation_->CurrentEstimate(&estimated_bitrate_bps, &fraction_loss, + &rtt_ms); + + estimated_bitrate_bps = std::max( + estimated_bitrate_bps, bandwidth_estimation_->GetMinBitrate()); + + BWE_TEST_LOGGING_PLOT(1, "fraction_loss_%", at_time.ms(), + (fraction_loss * 100) / 256); + BWE_TEST_LOGGING_PLOT(1, "rtt_ms", at_time.ms(), rtt_ms); + BWE_TEST_LOGGING_PLOT(1, "Target_bitrate_kbps", at_time.ms(), + estimated_bitrate_bps / 1000); + + if ((estimated_bitrate_bps != last_estimated_bitrate_bps_) || + (fraction_loss != last_estimated_fraction_loss_) || + (rtt_ms != last_estimated_rtt_ms_)) { + last_estimated_bitrate_bps_ = estimated_bitrate_bps; + last_estimated_fraction_loss_ = fraction_loss; + last_estimated_rtt_ms_ = rtt_ms; - bool estimate_changed = GetNetworkParameters( - &estimated_bitrate_bps, &fraction_loss, &rtt_ms, at_time); - if (estimate_changed) { alr_detector_->SetEstimatedBitrate(estimated_bitrate_bps); DataRate bandwidth = DataRate::bps(estimated_bitrate_bps); @@ -504,35 +515,6 @@ void GoogCcNetworkController::MaybeTriggerOnNetworkChanged( } } -bool GoogCcNetworkController::GetNetworkParameters( - int32_t* estimated_bitrate_bps, - uint8_t* fraction_loss, - int64_t* rtt_ms, - Timestamp at_time) { - bandwidth_estimation_->CurrentEstimate(estimated_bitrate_bps, fraction_loss, - rtt_ms); - *estimated_bitrate_bps = std::max( - *estimated_bitrate_bps, bandwidth_estimation_->GetMinBitrate()); - - bool estimate_changed = false; - if ((*estimated_bitrate_bps != last_estimated_bitrate_bps_) || - (*fraction_loss != last_estimated_fraction_loss_) || - (*rtt_ms != last_estimated_rtt_ms_)) { - last_estimated_bitrate_bps_ = *estimated_bitrate_bps; - last_estimated_fraction_loss_ = *fraction_loss; - last_estimated_rtt_ms_ = *rtt_ms; - estimate_changed = true; - } - - BWE_TEST_LOGGING_PLOT(1, "fraction_loss_%", at_time.ms(), - (*fraction_loss * 100) / 256); - BWE_TEST_LOGGING_PLOT(1, "rtt_ms", at_time.ms(), *rtt_ms); - BWE_TEST_LOGGING_PLOT(1, "Target_bitrate_kbps", at_time.ms(), - *estimated_bitrate_bps / 1000); - - return estimate_changed; -} - PacerConfig GoogCcNetworkController::GetPacingRates(Timestamp at_time) const { DataRate pacing_rate = std::max(min_pacing_rate_, last_bandwidth_) * pacing_factor_; 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 c20c1b3e62..b1fceebc29 100644 --- a/modules/congestion_controller/goog_cc/goog_cc_network_control.h +++ b/modules/congestion_controller/goog_cc/goog_cc_network_control.h @@ -56,13 +56,8 @@ class GoogCcNetworkController : public NetworkControllerInterface { std::vector UpdateBitrateConstraints( TargetRateConstraints constraints, absl::optional starting_rate); - absl::optional MaybeUpdateCongestionWindow(); void MaybeTriggerOnNetworkChanged(NetworkControlUpdate* update, Timestamp at_time); - bool GetNetworkParameters(int32_t* estimated_bitrate_bps, - uint8_t* fraction_loss, - int64_t* rtt_ms, - Timestamp at_time); PacerConfig GetPacingRates(Timestamp at_time) const; RtcEventLog* const event_log_; @@ -82,7 +77,6 @@ class GoogCcNetworkController : public NetworkControllerInterface { int expected_packets_since_last_loss_update_ = 0; std::deque feedback_max_rtts_; - absl::optional min_feedback_max_rtt_ms_; DataRate last_bandwidth_; absl::optional last_target_rate_;