Bug 1278005: Fix rounding problems. r?cpeterson draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 04 Jun 2016 12:22:39 +1000
changeset 375353 d01475e31ec6d2fc34a42bc0206b05e890717a2b
parent 375352 4256e5727d4f162d2c8c2b01cd40ea960f57c42a
child 522844 c3f3d1a45feffedf1a3c3f3563bb2da10e536e2d
push id20249
push userbmo:jyavenard@mozilla.com
push dateSat, 04 Jun 2016 02:24:35 +0000
reviewerscpeterson
bugs1278005
milestone49.0a1
Bug 1278005: Fix rounding problems. r?cpeterson We had two potentials rounding issue occurring. The one causing the problem is that adding an int64 with a float is a float, and would be limited to 24bits mantissa. The other, could be that rounding would occur if the segment duration was over 16s long, as that too would exceed the representation range as we using microseconds representation internally. MozReview-Commit-ID: FyBTGvfg25I
media/libstagefright/binding/MoofParser.cpp
--- a/media/libstagefright/binding/MoofParser.cpp
+++ b/media/libstagefright/binding/MoofParser.cpp
@@ -389,23 +389,23 @@ Moof::Moof(Box& aBox, Trex& aTrex, Mvhd&
       // duration, so we rewrite the dts accordingly.
       int64_t presentationDuration =
         ctsOrder.LastElement()->mCompositionRange.end
         - ctsOrder[0]->mCompositionRange.start;
       int64_t endDecodeTime =
         aMdhd.ToMicroseconds((int64_t)*aDecodeTime - aEdts.mMediaStart)
         + aMvhd.ToMicroseconds(aEdts.mEmptyOffset);
       int64_t decodeDuration = endDecodeTime - mIndex[0].mDecodeTime;
-      float adjust = (float)decodeDuration / presentationDuration;
+      double adjust = (double)decodeDuration / presentationDuration;
       int64_t dtsOffset = mIndex[0].mDecodeTime;
       int64_t compositionDuration = 0;
       // Adjust the dts, ensuring that the new adjusted dts will never be greater
       // than decodeTime (the next moof's decode start time).
       for (auto& sample : mIndex) {
-        sample.mDecodeTime = dtsOffset + compositionDuration * adjust;
+        sample.mDecodeTime = dtsOffset + int64_t(compositionDuration * adjust);
         compositionDuration += sample.mCompositionRange.Length();
       }
       mTimeRange = Interval<Microseconds>(ctsOrder[0]->mCompositionRange.start,
           ctsOrder.LastElement()->mCompositionRange.end);
     }
     ProcessCenc();
   }
 }