Bug 1440040 - Don't round up to next block unless necessary. r=padenot

With block size 128, rounding `128` to end of next block gives `256`, which is
not what we want when running MSG iterations. That could mean over-iterating and
buffering unnecessary amounts of silence.

MozReview-Commit-ID: vW14l2ygRy

--HG--
extra : rebase_source : 8aeedc8958e646f9730c9163447e3355a73fd42e
This commit is contained in:
Andreas Pehrson 2018-02-28 22:37:02 +01:00
Родитель d96c554c26
Коммит 60f3567035
3 изменённых файлов: 22 добавлений и 8 удалений

Просмотреть файл

@ -295,7 +295,7 @@ ThreadedDriver::RunThread()
}
GraphTime nextStateComputedTime =
mGraphImpl->RoundUpToNextAudioBlock(
mGraphImpl->RoundUpToEndOfAudioBlock(
mIterationEnd + mGraphImpl->MillisecondsToMediaTime(AUDIO_TARGET_MS));
if (nextStateComputedTime < stateComputedTime) {
// A previous driver may have been processing further ahead of
@ -923,7 +923,8 @@ AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer,
// compute the iteration start and end from there, trying to keep the amount
// of buffering in the graph constant.
GraphTime nextStateComputedTime =
mGraphImpl->RoundUpToNextAudioBlock(stateComputedTime + mBuffer.Available());
mGraphImpl->RoundUpToEndOfAudioBlock(
stateComputedTime + mBuffer.Available());
mIterationStart = mIterationEnd;
// inGraph is the number of audio frames there is between the state time and

Просмотреть файл

@ -1051,14 +1051,22 @@ MediaStreamGraphImpl::PrepareUpdatesToMainThreadState(bool aFinalUpdate)
}
}
GraphTime
MediaStreamGraphImpl::RoundUpToEndOfAudioBlock(GraphTime aTime)
{
if (aTime % WEBAUDIO_BLOCK_SIZE == 0) {
return aTime;
}
return RoundUpToNextAudioBlock(aTime);
}
GraphTime
MediaStreamGraphImpl::RoundUpToNextAudioBlock(GraphTime aTime)
{
StreamTime ticks = aTime;
uint64_t block = ticks >> WEBAUDIO_BLOCK_SIZE_BITS;
uint64_t block = aTime >> WEBAUDIO_BLOCK_SIZE_BITS;
uint64_t nextBlock = block + 1;
StreamTime nextTicks = nextBlock << WEBAUDIO_BLOCK_SIZE_BITS;
return nextTicks;
GraphTime nextTime = nextBlock << WEBAUDIO_BLOCK_SIZE_BITS;
return nextTime;
}
void
@ -4243,8 +4251,8 @@ MediaStreamGraph::StartNonRealtimeProcessing(uint32_t aTicksToProcess)
return;
graph->mEndTime =
graph->RoundUpToNextAudioBlock(graph->mStateComputedTime +
aTicksToProcess - 1);
graph->RoundUpToEndOfAudioBlock(graph->mStateComputedTime +
aTicksToProcess);
graph->mNonRealtimeProcessing = true;
graph->EnsureRunInStableState();
}

Просмотреть файл

@ -333,6 +333,11 @@ public:
*/
void UpdateStreamOrder();
/**
* Returns smallest value of t such that t is a multiple of
* WEBAUDIO_BLOCK_SIZE and t >= aTime.
*/
GraphTime RoundUpToEndOfAudioBlock(GraphTime aTime);
/**
* Returns smallest value of t such that t is a multiple of
* WEBAUDIO_BLOCK_SIZE and t > aTime.