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
--- 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();
}
}