Repository navigation
Conversation
AAudio never uses the MMAP path for a stream with a session ID, while a low latency stream still gets a FAST track on the legacy path. This gives a way to stay off MMAP without the conservative profile, which on some devices sends the stream to a deep buffer output with a high latency. The option is carried into the config rebuilt on a reroute, like the other AAudio settings.
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
A critical active finding remains because miniaudio.h assigns AAudioStreamBuilder_setSessionId unconditionally under MA_NO_RUNTIME_LINKING, which can fail to compile on Android targets below API 28 due to the symbol not being declared without an API-level guard.
1 open issue
What changed in this PR
Adds an AAudio-specific configuration flag to request allocation of an Android audio session ID, enabling low-latency playback while staying on the legacy (non-MMAP) path for improved robustness on affected devices.
Changes:
- Added
ma_device_config.aaudio.allocateSessionIdand persisted it throughma_devicestate and the AAudio reroute reinit path. - Added runtime/dynamic loading support for
AAudioStreamBuilder_setSessionId()and applied it during stream builder configuration when requested. - Documented the new option alongside other AAudio device configuration settings.
| File | Description |
|---|---|
| miniaudio.h | Updated as part of this pull request. |
Review effort: Balanced
| pContext->aaudio.AAudioStreamBuilder_setUsage = (ma_proc)AAudioStreamBuilder_setUsage; | ||
| pContext->aaudio.AAudioStreamBuilder_setContentType = (ma_proc)AAudioStreamBuilder_setContentType; | ||
| pContext->aaudio.AAudioStreamBuilder_setInputPreset = (ma_proc)AAudioStreamBuilder_setInputPreset; | ||
| pContext->aaudio.AAudioStreamBuilder_setSessionId = (ma_proc)AAudioStreamBuilder_setSessionId; |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds
aaudio.allocateSessionIdtoma_device_config. When set, the stream is opened withAAUDIO_SESSION_ID_ALLOCATE. AAudio never uses the MMAP path for a stream with a session ID(
AudioStreamBuilder::build(): "MMAP not used because sessionId specified"), while a low latencystream still gets a FAST track on the legacy path (
AudioStreamTrack::open()).Why
We need a low latency stream that stays off MMAP. On a Samsung Galaxy Z Fold5 (Android 17) an MMAP
stream fails to start after a system sound with haptics (see #1184): the HAL cannot route it and
AAudio returns
AAUDIO_ERROR_DISCONNECTEDafter about a second. The conservative profile avoidsMMAP too, but Samsung's audio policy sends that stream to its deep buffer output, about 0.2 s of
latency, audible on every button press.
With a session ID the stream gets
AUDIO_OUTPUT_FLAG_FASTon the low latency output, and launchesin that state play normally. AudioFlinger grants a FAST track only when the stream runs at the
output's sample rate, so we open the device with
sampleRate = 0.Details
allocateSessionIdis stored inma_device.aaudioand carried into the config rebuilt inma_device_reinit__aaudio(), like the other AAudio settings (see AAudio: allowSetBufferCapacity is not preserved across a reroute, so the configured buffer size is silently lost #1158), so a reroute does notbring MMAP back.
AAudioStreamBuilder_setSessionId()is API 28. It is loaded with the other functions and skippedwhen missing. With
MA_NO_RUNTIME_LINKINGit is linked directly, next toAAudioStreamBuilder_setUsage(), which is API 28 as well.aaudio.noAutoStartAfterReroute.Testing
MMAP not used because sessionId specified,AUDIO_OUTPUT_FLAG_FAST successfulandgot Legacy ... perf = LL. Three launchesright after a system sound with haptics all played; without the option 5 out of 5 such launches
failed.
-std=c89 -Wall -Wextra -Wpedantic), with andwithout
MA_NO_RUNTIME_LINKING, with no new warnings.dev-0.12hasaaudio.performanceModebut no session ID either. Happy to port this there if youwant it.