summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxians <xians@chromium.org>2014-11-12 15:15:52 +0100
committerxians <xians@chromium.org>2014-11-12 14:17:16 +0000
commit7cd5bd32496c2954a523009bff76293c08670829 (patch)
tree2a77d398c1cd744a483c37ee1405b9e9ece97497
parent6ac5b3b7a7861707e68ff88605ec7e2e1dd3f941 (diff)
downloadchromium_src-7cd5bd32496c2954a523009bff76293c08670829.zip
chromium_src-7cd5bd32496c2954a523009bff76293c08670829.tar.gz
chromium_src-7cd5bd32496c2954a523009bff76293c08670829.tar.bz2
Merged 673183002 to M39.
Increase the default buffer size from 128 to 256 on Mac. This is to avoid glitches when webaudio and webrtc streams are used at the same time. TBR=rtoy@chromium.org BUG=423696 Review URL: https://codereview.chromium.org/673183002 Cr-Commit-Position: refs/heads/master@{#301367} (cherry picked from commit ca469461bbd554ecddc82ea91d2cef7f3df5502e) Review URL: https://codereview.chromium.org/706893003 Cr-Commit-Position: refs/branch-heads/2171@{#416} Cr-Branched-From: 267aeeb8d85c8503a7fd12bd14654b8ea78d3974-refs/heads/master@{#297060}
-rw-r--r--media/audio/mac/audio_manager_mac.cc27
-rw-r--r--media/audio/mac/audio_manager_mac.h2
2 files changed, 19 insertions, 10 deletions
diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
index 336a8c4..f8b78b5 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -439,7 +439,7 @@ AudioParameters AudioManagerMac::GetInputStreamParameters(
DLOG(ERROR) << "Invalid device " << device_id;
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
- kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate));
+ kFallbackSampleRate, 16, ChooseBufferSize(true, kFallbackSampleRate));
}
int channels = 0;
@@ -459,7 +459,7 @@ AudioParameters AudioManagerMac::GetInputStreamParameters(
// Due to the sharing of the input and output buffer sizes, we need to choose
// the input buffer size based on the output sample rate. See
// http://crbug.com/154352.
- const int buffer_size = ChooseBufferSize(sample_rate);
+ const int buffer_size = ChooseBufferSize(true, sample_rate);
// TODO(xians): query the native channel layout for the specific device.
return AudioParameters(
@@ -640,7 +640,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
DLOG(ERROR) << "Invalid output device " << output_device_id;
return input_params.IsValid() ? input_params : AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
- kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate));
+ kFallbackSampleRate, 16, ChooseBufferSize(false, kFallbackSampleRate));
}
const bool has_valid_input_params = input_params.IsValid();
@@ -649,7 +649,7 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
// Allow pass through buffer sizes. If concurrent input and output streams
// exist, they will use the smallest buffer size amongst them. As such, each
// stream must be able to FIFO requests appropriately when this happens.
- int buffer_size = ChooseBufferSize(hardware_sample_rate);
+ int buffer_size = ChooseBufferSize(false, hardware_sample_rate);
if (has_valid_input_params) {
buffer_size =
std::min(kMaximumInputOutputBufferSize,
@@ -717,17 +717,26 @@ void AudioManagerMac::HandleDeviceChanges() {
NotifyAllOutputDeviceChangeListeners();
}
-int AudioManagerMac::ChooseBufferSize(int output_sample_rate) {
- int buffer_size = kMinimumInputOutputBufferSize;
+int AudioManagerMac::ChooseBufferSize(bool is_input, int sample_rate) {
+ // kMinimumInputOutputBufferSize is too small for the output side because
+ // CoreAudio can get into under-run if the renderer fails delivering data
+ // to the browser within the allowed time by the OS. The workaround is to
+ // use 256 samples as the default output buffer size for sample rates
+ // smaller than 96KHz.
+ // TODO(xians): Remove this workaround after WebAudio supports user defined
+ // buffer size. See https://github.com/WebAudio/web-audio-api/issues/348
+ // for details.
+ int buffer_size = is_input ?
+ kMinimumInputOutputBufferSize : 2 * kMinimumInputOutputBufferSize;
const int user_buffer_size = GetUserBufferSize();
if (user_buffer_size) {
buffer_size = user_buffer_size;
- } else if (output_sample_rate > 48000) {
+ } else if (sample_rate > 48000) {
// The default buffer size is too small for higher sample rates and may lead
// to glitching. Adjust upwards by multiples of the default size.
- if (output_sample_rate <= 96000)
+ if (sample_rate <= 96000)
buffer_size = 2 * kMinimumInputOutputBufferSize;
- else if (output_sample_rate <= 192000)
+ else if (sample_rate <= 192000)
buffer_size = 4 * kMinimumInputOutputBufferSize;
}
diff --git a/media/audio/mac/audio_manager_mac.h b/media/audio/mac/audio_manager_mac.h
index 490b0b6..9af5c6d 100644
--- a/media/audio/mac/audio_manager_mac.h
+++ b/media/audio/mac/audio_manager_mac.h
@@ -86,7 +86,7 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase {
void InitializeOnAudioThread();
void ShutdownOnAudioThread();
- int ChooseBufferSize(int output_sample_rate);
+ int ChooseBufferSize(bool is_input, int sample_rate);
// Notify streams of a device change if the default output device or its
// sample rate has changed, otherwise does nothing.