Bug 1406027 - Always use the mixer so AudioCallbackDriver can track processed samples. r?padenot draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Fri, 06 Oct 2017 12:42:11 +0200
changeset 677234 27719c0be40a77be79d32c7f67acd3be768af584
parent 670875 70158e4e215d784d1391db5e517b18727f4b3683
child 735153 1a03f026e243a2166750fea842d84bd59362d66a
push id83731
push userbmo:apehrson@mozilla.com
push dateTue, 10 Oct 2017 11:55:18 +0000
reviewerspadenot
bugs1406027
milestone58.0a1
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
dom/media/AudioMixer.h
dom/media/MediaStreamGraph.cpp
--- 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();
   }
 }