Bug 1188238: [MSE] P2. Don't assert when unable to find position in frames array. r=gerald a=sledru
Instead return an error which will terminate the video element.
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1563,53 +1563,56 @@ TrackBuffersManager::ProcessFrames(Track
}
if (samples.Length()) {
InsertFrames(samples, samplesRange, trackBuffer);
trackBuffer.mSizeBuffer += sizeNewSamples;
}
}
-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.
TimeInterval target;
for (const auto& interval : aTrackData.mBufferedRanges) {
if (aSampleTime < interval.mStart) {
target = interval;
break;
}
}
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<MediaRawData>& 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
TrackBuffersManager::InsertFrames(TrackBuffer& aSamples,
const TimeIntervals& aIntervals,
TrackData& aTrackData)
{
// 5. Let track buffer equal the track buffer that the coded frame will be added to.
@@ -1645,18 +1648,21 @@ TrackBuffersManager::InsertFrames(TrackB
TimeIntervals intersection = trackBuffer.mBufferedRanges;
intersection.Intersection(aIntervals);
if (intersection.Length()) {
RemoveFrames(aIntervals, trackBuffer, trackBuffer.mNextInsertionIndex.refOr(0));
}
// 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() &&
(trackBuffer.mNextInsertionIndex.ref() < trackBuffer.mNextGetSampleIndex.ref() ||
(trackBuffer.mNextInsertionIndex.ref() == trackBuffer.mNextGetSampleIndex.ref() &&
aIntervals.GetEnd() < trackBuffer.mNextSampleTime))) {
trackBuffer.mNextGetSampleIndex.ref() += aSamples.Length();
}
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -277,17 +277,17 @@ private:
mLongestFrameDuration.reset();
mNextInsertionIndex.reset();
}
};
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,
TrackData& aTrackData);
void RemoveFrames(const media::TimeIntervals& aIntervals,
TrackData& aTrackData,
uint32_t aStartIndex);
void UpdateBufferedRanges();