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

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

Issue 2908073002: Make OS audio buffer size limits visible. (Closed)
Patch Set: Updates based on reviewer feedback. Created 3 years, 6 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..b4e1dea2bb32dfc7d6c306bbb5c8b531c57ba046 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -27,6 +27,7 @@
#include "media/base/bind_to_current_loop.h"
#include "media/base/channel_layout.h"
#include "media/base/limits.h"
+#include "media/base/mac/audio_util_mac.h"
#include "media/base/media_switches.h"
namespace media {
@@ -34,10 +35,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;
@@ -836,12 +833,15 @@ 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(false, hardware_sample_rate);
- if (has_valid_input_params) {
- buffer_size =
- std::min(kMaximumInputOutputBufferSize,
- std::max(input_params.frames_per_buffer(), buffer_size));
- }
+ int buffer_size =
+ 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.
+ ? std::min(static_cast<int>(limits::kMaxAudioBufferSize),
+ std::max(input_params.frames_per_buffer(),
+ static_cast<int>(limits::kMinAudioBufferSize)))
+ : ChooseBufferSize(false, hardware_sample_rate);
int hardware_channels;
if (!GetDeviceChannels(device, AUElement::OUTPUT, &hardware_channels))
@@ -887,7 +887,7 @@ void AudioManagerMac::HandleDeviceChanges() {
}
int AudioManagerMac::ChooseBufferSize(bool is_input, int sample_rate) {
- // kMinimumInputOutputBufferSize is too small for the output side because
+ // kMinAudioBufferSize 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
@@ -895,20 +895,13 @@ int AudioManagerMac::ChooseBufferSize(bool is_input, int sample_rate) {
// 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;
+ int buffer_size =
+ is_input ? limits::kMinAudioBufferSize : 2 * limits::kMinAudioBufferSize;
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;
- }
-
+ buffer_size = user_buffer_size
+ ? user_buffer_size
+ : audio_util_mac::GetMinAudioBufferSizeForSampleRate(
+ buffer_size, sample_rate);
return buffer_size;
}

Powered by Google App Engine
This is Rietveld 408576698