From aafa084df3394ef815c0afed55aae7765413e63e Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 19 May 2016 15:37:34 +0800 Subject: [PATCH] Bug 1272964: [MSE] P5. Default to skipping to the next keyframe if no keyframe was found past currentTime. r=cpearce If no keyframe are found after our time threshold, we can still skip to another keyframe (despite being prior the desired time). So this is just a workaround for our inability to tell the MDSM when to enter buffering mode and instead the MDSM incorrectly uses the time of the last frame returned. MozReview-Commit-ID: 5sGULpvqY5m --HG-- extra : rebase_source : 392fe16a00eb9e10812ba4ada2e4e7c4e4aaa016 --- dom/media/mediasource/TrackBuffersManager.cpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/dom/media/mediasource/TrackBuffersManager.cpp b/dom/media/mediasource/TrackBuffersManager.cpp index 4216ef2d2f23..67cb9ce457d1 100644 --- a/dom/media/mediasource/TrackBuffersManager.cpp +++ b/dom/media/mediasource/TrackBuffersManager.cpp @@ -1939,6 +1939,7 @@ TrackBuffersManager::SkipToNextRandomAccessPoint(TrackInfo::TrackType aTrack, TimeUnit nextSampleTimecode = trackData.mNextSampleTimecode; TimeUnit nextSampleTime = trackData.mNextSampleTime; uint32_t i = trackData.mNextGetSampleIndex.ref(); + int32_t originalPos = i; for (; i < track.Length(); i++) { const MediaRawData* sample = @@ -1964,10 +1965,29 @@ TrackBuffersManager::SkipToNextRandomAccessPoint(TrackInfo::TrackType aTrack, // Adjust the next demux time and index so that the next call to // SkipToNextRandomAccessPoint will not count again the parsed sample as // skipped. - trackData.mNextSampleTimecode = nextSampleTimecode; - trackData.mNextSampleTime = nextSampleTime; - trackData.mNextGetSampleIndex = Some(i); - + if (aFound) { + trackData.mNextSampleTimecode = nextSampleTimecode; + trackData.mNextSampleTime = nextSampleTime; + trackData.mNextGetSampleIndex = Some(i); + } else if (i > 0) { + // Go back to the previous keyframe or the original position so the next + // demux can succeed and be decoded. + for (int j = i - 1; j >= originalPos; j--) { + const RefPtr& sample = track[j]; + if (sample->mKeyframe) { + trackData.mNextSampleTimecode = + TimeUnit::FromMicroseconds(sample->mTimecode); + trackData.mNextSampleTime = TimeUnit::FromMicroseconds(sample->mTime); + trackData.mNextGetSampleIndex = Some(uint32_t(j)); + // We are unable to skip to a keyframe past aTimeThreshold, however + // we are speeding up decoding by dropping the unplayable frames. + // So we can mark aFound as true. + aFound = true; + break; + } + parsed--; + } + } return parsed; }