Index: media/audio/audio_util.cc |
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc |
index 75e0831c6026b8c7da63e3f557db1027ba252852..14a9a1a1cc16cab3eaba0ef48ed30ca26534631c 100644 |
--- a/media/audio/audio_util.cc |
+++ b/media/audio/audio_util.cc |
@@ -19,6 +19,7 @@ |
#include "base/basictypes.h" |
#include "base/logging.h" |
+#include "base/string_number_conversions.h" |
#include "base/time.h" |
#include "media/audio/audio_parameters.h" |
#include "media/base/audio_bus.h" |
@@ -39,6 +40,20 @@ |
namespace media { |
+// Returns user buffer size as specified on the command line or 0 if no buffer |
+// size has been specified. |
+static int GetUserBufferSize() { |
+ const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
+ int buffer_size = 0; |
+ std::string buffer_size_str(cmd_line->GetSwitchValueASCII( |
+ switches::kAudioBufferSize)); |
+ if (base::StringToInt(buffer_size_str, &buffer_size) && buffer_size > 0) { |
+ return buffer_size; |
+ } |
+ |
+ return 0; |
+} |
+ |
// TODO(fbarchard): Convert to intrinsics for better efficiency. |
template<class Fixed> |
static int ScaleChannel(int channel, int volume) { |
@@ -225,6 +240,10 @@ int GetAudioInputHardwareSampleRate(const std::string& device_id) { |
} |
size_t GetAudioHardwareBufferSize() { |
+ int user_buffer_size = GetUserBufferSize(); |
+ if (user_buffer_size) |
+ return user_buffer_size; |
+ |
// The sizes here were determined by experimentation and are roughly |
// the lowest value (for low latency) that still allowed glitch-free |
// audio under high loads. |
@@ -236,7 +255,7 @@ size_t GetAudioHardwareBufferSize() { |
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; |
+ static const int kFallbackBufferSize = 4096; |
if (!CoreAudioUtil::IsSupported()) { |
// Fall back to Windows Wave implementation on Windows XP or lower |
@@ -314,6 +333,10 @@ ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { |
// Computes a buffer size based on the given |sample_rate|. Must be used in |
// conjunction with AUDIO_PCM_LINEAR. |
size_t GetHighLatencyOutputBufferSize(int sample_rate) { |
+ int user_buffer_size = GetUserBufferSize(); |
+ if (user_buffer_size) |
+ return user_buffer_size; |
+ |
// TODO(vrk/crogers): The buffer sizes that this function computes is probably |
// overly conservative. However, reducing the buffer size to 2048-8192 bytes |
// caused crbug.com/108396. This computation should be revisited while making |