From f889217015c046eb26266a2e31356d7ecda23fe3 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Wed, 30 Nov 2022 17:06:23 +0100 Subject: [PATCH] In RemoteBitrateEstimator unwrap remote_rate_ member from unique_ptr That member is always created during construction and thus doesn't need to be wrapped into unique_ptr and rechecked for beeing nullptr Bug: None Change-Id: I5d608c9b7bdfd8ec6e3296245359610ec1cf176c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/285660 Reviewed-by: Emil Lundmark Auto-Submit: Danil Chapovalov Commit-Queue: Emil Lundmark Cr-Commit-Position: refs/heads/main@{#38785} --- .../remote_bitrate_estimator_single_stream.cc | 23 +++++++------------ .../remote_bitrate_estimator_single_stream.h | 7 +----- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc index 6f442e5e2c..8f15912a49 100644 --- a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc +++ b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc @@ -63,7 +63,7 @@ RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream( : clock_(clock), incoming_bitrate_(kBitrateWindowMs, 8000), last_valid_incoming_bitrate_(0), - remote_rate_(new AimdRateControl(&field_trials_)), + remote_rate_(&field_trials_), observer_(observer), last_process_time_(-1), process_interval_ms_(kProcessIntervalMs), @@ -144,7 +144,7 @@ void RemoteBitrateEstimatorSingleStream::IncomingPacket( incoming_bitrate_.Rate(now_ms); if (incoming_bitrate_bps && (prior_state != BandwidthUsage::kBwOverusing || - GetRemoteRate()->TimeToReduceFurther( + remote_rate_.TimeToReduceFurther( Timestamp::Millis(now_ms), DataRate::BitsPerSec(*incoming_bitrate_bps)))) { // The first overuse should immediately trigger a new estimate. @@ -193,14 +193,13 @@ void RemoteBitrateEstimatorSingleStream::UpdateEstimate(int64_t now_ms) { if (overuse_detectors_.empty()) { return; } - AimdRateControl* remote_rate = GetRemoteRate(); const RateControlInput input( bw_state, OptionalRateFromOptionalBps(incoming_bitrate_.Rate(now_ms))); uint32_t target_bitrate = - remote_rate->Update(&input, Timestamp::Millis(now_ms)).bps(); - if (remote_rate->ValidEstimate()) { - process_interval_ms_ = remote_rate->GetFeedbackInterval().ms(); + remote_rate_.Update(&input, Timestamp::Millis(now_ms)).bps(); + if (remote_rate_.ValidEstimate()) { + process_interval_ms_ = remote_rate_.GetFeedbackInterval().ms(); RTC_DCHECK_GT(process_interval_ms_, 0); std::vector ssrcs; GetSsrcs(&ssrcs); @@ -212,7 +211,7 @@ void RemoteBitrateEstimatorSingleStream::UpdateEstimate(int64_t now_ms) { void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { MutexLock lock(&mutex_); - GetRemoteRate()->SetRtt(TimeDelta::Millis(avg_rtt_ms)); + remote_rate_.SetRtt(TimeDelta::Millis(avg_rtt_ms)); } void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) { @@ -226,10 +225,10 @@ void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) { DataRate RemoteBitrateEstimatorSingleStream::LatestEstimate() const { MutexLock lock(&mutex_); - if (!remote_rate_->ValidEstimate() || overuse_detectors_.empty()) { + if (!remote_rate_.ValidEstimate() || overuse_detectors_.empty()) { return DataRate::Zero(); } - return remote_rate_->LatestEstimate(); + return remote_rate_.LatestEstimate(); } void RemoteBitrateEstimatorSingleStream::GetSsrcs( @@ -243,10 +242,4 @@ void RemoteBitrateEstimatorSingleStream::GetSsrcs( } } -AimdRateControl* RemoteBitrateEstimatorSingleStream::GetRemoteRate() { - if (!remote_rate_) - remote_rate_.reset(new AimdRateControl(&field_trials_)); - return remote_rate_.get(); -} - } // namespace webrtc diff --git a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h index d62f922e02..699f259d48 100644 --- a/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h +++ b/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h @@ -15,7 +15,6 @@ #include #include -#include #include #include "api/transport/field_trial_based_config.h" @@ -65,16 +64,12 @@ class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator { void GetSsrcs(std::vector* ssrcs) const RTC_SHARED_LOCKS_REQUIRED(mutex_); - // Returns `remote_rate_` if the pointed to object exists, - // otherwise creates it. - AimdRateControl* GetRemoteRate() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); - Clock* const clock_; const FieldTrialBasedConfig field_trials_; SsrcOveruseEstimatorMap overuse_detectors_ RTC_GUARDED_BY(mutex_); RateStatistics incoming_bitrate_ RTC_GUARDED_BY(mutex_); uint32_t last_valid_incoming_bitrate_ RTC_GUARDED_BY(mutex_); - std::unique_ptr remote_rate_ RTC_GUARDED_BY(mutex_); + AimdRateControl remote_rate_ RTC_GUARDED_BY(mutex_); RemoteBitrateObserver* const observer_ RTC_GUARDED_BY(mutex_); mutable Mutex mutex_; int64_t last_process_time_;