xapu: optional Opus packet decode behind X2W_WITH_OPUS #2318
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2326"
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 R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T12:26:06Z.
Refs #1145, #1887
What
Optional Opus packet decoding in the
xapu.dllstand-in, as agreed in #1145.X2W_WITH_OPUS, OFF by default. When on,find_package(Opus CONFIG REQUIRED)linksOpus::opusintostartup_stub_xapu. The default configure and CI do not depend on libopus.X2W_AUDIO_PERMISSIVE=1andX2W_XAPU_TYPED_COMPLETIONS=1, a type 3 command decodes one Opus packet into the caller's output (interleaved float). The result carries the decoded byte count at+0x34.+0x1Crate (float),+0x24frames,+0x28/+0x2Cpacket bytes and pointer,+0x34/+0x38output bytes and pointer.XApuDisconnectfree it.E_INVALIDARGfor a bad rate, channel count, frames, packet, output or slot;E_FAILfor a packet libopus rejects;E_POINTERfor a command shorter than0x40bytes;E_OUTOFMEMORYfor a full queue, checked before any decode, reset or close.startup_xapu_queueis unchanged and passes in both builds.src/startup_stubs/THIRD_PARTY_NOTICES.md. The repo contains no libopus source or binary.Tests
startup_xapu_opusis registered only whenX2W_WITH_OPUS=ON. It encodes generated 1 kHz tones with the same libopus; there are no binary fixtures. It checks:E_FAILwith the output and queue untouched;Environment: Windows 11 (26300), MSVC 19.44, Ninja Debug, commit
ccde4c1e(based on31f46857; merges cleanly into current main).libopus 1.5.2 was built from
opus-1.5.2.tar.gz(SHA-25665c1d2f7…7ce1) with-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>, because the stand-ins link the static runtime.Negative controls: each mutant was built, then reverted.
Also passing:
tests/docs_links_check.py,tests/bidi_controls_check.py,git diff --check. Not run: Release builds.Local observation only
With a local libopus build of this decode path, I heard the decoded UI sounds through the desktop audio sink. This is a local observation only. It does not show that a title's audio works, and full-game startup remains unverified.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:28:32Z.
Review: COMMENTED
Review of head
6139a4b0a7f3f99087f2073003d1647c8fdde351(xapu: optional Opus packet decode behind X2W_WITH_OPUS).Scope read:
git diff --stat origin/main...HEAD(5 files, +615/-6), full diff ofsrc/startup_stubs/xapu.cppandCMakeLists.txt, notices and test layout.Commands executed locally (Linux):
python3 tests/docs_links_check.py-> Self-test passed. Checked 19 Markdown files and 452 links.python3 tests/bidi_controls_check.py-> Checked 1613 tracked files: no bidirectional controls.git diff --check origin/main...HEAD-> clean (rc=0).gh pr view-> MERGEABLE, title neutral.gh pr checks-> all jobs still pending at review time.Not run: the C++ code includes
windows.hand needs libopus. No libopus is installed on this Linux host, so I could not build or mutatestartup_xapu_opus_check. No Win2025 run was queued, because the default CI configure does not enableX2W_WITH_OPUS. So the findings below come from reading the code.What looks right:
X2W_HAVE_OPUS,push_resultis still used. The only new write is the zero+0x34value, and the result buffer was already zeroed.reserve_resultbefore the decode means a full queue refuses the command before any decoder changes.place_resultcannot fail after that.frames <= 5760andchannelsin {1,2} keep output at or below 46080 bytes.scratchholds 5760*2 floats.out_bytes % (frames*4)cannot overflow at these sizes.readable(packet)andwritable(out)are checked before use, and the output is only written after a successful decode. The shared staticscratchis guarded byconnection_lock.Findings:
CMakeLists.txt:510-518, test gating): the whole Opus path, including the new test, only builds withX2W_WITH_OPUS=ON. Default CI never compiles#ifdef X2W_HAVE_OPUScode, so it can rot silently. Please add one CI or documented Win2025 job with libopus 1.5.2 that builds and runsstartup_xapu_opus, and put the result in the PR body.src/startup_stubs/xapu.cpp:~162, header comment): "a refused decode ... leaves the output untouched / changes no decoder state" is true for output and for fresh decoders. For an existing slot decoder, a corrupt packet that fails insideopus_decode_floatcan still change libopus' internal state. Either soften the wording or decode into a cloned state. The first is enough.xapu.cppcomment): the cap comment changed from 128 KiB to 192 KiB, which matches the 12-byte entry (16384 x 12). Fine, just confirming it is intentional.Mutation: not possible here for the reason above (no libopus, Windows-only sources). Please confirm on Windows that flipping the
channelscheck or droppingreserve_resultbefore the decode failsstartup_xapu_opus.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:46:06Z.
Review: COMMENTED
Review of head
3ee95fa5d7bc09556576cd8cb0ea92a4e538cac2(comment only, no verdict).Result: no P1, no P2. Two nits.
Commands executed locally (Linux worktree of the PR head):
git diff --stat origin/main...HEAD: 5 files, +620/-6python3 tests/docs_links_check.py: self-test passed, 19 Markdown files, 452 linkspython3 tests/bidi_controls_check.py: 1613 files, no bidirectional controlsgit diff --check origin/main...HEAD: cleangh pr checks 2326: Linux Python checks, gfx1013 fixtures and Windows build/test all pass; PR is MERGEABLERead through
src/startup_stubs/xapu.cppandCMakeLists.txtagainst the description:reserve_result) runs before any decode, reset or close, andplace_resultcannot fail afterwards. So a full queue never changes decoder state.connection_lock. Output is copied only after the result is queued. Size is bounded (max_frames * 2floats, andout_bytes == frames * channels * 4with channels 1 or 2), so the copy cannot overrun the scratch.Connectionis created withnew (std::nothrow)and every new member has a default initializer, so the 256 decoder slots start empty.XApuDisconnectfrees them all.X2W_WITH_OPUSOFF): the only change is the 12-byteQueueEntry; the comment and docs on the 192 KiB cap match.Findings:
src/startup_stubs/xapu.cpp(decode_packet):opus_decoder_createfailures of any kind returnE_OUTOFMEMORY. Rate and channels are validated just above, so only a real allocation failure can reach it. Fine as is; a one-line comment would say so.CMakeLists.txt(X2W_WITH_OPUSblock): the new decode path andstartup_xapu_opusare not built by CI, because the option is OFF there. The PR's local results are therefore the only evidence for that path. Fine for an opt-in feature, but later edits to it can regress without a CI signal.Not run by me:
startup_xapu_opus. They need an installed libopus built with the static MSVC runtime, and this Linux box has none. I also did not run the Windows VM (win2025) because the VM is not set up with libopus.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T12:40:01Z.
I built upstream libopus 1.5.2 with the static MSVC runtime and independently verified Windows Release. With
X2W_WITH_OPUS=ON, the queue and Opus checks passed (2/2). With the default option off, the queue check passed (1/1). I added checks for a malformed packet on an already active slot at the same rate and for a valid packet whose output capacity is too small. Both were rejected, the queue and output guards held, and the next packet still matched the independent reference stream. This is source-built coverage. The new head3ee95fa5also distinguishes retaining the decoder object from any provider-specific internal state after a decoder error.