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

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

Issue 2060833002: Implementation of 'AudioContext.getOutputTimestamp' method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years 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
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"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/frame/LocalDOMWindow.h"
12 #include "core/frame/UseCounter.h" 13 #include "core/frame/UseCounter.h"
14 #include "core/timing/DOMWindowPerformance.h"
15 #include "core/timing/Performance.h"
13 #include "modules/webaudio/AudioBufferCallback.h" 16 #include "modules/webaudio/AudioBufferCallback.h"
17 #include "modules/webaudio/AudioTimestamp.h"
14 #include "platform/Histogram.h" 18 #include "platform/Histogram.h"
15 #include "platform/audio/AudioUtilities.h" 19 #include "platform/audio/AudioUtilities.h"
16 20
17 #if DEBUG_AUDIONODE_REFERENCES 21 #if DEBUG_AUDIONODE_REFERENCES
18 #include <stdio.h> 22 #include <stdio.h>
19 #endif 23 #endif
20 24
21 namespace blink { 25 namespace blink {
22 26
23 // Don't allow more than this number of simultaneous AudioContexts 27 // Don't allow more than this number of simultaneous AudioContexts
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // Save the resolver which will get resolved when the destination node starts 148 // Save the resolver which will get resolved when the destination node starts
145 // pulling on the graph again. 149 // pulling on the graph again.
146 { 150 {
147 AutoLocker locker(this); 151 AutoLocker locker(this);
148 m_resumeResolvers.append(resolver); 152 m_resumeResolvers.append(resolver);
149 } 153 }
150 154
151 return promise; 155 return promise;
152 } 156 }
153 157
158 void AudioContext::getOutputTimestamp(ScriptState* scriptState,
159 AudioTimestamp& result) {
160 DCHECK(isMainThread());
161 LocalDOMWindow* window = scriptState->domWindow();
162 if (!window)
163 return;
164
165 if (!destination()) {
166 result.setContextTime(0.0);
167 result.setPerformanceTime(0.0);
168 return;
169 }
170
171 Performance* performance = DOMWindowPerformance::performance(*window);
172 DCHECK(performance);
173
174 AudioIOPosition position = outputPosition();
175
176 double performanceTime =
177 performance->monotonicTimeToDOMHighResTimeStamp(position.timestamp);
178 if (performanceTime < 0.0)
179 performanceTime = 0.0;
180
181 result.setContextTime(position.position);
182 result.setPerformanceTime(performanceTime);
183 }
184
154 ScriptPromise AudioContext::closeContext(ScriptState* scriptState) { 185 ScriptPromise AudioContext::closeContext(ScriptState* scriptState) {
155 if (isContextClosed()) { 186 if (isContextClosed()) {
156 // We've already closed the context previously, but it hasn't yet been 187 // We've already closed the context previously, but it hasn't yet been
157 // resolved, so just create a new promise and reject it. 188 // resolved, so just create a new promise and reject it.
158 return ScriptPromise::rejectWithDOMException( 189 return ScriptPromise::rejectWithDOMException(
159 scriptState, 190 scriptState,
160 DOMException::create(InvalidStateError, 191 DOMException::create(InvalidStateError,
161 "Cannot close a context that is being closed or " 192 "Cannot close a context that is being closed or "
162 "has already been closed.")); 193 "has already been closed."));
163 } 194 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 DCHECK(destination()); 230 DCHECK(destination());
200 231
201 if (contextState() == Running) { 232 if (contextState() == Running) {
202 destination()->audioDestinationHandler().stopRendering(); 233 destination()->audioDestinationHandler().stopRendering();
203 setContextState(Suspended); 234 setContextState(Suspended);
204 deferredTaskHandler().clearHandlersToBeDeleted(); 235 deferredTaskHandler().clearHandlersToBeDeleted();
205 } 236 }
206 } 237 }
207 238
208 } // namespace blink 239 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioContext.h ('k') | third_party/WebKit/Source/modules/webaudio/AudioContext.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698