Bug 1298617: [MSE] P3. Optimize sample search by breaking loop early. r?gerald
MozReview-Commit-ID: 48YcQiy0p8S
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -2255,28 +2255,38 @@ TrackBuffersManager::FindCurrentPosition
const RefPtr<MediaRawData>& sample = track[i];
TimeInterval sampleInterval{
TimeUnit::FromMicroseconds(sample->mTimecode),
TimeUnit::FromMicroseconds(sample->mTimecode + sample->mDuration)};
if (sampleInterval.ContainsStrict(trackData.mNextSampleTimecode)) {
return i;
}
+ if (sampleInterval.mStart > trackData.mNextSampleTimecode) {
+ // Samples are ordered by timecode. There's no need to search
+ // any further.
+ break;
+ }
}
for (uint32_t i = 0; i < track.Length(); i++) {
const RefPtr<MediaRawData>& sample = track[i];
TimeInterval sampleInterval{
TimeUnit::FromMicroseconds(sample->mTimecode),
TimeUnit::FromMicroseconds(sample->mTimecode + sample->mDuration),
aFuzz};
if (sampleInterval.ContainsWithStrictEnd(trackData.mNextSampleTimecode)) {
return i;
}
+ if (sampleInterval.mStart - aFuzz > trackData.mNextSampleTimecode) {
+ // Samples are ordered by timecode. There's no need to search
+ // any further.
+ break;
+ }
}
// We couldn't find our sample by decode timestamp. Attempt to find it using
// presentation timestamp. There will likely be small jerkiness.
for (uint32_t i = 0; i < track.Length(); i++) {
const RefPtr<MediaRawData>& sample = track[i];
TimeInterval sampleInterval{
TimeUnit::FromMicroseconds(sample->mTime),