diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index fccd6df73a..3d0f664a19 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -897,6 +897,7 @@ void PeerConnection::DestroyAllChannels() { bool PeerConnection::Initialize( const PeerConnectionInterface::RTCConfiguration& configuration, PeerConnectionDependencies dependencies) { + RTC_DCHECK_RUN_ON(signaling_thread()); TRACE_EVENT0("webrtc", "PeerConnection::Initialize"); RTCError config_error = ValidateConfiguration(configuration); @@ -1155,6 +1156,7 @@ rtc::scoped_refptr PeerConnection::remote_streams() { } bool PeerConnection::AddStream(MediaStreamInterface* local_stream) { + RTC_DCHECK_RUN_ON(signaling_thread()); RTC_CHECK(!IsUnifiedPlan()) << "AddStream is not available with Unified Plan " "SdpSemantics. Please use AddTrack instead."; TRACE_EVENT0("webrtc", "PeerConnection::AddStream"); @@ -1190,6 +1192,7 @@ bool PeerConnection::AddStream(MediaStreamInterface* local_stream) { } void PeerConnection::RemoveStream(MediaStreamInterface* local_stream) { + RTC_DCHECK_RUN_ON(signaling_thread()); RTC_CHECK(!IsUnifiedPlan()) << "RemoveStream is not available with Unified " "Plan SdpSemantics. Please use RemoveTrack " "instead."; @@ -1220,6 +1223,7 @@ void PeerConnection::RemoveStream(MediaStreamInterface* local_stream) { RTCErrorOr> PeerConnection::AddTrack( rtc::scoped_refptr track, const std::vector& stream_ids) { + RTC_DCHECK_RUN_ON(signaling_thread()); TRACE_EVENT0("webrtc", "PeerConnection::AddTrack"); if (!track) { LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "Track is null."); @@ -1354,6 +1358,7 @@ bool PeerConnection::RemoveTrack(RtpSenderInterface* sender) { RTCError PeerConnection::RemoveTrackNew( rtc::scoped_refptr sender) { + RTC_DCHECK_RUN_ON(signaling_thread()); if (!sender) { LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, "Sender is null."); } @@ -1413,6 +1418,7 @@ RTCErrorOr> PeerConnection::AddTransceiver( rtc::scoped_refptr track, const RtpTransceiverInit& init) { + RTC_DCHECK_RUN_ON(signaling_thread()); RTC_CHECK(IsUnifiedPlan()) << "AddTransceiver is only available with Unified Plan SdpSemantics"; if (!track) { @@ -1438,6 +1444,7 @@ PeerConnection::AddTransceiver(cricket::MediaType media_type) { RTCErrorOr> PeerConnection::AddTransceiver(cricket::MediaType media_type, const RtpTransceiverInit& init) { + RTC_DCHECK_RUN_ON(signaling_thread()); RTC_CHECK(IsUnifiedPlan()) << "AddTransceiver is only available with Unified Plan SdpSemantics"; if (!(media_type == cricket::MEDIA_TYPE_AUDIO || @@ -1939,6 +1946,7 @@ void PeerConnection::RemoveRecvDirectionFromReceivingTransceiversOfType( void PeerConnection::AddUpToOneReceivingTransceiverOfType( cricket::MediaType media_type) { + RTC_DCHECK_RUN_ON(signaling_thread()); if (GetReceivingTransceiversOfType(media_type).empty()) { RTC_LOG(LS_INFO) << "Adding one recvonly " << cricket::MediaTypeToString(media_type) @@ -3375,6 +3383,7 @@ bool PeerConnection::SetConfiguration(const RTCConfiguration& configuration, bool PeerConnection::AddIceCandidate( const IceCandidateInterface* ice_candidate) { + RTC_DCHECK_RUN_ON(signaling_thread()); TRACE_EVENT0("webrtc", "PeerConnection::AddIceCandidate"); if (IsClosed()) { RTC_LOG(LS_ERROR) << "AddIceCandidate: PeerConnection is closed."; @@ -3651,6 +3660,7 @@ const SessionDescriptionInterface* PeerConnection::pending_remote_description() } void PeerConnection::Close() { + RTC_DCHECK_RUN_ON(signaling_thread()); TRACE_EVENT0("webrtc", "PeerConnection::Close"); // Update stats here so that we have the most recent stats for tracks and // streams before the channels are closed. @@ -3697,6 +3707,7 @@ void PeerConnection::Close() { } void PeerConnection::OnMessage(rtc::Message* msg) { + RTC_DCHECK_RUN_ON(signaling_thread()); switch (msg->message_id) { case MSG_SET_SESSIONDESCRIPTION_SUCCESS: { SetSessionDescriptionMsg* param = @@ -3900,7 +3911,6 @@ void PeerConnection::RemoveVideoTrack(VideoTrackInterface* track, } void PeerConnection::SetIceConnectionState(IceConnectionState new_state) { - RTC_DCHECK(signaling_thread()->IsCurrent()); if (ice_connection_state_ == new_state) { return; } @@ -3922,7 +3932,6 @@ void PeerConnection::SetIceConnectionState(IceConnectionState new_state) { void PeerConnection::SetStandardizedIceConnectionState( PeerConnectionInterface::IceConnectionState new_state) { - RTC_DCHECK(signaling_thread()->IsCurrent()); if (standardized_ice_connection_state_ == new_state) return; if (IsClosed()) @@ -3933,7 +3942,6 @@ void PeerConnection::SetStandardizedIceConnectionState( void PeerConnection::SetConnectionState( PeerConnectionInterface::PeerConnectionState new_state) { - RTC_DCHECK(signaling_thread()->IsCurrent()); if (connection_state_ == new_state) return; if (IsClosed()) @@ -3944,7 +3952,6 @@ void PeerConnection::SetConnectionState( void PeerConnection::OnIceGatheringChange( PeerConnectionInterface::IceGatheringState new_state) { - RTC_DCHECK(signaling_thread()->IsCurrent()); if (IsClosed()) { return; } @@ -3954,7 +3961,6 @@ void PeerConnection::OnIceGatheringChange( void PeerConnection::OnIceCandidate( std::unique_ptr candidate) { - RTC_DCHECK(signaling_thread()->IsCurrent()); if (IsClosed()) { return; } @@ -3968,7 +3974,6 @@ void PeerConnection::OnIceCandidate( void PeerConnection::OnIceCandidatesRemoved( const std::vector& candidates) { - RTC_DCHECK(signaling_thread()->IsCurrent()); if (IsClosed()) { return; } @@ -3977,7 +3982,6 @@ void PeerConnection::OnIceCandidatesRemoved( void PeerConnection::ChangeSignalingState( PeerConnectionInterface::SignalingState signaling_state) { - RTC_DCHECK(signaling_thread()->IsCurrent()); if (signaling_state_ == signaling_state) { return; } @@ -5876,7 +5880,6 @@ void PeerConnection::OnTransportControllerConnectionState( void PeerConnection::OnTransportControllerCandidatesGathered( const std::string& transport_name, const cricket::Candidates& candidates) { - RTC_DCHECK(signaling_thread()->IsCurrent()); int sdp_mline_index; if (!GetLocalCandidateMediaIndex(transport_name, &sdp_mline_index)) { RTC_LOG(LS_ERROR) @@ -5899,7 +5902,6 @@ void PeerConnection::OnTransportControllerCandidatesGathered( void PeerConnection::OnTransportControllerCandidatesRemoved( const std::vector& candidates) { - RTC_DCHECK(signaling_thread()->IsCurrent()); // Sanity check. for (const cricket::Candidate& candidate : candidates) { if (candidate.transport_name().empty()) { diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 660788fb80..321acde834 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -321,10 +321,12 @@ class PeerConnection : public PeerConnectionInternal, GetFirstAudioTransceiver() const; void CreateAudioReceiver(MediaStreamInterface* stream, - const RtpSenderInfo& remote_sender_info); + const RtpSenderInfo& remote_sender_info) + RTC_RUN_ON(signaling_thread()); void CreateVideoReceiver(MediaStreamInterface* stream, - const RtpSenderInfo& remote_sender_info); + const RtpSenderInfo& remote_sender_info) + RTC_RUN_ON(signaling_thread()); rtc::scoped_refptr RemoveAndStopReceiver( const RtpSenderInfo& remote_sender_info); @@ -361,7 +363,7 @@ class PeerConnection : public PeerConnectionInternal, cricket::MediaType media_type, rtc::scoped_refptr track, const RtpTransceiverInit& init, - bool fire_callback = true); + bool fire_callback = true) RTC_RUN_ON(signaling_thread()); rtc::scoped_refptr> CreateSender(cricket::MediaType media_type, @@ -381,32 +383,42 @@ class PeerConnection : public PeerConnectionInternal, rtc::scoped_refptr> receiver); - void SetIceConnectionState(IceConnectionState new_state); + void SetIceConnectionState(IceConnectionState new_state) + RTC_RUN_ON(signaling_thread()); void SetStandardizedIceConnectionState( - PeerConnectionInterface::IceConnectionState new_state); + PeerConnectionInterface::IceConnectionState new_state) + RTC_RUN_ON(signaling_thread()); void SetConnectionState( - PeerConnectionInterface::PeerConnectionState new_state); + PeerConnectionInterface::PeerConnectionState new_state) + RTC_RUN_ON(signaling_thread()); // Called any time the IceGatheringState changes - void OnIceGatheringChange(IceGatheringState new_state); + void OnIceGatheringChange(IceGatheringState new_state) + RTC_RUN_ON(signaling_thread()); // New ICE candidate has been gathered. - void OnIceCandidate(std::unique_ptr candidate); + void OnIceCandidate(std::unique_ptr candidate) + RTC_RUN_ON(signaling_thread()); // Some local ICE candidates have been removed. - void OnIceCandidatesRemoved( - const std::vector& candidates); + void OnIceCandidatesRemoved(const std::vector& candidates) + RTC_RUN_ON(signaling_thread()); // Update the state, signaling if necessary. - void ChangeSignalingState(SignalingState signaling_state); + void ChangeSignalingState(SignalingState signaling_state) + RTC_RUN_ON(signaling_thread()); // Signals from MediaStreamObserver. void OnAudioTrackAdded(AudioTrackInterface* track, - MediaStreamInterface* stream); + MediaStreamInterface* stream) + RTC_RUN_ON(signaling_thread()); void OnAudioTrackRemoved(AudioTrackInterface* track, - MediaStreamInterface* stream); + MediaStreamInterface* stream) + RTC_RUN_ON(signaling_thread()); void OnVideoTrackAdded(VideoTrackInterface* track, - MediaStreamInterface* stream); + MediaStreamInterface* stream) + RTC_RUN_ON(signaling_thread()); void OnVideoTrackRemoved(VideoTrackInterface* track, - MediaStreamInterface* stream); + MediaStreamInterface* stream) + RTC_RUN_ON(signaling_thread()); void PostSetSessionDescriptionSuccess( SetSessionDescriptionObserver* observer); @@ -576,7 +588,8 @@ class PeerConnection : public PeerConnectionInternal, // Remove all local and remote senders of type |media_type|. // Called when a media type is rejected (m-line set to port 0). - void RemoveSenders(cricket::MediaType media_type); + void RemoveSenders(cricket::MediaType media_type) + RTC_RUN_ON(signaling_thread()); // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, // and existing MediaStreamTracks are removed if there is no corresponding @@ -588,24 +601,26 @@ class PeerConnection : public PeerConnectionInternal, const std::vector& streams, bool default_track_needed, cricket::MediaType media_type, - StreamCollection* new_streams); + StreamCollection* new_streams) RTC_RUN_ON(signaling_thread()); // Triggered when a remote sender has been seen for the first time in a remote // session description. It creates a remote MediaStreamTrackInterface // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. void OnRemoteSenderAdded(const RtpSenderInfo& sender_info, - cricket::MediaType media_type); + cricket::MediaType media_type) + RTC_RUN_ON(signaling_thread()); // Triggered when a remote sender has been removed from a remote session // description. It removes the remote sender with id |sender_id| from a remote // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. void OnRemoteSenderRemoved(const RtpSenderInfo& sender_info, - cricket::MediaType media_type); + cricket::MediaType media_type) + RTC_RUN_ON(signaling_thread()); // Finds remote MediaStreams without any tracks and removes them from // |remote_streams_| and notifies the observer that the MediaStreams no longer // exist. - void UpdateEndedRemoteMediaStreams(); + void UpdateEndedRemoteMediaStreams() RTC_RUN_ON(signaling_thread()); // Loops through the vector of |streams| and finds added and removed // StreamParams since last time this method was called. @@ -831,9 +846,11 @@ class PeerConnection : public PeerConnectionInternal, int* sdp_mline_index); // Uses all remote candidates in |remote_desc| in this session. bool UseCandidatesInSessionDescription( - const SessionDescriptionInterface* remote_desc); + const SessionDescriptionInterface* remote_desc) + RTC_RUN_ON(signaling_thread()); // Uses |candidate| in this session. - bool UseCandidate(const IceCandidateInterface* candidate); + bool UseCandidate(const IceCandidateInterface* candidate) + RTC_RUN_ON(signaling_thread()); // Deletes the corresponding channel of contents that don't exist in |desc|. // |desc| can be null. This means that all channels are deleted. void RemoveUnusedChannels(const cricket::SessionDescription* desc); @@ -908,13 +925,17 @@ class PeerConnection : public PeerConnectionInternal, bool SrtpRequired() const; // JsepTransportController signal handlers. - void OnTransportControllerConnectionState(cricket::IceConnectionState state); - void OnTransportControllerGatheringState(cricket::IceGatheringState state); + void OnTransportControllerConnectionState(cricket::IceConnectionState state) + RTC_RUN_ON(signaling_thread()); + void OnTransportControllerGatheringState(cricket::IceGatheringState state) + RTC_RUN_ON(signaling_thread()); void OnTransportControllerCandidatesGathered( const std::string& transport_name, - const std::vector& candidates); + const std::vector& candidates) + RTC_RUN_ON(signaling_thread()); void OnTransportControllerCandidatesRemoved( - const std::vector& candidates); + const std::vector& candidates) + RTC_RUN_ON(signaling_thread()); void OnTransportControllerDtlsHandshakeError(rtc::SSLHandshakeError error); const char* SessionErrorToString(SessionError error) const; @@ -938,7 +959,7 @@ class PeerConnection : public PeerConnectionInternal, const std::set& media_types); void NoteUsageEvent(UsageEvent event); - void ReportUsagePattern() const; + void ReportUsagePattern() const RTC_RUN_ON(signaling_thread()); void OnSentPacket_w(const rtc::SentPacket& sent_packet); @@ -969,7 +990,7 @@ class PeerConnection : public PeerConnectionInternal, MediaTransportInterface* media_transport) override; // Returns the observer. Will crash on CHECK if the observer is removed. - PeerConnectionObserver* Observer() const; + PeerConnectionObserver* Observer() const RTC_RUN_ON(signaling_thread()); // Returns the CryptoOptions for this PeerConnection. This will always // return the RTCConfiguration.crypto_options if set and will only default @@ -1007,8 +1028,9 @@ class PeerConnection : public PeerConnectionInternal, // However, since the reference counting is done in the // PeerConnectionFactoryInterface all instances created using the raw pointer // will refer to the same reference count. - rtc::scoped_refptr factory_; - PeerConnectionObserver* observer_ = nullptr; + const rtc::scoped_refptr factory_; + PeerConnectionObserver* observer_ RTC_GUARDED_BY(signaling_thread()) = + nullptr; // The EventLog needs to outlive |call_| (and any other object that uses it). std::unique_ptr event_log_;