fix(libSceAudioOut): open the default output by name and follow its changes #22585
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22585"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gag21 on 2026-11-17T22:36:59Z.
What
Unplugging a DualSense that Windows uses as its default output crashed CUSA01709 01.02 within a second, each time on a different thread (the audio output thread, the title's audio decode thread, an AGC queue worker), always on a read of a corrupted heap block holding what look like small float audio samples.
libSceAudioOutopened ports on SDL's default device (SDL_OpenAudioDevice(nullptr, ...)). When the host's default output changes, SDL2's WASAPI backend moves such a device to the new default (RecoverWasapiDevice->UpdateAudioStream). That setscallbackspec.samplesto the new device's period and recomputescallbackspec.size, but only growswork_bufferto the device-sidespec.size.SDL_RunAudiothen fillscallbackspec.sizebytes ofwork_buffer, writing past it. The same lines are on SDL's currentSDL2branch.Ports now open the host's default output by the name
SDL_GetDefaultAudioInforeports, so SDL treats it as a fixed device and never moves it. To keep following a default-output switch, a port opened on the default output compares that name with the host's current default at most once a second before an output, and when it changed closes and reopens on the new default (dropping its queued audio). When the device disappears, SDL reports it stopped and the existing reopen insceAudioOutOutput/sceAudioOutOutputsopens the default of that moment. A port opened onANYPS5_AUDIO_DEVICEstays on that device.The AudioOut2 main output had the same open and, per its debt entry, was never reopened. A context now opens the default output by name too and, before a push, closes and reopens its device on the host's current default when SDL reports it stopped or the default changed (checked at most once a second). The close happens outside the context lock, since SDL waits for the device callback, which takes that lock; a separate device lock orders the swap against
sceAudioOut2ContextDestroy. Mixed but unplayed audio stays queued for the new device.Tested
Windows 11, CUSA01709 01.02, outputs "LG TV SSCR2 (NVIDIA High Definition Audio)" and "Speakers (DualSense Wireless Controller)", DualSense over USB as the default output, unplugged while the game played:
mainmerged with unrelated local AGC changes): crashed on unplug in 3 of 3 runs (access violations onAudioOut,SeadDecodeandqworker 0x20).ANYPS5_AUDIO_DEVICEset to the TV: no crash on unplug.ANYPS5_AUDIO_DEVICE: no crash on unplug and replug (also none with the first commit alone); sound moves to the TV on unplug, back to the DualSense when it is the default again, and follows a default-output switch in Windows' sound settings.ctest -R "audio_?out": 73/73 pass, including the newaudio_out_default_open_named_default,audio_out_default_open_default_switchandaudio_out2_default_output(stubbed SDL: a context opens the default by name, keeps it within a second of a default change, then moves to the new default, and reopens a stopped device). The stubbed-SDL tests now provideSDL_GetDefaultAudioInfoandSDL_free. The AudioOut2 change is covered by that test only: CUSA01709 useslibSceAudioOut's PS4 ports, and no PS5 title was run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T22:40:55Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
2c06d8b240:tools/check_conventions.pypassed.audio_out2_default_output_tests,audio_out_buffer_size_tests,audio_out_default_open_tests,audio_out_set_volume_tests,audio_out_vibration_device_testsbuilt cleanly.audio_out_vibration_device_quad,audio_out_vibration_device_pulse,audio_out_vibration_device_open_failure,audio_out_vibration_device_timing,audio_out_vibration_device_cadence,audio_out_vibration_device_discovery_failure,audio_out_vibration_device_disconnect,audio_out_default_open_zero_default,audio_out_default_open_wasapi_zero_default,audio_out_default_open_no_endpoint,audio_out_default_open_positive,audio_out_default_open_unknown,audio_out_default_open_disconnect,audio_out_default_open_named_default,audio_out_default_open_default_switch,audio_out_buffer_size_pass_through,audio_out_buffer_size_wrap,audio_out_buffer_size_mix,audio_out_buffer_size_threshold,audio_out_buffer_size_virtual_overflow,audio_out_buffer_size_invalid_format,audio_out_buffer_size_invalid_sample_rate,audio_out_buffer_size_any_index,audio_out2_default_output,audio_out_set_volume):core/libs/prx/libSceAudioOut/include/AudioOutSdl.hpp,core/libs/prx/libSceAudioOut/src/AudioOut.cpp,core/libs/prx/libSceAudioOut/src/AudioOut2Context.cpp,core/libs/prx/libSceAudioOut/src/AudioOut2Internal.hppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T01:27:12Z.
Review: APPROVED
Reviewed — looks good
The reviewed change is pinned to
2c06d8b240410310f66cce8ad9387ccf10d7ba2d; targeted source review found no verified blocking defect, and the author reports passing tests that I did not run.What I ran
Read the prepared description, commits, diff and manifest; inspected all 11 changed files listed as reviewed in the manifest, including targeted callers and context callback/destruction paths. No tests or build commands were run.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not independently run the reported 73 audio tests or reproduce the Windows 11 device-switch scenario. No files were excluded by the manifest; all 11 changed files marked included were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T12:17:29Z.
Review: COMMENTED
Actionable comments posted: 3
8f9461bd-a53f-4351-b797-293d92db9d77Reviewing files that changed from the base of the PR and between
f51f7fec91and6906c68654.core/libs/prx/libSceAudioOut/CMakeLists.txtcore/libs/prx/libSceAudioOut/include/AudioOutSdl.hppcore/libs/prx/libSceAudioOut/src/AudioOut.cppcore/libs/prx/libSceAudioOut/src/AudioOut2Context.cppcore/libs/prx/libSceAudioOut/src/AudioOut2Internal.hppcore/libs/prx/libSceAudioOut/tests/AudioOut2DefaultOutput.cppcore/libs/prx/libSceAudioOut/tests/AudioOutBufferSize.cppcore/libs/prx/libSceAudioOut/tests/AudioOutDefaultOpen.cppcore/libs/prx/libSceAudioOut/tests/AudioOutSetVolume.cppcore/libs/prx/libSceAudioOut/tests/AudioOutVibrationDevice.cppdocs/dev/debt/changes/fix-audio-output-retry.mddocs/dev/debt/changes/fix-audioout-open-default-device-by-name.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T12:25:21Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected code and supplied test report support merging.
What I ran
Reviewed head
6906c686545a4001e5a91ada44494ad68918f347. No commands or tests were run; the test results below are author-reported. I readdescription.md,commits.md,manifest.json, anddiff.patch, and read all changed repository files listed as reviewed in the manifest:core/libs/prx/libSceAudioOut/CMakeLists.txt,core/libs/prx/libSceAudioOut/include/AudioOutSdl.hpp,core/libs/prx/libSceAudioOut/src/AudioOut.cpp,core/libs/prx/libSceAudioOut/src/AudioOut2Context.cpp,core/libs/prx/libSceAudioOut/src/AudioOut2Internal.hpp,core/libs/prx/libSceAudioOut/tests/AudioOut2DefaultOutput.cpp,core/libs/prx/libSceAudioOut/tests/AudioOutBufferSize.cpp,core/libs/prx/libSceAudioOut/tests/AudioOutDefaultOpen.cpp,core/libs/prx/libSceAudioOut/tests/AudioOutSetVolume.cpp,core/libs/prx/libSceAudioOut/tests/AudioOutVibrationDevice.cpp,docs/dev/debt/changes/fix-audio-output-retry.md, anddocs/dev/debt/changes/fix-audioout-open-default-device-by-name.md.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run tests or reproduce the Windows output-device unplug/replug scenario. The review bundle's
files.jsonwas not available through the reader; manifest-listed files were all read. No merged-preview check was performed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:00:33Z.
Review: COMMENTED
Built the change on Linux and passed the
audio_out2_default_outputCTest. I also ran the built legacy AudioOut fixture’snamed_defaultanddefault_switchmodes directly. Both passed, covering the move to a newly selected default with the fixture’s SDL test doubles.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.