Bug 1298617: [MSE] P1. Don't attempt to estimate next sample time if exact value known. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sun, 28 Aug 2016 02:34:44 +1200
changeset 406723 e275f42c6a48b5bb3bafac87f6b4a1125aee87ce
parent 406671 84d84728326debeb4f673950122e1818a5549e69
child 406724 6a30b35a047fbbd9e634dae656baa2a21c6cb5b7
push id27810
push userbmo:jyavenard@mozilla.com
push dateMon, 29 Aug 2016 11:03:10 +0000
reviewersgerald
bugs1298617
milestone51.0a1
Bug 1298617: [MSE] P1. Don't attempt to estimate next sample time if exact value known. r?gerald MozReview-Commit-ID: 8DE9WHFsePt
dom/media/mediasource/TrackBuffersManager.cpp
--- 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()));