Bug 878015. Make RoundUpToAudioBlock always advance to the next audio block. r=padenot

--HG--
extra : rebase_source : d931a0f144579bd7f7f57bd9e2c7d4ecc1700b27
This commit is contained in:
Robert O'Callahan 2013-08-02 21:27:58 +12:00
parent 82b71516c9
commit 4108f3f1ec

View File

@ -983,18 +983,30 @@ MediaStreamGraphImpl::EnsureNextIterationLocked(MonitorAutoLock& aLock)
}
}
/**
* 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
RoundUpToAudioBlock(TrackRate aSampleRate, GraphTime aTime)
RoundUpToNextAudioBlock(TrackRate aSampleRate, GraphTime aTime)
{
int64_t ticksAtIdealaSampleRate = (aTime*aSampleRate) >> MEDIA_TIME_FRAC_BITS;
// Round up to nearest block boundary
int64_t blocksAtIdealaSampleRate =
(ticksAtIdealaSampleRate + (WEBAUDIO_BLOCK_SIZE - 1)) >>
WEBAUDIO_BLOCK_SIZE_BITS;
// Round up to nearest MediaTime unit
return
((((blocksAtIdealaSampleRate + 1)*WEBAUDIO_BLOCK_SIZE) << MEDIA_TIME_FRAC_BITS)
+ aSampleRate - 1)/aSampleRate;
TrackTicks ticks = TimeToTicksRoundUp(aSampleRate, 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;
}
void
@ -1005,7 +1017,7 @@ MediaStreamGraphImpl::ProduceDataForStreamsBlockByBlock(uint32_t aStreamIndex,
{
GraphTime t = aFrom;
while (t < aTo) {
GraphTime next = RoundUpToAudioBlock(aSampleRate, t + 1);
GraphTime next = RoundUpToNextAudioBlock(aSampleRate, t);
for (uint32_t i = aStreamIndex; i < mStreams.Length(); ++i) {
nsRefPtr<ProcessedMediaStream> ps = mStreams[i]->AsProcessedStream();
if (ps) {
@ -1069,7 +1081,7 @@ MediaStreamGraphImpl::RunThread()
}
GraphTime endBlockingDecisions =
RoundUpToAudioBlock(sampleRate, mCurrentTime + MillisecondsToMediaTime(AUDIO_TARGET_MS));
RoundUpToNextAudioBlock(sampleRate, mCurrentTime + MillisecondsToMediaTime(AUDIO_TARGET_MS));
bool ensureNextIteration = false;
// Grab pending stream input.