Index: third_party/WebKit/Source/modules/webaudio/AudioContext.cpp |
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp b/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp |
index f7cc9c928a7f3b814c40749e345b535337eaaf75..7a85589686fb1d1e2ad66e82365db7f7cf51ebb2 100644 |
--- a/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp |
+++ b/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp |
@@ -9,7 +9,11 @@ |
#include "bindings/core/v8/ScriptPromiseResolver.h" |
#include "core/dom/DOMException.h" |
#include "core/dom/ExceptionCode.h" |
+#include "core/frame/LocalDOMWindow.h" |
+#include "core/timing/DOMWindowPerformance.h" |
+#include "core/timing/Performance.h" |
#include "modules/webaudio/AudioBufferCallback.h" |
+#include "modules/webaudio/AudioTimestamp.h" |
#include "platform/Histogram.h" |
#include "platform/audio/AudioUtilities.h" |
@@ -80,6 +84,7 @@ AbstractAudioContext* AudioContext::create(Document& document, ExceptionState& e |
AudioContext::AudioContext(Document& document) |
: AbstractAudioContext(&document) |
, m_contextId(s_contextId++) |
+ , m_outputTimestampFramesOrigin(0) |
{ |
} |
@@ -138,8 +143,10 @@ ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) |
ScriptPromise promise = resolver->promise(); |
// Restart the destination node to pull on the audio graph. |
- if (destination()) |
+ if (destination()) { |
+ m_outputTimestampFramesOrigin = currentSampleFrame(); |
startRendering(); |
+ } |
// Save the resolver which will get resolved when the destination node starts pulling on the |
// graph again. |
@@ -151,6 +158,40 @@ ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) |
return promise; |
} |
+static double toPerformanceTime(ExecutionContext* context, double seconds) |
+{ |
+ if (!context) |
+ return 0.0; |
+ |
+ LocalDOMWindow* window = context->executingWindow(); |
+ if (!window) |
+ return 0.0; |
+ |
+ Performance* performance = DOMWindowPerformance::performance(*window); |
+ if (!performance) |
+ return 0.0; |
+ |
+ return performance->monotonicTimeToDOMHighResTimeStamp(seconds); |
+} |
+ |
+void AudioContext::getOutputTimestamp(AudioTimestamp& result) |
+{ |
+ DCHECK(isMainThread()); |
+ if (!destination()) { |
+ result.setContextTime(0.0); |
+ result.setPerformanceTime(0.0); |
+ return; |
+ } |
+ |
+ WebAudioTimestamp timestamp = outputTimestamp(); |
+ double sampleRate = destination()->audioDestinationHandler().sampleRate(); |
+ double contextTime = (m_outputTimestampFramesOrigin + timestamp.frames) / sampleRate; |
+ double performanceTime = timestamp.seconds ? toPerformanceTime(getExecutionContext(), timestamp.seconds) : 0.0; |
+ |
+ result.setContextTime(contextTime); |
+ result.setPerformanceTime(performanceTime); |
+} |
+ |
ScriptPromise AudioContext::closeContext(ScriptState* scriptState) |
{ |
if (isContextClosed()) { |