Bug 1264199: P0.1. Export SaferMultDiv method. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 26 Apr 2016 11:16:23 +1000
changeset 356279 ad5d064e03fb123f6bdceff00df385ac75321a7a
parent 356262 227854dfb623e7cb8ed5e73ef0bc66043e509944
child 356280 ae5183656326f1429951c53306fb1ac9acba8b9e
push id16486
push userbmo:jyavenard@mozilla.com
push dateTue, 26 Apr 2016 02:36:37 +0000
reviewersgerald
bugs1264199
milestone49.0a1
Bug 1264199: P0.1. Export SaferMultDiv method. r?gerald MozReview-Commit-ID: CzewhPB1Nod
dom/media/VideoUtils.cpp
dom/media/VideoUtils.h
--- a/dom/media/VideoUtils.cpp
+++ b/dom/media/VideoUtils.cpp
@@ -26,20 +26,20 @@
 #include "nsContentTypeParser.h"
 
 #include <stdint.h>
 
 namespace mozilla {
 
 using layers::PlanarYCbCrImage;
 
-static inline CheckedInt64 SaferMultDiv(int64_t aValue, uint32_t aMul, uint32_t aDiv) {
+CheckedInt64 SaferMultDiv(int64_t aValue, uint32_t aMul, uint32_t aDiv) {
   int64_t major = aValue / aDiv;
   int64_t remainder = aValue % aDiv;
-  return CheckedInt64(remainder) * aMul / aDiv + major * aMul;
+  return CheckedInt64(remainder) * aMul / aDiv + CheckedInt64(major) * aMul;
 }
 
 // Converts from number of audio frames to microseconds, given the specified
 // audio rate.
 CheckedInt64 FramesToUsecs(int64_t aFrames, uint32_t aRate) {
   return SaferMultDiv(aFrames, USECS_PER_S, aRate);
 }
 
--- a/dom/media/VideoUtils.h
+++ b/dom/media/VideoUtils.h
@@ -126,16 +126,19 @@ media::TimeIntervals GetEstimatedBuffere
                                                     int64_t aDurationUsecs);
 
 // Converts from number of audio frames (aFrames) to microseconds, given
 // the specified audio rate (aRate).
 CheckedInt64 FramesToUsecs(int64_t aFrames, uint32_t aRate);
 // Converts from number of audio frames (aFrames) TimeUnit, given
 // the specified audio rate (aRate).
 media::TimeUnit FramesToTimeUnit(int64_t aFrames, uint32_t aRate);
+// Perform aValue * aMul / aDiv, reducing the possibility of overflow due to
+// aValue * aMul overflowing.
+CheckedInt64 SaferMultDiv(int64_t aValue, uint32_t aMul, uint32_t aDiv);
 
 // Converts from microseconds (aUsecs) to number of audio frames, given the
 // specified audio rate (aRate). Stores the result in aOutFrames. Returns
 // true if the operation succeeded, or false if there was an integer
 // overflow while calulating the conversion.
 CheckedInt64 UsecsToFrames(int64_t aUsecs, uint32_t aRate);
 
 // Format TimeUnit as number of frames at given rate.