From 917e5967a597fa8d6e6cae9ffccb21e3d35d553b Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 8 Oct 2018 07:53:39 +0000 Subject: [PATCH] Revert "Using units in SendSideBandwidthEstimation." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 35b5e5f3b0dc409bf571b3609860ad5bb8e00c29. Reason for revert: Breaks downstream project Original change's description: > Using units in SendSideBandwidthEstimation. > > This CL moves SendSideBandwidthEstimation to use the unit types > DataRate, TimeDelta and Timestamp. This prepares for upcoming changes. > > Bug: webrtc:9718 > Change-Id: If10e329920dda037b53055ff3352ae7f8d7e32b8 > Reviewed-on: https://webrtc-review.googlesource.com/c/104021 > Commit-Queue: Sebastian Jansson > Reviewed-by: Björn Terelius > Cr-Commit-Position: refs/heads/master@{#25029} TBR=terelius@webrtc.org,srte@webrtc.org No-Try: True Bug: webrtc:9718 Change-Id: Iaf470f1eec9911ee6fc7c1b4f5db9675d89d3780 Reviewed-on: https://webrtc-review.googlesource.com/c/104480 Commit-Queue: Oleh Prypin Reviewed-by: Oleh Prypin Cr-Commit-Position: refs/heads/master@{#25035} --- modules/bitrate_controller/BUILD.gn | 1 - .../bitrate_controller_impl.cc | 51 +-- .../send_side_bandwidth_estimation.cc | 310 +++++++++--------- .../send_side_bandwidth_estimation.h | 68 ++-- ...send_side_bandwidth_estimation_unittest.cc | 53 ++- .../goog_cc/goog_cc_network_control.cc | 37 +-- .../goog_cc_network_control_unittest.cc | 7 +- modules/remote_bitrate_estimator/BUILD.gn | 1 - .../remote_bitrate_estimator/bwe_defines.cc | 4 - .../include/bwe_defines.h | 2 - 10 files changed, 245 insertions(+), 289 deletions(-) diff --git a/modules/bitrate_controller/BUILD.gn b/modules/bitrate_controller/BUILD.gn index 72046f0a01..ae6676578d 100644 --- a/modules/bitrate_controller/BUILD.gn +++ b/modules/bitrate_controller/BUILD.gn @@ -44,7 +44,6 @@ rtc_static_library("bitrate_controller") { "../rtp_rtcp", "../rtp_rtcp:rtp_rtcp_format", "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/types:optional", ] } diff --git a/modules/bitrate_controller/bitrate_controller_impl.cc b/modules/bitrate_controller/bitrate_controller_impl.cc index 93045b73a3..9b816f67dc 100644 --- a/modules/bitrate_controller/bitrate_controller_impl.cc +++ b/modules/bitrate_controller/bitrate_controller_impl.cc @@ -20,18 +20,7 @@ #include "rtc_base/logging.h" namespace webrtc { -namespace { -absl::optional ToOptionalDataRate(int start_bitrate_bps) { - if (start_bitrate_bps == -1) - return absl::nullopt; - return DataRate::bps(start_bitrate_bps); -} -DataRate MaxRate(int max_bitrate_bps) { - if (max_bitrate_bps == -1) - return DataRate::Infinity(); - return DataRate::bps(max_bitrate_bps); -} -} // namespace + class BitrateControllerImpl::RtcpBandwidthObserverImpl : public RtcpBandwidthObserver { public: @@ -91,9 +80,7 @@ RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { { rtc::CritScope cs(&critsect_); - bandwidth_estimation_.SetSendBitrate( - DataRate::bps(start_bitrate_bps), - Timestamp::ms(clock_->TimeInMilliseconds())); + bandwidth_estimation_.SetSendBitrate(start_bitrate_bps); } MaybeTriggerOnNetworkChanged(); } @@ -102,8 +89,7 @@ void BitrateControllerImpl::SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) { { rtc::CritScope cs(&critsect_); - bandwidth_estimation_.SetMinMaxBitrate(DataRate::bps(min_bitrate_bps), - DataRate::bps(max_bitrate_bps)); + bandwidth_estimation_.SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps); } MaybeTriggerOnNetworkChanged(); } @@ -113,9 +99,8 @@ void BitrateControllerImpl::SetBitrates(int start_bitrate_bps, int max_bitrate_bps) { { rtc::CritScope cs(&critsect_); - bandwidth_estimation_.SetBitrates( - ToOptionalDataRate(start_bitrate_bps), DataRate::bps(min_bitrate_bps), - MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds())); + bandwidth_estimation_.SetBitrates(start_bitrate_bps, min_bitrate_bps, + max_bitrate_bps); } MaybeTriggerOnNetworkChanged(); } @@ -126,9 +111,8 @@ void BitrateControllerImpl::ResetBitrates(int bitrate_bps, { rtc::CritScope cs(&critsect_); bandwidth_estimation_ = SendSideBandwidthEstimation(event_log_); - bandwidth_estimation_.SetBitrates( - ToOptionalDataRate(bitrate_bps), DataRate::bps(min_bitrate_bps), - MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds())); + bandwidth_estimation_.SetBitrates(bitrate_bps, min_bitrate_bps, + max_bitrate_bps); } MaybeTriggerOnNetworkChanged(); } @@ -137,8 +121,8 @@ void BitrateControllerImpl::ResetBitrates(int bitrate_bps, void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) { { rtc::CritScope cs(&critsect_); - bandwidth_estimation_.UpdateReceiverEstimate( - Timestamp::ms(clock_->TimeInMilliseconds()), DataRate::bps(bitrate)); + bandwidth_estimation_.UpdateReceiverEstimate(clock_->TimeInMilliseconds(), + bitrate); BWE_TEST_LOGGING_PLOT(1, "REMB_kbps", clock_->TimeInMilliseconds(), bitrate / 1000); } @@ -152,15 +136,12 @@ void BitrateControllerImpl::OnDelayBasedBweResult( { rtc::CritScope cs(&critsect_); if (result.probe) { - bandwidth_estimation_.SetSendBitrate( - DataRate::bps(result.target_bitrate_bps), - Timestamp::ms(clock_->TimeInMilliseconds())); + bandwidth_estimation_.SetSendBitrate(result.target_bitrate_bps); } // Since SetSendBitrate now resets the delay-based estimate, we have to call // UpdateDelayBasedEstimate after SetSendBitrate. - bandwidth_estimation_.UpdateDelayBasedEstimate( - Timestamp::ms(clock_->TimeInMilliseconds()), - DataRate::bps(result.target_bitrate_bps)); + bandwidth_estimation_.UpdateDelayBasedEstimate(clock_->TimeInMilliseconds(), + result.target_bitrate_bps); } MaybeTriggerOnNetworkChanged(); } @@ -177,8 +158,7 @@ int64_t BitrateControllerImpl::TimeUntilNextProcess() { void BitrateControllerImpl::Process() { { rtc::CritScope cs(&critsect_); - bandwidth_estimation_.UpdateEstimate( - Timestamp::ms(clock_->TimeInMilliseconds())); + bandwidth_estimation_.UpdateEstimate(clock_->TimeInMilliseconds()); } MaybeTriggerOnNetworkChanged(); last_bitrate_update_ms_ = clock_->TimeInMilliseconds(); @@ -233,9 +213,8 @@ void BitrateControllerImpl::OnReceivedRtcpReceiverReport( RTC_DCHECK_GE(total_number_of_packets, 0); - bandwidth_estimation_.UpdateReceiverBlock( - fraction_lost_aggregate, TimeDelta::ms(rtt), total_number_of_packets, - Timestamp::ms(now_ms)); + bandwidth_estimation_.UpdateReceiverBlock(fraction_lost_aggregate, rtt, + total_number_of_packets, now_ms); } MaybeTriggerOnNetworkChanged(); } diff --git a/modules/bitrate_controller/send_side_bandwidth_estimation.cc b/modules/bitrate_controller/send_side_bandwidth_estimation.cc index cc108a95b0..48eea3cd73 100644 --- a/modules/bitrate_controller/send_side_bandwidth_estimation.cc +++ b/modules/bitrate_controller/send_side_bandwidth_estimation.cc @@ -27,22 +27,22 @@ namespace webrtc { namespace { -constexpr TimeDelta kBweIncreaseInterval = TimeDelta::Millis<1000>(); -constexpr TimeDelta kBweDecreaseInterval = TimeDelta::Millis<300>(); -constexpr TimeDelta kStartPhase = TimeDelta::Millis<2000>(); -constexpr TimeDelta kBweConverganceTime = TimeDelta::Millis<20000>(); -constexpr int kLimitNumPackets = 20; -constexpr DataRate kDefaultMaxBitrate = DataRate::BitsPerSec<1000000000>(); -constexpr TimeDelta kLowBitrateLogPeriod = TimeDelta::Millis<10000>(); -constexpr TimeDelta kRtcEventLogPeriod = TimeDelta::Millis<5000>(); +const int64_t kBweIncreaseIntervalMs = 1000; +const int64_t kBweDecreaseIntervalMs = 300; +const int64_t kStartPhaseMs = 2000; +const int64_t kBweConverganceTimeMs = 20000; +const int kLimitNumPackets = 20; +const int kDefaultMaxBitrateBps = 1000000000; +const int64_t kLowBitrateLogPeriodMs = 10000; +const int64_t kRtcEventLogPeriodMs = 5000; // Expecting that RTCP feedback is sent uniformly within [0.5, 1.5]s intervals. -constexpr TimeDelta kMaxRtcpFeedbackInterval = TimeDelta::Millis<5000>(); -constexpr int kFeedbackTimeoutIntervals = 3; -constexpr TimeDelta kTimeoutInterval = TimeDelta::Millis<1000>(); +const int64_t kFeedbackIntervalMs = 5000; +const int64_t kFeedbackTimeoutIntervals = 3; +const int64_t kTimeoutIntervalMs = 1000; -constexpr float kDefaultLowLossThreshold = 0.02f; -constexpr float kDefaultHighLossThreshold = 0.1f; -constexpr DataRate kDefaultBitrateThreshold = DataRate::Zero(); +const float kDefaultLowLossThreshold = 0.02f; +const float kDefaultHighLossThreshold = 0.1f; +const int kDefaultBitrateThresholdKbps = 0; struct UmaRampUpMetric { const char* metric_name; @@ -99,7 +99,7 @@ bool ReadBweLossExperimentParameters(float* low_loss_threshold, "experiment from field trial string. Using default."; *low_loss_threshold = kDefaultLowLossThreshold; *high_loss_threshold = kDefaultHighLossThreshold; - *bitrate_threshold_kbps = kDefaultBitrateThreshold.kbps(); + *bitrate_threshold_kbps = kDefaultBitrateThresholdKbps; return false; } } // namespace @@ -107,34 +107,33 @@ bool ReadBweLossExperimentParameters(float* low_loss_threshold, SendSideBandwidthEstimation::SendSideBandwidthEstimation(RtcEventLog* event_log) : lost_packets_since_last_loss_update_(0), expected_packets_since_last_loss_update_(0), - current_bitrate_(DataRate::Zero()), - min_bitrate_configured_( - DataRate::bps(congestion_controller::GetMinBitrateBps())), - max_bitrate_configured_(kDefaultMaxBitrate), - last_low_bitrate_log_(Timestamp::MinusInfinity()), + current_bitrate_bps_(0), + min_bitrate_configured_(congestion_controller::GetMinBitrateBps()), + max_bitrate_configured_(kDefaultMaxBitrateBps), + last_low_bitrate_log_ms_(-1), has_decreased_since_last_fraction_loss_(false), - last_loss_feedback_(Timestamp::MinusInfinity()), - last_loss_packet_report_(Timestamp::MinusInfinity()), - last_timeout_(Timestamp::MinusInfinity()), + last_feedback_ms_(-1), + last_packet_report_ms_(-1), + last_timeout_ms_(-1), last_fraction_loss_(0), last_logged_fraction_loss_(0), - last_round_trip_time_(TimeDelta::Zero()), - bwe_incoming_(DataRate::Zero()), - delay_based_bitrate_(DataRate::Zero()), - time_last_decrease_(Timestamp::MinusInfinity()), - first_report_time_(Timestamp::MinusInfinity()), + last_round_trip_time_ms_(0), + bwe_incoming_(0), + delay_based_bitrate_bps_(0), + time_last_decrease_ms_(0), + first_report_time_ms_(-1), initially_lost_packets_(0), - bitrate_at_2_seconds_(DataRate::Zero()), + bitrate_at_2_seconds_kbps_(0), uma_update_state_(kNoUpdate), uma_rtt_state_(kNoUpdate), rampup_uma_stats_updated_(kNumUmaRampupMetrics, false), event_log_(event_log), - last_rtc_event_log_(Timestamp::MinusInfinity()), + last_rtc_event_log_ms_(-1), in_timeout_experiment_( webrtc::field_trial::IsEnabled("WebRTC-FeedbackTimeout")), low_loss_threshold_(kDefaultLowLossThreshold), high_loss_threshold_(kDefaultHighLossThreshold), - bitrate_threshold_(kDefaultBitrateThreshold) { + bitrate_threshold_bps_(1000 * kDefaultBitrateThresholdKbps) { RTC_DCHECK(event_log); if (BweLossExperimentIsEnabled()) { uint32_t bitrate_threshold_kbps; @@ -144,87 +143,87 @@ SendSideBandwidthEstimation::SendSideBandwidthEstimation(RtcEventLog* event_log) RTC_LOG(LS_INFO) << "Enabled BweLossExperiment with parameters " << low_loss_threshold_ << ", " << high_loss_threshold_ << ", " << bitrate_threshold_kbps; - bitrate_threshold_ = DataRate::kbps(bitrate_threshold_kbps); + bitrate_threshold_bps_ = bitrate_threshold_kbps * 1000; } } } SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} -void SendSideBandwidthEstimation::SetBitrates( - absl::optional send_bitrate, - DataRate min_bitrate, - DataRate max_bitrate, - Timestamp at_time) { +void SendSideBandwidthEstimation::SetBitrates(int send_bitrate, + int min_bitrate, + int max_bitrate) { SetMinMaxBitrate(min_bitrate, max_bitrate); - if (send_bitrate) - SetSendBitrate(*send_bitrate, at_time); + if (send_bitrate > 0) + SetSendBitrate(send_bitrate); } -void SendSideBandwidthEstimation::SetSendBitrate(DataRate bitrate, - Timestamp at_time) { - RTC_DCHECK(bitrate > DataRate::Zero()); - // Reset to avoid being capped by the estimate. - delay_based_bitrate_ = DataRate::Zero(); - CapBitrateToThresholds(at_time, bitrate); +void SendSideBandwidthEstimation::SetSendBitrate(int bitrate) { + RTC_DCHECK_GT(bitrate, 0); + delay_based_bitrate_bps_ = 0; // Reset to avoid being capped by the estimate. + CapBitrateToThresholds(Clock::GetRealTimeClock()->TimeInMilliseconds(), + bitrate); // Clear last sent bitrate history so the new value can be used directly // and not capped. min_bitrate_history_.clear(); } -void SendSideBandwidthEstimation::SetMinMaxBitrate(DataRate min_bitrate, - DataRate max_bitrate) { +void SendSideBandwidthEstimation::SetMinMaxBitrate(int min_bitrate, + int max_bitrate) { + RTC_DCHECK_GE(min_bitrate, 0); min_bitrate_configured_ = - std::max(min_bitrate, congestion_controller::GetMinBitrate()); - if (max_bitrate > DataRate::Zero() && max_bitrate.IsFinite()) { - max_bitrate_configured_ = std::max(min_bitrate_configured_, max_bitrate); + std::max(min_bitrate, congestion_controller::GetMinBitrateBps()); + if (max_bitrate > 0) { + max_bitrate_configured_ = + std::max(min_bitrate_configured_, max_bitrate); } else { - max_bitrate_configured_ = kDefaultMaxBitrate; + max_bitrate_configured_ = kDefaultMaxBitrateBps; } } int SendSideBandwidthEstimation::GetMinBitrate() const { - return min_bitrate_configured_.bps(); + return min_bitrate_configured_; } void SendSideBandwidthEstimation::CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const { - *bitrate = current_bitrate_.bps(); + *bitrate = current_bitrate_bps_; *loss = last_fraction_loss_; - *rtt = last_round_trip_time_.ms(); + *rtt = last_round_trip_time_ms_; } -void SendSideBandwidthEstimation::UpdateReceiverEstimate(Timestamp at_time, - DataRate bandwidth) { +void SendSideBandwidthEstimation::UpdateReceiverEstimate(int64_t now_ms, + uint32_t bandwidth) { bwe_incoming_ = bandwidth; - CapBitrateToThresholds(at_time, current_bitrate_); + CapBitrateToThresholds(now_ms, current_bitrate_bps_); } -void SendSideBandwidthEstimation::UpdateDelayBasedEstimate(Timestamp at_time, - DataRate bitrate) { - delay_based_bitrate_ = bitrate; - CapBitrateToThresholds(at_time, current_bitrate_); +void SendSideBandwidthEstimation::UpdateDelayBasedEstimate( + int64_t now_ms, + uint32_t bitrate_bps) { + delay_based_bitrate_bps_ = bitrate_bps; + CapBitrateToThresholds(now_ms, current_bitrate_bps_); } void SendSideBandwidthEstimation::UpdateReceiverBlock(uint8_t fraction_loss, - TimeDelta rtt, + int64_t rtt_ms, int number_of_packets, - Timestamp at_time) { + int64_t now_ms) { const int kRoundingConstant = 128; int packets_lost = (static_cast(fraction_loss) * number_of_packets + kRoundingConstant) >> 8; - UpdatePacketsLost(packets_lost, number_of_packets, at_time); - UpdateRtt(rtt, at_time); + UpdatePacketsLost(packets_lost, number_of_packets, now_ms); + UpdateRtt(rtt_ms, now_ms); } void SendSideBandwidthEstimation::UpdatePacketsLost(int packets_lost, int number_of_packets, - Timestamp at_time) { - last_loss_feedback_ = at_time; - if (first_report_time_.IsInfinite()) - first_report_time_ = at_time; + int64_t now_ms) { + last_feedback_ms_ = now_ms; + if (first_report_time_ms_ == -1) + first_report_time_ms_ = now_ms; // Check sequence number diff and weight loss report if (number_of_packets > 0) { @@ -245,201 +244,202 @@ void SendSideBandwidthEstimation::UpdatePacketsLost(int packets_lost, lost_packets_since_last_loss_update_ = 0; expected_packets_since_last_loss_update_ = 0; - last_loss_packet_report_ = at_time; - UpdateEstimate(at_time); + last_packet_report_ms_ = now_ms; + UpdateEstimate(now_ms); } - UpdateUmaStatsPacketsLost(at_time, packets_lost); + UpdateUmaStatsPacketsLost(now_ms, packets_lost); } -void SendSideBandwidthEstimation::UpdateUmaStatsPacketsLost(Timestamp at_time, +void SendSideBandwidthEstimation::UpdateUmaStatsPacketsLost(int64_t now_ms, int packets_lost) { - DataRate bitrate_kbps = DataRate::kbps((current_bitrate_.bps() + 500) / 1000); + int bitrate_kbps = static_cast((current_bitrate_bps_ + 500) / 1000); for (size_t i = 0; i < kNumUmaRampupMetrics; ++i) { if (!rampup_uma_stats_updated_[i] && - bitrate_kbps.kbps() >= kUmaRampupMetrics[i].bitrate_kbps) { + bitrate_kbps >= kUmaRampupMetrics[i].bitrate_kbps) { RTC_HISTOGRAMS_COUNTS_100000(i, kUmaRampupMetrics[i].metric_name, - (at_time - first_report_time_).ms()); + now_ms - first_report_time_ms_); rampup_uma_stats_updated_[i] = true; } } - if (IsInStartPhase(at_time)) { + if (IsInStartPhase(now_ms)) { initially_lost_packets_ += packets_lost; } else if (uma_update_state_ == kNoUpdate) { uma_update_state_ = kFirstDone; - bitrate_at_2_seconds_ = bitrate_kbps; + bitrate_at_2_seconds_kbps_ = bitrate_kbps; RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitiallyLostPackets", initially_lost_packets_, 0, 100, 50); RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialBandwidthEstimate", - bitrate_at_2_seconds_.kbps(), 0, 2000, 50); + bitrate_at_2_seconds_kbps_, 0, 2000, 50); } else if (uma_update_state_ == kFirstDone && - at_time - first_report_time_ >= kBweConverganceTime) { + now_ms - first_report_time_ms_ >= kBweConverganceTimeMs) { uma_update_state_ = kDone; - int bitrate_diff_kbps = std::max( - bitrate_at_2_seconds_.kbps() - bitrate_kbps.kbps(), 0); + int bitrate_diff_kbps = + std::max(bitrate_at_2_seconds_kbps_ - bitrate_kbps, 0); RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialVsConvergedDiff", bitrate_diff_kbps, 0, 2000, 50); } } -void SendSideBandwidthEstimation::UpdateRtt(TimeDelta rtt, Timestamp at_time) { +void SendSideBandwidthEstimation::UpdateRtt(int64_t rtt_ms, int64_t now_ms) { // Update RTT if we were able to compute an RTT based on this RTCP. // FlexFEC doesn't send RTCP SR, which means we won't be able to compute RTT. - if (rtt > TimeDelta::Zero()) - last_round_trip_time_ = rtt; + if (rtt_ms > 0) + last_round_trip_time_ms_ = rtt_ms; - if (!IsInStartPhase(at_time) && uma_rtt_state_ == kNoUpdate) { + if (!IsInStartPhase(now_ms) && uma_rtt_state_ == kNoUpdate) { uma_rtt_state_ = kDone; - RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialRtt", rtt.ms(), 0, 2000, 50); + RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialRtt", static_cast(rtt_ms), 0, + 2000, 50); } } -void SendSideBandwidthEstimation::UpdateEstimate(Timestamp at_time) { - DataRate new_bitrate = current_bitrate_; +void SendSideBandwidthEstimation::UpdateEstimate(int64_t now_ms) { + uint32_t new_bitrate = current_bitrate_bps_; // 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)) { + if (last_fraction_loss_ == 0 && IsInStartPhase(now_ms)) { new_bitrate = std::max(bwe_incoming_, new_bitrate); - new_bitrate = std::max(delay_based_bitrate_, new_bitrate); + new_bitrate = std::max(delay_based_bitrate_bps_, new_bitrate); - if (new_bitrate != current_bitrate_) { + if (new_bitrate != current_bitrate_bps_) { min_bitrate_history_.clear(); - min_bitrate_history_.push_back(std::make_pair(at_time, current_bitrate_)); - CapBitrateToThresholds(at_time, new_bitrate); + min_bitrate_history_.push_back( + std::make_pair(now_ms, current_bitrate_bps_)); + CapBitrateToThresholds(now_ms, new_bitrate); return; } } - UpdateMinHistory(at_time); - if (last_loss_packet_report_.IsInfinite()) { + UpdateMinHistory(now_ms); + if (last_packet_report_ms_ == -1) { // No feedback received. - CapBitrateToThresholds(at_time, current_bitrate_); + CapBitrateToThresholds(now_ms, current_bitrate_bps_); return; } - TimeDelta time_since_loss_packet_report = at_time - last_loss_packet_report_; - TimeDelta time_since_loss_feedback = at_time - last_loss_feedback_; - if (time_since_loss_packet_report < 1.2 * kMaxRtcpFeedbackInterval) { + int64_t time_since_packet_report_ms = now_ms - last_packet_report_ms_; + int64_t time_since_feedback_ms = now_ms - last_feedback_ms_; + if (time_since_packet_report_ms < 1.2 * kFeedbackIntervalMs) { // We only care about loss above a given bitrate threshold. float loss = last_fraction_loss_ / 256.0f; // We only make decisions based on loss when the bitrate is above a // threshold. This is a crude way of handling loss which is uncorrelated // to congestion. - if (current_bitrate_ < bitrate_threshold_ || loss <= low_loss_threshold_) { + if (current_bitrate_bps_ < bitrate_threshold_bps_ || + loss <= low_loss_threshold_) { // Loss < 2%: Increase rate by 8% of the min bitrate in the last - // kBweIncreaseInterval. + // kBweIncreaseIntervalMs. // Note that by remembering the bitrate over the last second one can // rampup up one second faster than if only allowed to start ramping // at 8% per second rate now. E.g.: // If sending a constant 100kbps it can rampup immediatly to 108kbps // whenever a receiver report is received with lower packet loss. - // If instead one would do: current_bitrate_ *= 1.08^(delta time), + // If instead one would do: current_bitrate_bps_ *= 1.08^(delta time), // it would take over one second since the lower packet loss to achieve // 108kbps. - new_bitrate = - DataRate::bps(min_bitrate_history_.front().second.bps() * 1.08 + 0.5); + new_bitrate = static_cast( + min_bitrate_history_.front().second * 1.08 + 0.5); // Add 1 kbps extra, just to make sure that we do not get stuck // (gives a little extra increase at low rates, negligible at higher // rates). - new_bitrate += DataRate::bps(1000); - } else if (current_bitrate_ > bitrate_threshold_) { + new_bitrate += 1000; + } else if (current_bitrate_bps_ > bitrate_threshold_bps_) { if (loss <= high_loss_threshold_) { // Loss between 2% - 10%: Do nothing. } else { - // Loss > 10%: Limit the rate decreases to once a kBweDecreaseInterval + // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs // + rtt. if (!has_decreased_since_last_fraction_loss_ && - (at_time - time_last_decrease_) >= - (kBweDecreaseInterval + last_round_trip_time_)) { - time_last_decrease_ = at_time; + (now_ms - time_last_decrease_ms_) >= + (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { + time_last_decrease_ms_ = now_ms; // Reduce rate: // newRate = rate * (1 - 0.5*lossRate); // where packetLoss = 256*lossRate; - new_bitrate = - DataRate::bps((current_bitrate_.bps() * - static_cast(512 - last_fraction_loss_)) / - 512.0); + new_bitrate = static_cast( + (current_bitrate_bps_ * + static_cast(512 - last_fraction_loss_)) / + 512.0); has_decreased_since_last_fraction_loss_ = true; } } } - } else if (time_since_loss_feedback > - kFeedbackTimeoutIntervals * kMaxRtcpFeedbackInterval && - (last_timeout_.IsInfinite() || - at_time - last_timeout_ > kTimeoutInterval)) { + } else if (time_since_feedback_ms > + kFeedbackTimeoutIntervals * kFeedbackIntervalMs && + (last_timeout_ms_ == -1 || + now_ms - last_timeout_ms_ > kTimeoutIntervalMs)) { if (in_timeout_experiment_) { - RTC_LOG(LS_WARNING) << "Feedback timed out (" - << ToString(time_since_loss_feedback) - << "), reducing bitrate."; - new_bitrate = new_bitrate * 0.8; + RTC_LOG(LS_WARNING) << "Feedback timed out (" << time_since_feedback_ms + << " ms), reducing bitrate."; + new_bitrate *= 0.8; // Reset accumulators since we've already acted on missing feedback and // shouldn't to act again on these old lost packets. lost_packets_since_last_loss_update_ = 0; expected_packets_since_last_loss_update_ = 0; - last_timeout_ = at_time; + last_timeout_ms_ = now_ms; } } - CapBitrateToThresholds(at_time, new_bitrate); + CapBitrateToThresholds(now_ms, new_bitrate); } -bool SendSideBandwidthEstimation::IsInStartPhase(Timestamp at_time) const { - return first_report_time_.IsInfinite() || - at_time - first_report_time_ < kStartPhase; +bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { + return first_report_time_ms_ == -1 || + now_ms - first_report_time_ms_ < kStartPhaseMs; } -void SendSideBandwidthEstimation::UpdateMinHistory(Timestamp at_time) { +void SendSideBandwidthEstimation::UpdateMinHistory(int64_t now_ms) { // Remove old data points from history. // Since history precision is in ms, add one so it is able to increase // bitrate if it is off by as little as 0.5ms. while (!min_bitrate_history_.empty() && - at_time - min_bitrate_history_.front().first + TimeDelta::ms(1) > - kBweIncreaseInterval) { + now_ms - min_bitrate_history_.front().first + 1 > + kBweIncreaseIntervalMs) { min_bitrate_history_.pop_front(); } // Typical minimum sliding-window algorithm: Pop values higher than current // bitrate before pushing it. while (!min_bitrate_history_.empty() && - current_bitrate_ <= min_bitrate_history_.back().second) { + current_bitrate_bps_ <= min_bitrate_history_.back().second) { min_bitrate_history_.pop_back(); } - min_bitrate_history_.push_back(std::make_pair(at_time, current_bitrate_)); + min_bitrate_history_.push_back(std::make_pair(now_ms, current_bitrate_bps_)); } -void SendSideBandwidthEstimation::CapBitrateToThresholds(Timestamp at_time, - DataRate bitrate) { - if (bwe_incoming_ > DataRate::Zero() && bitrate > bwe_incoming_) { - bitrate = bwe_incoming_; +void SendSideBandwidthEstimation::CapBitrateToThresholds(int64_t now_ms, + uint32_t bitrate_bps) { + if (bwe_incoming_ > 0 && bitrate_bps > bwe_incoming_) { + bitrate_bps = bwe_incoming_; } - if (delay_based_bitrate_ > DataRate::Zero() && - bitrate > delay_based_bitrate_) { - bitrate = delay_based_bitrate_; + if (delay_based_bitrate_bps_ > 0 && bitrate_bps > delay_based_bitrate_bps_) { + bitrate_bps = delay_based_bitrate_bps_; } - if (bitrate > max_bitrate_configured_) { - bitrate = max_bitrate_configured_; + if (bitrate_bps > max_bitrate_configured_) { + bitrate_bps = max_bitrate_configured_; } - if (bitrate < min_bitrate_configured_) { - if (last_low_bitrate_log_.IsInfinite() || - at_time - last_low_bitrate_log_ > kLowBitrateLogPeriod) { + if (bitrate_bps < min_bitrate_configured_) { + if (last_low_bitrate_log_ms_ == -1 || + now_ms - last_low_bitrate_log_ms_ > kLowBitrateLogPeriodMs) { RTC_LOG(LS_WARNING) << "Estimated available bandwidth " - << ToString(bitrate) - << " is below configured min bitrate " - << ToString(min_bitrate_configured_) << "."; - last_low_bitrate_log_ = at_time; + << bitrate_bps / 1000 + << " kbps is below configured min bitrate " + << min_bitrate_configured_ / 1000 << " kbps."; + last_low_bitrate_log_ms_ = now_ms; } - bitrate = min_bitrate_configured_; + bitrate_bps = min_bitrate_configured_; } - if (bitrate != current_bitrate_ || + if (bitrate_bps != current_bitrate_bps_ || last_fraction_loss_ != last_logged_fraction_loss_ || - at_time - last_rtc_event_log_ > kRtcEventLogPeriod) { + now_ms - last_rtc_event_log_ms_ > kRtcEventLogPeriodMs) { event_log_->Log(absl::make_unique( - bitrate.bps(), last_fraction_loss_, + bitrate_bps, last_fraction_loss_, expected_packets_since_last_loss_update_)); last_logged_fraction_loss_ = last_fraction_loss_; - last_rtc_event_log_ = at_time; + last_rtc_event_log_ms_ = now_ms; } - current_bitrate_ = bitrate; + current_bitrate_bps_ = bitrate_bps; } } // namespace webrtc diff --git a/modules/bitrate_controller/send_side_bandwidth_estimation.h b/modules/bitrate_controller/send_side_bandwidth_estimation.h index 2c8b4ee3d5..54b571e96e 100644 --- a/modules/bitrate_controller/send_side_bandwidth_estimation.h +++ b/modules/bitrate_controller/send_side_bandwidth_estimation.h @@ -17,7 +17,6 @@ #include #include -#include "absl/types/optional.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" namespace webrtc { @@ -33,86 +32,83 @@ class SendSideBandwidthEstimation { void CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const; // Call periodically to update estimate. - void UpdateEstimate(Timestamp at_time); + void UpdateEstimate(int64_t now_ms); // Call when we receive a RTCP message with TMMBR or REMB. - void UpdateReceiverEstimate(Timestamp at_time, DataRate bandwidth); + void UpdateReceiverEstimate(int64_t now_ms, uint32_t bandwidth); // Call when a new delay-based estimate is available. - void UpdateDelayBasedEstimate(Timestamp at_time, DataRate bitrate); + void UpdateDelayBasedEstimate(int64_t now_ms, uint32_t bitrate_bps); // Call when we receive a RTCP message with a ReceiveBlock. void UpdateReceiverBlock(uint8_t fraction_loss, - TimeDelta rtt_ms, + int64_t rtt_ms, int number_of_packets, - Timestamp at_time); + int64_t now_ms); // Call when we receive a RTCP message with a ReceiveBlock. void UpdatePacketsLost(int packets_lost, int number_of_packets, - Timestamp at_time); + int64_t now_ms); // Call when we receive a RTCP message with a ReceiveBlock. - void UpdateRtt(TimeDelta rtt, Timestamp at_time); + void UpdateRtt(int64_t rtt, int64_t now_ms); - void SetBitrates(absl::optional send_bitrate, - DataRate min_bitrate, - DataRate max_bitrate, - Timestamp at_time); - void SetSendBitrate(DataRate bitrate, Timestamp at_time); - void SetMinMaxBitrate(DataRate min_bitrate, DataRate max_bitrate); + void SetBitrates(int send_bitrate, int min_bitrate, int max_bitrate); + void SetSendBitrate(int bitrate); + void SetMinMaxBitrate(int min_bitrate, int max_bitrate); int GetMinBitrate() const; private: enum UmaState { kNoUpdate, kFirstDone, kDone }; - bool IsInStartPhase(Timestamp at_time) const; + bool IsInStartPhase(int64_t now_ms) const; - void UpdateUmaStatsPacketsLost(Timestamp at_time, int packets_lost); + void UpdateUmaStatsPacketsLost(int64_t now_ms, int packets_lost); // Updates history of min bitrates. // After this method returns min_bitrate_history_.front().second contains the // min bitrate used during last kBweIncreaseIntervalMs. - void UpdateMinHistory(Timestamp at_time); + void UpdateMinHistory(int64_t now_ms); - // Cap |bitrate| to [min_bitrate_configured_, max_bitrate_configured_] and - // set |current_bitrate_| to the capped value and updates the event log. - void CapBitrateToThresholds(Timestamp at_time, DataRate bitrate); + // Cap |bitrate_bps| to [min_bitrate_configured_, max_bitrate_configured_] and + // set |current_bitrate_bps_| to the capped value and updates the event log. + void CapBitrateToThresholds(int64_t now_ms, uint32_t bitrate_bps); - std::deque > min_bitrate_history_; + std::deque > min_bitrate_history_; // incoming filters int lost_packets_since_last_loss_update_; int expected_packets_since_last_loss_update_; - DataRate current_bitrate_; - DataRate min_bitrate_configured_; - DataRate max_bitrate_configured_; - Timestamp last_low_bitrate_log_; + uint32_t current_bitrate_bps_; + uint32_t min_bitrate_configured_; + uint32_t max_bitrate_configured_; + int64_t last_low_bitrate_log_ms_; bool has_decreased_since_last_fraction_loss_; - Timestamp last_loss_feedback_; - Timestamp last_loss_packet_report_; - Timestamp last_timeout_; + int64_t last_feedback_ms_; + int64_t last_packet_report_ms_; + int64_t last_timeout_ms_; uint8_t last_fraction_loss_; uint8_t last_logged_fraction_loss_; - TimeDelta last_round_trip_time_; + int64_t last_round_trip_time_ms_; - DataRate bwe_incoming_; - DataRate delay_based_bitrate_; - Timestamp time_last_decrease_; - Timestamp first_report_time_; + uint32_t bwe_incoming_; + uint32_t delay_based_bitrate_bps_; + int64_t time_last_decrease_ms_; + int64_t first_report_time_ms_; int initially_lost_packets_; - DataRate bitrate_at_2_seconds_; + int bitrate_at_2_seconds_kbps_; UmaState uma_update_state_; UmaState uma_rtt_state_; std::vector rampup_uma_stats_updated_; RtcEventLog* event_log_; - Timestamp last_rtc_event_log_; + int64_t last_rtc_event_log_ms_; bool in_timeout_experiment_; float low_loss_threshold_; float high_loss_threshold_; - DataRate bitrate_threshold_; + uint32_t bitrate_threshold_bps_; }; } // namespace webrtc #endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ diff --git a/modules/bitrate_controller/send_side_bandwidth_estimation_unittest.cc b/modules/bitrate_controller/send_side_bandwidth_estimation_unittest.cc index becc616cf3..8d5b08bd04 100644 --- a/modules/bitrate_controller/send_side_bandwidth_estimation_unittest.cc +++ b/modules/bitrate_controller/send_side_bandwidth_estimation_unittest.cc @@ -35,25 +35,24 @@ MATCHER(LossBasedBweUpdateWithBitrateAndLossFraction, "") { } void TestProbing(bool use_delay_based) { - testing::NiceMock event_log; + MockRtcEventLog event_log; SendSideBandwidthEstimation bwe(&event_log); - int64_t now_ms = 0; - bwe.SetMinMaxBitrate(DataRate::bps(100000), DataRate::bps(1500000)); - bwe.SetSendBitrate(DataRate::bps(200000), Timestamp::ms(now_ms)); + bwe.SetMinMaxBitrate(100000, 1500000); + bwe.SetSendBitrate(200000); const int kRembBps = 1000000; const int kSecondRembBps = kRembBps + 500000; + int64_t now_ms = 0; - bwe.UpdateReceiverBlock(0, TimeDelta::ms(50), 1, Timestamp::ms(now_ms)); + bwe.UpdateReceiverBlock(0, 50, 1, now_ms); // Initial REMB applies immediately. if (use_delay_based) { - bwe.UpdateDelayBasedEstimate(Timestamp::ms(now_ms), - DataRate::bps(kRembBps)); + bwe.UpdateDelayBasedEstimate(now_ms, kRembBps); } else { - bwe.UpdateReceiverEstimate(Timestamp::ms(now_ms), DataRate::bps(kRembBps)); + bwe.UpdateReceiverEstimate(now_ms, kRembBps); } - bwe.UpdateEstimate(Timestamp::ms(now_ms)); + bwe.UpdateEstimate(now_ms); int bitrate; uint8_t fraction_loss; int64_t rtt; @@ -63,13 +62,11 @@ void TestProbing(bool use_delay_based) { // Second REMB doesn't apply immediately. now_ms += 2001; if (use_delay_based) { - bwe.UpdateDelayBasedEstimate(Timestamp::ms(now_ms), - DataRate::bps(kSecondRembBps)); + bwe.UpdateDelayBasedEstimate(now_ms, kSecondRembBps); } else { - bwe.UpdateReceiverEstimate(Timestamp::ms(now_ms), - DataRate::bps(kSecondRembBps)); + bwe.UpdateReceiverEstimate(now_ms, kSecondRembBps); } - bwe.UpdateEstimate(Timestamp::ms(now_ms)); + bwe.UpdateEstimate(now_ms); bitrate = 0; bwe.CurrentEstimate(&bitrate, &fraction_loss, &rtt); EXPECT_EQ(kRembBps, bitrate); @@ -89,18 +86,17 @@ TEST(SendSideBweTest, DoesntReapplyBitrateDecreaseWithoutFollowingRemb) { .Times(1); EXPECT_CALL(event_log, LogProxy(LossBasedBweUpdateWithBitrateAndLossFraction())) - .Times(1); + .Times(2); SendSideBandwidthEstimation bwe(&event_log); static const int kMinBitrateBps = 100000; static const int kInitialBitrateBps = 1000000; - int64_t now_ms = 1000; - bwe.SetMinMaxBitrate(DataRate::bps(kMinBitrateBps), DataRate::bps(1500000)); - bwe.SetSendBitrate(DataRate::bps(kInitialBitrateBps), Timestamp::ms(now_ms)); + bwe.SetMinMaxBitrate(kMinBitrateBps, 1500000); + bwe.SetSendBitrate(kInitialBitrateBps); static const uint8_t kFractionLoss = 128; static const int64_t kRttMs = 50; - now_ms += 10000; + int64_t now_ms = 0; int bitrate_bps; uint8_t fraction_loss; int64_t rtt_ms; @@ -110,11 +106,10 @@ TEST(SendSideBweTest, DoesntReapplyBitrateDecreaseWithoutFollowingRemb) { EXPECT_EQ(0, rtt_ms); // Signal heavy loss to go down in bitrate. - bwe.UpdateReceiverBlock(kFractionLoss, TimeDelta::ms(kRttMs), 100, - Timestamp::ms(now_ms)); + bwe.UpdateReceiverBlock(kFractionLoss, kRttMs, 100, now_ms); // Trigger an update 2 seconds later to not be rate limited. now_ms += 1000; - bwe.UpdateEstimate(Timestamp::ms(now_ms)); + bwe.UpdateEstimate(now_ms); bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms); EXPECT_LT(bitrate_bps, kInitialBitrateBps); @@ -132,7 +127,7 @@ TEST(SendSideBweTest, DoesntReapplyBitrateDecreaseWithoutFollowingRemb) { // Trigger an update 2 seconds later to not be rate limited (but it still // shouldn't update). now_ms += 1000; - bwe.UpdateEstimate(Timestamp::ms(now_ms)); + bwe.UpdateEstimate(now_ms); bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms); EXPECT_EQ(last_bitrate_bps, bitrate_bps); @@ -155,18 +150,16 @@ TEST(SendSideBweTest, SettingSendBitrateOverridesDelayBasedEstimate) { uint8_t fraction_loss; int64_t rtt_ms; - bwe.SetMinMaxBitrate(DataRate::bps(kMinBitrateBps), - DataRate::bps(kMaxBitrateBps)); - bwe.SetSendBitrate(DataRate::bps(kInitialBitrateBps), Timestamp::ms(now_ms)); + bwe.SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); + bwe.SetSendBitrate(kInitialBitrateBps); - bwe.UpdateDelayBasedEstimate(Timestamp::ms(now_ms), - DataRate::bps(kDelayBasedBitrateBps)); - bwe.UpdateEstimate(Timestamp::ms(now_ms)); + bwe.UpdateDelayBasedEstimate(now_ms, kDelayBasedBitrateBps); + bwe.UpdateEstimate(now_ms); bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms); EXPECT_GE(bitrate_bps, kInitialBitrateBps); EXPECT_LE(bitrate_bps, kDelayBasedBitrateBps); - bwe.SetSendBitrate(DataRate::bps(kForcedHighBitrate), Timestamp::ms(now_ms)); + bwe.SetSendBitrate(kForcedHighBitrate); bwe.CurrentEstimate(&bitrate_bps, &fraction_loss, &rtt_ms); EXPECT_EQ(bitrate_bps, kForcedHighBitrate); } 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 4ab9694f37..7ad65ce67b 100644 --- a/modules/congestion_controller/goog_cc/goog_cc_network_control.cc +++ b/modules/congestion_controller/goog_cc/goog_cc_network_control.cc @@ -158,7 +158,7 @@ NetworkControlUpdate GoogCcNetworkController::OnNetworkAvailability( NetworkControlUpdate GoogCcNetworkController::OnNetworkRouteChange( NetworkRouteChange msg) { - int64_t min_bitrate_bps = GetBpsOrDefault(msg.constraints.min_data_rate, 0); + int64_t min_bitrate_bps = GetBpsOrDefault(msg.constraints.min_data_rate, -1); int64_t max_bitrate_bps = GetBpsOrDefault(msg.constraints.max_data_rate, -1); int64_t start_bitrate_bps = GetBpsOrDefault(msg.constraints.starting_rate, -1); @@ -167,10 +167,8 @@ NetworkControlUpdate GoogCcNetworkController::OnNetworkRouteChange( bandwidth_estimation_ = absl::make_unique(event_log_); - bandwidth_estimation_->SetBitrates( - msg.constraints.starting_rate, DataRate::bps(min_bitrate_bps), - msg.constraints.max_data_rate.value_or(DataRate::Infinity()), - msg.at_time); + bandwidth_estimation_->SetBitrates(start_bitrate_bps, min_bitrate_bps, + max_bitrate_bps); delay_based_bwe_.reset(new DelayBasedBwe(event_log_)); acknowledged_bitrate_estimator_.reset(new AcknowledgedBitrateEstimator()); delay_based_bwe_->SetStartBitrate(start_bitrate_bps); @@ -208,7 +206,7 @@ NetworkControlUpdate GoogCcNetworkController::OnProcessInterval( initial_config_.reset(); } - bandwidth_estimation_->UpdateEstimate(msg.at_time); + bandwidth_estimation_->UpdateEstimate(msg.at_time.ms()); absl::optional start_time_ms = alr_detector_->GetApplicationLimitedRegionStartTime(); probe_controller_->SetAlrStartTimeMs(start_time_ms); @@ -227,8 +225,8 @@ NetworkControlUpdate GoogCcNetworkController::OnRemoteBitrateReport( RTC_LOG(LS_ERROR) << "Received REMB for packet feedback only GoogCC"; return NetworkControlUpdate(); } - bandwidth_estimation_->UpdateReceiverEstimate(msg.receive_time, - msg.bandwidth); + bandwidth_estimation_->UpdateReceiverEstimate(msg.receive_time.ms(), + msg.bandwidth.bps()); BWE_TEST_LOGGING_PLOT(1, "REMB_kbps", msg.receive_time.ms(), msg.bandwidth.bps() / 1000); return NetworkControlUpdate(); @@ -241,7 +239,8 @@ NetworkControlUpdate GoogCcNetworkController::OnRoundTripTimeUpdate( if (msg.smoothed) { delay_based_bwe_->OnRttUpdate(msg.round_trip_time.ms()); } else { - bandwidth_estimation_->UpdateRtt(msg.round_trip_time, msg.receive_time); + bandwidth_estimation_->UpdateRtt(msg.round_trip_time.ms(), + msg.receive_time.ms()); } return NetworkControlUpdate(); } @@ -308,10 +307,8 @@ GoogCcNetworkController::UpdateBitrateConstraints( min_bitrate_bps, start_bitrate_bps, max_bitrate_bps, constraints.at_time.ms())); - bandwidth_estimation_->SetBitrates( - starting_rate, DataRate::bps(min_bitrate_bps), - constraints.max_data_rate.value_or(DataRate::Infinity()), - constraints.at_time); + bandwidth_estimation_->SetBitrates(start_bitrate_bps, min_bitrate_bps, + max_bitrate_bps); if (start_bitrate_bps > 0) delay_based_bwe_->SetStartBitrate(start_bitrate_bps); delay_based_bwe_->SetMinBitrate(min_bitrate_bps); @@ -325,7 +322,7 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportLossReport( int64_t total_packets_delta = msg.packets_received_delta + msg.packets_lost_delta; bandwidth_estimation_->UpdatePacketsLost( - msg.packets_lost_delta, total_packets_delta, msg.receive_time); + msg.packets_lost_delta, total_packets_delta, msg.receive_time.ms()); return NetworkControlUpdate(); } @@ -367,7 +364,8 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback( feedback_min_rtt = std::min(rtt, feedback_min_rtt); } if (feedback_min_rtt.IsFinite()) { - bandwidth_estimation_->UpdateRtt(feedback_min_rtt, report.feedback_time); + bandwidth_estimation_->UpdateRtt(feedback_min_rtt.ms(), + report.feedback_time.ms()); } expected_packets_since_last_loss_update_ += @@ -380,7 +378,7 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback( next_loss_update_ = report.feedback_time + kLossUpdateInterval; bandwidth_estimation_->UpdatePacketsLost( lost_packets_since_last_loss_update_, - expected_packets_since_last_loss_update_, report.feedback_time); + expected_packets_since_last_loss_update_, report.feedback_time.ms()); expected_packets_since_last_loss_update_ = 0; lost_packets_since_last_loss_update_ = 0; } @@ -409,13 +407,12 @@ NetworkControlUpdate GoogCcNetworkController::OnTransportPacketsFeedback( NetworkControlUpdate update; if (result.updated) { if (result.probe) { - bandwidth_estimation_->SetSendBitrate( - DataRate::bps(result.target_bitrate_bps), report.feedback_time); + bandwidth_estimation_->SetSendBitrate(result.target_bitrate_bps); } // Since SetSendBitrate now resets the delay-based estimate, we have to call // UpdateDelayBasedEstimate after SetSendBitrate. - bandwidth_estimation_->UpdateDelayBasedEstimate( - report.feedback_time, DataRate::bps(result.target_bitrate_bps)); + bandwidth_estimation_->UpdateDelayBasedEstimate(report.feedback_time.ms(), + result.target_bitrate_bps); // Update the estimate in the ProbeController, in case we want to probe. MaybeTriggerOnNetworkChanged(&update, report.feedback_time); } diff --git a/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc b/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc index e3f3abf2b1..ea561a65fa 100644 --- a/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc +++ b/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc @@ -91,10 +91,9 @@ class GoogCcNetworkControllerTest : public ::testing::Test { return packet_result; } - NetworkRouteChange CreateRouteChange( - absl::optional start_rate = absl::nullopt, - absl::optional min_rate = absl::nullopt, - absl::optional max_rate = absl::nullopt) { + NetworkRouteChange CreateRouteChange(DataRate start_rate = DataRate::Zero(), + DataRate min_rate = DataRate::Zero(), + DataRate max_rate = DataRate::Zero()) { NetworkRouteChange route_change; route_change.at_time = current_time_; route_change.constraints.at_time = current_time_; diff --git a/modules/remote_bitrate_estimator/BUILD.gn b/modules/remote_bitrate_estimator/BUILD.gn index a8d6850749..13fbad3603 100644 --- a/modules/remote_bitrate_estimator/BUILD.gn +++ b/modules/remote_bitrate_estimator/BUILD.gn @@ -41,7 +41,6 @@ rtc_static_library("remote_bitrate_estimator") { deps = [ "../..:webrtc_common", - "../../api/units:data_rate", "../../modules:module_api", "../../modules/rtp_rtcp:rtp_rtcp_format", "../../rtc_base:checks", diff --git a/modules/remote_bitrate_estimator/bwe_defines.cc b/modules/remote_bitrate_estimator/bwe_defines.cc index 6cbe468348..35f1d19cc3 100644 --- a/modules/remote_bitrate_estimator/bwe_defines.cc +++ b/modules/remote_bitrate_estimator/bwe_defines.cc @@ -26,10 +26,6 @@ int GetMinBitrateBps() { return kMinBitrateBps; } -DataRate GetMinBitrate() { - return DataRate::bps(GetMinBitrateBps()); -} - } // namespace congestion_controller RateControlInput::RateControlInput( diff --git a/modules/remote_bitrate_estimator/include/bwe_defines.h b/modules/remote_bitrate_estimator/include/bwe_defines.h index d9185de99c..0d8c49bda6 100644 --- a/modules/remote_bitrate_estimator/include/bwe_defines.h +++ b/modules/remote_bitrate_estimator/include/bwe_defines.h @@ -12,7 +12,6 @@ #define MODULES_REMOTE_BITRATE_ESTIMATOR_INCLUDE_BWE_DEFINES_H_ #include "absl/types/optional.h" -#include "api/units/data_rate.h" #define BWE_MAX(a, b) ((a) > (b) ? (a) : (b)) #define BWE_MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -21,7 +20,6 @@ namespace webrtc { namespace congestion_controller { int GetMinBitrateBps(); -DataRate GetMinBitrate(); } // namespace congestion_controller static const int64_t kBitrateWindowMs = 1000;