Bug 1189506. Create StreamTimeToGraphTime/GraphTimeToStreamTime that don't take account of blocking, and call them from AudioNodeStream. r=karlt
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 16 Sep 2015 16:35:16 +1200
changeset 295516 c9d2999a87739e3edd120cbd6ccbc3555fb43044
parent 295515 1e3d3c66fab5ab8ca71f05674b223769f06c3dff
child 295517 04c37cfa2299a6bd18a9f8a122120d605c81e5d2
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1189506
milestone43.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 1189506. Create StreamTimeToGraphTime/GraphTimeToStreamTime that don't take account of blocking, and call them from AudioNodeStream. r=karlt
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraph.h
dom/media/MediaStreamGraphImpl.h
dom/media/webaudio/AudioNodeStream.cpp
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -216,36 +216,27 @@ MediaStreamGraphImpl::ExtractPendingInpu
   }
   if (finished) {
     FinishStream(aStream);
   }
 }
 
 StreamTime
 MediaStreamGraphImpl::GraphTimeToStreamTimeWithBlocking(MediaStream* aStream,
-                                            GraphTime aTime)
+                                                        GraphTime aTime)
 {
   MOZ_ASSERT(aTime <= mStateComputedTime,
              "Don't ask about times where we haven't made blocking decisions yet");
   return std::max<StreamTime>(0,
       std::min(aTime, aStream->mStartBlocking) - aStream->mBufferStartTime);
 }
 
-StreamTime
-MediaStreamGraphImpl::GraphTimeToStreamTimeOptimistic(MediaStream* aStream,
-                                                      GraphTime aTime)
-{
-  GraphTime computedUpToTime = std::min(mStateComputedTime, aTime);
-  StreamTime s = GraphTimeToStreamTimeWithBlocking(aStream, computedUpToTime);
-  return s + (aTime - computedUpToTime);
-}
-
 GraphTime
 MediaStreamGraphImpl::StreamTimeToGraphTimeWithBlocking(MediaStream* aStream,
-                                            StreamTime aTime, uint32_t aFlags)
+    StreamTime aTime, uint32_t aFlags)
 {
   // Avoid overflows
   if (aTime >= STREAM_TIME_MAX) {
     return GRAPH_TIME_MAX;
   }
 
   // Assume we're unblocked from 0..mStartBlocking, blocked from mStartBlocking
   // to mStateComputedTime, and unblocked from mStateComputedTime..forever
@@ -1695,27 +1686,37 @@ MediaStream::SetGraphImpl(MediaStreamGra
 void
 MediaStream::SetGraphImpl(MediaStreamGraph* aGraph)
 {
   MediaStreamGraphImpl* graph = static_cast<MediaStreamGraphImpl*>(aGraph);
   SetGraphImpl(graph);
 }
 
 StreamTime
+MediaStream::GraphTimeToStreamTime(GraphTime aTime)
+{
+  NS_ASSERTION(mStartBlocking == GraphImpl()->mStateComputedTime,
+               "Don't call this when there's pending blocking time!");
+  return aTime - mBufferStartTime;
+}
+
+GraphTime
+MediaStream::StreamTimeToGraphTime(StreamTime aTime)
+{
+  NS_ASSERTION(mStartBlocking == GraphImpl()->mStateComputedTime,
+               "Don't call this when there's pending blocking time!");
+  return aTime + mBufferStartTime;
+}
+
+StreamTime
 MediaStream::GraphTimeToStreamTimeWithBlocking(GraphTime aTime)
 {
   return GraphImpl()->GraphTimeToStreamTimeWithBlocking(this, aTime);
 }
 
-StreamTime
-MediaStream::GraphTimeToStreamTimeOptimistic(GraphTime aTime)
-{
-  return GraphImpl()->GraphTimeToStreamTimeOptimistic(this, aTime);
-}
-
 GraphTime
 MediaStream::StreamTimeToGraphTimeWithBlocking(StreamTime aTime)
 {
   return GraphImpl()->StreamTimeToGraphTimeWithBlocking(this, aTime, 0);
 }
 
 void
 MediaStream::FinishOnGraphThread()
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -498,21 +498,29 @@ public:
   }
   /**
    * Convert graph time to stream time. aTime must be <= mStateComputedTime
    * to ensure we know exactly how much time this stream will be blocked during
    * the interval.
    */
   StreamTime GraphTimeToStreamTimeWithBlocking(GraphTime aTime);
   /**
-   * Convert graph time to stream time. aTime can be > mStateComputedTime,
-   * in which case we optimistically assume the stream will not be blocked
-   * after mStateComputedTime.
+   * Convert graph time to stream time. This assumes there is no blocking time
+   * to take account of, which is always true except between a stream
+   * having its blocking time calculated in UpdateGraph and its blocking time
+   * taken account of in UpdateCurrentTimeForStreams.
    */
-  StreamTime GraphTimeToStreamTimeOptimistic(GraphTime aTime);
+  StreamTime GraphTimeToStreamTime(GraphTime aTime);
+  /**
+   * Convert stream time to graph time. This assumes there is no blocking time
+   * to take account of, which is always true except between a stream
+   * having its blocking time calculated in UpdateGraph and its blocking time
+   * taken account of in UpdateCurrentTimeForStreams.
+   */
+  GraphTime StreamTimeToGraphTime(StreamTime aTime);
   /**
    * Convert stream time to graph time. The result can be > mStateComputedTime,
    * in which case we did the conversion optimistically assuming the stream
    * will not be blocked after mStateComputedTime.
    */
   GraphTime StreamTimeToGraphTimeWithBlocking(StreamTime aTime);
 
   bool IsFinishedOnGraphThread() { return mFinished; }
--- a/dom/media/MediaStreamGraphImpl.h
+++ b/dom/media/MediaStreamGraphImpl.h
@@ -319,22 +319,16 @@ public:
    */
   GraphTime WillUnderrun(MediaStream* aStream, GraphTime aEndBlockingDecisions);
 
   /**
    * Given a graph time aTime, convert it to a stream time taking into
    * account the time during which aStream is scheduled to be blocked.
    */
   StreamTime GraphTimeToStreamTimeWithBlocking(MediaStream* aStream, GraphTime aTime);
-  /**
-   * Given a graph time aTime, convert it to a stream time taking into
-   * account the time during which aStream is scheduled to be blocked, and
-   * when we don't know whether it's blocked or not, we assume it's not blocked.
-   */
-  StreamTime GraphTimeToStreamTimeOptimistic(MediaStream* aStream, GraphTime aTime);
   enum
   {
     INCLUDE_TRAILING_BLOCKED_INTERVAL = 0x01
   };
 
   /**
    * Given a stream time aTime, convert it to a graph time taking into
    * account the time during which aStream is scheduled to be blocked.
--- a/dom/media/webaudio/AudioNodeStream.cpp
+++ b/dom/media/webaudio/AudioNodeStream.cpp
@@ -649,18 +649,18 @@ AudioNodeStream::FractionalTicksFromDest
   double destinationSeconds = std::max(0.0, aSeconds);
   double destinationFractionalTicks = destinationSeconds * SampleRate();
   MOZ_ASSERT(destinationFractionalTicks < STREAM_TIME_MAX);
   StreamTime destinationStreamTime = destinationFractionalTicks; // round down
   // MediaTime does not have the resolution of double
   double offset = destinationFractionalTicks - destinationStreamTime;
 
   GraphTime graphTime =
-    aDestination->StreamTimeToGraphTimeWithBlocking(destinationStreamTime);
-  StreamTime thisStreamTime = GraphTimeToStreamTimeOptimistic(graphTime);
+    aDestination->StreamTimeToGraphTime(destinationStreamTime);
+  StreamTime thisStreamTime = GraphTimeToStreamTime(graphTime);
   double thisFractionalTicks = thisStreamTime + offset;
   MOZ_ASSERT(thisFractionalTicks >= 0.0);
   return thisFractionalTicks;
 }
 
 StreamTime
 AudioNodeStream::TicksFromDestinationTime(MediaStream* aDestination,
                                           double aSeconds)
@@ -675,14 +675,15 @@ AudioNodeStream::TicksFromDestinationTim
   return ticks;
 }
 
 double
 AudioNodeStream::DestinationTimeFromTicks(AudioNodeStream* aDestination,
                                           StreamTime aPosition)
 {
   MOZ_ASSERT(SampleRate() == aDestination->SampleRate());
-  GraphTime graphTime = StreamTimeToGraphTimeWithBlocking(aPosition);
-  StreamTime destinationTime = aDestination->GraphTimeToStreamTimeOptimistic(graphTime);
+
+  GraphTime graphTime = StreamTimeToGraphTime(aPosition);
+  StreamTime destinationTime = aDestination->GraphTimeToStreamTime(graphTime);
   return StreamTimeToSeconds(destinationTime);
 }
 
 } // namespace mozilla