| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webaudio/AudioContext.h" | 5 #include "modules/webaudio/AudioContext.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 ExceptionMessages::InclusiveBound)); | 57 ExceptionMessages::InclusiveBound)); |
| 58 return audioContext; | 58 return audioContext; |
| 59 } | 59 } |
| 60 // This starts the audio thread. The destination node's | 60 // This starts the audio thread. The destination node's |
| 61 // provideInput() method will now be called repeatedly to render | 61 // provideInput() method will now be called repeatedly to render |
| 62 // audio. Each time provideInput() is called, a portion of the | 62 // audio. Each time provideInput() is called, a portion of the |
| 63 // audio stream is rendered. Let's call this time period a "render | 63 // audio stream is rendered. Let's call this time period a "render |
| 64 // quantum". NOTE: for now AudioContext does not need an explicit | 64 // quantum". NOTE: for now AudioContext does not need an explicit |
| 65 // startRendering() call from JavaScript. We may want to consider | 65 // startRendering() call from JavaScript. We may want to consider |
| 66 // requiring it for symmetry with OfflineAudioContext. | 66 // requiring it for symmetry with OfflineAudioContext. |
| 67 audioContext->startRendering(); | 67 audioContext->maybeUnlockUserGesture(); |
| 68 if (audioContext->isAllowedToStart()) |
| 69 audioContext->startRendering(); |
| 68 ++s_hardwareContextCount; | 70 ++s_hardwareContextCount; |
| 69 #if DEBUG_AUDIONODE_REFERENCES | 71 #if DEBUG_AUDIONODE_REFERENCES |
| 70 fprintf(stderr, "[%16p]: AudioContext::AudioContext(): %u #%u\n", | 72 fprintf(stderr, "[%16p]: AudioContext::AudioContext(): %u #%u\n", |
| 71 audioContext, audioContext->m_contextId, s_hardwareContextCount); | 73 audioContext, audioContext->m_contextId, s_hardwareContextCount); |
| 72 #endif | 74 #endif |
| 73 | 75 |
| 74 DEFINE_STATIC_LOCAL(SparseHistogram, maxChannelCountHistogram, | 76 DEFINE_STATIC_LOCAL(SparseHistogram, maxChannelCountHistogram, |
| 75 ("WebAudio.AudioContext.MaxChannelsAvailable")); | 77 ("WebAudio.AudioContext.MaxChannelsAvailable")); |
| 76 DEFINE_STATIC_LOCAL(SparseHistogram, sampleRateHistogram, | 78 DEFINE_STATIC_LOCAL(SparseHistogram, sampleRateHistogram, |
| 77 ("WebAudio.AudioContext.HardwareSampleRate")); | 79 ("WebAudio.AudioContext.HardwareSampleRate")); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 DCHECK(isMainThread()); | 131 DCHECK(isMainThread()); |
| 130 | 132 |
| 131 if (isContextClosed()) { | 133 if (isContextClosed()) { |
| 132 return ScriptPromise::rejectWithDOMException( | 134 return ScriptPromise::rejectWithDOMException( |
| 133 scriptState, | 135 scriptState, |
| 134 DOMException::create( | 136 DOMException::create( |
| 135 InvalidAccessError, | 137 InvalidAccessError, |
| 136 "cannot resume a closed AudioContext")); | 138 "cannot resume a closed AudioContext")); |
| 137 } | 139 } |
| 138 | 140 |
| 139 recordUserGestureState(); | |
| 140 | |
| 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 142 ScriptPromise promise = resolver->promise(); | 142 ScriptPromise promise = resolver->promise(); |
| 143 | 143 |
| 144 // Restart the destination node to pull on the audio graph. | 144 // Restart the destination node to pull on the audio graph. |
| 145 if (destination()) | 145 if (destination()) { |
| 146 startRendering(); | 146 maybeUnlockUserGesture(); |
| 147 if (isAllowedToStart()) |
| 148 startRendering(); |
| 149 } |
| 147 | 150 |
| 148 // Save the resolver which will get resolved when the destination node start
s pulling on the | 151 // Save the resolver which will get resolved when the destination node start
s pulling on the |
| 149 // graph again. | 152 // graph again. |
| 150 { | 153 { |
| 151 AutoLocker locker(this); | 154 AutoLocker locker(this); |
| 152 m_resumeResolvers.append(resolver); | 155 m_resumeResolvers.append(resolver); |
| 153 } | 156 } |
| 154 | 157 |
| 155 return promise; | 158 return promise; |
| 156 } | 159 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 DCHECK(destination()); | 208 DCHECK(destination()); |
| 206 | 209 |
| 207 if (contextState() == Running) { | 210 if (contextState() == Running) { |
| 208 destination()->audioDestinationHandler().stopRendering(); | 211 destination()->audioDestinationHandler().stopRendering(); |
| 209 setContextState(Suspended); | 212 setContextState(Suspended); |
| 210 deferredTaskHandler().clearHandlersToBeDeleted(); | 213 deferredTaskHandler().clearHandlersToBeDeleted(); |
| 211 } | 214 } |
| 212 } | 215 } |
| 213 | 216 |
| 214 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |