Bug 1517711 - Guard other uses of SetPullingEnabled too. r=padenot, a=RyanVM
authorAndreas Pehrson <apehrson@mozilla.com>
Tue, 08 Jan 2019 10:06:08 +0000
changeset 506597 40a7055f712b38da3d8fe50e2481eb0d455f3796
parent 506596 d902ac21513900909c9673423827f16f76b12ada
child 506598 9886aad5caebd238622c3c625b0194de08f9664f
push id10476
push userryanvm@gmail.com
push dateWed, 09 Jan 2019 15:36:04 +0000
treeherdermozilla-beta@40a7055f712b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, RyanVM
bugs1517711
milestone65.0
Bug 1517711 - Guard other uses of SetPullingEnabled too. r=padenot, a=RyanVM Depends on D15892 Differential Revision: https://phabricator.services.mozilla.com/D15896
dom/media/MediaManager.cpp
dom/media/webrtc/MediaEngineDefault.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -4113,17 +4113,18 @@ SourceListener::InitializeAsync() {
                  MOZ_DIAGNOSTIC_ASSERT(!state->mTrackEnabled);
                  MOZ_DIAGNOSTIC_ASSERT(!state->mDeviceEnabled);
                  MOZ_DIAGNOSTIC_ASSERT(!state->mStopped);
 
                  state->mDeviceEnabled = true;
                  state->mTrackEnabled = true;
                  state->mTrackEnabledTime = TimeStamp::Now();
 
-                 if (state == mVideoDeviceState.get()) {
+                 if (state == mVideoDeviceState.get() &&
+                     !mStream->IsDestroyed()) {
                    mStream->SetPullingEnabled(kVideoTrack, true);
                  }
                }
                return SourceListenerPromise::CreateAndResolve(true, __func__);
              },
              [self = RefPtr<SourceListener>(this),
               this](RefPtr<MediaMgrError>&& aResult) {
                if (mStopped) {
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -456,16 +456,19 @@ nsresult MediaEngineDefaultAudioSource::
 
   {
     MutexAutoLock lock(mMutex);
     mState = kStarted;
   }
 
   NS_DispatchToMainThread(
       NS_NewRunnableFunction(__func__, [stream = mStream, track = mTrackID]() {
+        if (stream->IsDestroyed()) {
+          return;
+        }
         stream->SetPullingEnabled(track, true);
       }));
 
   return NS_OK;
 }
 
 nsresult MediaEngineDefaultAudioSource::Stop(
     const RefPtr<const AllocationHandle>& aHandle) {
@@ -479,16 +482,19 @@ nsresult MediaEngineDefaultAudioSource::
 
   {
     MutexAutoLock lock(mMutex);
     mState = kStopped;
   }
 
   NS_DispatchToMainThread(
       NS_NewRunnableFunction(__func__, [stream = mStream, track = mTrackID]() {
+        if (stream->IsDestroyed()) {
+          return;
+        }
         stream->SetPullingEnabled(track, false);
       }));
   return NS_OK;
 }
 
 nsresult MediaEngineDefaultAudioSource::Reconfigure(
     const RefPtr<AllocationHandle>& aHandle,
     const dom::MediaTrackConstraints& aConstraints,
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1470,26 +1470,32 @@ class GenericReceiveListener : public Me
             ("GenericReceiveListener added %s track %d (%p) to stream %p",
              mTrack->AsAudioStreamTrack() ? "audio" : "video", mTrackId,
              mTrack.get(), mSource.get()));
 
     mSource->AddTrackListener(this, mTrackId);
   }
 
   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);
     }
   }
 
   void OnRtpReceived() {
     if (mMaybeTrackNeedsUnmute) {
       mMaybeTrackNeedsUnmute = false;
       NS_DispatchToMainThread(