Title: [176403] trunk/Source/WebCore
Revision
176403
Author
[email protected]
Date
2014-11-20 10:50:12 -0800 (Thu, 20 Nov 2014)

Log Message

Add a way to mute an AudioContext.
https://bugs.webkit.org/show_bug.cgi?id=138104

Reviewed by Eric Carlson.

Keep a muted state in AudioDestinationNode. If m_muted is true,
zero out the audio buffers.

No new tests, since it's difficult to test whether the audio is indeed muted.

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::AudioContext):
Call pageMutedStateDidChange() so it'll initialize the destination audio node's muted state accordingly.
(WebCore::AudioContext::pageMutedStateDidChange):
Set the destination audio node's muted state to match the page's muted state.

* Modules/webaudio/AudioDestinationNode.cpp:
(WebCore::AudioDestinationNode::AudioDestinationNode):
Initialize m_muted.
(WebCore::AudioDestinationNode::render):
If m_muted is true, call AudioBus::zero() to zero out the buffers.
* Modules/webaudio/AudioDestinationNode.h:
(WebCore::AudioDestinationNode::setMuted):
Set m_muted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176402 => 176403)


--- trunk/Source/WebCore/ChangeLog	2014-11-20 18:44:12 UTC (rev 176402)
+++ trunk/Source/WebCore/ChangeLog	2014-11-20 18:50:12 UTC (rev 176403)
@@ -1,3 +1,30 @@
+2014-11-19  Ada Chan  <[email protected]>
+
+        Add a way to mute an AudioContext.
+        https://bugs.webkit.org/show_bug.cgi?id=138104
+
+        Reviewed by Eric Carlson.
+
+        Keep a muted state in AudioDestinationNode. If m_muted is true,
+        zero out the audio buffers.
+
+        No new tests, since it's difficult to test whether the audio is indeed muted.
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::AudioContext):
+        Call pageMutedStateDidChange() so it'll initialize the destination audio node's muted state accordingly.
+        (WebCore::AudioContext::pageMutedStateDidChange):
+        Set the destination audio node's muted state to match the page's muted state.
+
+        * Modules/webaudio/AudioDestinationNode.cpp:
+        (WebCore::AudioDestinationNode::AudioDestinationNode):
+        Initialize m_muted.
+        (WebCore::AudioDestinationNode::render):
+        If m_muted is true, call AudioBus::zero() to zero out the buffers.
+        * Modules/webaudio/AudioDestinationNode.h:
+        (WebCore::AudioDestinationNode::setMuted):
+        Set m_muted.
+
 2014-11-20  Chris Dumez  <[email protected]>
 
         Crash when destroying a Document that has a throttled timer still running

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (176402 => 176403)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2014-11-20 18:44:12 UTC (rev 176402)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2014-11-20 18:50:12 UTC (rev 176403)
@@ -142,6 +142,9 @@
     constructCommon();
 
     m_destinationNode = DefaultAudioDestinationNode::create(this);
+
+    // Initialize the destination node's muted state to match the page's current muted state.
+    pageMutedStateDidChange();
 }
 
 // Constructor for offline (non-realtime) rendering.
@@ -975,7 +978,8 @@
 
 void AudioContext::pageMutedStateDidChange()
 {
-    // FIXME https://bugs.webkit.org/show_bug.cgi?id=138104: Handle muting web audio.
+    if (m_destinationNode && document()->page())
+        m_destinationNode->setMuted(document()->page()->isMuted());
 }
 
 void AudioContext::isPlayingAudioDidChange()

Modified: trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp (176402 => 176403)


--- trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp	2014-11-20 18:44:12 UTC (rev 176402)
+++ trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp	2014-11-20 18:50:12 UTC (rev 176403)
@@ -41,6 +41,7 @@
     , m_currentSampleFrame(0)
     , m_isSilent(true)
     , m_isEffectivelyPlayingAudio(false)
+    , m_muted(false)
 {
     addInput(std::make_unique<AudioNodeInput>(this));
     
@@ -107,6 +108,11 @@
     m_currentSampleFrame += numberOfFrames;
 
     setIsSilent(destinationBus->isSilent());
+
+    // The reason we are handling mute after the call to setIsSilent() is because the muted state does
+    // not affect the audio destination node's effective playing state.
+    if (m_muted)
+        destinationBus->zero();
 }
 
 void AudioDestinationNode::isPlayingDidChange()

Modified: trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.h (176402 => 176403)


--- trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.h	2014-11-20 18:44:12 UTC (rev 176402)
+++ trunk/Source/WebCore/Modules/webaudio/AudioDestinationNode.h	2014-11-20 18:50:12 UTC (rev 176403)
@@ -64,6 +64,7 @@
     virtual bool isPlaying() { return false; }
     virtual void isPlayingDidChange() override;
     bool isPlayingAudio() const { return m_isEffectivelyPlayingAudio; }
+    void setMuted(bool muted) { m_muted = muted; }
 
 protected:
     // LocalAudioInputProvider allows us to expose an AudioSourceProvider for local/live audio input.
@@ -106,6 +107,7 @@
     LocalAudioInputProvider m_localAudioInputProvider;
     bool m_isSilent;
     bool m_isEffectivelyPlayingAudio;
+    bool m_muted;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to