| 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 20 matching lines...) Expand all Loading... |
| 31 #include "bindings/core/v8/ExceptionState.h" | 31 #include "bindings/core/v8/ExceptionState.h" |
| 32 #include "core/dom/CrossThreadTask.h" | 32 #include "core/dom/CrossThreadTask.h" |
| 33 #include "core/dom/ExecutionContext.h" | 33 #include "core/dom/ExecutionContext.h" |
| 34 #include "modules/webaudio/AudioBuffer.h" | 34 #include "modules/webaudio/AudioBuffer.h" |
| 35 #include "modules/webaudio/AudioContext.h" | 35 #include "modules/webaudio/AudioContext.h" |
| 36 #include "modules/webaudio/AudioNodeInput.h" | 36 #include "modules/webaudio/AudioNodeInput.h" |
| 37 #include "modules/webaudio/AudioNodeOutput.h" | 37 #include "modules/webaudio/AudioNodeOutput.h" |
| 38 #include "modules/webaudio/AudioProcessingEvent.h" | 38 #include "modules/webaudio/AudioProcessingEvent.h" |
| 39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 40 #include "wtf/Float32Array.h" | 40 #include "wtf/Float32Array.h" |
| 41 #include "wtf/UnretainedPtr.h" |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 static size_t chooseBufferSize() | 45 static size_t chooseBufferSize() |
| 45 { | 46 { |
| 46 // Choose a buffer size based on the audio hardware buffer size. Arbitarily
make it a power of | 47 // Choose a buffer size based on the audio hardware buffer size. Arbitarily
make it a power of |
| 47 // two that is 4 times greater than the hardware buffer size. | 48 // two that is 4 times greater than the hardware buffer size. |
| 48 // FIXME: What is the best way to choose this? | 49 // FIXME: What is the best way to choose this? |
| 49 size_t hardwareBufferSize = Platform::current()->audioHardwareBufferSize(); | 50 size_t hardwareBufferSize = Platform::current()->audioHardwareBufferSize(); |
| 50 size_t bufferSize = 1 << static_cast<unsigned>(log2(4 * hardwareBufferSize)
+ 0.5); | 51 size_t bufferSize = 1 << static_cast<unsigned>(log2(4 * hardwareBufferSize)
+ 0.5); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // This could be a problem if the main thread is very busy doing other t
hings and is being held up handling previous requests. | 224 // This could be a problem if the main thread is very busy doing other t
hings and is being held up handling previous requests. |
| 224 // The audio thread can't block on this lock, so we call tryLock() inste
ad. | 225 // The audio thread can't block on this lock, so we call tryLock() inste
ad. |
| 225 MutexTryLocker tryLocker(m_processEventLock); | 226 MutexTryLocker tryLocker(m_processEventLock); |
| 226 if (!tryLocker.locked()) { | 227 if (!tryLocker.locked()) { |
| 227 // We're late in handling the previous request. The main thread must
be very busy. | 228 // We're late in handling the previous request. The main thread must
be very busy. |
| 228 // The best we can do is clear out the buffer ourself here. | 229 // The best we can do is clear out the buffer ourself here. |
| 229 outputBuffer->zero(); | 230 outputBuffer->zero(); |
| 230 } else if (context()->executionContext()) { | 231 } else if (context()->executionContext()) { |
| 231 // Fire the event on the main thread, not this one (which is the rea
ltime audio thread). | 232 // Fire the event on the main thread, not this one (which is the rea
ltime audio thread). |
| 232 m_doubleBufferIndexForEvent = m_doubleBufferIndex; | 233 m_doubleBufferIndexForEvent = m_doubleBufferIndex; |
| 233 context()->executionContext()->postTask(createCrossThreadTask(&Scrip
tProcessorNode::fireProcessEvent, this)); | 234 context()->executionContext()->postTask(createCrossThreadTask(&Scrip
tProcessorNode::fireProcessEvent, UnretainedPtr<ScriptProcessorNode>(this))); |
| 234 } | 235 } |
| 235 | 236 |
| 236 swapBuffers(); | 237 swapBuffers(); |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 | 240 |
| 240 void ScriptProcessorNode::fireProcessEvent() | 241 void ScriptProcessorNode::fireProcessEvent() |
| 241 { | 242 { |
| 242 ASSERT(isMainThread()); | 243 ASSERT(isMainThread()); |
| 243 | 244 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 void ScriptProcessorNode::trace(Visitor* visitor) | 304 void ScriptProcessorNode::trace(Visitor* visitor) |
| 304 { | 305 { |
| 305 visitor->trace(m_inputBuffers); | 306 visitor->trace(m_inputBuffers); |
| 306 visitor->trace(m_outputBuffers); | 307 visitor->trace(m_outputBuffers); |
| 307 AudioNode::trace(visitor); | 308 AudioNode::trace(visitor); |
| 308 } | 309 } |
| 309 | 310 |
| 310 } // namespace blink | 311 } // namespace blink |
| 311 | 312 |
| 312 #endif // ENABLE(WEB_AUDIO) | 313 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |