From ca4b67f6195b4af2de5f23b73e21b9925f9fdc1b Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 19 Feb 2025 14:02:37 +0000 Subject: [PATCH] Bug 1947917 - Add cubeb patch to increase AAudio buffering when not doing low-latency and re-vendor. r=padenot,cubeb-reviewers Differential Revision: https://phabricator.services.mozilla.com/D238767 --- ...ncrease-aaudio-powersaving-buffering.patch | 24 +++++++++++++++++++ media/libcubeb/moz.yaml | 1 + media/libcubeb/src/cubeb_aaudio.cpp | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 media/libcubeb/0005-increase-aaudio-powersaving-buffering.patch diff --git a/media/libcubeb/0005-increase-aaudio-powersaving-buffering.patch b/media/libcubeb/0005-increase-aaudio-powersaving-buffering.patch new file mode 100644 index 000000000000..6a7bd72bb6e6 --- /dev/null +++ b/media/libcubeb/0005-increase-aaudio-powersaving-buffering.patch @@ -0,0 +1,24 @@ +diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp +--- a/src/cubeb_aaudio.cpp ++++ b/src/cubeb_aaudio.cpp +@@ -1328,18 +1328,18 @@ aaudio_stream_init_impl(cubeb_stream * s + + int rate = WRAP(AAudioStream_getSampleRate)(stm->ostream); + int32_t output_burst_frames = + WRAP(AAudioStream_getFramesPerBurst)(stm->ostream); + // 3 times the burst size seems fairly robust, use it as minimum. + int32_t output_buffer_size_frames = 3 * output_burst_frames; + if (stm->latency_frames > POWERSAVE_LATENCY_FRAMES_THRESHOLD) { + // FramesPerBurst is large in power saving mode, reduce the buffer size to +- // 1 burst. +- output_buffer_size_frames = output_burst_frames; ++ // 2 bursts. ++ output_buffer_size_frames = 2 * output_burst_frames; + } + // Make output buffer size a function of the requested latency so clients + // can adapt to their use case. + output_buffer_size_frames = + std::max(output_buffer_size_frames, + static_cast(stm->latency_frames / 2)); + int32_t output_final_buffer_size_frames = + WRAP(AAudioStream_setBufferSizeInFrames)(stm->ostream, diff --git a/media/libcubeb/moz.yaml b/media/libcubeb/moz.yaml index c5de036a41d1..d6ef6c629180 100644 --- a/media/libcubeb/moz.yaml +++ b/media/libcubeb/moz.yaml @@ -21,6 +21,7 @@ vendoring: - 0002-disable-crash-reporter-death-test.patch - 0003-audiounit-ios-compile-fixes.patch - 0004-disable-cubeb_one_duplex_one_input-macos10.15.patch + - 0005-increase-aaudio-powersaving-buffering.patch skip-vendoring-steps: - update-moz-build exclude: diff --git a/media/libcubeb/src/cubeb_aaudio.cpp b/media/libcubeb/src/cubeb_aaudio.cpp index 89d258510cc9..cf63b578cdbe 100644 --- a/media/libcubeb/src/cubeb_aaudio.cpp +++ b/media/libcubeb/src/cubeb_aaudio.cpp @@ -1333,8 +1333,8 @@ aaudio_stream_init_impl(cubeb_stream * stm, lock_guard & lock) int32_t output_buffer_size_frames = 3 * output_burst_frames; if (stm->latency_frames > POWERSAVE_LATENCY_FRAMES_THRESHOLD) { // FramesPerBurst is large in power saving mode, reduce the buffer size to - // 1 burst. - output_buffer_size_frames = output_burst_frames; + // 2 bursts. + output_buffer_size_frames = 2 * output_burst_frames; } // Make output buffer size a function of the requested latency so clients // can adapt to their use case.