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

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

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Add baseLatency and fix use of hardwareSampleRate. 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/UseCounter.h" 12 #include "core/frame/UseCounter.h"
13 #include "modules/webaudio/AudioBufferCallback.h" 13 #include "modules/webaudio/AudioBufferCallback.h"
14 #include "modules/webaudio/AudioContextOptions.h"
14 #include "platform/Histogram.h" 15 #include "platform/Histogram.h"
15 #include "platform/audio/AudioUtilities.h" 16 #include "platform/audio/AudioUtilities.h"
17 #include "public/platform/WebAudioLatencyHint.h"
16 18
17 #if DEBUG_AUDIONODE_REFERENCES 19 #if DEBUG_AUDIONODE_REFERENCES
18 #include <stdio.h> 20 #include <stdio.h>
19 #endif 21 #endif
20 22
21 namespace blink { 23 namespace blink {
22 24
23 // Don't allow more than this number of simultaneous AudioContexts 25 // Don't allow more than this number of simultaneous AudioContexts
24 // talking to hardware. 26 // talking to hardware.
25 const unsigned MaxHardwareContexts = 6; 27 const unsigned MaxHardwareContexts = 6;
26 static unsigned s_hardwareContextCount = 0; 28 static unsigned s_hardwareContextCount = 0;
27 static unsigned s_contextId = 0; 29 static unsigned s_contextId = 0;
28 30
29 AudioContext* AudioContext::create(Document& document, 31 AudioContext* AudioContext::create(Document& document,
32 const AudioContextOptions& contextOptions,
33 ExceptionState& exceptionState) {
34 WebAudioLatencyHint::Category latencyCategory;
o1ka 2016/11/30 11:46:26 This code looks like it worth a helper function.
Andrew MacPherson 2016/12/01 12:11:56 Done.
35 if (contextOptions.latencyHint() == "interactive") {
36 latencyCategory = WebAudioLatencyHint::CategoryInteractive;
37 } else if (contextOptions.latencyHint() == "balanced") {
38 latencyCategory = WebAudioLatencyHint::CategoryBalanced;
39 } else if (contextOptions.latencyHint() == "playback") {
40 latencyCategory = WebAudioLatencyHint::CategoryPlayback;
41 } else {
42 NOTREACHED();
43 latencyCategory = WebAudioLatencyHint::CategoryInteractive;
44 }
45
46 WebAudioLatencyHint latencyHint(latencyCategory);
o1ka 2016/11/30 11:46:26 Why do you need a local for that?
Andrew MacPherson 2016/12/01 12:11:56 That was a mistake but based on rtoy@'s suggestion
47 return AudioContext::create(document, latencyHint, exceptionState);
48 }
49
50 AudioContext* AudioContext::create(Document& document,
51 const WebAudioLatencyHint& latencyHint,
30 ExceptionState& exceptionState) { 52 ExceptionState& exceptionState) {
31 DCHECK(isMainThread()); 53 DCHECK(isMainThread());
32 54
33 UseCounter::countCrossOriginIframe(document, 55 UseCounter::countCrossOriginIframe(document,
34 UseCounter::AudioContextCrossOriginIframe); 56 UseCounter::AudioContextCrossOriginIframe);
35 57
36 if (s_hardwareContextCount >= MaxHardwareContexts) { 58 if (s_hardwareContextCount >= MaxHardwareContexts) {
37 exceptionState.throwDOMException( 59 exceptionState.throwDOMException(
38 NotSupportedError, ExceptionMessages::indexExceedsMaximumBound( 60 NotSupportedError, ExceptionMessages::indexExceedsMaximumBound(
39 "number of hardware contexts", 61 "number of hardware contexts",
40 s_hardwareContextCount, MaxHardwareContexts)); 62 s_hardwareContextCount, MaxHardwareContexts));
41 return nullptr; 63 return nullptr;
42 } 64 }
43 65
44 AudioContext* audioContext = new AudioContext(document); 66 AudioContext* audioContext = new AudioContext(document, latencyHint);
45 audioContext->suspendIfNeeded(); 67 audioContext->suspendIfNeeded();
46 68
47 if (!AudioUtilities::isValidAudioBufferSampleRate( 69 if (!AudioUtilities::isValidAudioBufferSampleRate(
48 audioContext->sampleRate())) { 70 audioContext->sampleRate())) {
49 exceptionState.throwDOMException( 71 exceptionState.throwDOMException(
50 NotSupportedError, 72 NotSupportedError,
51 ExceptionMessages::indexOutsideRange( 73 ExceptionMessages::indexOutsideRange(
52 "hardware sample rate", audioContext->sampleRate(), 74 "hardware sample rate", audioContext->sampleRate(),
53 AudioUtilities::minAudioBufferSampleRate(), 75 AudioUtilities::minAudioBufferSampleRate(),
54 ExceptionMessages::InclusiveBound, 76 ExceptionMessages::InclusiveBound,
(...skipping 21 matching lines...) Expand all
76 ("WebAudio.AudioContext.MaxChannelsAvailable")); 98 ("WebAudio.AudioContext.MaxChannelsAvailable"));
77 DEFINE_STATIC_LOCAL(SparseHistogram, sampleRateHistogram, 99 DEFINE_STATIC_LOCAL(SparseHistogram, sampleRateHistogram,
78 ("WebAudio.AudioContext.HardwareSampleRate")); 100 ("WebAudio.AudioContext.HardwareSampleRate"));
79 maxChannelCountHistogram.sample( 101 maxChannelCountHistogram.sample(
80 audioContext->destination()->maxChannelCount()); 102 audioContext->destination()->maxChannelCount());
81 sampleRateHistogram.sample(audioContext->sampleRate()); 103 sampleRateHistogram.sample(audioContext->sampleRate());
82 104
83 return audioContext; 105 return audioContext;
84 } 106 }
85 107
86 AudioContext::AudioContext(Document& document) 108 AudioContext::AudioContext(Document& document,
87 : BaseAudioContext(&document), m_contextId(s_contextId++) {} 109 const WebAudioLatencyHint& latencyHint)
110 : BaseAudioContext(&document, latencyHint), m_contextId(s_contextId++) {}
88 111
89 AudioContext::~AudioContext() { 112 AudioContext::~AudioContext() {
90 #if DEBUG_AUDIONODE_REFERENCES 113 #if DEBUG_AUDIONODE_REFERENCES
91 fprintf(stderr, "[%16p]: AudioContext::~AudioContext(): %u\n", this, 114 fprintf(stderr, "[%16p]: AudioContext::~AudioContext(): %u\n", this,
92 m_contextId); 115 m_contextId);
93 #endif 116 #endif
94 } 117 }
95 118
96 DEFINE_TRACE(AudioContext) { 119 DEFINE_TRACE(AudioContext) {
97 visitor->trace(m_closeResolver); 120 visitor->trace(m_closeResolver);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 DCHECK(destination()); 222 DCHECK(destination());
200 223
201 if (contextState() == Running) { 224 if (contextState() == Running) {
202 destination()->audioDestinationHandler().stopRendering(); 225 destination()->audioDestinationHandler().stopRendering();
203 setContextState(Suspended); 226 setContextState(Suspended);
204 deferredTaskHandler().clearHandlersToBeDeleted(); 227 deferredTaskHandler().clearHandlersToBeDeleted();
205 } 228 }
206 } 229 }
207 230
208 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698