Index: Source/core/platform/audio/HRTFDatabaseLoader.cpp |
diff --git a/Source/core/platform/audio/HRTFDatabaseLoader.cpp b/Source/core/platform/audio/HRTFDatabaseLoader.cpp |
index b4dc6301f3a234a8b9fd0c6fc09e9d8661ff06d2..94ab4ab3b0080306b048cb405a518dd838bf9ab2 100644 |
--- a/Source/core/platform/audio/HRTFDatabaseLoader.cpp |
+++ b/Source/core/platform/audio/HRTFDatabaseLoader.cpp |
@@ -39,7 +39,7 @@ |
namespace WebCore { |
// Singleton |
-HRTFDatabaseLoader* HRTFDatabaseLoader::s_loader = 0; |
+HRTFDatabaseLoader::LoaderMap* HRTFDatabaseLoader::s_loaderMap = 0; |
PassRefPtr<HRTFDatabaseLoader> HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(float sampleRate) |
{ |
@@ -47,16 +47,20 @@ PassRefPtr<HRTFDatabaseLoader> HRTFDatabaseLoader::createAndLoadAsynchronouslyIf |
RefPtr<HRTFDatabaseLoader> loader; |
- if (!s_loader) { |
- // Lazily create and load. |
- loader = adoptRef(new HRTFDatabaseLoader(sampleRate)); |
- s_loader = loader.get(); |
- loader->loadAsynchronously(); |
- } else { |
- loader = s_loader; |
+ if (!s_loaderMap) |
+ s_loaderMap = adoptPtr(new LoaderMap()).leakPtr(); |
+ |
+ 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; |
} |
@@ -73,12 +77,11 @@ HRTFDatabaseLoader::~HRTFDatabaseLoader() |
waitForLoaderThreadCompletion(); |
m_hrtfDatabase.clear(); |
- |
- // Clear out singleton. |
- ASSERT(this == s_loader); |
- s_loader = 0; |
-} |
+ // Remove ourself from the map. |
+ if (s_loaderMap) |
+ s_loaderMap->remove(m_databaseSampleRate); |
+} |
// Asynchronously load the database in this thread. |
static void databaseLoaderEntry(void* threadData) |
@@ -124,20 +127,24 @@ void HRTFDatabaseLoader::waitForLoaderThreadCompletion() |
m_databaseLoaderThread = 0; |
} |
-HRTFDatabase* HRTFDatabaseLoader::defaultHRTFDatabase() |
-{ |
- if (!s_loader) |
- return 0; |
- |
- return s_loader->database(); |
-} |
- |
void HRTFDatabaseLoader::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
{ |
MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::AudioSharedData); |
info.addMember(m_hrtfDatabase, "hrtfDatabase"); |
} |
+void HRTFDatabaseLoader::LoaderMap::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
+{ |
+ ASSERT(isMainThread()); |
+ |
+ if (s_loaderMap) { |
+ for (HRTFDatabaseLoader::LoaderMap::iterator i = s_loaderMap->begin(); i != s_loaderMap->end(); ++i) { |
+ HRTFDatabaseLoader* loader = i.get()->value; |
+ loader->reportMemoryUsage(memoryObjectInfo); |
+ } |
+ } |
+} |
+ |
} // namespace WebCore |
#endif // ENABLE(WEB_AUDIO) |