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

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

Issue 2501863003: Support for AudioContextOptions latencyHint. (Closed)
Patch Set: Fixes to WebAudioDeviceImpl unit test. Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #include "modules/webaudio/DefaultAudioDestinationNode.h" 26 #include "modules/webaudio/DefaultAudioDestinationNode.h"
27 #include "bindings/core/v8/ExceptionMessages.h" 27 #include "bindings/core/v8/ExceptionMessages.h"
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "core/dom/ExceptionCode.h" 29 #include "core/dom/ExceptionCode.h"
30 #include "modules/webaudio/BaseAudioContext.h" 30 #include "modules/webaudio/BaseAudioContext.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 DefaultAudioDestinationHandler::DefaultAudioDestinationHandler(AudioNode& node) 34 DefaultAudioDestinationHandler::DefaultAudioDestinationHandler(
35 : AudioDestinationHandler(node, AudioDestination::hardwareSampleRate()), 35 AudioNode& node,
36 m_numberOfInputChannels(0) { 36 const WebAudioLatencyHint& latencyHint)
37 : AudioDestinationHandler(node),
38 m_numberOfInputChannels(0),
39 m_latencyHint(latencyHint) {
37 // Node-specific default mixing rules. 40 // Node-specific default mixing rules.
38 m_channelCount = 2; 41 m_channelCount = 2;
39 setInternalChannelCountMode(Explicit); 42 setInternalChannelCountMode(Explicit);
40 setInternalChannelInterpretation(AudioBus::Speakers); 43 setInternalChannelInterpretation(AudioBus::Speakers);
41 } 44 }
42 45
43 PassRefPtr<DefaultAudioDestinationHandler> 46 PassRefPtr<DefaultAudioDestinationHandler>
44 DefaultAudioDestinationHandler::create(AudioNode& node) { 47 DefaultAudioDestinationHandler::create(AudioNode& node,
45 return adoptRef(new DefaultAudioDestinationHandler(node)); 48 const WebAudioLatencyHint& latencyHint) {
49 return adoptRef(new DefaultAudioDestinationHandler(node, latencyHint));
46 } 50 }
47 51
48 DefaultAudioDestinationHandler::~DefaultAudioDestinationHandler() { 52 DefaultAudioDestinationHandler::~DefaultAudioDestinationHandler() {
49 DCHECK(!isInitialized()); 53 DCHECK(!isInitialized());
50 } 54 }
51 55
52 void DefaultAudioDestinationHandler::dispose() { 56 void DefaultAudioDestinationHandler::dispose() {
53 uninitialize(); 57 uninitialize();
54 AudioDestinationHandler::dispose(); 58 AudioDestinationHandler::dispose();
55 } 59 }
(...skipping 12 matching lines...) Expand all
68 if (!isInitialized()) 72 if (!isInitialized())
69 return; 73 return;
70 74
71 m_destination->stop(); 75 m_destination->stop();
72 m_numberOfInputChannels = 0; 76 m_numberOfInputChannels = 0;
73 77
74 AudioHandler::uninitialize(); 78 AudioHandler::uninitialize();
75 } 79 }
76 80
77 void DefaultAudioDestinationHandler::createDestination() { 81 void DefaultAudioDestinationHandler::createDestination() {
78 float hardwareSampleRate = AudioDestination::hardwareSampleRate(); 82 m_destination = AudioDestination::create(*this, channelCount(), m_latencyHint,
79 VLOG(1) << ">>>> hardwareSampleRate = " << hardwareSampleRate; 83 context()->getSecurityOrigin());
80
81 m_destination =
82 AudioDestination::create(*this, channelCount(), hardwareSampleRate,
83 context()->getSecurityOrigin());
84 } 84 }
85 85
86 void DefaultAudioDestinationHandler::startRendering() { 86 void DefaultAudioDestinationHandler::startRendering() {
87 DCHECK(isInitialized()); 87 DCHECK(isInitialized());
88 if (isInitialized()) { 88 if (isInitialized()) {
89 DCHECK(!m_destination->isPlaying()); 89 DCHECK(!m_destination->isPlaying());
90 m_destination->start(); 90 m_destination->start();
91 } 91 }
92 } 92 }
93 93
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 if (!exceptionState.hadException() && 131 if (!exceptionState.hadException() &&
132 this->channelCount() != oldChannelCount && isInitialized()) { 132 this->channelCount() != oldChannelCount && isInitialized()) {
133 // Re-create destination. 133 // Re-create destination.
134 m_destination->stop(); 134 m_destination->stop();
135 createDestination(); 135 createDestination();
136 m_destination->start(); 136 m_destination->start();
137 } 137 }
138 } 138 }
139 139
140 double DefaultAudioDestinationHandler::sampleRate() const {
141 return m_destination ? m_destination->sampleRate() : 0;
142 }
143
144 int DefaultAudioDestinationHandler::framesPerBuffer() const {
145 return m_destination ? m_destination->framesPerBuffer() : 0;
146 }
147
140 // ---------------------------------------------------------------- 148 // ----------------------------------------------------------------
141 149
142 DefaultAudioDestinationNode::DefaultAudioDestinationNode( 150 DefaultAudioDestinationNode::DefaultAudioDestinationNode(
143 BaseAudioContext& context) 151 BaseAudioContext& context,
152 const WebAudioLatencyHint& latencyHint)
144 : AudioDestinationNode(context) { 153 : AudioDestinationNode(context) {
145 setHandler(DefaultAudioDestinationHandler::create(*this)); 154 setHandler(DefaultAudioDestinationHandler::create(*this, latencyHint));
146 } 155 }
147 156
148 DefaultAudioDestinationNode* DefaultAudioDestinationNode::create( 157 DefaultAudioDestinationNode* DefaultAudioDestinationNode::create(
149 BaseAudioContext* context) { 158 BaseAudioContext* context,
150 return new DefaultAudioDestinationNode(*context); 159 const WebAudioLatencyHint& latencyHint) {
160 return new DefaultAudioDestinationNode(*context, latencyHint);
151 } 161 }
152 162
153 } // namespace blink 163 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698