diff options
author | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 08:55:09 +0000 |
---|---|---|
committer | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 08:55:09 +0000 |
commit | 4ee1f756a5f579fc191697fd62503eea1c5b6254 (patch) | |
tree | ffcbfa8b8d23ef2167b62f2ad011ef5dde4b2474 /media/audio/audio_util.cc | |
parent | 288235fb2e2c3c168574100f9d6aa22a1d957831 (diff) | |
download | chromium_src-4ee1f756a5f579fc191697fd62503eea1c5b6254.zip chromium_src-4ee1f756a5f579fc191697fd62503eea1c5b6254.tar.gz chromium_src-4ee1f756a5f579fc191697fd62503eea1c5b6254.tar.bz2 |
This CL adds support for experimental exclusive-mode streaming to WASAPIAudioOutputStream. Enabling the flag "enable-exclusive-mode" will ensure that output audio streaming on Windows runs in exclusive mode (if the user has allowed it).
Initial tests shows that we can reach latencies of about 3.33ms for 48kHz. As a comparison, for shared-mode, the total latency is ~35ms (even if the time between each OnMoreData() callback is ~10ms).
BUG=133483
TEST=media_unittests --enable-exclusive-audio --gtest_filter=WinAudioOutputTest*
Review URL: https://chromiumcodereview.appspot.com/10575017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148731 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_util.cc')
-rw-r--r-- | media/audio/audio_util.cc | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc index 4035d28..0526616 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -20,20 +20,20 @@ #include "base/logging.h" #include "base/shared_memory.h" #include "base/time.h" -#if defined(OS_WIN) -#include "base/sys_info.h" -#include "base/win/windows_version.h" -#include "media/audio/audio_manager_base.h" -#endif #include "media/audio/audio_parameters.h" #include "media/audio/audio_util.h" + #if defined(OS_MACOSX) #include "media/audio/mac/audio_low_latency_input_mac.h" #include "media/audio/mac/audio_low_latency_output_mac.h" -#endif -#if defined(OS_WIN) +#elif defined(OS_WIN) +#include "base/command_line.h" +#include "base/sys_info.h" +#include "base/win/windows_version.h" +#include "media/audio/audio_manager_base.h" #include "media/audio/win/audio_low_latency_input_win.h" #include "media/audio/win/audio_low_latency_output_win.h" +#include "media/base/media_switches.h" #endif using base::subtle::Atomic32; @@ -351,16 +351,28 @@ int GetAudioHardwareSampleRate() { return 48000; } + // TODO(crogers): tune this rate for best possible WebAudio performance. + // WebRTC works well at 48kHz and a buffer size of 480 samples will be used + // for this case. Note that exclusive mode is experimental. + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); + if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { + // This sample rate will be combined with a buffer size of 256 samples + // (see GetAudioHardwareBufferSize()), which corresponds to an output + // delay of ~5.33ms. + return 48000; + } + // Hardware sample-rate on Windows can be configured, so we must query. - // TODO(henrika): improve possibility to specify audio endpoint. - // Use the default device (same as for Wave) for now to be compatible. + // TODO(henrika): improve possibility to specify an audio endpoint. + // Use the default device (same as for Wave) for now to be compatible + // or possibly remove the ERole argument completely until it is in use. return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); #elif defined(OS_ANDROID) return 16000; #else - // Hardware for Linux is nearly always 48KHz. - // TODO(crogers) : return correct value in rare non-48KHz cases. - return 48000; + // Hardware for Linux is nearly always 48KHz. + // TODO(crogers) : return correct value in rare non-48KHz cases. + return 48000; #endif } @@ -397,6 +409,15 @@ size_t GetAudioHardwareBufferSize() { // and assume 48kHz as default sample rate. return 2048; } + + // TODO(crogers): tune this size to best possible WebAudio performance. + // WebRTC always uses 10ms for Windows and does not call this method. + // Note that exclusive mode is experimental. + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); + if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { + return 256; + } + // This call must be done on a COM thread configured as MTA. // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. int mixing_sample_rate = |