From bd4b9d61f6215f55a54c798f7dc5d1fdfd6f5f00 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sat, 15 Aug 2015 18:36:13 -0400 Subject: [PATCH] Bug 1195051 - Part 2: Mute the destination node when the AudioContext is suspended, and unmute when resumed; r=padenot --- dom/media/webaudio/AudioContext.cpp | 4 +-- dom/media/webaudio/AudioDestinationNode.cpp | 31 +++++++++++++++++++++ dom/media/webaudio/AudioDestinationNode.h | 3 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index aa88af354be5..50731d37587f 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -855,7 +855,7 @@ AudioContext::Suspend(ErrorResult& aRv) return promise.forget(); } - Destination()->DestroyAudioChannelAgent(); + Destination()->Suspend(); MediaStream* ds = DestinationStream(); if (ds) { @@ -895,7 +895,7 @@ AudioContext::Resume(ErrorResult& aRv) return promise.forget(); } - Destination()->CreateAudioChannelAgent(); + Destination()->Resume(); MediaStream* ds = DestinationStream(); if (ds) { diff --git a/dom/media/webaudio/AudioDestinationNode.cpp b/dom/media/webaudio/AudioDestinationNode.cpp index dc01969210b4..daa58389b5c6 100644 --- a/dom/media/webaudio/AudioDestinationNode.cpp +++ b/dom/media/webaudio/AudioDestinationNode.cpp @@ -244,6 +244,7 @@ public: : AudioNodeEngine(aNode) , mVolume(1.0f) , mLastInputMuted(true) + , mSuspended(false) { MOZ_ASSERT(aNode); } @@ -256,6 +257,10 @@ public: *aOutput = aInput; aOutput->mVolume *= mVolume; + if (mSuspended) { + return; + } + bool newInputMuted = aInput.IsNull() || aInput.IsMuted(); if (newInputMuted != mLastInputMuted) { mLastInputMuted = newInputMuted; @@ -274,8 +279,19 @@ public: } } + virtual void SetInt32Parameter(uint32_t aIndex, int32_t aParam) override + { + if (aIndex == SUSPENDED) { + mSuspended = !!aParam; + if (mSuspended) { + mLastInputMuted = true; + } + } + } + enum Parameters { VOLUME, + SUSPENDED, }; virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override @@ -286,6 +302,7 @@ public: private: float mVolume; bool mLastInputMuted; + bool mSuspended; }; static bool UseAudioChannelService() @@ -451,6 +468,20 @@ AudioDestinationNode::Unmute() SendDoubleParameterToStream(DestinationNodeEngine::VOLUME, 1.0f); } +void +AudioDestinationNode::Suspend() +{ + DestroyAudioChannelAgent(); + SendInt32ParameterToStream(DestinationNodeEngine::SUSPENDED, 1); +} + +void +AudioDestinationNode::Resume() +{ + CreateAudioChannelAgent(); + SendInt32ParameterToStream(DestinationNodeEngine::SUSPENDED, 0); +} + void AudioDestinationNode::OfflineShutdown() { diff --git a/dom/media/webaudio/AudioDestinationNode.h b/dom/media/webaudio/AudioDestinationNode.h index 724e44d61d3c..632c2453e687 100644 --- a/dom/media/webaudio/AudioDestinationNode.h +++ b/dom/media/webaudio/AudioDestinationNode.h @@ -53,6 +53,9 @@ public: void Mute(); void Unmute(); + void Suspend(); + void Resume(); + void StartRendering(Promise* aPromise); void OfflineShutdown();