Bug 1199878: [MSE/webm] Properly calculate media segment duration. r=kinetik
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 01 Sep 2015 10:47:07 +1200
changeset 260238 8d9743e32b80c45609c464ff0e6b29396443235f
parent 260237 d773e076ec4a525cc01800f3d5a6f9dad3ce9696
child 260239 d92acf7fd4ce4d50e3f4dad416e280a4118c13d7
push id29304
push usercbook@mozilla.com
push dateTue, 01 Sep 2015 12:32:25 +0000
treeherdermozilla-central@dd509db16a13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1199878
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1199878: [MSE/webm] Properly calculate media segment duration. r=kinetik We can know with certainty the duration of a block if we have a following one. We do not have to always rely on having a previous segment to estimate the duration.
dom/media/mediasource/ContainerParser.cpp
--- a/dom/media/mediasource/ContainerParser.cpp
+++ b/dom/media/mediasource/ContainerParser.cpp
@@ -266,39 +266,50 @@ public:
       mLastMapping.reset();
       return false;
     }
 
     if (mCompleteMediaHeaderRange.IsNull()) {
       mCompleteMediaHeaderRange = MediaByteRange(mapping[0].mSyncOffset,
                                                  mapping[0].mEndOffset);
     }
-    mLastMapping = Some(mapping[completeIdx]);
 
     if (foundNewCluster && mOffset >= mapping[endIdx].mEndOffset) {
       // We now have all information required to delimit a complete cluster.
       int64_t endOffset = mapping[endIdx+1].mSyncOffset;
       if (mapping[endIdx+1].mInitOffset > mapping[endIdx].mInitOffset) {
         // We have a new init segment before this cluster.
         endOffset = mapping[endIdx+1].mInitOffset;
       }
       mCompleteMediaSegmentRange = MediaByteRange(mapping[endIdx].mSyncOffset,
                                                   endOffset);
     } else if (mapping[endIdx].mClusterEndOffset >= 0 &&
                mOffset >= mapping[endIdx].mClusterEndOffset) {
       mCompleteMediaSegmentRange = MediaByteRange(mapping[endIdx].mSyncOffset,
                                                   mParser.EndSegmentOffset(mapping[endIdx].mClusterEndOffset));
     }
 
-    if (!completeIdx) {
+    Maybe<WebMTimeDataOffset> previousMapping;
+    if (completeIdx) {
+      previousMapping = Some(mapping[completeIdx - 1]);
+    } else {
+      previousMapping = mLastMapping;
+    }
+
+    mLastMapping = Some(mapping[completeIdx]);
+
+    if (!previousMapping && completeIdx + 1u >= mapping.Length()) {
+      // We have no previous nor next block available,
+      // so we can't estimate this block's duration.
       return false;
     }
 
-    uint64_t frameDuration =
-      mapping[completeIdx].mTimecode - mapping[completeIdx - 1].mTimecode;
+    uint64_t frameDuration = (completeIdx + 1u < mapping.Length())
+      ? mapping[completeIdx + 1].mTimecode - mapping[completeIdx].mTimecode
+      : mapping[completeIdx].mTimecode - previousMapping.ref().mTimecode;
     aStart = mapping[0].mTimecode / NS_PER_USEC;
     aEnd = (mapping[completeIdx].mTimecode + frameDuration) / NS_PER_USEC;
 
     MSE_DEBUG(WebMContainerParser, "[%lld, %lld] [fso=%lld, leo=%lld, l=%u processedIdx=%u fs=%lld]",
               aStart, aEnd, mapping[0].mSyncOffset,
               mapping[completeIdx].mEndOffset, mapping.Length(), completeIdx,
               mCompleteMediaSegmentRange.mEnd);