Bug 1160695 - Miscellaneous changes to TimeUnit. r=jww
authorBobby Holley <bobbyholley@gmail.com>
Thu, 28 May 2015 12:13:26 -0700
changeset 247614 89dd8f457becd1b987b749b4d6bbfd9f87f5e772
parent 247613 e637319144d3906ef28aa51348de900e49c79c56
child 247615 149efc9c88cc2af250789bfb9711f6c4c9597323
push id60756
push userbobbyholley@gmail.com
push dateMon, 08 Jun 2015 16:23:28 +0000
treeherdermozilla-inbound@636412252449 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjww
bugs1160695
milestone41.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 1160695 - Miscellaneous changes to TimeUnit. r=jww I contemplated using the mIsValid bit on CheckedInt for nullability, but eventually decided that it's too much of an overload. typedef-ing a Maybe<> solves things nicely. The current clash between the constants makes it impossible to do using |using namespace mozilla::media;| in most cpp files. It would be nice to put the constants in mozilla::media, but that requires updating a bunch of files, so I'm not doing it now.
dom/media/TimeUnits.h
dom/media/VideoUtils.h
--- a/dom/media/TimeUnits.h
+++ b/dom/media/TimeUnits.h
@@ -5,39 +5,41 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef TIME_UNITS_H
 #define TIME_UNITS_H
 
 #include "Intervals.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/FloatingPoint.h"
+#include "mozilla/Maybe.h"
 #include "mozilla/dom/TimeRanges.h"
 
 namespace mozilla {
 namespace media {
 class TimeIntervals;
 }
 }
 // CopyChooser specalization for nsTArray
 template<>
 struct nsTArray_CopyChooser<mozilla::media::TimeIntervals>
 {
   typedef nsTArray_CopyWithConstructors<mozilla::media::TimeIntervals> Type;
 };
 
 namespace mozilla {
-namespace media {
 
 // Number of microseconds per second. 1e6.
 static const int64_t USECS_PER_S = 1000000;
 
 // Number of microseconds per millisecond.
 static const int64_t USECS_PER_MS = 1000;
 
+namespace media {
+
 // Number of nanoseconds per second. 1e9.
 static const int64_t NSECS_PER_S = 1000000000;
 
 struct Microseconds {
   Microseconds()
     : mValue(0)
   {}
 
@@ -198,16 +200,18 @@ private:
   explicit TimeUnit(CheckedInt64 aMicroseconds)
     : mValue(aMicroseconds)
   {}
 
   // Our internal representation is in microseconds.
   CheckedInt64 mValue;
 };
 
+typedef Maybe<TimeUnit> NullableTimeUnit;
+
 typedef Interval<TimeUnit> TimeInterval;
 
 class TimeIntervals : public IntervalSet<TimeUnit>
 {
 public:
   typedef IntervalSet<TimeUnit> BaseType;
 
   // We can't use inherited constructors yet. So we have to duplicate all the
--- a/dom/media/VideoUtils.h
+++ b/dom/media/VideoUtils.h
@@ -132,22 +132,16 @@ media::TimeIntervals GetEstimatedBuffere
 CheckedInt64 FramesToUsecs(int64_t aFrames, uint32_t aRate);
 
 // 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);
 
-// Number of microseconds per second. 1e6.
-static const int64_t USECS_PER_S = 1000000;
-
-// Number of microseconds per millisecond.
-static const int64_t USECS_PER_MS = 1000;
-
 // Converts milliseconds to seconds.
 #define MS_TO_SECONDS(ms) ((double)(ms) / (PR_MSEC_PER_SEC))
 
 // Converts seconds to milliseconds.
 #define SECONDS_TO_MS(s) ((int)((s) * (PR_MSEC_PER_SEC)))
 
 // Converts from seconds to microseconds. Returns failure if the resulting
 // integer is too big to fit in an int64_t.