fix(libSceAudioOut): reopen the output device the host stopped #13694

Merged
MarcZX10 merged 13 commits from upstream-pr/13694 into main 2026-10-31 19:31:08 +00:00
MarcZX10 commented 2026-10-31 00:16:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T00:16:16Z.


What

An AudioOut port stayed silent for the rest of a title after the host stopped the device it played through. SDL disables an opened device when its backend reports the device lost, and it does not enable it again: SDL_OpenedAudioDeviceDisconnected in src/audio/SDL_audio.c sets enabled to 0, and only opening a device sets it back to 1 (bundled 3rdparty/SDL2 at 4b69833bc). SDL_GetAudioDeviceStatus reports such a device as SDL_AUDIO_STOPPED. AnyPS5 never read that status for a port's default output or controller sound card, so the output calls kept returning success while the audio went nowhere.

This PR checks the status before a port's device is used and reopens the device when it is stopped:

  • the default output (sceAudioOutOpen with the main/default route) reopens through openDevice;
  • the controller sound card of a vibration port reopens through openVibrationDevice.

A failed reopen leaves the port with no device, so it runs as a virtual port, as a port opened with no output does today. Such a port is not retried later. The guest-visible API is unchanged: no export, return value or argument changes. The change is host-side only.

Base: upstream/main at 7ceda1326c, merged into the branch in 714d7e40e6. Earlier merges in the history: 9b6c28b8bd (of 50843f45d9), 2bdcad1490 (of ac551a129a), 01ffa65535 (of f25279c0) and 376d9b6fc2 (of b852c46c7d). All merges are clean.

Eight commits on top of upstream/main, plus the merges:

  • fix(libSceAudioOut): reopen the default output after the host stops it
  • test(libSceAudioOut): cover the default output reopen after a host stop
  • fix(libSceAudioOut): reopen a controller sound card the host stopped
  • test(libSceAudioOut): cover the controller sound card reopen after a host stop
  • docs(libSceAudioOut): record the host output reopen as debt
  • docs(libSceAudioOut): record the AudioOut2 main output as debt
  • test(libSceAudioOut): answer the device status query in two harnesses
  • test(libSceAudioOut): keep the queue target check in the default open harness

The status query stub in the two harnesses makes the fake device IDs of the port-lock and resampling tests report as playing, which matches the upstream behaviour those tests were written against. The default open harness keeps its queue target check in every mode except the disconnect mode, which removes the default output on purpose.

Debt: docs/dev/debt/libSceAudioOut.md records the host reopen (the console's behaviour is not measured) and a gap this PR does not fix: a context's main host device in AudioOut2 is still opened once and not reopened.

Not fixed, observed by reading only: VK_ERROR_SURFACE_LOST_KHR is not handled in VulkanDevice. check() in core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp throws on any non-success result except VK_ERROR_DEVICE_LOST, and presentLoop in core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp calls std::terminate on a std::exception. No headless seam exists to reproduce it, so it is not changed here.

Tested

Linux x86_64 (Intel Xeon E5-1620 v2, 8 threads), GCC 12, Ninja, -DBUILD_TESTING=ON, incremental build of the 30 AudioOut targets (the 27 audio_out* and libSceAudioOut targets plus the three audio_out_host_* tests of upstream main). Head tested: 714d7e40e6. The full runs were first done on 2bdcad1490 (base ac551a129a). The later merges (01ffa65535, 376d9b6fc2, 714d7e40e6) were each followed by an incremental build of the changed files and ctest -R audio_out, which gave 61 of 61 with identical test names every time. Between f25279c0 and 7ceda1326c upstream made no net change to any file under core/libs/prx/libSceAudioOut, to the libScePad, libc or libkernel sources, or to docs/dev/debt/libSceAudioOut.md; the other upstream changes are in other libraries (for example InventoryExports.hpp headers and the libSceJxr CMake file).

  • ctest -R audio_out on 2bdcad1490: 61 of 61 pass (repeated on 01ffa65535, see above). That is the 56 existing tests, the 3 upstream host tests, and the 2 new disconnect tests audio_out_default_open_disconnect and audio_out_vibration_device_disconnect.
  • Baseline on the base of the first full runs (ac551a129a): the eight branch-only files (CMakeLists.txt, src/AudioOut.cpp, the five AudioOut tests, the debt doc) set to their upstream/main versions, same build tree, ctest -R audio_out: 59 of 59 pass. Per test, the names are identical to the branch run except the two disconnect tests. So the defaults are unchanged. The files were then restored from the branch and checked byte for byte.
  • Negative control A (pre-fix harnesses): AudioOutPortLocks.cpp and AudioOutResampling.cpp from de0b4c4163, before the status stub. audio_out_independent_output, audio_out_independent_close, audio_out_same_port_close and audio_out_resampling abort: "AudioOut port locks: unknown device polled" (three times) and "resampling discarded the impulse response at the grain boundary". With the stub from 4e06acd31a they pass. The stub removes no assertion.
  • Negative control B (upstream AudioOut.cpp with the branch tests): audio_out_default_open_disconnect fails with "the removed default output was not replaced"; audio_out_vibration_device_disconnect fails with "the stopped controller sound card was not reopened". Both fail at the first assertion that depends on the reopen. The branch file was restored and both pass again. The later assertions of those two modes (queue into the live device, close count) follow the first failing assertion and were not controlled separately.
  • Negative control C (queue target): a scratch-only change in the build tree that queues to port.device + 1. With the restored default open harness, audio_out_default_open_disconnect fails with "wrong queue written". With the loosened harness from 4e06acd31a it fails with "output was queued to the removed default output". No existing default open mode calls sceAudioOutOutput, so their results do not depend on this check. The clone was not modified by the control.
  • python3 tools/env_reference.py --check: the same single failure on a clean upstream/main export and on the branch (APS5_PAD_SPEAKER_FALLBACK_DB has a row in docs/dev/ENVIRONMENT.md but the code no longer reads it), a known baseline failure. The branch adds no new failure.
  • python3 tools/check_conventions.py --base upstream/main: all conventions checks passed.
  • git diff --check upstream/main HEAD: clean.
  • python3 tools/pr_test_quality.py --json on the five changed AudioOut test files: five findings of kind possible-unregistered-cpp-test. These are a path-format false positive: all five are registered in core/libs/prx/libSceAudioOut/CMakeLists.txt with paths relative to that directory (tests/AudioOutBufferSize.cpp etc.), and all five run in ctest.
  • Overlap, python3 tools/pr_overlap.py --branch fix/host-device-changes: exit 2 (fails closed). The tool reports 10 open PRs sharing files with the branch, and could not compare three of them because they conflict with main: #5021, #9154, #12863. The rest of the report is in the tool output. Manual comparison of the three, against the PR metadata from GitHub:
    • #5021 (feat(aot): consolidate native ARM64 compiler, runtime and consumers): an AOT compiler PR. Its metadata lists 100 files, the GitHub list limit, none of them under libSceAudioOut; the tool reports it touches CMakeLists.txt and the debt doc. Its audio-related files beyond that list were not inspected.
    • #9154 (feat(pad): stream vibration ports to a Bluetooth DualSense as haptics reports): changes AudioOut.cpp in outputVirtualPort and AudioOut2Context.cpp. Its diff contains no device-status or reopen logic. It is in a different function from this PR's changes.
    • #12863 (feat(libSceVideoOut): opt-in host pause with a key or on focus loss): changes AudioOut.cpp in queueAudio, AudioOut2Context.cpp, AudioOutBufferSize.cpp, the debt doc and new HostPause files. Its diff contains no device-status or reopen logic. It is in a different function from this PR's changes.
  • Also named, checked with gh: #12954 (fix(libSceAudioOut): return from a blocking AudioOut2 push once the queue has room) is MERGED and touches AudioOut2Context.cpp and the debt doc. #12569 (host volume and mute) is MERGED and is part of current main. #9881, #12536, #11948 are OPEN and touch no AudioOut file. #12930 is OPEN and touches only docs/dev/debt/libSceVideoOut.md.

NOT RUN: the rest of the ctest suite (only audio_out* was run), Windows (WASAPI default-device path), macOS, real devices (no Bluetooth controller, no audio hotplug), console, GPUs and the Xvfb VUID run (no presentation code changed), performance.

Checklist

  • Based on current main; no other open PR implements the same functions
    (based on 7ceda1326c, tested and overlap-checked on it; main had moved to 813496001e (two commits, none changing a file this PR touches, merge clean) when the PR was opened; the overlap comparison above found no other open PR with the same device-status logic)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5092756716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13694). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T00:16:16Z. --- ### What An AudioOut port stayed silent for the rest of a title after the host stopped the device it played through. SDL disables an opened device when its backend reports the device lost, and it does not enable it again: `SDL_OpenedAudioDeviceDisconnected` in `src/audio/SDL_audio.c` sets `enabled` to 0, and only opening a device sets it back to 1 (bundled `3rdparty/SDL2` at 4b69833bc). `SDL_GetAudioDeviceStatus` reports such a device as `SDL_AUDIO_STOPPED`. AnyPS5 never read that status for a port's default output or controller sound card, so the output calls kept returning success while the audio went nowhere. This PR checks the status before a port's device is used and reopens the device when it is stopped: - the default output (`sceAudioOutOpen` with the main/default route) reopens through `openDevice`; - the controller sound card of a vibration port reopens through `openVibrationDevice`. A failed reopen leaves the port with no device, so it runs as a virtual port, as a port opened with no output does today. Such a port is not retried later. The guest-visible API is unchanged: no export, return value or argument changes. The change is host-side only. Base: `upstream/main` at `7ceda1326c`, merged into the branch in `714d7e40e6`. Earlier merges in the history: `9b6c28b8bd` (of `50843f45d9`), `2bdcad1490` (of `ac551a129a`), `01ffa65535` (of `f25279c0`) and `376d9b6fc2` (of `b852c46c7d`). All merges are clean. Eight commits on top of `upstream/main`, plus the merges: - `fix(libSceAudioOut): reopen the default output after the host stops it` - `test(libSceAudioOut): cover the default output reopen after a host stop` - `fix(libSceAudioOut): reopen a controller sound card the host stopped` - `test(libSceAudioOut): cover the controller sound card reopen after a host stop` - `docs(libSceAudioOut): record the host output reopen as debt` - `docs(libSceAudioOut): record the AudioOut2 main output as debt` - `test(libSceAudioOut): answer the device status query in two harnesses` - `test(libSceAudioOut): keep the queue target check in the default open harness` The status query stub in the two harnesses makes the fake device IDs of the port-lock and resampling tests report as playing, which matches the upstream behaviour those tests were written against. The default open harness keeps its queue target check in every mode except the disconnect mode, which removes the default output on purpose. Debt: `docs/dev/debt/libSceAudioOut.md` records the host reopen (the console's behaviour is not measured) and a gap this PR does not fix: a context's main host device in AudioOut2 is still opened once and not reopened. Not fixed, observed by reading only: `VK_ERROR_SURFACE_LOST_KHR` is not handled in `VulkanDevice`. `check()` in `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` throws on any non-success result except `VK_ERROR_DEVICE_LOST`, and `presentLoop` in `core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp` calls `std::terminate` on a `std::exception`. No headless seam exists to reproduce it, so it is not changed here. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux x86_64 (Intel Xeon E5-1620 v2, 8 threads), GCC 12, Ninja, `-DBUILD_TESTING=ON`, incremental build of the 30 AudioOut targets (the 27 `audio_out*` and `libSceAudioOut` targets plus the three `audio_out_host_*` tests of upstream main). Head tested: `714d7e40e6`. The full runs were first done on `2bdcad1490` (base `ac551a129a`). The later merges (`01ffa65535`, `376d9b6fc2`, `714d7e40e6`) were each followed by an incremental build of the changed files and `ctest -R audio_out`, which gave 61 of 61 with identical test names every time. Between `f25279c0` and `7ceda1326c` upstream made no net change to any file under `core/libs/prx/libSceAudioOut`, to the libScePad, libc or libkernel sources, or to `docs/dev/debt/libSceAudioOut.md`; the other upstream changes are in other libraries (for example `InventoryExports.hpp` headers and the `libSceJxr` CMake file). - `ctest -R audio_out` on `2bdcad1490`: 61 of 61 pass (repeated on `01ffa65535`, see above). That is the 56 existing tests, the 3 upstream host tests, and the 2 new disconnect tests `audio_out_default_open_disconnect` and `audio_out_vibration_device_disconnect`. - Baseline on the base of the first full runs (`ac551a129a`): the eight branch-only files (`CMakeLists.txt`, `src/AudioOut.cpp`, the five AudioOut tests, the debt doc) set to their `upstream/main` versions, same build tree, `ctest -R audio_out`: 59 of 59 pass. Per test, the names are identical to the branch run except the two disconnect tests. So the defaults are unchanged. The files were then restored from the branch and checked byte for byte. - Negative control A (pre-fix harnesses): `AudioOutPortLocks.cpp` and `AudioOutResampling.cpp` from `de0b4c4163`, before the status stub. `audio_out_independent_output`, `audio_out_independent_close`, `audio_out_same_port_close` and `audio_out_resampling` abort: "AudioOut port locks: unknown device polled" (three times) and "resampling discarded the impulse response at the grain boundary". With the stub from `4e06acd31a` they pass. The stub removes no assertion. - Negative control B (upstream `AudioOut.cpp` with the branch tests): `audio_out_default_open_disconnect` fails with "the removed default output was not replaced"; `audio_out_vibration_device_disconnect` fails with "the stopped controller sound card was not reopened". Both fail at the first assertion that depends on the reopen. The branch file was restored and both pass again. The later assertions of those two modes (queue into the live device, close count) follow the first failing assertion and were not controlled separately. - Negative control C (queue target): a scratch-only change in the build tree that queues to `port.device + 1`. With the restored default open harness, `audio_out_default_open_disconnect` fails with "wrong queue written". With the loosened harness from `4e06acd31a` it fails with "output was queued to the removed default output". No existing default open mode calls `sceAudioOutOutput`, so their results do not depend on this check. The clone was not modified by the control. - `python3 tools/env_reference.py --check`: the same single failure on a clean `upstream/main` export and on the branch (`APS5_PAD_SPEAKER_FALLBACK_DB has a row in docs/dev/ENVIRONMENT.md but the code no longer reads it`), a known baseline failure. The branch adds no new failure. - `python3 tools/check_conventions.py --base upstream/main`: all conventions checks passed. - `git diff --check upstream/main HEAD`: clean. - `python3 tools/pr_test_quality.py --json` on the five changed AudioOut test files: five findings of kind `possible-unregistered-cpp-test`. These are a path-format false positive: all five are registered in `core/libs/prx/libSceAudioOut/CMakeLists.txt` with paths relative to that directory (`tests/AudioOutBufferSize.cpp` etc.), and all five run in ctest. - Overlap, `python3 tools/pr_overlap.py --branch fix/host-device-changes`: exit 2 (fails closed). The tool reports 10 open PRs sharing files with the branch, and could not compare three of them because they conflict with `main`: #5021, #9154, #12863. The rest of the report is in the tool output. Manual comparison of the three, against the PR metadata from GitHub: - #5021 (`feat(aot): consolidate native ARM64 compiler, runtime and consumers`): an AOT compiler PR. Its metadata lists 100 files, the GitHub list limit, none of them under `libSceAudioOut`; the tool reports it touches `CMakeLists.txt` and the debt doc. Its audio-related files beyond that list were not inspected. - #9154 (`feat(pad): stream vibration ports to a Bluetooth DualSense as haptics reports`): changes `AudioOut.cpp` in `outputVirtualPort` and `AudioOut2Context.cpp`. Its diff contains no device-status or reopen logic. It is in a different function from this PR's changes. - #12863 (`feat(libSceVideoOut): opt-in host pause with a key or on focus loss`): changes `AudioOut.cpp` in `queueAudio`, `AudioOut2Context.cpp`, `AudioOutBufferSize.cpp`, the debt doc and new `HostPause` files. Its diff contains no device-status or reopen logic. It is in a different function from this PR's changes. - Also named, checked with `gh`: #12954 (`fix(libSceAudioOut): return from a blocking AudioOut2 push once the queue has room`) is MERGED and touches `AudioOut2Context.cpp` and the debt doc. #12569 (host volume and mute) is MERGED and is part of current `main`. #9881, #12536, #11948 are OPEN and touch no AudioOut file. #12930 is OPEN and touches only `docs/dev/debt/libSceVideoOut.md`. NOT RUN: the rest of the ctest suite (only `audio_out*` was run), Windows (WASAPI default-device path), macOS, real devices (no Bluetooth controller, no audio hotplug), console, GPUs and the Xvfb VUID run (no presentation code changed), performance. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions (based on `7ceda1326c`, tested and overlap-checked on it; `main` had moved to `813496001e` (two commits, none changing a file this PR touches, merge clean) when the PR was opened; the overlap comparison above found no other open PR with the same device-status logic) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13694
No description provided.