b=1023697 use audio ticks for graph time units r=roc
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 12 Jun 2014 16:45:00 +1200
changeset 188307 d4e08e926326f2b9d12892de9b7c6d2e90d77553
parent 188306 d4660a1d473d1016b8a340fa0ff471c64d5dc445
child 188308 5c6d45ad7f1171b6a5cc32d7d7976a5a10169eee
push id26950
push useremorley@mozilla.com
push dateThu, 12 Jun 2014 13:50:58 +0000
treeherdermozilla-central@1d9513f22934 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1023697
milestone33.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
b=1023697 use audio ticks for graph time units r=roc
content/media/MediaSegment.h
content/media/MediaStreamGraph.cpp
content/media/MediaStreamGraphImpl.h
content/media/webaudio/WebAudioUtils.h
--- a/content/media/MediaSegment.h
+++ b/content/media/MediaSegment.h
@@ -11,40 +11,39 @@
 #include "mozilla/TimeStamp.h"
 #endif
 #include <algorithm>
 #include "Latency.h"
 
 namespace mozilla {
 
 /**
- * Track rate in Hz. Maximum 1 << TRACK_RATE_MAX_BITS Hz. This
+ * Track or graph rate in Hz. Maximum 1 << TRACK_RATE_MAX_BITS Hz. This
  * maximum avoids overflow in conversions between track rates and conversions
  * from seconds.
  */
 typedef int32_t TrackRate;
 const int64_t TRACK_RATE_MAX_BITS = 20;
 const TrackRate TRACK_RATE_MAX = 1 << TRACK_RATE_MAX_BITS;
 
 /**
- * We represent media times in 64-bit fixed point. So 1 MediaTime is
- * 1/(2^MEDIA_TIME_FRAC_BITS) seconds.  We want to make sure that multiplying
- * MediaTime by a TrackRate doesn't overflow, so we set its max accordingly.
+ * A number of ticks at a rate determined by some underlying track (e.g.
+ * audio sample rate). We want to make sure that multiplying TrackTicks by
+ * a TrackRate doesn't overflow, so we set its max accordingly.
+ */
+typedef int64_t TrackTicks;
+const int64_t TRACK_TICKS_MAX = INT64_MAX >> TRACK_RATE_MAX_BITS;
+
+/**
+ * We represent media times in 64-bit audio frame counts or ticks.
+ * All audio tracks in a MediaStreamGraph have the same sample rate and all
+ * streams in the graph measure time using ticks at the same audio rate.
  */
 typedef int64_t MediaTime;
-const int64_t MEDIA_TIME_FRAC_BITS = 20;
-const int64_t MEDIA_TIME_MAX = INT64_MAX >> TRACK_RATE_MAX_BITS;
-
-/**
- * A number of ticks at a rate determined by some underlying track (e.g.
- * audio sample rate). We want to make sure that multiplying TrackTicks by
- * 2^MEDIA_TIME_FRAC_BITS doesn't overflow, so we set its max accordingly.
- */
-typedef int64_t TrackTicks;
-const int64_t TRACK_TICKS_MAX = INT64_MAX >> MEDIA_TIME_FRAC_BITS;
+const int64_t MEDIA_TIME_MAX = TRACK_TICKS_MAX;
 
 /**
  * A MediaSegment is a chunk of media data sequential in time. Different
  * types of data have different subclasses of MediaSegment, all inheriting
  * from MediaSegmentBase.
  * All MediaSegment data is timed using TrackTicks. The actual tick rate
  * is defined on a per-track basis. For some track types, this can be
  * a fixed constant for all tracks of that type (e.g. 1MHz for video).
--- a/content/media/MediaStreamGraph.cpp
+++ b/content/media/MediaStreamGraph.cpp
@@ -1145,32 +1145,21 @@ MediaStreamGraphImpl::EnsureNextIteratio
  * Returns smallest value of t such that
  * TimeToTicksRoundUp(aSampleRate, t) is a multiple of WEBAUDIO_BLOCK_SIZE
  * and floor(TimeToTicksRoundUp(aSampleRate, t)/WEBAUDIO_BLOCK_SIZE) >
  * floor(TimeToTicksRoundUp(aSampleRate, aTime)/WEBAUDIO_BLOCK_SIZE).
  */
 static GraphTime
 RoundUpToNextAudioBlock(TrackRate aSampleRate, GraphTime aTime)
 {
-  TrackTicks ticks = RateConvertTicksRoundUp(aSampleRate,
-                                             1 << MEDIA_TIME_FRAC_BITS, aTime);
+  TrackTicks ticks = aTime;
   uint64_t block = ticks >> WEBAUDIO_BLOCK_SIZE_BITS;
   uint64_t nextBlock = block + 1;
   TrackTicks nextTicks = nextBlock << WEBAUDIO_BLOCK_SIZE_BITS;
-  // Find the smallest time t such that TimeToTicksRoundUp(aSampleRate,t) == nextTicks
-  // That's the smallest integer t such that
-  //   t*aSampleRate > ((nextTicks - 1) << MEDIA_TIME_FRAC_BITS)
-  // Both sides are integers, so this is equivalent to
-  //   t*aSampleRate >= ((nextTicks - 1) << MEDIA_TIME_FRAC_BITS) + 1
-  //   t >= (((nextTicks - 1) << MEDIA_TIME_FRAC_BITS) + 1)/aSampleRate
-  //   t = ceil((((nextTicks - 1) << MEDIA_TIME_FRAC_BITS) + 1)/aSampleRate)
-  // Using integer division, that's
-  //   t = (((nextTicks - 1) << MEDIA_TIME_FRAC_BITS) + 1 + aSampleRate - 1)/aSampleRate
-  //     = ((nextTicks - 1) << MEDIA_TIME_FRAC_BITS)/aSampleRate + 1
-  return ((nextTicks - 1) << MEDIA_TIME_FRAC_BITS)/aSampleRate + 1;
+  return nextTicks;
 }
 
 void
 MediaStreamGraphImpl::ProduceDataForStreamsBlockByBlock(uint32_t aStreamIndex,
                                                         TrackRate aSampleRate,
                                                         GraphTime aFrom,
                                                         GraphTime aTo)
 {
--- a/content/media/MediaStreamGraphImpl.h
+++ b/content/media/MediaStreamGraphImpl.h
@@ -388,17 +388,17 @@ public:
    */
   void PauseAllAudioOutputs();
   /**
    * Resume all AudioStreams being written to by MediaStreams
    */
   void ResumeAllAudioOutputs();
 
   TrackRate AudioSampleRate() const { return mSampleRate; }
-  TrackRate GraphRate() const { return 1 << MEDIA_TIME_FRAC_BITS; }
+  TrackRate GraphRate() const { return mSampleRate; }
 
   double MediaTimeToSeconds(GraphTime aTime)
   {
     return TrackTicksToSeconds(GraphRate(), aTime);
   }
   GraphTime SecondsToMediaTime(double aS)
   {
     return SecondsToTicksRoundDown(GraphRate(), aS);
--- a/content/media/webaudio/WebAudioUtils.h
+++ b/content/media/webaudio/WebAudioUtils.h
@@ -101,17 +101,17 @@ namespace WebAudioUtils {
 
   inline double DiscreteTimeConstantForSampleRate(double timeConstant, double sampleRate)
   {
     return 1.0 - std::exp(-1.0 / (sampleRate * timeConstant));
   }
 
   inline bool IsTimeValid(double aTime)
   {
-    return aTime >= 0 &&  aTime <= (MEDIA_TIME_MAX >> MEDIA_TIME_FRAC_BITS);
+    return aTime >= 0 && aTime <= (MEDIA_TIME_MAX >> TRACK_RATE_MAX_BITS);
   }
 
   /**
    * Converts a floating point value to an integral type in a safe and
    * platform agnostic way.  The following program demonstrates the kinds
    * of ways things can go wrong depending on the CPU architecture you're
    * compiling for:
    *