Skip to content

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

Open
kinetiknz wants to merge 2 commits intomasterfrom
aaudio-buffer-sizing
Open

aaudio: rework buffer sizing strategy, treat latency as performance hint#836
kinetiknz wants to merge 2 commits intomasterfrom
aaudio-buffer-sizing

Conversation

@kinetiknz
Copy link
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
Collaborator Author

This is green on CI.

Copy link
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.

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