diff --git a/dom/media/mediasource/TrackBuffersManager.cpp b/dom/media/mediasource/TrackBuffersManager.cpp index 50a0467c34ae..16b88f7ffe2b 100644 --- a/dom/media/mediasource/TrackBuffersManager.cpp +++ b/dom/media/mediasource/TrackBuffersManager.cpp @@ -1568,19 +1568,19 @@ TrackBuffersManager::ProcessFrames(TrackBuffer& aSamples, TrackData& aTrackData) } } -void +bool TrackBuffersManager::CheckNextInsertionIndex(TrackData& aTrackData, const TimeUnit& aSampleTime) { if (aTrackData.mNextInsertionIndex.isSome()) { - return; + return true; } TrackBuffer& data = aTrackData.mBuffers.LastElement(); if (data.IsEmpty() || aSampleTime < aTrackData.mBufferedRanges.GetStart()) { aTrackData.mNextInsertionIndex = Some(size_t(0)); - return; + return true; } // Find which discontinuity we should insert the frame before. @@ -1594,17 +1594,20 @@ TrackBuffersManager::CheckNextInsertionIndex(TrackData& aTrackData, if (target.IsEmpty()) { // No target found, it will be added at the end of the track buffer. aTrackData.mNextInsertionIndex = Some(data.Length()); - return; + return true; } + // We now need to find the first frame of the searched interval. + // We will insert our new frames right before. for (uint32_t i = 0; i < data.Length(); i++) { const nsRefPtr& sample = data[i]; if (sample->mTime >= target.mStart.ToMicroseconds() || sample->GetEndTime() > target.mStart.ToMicroseconds()) { aTrackData.mNextInsertionIndex = Some(size_t(i)); - return; + return true; } } - MOZ_CRASH("Insertion Index Not Found"); + NS_ASSERTION(false, "Insertion Index Not Found"); + return false; } void @@ -1650,8 +1653,11 @@ TrackBuffersManager::InsertFrames(TrackBuffer& aSamples, } // 16. Add the coded frame with the presentation timestamp, decode timestamp, and frame duration to the track buffer. - CheckNextInsertionIndex(aTrackData, - TimeUnit::FromMicroseconds(aSamples[0]->mTime)); + if (!CheckNextInsertionIndex(aTrackData, + TimeUnit::FromMicroseconds(aSamples[0]->mTime))) { + RejectProcessing(NS_ERROR_FAILURE, __func__); + return; + } // Adjust our demuxing index if necessary. if (trackBuffer.mNextGetSampleIndex.isSome() && diff --git a/dom/media/mediasource/TrackBuffersManager.h b/dom/media/mediasource/TrackBuffersManager.h index 7adec08c0c3b..a54db4b5b878 100644 --- a/dom/media/mediasource/TrackBuffersManager.h +++ b/dom/media/mediasource/TrackBuffersManager.h @@ -282,7 +282,7 @@ private: void CheckSequenceDiscontinuity(); void ProcessFrames(TrackBuffer& aSamples, TrackData& aTrackData); - void CheckNextInsertionIndex(TrackData& aTrackData, + bool CheckNextInsertionIndex(TrackData& aTrackData, const media::TimeUnit& aSampleTime); void InsertFrames(TrackBuffer& aSamples, const media::TimeIntervals& aIntervals,