| 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 920678225ca55b9c22d8908fa4de6b3d7bce0f17..793180995559f5ad443652ce4be61f74f1b88074 100644
|
| --- a/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp
|
| +++ b/third_party/WebKit/Source/modules/webaudio/AudioContext.cpp
|
| @@ -11,8 +11,10 @@
|
| #include "core/dom/ExceptionCode.h"
|
| #include "core/frame/UseCounter.h"
|
| #include "modules/webaudio/AudioBufferCallback.h"
|
| +#include "modules/webaudio/AudioContextOptions.h"
|
| #include "platform/Histogram.h"
|
| #include "platform/audio/AudioUtilities.h"
|
| +#include "public/platform/WebAudioLatencyHint.h"
|
|
|
| #if DEBUG_AUDIONODE_REFERENCES
|
| #include <stdio.h>
|
| @@ -20,6 +22,25 @@
|
|
|
| namespace blink {
|
|
|
| +namespace {
|
| +
|
| +WebAudioLatencyHint::Category LatencyHintCategoryFromString(String category) {
|
| + WebAudioLatencyHint::Category latencyCategory;
|
| + if (category == "interactive") {
|
| + latencyCategory = WebAudioLatencyHint::CategoryInteractive;
|
| + } else if (category == "balanced") {
|
| + latencyCategory = WebAudioLatencyHint::CategoryBalanced;
|
| + } else if (category == "playback") {
|
| + latencyCategory = WebAudioLatencyHint::CategoryPlayback;
|
| + } else {
|
| + NOTREACHED();
|
| + latencyCategory = WebAudioLatencyHint::CategoryInteractive;
|
| + }
|
| + return latencyCategory;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // Don't allow more than this number of simultaneous AudioContexts
|
| // talking to hardware.
|
| const unsigned MaxHardwareContexts = 6;
|
| @@ -27,6 +48,21 @@ static unsigned s_hardwareContextCount = 0;
|
| static unsigned s_contextId = 0;
|
|
|
| AudioContext* AudioContext::create(Document& document,
|
| + const AudioContextOptions& contextOptions,
|
| + ExceptionState& exceptionState) {
|
| + WebAudioLatencyHint::Category latencyCategory =
|
| + WebAudioLatencyHint::CategoryInteractive;
|
| + if (contextOptions.latencyHint().isAudioContextLatencyCategory()) {
|
| + latencyCategory = LatencyHintCategoryFromString(
|
| + contextOptions.latencyHint().getAsAudioContextLatencyCategory());
|
| + }
|
| + // TODO: add support for latencyHint().isDouble()
|
| +
|
| + return AudioContext::create(document, latencyCategory, exceptionState);
|
| +}
|
| +
|
| +AudioContext* AudioContext::create(Document& document,
|
| + const WebAudioLatencyHint& latencyHint,
|
| ExceptionState& exceptionState) {
|
| DCHECK(isMainThread());
|
|
|
| @@ -41,7 +77,7 @@ AudioContext* AudioContext::create(Document& document,
|
| return nullptr;
|
| }
|
|
|
| - AudioContext* audioContext = new AudioContext(document);
|
| + AudioContext* audioContext = new AudioContext(document, latencyHint);
|
| audioContext->suspendIfNeeded();
|
|
|
| if (!AudioUtilities::isValidAudioBufferSampleRate(
|
| @@ -83,8 +119,9 @@ AudioContext* AudioContext::create(Document& document,
|
| return audioContext;
|
| }
|
|
|
| -AudioContext::AudioContext(Document& document)
|
| - : BaseAudioContext(&document), m_contextId(s_contextId++) {}
|
| +AudioContext::AudioContext(Document& document,
|
| + const WebAudioLatencyHint& latencyHint)
|
| + : BaseAudioContext(&document, latencyHint), m_contextId(s_contextId++) {}
|
|
|
| AudioContext::~AudioContext() {
|
| #if DEBUG_AUDIONODE_REFERENCES
|
| @@ -205,4 +242,8 @@ void AudioContext::stopRendering() {
|
| }
|
| }
|
|
|
| +double AudioContext::baseLatency() const {
|
| + return framesPerBuffer() * 2 / static_cast<double>(sampleRate());
|
| +}
|
| +
|
| } // namespace blink
|
|
|