| OLD | NEW |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 public: | 46 public: |
| 47 // Lazily creates a HRTFDatabaseLoader (if not already created) for the give
n sample-rate | 47 // Lazily creates a HRTFDatabaseLoader (if not already created) for the give
n sample-rate |
| 48 // and starts loading asynchronously (when created the first time). | 48 // and starts loading asynchronously (when created the first time). |
| 49 // Returns the HRTFDatabaseLoader. | 49 // Returns the HRTFDatabaseLoader. |
| 50 // Must be called from the main thread. | 50 // Must be called from the main thread. |
| 51 static PassRefPtr<HRTFDatabaseLoader> createAndLoadAsynchronouslyIfNecessary
(float sampleRate); | 51 static PassRefPtr<HRTFDatabaseLoader> createAndLoadAsynchronouslyIfNecessary
(float sampleRate); |
| 52 | 52 |
| 53 // Both constructor and destructor must be called from the main thread. | 53 // Both constructor and destructor must be called from the main thread. |
| 54 ~HRTFDatabaseLoader(); | 54 ~HRTFDatabaseLoader(); |
| 55 | 55 |
| 56 // Returns true once the default database has been completely loaded. | 56 // Returns true once the default database has been completely loaded. This |
| 57 bool isLoaded(); | 57 // must be called from the audio thread. |
| 58 bool isLoaded() { return database(); } |
| 58 | 59 |
| 59 // waitForLoaderThreadCompletion() may be called more than once and is threa
d-safe. | 60 // waitForLoaderThreadCompletion() may be called more than once and is threa
d-safe. |
| 60 void waitForLoaderThreadCompletion(); | 61 void waitForLoaderThreadCompletion(); |
| 61 | 62 |
| 62 HRTFDatabase* database() { return m_hrtfDatabase.get(); } | 63 // Returns the database or nullptr if the database doesn't yet exist. Must |
| 64 // be called from the audio thread. |
| 65 HRTFDatabase* database(); |
| 63 | 66 |
| 64 float databaseSampleRate() const { return m_databaseSampleRate; } | 67 float databaseSampleRate() const { return m_databaseSampleRate; } |
| 65 | 68 |
| 66 private: | 69 private: |
| 67 // Both constructor and destructor must be called from the main thread. | 70 // Both constructor and destructor must be called from the main thread. |
| 68 explicit HRTFDatabaseLoader(float sampleRate); | 71 explicit HRTFDatabaseLoader(float sampleRate); |
| 69 | 72 |
| 70 // If it hasn't already been loaded, creates a new thread and initiates asyn
chronous loading of the default database. | 73 // If it hasn't already been loaded, creates a new thread and initiates asyn
chronous loading of the default database. |
| 71 // This must be called from the main thread. | 74 // This must be called from the main thread. |
| 72 void loadAsynchronously(); | 75 void loadAsynchronously(); |
| 73 | 76 |
| 74 // Called in asynchronous loading thread. | 77 // Called in asynchronous loading thread. |
| 75 void loadTask(); | 78 void loadTask(); |
| 76 void cleanupTask(TaskSynchronizer*); | 79 void cleanupTask(TaskSynchronizer*); |
| 77 | 80 |
| 78 // Holding a m_lock is required when accessing m_hrtfDatabase since we acces
s it from multiple threads. | 81 // Holding a m_lock is required when accessing m_hrtfDatabase since we acces
s it from multiple threads. |
| 79 Mutex m_lock; | 82 Mutex m_lock; |
| 80 std::unique_ptr<HRTFDatabase> m_hrtfDatabase; | 83 std::unique_ptr<HRTFDatabase> m_hrtfDatabase; |
| 81 | 84 |
| 82 std::unique_ptr<WebThread> m_thread; | 85 std::unique_ptr<WebThread> m_thread; |
| 83 | 86 |
| 84 float m_databaseSampleRate; | 87 float m_databaseSampleRate; |
| 85 }; | 88 }; |
| 86 | 89 |
| 87 } // namespace blink | 90 } // namespace blink |
| 88 | 91 |
| 89 #endif // HRTFDatabaseLoader_h | 92 #endif // HRTFDatabaseLoader_h |
| OLD | NEW |