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

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

Issue 10575017: Adding experimental exclusive-mode streaming to WASAPIAudioOutputStream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor changes proposed by Andrew Created 8 years, 4 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
« no previous file with comments | « no previous file | media/audio/win/audio_low_latency_output_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 // TODO(vrk): This file has been running pretty wild and free, and it's likely 11 // TODO(vrk): This file has been running pretty wild and free, and it's likely
12 // that a lot of the functions can be simplified and made more elegant. Revisit 12 // that a lot of the functions can be simplified and made more elegant. Revisit
13 // after other audio cleanup is done. (crbug.com/120319) 13 // after other audio cleanup is done. (crbug.com/120319)
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <limits> 16 #include <limits>
17 17
18 #include "base/atomicops.h" 18 #include "base/atomicops.h"
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/shared_memory.h" 21 #include "base/shared_memory.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #if defined(OS_WIN) 23 #include "media/audio/audio_parameters.h"
24 #include "media/audio/audio_util.h"
25
26 #if defined(OS_MACOSX)
27 #include "media/audio/mac/audio_low_latency_input_mac.h"
28 #include "media/audio/mac/audio_low_latency_output_mac.h"
29 #elif defined(OS_WIN)
30 #include "base/command_line.h"
24 #include "base/sys_info.h" 31 #include "base/sys_info.h"
25 #include "base/win/windows_version.h" 32 #include "base/win/windows_version.h"
26 #include "media/audio/audio_manager_base.h" 33 #include "media/audio/audio_manager_base.h"
27 #endif
28 #include "media/audio/audio_parameters.h"
29 #include "media/audio/audio_util.h"
30 #if defined(OS_MACOSX)
31 #include "media/audio/mac/audio_low_latency_input_mac.h"
32 #include "media/audio/mac/audio_low_latency_output_mac.h"
33 #endif
34 #if defined(OS_WIN)
35 #include "media/audio/win/audio_low_latency_input_win.h" 34 #include "media/audio/win/audio_low_latency_input_win.h"
36 #include "media/audio/win/audio_low_latency_output_win.h" 35 #include "media/audio/win/audio_low_latency_output_win.h"
36 #include "media/base/media_switches.h"
37 #endif 37 #endif
38 38
39 using base::subtle::Atomic32; 39 using base::subtle::Atomic32;
40 40
41 const uint32 kUnknownDataSize = static_cast<uint32>(-1); 41 const uint32 kUnknownDataSize = static_cast<uint32>(-1);
42 42
43 namespace media { 43 namespace media {
44 44
45 // TODO(fbarchard): Convert to intrinsics for better efficiency. 45 // TODO(fbarchard): Convert to intrinsics for better efficiency.
46 template<class Fixed> 46 template<class Fixed>
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 #if defined(OS_MACOSX) 344 #if defined(OS_MACOSX)
345 // Hardware sample-rate on the Mac can be configured, so we must query. 345 // Hardware sample-rate on the Mac can be configured, so we must query.
346 return AUAudioOutputStream::HardwareSampleRate(); 346 return AUAudioOutputStream::HardwareSampleRate();
347 #elif defined(OS_WIN) 347 #elif defined(OS_WIN)
348 if (!IsWASAPISupported()) { 348 if (!IsWASAPISupported()) {
349 // Fall back to Windows Wave implementation on Windows XP or lower 349 // Fall back to Windows Wave implementation on Windows XP or lower
350 // and use 48kHz as default input sample rate. 350 // and use 48kHz as default input sample rate.
351 return 48000; 351 return 48000;
352 } 352 }
353 353
354 // TODO(crogers): tune this rate for best possible WebAudio performance.
355 // WebRTC works well at 48kHz and a buffer size of 480 samples will be used
356 // for this case. Note that exclusive mode is experimental.
357 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
358 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
359 // This sample rate will be combined with a buffer size of 256 samples
360 // (see GetAudioHardwareBufferSize()), which corresponds to an output
361 // delay of ~5.33ms.
362 return 48000;
363 }
364
354 // Hardware sample-rate on Windows can be configured, so we must query. 365 // Hardware sample-rate on Windows can be configured, so we must query.
355 // TODO(henrika): improve possibility to specify audio endpoint. 366 // TODO(henrika): improve possibility to specify an audio endpoint.
356 // Use the default device (same as for Wave) for now to be compatible. 367 // Use the default device (same as for Wave) for now to be compatible
368 // or possibly remove the ERole argument completely until it is in use.
357 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); 369 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
358 #elif defined(OS_ANDROID) 370 #elif defined(OS_ANDROID)
359 return 16000; 371 return 16000;
360 #else 372 #else
361 // Hardware for Linux is nearly always 48KHz. 373 // Hardware for Linux is nearly always 48KHz.
362 // TODO(crogers) : return correct value in rare non-48KHz cases. 374 // TODO(crogers) : return correct value in rare non-48KHz cases.
363 return 48000; 375 return 48000;
364 #endif 376 #endif
365 } 377 }
366 378
367 int GetAudioInputHardwareSampleRate(const std::string& device_id) { 379 int GetAudioInputHardwareSampleRate(const std::string& device_id) {
368 // TODO(henrika): add support for device selection on all platforms. 380 // TODO(henrika): add support for device selection on all platforms.
369 // Only exists on Windows today. 381 // Only exists on Windows today.
370 #if defined(OS_MACOSX) 382 #if defined(OS_MACOSX)
371 return AUAudioInputStream::HardwareSampleRate(); 383 return AUAudioInputStream::HardwareSampleRate();
372 #elif defined(OS_WIN) 384 #elif defined(OS_WIN)
373 if (!IsWASAPISupported()) { 385 if (!IsWASAPISupported()) {
(...skipping 16 matching lines...) Expand all
390 // Core Audio API, so a low buffer size is possible. For Linux, further 402 // Core Audio API, so a low buffer size is possible. For Linux, further
391 // tuning may be needed. 403 // tuning may be needed.
392 #if defined(OS_MACOSX) 404 #if defined(OS_MACOSX)
393 return 128; 405 return 128;
394 #elif defined(OS_WIN) 406 #elif defined(OS_WIN)
395 if (!IsWASAPISupported()) { 407 if (!IsWASAPISupported()) {
396 // Fall back to Windows Wave implementation on Windows XP or lower 408 // Fall back to Windows Wave implementation on Windows XP or lower
397 // and assume 48kHz as default sample rate. 409 // and assume 48kHz as default sample rate.
398 return 2048; 410 return 2048;
399 } 411 }
412
413 // TODO(crogers): tune this size to best possible WebAudio performance.
414 // WebRTC always uses 10ms for Windows and does not call this method.
415 // Note that exclusive mode is experimental.
416 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
417 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
418 return 256;
419 }
420
400 // This call must be done on a COM thread configured as MTA. 421 // This call must be done on a COM thread configured as MTA.
401 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. 422 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835.
402 int mixing_sample_rate = 423 int mixing_sample_rate =
403 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); 424 WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
404 if (mixing_sample_rate == 48000) 425 if (mixing_sample_rate == 48000)
405 return 480; 426 return 480;
406 else if (mixing_sample_rate == 44100) 427 else if (mixing_sample_rate == 44100)
407 return 448; 428 return 448;
408 else 429 else
409 return 960; 430 return 960;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if ((base::SysInfo::NumberOfProcessors() < 2) || 551 if ((base::SysInfo::NumberOfProcessors() < 2) ||
531 (base::win::GetVersion() == base::win::VERSION_VISTA)) { 552 (base::win::GetVersion() == base::win::VERSION_VISTA)) {
532 return 3; 553 return 3;
533 } 554 }
534 return 2; 555 return 2;
535 } 556 }
536 557
537 #endif 558 #endif
538 559
539 } // namespace media 560 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/audio/win/audio_low_latency_output_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698