diff --git a/dom/media/MediaTrackGraph.cpp b/dom/media/MediaTrackGraph.cpp index a7208d06c528..42d66530983f 100644 --- a/dom/media/MediaTrackGraph.cpp +++ b/dom/media/MediaTrackGraph.cpp @@ -1618,9 +1618,8 @@ class MediaTrackGraphShutDownRunnable : public Runnable { // mGraph is no longer needed, so delete it. mGraph->Destroy(); } else { - // The graph is not empty. We must be in a forced shutdown, either for - // process shutdown or a non-realtime graph that has finished - // processing. Some later AppendMessage will detect that the graph has + // The graph is not empty. We must be in a forced shutdown. + // Some later AppendMessage will detect that the graph has // been emptied, and delete it. NS_ASSERTION(mGraph->mForceShutDownReceived, "Not in forced shutdown?"); mGraph->LifecycleStateRef() = @@ -3129,12 +3128,10 @@ MediaTrackGraph* MediaTrackGraph::CreateNonRealtimeInstance( return graph; } -void MediaTrackGraph::DestroyNonRealtimeInstance(MediaTrackGraph* aGraph) { +void MediaTrackGraph::ForceShutDown() { MOZ_ASSERT(NS_IsMainThread(), "Main thread only"); - MOZ_ASSERT(aGraph->IsNonRealtime(), - "Should not destroy the global graph here"); - MediaTrackGraphImpl* graph = static_cast(aGraph); + MediaTrackGraphImpl* graph = static_cast(this); graph->ForceShutDown(); } diff --git a/dom/media/MediaTrackGraph.h b/dom/media/MediaTrackGraph.h index 59b3453d08fe..f9da4bf511b7 100644 --- a/dom/media/MediaTrackGraph.h +++ b/dom/media/MediaTrackGraph.h @@ -1026,7 +1026,7 @@ class MediaTrackGraph { AbstractThread* AbstractMainThread(); // Idempotent - static void DestroyNonRealtimeInstance(MediaTrackGraph* aGraph); + void ForceShutDown(); virtual nsresult OpenAudioInput(CubebUtils::AudioDeviceID aID, AudioDataListener* aListener) = 0; diff --git a/dom/media/MediaTrackGraphImpl.h b/dom/media/MediaTrackGraphImpl.h index cdfbf79a483e..a81704c03305 100644 --- a/dom/media/MediaTrackGraphImpl.h +++ b/dom/media/MediaTrackGraphImpl.h @@ -174,7 +174,8 @@ class MediaTrackGraphImpl : public MediaTrackGraph, * Make this MediaTrackGraph enter forced-shutdown state. This state * will be noticed by the media graph thread, which will shut down all tracks * and other state controlled by the media graph thread. - * This is called during application shutdown. + * This is called during application shutdown, and on document unload if an + * AudioContext is using the graph. */ void ForceShutDown(); @@ -841,13 +842,13 @@ class MediaTrackGraphImpl : public MediaTrackGraph, * creation after this point will create a new graph. An async event is * dispatched to Shutdown() the graph's threads and then delete the graph * object. - * 2) Forced shutdown at application shutdown, or completion of a - * non-realtime graph. A flag is set, RunThread() detects the flag and - * exits, the next RunInStableState() detects the flag, and dispatches the - * async event to Shutdown() the graph's threads. However the graph object - * is not deleted. New messages for the graph are processed synchronously on - * the main thread if necessary. When the last track is destroyed, the - * graph object is deleted. + * 2) Forced shutdown at application shutdown, completion of a non-realtime + * graph, or document unload. A flag is set, RunThread() detects the flag + * and exits, the next RunInStableState() detects the flag, and dispatches + * the async event to Shutdown() the graph's threads. However the graph + * object is not deleted. New messages for the graph are processed + * synchronously on the main thread if necessary. When the last track is + * destroyed, the graph object is deleted. * * This should be kept in sync with the LifecycleState_str array in * MediaTrackGraph.cpp @@ -902,9 +903,8 @@ class MediaTrackGraphImpl : public MediaTrackGraph, } /** - * True when we need to do a forced shutdown, during process shutdown or - * when shutting down a non-realtime graph, and the graph thread has - * received the message. This is checked in the decision to shut down the + * True once the graph thread has received the message from ForceShutDown(). + * This is checked in the decision to shut down the * graph thread so that control messages dispatched before forced shutdown * are processed on the graph thread. * Only set on the graph thread. diff --git a/dom/media/webaudio/AudioDestinationNode.cpp b/dom/media/webaudio/AudioDestinationNode.cpp index ba45f4048241..09e3829ae73c 100644 --- a/dom/media/webaudio/AudioDestinationNode.cpp +++ b/dom/media/webaudio/AudioDestinationNode.cpp @@ -499,7 +499,7 @@ void AudioDestinationNode::OfflineShutdown() { "Should only be called on a valid OfflineAudioContext"); if (mTrack) { - MediaTrackGraph::DestroyNonRealtimeInstance(mTrack->Graph()); + mTrack->Graph()->MediaTrackGraph::ForceShutDown(); mOfflineRenderingRef.Drop(this); } }