From ddfbf6cc1967b361e5c59117600de1b25ae668e2 Mon Sep 17 00:00:00 2001 From: Tomas Gunnarsson Date: Mon, 3 Jan 2022 21:30:26 +0000 Subject: [PATCH] Restrict access to `BaseChannel::previous_demuxer_criteria_`. Make sure previous_demuxer_criteria_ is only accessed on the network thread and add annotation. Bug: webrtc:11993, webrtc:12230 Change-Id: I4700fe41c947a3b1cce9649642dcd38ed62f873d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/244087 Reviewed-by: Niels Moller Commit-Queue: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#35618} --- pc/channel.cc | 8 +++----- pc/channel.h | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pc/channel.cc b/pc/channel.cc index 745a380051..032c7356f4 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -488,11 +488,6 @@ void BaseChannel::UpdateRtpHeaderExtensionMap( } bool BaseChannel::RegisterRtpDemuxerSink_w() { - // TODO(bugs.webrtc.org/11993): `previous_demuxer_criteria_` should only be - // accessed on the network thread. - if (demuxer_criteria_ == previous_demuxer_criteria_) { - return true; - } media_channel_->OnDemuxerCriteriaUpdatePending(); // Copy demuxer criteria, since they're a worker-thread variable // and we want to pass them to the network thread @@ -500,6 +495,9 @@ bool BaseChannel::RegisterRtpDemuxerSink_w() { RTC_FROM_HERE, [this, demuxer_criteria = demuxer_criteria_] { RTC_DCHECK_RUN_ON(network_thread()); RTC_DCHECK(rtp_transport_); + if (demuxer_criteria_ == previous_demuxer_criteria_) + return true; + bool result = rtp_transport_->RegisterRtpDemuxerSink(demuxer_criteria, this); if (result) { diff --git a/pc/channel.h b/pc/channel.h index fa4a26e96f..7f7cfb9b8e 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -357,7 +357,8 @@ class BaseChannel : public ChannelInterface, webrtc::RtpDemuxerCriteria demuxer_criteria_; // Accessed on the worker thread, modified on the network thread from // RegisterRtpDemuxerSink_w's Invoke. - webrtc::RtpDemuxerCriteria previous_demuxer_criteria_; + webrtc::RtpDemuxerCriteria previous_demuxer_criteria_ + RTC_GUARDED_BY(network_thread()); // This generator is used to generate SSRCs for local streams. // This is needed in cases where SSRCs are not negotiated or set explicitly // like in Simulcast.