Bug 1061702: Stop audio sources from continuing to play garbage after being stopped r=roc a=lmandel
authorRandell Jesup <rjesup@jesup.org>
Fri, 03 Oct 2014 00:47:59 -0400
changeset 221107 d9f441a027e5c320647f63eda2ed673784c8a931
parent 221106 a8edc81c39d564c3c8494615f2f4e9c10e2012cb
child 221108 0430d2b93ed3b1b4b8d3b06ea1d708b7105a5a8e
push id146
push userryanvm@gmail.com
push dateThu, 06 Nov 2014 22:02:02 +0000
treeherdermozilla-b2g34_v2_1@2e81cf5d2bd7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, lmandel
bugs1061702
milestone34.0
Bug 1061702: Stop audio sources from continuing to play garbage after being stopped r=roc a=lmandel * clear audio callback buffer if no streams have audio
content/media/AudioBufferUtils.h
--- a/content/media/AudioBufferUtils.h
+++ b/content/media/AudioBufferUtils.h
@@ -72,19 +72,28 @@ public:
 
   /**
    * Check that the buffer is completly filled, and reset internal state so this
    * instance can be reused.
    */
   void BufferFilled() {
     // It's okay to have exactly zero samples here, it can happen we have an
     // audio callback driver because of a hint on MSG creation, but the
-    // AudioOutputStream has not been created yet.
+    // AudioOutputStream has not been created yet, or if all the streams have finished
+    // but we're still running.
+    // Note: it's also ok if we had data in the scratch buffer - and we usually do - and
+    // all the streams were ended (no mixer callback occured).
+    // XXX Remove this warning, or find a way to avoid it if the mixer callback
+    // isn't called.
     NS_WARN_IF_FALSE(Available() == 0 || mSampleWriteOffset == 0,
             "Audio Buffer is not full by the end of the callback.");
+    // Make sure the data returned is always set and not random!
+    if (Available()) {
+      PodZero(mBuffer + mSampleWriteOffset, FramesToSamples(CHANNELS, Available()));
+    }
     MOZ_ASSERT(mSamples, "Buffer not set.");
     mSamples = 0;
     mSampleWriteOffset = 0;
     mBuffer = nullptr;
   }
 
 private:
   /* This is not an owned pointer, but the pointer passed to use via the audio