Skip to content

SDL: reopen an AAudio stream disconnected while in the background - #96

Merged
mamcjr merged 1 commit into
mamcjr:mainfrom
3122380113:sdl-aaudio-resume
Nov 3, 2026
Merged

mamcjr merged 1 commit into
mamcjr:mainfrom
3122380113:sdl-aaudio-resume

Conversation

@3122380113

Copy link
Copy Markdown
Contributor

Problem

After switching away from the game and back, it can stay silent until it is restarted. Seen on an AYN Odin 3 (Adreno 830, Android, 1.8.2) after ~2.5 h of play with an app switch in between:

AAudioStream: systemStart() stream is disconnected
AAudioStream_requestStart(s#1) returned -895

The game kept rendering at 60 fps while the system reported its AAudio player as paused.

Android can disconnect an AAudio (MMAP) stream while SDL holds it paused in the background. On resume, SDL 3.4.16's AAUDIO_ResumeDevices only logs requestStart's failure. A paused stream gets no error callback, so AAUDIO_PlayDevice never reaches RecoverAAudioDevice and nothing reopens the stream.

Fix

android/deps/sdl-aaudio-resume.patch: when requestStart fails on resume, set error_callback_triggered and signal the device semaphore, as the error callback does. The device thread then rebuilds the stream through SDL's existing recovery path. build_deps.sh applies the patch after unpacking SDL (delete out/lib/libSDL3.so to rebuild).

Testing

  • Built SDL with the patch and the debug APK; installed on the Odin 3.
  • Audio starts normally, and a short background/foreground cycle resumes it (requestStart returns 0, player started).
  • Not yet reproduced: the disconnected-on-resume case with the patched build, since the disconnect did not happen again in a short test. That's why this PR is a draft.

🤖 Generated with Claude Code

…d on resume, not left silent

Android may disconnect an app's AAudio (MMAP) stream while SDL has it paused in the background. On resume SDL 3.4.16's
AAUDIO_ResumeDevices only logs requestStart's failure (-895, "stream is disconnected"); a paused stream gets no error
callback, so the device thread never rebuilds it and the game stays silent until restarted (Odin 3, after switching
apps). The patch flags that failure as the error callback would, and PlayDevice opens a new stream. Applied by
android/deps/build_deps.sh after unpacking SDL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mamcjr
mamcjr marked this pull request as ready for review November 3, 2026 11:13
@mamcjr
mamcjr merged commit 64c3273 into mamcjr:main Nov 3, 2026
mamcjr added a commit that referenced this pull request Nov 3, 2026
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.

3 participants