b=1023697 use audio ticks for graph time units r=roc

--HG--
extra : transplant_source : 8%BA%9D%5C%E32%05x%A79K%08TH%A7%F4%F2tg%EC
This commit is contained in:
Karl Tomlinson 2014-06-12 16:45:00 +12:00
parent 36c7833021
commit a4b9a3c57e
4 changed files with 15 additions and 27 deletions

View File

@ -16,7 +16,7 @@
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.
*/
@ -24,22 +24,21 @@ 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.
*/
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.
* a TrackRate 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 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_MAX = TRACK_TICKS_MAX;
/**
* A MediaSegment is a chunk of media data sequential in time. Different

View File

@ -1150,22 +1150,11 @@ MediaStreamGraphImpl::EnsureNextIterationLocked(MonitorAutoLock& aLock)
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

View File

@ -393,7 +393,7 @@ public:
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)
{

View File

@ -106,7 +106,7 @@ namespace WebAudioUtils {
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);
}
/**