Bug 1276184: [MSE] P2. Remove the need to scan the track buffer when frames are being removed. r=kamidphish, a=gchang
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 02 Jun 2016 16:59:00 +1000
changeset 333546 3c50c8027389
parent 333545 aa702c6e60ea
child 333547 3e04c4853a8b
push id6161
push usercbook@mozilla.com
push dateMon, 04 Jul 2016 13:50:39 +0000
treeherdermozilla-beta@3e04c4853a8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish, gchang
bugs1276184
milestone48.0
Bug 1276184: [MSE] P2. Remove the need to scan the track buffer when frames are being removed. r=kamidphish, a=gchang The index at which we are removing frames is always the one where we will be inserting the next ones. MozReview-Commit-ID: DHeJDmwiMS9
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mediasource/TrackBuffersManager.h
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1628,17 +1628,21 @@ TrackBuffersManager::InsertFrames(TrackB
 
   if (intersection.Length()) {
     if (aSamples[0]->mKeyframe) {
       // We are starting a new GOP, we do not have to worry about breaking an
       // existing current coded frame group. Reset the next insertion index
       // so the search for when to start our frames removal can be exhaustive.
       trackBuffer.mNextInsertionIndex.reset();
     }
-    RemoveFrames(aIntervals, trackBuffer, trackBuffer.mNextInsertionIndex.refOr(0));
+    size_t index =
+      RemoveFrames(aIntervals, trackBuffer, trackBuffer.mNextInsertionIndex.refOr(0));
+    if (index) {
+      trackBuffer.mNextInsertionIndex = Some(index);
+    }
   }
 
   // 16. Add the coded frame with the presentation timestamp, decode timestamp, and frame duration to the track buffer.
   if (!CheckNextInsertionIndex(aTrackData,
                                TimeUnit::FromMicroseconds(aSamples[0]->mTime))) {
     RejectProcessing(NS_ERROR_FAILURE, __func__);
     return;
   }
@@ -1663,17 +1667,17 @@ TrackBuffersManager::InsertFrames(TrackB
   // We allow a fuzz factor in our interval of half a frame length,
   // as fuzz is +/- value, giving an effective leeway of a full frame
   // length.
   TimeIntervals range(aIntervals);
   range.SetFuzz(trackBuffer.mLongestFrameDuration / 2);
   trackBuffer.mSanitizedBufferedRanges += range;
 }
 
-void
+size_t
 TrackBuffersManager::RemoveFrames(const TimeIntervals& aIntervals,
                                   TrackData& aTrackData,
                                   uint32_t aStartIndex)
 {
   TrackBuffer& data = aTrackData.mBuffers.LastElement();
   Maybe<uint32_t> firstRemovedIndex;
   uint32_t lastRemovedIndex = 0;
 
@@ -1695,17 +1699,17 @@ TrackBuffersManager::RemoveFrames(const 
       if (firstRemovedIndex.isNothing()) {
         firstRemovedIndex = Some(i);
       }
       lastRemovedIndex = i;
     }
   }
 
   if (firstRemovedIndex.isNothing()) {
-    return;
+    return 0;
   }
 
   // Remove decoding dependencies of the coded frames removed in the previous step:
   // Remove all coded frames between the coded frames removed in the previous step and the next random access point after those removed frames.
   for (uint32_t i = lastRemovedIndex + 1; i < data.Length(); i++) {
     MediaRawData* sample = data[i].get();
     if (sample->mKeyframe) {
       break;
@@ -1759,16 +1763,18 @@ TrackBuffersManager::RemoveFrames(const 
   aTrackData.mBufferedRanges -= removedIntervals;
 
   // Recalculate sanitized buffered ranges.
   aTrackData.mSanitizedBufferedRanges = aTrackData.mBufferedRanges;
   aTrackData.mSanitizedBufferedRanges.SetFuzz(TimeUnit::FromMicroseconds(maxSampleDuration/2));
 
   data.RemoveElementsAt(firstRemovedIndex.ref(),
                         lastRemovedIndex - firstRemovedIndex.ref() + 1);
+
+  return firstRemovedIndex.ref();
 }
 
 void
 TrackBuffersManager::RecreateParser(bool aReuseInitData)
 {
   MOZ_ASSERT(OnTaskQueue());
   // Recreate our parser for only the data remaining. This is required
   // as it has parsed the entire InputBuffer provided.
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -333,19 +333,22 @@ private:
 
   void CheckSequenceDiscontinuity(const media::TimeUnit& aPresentationTime);
   void ProcessFrames(TrackBuffer& aSamples, TrackData& aTrackData);
   bool CheckNextInsertionIndex(TrackData& aTrackData,
                                const media::TimeUnit& aSampleTime);
   void InsertFrames(TrackBuffer& aSamples,
                     const media::TimeIntervals& aIntervals,
                     TrackData& aTrackData);
-  void RemoveFrames(const media::TimeIntervals& aIntervals,
-                    TrackData& aTrackData,
-                    uint32_t aStartIndex);
+  // Remove all frames and their dependencies contained in aIntervals.
+  // Return the index at which frames were first removed or 0 if no frames
+  // removed.
+  size_t RemoveFrames(const media::TimeIntervals& aIntervals,
+                      TrackData& aTrackData,
+                      uint32_t aStartIndex);
   // Find index of sample. Return a negative value if not found.
   uint32_t FindSampleIndex(const TrackBuffer& aTrackBuffer,
                            const media::TimeInterval& aInterval);
   const MediaRawData* GetSample(TrackInfo::TrackType aTrack,
                                 size_t aIndex,
                                 const media::TimeUnit& aExpectedDts,
                                 const media::TimeUnit& aExpectedPts,
                                 const media::TimeUnit& aFuzz);