Add thread safety annotations for some more PeerConnection members (part 4)

Plus all the annotations that were necessary to make things compile
again.

Bug: webrtc:9987
Change-Id: Ia421e4dc0e1bbc81c3976cc7530d44de934d33bb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128882
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27257}
diff --git a/pc/peer_connection.h b/pc/peer_connection.h
index 07419bf..5fa8da5 100644
--- a/pc/peer_connection.h
+++ b/pc/peer_connection.h
@@ -246,6 +246,7 @@
 
   std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels()
       const override {
+    RTC_DCHECK_RUN_ON(signaling_thread());
     return sctp_data_channels_;
   }
 
@@ -594,17 +595,18 @@
       absl::optional<size_t>* audio_index,
       absl::optional<size_t>* video_index,
       absl::optional<size_t>* data_index,
-      cricket::MediaSessionOptions* session_options);
+      cricket::MediaSessionOptions* session_options)
+      RTC_RUN_ON(signaling_thread());
 
   // Generates the active MediaDescriptionOptions for the local data channel
   // given the specified MID.
   cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData(
-      const std::string& mid) const;
+      const std::string& mid) const RTC_RUN_ON(signaling_thread());
 
   // Generates the rejected MediaDescriptionOptions for the local data channel
   // given the specified MID.
   cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData(
-      const std::string& mid) const;
+      const std::string& mid) const RTC_RUN_ON(signaling_thread());
 
   // Returns the MID for the data section associated with either the
   // RtpDataChannel or SCTP data channel, if it has been set. If no data
@@ -672,12 +674,13 @@
   void OnLocalSenderRemoved(const RtpSenderInfo& sender_info,
                             cricket::MediaType media_type);
 
-  void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams);
+  void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams)
+      RTC_RUN_ON(signaling_thread());
   void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams)
       RTC_RUN_ON(signaling_thread());
   void UpdateClosingRtpDataChannels(
       const std::vector<std::string>& active_channels,
-      bool is_local_update);
+      bool is_local_update) RTC_RUN_ON(signaling_thread());
   void CreateRemoteRtpDataChannel(const std::string& label,
                                   uint32_t remote_ssrc)
       RTC_RUN_ON(signaling_thread());
@@ -689,12 +692,13 @@
       const InternalDataChannelInit* config) RTC_RUN_ON(signaling_thread());
 
   // Checks if any data channel has been added.
-  bool HasDataChannels() const;
+  bool HasDataChannels() const RTC_RUN_ON(signaling_thread());
 
-  void AllocateSctpSids(rtc::SSLRole role);
-  void OnSctpDataChannelClosed(DataChannel* channel);
+  void AllocateSctpSids(rtc::SSLRole role) RTC_RUN_ON(signaling_thread());
+  void OnSctpDataChannelClosed(DataChannel* channel)
+      RTC_RUN_ON(signaling_thread());
 
-  void OnDataChannelDestroyed();
+  void OnDataChannelDestroyed() RTC_RUN_ON(signaling_thread());
   // Called when a valid data channel OPEN message is received.
   void OnDataChannelOpenMessage(const std::string& label,
                                 const InternalDataChannelInit& config)
@@ -749,7 +753,8 @@
 
   // Returns the specified SCTP DataChannel in sctp_data_channels_,
   // or nullptr if not found.
-  DataChannel* FindDataChannelBySid(int sid) const;
+  DataChannel* FindDataChannelBySid(int sid) const
+      RTC_RUN_ON(signaling_thread());
 
   // Called when first configuring the port allocator.
   struct InitializePortAllocatorResult {
@@ -869,7 +874,7 @@
   void EnableSending();
 
   // Destroys all BaseChannels and destroys the SCTP data channel, if present.
-  void DestroyAllChannels();
+  void DestroyAllChannels() RTC_RUN_ON(signaling_thread());
 
   // Returns the media index for a local ice candidate given the content name.
   // Returns false if the local session description does not have a media
@@ -1010,7 +1015,7 @@
           transceiver);
 
   // Destroys the RTP data channel and/or the SCTP data channel and clears it.
-  void DestroyDataChannel();
+  void DestroyDataChannel() RTC_RUN_ON(signaling_thread());
 
   // Destroys the given ChannelInterface.
   // The channel cannot be accessed after this method is called.
@@ -1134,13 +1139,16 @@
   std::vector<RtpSenderInfo> local_video_sender_infos_
       RTC_GUARDED_BY(signaling_thread());
 
-  SctpSidAllocator sid_allocator_;
+  SctpSidAllocator sid_allocator_ RTC_GUARDED_BY(signaling_thread());
   // label -> DataChannel
-  std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_;
-  std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_;
-  std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_;
+  std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_
+      RTC_GUARDED_BY(signaling_thread());
+  std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_
+      RTC_GUARDED_BY(signaling_thread());
+  std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_
+      RTC_GUARDED_BY(signaling_thread());
 
-  bool remote_peer_supports_msid_ = false;
+  bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false;
 
   std::unique_ptr<Call> call_;
   std::unique_ptr<StatsCollector> stats_;  // A pointer is passed to senders_