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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND |
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE | 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE |
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
23 * DAMAGE. | 23 * DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "modules/webaudio/ScriptProcessorNode.h" | 26 #include "modules/webaudio/ScriptProcessorNode.h" |
27 #include "bindings/core/v8/ExceptionState.h" | 27 #include "bindings/core/v8/ExceptionState.h" |
28 #include "core/dom/ExceptionCode.h" | 28 #include "core/dom/ExceptionCode.h" |
29 #include "core/dom/ExecutionContext.h" | 29 #include "core/dom/ExecutionContext.h" |
30 #include "core/dom/ExecutionContextTask.h" | |
31 #include "core/dom/TaskRunnerHelper.h" | 30 #include "core/dom/TaskRunnerHelper.h" |
32 #include "modules/webaudio/AudioBuffer.h" | 31 #include "modules/webaudio/AudioBuffer.h" |
33 #include "modules/webaudio/AudioNodeInput.h" | 32 #include "modules/webaudio/AudioNodeInput.h" |
34 #include "modules/webaudio/AudioNodeOutput.h" | 33 #include "modules/webaudio/AudioNodeOutput.h" |
35 #include "modules/webaudio/AudioProcessingEvent.h" | 34 #include "modules/webaudio/AudioProcessingEvent.h" |
36 #include "modules/webaudio/BaseAudioContext.h" | 35 #include "modules/webaudio/BaseAudioContext.h" |
| 36 #include "platform/CrossThreadFunctional.h" |
37 #include "platform/WaitableEvent.h" | 37 #include "platform/WaitableEvent.h" |
38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 ScriptProcessorHandler::ScriptProcessorHandler(AudioNode& node, | 42 ScriptProcessorHandler::ScriptProcessorHandler(AudioNode& node, |
43 float sampleRate, | 43 float sampleRate, |
44 size_t bufferSize, | 44 size_t bufferSize, |
45 unsigned numberOfInputChannels, | 45 unsigned numberOfInputChannels, |
46 unsigned numberOfOutputChannels) | 46 unsigned numberOfOutputChannels) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 if (!tryLocker.locked()) { | 199 if (!tryLocker.locked()) { |
200 // We're late in handling the previous request. The main thread must be | 200 // We're late in handling the previous request. The main thread must be |
201 // very busy. The best we can do is clear out the buffer ourself here. | 201 // very busy. The best we can do is clear out the buffer ourself here. |
202 outputBuffer->zero(); | 202 outputBuffer->zero(); |
203 } else if (context()->getExecutionContext()) { | 203 } else if (context()->getExecutionContext()) { |
204 // With the realtime context, execute the script code asynchronously | 204 // With the realtime context, execute the script code asynchronously |
205 // and do not wait. | 205 // and do not wait. |
206 if (context()->hasRealtimeConstraint()) { | 206 if (context()->hasRealtimeConstraint()) { |
207 // Fire the event on the main thread with the appropriate buffer | 207 // Fire the event on the main thread with the appropriate buffer |
208 // index. | 208 // index. |
209 context()->getExecutionContext()->postTask( | 209 TaskRunnerHelper::get(TaskType::MediaElementEvent, |
210 TaskType::MediaElementEvent, BLINK_FROM_HERE, | 210 context()->getExecutionContext()) |
211 createCrossThreadTask(&ScriptProcessorHandler::fireProcessEvent, | 211 ->postTask(BLINK_FROM_HERE, |
212 crossThreadUnretained(this), | 212 crossThreadBind( |
213 m_doubleBufferIndex)); | 213 &ScriptProcessorHandler::fireProcessEvent, |
| 214 crossThreadUnretained(this), m_doubleBufferIndex)); |
214 } else { | 215 } else { |
215 // If this node is in the offline audio context, use the | 216 // If this node is in the offline audio context, use the |
216 // waitable event to synchronize to the offline rendering thread. | 217 // waitable event to synchronize to the offline rendering thread. |
217 std::unique_ptr<WaitableEvent> waitableEvent = | 218 std::unique_ptr<WaitableEvent> waitableEvent = |
218 WTF::makeUnique<WaitableEvent>(); | 219 WTF::makeUnique<WaitableEvent>(); |
219 | 220 |
220 context()->getExecutionContext()->postTask( | 221 TaskRunnerHelper::get(TaskType::MediaElementEvent, |
221 TaskType::MediaElementEvent, BLINK_FROM_HERE, | 222 context()->getExecutionContext()) |
222 createCrossThreadTask( | 223 ->postTask(BLINK_FROM_HERE, |
223 &ScriptProcessorHandler::fireProcessEventForOfflineAudioContext, | 224 crossThreadBind( |
224 crossThreadUnretained(this), m_doubleBufferIndex, | 225 &ScriptProcessorHandler:: |
225 crossThreadUnretained(waitableEvent.get()))); | 226 fireProcessEventForOfflineAudioContext, |
| 227 crossThreadUnretained(this), m_doubleBufferIndex, |
| 228 crossThreadUnretained(waitableEvent.get()))); |
226 | 229 |
227 // Okay to block the offline audio rendering thread since it is | 230 // Okay to block the offline audio rendering thread since it is |
228 // not the actual audio device thread. | 231 // not the actual audio device thread. |
229 waitableEvent->wait(); | 232 waitableEvent->wait(); |
230 } | 233 } |
231 } | 234 } |
232 | 235 |
233 swapBuffers(); | 236 swapBuffers(); |
234 } | 237 } |
235 } | 238 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 483 |
481 // If |onaudioprocess| event handler is defined, the node should not be | 484 // If |onaudioprocess| event handler is defined, the node should not be |
482 // GCed even if it is out of scope. | 485 // GCed even if it is out of scope. |
483 if (hasEventListeners(EventTypeNames::audioprocess)) | 486 if (hasEventListeners(EventTypeNames::audioprocess)) |
484 return true; | 487 return true; |
485 | 488 |
486 return false; | 489 return false; |
487 } | 490 } |
488 | 491 |
489 } // namespace blink | 492 } // namespace blink |
OLD | NEW |