Bug 1298617: [MSE] P1. Don't attempt to estimate next sample time if exact value known. r?gerald
MozReview-Commit-ID: 8DE9WHFsePt
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -2081,18 +2081,20 @@ TrackBuffersManager::SkipToNextRandomAcc
nextSampleTime = TimeUnit::FromMicroseconds(sample->GetEndTime());
parsed++;
}
// Adjust the next demux time and index so that the next call to
// SkipToNextRandomAccessPoint will not count again the parsed sample as
// skipped.
if (aFound) {
- trackData.mNextSampleTimecode = nextSampleTimecode;
- trackData.mNextSampleTime = nextSampleTime;
+ trackData.mNextSampleTimecode =
+ TimeUnit::FromMicroseconds(track[i]->mTimecode);
+ trackData.mNextSampleTime =
+ TimeUnit::FromMicroseconds(track[i]->mTime);
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<MediaRawData>& sample = track[j];
if (sample->mKeyframe) {
trackData.mNextSampleTimecode =
@@ -2176,21 +2178,38 @@ TrackBuffersManager::GetSample(TrackInfo
}
RefPtr<MediaRawData> p = sample->Clone();
if (!p) {
aResult = GetSampleResult::ERROR;
return nullptr;
}
trackData.mNextGetSampleIndex.ref()++;
- // Estimate decode timestamp of the next sample.
- trackData.mNextSampleTimecode =
+ // Estimate decode timestamp and timestamp of the next sample.
+ TimeUnit nextSampleTimecode =
TimeUnit::FromMicroseconds(sample->mTimecode + sample->mDuration);
- trackData.mNextSampleTime =
+ TimeUnit nextSampleTime =
TimeUnit::FromMicroseconds(sample->GetEndTime());
+ const MediaRawData* nextSample =
+ GetSample(aTrack,
+ trackData.mNextGetSampleIndex.ref(),
+ nextSampleTimecode,
+ nextSampleTime,
+ aFuzz);
+ if (nextSample) {
+ // We have a valid next sample, can use exact values.
+ trackData.mNextSampleTimecode =
+ TimeUnit::FromMicroseconds(nextSample->mTimecode);
+ trackData.mNextSampleTime =
+ TimeUnit::FromMicroseconds(nextSample->mTime);
+ } else {
+ // Next sample isn't available yet. Use estimates.
+ trackData.mNextSampleTimecode = nextSampleTimecode;
+ trackData.mNextSampleTime = nextSampleTime;
+ }
aResult = GetSampleResult::NO_ERROR;
return p.forget();
}
if (trackData.mNextSampleTimecode.ToMicroseconds() >
track.LastElement()->mTimecode + track.LastElement()->mDuration) {
// The next element is past our last sample. We're done.
trackData.mNextGetSampleIndex = Some(uint32_t(track.Length()));