b=916680 don't keep active AudioNodes alive from an AudioContext that has shut down r=ehsan
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 18 Sep 2013 13:10:30 +1200
changeset 147670 050030456ff517e72e684b819df6c3410584dcec
parent 147669 81d850fca7b0ea73c2dcfa6ae83cdf74d37dc28f
child 147671 fcdd366cd2f5ee1185b3a85fe822597f80cd5ac6
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersehsan
bugs916680
milestone27.0a1
b=916680 don't keep active AudioNodes alive from an AudioContext that has shut down r=ehsan
content/media/webaudio/AudioContext.cpp
content/media/webaudio/AudioContext.h
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -55,16 +55,17 @@ AudioContext::AudioContext(nsPIDOMWindow
                            float aSampleRate)
   : mSampleRate(aIsOffline ? aSampleRate : IdealAudioRate())
   , mDestination(new AudioDestinationNode(MOZ_THIS_IN_INITIALIZER_LIST(),
                                           aIsOffline, aNumberOfChannels,
                                           aLength, aSampleRate))
   , mNumberOfChannels(aNumberOfChannels)
   , mIsOffline(aIsOffline)
   , mIsStarted(!aIsOffline)
+  , mIsShutDown(false)
 {
   // Actually play audio
   mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
   nsDOMEventTargetHelper::BindToOwner(aWindow);
   aWindow->AddAudioContext(this);
   SetIsDOMBinding();
 }
 
@@ -438,17 +439,19 @@ void
 AudioContext::RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob)
 {
   mDecodeJobs.RemoveElement(aDecodeJob);
 }
 
 void
 AudioContext::RegisterActiveNode(AudioNode* aNode)
 {
-  mActiveNodes.PutEntry(aNode);
+  if (!mIsShutDown) {
+    mActiveNodes.PutEntry(aNode);
+  }
 }
 
 void
 AudioContext::UnregisterActiveNode(AudioNode* aNode)
 {
   mActiveNodes.RemoveEntry(aNode);
 }
 
@@ -531,16 +534,18 @@ static void
 GetHashtableElements(nsTHashtable<nsPtrHashKey<T> >& aHashtable, nsTArray<T*>& aArray)
 {
   aHashtable.EnumerateEntries(&GetHashtableEntry<T>, &aArray);
 }
 
 void
 AudioContext::Shutdown()
 {
+  mIsShutDown = true;
+
   Suspend();
 
   // Release references to active nodes.
   // Active AudioNodes don't unregister in destructors, at which point the
   // Node is already unregistered.
   mActiveNodes.Clear();
 
   // Stop all audio buffer source nodes, to make sure that they release
--- a/content/media/webaudio/AudioContext.h
+++ b/content/media/webaudio/AudioContext.h
@@ -265,15 +265,16 @@ private:
   nsTHashtable<nsPtrHashKey<OscillatorNode> > mOscillatorNodes;
   // Hashset containing all ScriptProcessorNodes in order to stop them.
   // These are all weak pointers.
   nsTHashtable<nsPtrHashKey<ScriptProcessorNode> > mScriptProcessorNodes;
   // Number of channels passed in the OfflineAudioContext ctor.
   uint32_t mNumberOfChannels;
   bool mIsOffline;
   bool mIsStarted;
+  bool mIsShutDown;
 };
 
 }
 }
 
 #endif