Bug 1406027 - Always use the mixer so AudioCallbackDriver can track processed samples. r?padenot
This is unnecessary work but simpler than adding a path to, or refactoring, AudioCallbackDriver::DataCallback.
MozReview-Commit-ID: GLNoBqxEuwz
--- a/dom/media/AudioMixer.h
+++ b/dom/media/AudioMixer.h
@@ -68,32 +68,37 @@ public:
mChannels,
mFrames,
mSampleRate);
}
PodZero(mMixedAudio.Elements(), mMixedAudio.Length());
mSampleRate = mChannels = mFrames = 0;
}
- /* Add a buffer to the mix. */
+ /* Add a buffer to the mix. The buffer can be null if there's nothing to mix
+ * but the callback is still needed. */
void Mix(AudioDataValue* aSamples,
uint32_t aChannels,
uint32_t aFrames,
uint32_t aSampleRate) {
if (!mFrames && !mChannels) {
mFrames = aFrames;
mChannels = aChannels;
mSampleRate = aSampleRate;
EnsureCapacityAndSilence();
}
MOZ_ASSERT(aFrames == mFrames);
MOZ_ASSERT(aChannels == mChannels);
MOZ_ASSERT(aSampleRate == mSampleRate);
+ if (!aSamples) {
+ return;
+ }
+
for (uint32_t i = 0; i < aFrames * aChannels; i++) {
mMixedAudio[i] += aSamples[i];
}
}
void AddCallback(MixerCallbackReceiver* aReceiver) {
mCallbacks.insertBack(new MixerCallback(aReceiver));
}
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1402,17 +1402,26 @@ MediaStreamGraphImpl::Process()
}
}
}
if (stream->mStartBlocking > mProcessedTime) {
allBlockedForever = false;
}
}
- if (CurrentDriver()->AsAudioCallbackDriver() && ticksPlayed) {
+ if (CurrentDriver()->AsAudioCallbackDriver()) {
+ if (!ticksPlayed) {
+ // Nothing was played, so the mixer doesn't know how many frames were
+ // processed. We still tell it so AudioCallbackDriver knows how much has
+ // been processed. (bug 1406027)
+ mMixer.Mix(nullptr,
+ CurrentDriver()->AsAudioCallbackDriver()->OutputChannelCount(),
+ mStateComputedTime - mProcessedTime,
+ mSampleRate);
+ }
mMixer.FinishMixing();
}
if (!allBlockedForever) {
EnsureNextIteration();
}
}