Bug 1276184: [MSE] P2. Remove the need to scan the track buffer when frames are being removed. r=kamidphish
The index at which we are removing frames is always the one where we will be inserting the next ones.
MozReview-Commit-ID: DHeJDmwiMS9
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1625,17 +1625,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;
}
@@ -1662,17 +1666,17 @@ TrackBuffersManager::InsertFrames(TrackB
// length.
if (aIntervals.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;
@@ -1694,17 +1698,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;
@@ -1758,16 +1762,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
@@ -336,19 +336,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);