Bug 1517710 - Avoid calling SetPullingEnabled on a destroyed MediaStream. r=padenot, a=RyanVM
authorAndreas Pehrson <apehrson@mozilla.com>
Mon, 07 Jan 2019 08:24:08 +0000
changeset 506551 dac16eb67fd6c9fc34d50269a064c8c9a9dbca76
parent 506550 61fc844e1f4848cdc47c8056f8d9e76795cecaca
child 506552 467d52576809bb88da1bc38d74ffc88671088c04
push id10457
push userryanvm@gmail.com
push dateMon, 07 Jan 2019 15:23:57 +0000
treeherdermozilla-beta@dac16eb67fd6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, RyanVM
bugs1517710
milestone65.0
Bug 1517710 - Avoid calling SetPullingEnabled on a destroyed MediaStream. r=padenot, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D15798
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -570,27 +570,25 @@ nsresult MediaEngineWebRTCMicrophoneSour
     // because we can only have one MSG per document.
     return NS_ERROR_FAILURE;
   }
 
   mInputProcessing = new AudioInputProcessing(mDeviceMaxChannelCount, mStream,
                                               mTrackID, mPrincipal);
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
-  NS_DispatchToMainThread(
-      media::NewRunnableFrom([that, graph = std::move(gripGraph), deviceID,
-                              stream = mStream, track = mTrackID]() {
-        if (graph) {
+  NS_DispatchToMainThread(media::NewRunnableFrom(
+      [that, deviceID, stream = mStream, track = mTrackID]() {
+        if (MediaStreamGraphImpl* graph = stream->GraphImpl()) {
           graph->AppendMessage(MakeUnique<StartStopMessage>(
               that->mInputProcessing, StartStopMessage::Start));
+          stream->SetPullingEnabled(track, true);
         }
 
         stream->OpenAudioInput(deviceID, that->mInputProcessing);
-        stream->SetPullingEnabled(track, true);
 
         return NS_OK;
       }));
 
   ApplySettings(mCurrentPrefs);
 
   MOZ_ASSERT(mState != kReleased);
   mState = kStarted;
@@ -607,29 +605,27 @@ nsresult MediaEngineWebRTCMicrophoneSour
   MOZ_ASSERT(mStream, "SetTrack must have been called before ::Stop");
 
   if (mState == kStopped) {
     // Already stopped - this is allowed
     return NS_OK;
   }
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> gripGraph = mStream->GraphImpl();
   NS_DispatchToMainThread(
-      media::NewRunnableFrom([that, graph = std::move(gripGraph),
-                              stream = mStream, track = mTrackID]() {
-        if (graph) {
+      media::NewRunnableFrom([that, stream = mStream, track = mTrackID]() {
+        if (MediaStreamGraphImpl* graph = stream->GraphImpl()) {
+          stream->SetPullingEnabled(track, false);
           graph->AppendMessage(MakeUnique<StartStopMessage>(
               that->mInputProcessing, StartStopMessage::Stop));
         }
 
         CubebUtils::AudioDeviceID deviceID = that->mDeviceInfo->DeviceID();
         Maybe<CubebUtils::AudioDeviceID> id = Some(deviceID);
         stream->CloseAudioInput(id, that->mInputProcessing);
-        stream->SetPullingEnabled(track, false);
 
         return NS_OK;
       }));
 
   MOZ_ASSERT(mState == kStarted, "Should be started when stopping");
   mState = kStopped;
 
   return NS_OK;