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

Side by Side Diff: media/audio/audio_util.cc

Issue 12049070: Avoids irregular OnMoreData callbacks on Windows using Core Audio (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Non trivial rebase Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Software adjust volume of samples, allows each audio stream its own 5 // Software adjust volume of samples, allows each audio stream its own
6 // volume without impacting master volume for chrome and other applications. 6 // volume without impacting master volume for chrome and other applications.
7 7
8 // Implemented as templates to allow 8, 16 and 32 bit implementations. 8 // Implemented as templates to allow 8, 16 and 32 bit implementations.
9 // 8 bit is unsigned and biased by 128. 9 // 8 bit is unsigned and biased by 128.
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 125 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
126 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { 126 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
127 // This sample rate will be combined with a buffer size of 256 samples 127 // This sample rate will be combined with a buffer size of 256 samples
128 // (see GetAudioHardwareBufferSize()), which corresponds to an output 128 // (see GetAudioHardwareBufferSize()), which corresponds to an output
129 // delay of ~5.33ms. 129 // delay of ~5.33ms.
130 return 48000; 130 return 48000;
131 } 131 }
132 132
133 // Hardware sample-rate on Windows can be configured, so we must query. 133 // Hardware sample-rate on Windows can be configured, so we must query.
134 // TODO(henrika): improve possibility to specify an audio endpoint. 134 // TODO(henrika): improve possibility to specify an audio endpoint.
135 // Use the default device (same as for Wave) for now to be compatible 135 // Use the default device (same as for Wave) for now to be compatible.
136 // or possibly remove the ERole argument completely until it is in use. 136 return WASAPIAudioOutputStream::HardwareSampleRate();
137 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
138 #elif defined(OS_ANDROID) 137 #elif defined(OS_ANDROID)
139 return 16000; 138 return 16000;
140 #else 139 #else
141 // Hardware for Linux is nearly always 48KHz. 140 // Hardware for Linux is nearly always 48KHz.
142 // TODO(crogers) : return correct value in rare non-48KHz cases. 141 // TODO(crogers) : return correct value in rare non-48KHz cases.
143 return 48000; 142 return 48000;
144 #endif 143 #endif
145 } 144 }
146 145
147 int GetAudioInputHardwareSampleRate(const std::string& device_id) { 146 int GetAudioInputHardwareSampleRate(const std::string& device_id) {
(...skipping 21 matching lines...) Expand all
169 // The sizes here were determined by experimentation and are roughly 168 // The sizes here were determined by experimentation and are roughly
170 // the lowest value (for low latency) that still allowed glitch-free 169 // the lowest value (for low latency) that still allowed glitch-free
171 // audio under high loads. 170 // audio under high loads.
172 // 171 //
173 // For Mac OS X and Windows the chromium audio backend uses a low-latency 172 // For Mac OS X and Windows the chromium audio backend uses a low-latency
174 // Core Audio API, so a low buffer size is possible. For Linux, further 173 // Core Audio API, so a low buffer size is possible. For Linux, further
175 // tuning may be needed. 174 // tuning may be needed.
176 #if defined(OS_MACOSX) 175 #if defined(OS_MACOSX)
177 return 128; 176 return 128;
178 #elif defined(OS_WIN) 177 #elif defined(OS_WIN)
178 // TODO(henrika): resolve conflict with GetUserBufferSize().
179 // If the user tries to set a buffer size using GetUserBufferSize() it will
180 // most likely fail since only the native/perfect buffer size is allowed.
181
179 // Buffer size to use when a proper size can't be determined from the system. 182 // Buffer size to use when a proper size can't be determined from the system.
180 static const int kFallbackBufferSize = 2048; 183 static const int kFallbackBufferSize = 4096;
DaleCurtis 2013/02/02 00:19:51 I just changed this to 2048 in https://codereview.
henrika (OOO until Aug 14) 2013/02/04 08:25:38 Cool. I will of course not mess that up. Now using
181 184
182 if (!CoreAudioUtil::IsSupported()) { 185 if (!CoreAudioUtil::IsSupported()) {
183 // Fall back to Windows Wave implementation on Windows XP or lower 186 // Fall back to Windows Wave implementation on Windows XP or lower
184 // and assume 48kHz as default sample rate. 187 // and assume 48kHz as default sample rate.
185 return kFallbackBufferSize; 188 return kFallbackBufferSize;
186 } 189 }
187 190
188 // TODO(crogers): tune this size to best possible WebAudio performance. 191 // TODO(crogers): tune this size to best possible WebAudio performance.
189 // WebRTC always uses 10ms for Windows and does not call this method. 192 // WebRTC always uses 10ms for Windows and does not call this method.
190 // Note that exclusive mode is experimental. 193 // Note that exclusive mode is experimental.
191 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 194 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
192 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { 195 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
193 return 256; 196 return 256;
194 } 197 }
195 198
196 // TODO(henrika): remove when the --enable-webaudio-input flag is no longer 199 AudioParameters params;
197 // utilized. 200 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole,
198 if (cmd_line->HasSwitch(switches::kEnableWebAudioInput)) { 201 &params);
199 AudioParameters params; 202 return FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer();
200 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole,
201 &params);
202 return FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer();
203 }
204
205 // This call must be done on a COM thread configured as MTA.
206 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835.
207 int mixing_sample_rate =
208 WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
209
210 // Windows will return a sample rate of 0 when no audio output is available
211 // (i.e. via RemoteDesktop with remote audio disabled), but we should never
212 // return a buffer size of zero.
213 if (mixing_sample_rate == 0)
214 return kFallbackBufferSize;
215
216 // Use different buffer sizes depening on the sample rate . The existing
217 // WASAPI implementation is tuned to provide the most stable callback
218 // sequence using these combinations.
219 if (mixing_sample_rate % 11025 == 0)
220 // Use buffer size of ~10.15873 ms.
221 return (112 * (mixing_sample_rate / 11025));
222
223 if (mixing_sample_rate % 8000 == 0)
224 // Use buffer size of 10ms.
225 return (80 * (mixing_sample_rate / 8000));
226
227 // Ensure we always return a buffer size which is somewhat appropriate.
228 LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected.";
229 if (mixing_sample_rate > limits::kMinSampleRate)
230 return (mixing_sample_rate / 100);
231 return kFallbackBufferSize;
232 #else 203 #else
233 return 2048; 204 return 2048;
234 #endif 205 #endif
235 } 206 }
236 207
237 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { 208 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) {
238 // TODO(henrika): add support for device selection on all platforms. 209 // TODO(henrika): add support for device selection on all platforms.
239 // Only exists on Windows today. 210 // Only exists on Windows today.
240 #if defined(OS_MACOSX) 211 #if defined(OS_MACOSX)
241 return CHANNEL_LAYOUT_MONO; 212 return CHANNEL_LAYOUT_MONO;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // out performance was degraded compared to XP. 267 // out performance was degraded compared to XP.
297 // - The regression was fixed in Windows 7 and most configurations will work 268 // - The regression was fixed in Windows 7 and most configurations will work
298 // with 2, but some (e.g., some Sound Blasters) still need 3. 269 // with 2, but some (e.g., some Sound Blasters) still need 3.
299 // - Some XP configurations (even multi-processor ones) also need 3. 270 // - Some XP configurations (even multi-processor ones) also need 3.
300 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 271 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
301 } 272 }
302 273
303 #endif 274 #endif
304 275
305 } // namespace media 276 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698