Chromium Code Reviews| 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 } |
| 59 | 59 |
| 60 void DeferredTaskHandler::offlineLock() | 60 void DeferredTaskHandler::offlineLock() |
| 61 { | 61 { |
| 62 // CHECK is here to make sure to explicitly crash if this is called from | 62 // CHECK is here to make sure to explicitly crash if this is called from |
| 63 // other than the offline render thread, which is considered as the audio | 63 // other than the offline render thread, which is considered as the audio |
| 64 // thread in OfflineAudioContext. | 64 // thread in OfflineAudioContext. |
| 65 CHECK(isAudioThread()) | 65 CHECK(isAudioThread()) |
| 66 << "DeferredTaskHandler::offlineLock() must be called within the offline audio thread."; | 66 << "DeferredTaskHandler::offlineLock() must be called within the offline audio thread."; |
| 67 | 67 |
| 68 m_contextGraphMutex.lock(); | 68 m_contextGraphMutex.lock(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 #if ENABLE(ASSERT) | |
| 72 bool DeferredTaskHandler::isGraphOwner() | 71 bool DeferredTaskHandler::isGraphOwner() |
| 73 { | 72 { |
| 73 #if ENABLE(ASSERT) | |
| 74 return m_contextGraphMutex.locked(); | 74 return m_contextGraphMutex.locked(); |
| 75 #else | |
| 76 return true; | |
|
Raymond Toy
2016/08/10 16:29:15
Please add comment on why true is the correct resu
HyungwookLee
2016/08/11 08:35:15
I think the best solution is removing #if ENABLE(A
| |
| 77 #endif | |
| 75 } | 78 } |
| 76 #endif | |
| 77 | 79 |
| 78 void DeferredTaskHandler::addDeferredBreakConnection(AudioHandler& node) | 80 void DeferredTaskHandler::addDeferredBreakConnection(AudioHandler& node) |
| 79 { | 81 { |
| 80 ASSERT(isAudioThread()); | 82 DCHECK(isAudioThread()); |
| 81 m_deferredBreakConnectionList.append(&node); | 83 m_deferredBreakConnectionList.append(&node); |
| 82 } | 84 } |
| 83 | 85 |
| 84 void DeferredTaskHandler::breakConnections() | 86 void DeferredTaskHandler::breakConnections() |
| 85 { | 87 { |
| 86 ASSERT(isAudioThread()); | 88 DCHECK(isAudioThread()); |
| 87 ASSERT(isGraphOwner()); | 89 DCHECK(isGraphOwner()); |
| 88 | 90 |
| 89 for (unsigned i = 0; i < m_deferredBreakConnectionList.size(); ++i) | 91 for (unsigned i = 0; i < m_deferredBreakConnectionList.size(); ++i) |
| 90 m_deferredBreakConnectionList[i]->breakConnectionWithLock(); | 92 m_deferredBreakConnectionList[i]->breakConnectionWithLock(); |
| 91 m_deferredBreakConnectionList.clear(); | 93 m_deferredBreakConnectionList.clear(); |
| 92 } | 94 } |
| 93 | 95 |
| 94 void DeferredTaskHandler::markSummingJunctionDirty(AudioSummingJunction* summing Junction) | 96 void DeferredTaskHandler::markSummingJunctionDirty(AudioSummingJunction* summing Junction) |
| 95 { | 97 { |
| 96 ASSERT(isGraphOwner()); | 98 DCHECK(isGraphOwner()); |
| 97 m_dirtySummingJunctions.add(summingJunction); | 99 m_dirtySummingJunctions.add(summingJunction); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void DeferredTaskHandler::removeMarkedSummingJunction(AudioSummingJunction* summ ingJunction) | 102 void DeferredTaskHandler::removeMarkedSummingJunction(AudioSummingJunction* summ ingJunction) |
| 101 { | 103 { |
| 102 ASSERT(isMainThread()); | 104 DCHECK(isMainThread()); |
| 103 AutoLocker locker(*this); | 105 AutoLocker locker(*this); |
| 104 m_dirtySummingJunctions.remove(summingJunction); | 106 m_dirtySummingJunctions.remove(summingJunction); |
| 105 } | 107 } |
| 106 | 108 |
| 107 void DeferredTaskHandler::markAudioNodeOutputDirty(AudioNodeOutput* output) | 109 void DeferredTaskHandler::markAudioNodeOutputDirty(AudioNodeOutput* output) |
| 108 { | 110 { |
| 109 ASSERT(isGraphOwner()); | 111 DCHECK(isGraphOwner()); |
| 110 ASSERT(isMainThread()); | 112 DCHECK(isMainThread()); |
| 111 m_dirtyAudioNodeOutputs.add(output); | 113 m_dirtyAudioNodeOutputs.add(output); |
| 112 } | 114 } |
| 113 | 115 |
| 114 void DeferredTaskHandler::removeMarkedAudioNodeOutput(AudioNodeOutput* output) | 116 void DeferredTaskHandler::removeMarkedAudioNodeOutput(AudioNodeOutput* output) |
| 115 { | 117 { |
| 116 ASSERT(isGraphOwner()); | 118 DCHECK(isGraphOwner()); |
| 117 ASSERT(isMainThread()); | 119 DCHECK(isMainThread()); |
| 118 m_dirtyAudioNodeOutputs.remove(output); | 120 m_dirtyAudioNodeOutputs.remove(output); |
| 119 } | 121 } |
| 120 | 122 |
| 121 void DeferredTaskHandler::handleDirtyAudioSummingJunctions() | 123 void DeferredTaskHandler::handleDirtyAudioSummingJunctions() |
| 122 { | 124 { |
| 123 ASSERT(isGraphOwner()); | 125 DCHECK(isGraphOwner()); |
| 124 | 126 |
| 125 for (AudioSummingJunction* junction : m_dirtySummingJunctions) | 127 for (AudioSummingJunction* junction : m_dirtySummingJunctions) |
| 126 junction->updateRenderingState(); | 128 junction->updateRenderingState(); |
| 127 m_dirtySummingJunctions.clear(); | 129 m_dirtySummingJunctions.clear(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void DeferredTaskHandler::handleDirtyAudioNodeOutputs() | 132 void DeferredTaskHandler::handleDirtyAudioNodeOutputs() |
| 131 { | 133 { |
| 132 ASSERT(isGraphOwner()); | 134 DCHECK(isGraphOwner()); |
| 133 | 135 |
| 134 HashSet<AudioNodeOutput*> dirtyOutputs; | 136 HashSet<AudioNodeOutput*> dirtyOutputs; |
| 135 m_dirtyAudioNodeOutputs.swap(dirtyOutputs); | 137 m_dirtyAudioNodeOutputs.swap(dirtyOutputs); |
| 136 | 138 |
| 137 // Note: the updating of rendering state may cause output nodes | 139 // Note: the updating of rendering state may cause output nodes |
| 138 // further down the chain to be marked as dirty. These will not | 140 // further down the chain to be marked as dirty. These will not |
| 139 // be processed in this render quantum. | 141 // be processed in this render quantum. |
| 140 for (AudioNodeOutput* output : dirtyOutputs) | 142 for (AudioNodeOutput* output : dirtyOutputs) |
| 141 output->updateRenderingState(); | 143 output->updateRenderingState(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void DeferredTaskHandler::addAutomaticPullNode(AudioHandler* node) | 146 void DeferredTaskHandler::addAutomaticPullNode(AudioHandler* node) |
| 145 { | 147 { |
| 146 ASSERT(isGraphOwner()); | 148 DCHECK(isGraphOwner()); |
| 147 | 149 |
| 148 if (!m_automaticPullNodes.contains(node)) { | 150 if (!m_automaticPullNodes.contains(node)) { |
| 149 m_automaticPullNodes.add(node); | 151 m_automaticPullNodes.add(node); |
| 150 m_automaticPullNodesNeedUpdating = true; | 152 m_automaticPullNodesNeedUpdating = true; |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | 155 |
| 154 void DeferredTaskHandler::removeAutomaticPullNode(AudioHandler* node) | 156 void DeferredTaskHandler::removeAutomaticPullNode(AudioHandler* node) |
| 155 { | 157 { |
| 156 ASSERT(isGraphOwner()); | 158 DCHECK(isGraphOwner()); |
| 157 | 159 |
| 158 if (m_automaticPullNodes.contains(node)) { | 160 if (m_automaticPullNodes.contains(node)) { |
| 159 m_automaticPullNodes.remove(node); | 161 m_automaticPullNodes.remove(node); |
| 160 m_automaticPullNodesNeedUpdating = true; | 162 m_automaticPullNodesNeedUpdating = true; |
| 161 } | 163 } |
| 162 } | 164 } |
| 163 | 165 |
| 164 void DeferredTaskHandler::updateAutomaticPullNodes() | 166 void DeferredTaskHandler::updateAutomaticPullNodes() |
| 165 { | 167 { |
| 166 ASSERT(isGraphOwner()); | 168 DCHECK(isGraphOwner()); |
| 167 | 169 |
| 168 if (m_automaticPullNodesNeedUpdating) { | 170 if (m_automaticPullNodesNeedUpdating) { |
| 169 copyToVector(m_automaticPullNodes, m_renderingAutomaticPullNodes); | 171 copyToVector(m_automaticPullNodes, m_renderingAutomaticPullNodes); |
| 170 m_automaticPullNodesNeedUpdating = false; | 172 m_automaticPullNodesNeedUpdating = false; |
| 171 } | 173 } |
| 172 } | 174 } |
| 173 | 175 |
| 174 void DeferredTaskHandler::processAutomaticPullNodes(size_t framesToProcess) | 176 void DeferredTaskHandler::processAutomaticPullNodes(size_t framesToProcess) |
| 175 { | 177 { |
| 176 ASSERT(isAudioThread()); | 178 DCHECK(isAudioThread()); |
| 177 | 179 |
| 178 for (unsigned i = 0; i < m_renderingAutomaticPullNodes.size(); ++i) | 180 for (unsigned i = 0; i < m_renderingAutomaticPullNodes.size(); ++i) |
| 179 m_renderingAutomaticPullNodes[i]->processIfNecessary(framesToProcess); | 181 m_renderingAutomaticPullNodes[i]->processIfNecessary(framesToProcess); |
| 180 } | 182 } |
| 181 | 183 |
| 182 void DeferredTaskHandler::addChangedChannelCountMode(AudioHandler* node) | 184 void DeferredTaskHandler::addChangedChannelCountMode(AudioHandler* node) |
| 183 { | 185 { |
| 184 ASSERT(isGraphOwner()); | 186 DCHECK(isGraphOwner()); |
| 185 ASSERT(isMainThread()); | 187 DCHECK(isMainThread()); |
| 186 m_deferredCountModeChange.add(node); | 188 m_deferredCountModeChange.add(node); |
| 187 } | 189 } |
| 188 | 190 |
| 189 void DeferredTaskHandler::removeChangedChannelCountMode(AudioHandler* node) | 191 void DeferredTaskHandler::removeChangedChannelCountMode(AudioHandler* node) |
| 190 { | 192 { |
| 191 ASSERT(isGraphOwner()); | 193 DCHECK(isGraphOwner()); |
| 192 | 194 |
| 193 m_deferredCountModeChange.remove(node); | 195 m_deferredCountModeChange.remove(node); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void DeferredTaskHandler::addChangedChannelInterpretation(AudioHandler* node) | 198 void DeferredTaskHandler::addChangedChannelInterpretation(AudioHandler* node) |
| 197 { | 199 { |
| 198 ASSERT(isGraphOwner()); | 200 DCHECK(isGraphOwner()); |
| 199 ASSERT(isMainThread()); | 201 DCHECK(isMainThread()); |
| 200 m_deferredChannelInterpretationChange.add(node); | 202 m_deferredChannelInterpretationChange.add(node); |
| 201 } | 203 } |
| 202 | 204 |
| 203 void DeferredTaskHandler::removeChangedChannelInterpretation(AudioHandler* node) | 205 void DeferredTaskHandler::removeChangedChannelInterpretation(AudioHandler* node) |
| 204 { | 206 { |
| 205 ASSERT(isGraphOwner()); | 207 DCHECK(isGraphOwner()); |
| 206 | 208 |
| 207 m_deferredChannelInterpretationChange.remove(node); | 209 m_deferredChannelInterpretationChange.remove(node); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void DeferredTaskHandler::updateChangedChannelCountMode() | 212 void DeferredTaskHandler::updateChangedChannelCountMode() |
| 211 { | 213 { |
| 212 ASSERT(isGraphOwner()); | 214 DCHECK(isGraphOwner()); |
| 213 | 215 |
| 214 for (AudioHandler* node : m_deferredCountModeChange) | 216 for (AudioHandler* node : m_deferredCountModeChange) |
| 215 node->updateChannelCountMode(); | 217 node->updateChannelCountMode(); |
| 216 m_deferredCountModeChange.clear(); | 218 m_deferredCountModeChange.clear(); |
| 217 } | 219 } |
| 218 | 220 |
| 219 void DeferredTaskHandler::updateChangedChannelInterpretation() | 221 void DeferredTaskHandler::updateChangedChannelInterpretation() |
| 220 { | 222 { |
| 221 ASSERT(isGraphOwner()); | 223 DCHECK(isGraphOwner()); |
| 222 | 224 |
| 223 for (AudioHandler* node : m_deferredChannelInterpretationChange) | 225 for (AudioHandler* node : m_deferredChannelInterpretationChange) |
| 224 node->updateChannelInterpretation(); | 226 node->updateChannelInterpretation(); |
| 225 m_deferredChannelInterpretationChange.clear(); | 227 m_deferredChannelInterpretationChange.clear(); |
| 226 } | 228 } |
| 227 | 229 |
| 228 DeferredTaskHandler::DeferredTaskHandler() | 230 DeferredTaskHandler::DeferredTaskHandler() |
| 229 : m_automaticPullNodesNeedUpdating(false) | 231 : m_automaticPullNodesNeedUpdating(false) |
| 230 , m_audioThread(0) | 232 , m_audioThread(0) |
| 231 { | 233 { |
| 232 } | 234 } |
| 233 | 235 |
| 234 PassRefPtr<DeferredTaskHandler> DeferredTaskHandler::create() | 236 PassRefPtr<DeferredTaskHandler> DeferredTaskHandler::create() |
| 235 { | 237 { |
| 236 return adoptRef(new DeferredTaskHandler()); | 238 return adoptRef(new DeferredTaskHandler()); |
| 237 } | 239 } |
| 238 | 240 |
| 239 DeferredTaskHandler::~DeferredTaskHandler() | 241 DeferredTaskHandler::~DeferredTaskHandler() |
| 240 { | 242 { |
| 241 ASSERT(!m_automaticPullNodes.size()); | 243 DCHECK(!m_automaticPullNodes.size()); |
| 242 if (m_automaticPullNodesNeedUpdating) | 244 if (m_automaticPullNodesNeedUpdating) |
| 243 m_renderingAutomaticPullNodes.resize(m_automaticPullNodes.size()); | 245 m_renderingAutomaticPullNodes.resize(m_automaticPullNodes.size()); |
| 244 ASSERT(!m_renderingAutomaticPullNodes.size()); | 246 DCHECK(!m_renderingAutomaticPullNodes.size()); |
| 245 } | 247 } |
| 246 | 248 |
| 247 void DeferredTaskHandler::handleDeferredTasks() | 249 void DeferredTaskHandler::handleDeferredTasks() |
| 248 { | 250 { |
| 249 updateChangedChannelCountMode(); | 251 updateChangedChannelCountMode(); |
| 250 updateChangedChannelInterpretation(); | 252 updateChangedChannelInterpretation(); |
| 251 handleDirtyAudioSummingJunctions(); | 253 handleDirtyAudioSummingJunctions(); |
| 252 handleDirtyAudioNodeOutputs(); | 254 handleDirtyAudioNodeOutputs(); |
| 253 updateAutomaticPullNodes(); | 255 updateAutomaticPullNodes(); |
| 254 } | 256 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 270 } | 272 } |
| 271 | 273 |
| 272 DeferredTaskHandler::OfflineGraphAutoLocker::OfflineGraphAutoLocker(OfflineAudio Context* context) | 274 DeferredTaskHandler::OfflineGraphAutoLocker::OfflineGraphAutoLocker(OfflineAudio Context* context) |
| 273 : m_handler(context->deferredTaskHandler()) | 275 : m_handler(context->deferredTaskHandler()) |
| 274 { | 276 { |
| 275 m_handler.offlineLock(); | 277 m_handler.offlineLock(); |
| 276 } | 278 } |
| 277 | 279 |
| 278 void DeferredTaskHandler::addRenderingOrphanHandler(PassRefPtr<AudioHandler> han dler) | 280 void DeferredTaskHandler::addRenderingOrphanHandler(PassRefPtr<AudioHandler> han dler) |
| 279 { | 281 { |
| 280 ASSERT(handler); | 282 DCHECK(handler); |
| 281 ASSERT(!m_renderingOrphanHandlers.contains(handler)); | 283 DCHECK(!m_renderingOrphanHandlers.contains(handler)); |
| 282 m_renderingOrphanHandlers.append(handler); | 284 m_renderingOrphanHandlers.append(handler); |
| 283 } | 285 } |
| 284 | 286 |
| 285 void DeferredTaskHandler::requestToDeleteHandlersOnMainThread() | 287 void DeferredTaskHandler::requestToDeleteHandlersOnMainThread() |
| 286 { | 288 { |
| 287 ASSERT(isGraphOwner()); | 289 DCHECK(isGraphOwner()); |
| 288 ASSERT(isAudioThread()); | 290 DCHECK(isAudioThread()); |
| 289 if (m_renderingOrphanHandlers.isEmpty()) | 291 if (m_renderingOrphanHandlers.isEmpty()) |
| 290 return; | 292 return; |
| 291 m_deletableOrphanHandlers.appendVector(m_renderingOrphanHandlers); | 293 m_deletableOrphanHandlers.appendVector(m_renderingOrphanHandlers); |
| 292 m_renderingOrphanHandlers.clear(); | 294 m_renderingOrphanHandlers.clear(); |
| 293 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, crossThreadBind(&DeferredTaskHandler::deleteHandlersOnMainThread, PassRefPt r<DeferredTaskHandler>(this))); | 295 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, crossThreadBind(&DeferredTaskHandler::deleteHandlersOnMainThread, PassRefPt r<DeferredTaskHandler>(this))); |
| 294 } | 296 } |
| 295 | 297 |
| 296 void DeferredTaskHandler::deleteHandlersOnMainThread() | 298 void DeferredTaskHandler::deleteHandlersOnMainThread() |
| 297 { | 299 { |
| 298 ASSERT(isMainThread()); | 300 DCHECK(isMainThread()); |
| 299 AutoLocker locker(*this); | 301 AutoLocker locker(*this); |
| 300 m_deletableOrphanHandlers.clear(); | 302 m_deletableOrphanHandlers.clear(); |
| 301 } | 303 } |
| 302 | 304 |
| 303 void DeferredTaskHandler::clearHandlersToBeDeleted() | 305 void DeferredTaskHandler::clearHandlersToBeDeleted() |
| 304 { | 306 { |
| 305 ASSERT(isMainThread()); | 307 DCHECK(isMainThread()); |
| 306 AutoLocker locker(*this); | 308 AutoLocker locker(*this); |
| 307 m_renderingOrphanHandlers.clear(); | 309 m_renderingOrphanHandlers.clear(); |
| 308 m_deletableOrphanHandlers.clear(); | 310 m_deletableOrphanHandlers.clear(); |
| 309 } | 311 } |
| 310 | 312 |
| 311 void DeferredTaskHandler::setAudioThreadToCurrentThread() | 313 void DeferredTaskHandler::setAudioThreadToCurrentThread() |
| 312 { | 314 { |
| 313 ASSERT(!isMainThread()); | 315 DCHECK(!isMainThread()); |
| 314 ThreadIdentifier thread = currentThread(); | 316 ThreadIdentifier thread = currentThread(); |
| 315 releaseStore(&m_audioThread, thread); | 317 releaseStore(&m_audioThread, thread); |
| 316 } | 318 } |
| 317 | 319 |
| 318 } // namespace blink | 320 } // namespace blink |
| 319 | 321 |
| OLD | NEW |