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

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

Issue 2908073002: Make OS audio buffer size limits visible. (Closed)
Patch Set: Remove pulse-related changes. Created 3 years, 5 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
« no previous file with comments | « media/audio/cras/audio_manager_cras.cc ('k') | media/base/audio_latency.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8478e0f70c56e5aded802dd0a8182f25dd605a35 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_latency_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,11 +833,17 @@ 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);
+ int buffer_size;
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(kMaximumInputOutputBufferSize,
- std::max(input_params.frames_per_buffer(), 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);
}
int hardware_channels;
@@ -887,7 +890,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 +898,12 @@ 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
+ : GetMinAudioBufferSizeMacOS(buffer_size, sample_rate);
return buffer_size;
}
« no previous file with comments | « media/audio/cras/audio_manager_cras.cc ('k') | media/base/audio_latency.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698