Bug 1174588: P1. Update insertion index on the fly. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 15 Jun 2015 15:03:20 +1000
changeset 280492 c2e4889a65a1a28511668e293430e6b666584fed
parent 280491 06868346ce621d4498bff04b9217a4eed98272be
child 280493 b3f78edbfbe327bd662cf298146320a14307a2aa
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1174588
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1174588: P1. Update insertion index on the fly. r=gerald Prevent reparsing the entire stream in the next call to appendBuffer.
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -474,16 +474,22 @@ TrackBuffersManager::CodedFrameRemoval(T
           firstRemovedIndex = Some(i);
         } else {
           removedInterval = removedInterval.Span(
             TimeInterval(TimeUnit::FromMicroseconds(frame->mTime),
                          TimeUnit::FromMicroseconds(frame->mTime + frame->mDuration)));
         }
         track->mSizeBuffer -= sizeof(*frame) + frame->mSize;
         data.RemoveElementAt(i);
+        MOZ_ASSERT(track->mNextInsertionIndex.isNothing() ||
+                   track->mNextInsertionIndex.ref() != i);
+        if (track->mNextInsertionIndex.isSome() &&
+            track->mNextInsertionIndex.ref() > i) {
+          track->mNextInsertionIndex.ref()--;
+        }
       } else {
         i++;
       }
     }
     // 4. 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.
     if (firstRemovedIndex.isSome()) {
       uint32_t start = firstRemovedIndex.ref();
@@ -494,16 +500,23 @@ TrackBuffersManager::CodedFrameRemoval(T
           break;
         }
         removedInterval = removedInterval.Span(
           TimeInterval(TimeUnit::FromMicroseconds(sample->mTime),
                        TimeUnit::FromMicroseconds(sample->GetEndTime())));
         track->mSizeBuffer -= sizeof(*sample) + sample->mSize;
       }
       data.RemoveElementsAt(start, end - start);
+      MOZ_ASSERT(track->mNextInsertionIndex.isNothing() ||
+                 track->mNextInsertionIndex.ref() <= start ||
+                 track->mNextInsertionIndex.ref() >= end);
+      if (track->mNextInsertionIndex.isSome() &&
+          track->mNextInsertionIndex.ref() >= end) {
+        track->mNextInsertionIndex.ref() -= end - start;
+      }
 
       MSE_DEBUG("Removing undecodable frames from:%u (frames:%d) ([%f, %f))",
                 start, end - start,
                 removedInterval.mStart.ToSeconds(), removedInterval.mEnd.ToSeconds());
       track->mBufferedRanges -= removedInterval;
       dataRemoved = true;
     }
 
@@ -530,20 +543,16 @@ TrackBuffersManager::CodedFrameRemoval(T
   if (HasAudio()) {
     MSE_DEBUG("after audio ranges=%s",
               DumpTimeRanges(mAudioTracks.mBufferedRanges).get());
   }
 
   // Update our reported total size.
   mSizeSourceBuffer = mVideoTracks.mSizeBuffer + mAudioTracks.mSizeBuffer;
 
-  // Reset our insertion indexes as they are now invalid.
-  mAudioTracks.mNextInsertionIndex.reset();
-  mVideoTracks.mNextInsertionIndex.reset();
-
   // Tell our demuxer that data was removed.
   mMediaSourceDemuxer->NotifyTimeRangesChanged();
 
   return dataRemoved;
 }
 
 nsRefPtr<TrackBuffersManager::AppendPromise>
 TrackBuffersManager::InitSegmentParserLoop()