Bug 966247 - Make MediaElementAudioSourceNode take the HTMLMediaElement volume into account. r=padenot
authorCgg <clement.geiger@gmail.com>
Sun, 22 Jun 2014 14:12:57 +0200
changeset 230158 59240f2df2c223d0bf7efbccde8cba6991e7138b
parent 230157 e22919023341136bf1272cb75efd542e38fb4a0d
child 230159 f718ec4b4cb013a60fa3ce2941208eb07f456be8
push id7326
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:58:42 +0000
treeherdermozilla-aurora@d3a3b2a0f2f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs966247
milestone36.0a1
Bug 966247 - Make MediaElementAudioSourceNode take the HTMLMediaElement volume into account. r=padenot
dom/media/MediaDecoderStateMachine.cpp
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_bug966247.html
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -337,16 +337,17 @@ void MediaDecoderStateMachine::SendStrea
   nsAutoTArray<const AudioDataValue*,2> channels;
   for (uint32_t i = 0; i < aAudio->mChannels; ++i) {
     channels.AppendElement(bufferData + i*aAudio->mFrames + offset);
   }
   aOutput->AppendFrames(buffer.forget(), channels, aAudio->mFrames);
   VERBOSE_LOG("writing %d frames of data to MediaStream for AudioData at %lld",
               aAudio->mFrames - int32_t(offset), aAudio->mTime);
   aStream->mAudioFramesWritten += aAudio->mFrames - int32_t(offset);
+  aOutput->ApplyVolume(mVolume);
 }
 
 static void WriteVideoToMediaStream(layers::Image* aImage,
                                     int64_t aDuration,
                                     const IntSize& aIntrinsicSize,
                                     VideoSegment* aOutput)
 {
   nsRefPtr<layers::Image> image = aImage;
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -67,16 +67,17 @@ skip-if = (toolkit == 'gonk') || (toolki
 [test_bug867104.html]
 [test_bug867174.html]
 [test_bug867203.html]
 [test_bug875221.html]
 [test_bug875402.html]
 [test_bug894150.html]
 [test_bug956489.html]
 [test_bug964376.html]
+[test_bug966247.html]
 [test_bug972678.html]
 [test_bug1056032.html]
 skip-if = toolkit == 'android' # bug 1056706
 [test_channelMergerNode.html]
 [test_channelMergerNodeWithVolume.html]
 [test_channelSplitterNode.html]
 [test_channelSplitterNodeWithVolume.html]
 [test_convolverNode.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_bug966247.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test whether an audio file played with a volume set to 0 plays silence</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<audio preload=none src="ting-48k-1ch.ogg" controls> </audio>
+<script>
+  SimpleTest.waitForExplicitFinish();
+
+  var count = 20;
+
+  function isSilent(b) {
+    for (var i = 0; i < b.length; b++) {
+      if (b[i] != 0.0) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  var a = document.getElementsByTagName("audio")[0];
+  a.volume = 0.0;
+  var ac = new AudioContext();
+  var measn = ac.createMediaElementSource(a);
+  var sp = ac.createScriptProcessor();
+
+  sp.onaudioprocess = function(e) {
+    var inputBuffer = e.inputBuffer.getChannelData(0);
+    ok(isSilent(inputBuffer), "The volume is set to 0, so all the elements of the buffer are supposed to be equal to 0.0");
+  }
+  // Connect the MediaElementAudioSourceNode to the ScriptProcessorNode to check
+  // the audio volume.
+  measn.connect(sp);
+  a.play();
+
+  a.addEventListener("ended", function() {
+    sp.onaudioprocess = null;
+    SimpleTest.finish();
+  });
+
+</script>
+</body>
+</html>