Beispiel #1
0
double
AudioNodeStream::DestinationTimeFromTicks(AudioNodeStream* aDestination,
                                          StreamTime aPosition)
{
  MOZ_ASSERT(SampleRate() == aDestination->SampleRate());
  GraphTime graphTime = StreamTimeToGraphTime(aPosition);
  StreamTime destinationTime = aDestination->GraphTimeToStreamTimeOptimistic(graphTime);
  return StreamTimeToSeconds(destinationTime);
}
double
AudioNodeStream::DestinationTimeFromTicks(AudioNodeStream* aDestination,
                                          TrackTicks aPosition)
{
  MOZ_ASSERT(SampleRate() == aDestination->SampleRate());
  StreamTime sourceTime = TicksToTimeRoundDown(SampleRate(), aPosition);
  GraphTime graphTime = StreamTimeToGraphTime(sourceTime);
  StreamTime destinationTime = aDestination->GraphTimeToStreamTimeOptimistic(graphTime);
  return StreamTimeToSeconds(destinationTime);
}
double
AudioNodeStream::TimeFromDestinationTime(AudioNodeStream* aDestination,
                                         double aSeconds)
{
  MOZ_ASSERT(aDestination->SampleRate() == SampleRate());

  double destinationSeconds = std::max(0.0, aSeconds);
  StreamTime streamTime =
    aDestination->SecondsToStreamTimeRoundDown(destinationSeconds);
  // MediaTime does not have the resolution of double
  double offset =
    destinationSeconds - aDestination->StreamTimeToSeconds(streamTime);

  GraphTime graphTime = aDestination->StreamTimeToGraphTime(streamTime);
  StreamTime thisStreamTime = GraphTimeToStreamTimeOptimistic(graphTime);
  double thisSeconds = StreamTimeToSeconds(thisStreamTime) + offset;
  MOZ_ASSERT(thisSeconds >= 0.0);
  return thisSeconds;
}