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 225949 d9f441a027e5
parent 225948 a8edc81c39d5
child 225950 0430d2b93ed3
push id4079
push userrjesup@wgate.com
push date2014-11-05 21:39 +0000
treeherdermozilla-beta@d9f441a027e5 [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