Index: media/audio/mac/audio_manager_mac.cc |
diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc |
index 8478e0f70c56e5aded802dd0a8182f25dd605a35..09b6433e631d819fc6bc87ab72f4c55b5cc672d1 100644 |
--- a/media/audio/mac/audio_manager_mac.cc |
+++ b/media/audio/mac/audio_manager_mac.cc |
@@ -27,13 +27,16 @@ |
#include "media/base/bind_to_current_loop.h" |
#include "media/base/channel_layout.h" |
#include "media/base/limits.h" |
-#include "media/base/mac/audio_latency_mac.h" |
#include "media/base/media_switches.h" |
namespace media { |
// Maximum number of output streams that can be open simultaneously. |
static const int kMaxOutputStreams = 50; |
+ |
+// Define bounds for for low-latency input and output streams. |
+static const int kMinimumInputOutputBufferSize = 128; |
+static const int kMaximumInputOutputBufferSize = 4096; |
// Default sample-rate on most Apple hardware. |
static const int kFallbackSampleRate = 44100; |
@@ -833,17 +836,11 @@ |
// 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; |
+ int buffer_size = ChooseBufferSize(false, hardware_sample_rate); |
if (has_valid_input_params) { |
- // If passed in via the input_params we allow buffer sizes to go as |
- // low as the the kMinAudioBufferSize, ignoring what |
- // ChooseBufferSize() normally returns. |
buffer_size = |
- std::min(static_cast<int>(limits::kMaxAudioBufferSize), |
- std::max(input_params.frames_per_buffer(), |
- static_cast<int>(limits::kMinAudioBufferSize))); |
- } else { |
- buffer_size = ChooseBufferSize(false, hardware_sample_rate); |
+ std::min(kMaximumInputOutputBufferSize, |
+ std::max(input_params.frames_per_buffer(), buffer_size)); |
} |
int hardware_channels; |
@@ -890,7 +887,7 @@ |
} |
int AudioManagerMac::ChooseBufferSize(bool is_input, int sample_rate) { |
- // kMinAudioBufferSize is too small for the output side because |
+ // 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 |
@@ -898,12 +895,20 @@ |
// 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 ? limits::kMinAudioBufferSize : 2 * limits::kMinAudioBufferSize; |
+ int buffer_size = is_input ? |
+ kMinimumInputOutputBufferSize : 2 * kMinimumInputOutputBufferSize; |
const int user_buffer_size = GetUserBufferSize(); |
- buffer_size = user_buffer_size |
- ? user_buffer_size |
- : GetMinAudioBufferSizeMacOS(buffer_size, sample_rate); |
+ if (user_buffer_size) { |
+ buffer_size = user_buffer_size; |
+ } 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 (sample_rate <= 96000) |
+ buffer_size = 2 * kMinimumInputOutputBufferSize; |
+ else if (sample_rate <= 192000) |
+ buffer_size = 4 * kMinimumInputOutputBufferSize; |
+ } |
+ |
return buffer_size; |
} |