Bug 1280445 - Clear out all MediaSegments directly on forced MediaStreamGraph shutdown. r?jesup
MozReview-Commit-ID: 3nDPEAAJABw
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1694,16 +1694,25 @@ 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 manager 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.
+ if (SourceMediaStream* source = stream->AsSourceStream()) {
+ // Finishing a SourceStream prevents new data from being appended.
+ source->Finish();
+ }
+ stream->GetStreamTracks().Clear();
+ }
mGraph->mLifecycleState =
MediaStreamGraphImpl::LIFECYCLE_WAITING_FOR_STREAM_DESTRUCTION;
}
return NS_OK;
}
private:
RefPtr<MediaStreamGraphImpl> mGraph;
--- a/dom/media/StreamTracks.cpp
+++ b/dom/media/StreamTracks.cpp
@@ -103,9 +103,15 @@ StreamTracks::ForgetUpTo(StreamTime aTim
for (uint32_t i = 0; i < mTracks.Length(); ++i) {
Track* track = mTracks[i];
StreamTime forgetTo = std::min(track->GetEnd() - 1, aTime);
track->ForgetUpTo(forgetTo);
}
}
+void
+StreamTracks::Clear()
+{
+ mTracks.Clear();
+}
+
} // namespace mozilla
--- a/dom/media/StreamTracks.h
+++ b/dom/media/StreamTracks.h
@@ -298,16 +298,21 @@ public:
/**
* Forget stream data before aTime; they will no longer be needed.
* Also can forget entire tracks that have ended at or before aTime.
* Can't be used to forget beyond GetEnd().
*/
void ForgetUpTo(StreamTime aTime);
/**
+ * Clears out all Tracks and the data they are holding.
+ * MediaStreamGraph calls this during forced shutdown.
+ */
+ void Clear();
+ /**
* Returns the latest time passed to ForgetUpTo.
*/
StreamTime GetForgottenDuration()
{
return mForgottenTime;
}
bool GetAndResetTracksDirty()