Bug 865548 - Convert the node arrays in AudioContext to hashsets; r=padenot

This commit is contained in:
Ehsan Akhgari 2013-04-24 23:32:41 -04:00
parent d2d94d205c
commit 6aacd34ff0
2 changed files with 52 additions and 24 deletions

View File

@ -44,6 +44,10 @@ AudioContext::AudioContext(nsPIDOMWindow* aWindow)
// Actually play audio
mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
SetIsDOMBinding();
mPannerNodes.Init();
mAudioBufferSourceNodes.Init();
mScriptProcessorNodes.Init();
}
AudioContext::~AudioContext()
@ -75,7 +79,7 @@ AudioContext::CreateBufferSource()
{
nsRefPtr<AudioBufferSourceNode> bufferNode =
new AudioBufferSourceNode(this);
mAudioBufferSourceNodes.AppendElement(bufferNode);
mAudioBufferSourceNodes.PutEntry(bufferNode);
return bufferNode.forget();
}
@ -141,7 +145,7 @@ AudioContext::CreateScriptProcessor(uint32_t aBufferSize,
nsRefPtr<ScriptProcessorNode> scriptProcessor =
new ScriptProcessorNode(this, aBufferSize, aNumberOfInputChannels,
aNumberOfOutputChannels);
mScriptProcessorNodes.AppendElement(scriptProcessor);
mScriptProcessorNodes.PutEntry(scriptProcessor);
return scriptProcessor.forget();
}
@ -174,7 +178,7 @@ already_AddRefed<PannerNode>
AudioContext::CreatePanner()
{
nsRefPtr<PannerNode> pannerNode = new PannerNode(this);
mPannerNodes.AppendElement(pannerNode);
mPannerNodes.PutEntry(pannerNode);
return pannerNode.forget();
}
@ -237,30 +241,40 @@ AudioContext::RemoveFromDecodeQueue(WebAudioDecodeJob* aDecodeJob)
void
AudioContext::UnregisterAudioBufferSourceNode(AudioBufferSourceNode* aNode)
{
mAudioBufferSourceNodes.RemoveElement(aNode);
mAudioBufferSourceNodes.RemoveEntry(aNode);
}
void
AudioContext::UnregisterPannerNode(PannerNode* aNode)
{
mPannerNodes.RemoveElement(aNode);
mPannerNodes.RemoveEntry(aNode);
}
void
AudioContext::UnregisterScriptProcessorNode(ScriptProcessorNode* aNode)
{
mScriptProcessorNodes.RemoveElement(aNode);
mScriptProcessorNodes.RemoveEntry(aNode);
}
static PLDHashOperator
UnregisterPannerNodeOn(nsPtrHashKey<AudioBufferSourceNode>* aEntry, void* aData)
{
aEntry->GetKey()->UnregisterPannerNode();
return PL_DHASH_NEXT;
}
static PLDHashOperator
FindConnectedSourcesOn(nsPtrHashKey<PannerNode>* aEntry, void* aData)
{
aEntry->GetKey()->FindConnectedSources();
return PL_DHASH_NEXT;
}
void
AudioContext::UpdatePannerSource()
{
for (unsigned i = 0; i < mAudioBufferSourceNodes.Length(); i++) {
mAudioBufferSourceNodes[i]->UnregisterPannerNode();
}
for (unsigned i = 0; i < mPannerNodes.Length(); i++) {
mPannerNodes[i]->FindConnectedSources();
}
mAudioBufferSourceNodes.EnumerateEntries(UnregisterPannerNodeOn, nullptr);
mPannerNodes.EnumerateEntries(FindConnectedSourcesOn, nullptr);
}
MediaStreamGraph*
@ -281,6 +295,21 @@ AudioContext::CurrentTime() const
return MediaTimeToSeconds(Destination()->Stream()->GetCurrentTime());
}
static PLDHashOperator
StopAudioBufferSourceNode(nsPtrHashKey<AudioBufferSourceNode>* aEntry, void* aData)
{
ErrorResult rv;
aEntry->GetKey()->Stop(0.0, rv);
return PL_DHASH_NEXT;
}
static PLDHashOperator
StopScriptProcessorNode(nsPtrHashKey<ScriptProcessorNode>* aEntry, void* aData)
{
aEntry->GetKey()->Stop();
return PL_DHASH_NEXT;
}
void
AudioContext::Shutdown()
{
@ -289,15 +318,10 @@ AudioContext::Shutdown()
// Stop all audio buffer source nodes, to make sure that they release
// their self-references.
for (uint32_t i = 0; i < mAudioBufferSourceNodes.Length(); ++i) {
ErrorResult rv;
mAudioBufferSourceNodes[i]->Stop(0.0, rv);
}
mAudioBufferSourceNodes.EnumerateEntries(StopAudioBufferSourceNode, nullptr);
// Stop all script processor nodes, to make sure that they release
// their self-references.
for (uint32_t i = 0; i < mScriptProcessorNodes.Length(); ++i) {
mScriptProcessorNodes[i]->Stop();
}
mScriptProcessorNodes.EnumerateEntries(StopScriptProcessorNode, nullptr);
}
void

View File

@ -19,6 +19,7 @@
#include "MediaBufferDecoder.h"
#include "StreamBuffer.h"
#include "MediaStreamGraph.h"
#include "nsTHashtable.h"
// X11 has a #define for CurrentTime. Unbelievable :-(.
// See content/media/DOMMediaStream.h for more fun!
@ -167,11 +168,14 @@ private:
nsRefPtr<AudioListener> mListener;
MediaBufferDecoder mDecoder;
nsTArray<nsAutoPtr<WebAudioDecodeJob> > mDecodeJobs;
// Two arrays containing all the PannerNodes and AudioBufferSourceNodes,
// to compute the doppler shift. Those are weak pointers.
nsTArray<PannerNode*> mPannerNodes;
nsTArray<AudioBufferSourceNode*> mAudioBufferSourceNodes;
nsTArray<ScriptProcessorNode*> mScriptProcessorNodes;
// Two hashsets containing all the PannerNodes and AudioBufferSourceNodes,
// to compute the doppler shift, and also to stop AudioBufferSourceNodes.
// These are all weak pointers.
nsTHashtable<nsPtrHashKey<PannerNode> > mPannerNodes;
nsTHashtable<nsPtrHashKey<AudioBufferSourceNode> > mAudioBufferSourceNodes;
// Hashset containing all ScriptProcessorNodes in order to stop them.
// These are all weak pointers.
nsTHashtable<nsPtrHashKey<ScriptProcessorNode> > mScriptProcessorNodes;
};
}