Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1103)

Unified Diff: Source/core/platform/audio/HRTFDatabaseLoader.cpp

Issue 14636011: Support multiple HRTFDatabases for different sample-rates (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add ASSERT(isMainThread()) Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/platform/audio/HRTFDatabaseLoader.h ('k') | Source/core/platform/audio/HRTFPanner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « Source/core/platform/audio/HRTFDatabaseLoader.h ('k') | Source/core/platform/audio/HRTFPanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698