Bug 1410829 - Clean up streams and listeners before unblocking shutdown. r?padenot
MozReview-Commit-ID: CcGaAJAUahm
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1587,16 +1587,29 @@ public:
MOZ_ASSERT(false,
"AudioCallbackDriver took too long to shut down and we let shutdown"
" continue - freezing and leaking");
// The timer fired, so we may be deeper in shutdown now. Block any further
// teardown and just leak, for safety.
return NS_OK;
}
+
+ for (MediaStream* stream : mGraph->AllStreams()) {
+ // Clean up all MediaSegments since we cannot release Images too
+ // late during shutdown. Also notify listeners that they were removed
+ // so they can clean up any gfx resources.
+ if (SourceMediaStream* source = stream->AsSourceStream()) {
+ // Finishing a SourceStream prevents new data from being appended.
+ source->Finish();
+ }
+ stream->GetStreamTracks().Clear();
+ stream->RemoveAllListenersImpl();
+ }
+
mGraph->mForceShutdownTicket = nullptr;
// We can't block past the final LIFECYCLE_WAITING_FOR_STREAM_DESTRUCTION
// stage, since completion of that stage requires all streams to be freed,
// which requires shutdown to proceed.
// mGraph's thread is not running so it's OK to do whatever here
if (mGraph->IsEmpty()) {
@@ -1604,28 +1617,16 @@ public:
mGraph->Destroy();
} else {
// The graph is not empty. We must be in a forced shutdown, or a
// non-realtime graph that has finished processing. Some later
// AppendMessage will detect that the graph has been emptied, and
// delete it.
NS_ASSERTION(mGraph->mForceShutDown || !mGraph->mRealtime,
"Not in forced shutdown?");
- for (MediaStream* stream : mGraph->AllStreams()) {
- // Clean up all MediaSegments since we cannot release Images too
- // late during shutdown. Also notify listeners that they were removed
- // so they can clean up any gfx resources.
- if (SourceMediaStream* source = stream->AsSourceStream()) {
- // Finishing a SourceStream prevents new data from being appended.
- source->Finish();
- }
- stream->GetStreamTracks().Clear();
- stream->RemoveAllListenersImpl();
- }
-
mGraph->mLifecycleState =
MediaStreamGraphImpl::LIFECYCLE_WAITING_FOR_STREAM_DESTRUCTION;
}
return NS_OK;
}
private:
RefPtr<MediaStreamGraphImpl> mGraph;
};