Bug 1207946 - [MSE] P3. Reset cached demuxing index when new data overwrite the end. r=gerald, a=sylvestre
This will force an iterative search upon the next demux request.
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -1655,21 +1655,24 @@ TrackBuffersManager::InsertFrames(TrackB
// 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;
}
// 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();
+ if (trackBuffer.mNextGetSampleIndex.isSome()) {
+ if (trackBuffer.mNextInsertionIndex.ref() == trackBuffer.mNextGetSampleIndex.ref() &&
+ aIntervals.GetEnd() >= trackBuffer.mNextSampleTime) {
+ MSE_DEBUG("Next sample to be played got overwritten");
+ trackBuffer.mNextGetSampleIndex.reset();
+ } else if (trackBuffer.mNextInsertionIndex.ref() <= trackBuffer.mNextGetSampleIndex.ref()) {
+ trackBuffer.mNextGetSampleIndex.ref() += aSamples.Length();
+ }
}
TrackBuffer& data = trackBuffer.mBuffers.LastElement();
data.InsertElementsAt(trackBuffer.mNextInsertionIndex.ref(), aSamples);
trackBuffer.mNextInsertionIndex.ref() += aSamples.Length();
// Update our buffered range with new sample interval.
// We allow a fuzz factor in our interval of half a frame length,
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -258,16 +258,18 @@ private:
// Byte size of all samples contained in this track buffer.
uint32_t mSizeBuffer;
// TrackInfo of the first metadata received.
nsRefPtr<SharedTrackInfo> mInfo;
// TrackInfo of the last metadata parsed (updated with each init segment.
nsRefPtr<SharedTrackInfo> mLastInfo;
// If set, position of the next sample to be retrieved by GetSample().
+ // If the position is equal to the TrackBuffer's length, it indicates that
+ // we've reached EOS.
Maybe<uint32_t> mNextGetSampleIndex;
// Approximation of the next sample's decode timestamp.
media::TimeUnit mNextSampleTimecode;
// Approximation of the next sample's presentation timestamp.
media::TimeUnit mNextSampleTime;
void ResetAppendState()
{