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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 class ScriptProcessorNode; | 72 class ScriptProcessorNode; |
73 class ScriptPromiseResolver; | 73 class ScriptPromiseResolver; |
74 class ScriptState; | 74 class ScriptState; |
75 class SecurityOrigin; | 75 class SecurityOrigin; |
76 class StereoPannerNode; | 76 class StereoPannerNode; |
77 class WaveShaperNode; | 77 class WaveShaperNode; |
78 | 78 |
79 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c
reated from it. | 79 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c
reated from it. |
80 // For thread safety between the audio thread and the main thread, it has a rend
ering graph locking mechanism. | 80 // For thread safety between the audio thread and the main thread, it has a rend
ering graph locking mechanism. |
81 | 81 |
82 class AudioContext : public RefCountedGarbageCollectedEventTargetWithInlineData<
AudioContext>, public ActiveDOMObject { | 82 class AudioContext |
| 83 : public RefCountedGarbageCollectedEventTargetWithInlineData<AudioContext> |
| 84 , public ActiveDOMObject |
| 85 , private ThreadState::MarkingTask { |
83 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<A
udioContext>); | 86 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<A
udioContext>); |
84 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext); | 87 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AudioContext); |
85 DEFINE_WRAPPERTYPEINFO(); | 88 DEFINE_WRAPPERTYPEINFO(); |
86 public: | 89 public: |
87 // The state of an audio context. On creation, the state is Suspended. The
state is Running if | 90 // The state of an audio context. On creation, the state is Suspended. The
state is Running if |
88 // audio is being processed (audio graph is being pulled for data). The stat
e is Closed if the | 91 // audio is being processed (audio graph is being pulled for data). The stat
e is Closed if the |
89 // audio context has been closed. The valid transitions are from Suspended
to either Running or | 92 // audio context has been closed. The valid transitions are from Suspended
to either Running or |
90 // Closed; Running to Suspended or Closed. Once Closed, there are no valid t
ransitions. | 93 // Closed; Running to Suspended or Closed. Once Closed, there are no valid t
ransitions. |
91 enum AudioContextState { | 94 enum AudioContextState { |
92 Suspended, | 95 Suspended, |
93 Running, | 96 Running, |
94 Closed | 97 Closed |
95 }; | 98 }; |
96 | 99 |
97 // Create an AudioContext for rendering to the audio hardware. | 100 // Create an AudioContext for rendering to the audio hardware. |
98 static AudioContext* create(Document&, ExceptionState&); | 101 static AudioContext* create(Document&, ExceptionState&); |
99 | 102 |
100 virtual ~AudioContext(); | 103 virtual ~AudioContext(); |
101 | 104 |
102 DECLARE_VIRTUAL_TRACE(); | 105 DECLARE_VIRTUAL_TRACE(); |
103 | 106 |
104 bool isInitialized() const { return m_isInitialized; } | 107 bool isInitialized() const { return m_isInitialized; } |
105 bool isOfflineContext() { return m_isOfflineContext; } | 108 bool isOfflineContext() { return m_isOfflineContext; } |
| 109 AudioContextState contextState() const { return m_contextState; } |
| 110 void setLastZombie(void*); |
106 | 111 |
107 // Document notification | 112 // Document notification |
108 virtual void stop() override final; | 113 virtual void stop() override final; |
109 virtual bool hasPendingActivity() const override; | 114 virtual bool hasPendingActivity() const override; |
110 | 115 |
111 AudioDestinationNode* destination() { return m_destinationNode.get(); } | 116 AudioDestinationNode* destination() { return m_destinationNode.get(); } |
112 | 117 |
113 size_t currentSampleFrame() const { return m_destinationNode ? m_destination
Node->currentSampleFrame() : 0; } | 118 size_t currentSampleFrame() const { return m_destinationNode ? m_destination
Node->currentSampleFrame() : 0; } |
114 double currentTime() const { return m_destinationNode ? m_destinationNode->c
urrentTime() : 0; } | 119 double currentTime() const { return m_destinationNode ? m_destinationNode->c
urrentTime() : 0; } |
115 // cachedSampleFrame() is like currentSampleFrame() but must be called from
the main thread to | 120 // cachedSampleFrame() is like currentSampleFrame() but must be called from
the main thread to |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 288 |
284 protected: | 289 protected: |
285 explicit AudioContext(Document*); | 290 explicit AudioContext(Document*); |
286 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl
oat sampleRate); | 291 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, fl
oat sampleRate); |
287 | 292 |
288 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver; | 293 RefPtrWillBeMember<ScriptPromiseResolver> m_offlineResolver; |
289 private: | 294 private: |
290 void initialize(); | 295 void initialize(); |
291 void uninitialize(); | 296 void uninitialize(); |
292 | 297 |
| 298 // ThreadState::MarkingTask functions. |
| 299 void willStartMarking(ThreadState&) override; |
| 300 void didFinishMarking(ThreadState&) override; |
| 301 |
293 // ExecutionContext calls stop twice. | 302 // ExecutionContext calls stop twice. |
294 // We'd like to schedule only one stop action for them. | 303 // We'd like to schedule only one stop action for them. |
295 bool m_isStopScheduled; | 304 bool m_isStopScheduled; |
296 bool m_isCleared; | 305 bool m_isCleared; |
297 void clear(); | 306 void clear(); |
298 | 307 |
299 void throwExceptionForClosedState(ExceptionState&); | 308 void throwExceptionForClosedState(ExceptionState&); |
300 | 309 |
301 // Set to true when the destination node has been initialized and is ready t
o process data. | 310 // Set to true when the destination node has been initialized and is ready t
o process data. |
302 bool m_isInitialized; | 311 bool m_isInitialized; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // m_automaticPullNodesNeedUpdating keeps track if m_automaticPullNodes is m
odified. | 401 // m_automaticPullNodesNeedUpdating keeps track if m_automaticPullNodes is m
odified. |
393 bool m_automaticPullNodesNeedUpdating; | 402 bool m_automaticPullNodesNeedUpdating; |
394 void updateAutomaticPullNodes(); | 403 void updateAutomaticPullNodes(); |
395 | 404 |
396 unsigned m_connectionCount; | 405 unsigned m_connectionCount; |
397 | 406 |
398 // Graph locking. | 407 // Graph locking. |
399 bool m_didInitializeContextGraphMutex; | 408 bool m_didInitializeContextGraphMutex; |
400 RecursiveMutex m_contextGraphMutex; | 409 RecursiveMutex m_contextGraphMutex; |
401 volatile ThreadIdentifier m_audioThread; | 410 volatile ThreadIdentifier m_audioThread; |
| 411 // Accessing m_last*Zombie should be protected by |
| 412 // m_didInitializeContextGraphMutex. |
| 413 void* m_lastZombie; |
| 414 void* m_lastRemovableZombie; |
402 | 415 |
403 // Only accessed in the audio thread. | 416 // Only accessed in the audio thread. |
404 // Oilpan: Since items are added to these vectors by the audio thread (not r
egistered to Oilpan), | 417 // Oilpan: Since items are added to these vectors by the audio thread (not r
egistered to Oilpan), |
405 // we cannot use HeapVectors. | 418 // we cannot use HeapVectors. |
406 GC_PLUGIN_IGNORE("http://crbug.com/404527") | 419 GC_PLUGIN_IGNORE("http://crbug.com/404527") |
407 Vector<AudioNode*> m_deferredBreakConnectionList; | 420 Vector<AudioNode*> m_deferredBreakConnectionList; |
408 | 421 |
409 Member<AudioBuffer> m_renderTarget; | 422 Member<AudioBuffer> m_renderTarget; |
410 | 423 |
411 bool m_isOfflineContext; | 424 bool m_isOfflineContext; |
(...skipping 23 matching lines...) Expand all Loading... |
435 // This is considering 32 is large enough for multiple channels audio. | 448 // This is considering 32 is large enough for multiple channels audio. |
436 // It is somewhat arbitrary and could be increased if necessary. | 449 // It is somewhat arbitrary and could be increased if necessary. |
437 enum { MaxNumberOfChannels = 32 }; | 450 enum { MaxNumberOfChannels = 32 }; |
438 | 451 |
439 unsigned m_contextId; | 452 unsigned m_contextId; |
440 }; | 453 }; |
441 | 454 |
442 } // namespace blink | 455 } // namespace blink |
443 | 456 |
444 #endif // AudioContext_h | 457 #endif // AudioContext_h |
OLD | NEW |