Bug 1298617: [MSE] P3. Optimize sample search by breaking loop early. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sun, 28 Aug 2016 02:43:36 +1200
changeset 406725 c02d41d67f01d1f152816f9e177b04c779a6d0f2
parent 406724 6a30b35a047fbbd9e634dae656baa2a21c6cb5b7
child 529730 3ef5517dc1c6d452661f3ae570793fcb3ac5b2e0
push id27810
push userbmo:jyavenard@mozilla.com
push dateMon, 29 Aug 2016 11:03:10 +0000
reviewersgerald
bugs1298617
milestone51.0a1
Bug 1298617: [MSE] P3. Optimize sample search by breaking loop early. r?gerald MozReview-Commit-ID: 48YcQiy0p8S
dom/media/mediasource/TrackBuffersManager.cpp
--- 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),