audio: stop AudioOut2 contexts from stalling each other (PPSA09809) #1745
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1745
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1745/head"
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?
@MrBigBritches on GitHub · 2026-10-20 02:48 UTC · original
MrBigBritches:octopath-fixes→main· +118 −19 · 2 files · 1 commits · merged 2026-10-22 00:52 UTCaudioout2_queue_context_audio held the global AudioOut2 state mutex across AudioOutOutputs, which sleeps while pacing a blocking push. Titles with several contexts on separate threads (Octopath Traveler II: CRI ADX + Unreal AudioMixer, 2 x 256-sample grains) serialized on it, along with every PortSetAttributes/GetQueueLevel call, causing heavy stutter. Snapshot the PCM under the state mutex and submit outside it; a shared_mutex keeps backend handles alive until submission finishes.
Also:
Co-Authored-By: Claude Opus 5.5 [email protected]
Partial Fix: #1617
@coderabbitai[bot] on GitHub · 2026-10-20 02:54 UTC · original · edited 2026-10-22 00:51 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
bc61a3a6-09f2-436a-b390-eb84b62c2244📥 Commits
Reviewing files that changed from the base of the PR and between 903861cba9f96dd5f22c0b285fdb4eb08a2f1ded and
392966bf34.📒 Files selected for processing: 2
src/libs/libAudio2.cpptests/AudioOut2PortTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Audio queueing now stores each context’s PCM, gain, and object mix data in dedicated submission storage. It releases the global state mutex before backend output. Context and port destruction wait for in-flight submissions before closing audio handles. A new test checks cross-context progress, stable submission data, and concurrent destruction while output is blocked.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix · Severity of issue fixed: Low
Merge Risk: ⚪ Minimal · up to
39296No outstanding audio submission issue is established; the PR is mergeable after normal checks.
Pre-merge checks:
4 ·
1
#1617requires undistorted audio. The change addresses the AudioOut2 contention that can cause audio stutter or distortion. It snapshots PCM and gain data under the state mutex, su…#1617. Submission buffering, per-context synchronization, safe handle destruction, and the blocked-push regression tes…Full details: Linked Issues check
Explanation
Active direct issue
#1617requires undistorted audio. The change addresses the AudioOut2 contention that can cause audio stutter or distortion. It snapshots PCM and gain data under the state mutex, submits outside that mutex, and protects each context submission until backend output completes. The regression test verifies that a blocked push in one context does not block another context and that destruction does not close in-use devices. The issue's completed illumination item is not an active requirement.Full details: Out of Scope Changes check
Explanation
The changed implementation and test code support the AudioOut2 audio objective in
#1617. Submission buffering, per-context synchronization, safe handle destruction, and the blocked-push regression test are connected to that objective. No unrelated change is shown.Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-20 02:54 UTC · original · edited 2026-10-20 07:59 UTC
On
src/libs/libAudio2.cppline 353 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use the device-derived queue level only when the context feeds the device.
audioout2_device_queued_frames_lockedreturnstruefor any port or object handle with an open SDL stream. It does not check whether PCM is being submitted. The branch then setsstate->queuedfrom the device queue on every update.Consider a context that has open streams and empty
pcm_data. This happens before the first PCM attribute, and afterAudioOut2PortSetAttributesclears PCM with a null pointer. In that state:device_framesstays at 0, sostate->queuedresets to 0 on every update.use_device_clockisfalsebecauseaudioout2_context_has_queueable_devicerequires PCM.state->queued < state->queue_depthcheck always passes.audioout2_queue_context_audiohas no params and returns at once.As a result, blocking
AudioOut2ContextPushcalls never sleep. Async pushes never returnAUDIO_OUT2_ERROR_NOT_READY. A guest audio thread that relies on push backpressure spins at full CPU, and its audio clock runs faster than real time.The comment at Lines 696-698 says that pushes without PCM depend on queue-depth backpressure. The old wall-clock model gave that backpressure because
queued++accumulated and drained over time. The new branch overwritesqueuedon every update, so that backpressure is lost.Fix: guard the device branch with
audioout2_context_has_queueable_device(*state). In all other cases, fall back to the wall-clock model.🐛 Proposed fix
audioout2_context_has_queueable_deviceis defined at Line 416, after this function. Add a forward declaration next to the one at Lines 330-331.✅ Addressed in commit e0166ff
@coderabbitai[bot] on GitHub · 2026-10-20 02:54 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
9de56410-93dd-4ad4-ac79-a66386bd4df7📥 Commits
Reviewing files that changed from the base of the PR and between
f186b35706and 1b6f5ec330be4b3a6a1e18c3a1adac01b7ed1468.📒 Files selected for processing: 3
src/libs/audio.cppsrc/libs/audio_internal.hsrc/libs/libAudio2.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@MrBigBritches on GitHub · 2026-10-20 08:00 UTC · original
Fixed in e0166ff: the device-derived queue level is only used when the context is submitting PCM (audioout2_context_has_queueable_device); otherwise the wall-clock model keeps push backpressure.
@coderabbitai[bot] on GitHub · 2026-10-20 08:19 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
3bb6ea07-e3e6-4587-89a5-7f9580436290📥 Commits
Reviewing files that changed from the base of the PR and between e0166ff99074fdbcdd2d8ddc794a2076ec973590 and 903861cba9f96dd5f22c0b285fdb4eb08a2f1ded.
📒 Files selected for processing: 1
tests/AudioOut2PortTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.