Bug 1517711 - Check for a destroyed MediaStream on the right thread. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Tue, 08 Jan 2019 10:06:11 +0000
changeset 509975 f134e4af88f7ff8dc90160f1e2858767cfe8f751
parent 509974 bc5767b55411524f9e137e954bc7f863ab0680c4
child 509976 c2de6f3221df754e9ee2430b4ae269e8aa5e4c62
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1517711
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1517711 - Check for a destroyed MediaStream on the right thread. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D15892
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -567,22 +567,23 @@ nsresult MediaEngineWebRTCMicrophoneSour
   }
 
   mInputProcessing = new AudioInputProcessing(mDeviceMaxChannelCount, mStream,
                                               mTrackID, mPrincipal);
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
   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);
+        if (stream->IsDestroyed()) {
+          return NS_OK;
         }
 
+        stream->GraphImpl()->AppendMessage(MakeUnique<StartStopMessage>(
+            that->mInputProcessing, StartStopMessage::Start));
+        stream->SetPullingEnabled(track, true);
         stream->OpenAudioInput(deviceID, that->mInputProcessing);
 
         return NS_OK;
       }));
 
   ApplySettings(mCurrentPrefs);
 
   MOZ_ASSERT(mState != kReleased);
@@ -601,22 +602,23 @@ nsresult MediaEngineWebRTCMicrophoneSour
   if (mState == kStopped) {
     // Already stopped - this is allowed
     return NS_OK;
   }
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
   NS_DispatchToMainThread(
       media::NewRunnableFrom([that, stream = mStream, track = mTrackID]() {
-        if (MediaStreamGraphImpl* graph = stream->GraphImpl()) {
-          stream->SetPullingEnabled(track, false);
-          graph->AppendMessage(MakeUnique<StartStopMessage>(
-              that->mInputProcessing, StartStopMessage::Stop));
+        if (stream->IsDestroyed()) {
+          return NS_OK;
         }
 
+        stream->SetPullingEnabled(track, false);
+        stream->GraphImpl()->AppendMessage(MakeUnique<StartStopMessage>(
+            that->mInputProcessing, StartStopMessage::Stop));
         CubebUtils::AudioDeviceID deviceID = that->mDeviceInfo->DeviceID();
         Maybe<CubebUtils::AudioDeviceID> id = Some(deviceID);
         stream->CloseAudioInput(id, that->mInputProcessing);
 
         return NS_OK;
       }));
 
   MOZ_ASSERT(mState == kStarted, "Should be started when stopping");