Bug 1406027 - Always use the mixer so AudioCallbackDriver can track processed samples. r=padenot
authorAndreas Pehrson <pehrsons@mozilla.com>
Fri, 06 Oct 2017 12:42:11 +0200
changeset 385325 02be66f5ff0c2eb9cb5c4cfda62ad26d2312804f
parent 385324 2ece41a76b0c270b66b35d23434f799fb13b0c1f
child 385326 2f5f7289c2d5a1f7ab3e592cb7900a9217a21970
push id32652
push userarchaeopteryx@coole-files.de
push dateTue, 10 Oct 2017 21:49:31 +0000
treeherdermozilla-central@f1ecd5c26948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1406027
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -1396,17 +1396,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();
   }
 }