Skip to content

aaudio: rework buffer sizing strategy, treat latency as performance hint#836

Merged
kinetiknz merged 2 commits into
masterfrom
aaudio-buffer-sizing
Mar 24, 2026
Merged

aaudio: rework buffer sizing strategy, treat latency as performance hint#836
kinetiknz merged 2 commits into
masterfrom
aaudio-buffer-sizing

Conversation

@kinetiknz
Copy link
Copy Markdown
Collaborator

Rework our AAudio backend's buffer sizing strategy based on AAudio best practices and a thorough review of the decisions made in liboboe and Chromium. Also only do buffer size tuning if LOW_LATENCY performance mode was actually granted.

Note that we no longer call setFramesPerDataCallback, so we'll get data callbacks in AAudio's preferred size rather than forcing sizes that could result in internal buffering in AAudio. I think this will be better for latency/performance, but if it turns out to be problematic we can revisit this.

This also makes 0005-increase-aaudio-powersaving-buffering.patch in Gecko obsolete, so it will be dropped when this change is imported.

@kinetiknz kinetiknz requested review from Pehrsons and padenot March 18, 2026 04:16
@kinetiknz kinetiknz self-assigned this Mar 18, 2026
@kinetiknz kinetiknz force-pushed the aaudio-buffer-sizing branch from 36f6f58 to d7e0596 Compare March 18, 2026 04:43
For output, use 2 bursts (matching Oboe defaults) for low-latency
streams and keep defaults for power-saving; for input, maximize buffer
size to reduce XRuns. Remove hardcoded setFramesPerDataCallback/
setBufferCapacityInFrames and let AAudio choose optimal values.

Check the actual performance mode granted by AAudio rather than the
requested latency to decide whether to tune the output buffer. This
avoids shrinking the buffer below AAudio's default when the mode is
downgraded (e.g. Bluetooth routing).
@kinetiknz kinetiknz force-pushed the aaudio-buffer-sizing branch from d7e0596 to 29953c6 Compare March 18, 2026 04:49
@kinetiknz
Copy link
Copy Markdown
Collaborator Author

This is green on CI.

Copy link
Copy Markdown
Contributor

@Pehrsons Pehrsons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I trust you've done a fair bit of manual testing across devices (phones and headphones) here.

@kinetiknz
Copy link
Copy Markdown
Collaborator Author

I trust you've done a fair bit of manual testing across devices (phones and headphones) here.

I've tested a bunch of scenarios across: Xiaomi Redmi 14C (Android 14), Samsung S9+ (Android 10), and the emulator (various versions) with several Bluetooth and wired headphones/headsets plus the built-in speakers.

@kinetiknz kinetiknz merged commit 774182f into master Mar 24, 2026
30 of 46 checks passed
@kinetiknz kinetiknz deleted the aaudio-buffer-sizing branch March 24, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants