This source file includes following definitions.
- createAndLoadAsynchronouslyIfNecessary
- load
- loadAsynchronously
- isLoaded
- waitForLoaderThreadCompletion
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "platform/audio/HRTFDatabaseLoader.h"
#include "platform/Task.h"
#include "public/platform/Platform.h"
#include "wtf/MainThread.h"
namespace WebCore {
HRTFDatabaseLoader::LoaderMap* HRTFDatabaseLoader::s_loaderMap = 0;
PassRefPtr<HRTFDatabaseLoader> HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(float sampleRate)
{
ASSERT(isMainThread());
if (!s_loaderMap)
s_loaderMap = adoptPtr(new LoaderMap()).leakPtr();
RefPtr<HRTFDatabaseLoader> loader = s_loaderMap->get(sampleRate);
if (loader) {
ASSERT(sampleRate == loader->databaseSampleRate());
return loader;
}
loader = adoptRef(new HRTFDatabaseLoader(sampleRate));
s_loaderMap->add(sampleRate, loader.get());
loader->loadAsynchronously();
return loader;
}
HRTFDatabaseLoader::HRTFDatabaseLoader(float sampleRate)
: m_databaseSampleRate(sampleRate)
{
ASSERT(isMainThread());
}
HRTFDatabaseLoader::~HRTFDatabaseLoader()
{
ASSERT(isMainThread());
waitForLoaderThreadCompletion();
m_hrtfDatabase.clear();
if (s_loaderMap)
s_loaderMap->remove(m_databaseSampleRate);
}
void HRTFDatabaseLoader::load()
{
ASSERT(!isMainThread());
if (!m_hrtfDatabase) {
m_hrtfDatabase = HRTFDatabase::create(m_databaseSampleRate);
}
}
void HRTFDatabaseLoader::loadAsynchronously()
{
ASSERT(isMainThread());
MutexLocker locker(m_threadLock);
if (!m_hrtfDatabase && !m_databaseLoaderThread) {
m_databaseLoaderThread = adoptPtr(blink::Platform::current()->createThread("HRTF database loader"));
m_databaseLoaderThread->postTask(new Task(WTF::bind(&HRTFDatabaseLoader::load, this)));
}
}
bool HRTFDatabaseLoader::isLoaded() const
{
return m_hrtfDatabase;
}
void HRTFDatabaseLoader::waitForLoaderThreadCompletion()
{
MutexLocker locker(m_threadLock);
m_databaseLoaderThread.clear();
}
}
#endif