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

Side by Side Diff: Source/core/platform/audio/HRTFDatabaseLoader.h

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #ifndef HRTFDatabaseLoader_h 29 #ifndef HRTFDatabaseLoader_h
30 #define HRTFDatabaseLoader_h 30 #define HRTFDatabaseLoader_h
31 31
32 #include "core/platform/audio/HRTFDatabase.h" 32 #include "core/platform/audio/HRTFDatabase.h"
33 #include <wtf/PassRefPtr.h> 33 #include "wtf/HashMap.h"
34 #include <wtf/RefCounted.h> 34 #include "wtf/PassRefPtr.h"
35 #include <wtf/RefPtr.h> 35 #include "wtf/RefCounted.h"
36 #include <wtf/Threading.h> 36 #include "wtf/RefPtr.h"
37 #include "wtf/Threading.h"
37 38
38 namespace WebCore { 39 namespace WebCore {
39 40
40 // HRTFDatabaseLoader will asynchronously load the default HRTFDatabase in a new thread. 41 // HRTFDatabaseLoader will asynchronously load the default HRTFDatabase in a new thread.
41 42
42 class HRTFDatabaseLoader : public RefCounted<HRTFDatabaseLoader> { 43 class HRTFDatabaseLoader : public RefCounted<HRTFDatabaseLoader> {
43 public: 44 public:
44 // Lazily creates the singleton HRTFDatabaseLoader (if not already created) and starts loading asynchronously (when created the first time). 45 // Lazily creates a HRTFDatabaseLoader (if not already created) for the give n sample-rate
45 // Returns the singleton HRTFDatabaseLoader. 46 // and starts loading asynchronously (when created the first time).
47 // Returns the HRTFDatabaseLoader.
46 // Must be called from the main thread. 48 // Must be called from the main thread.
47 static PassRefPtr<HRTFDatabaseLoader> createAndLoadAsynchronouslyIfNecessary (float sampleRate); 49 static PassRefPtr<HRTFDatabaseLoader> createAndLoadAsynchronouslyIfNecessary (float sampleRate);
48 50
49 // Returns the singleton HRTFDatabaseLoader.
50 static HRTFDatabaseLoader* loader() { return s_loader; }
51
52 // Both constructor and destructor must be called from the main thread. 51 // Both constructor and destructor must be called from the main thread.
53 ~HRTFDatabaseLoader(); 52 ~HRTFDatabaseLoader();
54 53
55 // Returns true once the default database has been completely loaded. 54 // Returns true once the default database has been completely loaded.
56 bool isLoaded() const; 55 bool isLoaded() const;
57 56
58 // waitForLoaderThreadCompletion() may be called more than once and is threa d-safe. 57 // waitForLoaderThreadCompletion() may be called more than once and is threa d-safe.
59 void waitForLoaderThreadCompletion(); 58 void waitForLoaderThreadCompletion();
60 59
61 HRTFDatabase* database() { return m_hrtfDatabase.get(); } 60 HRTFDatabase* database() { return m_hrtfDatabase.get(); }
62 61
63 float databaseSampleRate() const { return m_databaseSampleRate; } 62 float databaseSampleRate() const { return m_databaseSampleRate; }
64 63
65 // Called in asynchronous loading thread. 64 // Called in asynchronous loading thread.
66 void load(); 65 void load();
67 66
68 // defaultHRTFDatabase() gives access to the loaded database. 67 void reportMemoryUsage(MemoryObjectInfo*) const;
69 // This can be called from any thread, but it is the callers responsibilty t o call this while the context (and thus HRTFDatabaseLoader)
70 // is still alive. Otherwise this will return 0.
71 static HRTFDatabase* defaultHRTFDatabase();
72 68
73 void reportMemoryUsage(MemoryObjectInfo*) const; 69 // Map from sample-rate to loader.
70 class LoaderMap : public HashMap<double, HRTFDatabaseLoader*> {
71 public:
72 void reportMemoryUsage(MemoryObjectInfo*) const;
73 };
74
75 static HRTFDatabaseLoader::LoaderMap* loaderMap() { return s_loaderMap; }
74 76
75 private: 77 private:
76 // Both constructor and destructor must be called from the main thread. 78 // Both constructor and destructor must be called from the main thread.
77 explicit HRTFDatabaseLoader(float sampleRate); 79 explicit HRTFDatabaseLoader(float sampleRate);
78 80
79 // If it hasn't already been loaded, creates a new thread and initiates asyn chronous loading of the default database. 81 // If it hasn't already been loaded, creates a new thread and initiates asyn chronous loading of the default database.
80 // This must be called from the main thread. 82 // This must be called from the main thread.
81 void loadAsynchronously(); 83 void loadAsynchronously();
82 84
83 static HRTFDatabaseLoader* s_loader; // singleton 85 // Keeps track of loaders on a per-sample-rate basis.
86 static LoaderMap* s_loaderMap; // singleton
87
84 OwnPtr<HRTFDatabase> m_hrtfDatabase; 88 OwnPtr<HRTFDatabase> m_hrtfDatabase;
85 89
86 // Holding a m_threadLock is required when accessing m_databaseLoaderThread. 90 // Holding a m_threadLock is required when accessing m_databaseLoaderThread.
87 Mutex m_threadLock; 91 Mutex m_threadLock;
88 ThreadIdentifier m_databaseLoaderThread; 92 ThreadIdentifier m_databaseLoaderThread;
89 93
90 float m_databaseSampleRate; 94 float m_databaseSampleRate;
91 }; 95 };
92 96
93 } // namespace WebCore 97 } // namespace WebCore
94 98
95 #endif // HRTFDatabaseLoader_h 99 #endif // HRTFDatabaseLoader_h
OLDNEW
« no previous file with comments | « Source/core/platform/PlatformMemoryInstrumentation.cpp ('k') | Source/core/platform/audio/HRTFDatabaseLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698