OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, 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 11 matching lines...) Expand all Loading... |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 | 26 |
27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
28 | 28 |
29 #include "modules/webaudio/AudioScheduledSourceNode.h" | 29 #include "modules/webaudio/AudioScheduledSourceNode.h" |
30 | 30 |
31 #include "bindings/core/v8/ExceptionState.h" | 31 #include "bindings/core/v8/ExceptionState.h" |
| 32 #include "core/dom/CrossThreadTask.h" |
32 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
33 #include "modules/EventModules.h" | 34 #include "modules/EventModules.h" |
34 #include "modules/webaudio/AudioContext.h" | 35 #include "modules/webaudio/AudioContext.h" |
35 #include "platform/audio/AudioUtilities.h" | 36 #include "platform/audio/AudioUtilities.h" |
| 37 #include "wtf/MathExtras.h" |
36 #include <algorithm> | 38 #include <algorithm> |
37 #include "wtf/MathExtras.h" | |
38 | 39 |
39 namespace WebCore { | 40 namespace WebCore { |
40 | 41 |
| 42 #if !ENABLE(OILPAN) |
| 43 // We need a dedicated specialization for AudioScheduledSourceNode because it |
| 44 // doesn't inherit from RefCounted. |
| 45 template<> struct CrossThreadCopierBase<false, false, false, PassRefPtr<AudioSch
eduledSourceNode> > : public CrossThreadCopierPassThrough<PassRefPtr<AudioSchedu
ledSourceNode> > { |
| 46 }; |
| 47 #endif |
| 48 |
41 const double AudioScheduledSourceNode::UnknownTime = -1; | 49 const double AudioScheduledSourceNode::UnknownTime = -1; |
42 | 50 |
43 AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* context, float
sampleRate) | 51 AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* context, float
sampleRate) |
44 : AudioSourceNode(context, sampleRate) | 52 : AudioSourceNode(context, sampleRate) |
45 , m_playbackState(UNSCHEDULED_STATE) | 53 , m_playbackState(UNSCHEDULED_STATE) |
46 , m_startTime(0) | 54 , m_startTime(0) |
47 , m_endTime(UnknownTime) | 55 , m_endTime(UnknownTime) |
48 , m_hasEndedListener(false) | 56 , m_hasEndedListener(false) |
49 { | 57 { |
50 } | 58 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 180 } |
173 | 181 |
174 void AudioScheduledSourceNode::finish() | 182 void AudioScheduledSourceNode::finish() |
175 { | 183 { |
176 if (m_playbackState != FINISHED_STATE) { | 184 if (m_playbackState != FINISHED_STATE) { |
177 // Let the context dereference this AudioNode. | 185 // Let the context dereference this AudioNode. |
178 context()->notifyNodeFinishedProcessing(this); | 186 context()->notifyNodeFinishedProcessing(this); |
179 m_playbackState = FINISHED_STATE; | 187 m_playbackState = FINISHED_STATE; |
180 } | 188 } |
181 | 189 |
182 if (m_hasEndedListener) { | 190 if (m_hasEndedListener && context()->executionContext()) { |
183 // |task| will keep the AudioScheduledSourceNode alive until the listene
r has been handled. | 191 context()->executionContext()->postTask(createCrossThreadTask(&AudioSche
duledSourceNode::notifyEnded, PassRefPtrWillBeRawPtr<AudioScheduledSourceNode>(t
his))); |
184 OwnPtr<NotifyEndedTask> task = adoptPtr(new NotifyEndedTask(this)); | |
185 callOnMainThread(&AudioScheduledSourceNode::notifyEndedDispatch, task.le
akPtr()); | |
186 } | 192 } |
187 } | 193 } |
188 | 194 |
189 void AudioScheduledSourceNode::notifyEndedDispatch(void* userData) | 195 void AudioScheduledSourceNode::notifyEnded() |
190 { | 196 { |
191 OwnPtr<NotifyEndedTask> task = adoptPtr(static_cast<NotifyEndedTask*>(userDa
ta)); | 197 dispatchEvent(Event::create(EventTypeNames::ended)); |
192 | |
193 task->notifyEnded(); | |
194 } | |
195 | |
196 AudioScheduledSourceNode::NotifyEndedTask::NotifyEndedTask(PassRefPtr<AudioSched
uledSourceNode> sourceNode) | |
197 : m_scheduledNode(sourceNode) | |
198 { | |
199 } | |
200 | |
201 void AudioScheduledSourceNode::NotifyEndedTask::notifyEnded() | |
202 { | |
203 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::ended); | |
204 event->setTarget(m_scheduledNode.get()); | |
205 m_scheduledNode->dispatchEvent(event.get()); | |
206 } | 198 } |
207 | 199 |
208 } // namespace WebCore | 200 } // namespace WebCore |
209 | 201 |
210 #endif // ENABLE(WEB_AUDIO) | 202 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |