Move handle of HRTFDatabaseLoader to AudioListener.

Fix regression on specific application.

http://googlechrome.github.io/web-audio-samples/samples/audio/box2d-js/box2d-audio.html

Although a HRTFDatabaseLoader should keep the handle until AudioContext is destroyed,
a panner node tries to create the loader again since being removed the handle
by deref() of AudioNode.

The handle has been moved to AudioListener that is related mostly to keep the handle.

BUG=393751

Review URL: https://codereview.chromium.org/393363002

git-svn-id: svn://svn.chromium.org/blink/trunk@178583 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 106d9e3f
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "modules/webaudio/PannerNode.h" #include "modules/webaudio/PannerNode.h"
#include "platform/audio/AudioBus.h" #include "platform/audio/AudioBus.h"
#include "platform/audio/HRTFDatabaseLoader.h"
namespace blink { namespace blink {
...@@ -71,6 +72,22 @@ void AudioListener::removePanner(PannerNode* panner) ...@@ -71,6 +72,22 @@ void AudioListener::removePanner(PannerNode* panner)
} }
} }
void AudioListener::createAndLoadHRTFDatabaseLoader(float sampleRate)
{
if (!m_hrtfDatabaseLoader)
m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(sampleRate);
}
bool AudioListener::isHRTFDatabaseLoaded()
{
return m_hrtfDatabaseLoader->isLoaded();
}
void AudioListener::waitForHRTFDatabaseLoaderThreadCompletion()
{
m_hrtfDatabaseLoader->waitForLoaderThreadCompletion();
}
void AudioListener::markPannersAsDirty(unsigned type) void AudioListener::markPannersAsDirty(unsigned type)
{ {
for (unsigned i = 0; i < m_panners.size(); ++i) for (unsigned i = 0; i < m_panners.size(); ++i)
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
namespace blink { namespace blink {
class HRTFDatabaseLoader;
class PannerNode; class PannerNode;
// AudioListener maintains the state of the listener in the audio scene as defined in the OpenAL specification. // AudioListener maintains the state of the listener in the audio scene as defined in the OpenAL specification.
...@@ -79,6 +80,12 @@ public: ...@@ -79,6 +80,12 @@ public:
void addPanner(PannerNode*); void addPanner(PannerNode*);
void removePanner(PannerNode*); void removePanner(PannerNode*);
// HRTF DB loader
HRTFDatabaseLoader* hrtfDatabaseLoader() { return m_hrtfDatabaseLoader.get(); }
void createAndLoadHRTFDatabaseLoader(float);
bool isHRTFDatabaseLoaded();
void waitForHRTFDatabaseLoaderThreadCompletion();
void trace(Visitor*) { } void trace(Visitor*) { }
private: private:
...@@ -100,9 +107,10 @@ private: ...@@ -100,9 +107,10 @@ private:
// Synchronize a panner's process() with setting of the state of the listener. // Synchronize a panner's process() with setting of the state of the listener.
mutable Mutex m_listenerLock; mutable Mutex m_listenerLock;
// List for pannerNodes in context. // List for pannerNodes in context.
Vector<PannerNode*> m_panners; Vector<PannerNode*> m_panners;
// HRTF DB loader for panner node.
RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
}; };
} // WebCore } // WebCore
......
...@@ -63,7 +63,7 @@ PannerNode::PannerNode(AudioContext* context, float sampleRate) ...@@ -63,7 +63,7 @@ PannerNode::PannerNode(AudioContext* context, float sampleRate)
{ {
// Load the HRTF database asynchronously so we don't block the Javascript thread while creating the HRTF database. // Load the HRTF database asynchronously so we don't block the Javascript thread while creating the HRTF database.
// The HRTF panner will return zeroes until the database is loaded. // The HRTF panner will return zeroes until the database is loaded.
m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(context->sampleRate()); listener()->createAndLoadHRTFDatabaseLoader(context->sampleRate());
ScriptWrappable::init(this); ScriptWrappable::init(this);
addInput(); addInput();
...@@ -123,9 +123,9 @@ void PannerNode::process(size_t framesToProcess) ...@@ -123,9 +123,9 @@ void PannerNode::process(size_t framesToProcess)
if (tryLocker.locked() && tryListenerLocker.locked()) { if (tryLocker.locked() && tryListenerLocker.locked()) {
// HRTFDatabase should be loaded before proceeding for offline audio context when the panning model is HRTF. // HRTFDatabase should be loaded before proceeding for offline audio context when the panning model is HRTF.
if (m_panningModel == Panner::PanningModelHRTF && !m_hrtfDatabaseLoader->isLoaded()) { if (m_panningModel == Panner::PanningModelHRTF && !listener()->isHRTFDatabaseLoaded()) {
if (context()->isOfflineContext()) { if (context()->isOfflineContext()) {
m_hrtfDatabaseLoader->waitForLoaderThreadCompletion(); listener()->waitForHRTFDatabaseLoaderThreadCompletion();
} else { } else {
destination->zero(); destination->zero();
return; return;
...@@ -160,7 +160,7 @@ void PannerNode::initialize() ...@@ -160,7 +160,7 @@ void PannerNode::initialize()
if (isInitialized()) if (isInitialized())
return; return;
m_panner = Panner::create(m_panningModel, sampleRate(), m_hrtfDatabaseLoader.get()); m_panner = Panner::create(m_panningModel, sampleRate(), listener()->hrtfDatabaseLoader());
listener()->addPanner(this); listener()->addPanner(this);
AudioNode::initialize(); AudioNode::initialize();
...@@ -211,7 +211,7 @@ bool PannerNode::setPanningModel(unsigned model) ...@@ -211,7 +211,7 @@ bool PannerNode::setPanningModel(unsigned model)
if (!m_panner.get() || model != m_panningModel) { if (!m_panner.get() || model != m_panningModel) {
// This synchronizes with process(). // This synchronizes with process().
MutexLocker processLocker(m_processLock); MutexLocker processLocker(m_processLock);
OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), m_hrtfDatabaseLoader.get()); OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), listener()->hrtfDatabaseLoader());
m_panner = newPanner.release(); m_panner = newPanner.release();
m_panningModel = model; m_panningModel = model;
} }
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "platform/audio/AudioBus.h" #include "platform/audio/AudioBus.h"
#include "platform/audio/Cone.h" #include "platform/audio/Cone.h"
#include "platform/audio/Distance.h" #include "platform/audio/Distance.h"
#include "platform/audio/HRTFDatabaseLoader.h"
#include "platform/audio/Panner.h" #include "platform/audio/Panner.h"
#include "modules/webaudio/AudioListener.h" #include "modules/webaudio/AudioListener.h"
#include "modules/webaudio/AudioNode.h" #include "modules/webaudio/AudioNode.h"
...@@ -155,8 +154,6 @@ private: ...@@ -155,8 +154,6 @@ private:
float m_cachedDistanceConeGain; float m_cachedDistanceConeGain;
double m_cachedDopplerRate; double m_cachedDopplerRate;
RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
// AudioContext's connection count // AudioContext's connection count
unsigned m_connectionCount; unsigned m_connectionCount;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment