Bug 1423241 - Handle DOMMediaStream destroying its input stream before we can end its track. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 23 Nov 2018 15:03:39 +0000
changeset 504289 6be5d281ae921fca461799ba5168599b480cd7e5
parent 504288 0c83ce85257f084614b5824836874d717ca53210
child 504290 9ef539ed2f409a3844cbbadc681ea209af44bca5
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1423241
milestone65.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 1423241 - Handle DOMMediaStream destroying its input stream before we can end its track. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D12746
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -468,26 +468,29 @@ nsresult MediaEngineWebRTCMicrophoneSour
 
    protected:
     RefPtr<AudioInputProcessing> mInputProcessing;
     TrackID mTrackID;
   };
 
   if (mStream && IsTrackIDExplicit(mTrackID)) {
     RefPtr<MediaStream> sourceStream = mStream;
-    RefPtr<MediaStreamGraphImpl> graphImpl = mStream->GraphImpl();
     RefPtr<AudioInputProcessing> inputProcessing = mInputProcessing;
     NS_DispatchToMainThread(media::NewRunnableFrom(
-        [graph = std::move(graphImpl), stream = std::move(sourceStream),
+        [stream = std::move(sourceStream),
          audioInputProcessing = std::move(inputProcessing),
          trackID = mTrackID]() mutable {
-          if (graph) {
-            graph->AppendMessage(MakeUnique<EndTrackMessage>(
-                stream, audioInputProcessing, trackID));
+          if (stream->IsDestroyed()) {
+            // This stream has already been destroyed on main thread by its
+            // DOMMediaStream. No cleanup left to do.
+            return NS_OK;
           }
+          MOZ_ASSERT(stream->GraphImpl());
+          stream->GraphImpl()->AppendMessage(MakeUnique<EndTrackMessage>(
+              stream, audioInputProcessing, trackID));
           return NS_OK;
         }));
   }
 
   MOZ_ASSERT(mTrackID != TRACK_NONE, "Only deallocate once");
 
   // Reset all state. This is not strictly necessary, this instance will get
   // destroyed soon.