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

Side by Side Diff: Source/WebCore/webaudio/AudioContext.h

Issue 7749016: Merge 92658 - Fix thread-safety of AudioNode deletion (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 4 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
« no previous file with comments | « no previous file | Source/WebCore/webaudio/AudioContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * 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 19 matching lines...) Expand all
30 #include "AudioBus.h" 30 #include "AudioBus.h"
31 #include "AudioDestinationNode.h" 31 #include "AudioDestinationNode.h"
32 #include "EventListener.h" 32 #include "EventListener.h"
33 #include "EventTarget.h" 33 #include "EventTarget.h"
34 #include "HRTFDatabaseLoader.h" 34 #include "HRTFDatabaseLoader.h"
35 #include <wtf/HashSet.h> 35 #include <wtf/HashSet.h>
36 #include <wtf/OwnPtr.h> 36 #include <wtf/OwnPtr.h>
37 #include <wtf/PassRefPtr.h> 37 #include <wtf/PassRefPtr.h>
38 #include <wtf/RefCounted.h> 38 #include <wtf/RefCounted.h>
39 #include <wtf/RefPtr.h> 39 #include <wtf/RefPtr.h>
40 #include <wtf/ThreadSafeRefCounted.h>
40 #include <wtf/Threading.h> 41 #include <wtf/Threading.h>
41 #include <wtf/Vector.h> 42 #include <wtf/Vector.h>
42 #include <wtf/text/AtomicStringHash.h> 43 #include <wtf/text/AtomicStringHash.h>
43 44
44 namespace WebCore { 45 namespace WebCore {
45 46
46 class ArrayBuffer; 47 class ArrayBuffer;
47 class AudioBuffer; 48 class AudioBuffer;
48 class AudioBufferCallback; 49 class AudioBufferCallback;
49 class AudioBufferSourceNode; 50 class AudioBufferSourceNode;
50 class AudioChannelMerger; 51 class AudioChannelMerger;
51 class AudioChannelSplitter; 52 class AudioChannelSplitter;
52 class AudioGainNode; 53 class AudioGainNode;
53 class AudioPannerNode; 54 class AudioPannerNode;
54 class AudioListener; 55 class AudioListener;
55 class BiquadFilterNode; 56 class BiquadFilterNode;
56 class DelayNode; 57 class DelayNode;
57 class Document; 58 class Document;
58 class LowPass2FilterNode; 59 class LowPass2FilterNode;
59 class HighPass2FilterNode; 60 class HighPass2FilterNode;
60 class ConvolverNode; 61 class ConvolverNode;
61 class DynamicsCompressorNode; 62 class DynamicsCompressorNode;
62 class RealtimeAnalyserNode; 63 class RealtimeAnalyserNode;
63 class WaveShaperNode; 64 class WaveShaperNode;
64 class JavaScriptAudioNode; 65 class JavaScriptAudioNode;
65 66
66 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it. 67 // AudioContext is the cornerstone of the web audio API and all AudioNodes are c reated from it.
67 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism. 68 // For thread safety between the audio thread and the main thread, it has a rend ering graph locking mechanism.
68 69
69 class AudioContext : public ActiveDOMObject, public RefCounted<AudioContext>, pu blic EventTarget { 70 class AudioContext : public ActiveDOMObject, public ThreadSafeRefCounted<AudioCo ntext>, public EventTarget {
70 public: 71 public:
71 // Create an AudioContext for rendering to the audio hardware. 72 // Create an AudioContext for rendering to the audio hardware.
72 static PassRefPtr<AudioContext> create(Document*); 73 static PassRefPtr<AudioContext> create(Document*);
73 74
74 // Create an AudioContext for offline (non-realtime) rendering. 75 // Create an AudioContext for offline (non-realtime) rendering.
75 static PassRefPtr<AudioContext> createOfflineContext(Document*, unsigned num berOfChannels, size_t numberOfFrames, double sampleRate, ExceptionCode&); 76 static PassRefPtr<AudioContext> createOfflineContext(Document*, unsigned num berOfChannels, size_t numberOfFrames, double sampleRate, ExceptionCode&);
76 77
77 virtual ~AudioContext(); 78 virtual ~AudioContext();
78 79
79 bool isInitialized() const; 80 bool isInitialized() const;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 129
129 // Called at the start of each render quantum. 130 // Called at the start of each render quantum.
130 void handlePreRenderTasks(); 131 void handlePreRenderTasks();
131 132
132 // Called at the end of each render quantum. 133 // Called at the end of each render quantum.
133 void handlePostRenderTasks(); 134 void handlePostRenderTasks();
134 135
135 // Called periodically at the end of each render quantum to dereference fini shed source nodes. 136 // Called periodically at the end of each render quantum to dereference fini shed source nodes.
136 void derefFinishedSourceNodes(); 137 void derefFinishedSourceNodes();
137 138
138 // We reap all marked nodes at the end of each realtime render quantum in de leteMarkedNodes(). 139 // We schedule deletion of all marked nodes at the end of each realtime rend er quantum.
139 void markForDeletion(AudioNode*); 140 void markForDeletion(AudioNode*);
140 void deleteMarkedNodes(); 141 void deleteMarkedNodes();
141 142
142 // Keeps track of the number of connections made. 143 // Keeps track of the number of connections made.
143 void incrementConnectionCount() 144 void incrementConnectionCount()
144 { 145 {
145 ASSERT(isMainThread()); 146 ASSERT(isMainThread());
146 m_connectionCount++; 147 m_connectionCount++;
147 } 148 }
148 149
149 unsigned connectionCount() const { return m_connectionCount; } 150 unsigned connectionCount() const { return m_connectionCount; }
150 151
151 // 152 //
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 void markAudioNodeOutputDirty(AudioNodeOutput*); 202 void markAudioNodeOutputDirty(AudioNodeOutput*);
202 203
203 // EventTarget 204 // EventTarget
204 virtual ScriptExecutionContext* scriptExecutionContext() const; 205 virtual ScriptExecutionContext* scriptExecutionContext() const;
205 virtual AudioContext* toAudioContext(); 206 virtual AudioContext* toAudioContext();
206 virtual EventTargetData* eventTargetData() { return &m_eventTargetData; } 207 virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
207 virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData ; } 208 virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData ; }
208 209
209 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); 210 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
210 211
211 // Reconcile ref/deref which are defined both in AudioNode and EventTarget. 212 // Reconcile ref/deref which are defined both in ThreadSafeRefCounted and Ev entTarget.
212 using RefCounted<AudioContext>::ref; 213 using ThreadSafeRefCounted<AudioContext>::ref;
213 using RefCounted<AudioContext>::deref; 214 using ThreadSafeRefCounted<AudioContext>::deref;
214 215
215 void startRendering(); 216 void startRendering();
216 void fireCompletionEvent(); 217 void fireCompletionEvent();
217 218
218 static unsigned s_hardwareContextCount; 219 static unsigned s_hardwareContextCount;
219 220
220 private: 221 private:
221 AudioContext(Document*); 222 AudioContext(Document*);
222 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, do uble sampleRate); 223 AudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, do uble sampleRate);
223 void constructCommon(); 224 void constructCommon();
224 225
225 void lazyInitialize(); 226 void lazyInitialize();
226 void uninitialize(); 227 void uninitialize();
228
229 void scheduleNodeDeletion();
230 static void deleteMarkedNodesDispatch(void* userData);
227 231
228 bool m_isInitialized; 232 bool m_isInitialized;
229 bool m_isAudioThreadFinished; 233 bool m_isAudioThreadFinished;
230 bool m_isAudioThreadShutdown; 234 bool m_isAudioThreadShutdown;
231 235
232 Document* m_document; 236 Document* m_document;
233 237
234 // The context itself keeps a reference to all source nodes. The source nod es, then reference all nodes they're connected to. 238 // The context itself keeps a reference to all source nodes. The source nod es, then reference all nodes they're connected to.
235 // In turn, these nodes reference all nodes they're connected to. All nodes are ultimately connected to the AudioDestinationNode. 239 // In turn, these nodes reference all nodes they're connected to. All nodes are ultimately connected to the AudioDestinationNode.
236 // When the context dereferences a source node, it will be deactivated from the rendering graph along with all other nodes it is 240 // When the context dereferences a source node, it will be deactivated from the rendering graph along with all other nodes it is
(...skipping 12 matching lines...) Expand all
249 Vector<RefPtr<AudioBuffer> > m_allocatedBuffers; 253 Vector<RefPtr<AudioBuffer> > m_allocatedBuffers;
250 254
251 // Only accessed in the audio thread. 255 // Only accessed in the audio thread.
252 Vector<AudioNode*> m_finishedNodes; 256 Vector<AudioNode*> m_finishedNodes;
253 257
254 // We don't use RefPtr<AudioNode> here because AudioNode has a more complex ref() / deref() implementation 258 // We don't use RefPtr<AudioNode> here because AudioNode has a more complex ref() / deref() implementation
255 // with an optional argument for refType. We need to use the special refTyp e: RefTypeConnection 259 // with an optional argument for refType. We need to use the special refTyp e: RefTypeConnection
256 // Either accessed when the graph lock is held, or on the main thread when t he audio thread has finished. 260 // Either accessed when the graph lock is held, or on the main thread when t he audio thread has finished.
257 Vector<AudioNode*> m_referencedNodes; 261 Vector<AudioNode*> m_referencedNodes;
258 262
259 // Accumulate nodes which need to be deleted at the end of a render cycle (i n realtime thread) here. 263 // Accumulate nodes which need to be deleted here.
264 // They will be scheduled for deletion (on the main thread) at the end of a render cycle (in realtime thread).
260 Vector<AudioNode*> m_nodesToDelete; 265 Vector<AudioNode*> m_nodesToDelete;
266 bool m_isDeletionScheduled;
261 267
262 // Only accessed when the graph lock is held. 268 // Only accessed when the graph lock is held.
263 HashSet<AudioNodeInput*> m_dirtyAudioNodeInputs; 269 HashSet<AudioNodeInput*> m_dirtyAudioNodeInputs;
264 HashSet<AudioNodeOutput*> m_dirtyAudioNodeOutputs; 270 HashSet<AudioNodeOutput*> m_dirtyAudioNodeOutputs;
265 void handleDirtyAudioNodeInputs(); 271 void handleDirtyAudioNodeInputs();
266 void handleDirtyAudioNodeOutputs(); 272 void handleDirtyAudioNodeOutputs();
267 273
268 OwnPtr<AudioBus> m_temporaryMonoBus; 274 OwnPtr<AudioBus> m_temporaryMonoBus;
269 OwnPtr<AudioBus> m_temporaryStereoBus; 275 OwnPtr<AudioBus> m_temporaryStereoBus;
270 276
(...skipping 29 matching lines...) Expand all
300 RefPtr<AudioBuffer> m_renderTarget; 306 RefPtr<AudioBuffer> m_renderTarget;
301 307
302 bool m_isOfflineContext; 308 bool m_isOfflineContext;
303 309
304 AsyncAudioDecoder m_audioDecoder; 310 AsyncAudioDecoder m_audioDecoder;
305 }; 311 };
306 312
307 } // WebCore 313 } // WebCore
308 314
309 #endif // AudioContext_h 315 #endif // AudioContext_h
OLDNEW
« no previous file with comments | « no previous file | Source/WebCore/webaudio/AudioContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698