From ebb50c217dcf49ab0d654a9fc8cadd1cb5b057c6 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Thu, 22 Nov 2018 14:04:02 +0100 Subject: [PATCH] Fix setting max reordering threshold in ReceiveStatistics By ensuring new max reordering threshold applies to future statisticians too. Bug: b/38179459 Change-Id: I0df32fb893a930b93faaf2161cd03626f9544a74 Reviewed-on: https://webrtc-review.googlesource.com/c/111752 Reviewed-by: Stefan Holmer Reviewed-by: Niels Moller Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/master@{#25756} --- .../rtp_rtcp/source/receive_statistics_impl.cc | 18 +++++++++++++----- .../rtp_rtcp/source/receive_statistics_impl.h | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/rtp_rtcp/source/receive_statistics_impl.cc b/modules/rtp_rtcp/source/receive_statistics_impl.cc index 34356e3455..30a0f360f6 100644 --- a/modules/rtp_rtcp/source/receive_statistics_impl.cc +++ b/modules/rtp_rtcp/source/receive_statistics_impl.cc @@ -33,13 +33,14 @@ StreamStatisticianImpl::StreamStatisticianImpl( uint32_t ssrc, Clock* clock, bool enable_retransmit_detection, + int max_reordering_threshold, RtcpStatisticsCallback* rtcp_callback, StreamDataCountersCallback* rtp_callback) : ssrc_(ssrc), clock_(clock), incoming_bitrate_(kStatisticsProcessIntervalMs, RateStatistics::kBpsScale), - max_reordering_threshold_(kDefaultMaxReorderingThreshold), + max_reordering_threshold_(max_reordering_threshold), enable_retransmit_detection_(enable_retransmit_detection), jitter_q4_(0), cumulative_loss_(0), @@ -340,6 +341,7 @@ ReceiveStatistics* ReceiveStatistics::Create(Clock* clock) { ReceiveStatisticsImpl::ReceiveStatisticsImpl(Clock* clock) : clock_(clock), last_returned_ssrc_(0), + max_reordering_threshold_(kDefaultMaxReorderingThreshold), rtcp_stats_callback_(NULL), rtp_stats_callback_(NULL) {} @@ -360,7 +362,7 @@ void ReceiveStatisticsImpl::OnRtpPacket(const RtpPacketReceived& packet) { } else { impl = new StreamStatisticianImpl( packet.Ssrc(), clock_, /* enable_retransmit_detection = */ false, - this, this); + max_reordering_threshold_, this, this); statisticians_[packet.Ssrc()] = impl; } } @@ -395,8 +397,13 @@ StreamStatistician* ReceiveStatisticsImpl::GetStatistician( void ReceiveStatisticsImpl::SetMaxReorderingThreshold( int max_reordering_threshold) { - rtc::CritScope cs(&receive_statistics_lock_); - for (auto& statistician : statisticians_) { + std::map statisticians; + { + rtc::CritScope cs(&receive_statistics_lock_); + max_reordering_threshold_ = max_reordering_threshold; + statisticians = statisticians_; + } + for (auto& statistician : statisticians) { statistician.second->SetMaxReorderingThreshold(max_reordering_threshold); } } @@ -408,7 +415,8 @@ void ReceiveStatisticsImpl::EnableRetransmitDetection(uint32_t ssrc, rtc::CritScope cs(&receive_statistics_lock_); StreamStatisticianImpl*& impl_ref = statisticians_[ssrc]; if (impl_ref == nullptr) { // new element - impl_ref = new StreamStatisticianImpl(ssrc, clock_, enable, this, this); + impl_ref = new StreamStatisticianImpl( + ssrc, clock_, enable, max_reordering_threshold_, this, this); return; } impl = impl_ref; diff --git a/modules/rtp_rtcp/source/receive_statistics_impl.h b/modules/rtp_rtcp/source/receive_statistics_impl.h index 56e263fe58..f6aec69ffb 100644 --- a/modules/rtp_rtcp/source/receive_statistics_impl.h +++ b/modules/rtp_rtcp/source/receive_statistics_impl.h @@ -19,6 +19,7 @@ #include "rtc_base/criticalsection.h" #include "rtc_base/rate_statistics.h" +#include "rtc_base/thread_annotations.h" #include "system_wrappers/include/ntp_time.h" namespace webrtc { @@ -29,6 +30,7 @@ class StreamStatisticianImpl : public StreamStatistician, StreamStatisticianImpl(uint32_t ssrc, Clock* clock, bool enable_retransmit_detection, + int max_reordering_threshold, RtcpStatisticsCallback* rtcp_callback, StreamDataCountersCallback* rtp_callback); ~StreamStatisticianImpl() override; @@ -128,7 +130,9 @@ class ReceiveStatisticsImpl : public ReceiveStatistics, Clock* const clock_; rtc::CriticalSection receive_statistics_lock_; uint32_t last_returned_ssrc_; - std::map statisticians_; + int max_reordering_threshold_ RTC_GUARDED_BY(receive_statistics_lock_); + std::map statisticians_ + RTC_GUARDED_BY(receive_statistics_lock_); RtcpStatisticsCallback* rtcp_stats_callback_; StreamDataCountersCallback* rtp_stats_callback_;