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

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: Moved FillRenderEndpointBufferWithSilence to CoreAudioUtil 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // The sizes here were determined by experimentation and are roughly 249 // The sizes here were determined by experimentation and are roughly
250 // the lowest value (for low latency) that still allowed glitch-free 250 // the lowest value (for low latency) that still allowed glitch-free
251 // audio under high loads. 251 // audio under high loads.
252 // 252 //
253 // For Mac OS X and Windows the chromium audio backend uses a low-latency 253 // For Mac OS X and Windows the chromium audio backend uses a low-latency
254 // Core Audio API, so a low buffer size is possible. For Linux, further 254 // Core Audio API, so a low buffer size is possible. For Linux, further
255 // tuning may be needed. 255 // tuning may be needed.
256 #if defined(OS_MACOSX) 256 #if defined(OS_MACOSX)
257 return 128; 257 return 128;
258 #elif defined(OS_WIN) 258 #elif defined(OS_WIN)
259 // TODO(henrika): resolve conflict with GetUserBufferSize().
260 // If the user tries to set a buffer size using GetUserBufferSize() it will
261 // most likely fail since only the native/perfect buffer size is allowed.
262
259 // Buffer size to use when a proper size can't be determined from the system. 263 // Buffer size to use when a proper size can't be determined from the system.
260 static const int kFallbackBufferSize = 4096; 264 static const int kFallbackBufferSize = 4096;
261 265
262 if (!CoreAudioUtil::IsSupported()) { 266 if (!CoreAudioUtil::IsSupported()) {
263 // Fall back to Windows Wave implementation on Windows XP or lower 267 // Fall back to Windows Wave implementation on Windows XP or lower
264 // and assume 48kHz as default sample rate. 268 // and assume 48kHz as default sample rate.
265 return kFallbackBufferSize; 269 return kFallbackBufferSize;
266 } 270 }
267 271
268 // TODO(crogers): tune this size to best possible WebAudio performance. 272 // TODO(crogers): tune this size to best possible WebAudio performance.
269 // WebRTC always uses 10ms for Windows and does not call this method. 273 // WebRTC always uses 10ms for Windows and does not call this method.
270 // Note that exclusive mode is experimental. 274 // Note that exclusive mode is experimental.
271 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 275 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
272 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { 276 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
273 return 256; 277 return 256;
274 } 278 }
275 279
276 // TODO(henrika): remove when the --enable-webaudio-input flag is no longer 280 AudioParameters params;
277 // utilized. 281 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole,
278 if (cmd_line->HasSwitch(switches::kEnableWebAudioInput)) { 282 &params);
279 AudioParameters params; 283 return FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer();
280 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole,
281 &params);
282 return FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer();
283 }
284
285 // This call must be done on a COM thread configured as MTA.
286 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835.
287 int mixing_sample_rate =
288 WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
289
290 // Windows will return a sample rate of 0 when no audio output is available
291 // (i.e. via RemoteDesktop with remote audio disabled), but we should never
292 // return a buffer size of zero.
293 if (mixing_sample_rate == 0)
294 return kFallbackBufferSize;
295
296 // Use different buffer sizes depening on the sample rate . The existing
297 // WASAPI implementation is tuned to provide the most stable callback
298 // sequence using these combinations.
299 if (mixing_sample_rate % 11025 == 0)
300 // Use buffer size of ~10.15873 ms.
301 return (112 * (mixing_sample_rate / 11025));
302
303 if (mixing_sample_rate % 8000 == 0)
304 // Use buffer size of 10ms.
305 return (80 * (mixing_sample_rate / 8000));
306
307 // Ensure we always return a buffer size which is somewhat appropriate.
308 LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected.";
309 if (mixing_sample_rate > limits::kMinSampleRate)
310 return (mixing_sample_rate / 100);
311 return kFallbackBufferSize;
312 #else 284 #else
313 return 2048; 285 return 2048;
314 #endif 286 #endif
315 } 287 }
316 288
317 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { 289 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) {
318 // TODO(henrika): add support for device selection on all platforms. 290 // TODO(henrika): add support for device selection on all platforms.
319 // Only exists on Windows today. 291 // Only exists on Windows today.
320 #if defined(OS_MACOSX) 292 #if defined(OS_MACOSX)
321 return CHANNEL_LAYOUT_MONO; 293 return CHANNEL_LAYOUT_MONO;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // out performance was degraded compared to XP. 348 // out performance was degraded compared to XP.
377 // - The regression was fixed in Windows 7 and most configurations will work 349 // - The regression was fixed in Windows 7 and most configurations will work
378 // with 2, but some (e.g., some Sound Blasters) still need 3. 350 // with 2, but some (e.g., some Sound Blasters) still need 3.
379 // - Some XP configurations (even multi-processor ones) also need 3. 351 // - Some XP configurations (even multi-processor ones) also need 3.
380 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 352 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
381 } 353 }
382 354
383 #endif 355 #endif
384 356
385 } // namespace media 357 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698