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