Bug 1654112 - Always iterate the graph on a data callback. r=padenot

Before this patch, if the data callback contained less data than was left over
from the last iteration, we'd skip iterating the graph again. The graph is
however is capable of 0-iterations.

This patch removes that optimization so that every data callback results in an
iteration.

This makes it easier to defer processing input data to the track processing
step, as is needed by the next patch in this stack, to keep input and output as
handed to AudioProcessing in sync as config changes are applied with
ControlMessages (in between input and output data notifications). With input
data processing deferred, ControlMessages are run first, then processing of
input data and last processing of output data.

Differential Revision: https://phabricator.services.mozilla.com/D102650
This commit is contained in:
Andreas Pehrson 2021-01-21 22:37:16 +01:00
parent 89e433e51a
commit 3fdb5d8a29
2 changed files with 5 additions and 18 deletions

View File

@ -50,8 +50,7 @@ class AudioMixer {
/* Get the data from the mixer. This is supposed to be called when all the
* tracks have been mixed in. The caller should not hold onto the data. */
void FinishMixing() {
MOZ_ASSERT(mChannels && mFrames && mSampleRate,
"Mix not called for this cycle?");
MOZ_ASSERT(mChannels && mSampleRate, "Mix not called for this cycle?");
for (MixerCallback* cb = mCallbacks.getFirst(); cb != nullptr;
cb = cb->getNext()) {
MixerCallbackReceiver* receiver = cb->mReceiver;

View File

@ -945,22 +945,10 @@ long AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer,
mSampleRate, mInputChannelCount, alreadyBuffered);
}
bool iterate = mBuffer.Available();
IterationResult result =
iterate
? Graph()->OneIteration(nextStateComputedTime, mIterationEnd, &mMixer)
: IterationResult::CreateStillProcessing();
if (iterate) {
// We totally filled the buffer (and mScratchBuffer isn't empty).
// We don't need to run an iteration and if we do so we may overflow.
mStateComputedTime = nextStateComputedTime;
} else {
LOG(LogLevel::Verbose,
("%p: DataCallback buffer filled entirely from scratch "
"buffer, skipping iteration.",
Graph()));
result = IterationResult::CreateStillProcessing();
}
Graph()->OneIteration(nextStateComputedTime, mIterationEnd, &mMixer);
mStateComputedTime = nextStateComputedTime;
MOZ_ASSERT(mBuffer.Available() == 0,
"The graph should have filled the buffer");
@ -1099,7 +1087,7 @@ void AudioCallbackDriver::MixerCallback(AudioDataValue* aMixedBuffer,
MOZ_ASSERT(InIteration());
uint32_t toWrite = mBuffer.Available();
if (!mBuffer.Available()) {
if (!mBuffer.Available() && aFrames > 0) {
NS_WARNING("DataCallback buffer full, expect frame drops.");
}