Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: media/audio/mac/audio_manager_mac.cc

Issue 2908073002: Make OS audio buffer size limits visible. (Closed)
Patch Set: Move all buffer size calculations to AudioLatency. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 09b6433e631d819fc6bc87ab72f4c55b5cc672d1..c837442d3ff809ff89af370e5069fb078226d9ae 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -34,10 +34,6 @@ 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;
@@ -838,9 +834,11 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
// stream must be able to FIFO requests appropriately when this happens.
int buffer_size = ChooseBufferSize(false, hardware_sample_rate);
if (has_valid_input_params) {
- buffer_size =
- std::min(kMaximumInputOutputBufferSize,
- std::max(input_params.frames_per_buffer(), buffer_size));
+ buffer_size = std::min(
+ AudioLatency::GetMaximumAudioBufferSize(hardware_sample_rate),
+ std::max(
+ input_params.frames_per_buffer(),
+ AudioLatency::GetMinimumAudioBufferSize(hardware_sample_rate)));
}
int hardware_channels;
@@ -887,29 +885,10 @@ void AudioManagerMac::HandleDeviceChanges() {
}
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 (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;
+ if (user_buffer_size)
+ return user_buffer_size;
+ return AudioLatency::GetDefaultAudioBufferSize(is_input, sample_rate);
}
bool AudioManagerMac::IsSuspending() const {

Powered by Google App Engine
This is Rietveld 408576698