Bug 1435673 - Clean up WebRTCAudioDataListener in Deallocate(). r?padenot draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Mon, 05 Feb 2018 10:52:47 +0100
changeset 751090 1ba19c27797cac2c72ae422c6cffc50e434e4d9e
parent 751089 ef7e7c44906b4c319e21eb9903feb41db820b537
child 751091 11d3c00e215045bb64f1745e842050e9967b8f19
push id97847
push userbmo:apehrson@mozilla.com
push dateMon, 05 Feb 2018 10:00:19 +0000
reviewerspadenot
bugs1435673
milestone60.0a1
Bug 1435673 - Clean up WebRTCAudioDataListener in Deallocate(). r?padenot MozReview-Commit-ID: LKRbMHFXtSq
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -612,16 +612,21 @@ MediaEngineWebRTCMicrophoneSource::Deall
   if (mAllocations.IsEmpty()) {
     // If empty, no callbacks to deliver data should be occuring
     MOZ_ASSERT(mState != kReleased, "Source not allocated");
     MOZ_ASSERT(mState != kStarted, "Source not stopped");
     MOZ_ASSERT(sChannelsOpen > 0);
     --sChannelsOpen;
 
     MutexAutoLock lock(mMutex);
+    if (mListener) {
+      // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
+      mListener->Shutdown();
+      mListener = nullptr;
+    }
     mState = kReleased;
     LOG(("Audio device %d deallocated", mCapIndex));
   } else {
     LOG(("Audio device %d deallocated but still in use", mCapIndex));
   }
   return NS_OK;
 }
 
@@ -743,22 +748,16 @@ MediaEngineWebRTCMicrophoneSource::Stop(
       // Another track is keeping us from stopping
       return NS_OK;
     }
 
     MOZ_ASSERT(mState == kStarted, "Should be started when stopping");
     mState = kStopped;
   }
 
-  if (mListener) {
-    // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
-    mListener->Shutdown();
-    mListener = nullptr;
-  }
-
   return NS_OK;
 }
 
 void
 MediaEngineWebRTCMicrophoneSource::Pull(const RefPtr<const AllocationHandle>& aHandle,
                                         const RefPtr<SourceMediaStream>& aStream,
                                         TrackID aTrackID,
                                         StreamTime aDesiredTime,
@@ -1132,23 +1131,16 @@ MediaEngineWebRTCMicrophoneSource::Devic
   ResetProcessingIfNeeded(noise_suppression);
 }
 
 void
 MediaEngineWebRTCMicrophoneSource::Shutdown()
 {
   AssertIsOnOwningThread();
 
-  if (mListener) {
-    // breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
-    mListener->Shutdown();
-    // Don't release the webrtc.org pointers yet until the Listener is (async) shutdown
-    mListener = nullptr;
-  }
-
   if (mState == kStarted) {
     for (const Allocation& allocation : mAllocations) {
       if (allocation.mEnabled) {
         Stop(allocation.mHandle);
       }
     }
     MOZ_ASSERT(mState == kStopped);
   }