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 24 matching lines...) Expand all Loading... | |
35 #include "wtf/MathExtras.h" | 35 #include "wtf/MathExtras.h" |
36 | 36 |
37 using namespace std; | 37 using namespace std; |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 const double AudioScheduledSourceNode::UnknownTime = -1; | 41 const double AudioScheduledSourceNode::UnknownTime = -1; |
42 | 42 |
43 AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* context, float sampleRate) | 43 AudioScheduledSourceNode::AudioScheduledSourceNode(AudioContext* context, float sampleRate) |
44 : AudioSourceNode(context, sampleRate) | 44 : AudioSourceNode(context, sampleRate) |
45 , ActiveDOMObject(context->scriptExecutionContext()) | |
45 , m_playbackState(UNSCHEDULED_STATE) | 46 , m_playbackState(UNSCHEDULED_STATE) |
46 , m_startTime(0) | 47 , m_startTime(0) |
47 , m_endTime(UnknownTime) | 48 , m_endTime(UnknownTime) |
48 , m_hasEndedListener(false) | 49 , m_hasEndedListener(false) |
49 { | 50 { |
50 } | 51 } |
51 | 52 |
52 void AudioScheduledSourceNode::updateSchedulingInfo(size_t quantumFrameSize, | 53 void AudioScheduledSourceNode::updateSchedulingInfo(size_t quantumFrameSize, |
53 AudioBus* outputBus, | 54 AudioBus* outputBus, |
54 size_t& quantumFrameOffset, | 55 size_t& quantumFrameOffset, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 void AudioScheduledSourceNode::start(double when) | 138 void AudioScheduledSourceNode::start(double when) |
138 { | 139 { |
139 ASSERT(isMainThread()); | 140 ASSERT(isMainThread()); |
140 if (m_playbackState != UNSCHEDULED_STATE) | 141 if (m_playbackState != UNSCHEDULED_STATE) |
141 return; | 142 return; |
142 | 143 |
143 m_startTime = when; | 144 m_startTime = when; |
144 m_playbackState = SCHEDULED_STATE; | 145 m_playbackState = SCHEDULED_STATE; |
145 } | 146 } |
146 | 147 |
147 void AudioScheduledSourceNode::stop(double when) | 148 void AudioScheduledSourceNode::stopNote(double when) |
148 { | 149 { |
149 ASSERT(isMainThread()); | 150 ASSERT(isMainThread()); |
150 if (!(m_playbackState == SCHEDULED_STATE || m_playbackState == PLAYING_STATE )) | 151 if (!(m_playbackState == SCHEDULED_STATE || m_playbackState == PLAYING_STATE )) |
151 return; | 152 return; |
152 | 153 |
153 when = max(0.0, when); | 154 when = max(0.0, when); |
154 m_endTime = when; | 155 m_endTime = when; |
155 } | 156 } |
156 | 157 |
157 void AudioScheduledSourceNode::noteOn(double when) | 158 void AudioScheduledSourceNode::noteOn(double when) |
158 { | 159 { |
159 start(when); | 160 start(when); |
160 } | 161 } |
161 | 162 |
162 void AudioScheduledSourceNode::noteOff(double when) | 163 void AudioScheduledSourceNode::noteOff(double when) |
163 { | 164 { |
164 stop(when); | 165 stopNote(when); |
165 } | 166 } |
166 | 167 |
167 void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener, DO MWrapperWorld* isolatedWorld) | 168 void AudioScheduledSourceNode::setOnended(PassRefPtr<EventListener> listener, DO MWrapperWorld* isolatedWorld) |
168 { | 169 { |
169 m_hasEndedListener = listener; | 170 m_hasEndedListener = listener; |
170 setAttributeEventListener(eventNames().endedEvent, listener, isolatedWorld); | 171 setAttributeEventListener(eventNames().endedEvent, listener, isolatedWorld); |
171 } | 172 } |
172 | 173 |
173 void AudioScheduledSourceNode::finish() | 174 void AudioScheduledSourceNode::finish() |
174 { | 175 { |
175 if (m_playbackState != FINISHED_STATE) { | 176 if (m_playbackState != FINISHED_STATE) { |
176 // Let the context dereference this AudioNode. | 177 // Let the context dereference this AudioNode. |
177 context()->notifyNodeFinishedProcessing(this); | 178 context()->notifyNodeFinishedProcessing(this); |
178 m_playbackState = FINISHED_STATE; | 179 m_playbackState = FINISHED_STATE; |
179 context()->decrementActiveSourceCount(); | 180 context()->decrementActiveSourceCount(); |
180 } | 181 } |
181 | 182 |
182 if (m_hasEndedListener) | 183 if (m_hasEndedListener) { |
184 setPendingActivity(this); | |
Ken Russell (switch to Gerrit)
2013/09/09 21:30:05
Sorry, I failed to realize this before. This can't
Ken Russell (switch to Gerrit)
2013/09/09 21:34:31
Apologies, I think I'm wrong. AudioNode::ref is sp
| |
183 callOnMainThread(&AudioScheduledSourceNode::notifyEndedDispatch, this); | 185 callOnMainThread(&AudioScheduledSourceNode::notifyEndedDispatch, this); |
186 } | |
184 } | 187 } |
185 | 188 |
186 void AudioScheduledSourceNode::notifyEndedDispatch(void* userData) | 189 void AudioScheduledSourceNode::notifyEndedDispatch(void* userData) |
187 { | 190 { |
188 static_cast<AudioScheduledSourceNode*>(userData)->notifyEnded(); | 191 static_cast<AudioScheduledSourceNode*>(userData)->notifyEnded(); |
189 } | 192 } |
190 | 193 |
191 void AudioScheduledSourceNode::notifyEnded() | 194 void AudioScheduledSourceNode::notifyEnded() |
192 { | 195 { |
193 RefPtr<Event> event = Event::create(eventNames().endedEvent); | 196 // Avoid firing the event if the document has already gone away. |
194 event->setTarget(this); | 197 if (context()->scriptExecutionContext()) { |
195 dispatchEvent(event.get()); | 198 RefPtr<Event> event = Event::create(eventNames().endedEvent); |
199 event->setTarget(this); | |
200 dispatchEvent(event.get()); | |
201 } | |
202 unsetPendingActivity(this); | |
Ken Russell (switch to Gerrit)
2013/09/09 19:45:47
This looks wrong now. What happens if we navigate
| |
203 } | |
204 | |
205 ScriptExecutionContext* AudioScheduledSourceNode::scriptExecutionContext() const | |
206 { | |
207 return context()->scriptExecutionContext(); | |
208 } | |
209 | |
210 void AudioScheduledSourceNode::stop() | |
211 { | |
212 if (hasPendingActivity()) | |
213 unsetPendingActivity(this); | |
196 } | 214 } |
197 | 215 |
198 } // namespace WebCore | 216 } // namespace WebCore |
199 | 217 |
200 #endif // ENABLE(WEB_AUDIO) | 218 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |