Commit 6610df62 authored by rtoy's avatar rtoy Committed by Commit bot

Load HRTF database only when the panner is set to HRTF

Currently, the creation of any panner node causes the HRTF database to
be loaded.  However, the default panning model is "equalpower" (about
99.8%) so loading the database is a waste of time and memory.
(According to https://codereview.chromium.org/176683003/, it takes
30MB to hold the database.)

Thus, only load the HRTF database when the panning model is set to
HRTF.

Can't test this easily, but did verify with a debugger that the
database is only created when the panning model is set to HRTF and not
before.

BUG=592787
TEST=none

Review-Url: https://codereview.chromium.org/2171703003
Cr-Commit-Position: refs/heads/master@{#407307}
parent 1b289d98
......@@ -231,13 +231,15 @@ void AudioListener::updateState()
void AudioListener::createAndLoadHRTFDatabaseLoader(float sampleRate)
{
DCHECK(isMainThread());
if (!m_hrtfDatabaseLoader)
m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(sampleRate);
}
bool AudioListener::isHRTFDatabaseLoaded()
{
return m_hrtfDatabaseLoader->isLoaded();
return m_hrtfDatabaseLoader && m_hrtfDatabaseLoader->isLoaded();
}
void AudioListener::waitForHRTFDatabaseLoaderThreadCompletion()
......
......@@ -67,10 +67,6 @@ PannerHandler::PannerHandler(
, m_orientationY(orientationY)
, m_orientationZ(orientationZ)
{
// 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.
listener()->createAndLoadHRTFDatabaseLoader(node.context()->sampleRate());
addInput();
addOutput(2);
......@@ -276,33 +272,37 @@ String PannerHandler::panningModel() const
void PannerHandler::setPanningModel(const String& model)
{
// WebIDL should guarantee that we are never called with an invalid string
// for the model.
if (model == "equalpower")
setPanningModel(Panner::PanningModelEqualPower);
else if (model == "HRTF")
setPanningModel(Panner::PanningModelHRTF);
else
NOTREACHED();
}
// This method should only be called from setPanningModel(const String&)!
bool PannerHandler::setPanningModel(unsigned model)
{
DEFINE_STATIC_LOCAL(EnumerationHistogram, panningModelHistogram,
("WebAudio.PannerNode.PanningModel", 2));
panningModelHistogram.count(model);
switch (model) {
case Panner::PanningModelEqualPower:
case Panner::PanningModelHRTF:
if (!m_panner.get() || model != m_panningModel) {
// This synchronizes with process().
MutexLocker processLocker(m_processLock);
m_panner = Panner::create(model, sampleRate(), listener()->hrtfDatabaseLoader());
m_panningModel = model;
}
break;
default:
ASSERT_NOT_REACHED();
return false;
if (model == Panner::PanningModelHRTF) {
// Load the HRTF database asynchronously so we don't block the
// Javascript thread while creating the HRTF database. It's ok to call
// this multiple times; we won't be constantly loading the database over
// and over.
listener()->createAndLoadHRTFDatabaseLoader(context()->sampleRate());
}
if (!m_panner.get() || model != m_panningModel) {
// This synchronizes with process().
MutexLocker processLocker(m_processLock);
m_panner = Panner::create(model, sampleRate(), listener()->hrtfDatabaseLoader());
m_panningModel = model;
}
return true;
}
......
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