| 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 DEFINE_EVENT_TARGET_REFCOUNTING(ThreadSafeRefCountedWillBeThreadSafeRefCount
edGarbageCollected<AudioContext>); | 78 DEFINE_EVENT_TARGET_REFCOUNTING(ThreadSafeRefCountedWillBeThreadSafeRefCount
edGarbageCollected<AudioContext>); |
| 79 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext); | 79 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext); |
| 80 public: | 80 public: |
| 81 // Create an AudioContext for rendering to the audio hardware. | 81 // Create an AudioContext for rendering to the audio hardware. |
| 82 static PassRefPtrWillBeRawPtr<AudioContext> create(Document&, ExceptionState
&); | 82 static PassRefPtrWillBeRawPtr<AudioContext> create(Document&, ExceptionState
&); |
| 83 | 83 |
| 84 virtual ~AudioContext(); | 84 virtual ~AudioContext(); |
| 85 | 85 |
| 86 virtual void trace(Visitor*) OVERRIDE; | 86 virtual void trace(Visitor*) OVERRIDE; |
| 87 | 87 |
| 88 bool isInitialized() const; | 88 bool isInitialized() const { return m_isInitialized; } |
| 89 bool isOfflineContext() { return m_isOfflineContext; } | 89 bool isOfflineContext() { return m_isOfflineContext; } |
| 90 | 90 |
| 91 // Document notification | 91 // Document notification |
| 92 virtual void stop() OVERRIDE FINAL; | 92 virtual void stop() OVERRIDE FINAL; |
| 93 virtual bool hasPendingActivity() const OVERRIDE; | 93 virtual bool hasPendingActivity() const OVERRIDE; |
| 94 | 94 |
| 95 AudioDestinationNode* destination() { return m_destinationNode.get(); } | 95 AudioDestinationNode* destination() { return m_destinationNode.get(); } |
| 96 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF
rame(); } | 96 size_t currentSampleFrame() const { return m_destinationNode->currentSampleF
rame(); } |
| 97 double currentTime() const { return m_destinationNode->currentTime(); } | 97 double currentTime() const { return m_destinationNode->currentTime(); } |
| 98 float sampleRate() const { return m_destinationNode->sampleRate(); } | 98 float sampleRate() const { return m_destinationNode->sampleRate(); } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 unsigned connectionCount() const { return m_connectionCount; } | 163 unsigned connectionCount() const { return m_connectionCount; } |
| 164 | 164 |
| 165 // | 165 // |
| 166 // Thread Safety and Graph Locking: | 166 // Thread Safety and Graph Locking: |
| 167 // | 167 // |
| 168 | 168 |
| 169 void setAudioThread(ThreadIdentifier thread) { m_audioThread = thread; } //
FIXME: check either not initialized or the same | 169 void setAudioThread(ThreadIdentifier thread) { m_audioThread = thread; } //
FIXME: check either not initialized or the same |
| 170 ThreadIdentifier audioThread() const { return m_audioThread; } | 170 ThreadIdentifier audioThread() const { return m_audioThread; } |
| 171 bool isAudioThread() const; | 171 bool isAudioThread() const; |
| 172 | 172 |
| 173 // Returns true only after the audio thread has been started and then shutdo
wn. | |
| 174 bool isAudioThreadFinished() { return m_isAudioThreadFinished; } | |
| 175 | |
| 176 // mustReleaseLock is set to true if we acquired the lock in this method cal
l and caller must unlock(), false if it was previously acquired. | 173 // mustReleaseLock is set to true if we acquired the lock in this method cal
l and caller must unlock(), false if it was previously acquired. |
| 177 void lock(bool& mustReleaseLock); | 174 void lock(bool& mustReleaseLock); |
| 178 | 175 |
| 179 // Returns true if we own the lock. | 176 // Returns true if we own the lock. |
| 180 // mustReleaseLock is set to true if we acquired the lock in this method cal
l and caller must unlock(), false if it was previously acquired. | 177 // mustReleaseLock is set to true if we acquired the lock in this method cal
l and caller must unlock(), false if it was previously acquired. |
| 181 bool tryLock(bool& mustReleaseLock); | 178 bool tryLock(bool& mustReleaseLock); |
| 182 | 179 |
| 183 void unlock(); | 180 void unlock(); |
| 184 | 181 |
| 185 // Returns true if this thread owns the context's lock. | 182 // Returns true if this thread owns the context's lock. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 228 |
| 232 static unsigned s_hardwareContextCount; | 229 static unsigned s_hardwareContextCount; |
| 233 | 230 |
| 234 protected: | 231 protected: |
| 235 explicit AudioContext(Document*); | 232 explicit AudioContext(Document*); |
| 236 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl
oat sampleRate); | 233 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl
oat sampleRate); |
| 237 | 234 |
| 238 static bool isSampleRateRangeGood(float sampleRate); | 235 static bool isSampleRateRangeGood(float sampleRate); |
| 239 | 236 |
| 240 private: | 237 private: |
| 241 void constructCommon(); | |
| 242 | |
| 243 void initialize(); | 238 void initialize(); |
| 244 void uninitialize(); | 239 void uninitialize(); |
| 245 | 240 |
| 246 // ExecutionContext calls stop twice. | 241 // ExecutionContext calls stop twice. |
| 247 // We'd like to schedule only one stop action for them. | 242 // We'd like to schedule only one stop action for them. |
| 248 bool m_isStopScheduled; | 243 bool m_isStopScheduled; |
| 249 static void stopDispatch(void* userData); | 244 static void stopDispatch(void* userData); |
| 250 bool m_isCleared; | 245 bool m_isCleared; |
| 251 void clear(); | 246 void clear(); |
| 252 | 247 |
| 253 void scheduleNodeDeletion(); | 248 void scheduleNodeDeletion(); |
| 254 static void deleteMarkedNodesDispatch(void* userData); | 249 static void deleteMarkedNodesDispatch(void* userData); |
| 255 | 250 |
| 256 // Set to true when the destination node has been initialized and is ready t
o process data. | 251 // Set to true when the destination node has been initialized and is ready t
o process data. |
| 257 bool m_isInitialized; | 252 bool m_isInitialized; |
| 258 bool m_isAudioThreadFinished; | |
| 259 | 253 |
| 260 // The context itself keeps a reference to all source nodes. The source nod
es, then reference all nodes they're connected to. | 254 // The context itself keeps a reference to all source nodes. The source nod
es, then reference all nodes they're connected to. |
| 261 // In turn, these nodes reference all nodes they're connected to. All nodes
are ultimately connected to the AudioDestinationNode. | 255 // In turn, these nodes reference all nodes they're connected to. All nodes
are ultimately connected to the AudioDestinationNode. |
| 262 // When the context dereferences a source node, it will be deactivated from
the rendering graph along with all other nodes it is | 256 // When the context dereferences a source node, it will be deactivated from
the rendering graph along with all other nodes it is |
| 263 // uniquely connected to. See the AudioNode::ref() and AudioNode::deref() m
ethods for more details. | 257 // uniquely connected to. See the AudioNode::ref() and AudioNode::deref() m
ethods for more details. |
| 264 void refNode(AudioNode*); | 258 void refNode(AudioNode*); |
| 265 void derefNode(AudioNode*); | 259 void derefNode(AudioNode*); |
| 266 | 260 |
| 267 // When the context goes away, there might still be some sources which haven
't finished playing. | 261 // When the context goes away, there might still be some sources which haven
't finished playing. |
| 268 // Make sure to dereference them here. | 262 // Make sure to dereference them here. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 AsyncAudioDecoder m_audioDecoder; | 314 AsyncAudioDecoder m_audioDecoder; |
| 321 | 315 |
| 322 // This is considering 32 is large enough for multiple channels audio. | 316 // This is considering 32 is large enough for multiple channels audio. |
| 323 // It is somewhat arbitrary and could be increased if necessary. | 317 // It is somewhat arbitrary and could be increased if necessary. |
| 324 enum { MaxNumberOfChannels = 32 }; | 318 enum { MaxNumberOfChannels = 32 }; |
| 325 }; | 319 }; |
| 326 | 320 |
| 327 } // WebCore | 321 } // WebCore |
| 328 | 322 |
| 329 #endif // AudioContext_h | 323 #endif // AudioContext_h |
| OLD | NEW |