diff options
author | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-25 21:00:21 +0000 |
---|---|---|
committer | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-25 21:00:21 +0000 |
commit | ddb76228e9d0993ce59c6b141f79fc4fe5efd133 (patch) | |
tree | 8a1863650034fc9e69a26425f18fa31e023f7849 /media/audio | |
parent | 231cf3e4b7e83241c6ebf8d4887ec025bd4656c5 (diff) | |
download | chromium_src-ddb76228e9d0993ce59c6b141f79fc4fe5efd133.zip chromium_src-ddb76228e9d0993ce59c6b141f79fc4fe5efd133.tar.gz chromium_src-ddb76228e9d0993ce59c6b141f79fc4fe5efd133.tar.bz2 |
Return fixed hardware buffer size for odd sample rates.
Windows will return a sample rate of zero if audio can't
be output, in this case we shouldn't return a buffer size
of zero.
Some hardware also might return a hardware sample rate < 100,
in this case we should choose a non-zero fixed buffer size to
prevent crashes.
In either case, AudioOutputResampler will later check the hardware
config for validity and fallback to the high latency audio path in
cases where a bogus sample rate exists.
BUG=152073
TEST=compiles
Review URL: https://codereview.chromium.org/10993013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/audio_util.cc | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc index 2b4fd17..6307563 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -32,6 +32,7 @@ #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/limits.h" #include "media/base/media_switches.h" #endif @@ -305,10 +306,13 @@ size_t GetAudioHardwareBufferSize() { #if defined(OS_MACOSX) return 128; #elif defined(OS_WIN) + // Buffer size to use when a proper size can't be determined from the system. + static const int kFallbackBufferSize = 2048; + if (!IsWASAPISupported()) { // Fall back to Windows Wave implementation on Windows XP or lower // and assume 48kHz as default sample rate. - return 2048; + return kFallbackBufferSize; } // TODO(crogers): tune this size to best possible WebAudio performance. @@ -324,6 +328,12 @@ size_t GetAudioHardwareBufferSize() { int mixing_sample_rate = WASAPIAudioOutputStream::HardwareSampleRate(eConsole); + // Windows will return a sample rate of 0 when no audio output is available + // (i.e. via RemoteDesktop with remote audio disabled), but we should never + // return a buffer size of zero. + if (mixing_sample_rate == 0) + return kFallbackBufferSize; + // Use different buffer sizes depening on the sample rate . The existing // WASAPI implementation is tuned to provide the most stable callback // sequence using these combinations. @@ -335,8 +345,11 @@ size_t GetAudioHardwareBufferSize() { // Use buffer size of 10ms. return (80 * (mixing_sample_rate / 8000)); + // Ensure we always return a buffer size which is somewhat appropriate. LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected."; - return (mixing_sample_rate / 100); + if (mixing_sample_rate > limits::kMinSampleRate) + return (mixing_sample_rate / 100); + return kFallbackBufferSize; #else return 2048; #endif |