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 <nisse@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35618}
diff --git a/pc/channel.cc b/pc/channel.cc
index 745a380..032c735 100644
--- a/pc/channel.cc
+++ b/pc/channel.cc
@@ -488,11 +488,6 @@
 }
 
 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 @@
       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 fa4a26e..7f7cfb9 100644
--- a/pc/channel.h
+++ b/pc/channel.h
@@ -357,7 +357,8 @@
   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.