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 16 matching lines...) Expand all Loading... |
27 #include "modules/webaudio/AudioNodeOutput.h" | 27 #include "modules/webaudio/AudioNodeOutput.h" |
28 #include "modules/webaudio/OfflineAudioContext.h" | 28 #include "modules/webaudio/OfflineAudioContext.h" |
29 #include "platform/CrossThreadFunctional.h" | 29 #include "platform/CrossThreadFunctional.h" |
30 #include "public/platform/Platform.h" | 30 #include "public/platform/Platform.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 void DeferredTaskHandler::lock() | 34 void DeferredTaskHandler::lock() |
35 { | 35 { |
36 // Don't allow regular lock in real-time audio thread. | 36 // Don't allow regular lock in real-time audio thread. |
37 ASSERT(!isAudioThread()); | 37 DCHECK(!isAudioThread()); |
38 m_contextGraphMutex.lock(); | 38 m_contextGraphMutex.lock(); |
39 } | 39 } |
40 | 40 |
41 bool DeferredTaskHandler::tryLock() | 41 bool DeferredTaskHandler::tryLock() |
42 { | 42 { |
43 // Try to catch cases of using try lock on main thread | 43 // Try to catch cases of using try lock on main thread |
44 // - it should use regular lock. | 44 // - it should use regular lock. |
45 ASSERT(isAudioThread()); | 45 DCHECK(isAudioThread()); |
46 if (!isAudioThread()) { | 46 if (!isAudioThread()) { |
47 // In release build treat tryLock() as lock() (since above | 47 // In release build treat tryLock() as lock() (since above |
48 // ASSERT(isAudioThread) never fires) - this is the best we can do. | 48 // DCHECK(isAudioThread) never fires) - this is the best we can do. |
49 lock(); | 49 lock(); |
50 return true; | 50 return true; |
51 } | 51 } |
52 return m_contextGraphMutex.tryLock(); | 52 return m_contextGraphMutex.tryLock(); |
53 } | 53 } |
54 | 54 |
55 void DeferredTaskHandler::unlock() | 55 void DeferredTaskHandler::unlock() |
56 { | 56 { |
57 m_contextGraphMutex.unlock(); | 57 m_contextGraphMutex.unlock(); |
58 } | 58 } |
(...skipping 11 matching lines...) Expand all Loading... |
70 | 70 |
71 #if ENABLE(ASSERT) | 71 #if ENABLE(ASSERT) |
72 bool DeferredTaskHandler::isGraphOwner() | 72 bool DeferredTaskHandler::isGraphOwner() |
73 { | 73 { |
74 return m_contextGraphMutex.locked(); | 74 return m_contextGraphMutex.locked(); |
75 } | 75 } |
76 #endif | 76 #endif |
77 | 77 |
78 void DeferredTaskHandler::addDeferredBreakConnection(AudioHandler& node) | 78 void DeferredTaskHandler::addDeferredBreakConnection(AudioHandler& node) |
79 { | 79 { |
80 ASSERT(isAudioThread()); | 80 DCHECK(isAudioThread()); |
81 m_deferredBreakConnectionList.append(&node); | 81 m_deferredBreakConnectionList.append(&node); |
82 } | 82 } |
83 | 83 |
84 void DeferredTaskHandler::breakConnections() | 84 void DeferredTaskHandler::breakConnections() |
85 { | 85 { |
86 ASSERT(isAudioThread()); | 86 DCHECK(isAudioThread()); |
87 ASSERT(isGraphOwner()); | 87 ASSERT(isGraphOwner()); |
88 | 88 |
89 for (unsigned i = 0; i < m_deferredBreakConnectionList.size(); ++i) | 89 for (unsigned i = 0; i < m_deferredBreakConnectionList.size(); ++i) |
90 m_deferredBreakConnectionList[i]->breakConnectionWithLock(); | 90 m_deferredBreakConnectionList[i]->breakConnectionWithLock(); |
91 m_deferredBreakConnectionList.clear(); | 91 m_deferredBreakConnectionList.clear(); |
92 } | 92 } |
93 | 93 |
94 void DeferredTaskHandler::markSummingJunctionDirty(AudioSummingJunction* summing
Junction) | 94 void DeferredTaskHandler::markSummingJunctionDirty(AudioSummingJunction* summing
Junction) |
95 { | 95 { |
96 ASSERT(isGraphOwner()); | 96 ASSERT(isGraphOwner()); |
97 m_dirtySummingJunctions.add(summingJunction); | 97 m_dirtySummingJunctions.add(summingJunction); |
98 } | 98 } |
99 | 99 |
100 void DeferredTaskHandler::removeMarkedSummingJunction(AudioSummingJunction* summ
ingJunction) | 100 void DeferredTaskHandler::removeMarkedSummingJunction(AudioSummingJunction* summ
ingJunction) |
101 { | 101 { |
102 ASSERT(isMainThread()); | 102 DCHECK(isMainThread()); |
103 AutoLocker locker(*this); | 103 AutoLocker locker(*this); |
104 m_dirtySummingJunctions.remove(summingJunction); | 104 m_dirtySummingJunctions.remove(summingJunction); |
105 } | 105 } |
106 | 106 |
107 void DeferredTaskHandler::markAudioNodeOutputDirty(AudioNodeOutput* output) | 107 void DeferredTaskHandler::markAudioNodeOutputDirty(AudioNodeOutput* output) |
108 { | 108 { |
109 ASSERT(isGraphOwner()); | 109 ASSERT(isGraphOwner()); |
110 ASSERT(isMainThread()); | 110 DCHECK(isMainThread()); |
111 m_dirtyAudioNodeOutputs.add(output); | 111 m_dirtyAudioNodeOutputs.add(output); |
112 } | 112 } |
113 | 113 |
114 void DeferredTaskHandler::removeMarkedAudioNodeOutput(AudioNodeOutput* output) | 114 void DeferredTaskHandler::removeMarkedAudioNodeOutput(AudioNodeOutput* output) |
115 { | 115 { |
116 ASSERT(isGraphOwner()); | 116 ASSERT(isGraphOwner()); |
117 ASSERT(isMainThread()); | 117 DCHECK(isMainThread()); |
118 m_dirtyAudioNodeOutputs.remove(output); | 118 m_dirtyAudioNodeOutputs.remove(output); |
119 } | 119 } |
120 | 120 |
121 void DeferredTaskHandler::handleDirtyAudioSummingJunctions() | 121 void DeferredTaskHandler::handleDirtyAudioSummingJunctions() |
122 { | 122 { |
123 ASSERT(isGraphOwner()); | 123 ASSERT(isGraphOwner()); |
124 | 124 |
125 for (AudioSummingJunction* junction : m_dirtySummingJunctions) | 125 for (AudioSummingJunction* junction : m_dirtySummingJunctions) |
126 junction->updateRenderingState(); | 126 junction->updateRenderingState(); |
127 m_dirtySummingJunctions.clear(); | 127 m_dirtySummingJunctions.clear(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 ASSERT(isGraphOwner()); | 166 ASSERT(isGraphOwner()); |
167 | 167 |
168 if (m_automaticPullNodesNeedUpdating) { | 168 if (m_automaticPullNodesNeedUpdating) { |
169 copyToVector(m_automaticPullNodes, m_renderingAutomaticPullNodes); | 169 copyToVector(m_automaticPullNodes, m_renderingAutomaticPullNodes); |
170 m_automaticPullNodesNeedUpdating = false; | 170 m_automaticPullNodesNeedUpdating = false; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 void DeferredTaskHandler::processAutomaticPullNodes(size_t framesToProcess) | 174 void DeferredTaskHandler::processAutomaticPullNodes(size_t framesToProcess) |
175 { | 175 { |
176 ASSERT(isAudioThread()); | 176 DCHECK(isAudioThread()); |
177 | 177 |
178 for (unsigned i = 0; i < m_renderingAutomaticPullNodes.size(); ++i) | 178 for (unsigned i = 0; i < m_renderingAutomaticPullNodes.size(); ++i) |
179 m_renderingAutomaticPullNodes[i]->processIfNecessary(framesToProcess); | 179 m_renderingAutomaticPullNodes[i]->processIfNecessary(framesToProcess); |
180 } | 180 } |
181 | 181 |
182 DeferredTaskHandler::DeferredTaskHandler() | 182 DeferredTaskHandler::DeferredTaskHandler() |
183 : m_automaticPullNodesNeedUpdating(false) | 183 : m_automaticPullNodesNeedUpdating(false) |
184 , m_audioThread(0) | 184 , m_audioThread(0) |
185 { | 185 { |
186 } | 186 } |
187 | 187 |
188 PassRefPtr<DeferredTaskHandler> DeferredTaskHandler::create() | 188 PassRefPtr<DeferredTaskHandler> DeferredTaskHandler::create() |
189 { | 189 { |
190 return adoptRef(new DeferredTaskHandler()); | 190 return adoptRef(new DeferredTaskHandler()); |
191 } | 191 } |
192 | 192 |
193 DeferredTaskHandler::~DeferredTaskHandler() | 193 DeferredTaskHandler::~DeferredTaskHandler() |
194 { | 194 { |
195 ASSERT(!m_automaticPullNodes.size()); | 195 DCHECK(!m_automaticPullNodes.size()); |
196 if (m_automaticPullNodesNeedUpdating) | 196 if (m_automaticPullNodesNeedUpdating) |
197 m_renderingAutomaticPullNodes.resize(m_automaticPullNodes.size()); | 197 m_renderingAutomaticPullNodes.resize(m_automaticPullNodes.size()); |
198 ASSERT(!m_renderingAutomaticPullNodes.size()); | 198 DCHECK(!m_renderingAutomaticPullNodes.size()); |
199 } | 199 } |
200 | 200 |
201 void DeferredTaskHandler::handleDeferredTasks() | 201 void DeferredTaskHandler::handleDeferredTasks() |
202 { | 202 { |
203 handleDirtyAudioSummingJunctions(); | 203 handleDirtyAudioSummingJunctions(); |
204 handleDirtyAudioNodeOutputs(); | 204 handleDirtyAudioNodeOutputs(); |
205 updateAutomaticPullNodes(); | 205 updateAutomaticPullNodes(); |
206 } | 206 } |
207 | 207 |
208 void DeferredTaskHandler::contextWillBeDestroyed() | 208 void DeferredTaskHandler::contextWillBeDestroyed() |
(...skipping 13 matching lines...) Expand all Loading... |
222 } | 222 } |
223 | 223 |
224 DeferredTaskHandler::OfflineGraphAutoLocker::OfflineGraphAutoLocker(OfflineAudio
Context* context) | 224 DeferredTaskHandler::OfflineGraphAutoLocker::OfflineGraphAutoLocker(OfflineAudio
Context* context) |
225 : m_handler(context->deferredTaskHandler()) | 225 : m_handler(context->deferredTaskHandler()) |
226 { | 226 { |
227 m_handler.offlineLock(); | 227 m_handler.offlineLock(); |
228 } | 228 } |
229 | 229 |
230 void DeferredTaskHandler::addRenderingOrphanHandler(PassRefPtr<AudioHandler> han
dler) | 230 void DeferredTaskHandler::addRenderingOrphanHandler(PassRefPtr<AudioHandler> han
dler) |
231 { | 231 { |
232 ASSERT(handler); | 232 DCHECK(handler); |
233 ASSERT(!m_renderingOrphanHandlers.contains(handler)); | 233 DCHECK(!m_renderingOrphanHandlers.contains(handler)); |
234 m_renderingOrphanHandlers.append(handler); | 234 m_renderingOrphanHandlers.append(handler); |
235 } | 235 } |
236 | 236 |
237 void DeferredTaskHandler::requestToDeleteHandlersOnMainThread() | 237 void DeferredTaskHandler::requestToDeleteHandlersOnMainThread() |
238 { | 238 { |
239 ASSERT(isGraphOwner()); | 239 ASSERT(isGraphOwner()); |
240 ASSERT(isAudioThread()); | 240 DCHECK(isAudioThread()); |
241 if (m_renderingOrphanHandlers.isEmpty()) | 241 if (m_renderingOrphanHandlers.isEmpty()) |
242 return; | 242 return; |
243 m_deletableOrphanHandlers.appendVector(m_renderingOrphanHandlers); | 243 m_deletableOrphanHandlers.appendVector(m_renderingOrphanHandlers); |
244 m_renderingOrphanHandlers.clear(); | 244 m_renderingOrphanHandlers.clear(); |
245 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, crossThreadBind(&DeferredTaskHandler::deleteHandlersOnMainThread, PassRefPt
r<DeferredTaskHandler>(this))); | 245 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, crossThreadBind(&DeferredTaskHandler::deleteHandlersOnMainThread, PassRefPt
r<DeferredTaskHandler>(this))); |
246 } | 246 } |
247 | 247 |
248 void DeferredTaskHandler::deleteHandlersOnMainThread() | 248 void DeferredTaskHandler::deleteHandlersOnMainThread() |
249 { | 249 { |
250 ASSERT(isMainThread()); | 250 DCHECK(isMainThread()); |
251 AutoLocker locker(*this); | 251 AutoLocker locker(*this); |
252 m_deletableOrphanHandlers.clear(); | 252 m_deletableOrphanHandlers.clear(); |
253 } | 253 } |
254 | 254 |
255 void DeferredTaskHandler::clearHandlersToBeDeleted() | 255 void DeferredTaskHandler::clearHandlersToBeDeleted() |
256 { | 256 { |
257 ASSERT(isMainThread()); | 257 DCHECK(isMainThread()); |
258 AutoLocker locker(*this); | 258 AutoLocker locker(*this); |
259 m_renderingOrphanHandlers.clear(); | 259 m_renderingOrphanHandlers.clear(); |
260 m_deletableOrphanHandlers.clear(); | 260 m_deletableOrphanHandlers.clear(); |
261 } | 261 } |
262 | 262 |
263 void DeferredTaskHandler::setAudioThreadToCurrentThread() | 263 void DeferredTaskHandler::setAudioThreadToCurrentThread() |
264 { | 264 { |
265 ASSERT(!isMainThread()); | 265 DCHECK(!isMainThread()); |
266 ThreadIdentifier thread = currentThread(); | 266 ThreadIdentifier thread = currentThread(); |
267 releaseStore(&m_audioThread, thread); | 267 releaseStore(&m_audioThread, thread); |
268 } | 268 } |
269 | 269 |
270 } // namespace blink | 270 } // namespace blink |
271 | 271 |
OLD | NEW |