OLD | NEW |
---|---|
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 } | 235 } |
236 return WASAPIAudioInputStream::HardwareSampleRate(device_id); | 236 return WASAPIAudioInputStream::HardwareSampleRate(device_id); |
237 #elif defined(OS_ANDROID) | 237 #elif defined(OS_ANDROID) |
238 return 16000; | 238 return 16000; |
239 #else | 239 #else |
240 return 48000; | 240 return 48000; |
241 #endif | 241 #endif |
242 } | 242 } |
243 | 243 |
244 size_t GetAudioHardwareBufferSize() { | 244 size_t GetAudioHardwareBufferSize() { |
245 // TODO(henrika): resolve conflict on Windows where we today only allow | |
tommi (sloooow) - chröme
2013/01/31 13:42:08
Move this todo into the OS_WIN section?
Also, can
henrika (OOO until Aug 14)
2013/01/31 14:29:38
Done.
| |
246 // the native buffer size. | |
245 int user_buffer_size = GetUserBufferSize(); | 247 int user_buffer_size = GetUserBufferSize(); |
246 if (user_buffer_size) | 248 if (user_buffer_size) |
247 return user_buffer_size; | 249 return user_buffer_size; |
248 | 250 |
249 // The sizes here were determined by experimentation and are roughly | 251 // The sizes here were determined by experimentation and are roughly |
250 // the lowest value (for low latency) that still allowed glitch-free | 252 // the lowest value (for low latency) that still allowed glitch-free |
251 // audio under high loads. | 253 // audio under high loads. |
252 // | 254 // |
253 // For Mac OS X and Windows the chromium audio backend uses a low-latency | 255 // 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 | 256 // Core Audio API, so a low buffer size is possible. For Linux, further |
255 // tuning may be needed. | 257 // tuning may be needed. |
256 #if defined(OS_MACOSX) | 258 #if defined(OS_MACOSX) |
257 return 128; | 259 return 128; |
258 #elif defined(OS_WIN) | 260 #elif defined(OS_WIN) |
259 // Buffer size to use when a proper size can't be determined from the system. | 261 // Buffer size to use when a proper size can't be determined from the system. |
260 static const int kFallbackBufferSize = 4096; | 262 static const int kFallbackBufferSize = 1440; |
DaleCurtis
2013/01/31 02:34:33
Hmm, this is going to bust XP. If WaveOut isn't su
henrika (OOO until Aug 14)
2013/01/31 14:29:38
I hope you did not think I meant to do this change
| |
261 | 263 |
262 if (!CoreAudioUtil::IsSupported()) { | 264 if (!CoreAudioUtil::IsSupported()) { |
263 // Fall back to Windows Wave implementation on Windows XP or lower | 265 // Fall back to Windows Wave implementation on Windows XP or lower |
264 // and assume 48kHz as default sample rate. | 266 // and assume 48kHz as default sample rate. |
265 return kFallbackBufferSize; | 267 return kFallbackBufferSize; |
266 } | 268 } |
267 | 269 |
268 // TODO(crogers): tune this size to best possible WebAudio performance. | 270 // TODO(crogers): tune this size to best possible WebAudio performance. |
269 // WebRTC always uses 10ms for Windows and does not call this method. | 271 // WebRTC always uses 10ms for Windows and does not call this method. |
270 // Note that exclusive mode is experimental. | 272 // Note that exclusive mode is experimental. |
271 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 273 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
272 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { | 274 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { |
273 return 256; | 275 return 256; |
274 } | 276 } |
275 | 277 |
276 // TODO(henrika): remove when the --enable-webaudio-input flag is no longer | 278 AudioParameters params; |
277 // utilized. | 279 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole, |
278 if (cmd_line->HasSwitch(switches::kEnableWebAudioInput)) { | 280 ¶ms); |
279 AudioParameters params; | 281 return FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer(); |
280 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole, | |
281 ¶ms); | |
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 | 282 #else |
313 return 2048; | 283 return 2048; |
314 #endif | 284 #endif |
315 } | 285 } |
316 | 286 |
317 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { | 287 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { |
318 // TODO(henrika): add support for device selection on all platforms. | 288 // TODO(henrika): add support for device selection on all platforms. |
319 // Only exists on Windows today. | 289 // Only exists on Windows today. |
320 #if defined(OS_MACOSX) | 290 #if defined(OS_MACOSX) |
321 return CHANNEL_LAYOUT_MONO; | 291 return CHANNEL_LAYOUT_MONO; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 // out performance was degraded compared to XP. | 346 // out performance was degraded compared to XP. |
377 // - The regression was fixed in Windows 7 and most configurations will work | 347 // - 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. | 348 // with 2, but some (e.g., some Sound Blasters) still need 3. |
379 // - Some XP configurations (even multi-processor ones) also need 3. | 349 // - Some XP configurations (even multi-processor ones) also need 3. |
380 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; | 350 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; |
381 } | 351 } |
382 | 352 |
383 #endif | 353 #endif |
384 | 354 |
385 } // namespace media | 355 } // namespace media |
OLD | NEW |