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

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

Issue 2908073002: Make OS audio buffer size limits visible. (Closed)
Patch Set: 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..c572a055657e3b63ca2be40d77e0537b019bfa9f 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -41,6 +41,28 @@ static const int kMaximumInputOutputBufferSize = 4096;
// Default sample-rate on most Apple hardware.
static const int kFallbackSampleRate = 44100;
+static int GetDefaultBufferSize(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;
+ 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;
+}
+
// Helper method to construct AudioObjectPropertyAddress structure given
// property selector and scope. The property element is always set to
// kAudioObjectPropertyElementMaster.
@@ -840,7 +862,8 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
if (has_valid_input_params) {
buffer_size =
std::min(kMaximumInputOutputBufferSize,
- std::max(input_params.frames_per_buffer(), buffer_size));
+ std::max(input_params.frames_per_buffer(),
+ GetMinimumAudioBufferSize(hardware_sample_rate)));
}
int hardware_channels;
@@ -887,29 +910,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 GetDefaultBufferSize(is_input, sample_rate);
}
bool AudioManagerMac::IsSuspending() const {
@@ -1189,4 +1193,12 @@ std::unique_ptr<AudioManager> CreateAudioManager(
audio_log_factory);
}
+int AudioManager::GetMinimumAudioBufferSize(int sample_rate) {
+ return GetDefaultBufferSize(false, sample_rate);
+}
+
+int AudioManager::GetMaximumAudioBufferSize(int sample_rate) {
+ return kMaximumInputOutputBufferSize;
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698