Bug 1280445 - Clear out all MediaSegments directly on forced MediaStreamGraph shutdown. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 16 Jun 2016 12:45:29 +0100
changeset 382261 0db00007f0803623e0c1ab9c80c05ace0d6ae191
parent 382260 9e4efe4de3f46d577503d83ba1868b5945d7073e
child 382262 1a2b9f32a4400f5f4d66b84e7e0e1180d4f173a5
push id21677
push userpehrsons@gmail.com
push dateWed, 29 Jun 2016 12:36:03 +0000
reviewersjesup
bugs1280445
milestone50.0a1
Bug 1280445 - Clear out all MediaSegments directly on forced MediaStreamGraph shutdown. r?jesup MozReview-Commit-ID: 3nDPEAAJABw
dom/media/MediaStreamGraph.cpp
dom/media/StreamTracks.cpp
dom/media/StreamTracks.h
--- 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()