From ec1a670167c8eb02bea11fb944b6bedf4ddca63a Mon Sep 17 00:00:00 2001 From: Rasmus Brandt Date: Mon, 28 Nov 2016 14:48:26 +0100 Subject: [PATCH] Only create |remote_rate| when needed in RemoteBitrateEstimatorSingleStream. R=stefan@webrtc.org BUG=None Review URL: https://codereview.webrtc.org/2532113002 . Cr-Commit-Position: refs/heads/master@{#15264} --- .../remote_bitrate_estimator_single_stream.cc | 20 ++++++++++++------- .../remote_bitrate_estimator_single_stream.h | 4 ++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc index 6730cbb611..b689aa62b8 100644 --- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc +++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc @@ -133,7 +133,7 @@ void RemoteBitrateEstimatorSingleStream::IncomingPacket( incoming_bitrate_.Rate(now_ms); if (incoming_bitrate_bps && (prior_state != kBwOverusing || - remote_rate_->TimeToReduceFurther(now_ms, *incoming_bitrate_bps))) { + GetRemoteRate()->TimeToReduceFurther(now_ms, *incoming_bitrate_bps))) { // The first overuse should immediately trigger a new estimate. // We also have to update the estimate immediately if we are overusing // and the target bitrate is too high compared to what we are receiving. @@ -189,19 +189,19 @@ void RemoteBitrateEstimatorSingleStream::UpdateEstimate(int64_t now_ms) { } // We can't update the estimate if we don't have any active streams. if (overuse_detectors_.empty()) { - remote_rate_.reset(new AimdRateControl()); return; } + AimdRateControl* remote_rate = GetRemoteRate(); double mean_noise_var = sum_var_noise / static_cast(overuse_detectors_.size()); const RateControlInput input(bw_state, incoming_bitrate_.Rate(now_ms), mean_noise_var); - remote_rate_->Update(&input, now_ms); - uint32_t target_bitrate = remote_rate_->UpdateBandwidthEstimate(now_ms); - if (remote_rate_->ValidEstimate()) { - process_interval_ms_ = remote_rate_->GetFeedbackInterval(); + remote_rate->Update(&input, now_ms); + uint32_t target_bitrate = remote_rate->UpdateBandwidthEstimate(now_ms); + if (remote_rate->ValidEstimate()) { + process_interval_ms_ = remote_rate->GetFeedbackInterval(); std::vector ssrcs; GetSsrcs(&ssrcs); observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate); @@ -211,7 +211,7 @@ void RemoteBitrateEstimatorSingleStream::UpdateEstimate(int64_t now_ms) { void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { CriticalSectionScoped cs(crit_sect_.get()); - remote_rate_->SetRtt(avg_rtt_ms); + GetRemoteRate()->SetRtt(avg_rtt_ms); } void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) { @@ -250,6 +250,12 @@ void RemoteBitrateEstimatorSingleStream::GetSsrcs( } } +AimdRateControl* RemoteBitrateEstimatorSingleStream::GetRemoteRate() { + if (!remote_rate_) + remote_rate_.reset(new AimdRateControl()); + return remote_rate_.get(); +} + void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int min_bitrate_bps) { CriticalSectionScoped cs(crit_sect_.get()); remote_rate_->SetMinBitrate(min_bitrate_bps); diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h index aa238d1e96..31d796225a 100644 --- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h +++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h @@ -52,6 +52,10 @@ class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator { void GetSsrcs(std::vector* ssrcs) const SHARED_LOCKS_REQUIRED(crit_sect_.get()); + // Returns |remote_rate_| if the pointed to object exists, + // otherwise creates it. + AimdRateControl* GetRemoteRate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get()); + Clock* clock_; SsrcOveruseEstimatorMap overuse_detectors_ GUARDED_BY(crit_sect_.get()); RateStatistics incoming_bitrate_ GUARDED_BY(crit_sect_.get());