Bug 1406027 - Always use the mixer so AudioCallbackDriver can track processed samples. r=padenot, a=ritu
authorAndreas Pehrson <pehrsons@mozilla.com>
Fri, 06 Oct 2017 12:42:11 +0200
changeset 432441 4522bc7343e6a569a032d95a5478192f1ca04f19
parent 432440 9040197e9047d5a28820943f91b8db0945581b74
child 432442 a59416fd921a6ae31849f25238c2cb82bab3d94f
push id7955
push userryanvm@gmail.com
push dateThu, 12 Oct 2017 18:26:39 +0000
treeherdermozilla-beta@c8d3b27528f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, ritu
bugs1406027
milestone57.0
Bug 1406027 - Always use the mixer so AudioCallbackDriver can track processed samples. r=padenot, a=ritu 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();
   }
 }