diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 6d3b2cd16ed9..2468d572807c 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -4193,7 +4193,8 @@ SourceListener::InitializeAsync() { state->mTrackEnabled = true; state->mTrackEnabledTime = TimeStamp::Now(); - if (state == mVideoDeviceState.get()) { + if (state == mVideoDeviceState.get() && + !mStream->IsDestroyed()) { mStream->SetPullingEnabled(kVideoTrack, true); } } diff --git a/dom/media/webrtc/MediaEngineDefault.cpp b/dom/media/webrtc/MediaEngineDefault.cpp index c6e596308ac5..029d09681648 100644 --- a/dom/media/webrtc/MediaEngineDefault.cpp +++ b/dom/media/webrtc/MediaEngineDefault.cpp @@ -461,6 +461,9 @@ nsresult MediaEngineDefaultAudioSource::Start( NS_DispatchToMainThread( NS_NewRunnableFunction(__func__, [stream = mStream, track = mTrackID]() { + if (stream->IsDestroyed()) { + return; + } stream->SetPullingEnabled(track, true); })); @@ -484,6 +487,9 @@ nsresult MediaEngineDefaultAudioSource::Stop( NS_DispatchToMainThread( NS_NewRunnableFunction(__func__, [stream = mStream, track = mTrackID]() { + if (stream->IsDestroyed()) { + return; + } stream->SetPullingEnabled(track, false); })); return NS_OK; diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 5666c1d4ed2f..48140e4ddbd6 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -1475,16 +1475,22 @@ class GenericReceiveListener : public MediaStreamTrackListener { } void AddSelf() { - if (!mListening) { - mListening = true; + if (mListening) { + return; + } + mListening = true; + mMaybeTrackNeedsUnmute = true; + if (!mSource->IsDestroyed()) { mSource->SetPullingEnabled(mTrackId, true); - mMaybeTrackNeedsUnmute = true; } } void RemoveSelf() { - if (mListening) { - mListening = false; + if (!mListening) { + return; + } + mListening = false; + if (!mSource->IsDestroyed()) { mSource->SetPullingEnabled(mTrackId, false); } }