Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioContext.cpp

Issue 2717613007: Set "Running" state only when actually running (Closed)
Patch Set: State must be set AFTER startRendering(). Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/BaseAudioContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return audioContext; 72 return audioContext;
73 } 73 }
74 // This starts the audio thread. The destination node's 74 // This starts the audio thread. The destination node's
75 // provideInput() method will now be called repeatedly to render 75 // provideInput() method will now be called repeatedly to render
76 // audio. Each time provideInput() is called, a portion of the 76 // audio. Each time provideInput() is called, a portion of the
77 // audio stream is rendered. Let's call this time period a "render 77 // audio stream is rendered. Let's call this time period a "render
78 // quantum". NOTE: for now AudioContext does not need an explicit 78 // quantum". NOTE: for now AudioContext does not need an explicit
79 // startRendering() call from JavaScript. We may want to consider 79 // startRendering() call from JavaScript. We may want to consider
80 // requiring it for symmetry with OfflineAudioContext. 80 // requiring it for symmetry with OfflineAudioContext.
81 audioContext->maybeUnlockUserGesture(); 81 audioContext->maybeUnlockUserGesture();
82 if (audioContext->isAllowedToStart()) 82 if (audioContext->isAllowedToStart()) {
83 audioContext->startRendering(); 83 audioContext->startRendering();
84 audioContext->setContextState(Running);
85 }
84 ++s_hardwareContextCount; 86 ++s_hardwareContextCount;
85 #if DEBUG_AUDIONODE_REFERENCES 87 #if DEBUG_AUDIONODE_REFERENCES
86 fprintf(stderr, "[%16p]: AudioContext::AudioContext(): %u #%u\n", 88 fprintf(stderr, "[%16p]: AudioContext::AudioContext(): %u #%u\n",
87 audioContext, audioContext->m_contextId, s_hardwareContextCount); 89 audioContext, audioContext->m_contextId, s_hardwareContextCount);
88 #endif 90 #endif
89 91
90 DEFINE_STATIC_LOCAL(SparseHistogram, maxChannelCountHistogram, 92 DEFINE_STATIC_LOCAL(SparseHistogram, maxChannelCountHistogram,
91 ("WebAudio.AudioContext.MaxChannelsAvailable")); 93 ("WebAudio.AudioContext.MaxChannelsAvailable"));
92 DEFINE_STATIC_LOCAL(SparseHistogram, sampleRateHistogram, 94 DEFINE_STATIC_LOCAL(SparseHistogram, sampleRateHistogram,
93 ("WebAudio.AudioContext.HardwareSampleRate")); 95 ("WebAudio.AudioContext.HardwareSampleRate"));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 DOMException::create(InvalidAccessError, 151 DOMException::create(InvalidAccessError,
150 "cannot resume a closed AudioContext")); 152 "cannot resume a closed AudioContext"));
151 } 153 }
152 154
153 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 155 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
154 ScriptPromise promise = resolver->promise(); 156 ScriptPromise promise = resolver->promise();
155 157
156 // Restart the destination node to pull on the audio graph. 158 // Restart the destination node to pull on the audio graph.
157 if (destination()) { 159 if (destination()) {
158 maybeUnlockUserGesture(); 160 maybeUnlockUserGesture();
159 if (isAllowedToStart()) 161 if (isAllowedToStart()) {
162 // Do not set the state to running here. We wait for the
163 // destination to start to set the state.
160 startRendering(); 164 startRendering();
165 }
161 } 166 }
162 167
163 // Save the resolver which will get resolved when the destination node starts 168 // Save the resolver which will get resolved when the destination node starts
164 // pulling on the graph again. 169 // pulling on the graph again.
165 { 170 {
166 AutoLocker locker(this); 171 AutoLocker locker(this);
167 m_resumeResolvers.push_back(resolver); 172 m_resumeResolvers.push_back(resolver);
168 } 173 }
169 174
170 return promise; 175 return promise;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 setContextState(Suspended); 254 setContextState(Suspended);
250 deferredTaskHandler().clearHandlersToBeDeleted(); 255 deferredTaskHandler().clearHandlersToBeDeleted();
251 } 256 }
252 } 257 }
253 258
254 double AudioContext::baseLatency() const { 259 double AudioContext::baseLatency() const {
255 return framesPerBuffer() * 2 / static_cast<double>(sampleRate()); 260 return framesPerBuffer() * 2 / static_cast<double>(sampleRate());
256 } 261 }
257 262
258 } // namespace blink 263 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/BaseAudioContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698