b=972678 round double times to ticks consistently and round to nearest r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 17 Feb 2014 09:47:19 +1300
changeset 169438 085ca09d085e9e7ee5d5174b59a3d7449af7be3b
parent 169437 49f896f2264116e6698eba6fd00d5ed0c1a854e8
child 169439 5ac235837f6a9c9a5166e8145ff6c8d3ff345815
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerspadenot
bugs972678
milestone30.0a1
b=972678 round double times to ticks consistently and round to nearest r=padenot
content/media/AudioNodeStream.cpp
--- a/content/media/AudioNodeStream.cpp
+++ b/content/media/AudioNodeStream.cpp
@@ -514,20 +514,30 @@ AudioNodeStream::FinishOutput()
                                 MediaStreamListener::TRACK_EVENT_ENDED, emptySegment);
   }
 }
 
 TrackTicks
 AudioNodeStream::TicksFromDestinationTime(MediaStream* aDestination,
                                           double aSeconds)
 {
-  StreamTime streamTime = std::max<MediaTime>(0, SecondsToMediaTime(aSeconds));
+  MOZ_ASSERT(aDestination->AsAudioNodeStream() &&
+             aDestination->AsAudioNodeStream()->SampleRate() == SampleRate());
+
+  double destinationSeconds = std::max(0.0, aSeconds);
+  StreamTime streamTime = SecondsToMediaTime(destinationSeconds);
+  // MediaTime does not have the resolution of double
+  double offset = destinationSeconds - MediaTimeToSeconds(streamTime);
+
   GraphTime graphTime = aDestination->StreamTimeToGraphTime(streamTime);
   StreamTime thisStreamTime = GraphTimeToStreamTimeOptimistic(graphTime);
-  TrackTicks ticks = TimeToTicksRoundUp(SampleRate(), thisStreamTime);
+  double thisSeconds = MediaTimeToSeconds(thisStreamTime) + offset;
+  MOZ_ASSERT(thisSeconds >= 0.0);
+  // Round to nearest
+  TrackTicks ticks = thisSeconds * SampleRate() + 0.5;
   return ticks;
 }
 
 double
 AudioNodeStream::DestinationTimeFromTicks(AudioNodeStream* aDestination,
                                           TrackTicks aPosition)
 {
   MOZ_ASSERT(SampleRate() == aDestination->SampleRate());