From 7baa63ff9c35f2f0d9845316031bb33b859cd216 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Thu, 1 Sep 2022 15:39:50 +0200 Subject: [PATCH] peerconnection: invalidate stats cache during SLD/SRD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit which may allow caching some relatively persistent statistics such as codec statistics that only change during renegotiation. BUG=webrtc:8693 Change-Id: Ifd68c9d666d9f328d0efecb64e4201d003788ca8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273324 Commit-Queue: Philipp Hancke Reviewed-by: Henrik Boström Cr-Commit-Position: refs/heads/main@{#37981} --- api/peer_connection_interface.h | 2 -- pc/peer_connection.cc | 3 +++ pc/peer_connection_internal.h | 2 ++ pc/sdp_offer_answer.cc | 16 ++++++++-------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index 373b7586de..66a12f4fac 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -950,8 +950,6 @@ class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface { rtc::scoped_refptr selector, rtc::scoped_refptr callback) = 0; // Clear cached stats in the RTCStatsCollector. - // Exposed for testing while waiting for automatic cache clear to work. - // https://bugs.webrtc.org/8693 virtual void ClearStatsCache() {} // Create a data channel with the provided config, or default config if none diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 367341bbb3..1c0e695158 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -2985,6 +2985,9 @@ CryptoOptions PeerConnection::GetCryptoOptions() { void PeerConnection::ClearStatsCache() { RTC_DCHECK_RUN_ON(signaling_thread()); + if (legacy_stats_) { + legacy_stats_->InvalidateCache(); + } if (stats_collector_) { stats_collector_->ClearCachedStatsReport(); } diff --git a/pc/peer_connection_internal.h b/pc/peer_connection_internal.h index bc1ce183e7..1bca156316 100644 --- a/pc/peer_connection_internal.h +++ b/pc/peer_connection_internal.h @@ -125,6 +125,8 @@ class PeerConnectionSdpMethods { virtual void ResetSctpDataMid() = 0; virtual const FieldTrialsView& trials() const = 0; + + virtual void ClearStatsCache() = 0; }; // Functions defined in this class are called by other objects, diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc index 6936029b50..9a5023cd0b 100644 --- a/pc/sdp_offer_answer.cc +++ b/pc/sdp_offer_answer.cc @@ -1488,10 +1488,10 @@ RTCError SdpOfferAnswerHandler::ApplyLocalDescription( RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(desc); - // Invalidate the legacy stats cache to make sure that it gets updated next - // time getStats() gets called, as updating the session description affects - // the stats. - pc_->legacy_stats()->InvalidateCache(); + // Invalidate the stats caches to make sure that they get + // updated the next time getStats() gets called, as updating the session + // description affects the stats. + pc_->ClearStatsCache(); // Take a reference to the old local description since it's used below to // compare against the new local description. When setting the new local @@ -1823,10 +1823,10 @@ void SdpOfferAnswerHandler::ApplyRemoteDescription( RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(operation->description()); - // Invalidate the [legacy] stats cache to make sure that it gets updated next - // time getStats() gets called, as updating the session description affects - // the stats. - pc_->legacy_stats()->InvalidateCache(); + // Invalidate the stats caches to make sure that they get + // updated next time getStats() gets called, as updating the session + // description affects the stats. + pc_->ClearStatsCache(); if (!operation->ReplaceRemoteDescriptionAndCheckEror()) return;