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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 148 |
149 // Create a new destination for offline rendering. | 149 // Create a new destination for offline rendering. |
150 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate); | 150 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate); |
151 if (m_renderTarget.get()) | 151 if (m_renderTarget.get()) |
152 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get()); | 152 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get()); |
153 } | 153 } |
154 | 154 |
155 void AudioContext::constructCommon() | 155 void AudioContext::constructCommon() |
156 { | 156 { |
157 ScriptWrappable::init(this); | 157 ScriptWrappable::init(this); |
158 // According to spec AudioContext must die only after page navigate. | |
159 // Lets mark it as ActiveDOMObject with pending activity and unmark it in cl ear method. | |
160 setPendingActivity(this); | |
161 | 158 |
162 FFTFrame::initialize(); | 159 FFTFrame::initialize(); |
163 | 160 |
164 m_listener = AudioListener::create(); | 161 m_listener = AudioListener::create(); |
165 } | 162 } |
166 | 163 |
167 AudioContext::~AudioContext() | 164 AudioContext::~AudioContext() |
168 { | 165 { |
169 #if DEBUG_AUDIONODE_REFERENCES | 166 #if DEBUG_AUDIONODE_REFERENCES |
170 fprintf(stderr, "%p: AudioContext::~AudioContext()\n", this); | 167 fprintf(stderr, "%p: AudioContext::~AudioContext()\n", this); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // We have to release our reference to the destination node before the conte xt will ever be deleted since the destination node holds a reference to the cont ext. | 207 // We have to release our reference to the destination node before the conte xt will ever be deleted since the destination node holds a reference to the cont ext. |
211 if (m_destinationNode) | 208 if (m_destinationNode) |
212 m_destinationNode.clear(); | 209 m_destinationNode.clear(); |
213 | 210 |
214 // Audio thread is dead. Nobody will schedule node deletion action. Let's do it ourselves. | 211 // Audio thread is dead. Nobody will schedule node deletion action. Let's do it ourselves. |
215 do { | 212 do { |
216 deleteMarkedNodes(); | 213 deleteMarkedNodes(); |
217 m_nodesToDelete.appendVector(m_nodesMarkedForDeletion); | 214 m_nodesToDelete.appendVector(m_nodesMarkedForDeletion); |
218 m_nodesMarkedForDeletion.clear(); | 215 m_nodesMarkedForDeletion.clear(); |
219 } while (m_nodesToDelete.size()); | 216 } while (m_nodesToDelete.size()); |
220 | |
221 // It was set in constructCommon. | |
222 unsetPendingActivity(this); | |
223 } | 217 } |
224 | 218 |
225 void AudioContext::uninitialize() | 219 void AudioContext::uninitialize() |
226 { | 220 { |
227 ASSERT(isMainThread()); | 221 ASSERT(isMainThread()); |
228 | 222 |
229 if (!m_isInitialized) | 223 if (!m_isInitialized) |
230 return; | 224 return; |
231 | 225 |
232 // This stops the audio thread and all audio rendering. | 226 // This stops the audio thread and all audio rendering. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 return; | 263 return; |
270 m_isStopScheduled = true; | 264 m_isStopScheduled = true; |
271 | 265 |
272 // Don't call uninitialize() immediately here because the ExecutionContext i s in the middle | 266 // Don't call uninitialize() immediately here because the ExecutionContext i s in the middle |
273 // of dealing with all of its ActiveDOMObjects at this point. uninitialize() can de-reference other | 267 // of dealing with all of its ActiveDOMObjects at this point. uninitialize() can de-reference other |
274 // ActiveDOMObjects so let's schedule uninitialize() to be called later. | 268 // ActiveDOMObjects so let's schedule uninitialize() to be called later. |
275 // FIXME: see if there's a more direct way to handle this issue. | 269 // FIXME: see if there's a more direct way to handle this issue. |
276 callOnMainThread(stopDispatch, this); | 270 callOnMainThread(stopDispatch, this); |
277 } | 271 } |
278 | 272 |
273 bool AudioContext::hasPendingActivity() const | |
274 { | |
275 // According to spec AudioContext must die only after page navigate. | |
276 return executionContext()->activeDOMObjectsAreStopped(); | |
kouhei (in TOK)
2014/03/21 16:32:40
Sorry this must be the opposite!
| |
277 } | |
278 | |
279 PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, si ze_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) | 279 PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, si ze_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) |
280 { | 280 { |
281 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::create(numberOfChannels, numb erOfFrames, sampleRate); | 281 RefPtr<AudioBuffer> audioBuffer = AudioBuffer::create(numberOfChannels, numb erOfFrames, sampleRate); |
282 if (!audioBuffer.get()) { | 282 if (!audioBuffer.get()) { |
283 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { | 283 if (numberOfChannels > AudioContext::maxNumberOfChannels()) { |
284 exceptionState.throwDOMException( | 284 exceptionState.throwDOMException( |
285 NotSupportedError, | 285 NotSupportedError, |
286 "requested number of channels (" + String::number(numberOfChanne ls) + ") exceeds maximum (" + String::number(AudioContext::maxNumberOfChannels() ) + ")"); | 286 "requested number of channels (" + String::number(numberOfChanne ls) + ") exceeds maximum (" + String::number(AudioContext::maxNumberOfChannels() ) + ")"); |
287 } else if (sampleRate < AudioBuffer::minAllowedSampleRate() || sampleRat e > AudioBuffer::maxAllowedSampleRate()) { | 287 } else if (sampleRate < AudioBuffer::minAllowedSampleRate() || sampleRat e > AudioBuffer::maxAllowedSampleRate()) { |
288 exceptionState.throwDOMException( | 288 exceptionState.throwDOMException( |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1039 } | 1039 } |
1040 | 1040 |
1041 void AudioContext::decrementActiveSourceCount() | 1041 void AudioContext::decrementActiveSourceCount() |
1042 { | 1042 { |
1043 atomicDecrement(&m_activeSourceCount); | 1043 atomicDecrement(&m_activeSourceCount); |
1044 } | 1044 } |
1045 | 1045 |
1046 } // namespace WebCore | 1046 } // namespace WebCore |
1047 | 1047 |
1048 #endif // ENABLE(WEB_AUDIO) | 1048 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |