fix(opus): remove artificial decoder delay with bundled libopus #8739
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8739"
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 p3n1cillin on 2026-10-20T23:03:27Z.
What
The current FFmpeg Opus backend pads narrowband packets with silence and resamples lower creation rates from 48 kHz, delaying the PCM. Replace it with bundled libopus 1.6.1, decoding directly at the requested rate for both
libSceOpusDecandlibSceOpusCeltDec. Remove the pending PCM queue and FFmpeg resampler.The dependency is a pinned submodule built statically from source. libopus is compiled with hidden visibility and an empty
OPUS_EXPORT, so its symbols stay internal on every platform. Its stack protector and FORTIFY_SOURCE options are off, so the MinGW libraries don't importlibssp-0.dll. Release archives carry its notice aslibs/licenses/opus.txt, from the bundled source. The validation errors and precedence recovered onmainare kept. Console PCM equivalence remains unverified in the library debt files.Tested
Windows 11 Pro (26300), WinLibs GCC 15.2.0, and WSL Ubuntu 26.04.1 LTS, GCC 15.2.0: both complete library suites (
guest_opus_dec,guest_opus_celt_dec) pass. The added PCM comparisons fail on the original FFmpeg implementation in both libraries at 8 kHz mono, then pass with the new backend.Compared PCM sample for sample with direct libopus calls at 8000, 12000, 16000, 24000 and 48000 Hz, in mono and stereo, across SILK/hybrid bandwidth transitions and CELT packets. Includes a repacketized 120 ms packet, output guards, odd byte capacities, too-small buffers, invalid framing and decoder/context lifetime checks. No game or console run.
All executed packaging tests pass on both hosts: 40 tests discovered, with 1 host-dependent skip on Windows and 5 on Linux. They cover notice inclusion in ZIP and tar.gz and rejection of a missing notice. Verified the generated notice matches the submodule source and the built libraries do not export libopus internals. Relinker-only configuration still succeeds.
Conventions and whitespace checks pass. Ran
tools/pr_overlap.py --branch codex/opus-native-decoder-20261021: no confirmed conflict or competing implementation. Reviewed the shared-file diffs of the stale PRs the tool could not compare; they add other dependencies/notices or reorganize tests.Update 2026-10-22, rebased on
maind2b1c3edd5: Windows full Release build,guest_opus_dec,guest_opus_celt_decand the packaging tests pass. On WSL Ubuntu both opus tests andtest_package_releasepass.libopus.asymbols areHIDDENin the objects, neither PRX exports or imports anything from libopus or libssp, and conventions pass.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T23:07:30Z.
Review: COMMENTED
One platform-specific check remains for the stated symbol-hiding guarantee.
add_bundled_opus()setsBUILD_SHARED_LIBStoOFF, so the pinned libopus CMake only applies its hidden visibility preset when building a shared Opus library, which this is not. The--exclude-libs,libopus.alink option incmake/Opus.cmakeis added only for MinGW/Linux; there is no corresponding Apple export restriction. Could you verify the exported symbols of the macOS PRX libraries and hide libopus internals there too if they are visible? The current PR test report covers Windows and WSL, and these hosted jobs build the relinker rather than the PRX libraries.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T23:39:16Z.
I see the updated report now says the built libraries do not export libopus internals, but the listed builds/export inspection are Windows and WSL Ubuntu; the hosted macOS jobs here are relinker-only. Could you clarify whether you checked the PRX exports from a macOS build specifically? The concern is still the Apple static-link path:
--exclude-libs,libopus.ais only added for MinGW/Linux, and the pinned Opus CMake visibility preset is conditional on a shared Opus build. If macOS has not been checked yet, please recordnm/llvm-nmoutput for the two PRX libraries (or add an Apple linker export restriction) before claiming the hiding guarantee across hosts.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T06:16:19Z.
@p3n1cillin thanks, the delay removal and the reference comparisons look right to us, and the comparisons do catch a wrong decode rate or a one-sample shift when we try those.
One packaging change, please. Since this branch was cut,
mainhas started packaging third-party notices through thelicenseslist intools/package_release.py: each one is copied from3rdparty/<name>/COPYINGintolibs/licenses/<name>.txtin the archives (see the vgmstream entry). Could the Opus notice follow the same path,licenses.append((ROOT / "3rdparty/opus/COPYING", "libs/licenses/opus.txt")), instead of theconfigure_filecopy incmake/Opus.cmakeandlibs/COPYING.opus? The two packaging tests would then checklibs/licenses/opus.txt.Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T13:29:03Z.
@p3n1cillin a Windows packaging issue with the bundled libopus, found while building #9764 on top of this PR.
On MinGW, libopus's
OpusConfig.cmaketurns on-fstack-protector-strongandFORTIFY_SOURCEwhenever it finds libssp, and then linksssp. As a result,libSceOpusDec.prxandlibSceOpusCeltDec.prximportlibssp-0.dll, which isn't one of the runtime DLLs we ship. Under Wine (MinGW-w64 GCC 16.2.0, Wine 11.20),guest_opus_decandguest_opus_celt_deccan't start: the loader fails with c0000135 before any test code runs. You can confirm withobjdump -p libSceOpusDec.prx | grep "DLL Name".Setting these two in
add_bundled_opusbefore theadd_subdirectoryfixes it:After that the prx imports only the usual runtime DLLs and both tests pass under Wine. The fix is commit
27c0acabe2in #9764; feel free to take it here, and I'll drop it from #9764 once this PR has it.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T23:44:06Z.
Review: COMMENTED
macOS check of the libopus symbol hiding asked about above, on the Apple static-link path.
Mac M2 Max, macOS 27.2, Apple clang 21.0.0, x86_64 (Rosetta), Release.
maindoes not build the PRX libraries on macOS yet, so the tree is #8658 (feat/macos-port) @26d6b1197amerged with this PR @a6e9733c17(clean merge). Built onlylibSceOpusDecandlibSceOpusCeltDec; I did not run the opus tests.nm -gUanddyld_info -exports:libSceOpusDec.prxexports 14 symbols,libSceOpusCeltDec.prx11, allsceOpus*Dec*NIDs. 0opus_*,silk_*orcelt_*symbols exported or imported; the decoder is linked in as local symbols (120t _opus_/_silk_/_celt_per library).nm -m libopus.a: 448 defined globals, allprivate external,_opus_decodeand_opus_decoder_createincluded; 0 public externals. The only Apple link options on these targets are the existing-unexported_symbol _mbedtls_*/_psa_*, so the hiding comes from the compile-time visibility alone.C_VISIBILITY_PRESET hiddenandOPUS_EXPORT=fromcmake/Opus.cmakemakes each PRX export 247 libopus symbols (52opus_*, 112silk_*, 12celt_*, plus others),opus_decodeamong them. So the Apple path needed the compile-time hiding, and the current head has it.Written with AI assistance (Claude Code). I ran the builds and checks above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:17:03Z.
Review: CHANGES_REQUESTED
The macOS symbol-visibility evidence in the latest thread resolves my earlier platform-specific question: the reported PRX exports contain only the expected NIDs, with libopus symbols local. The source change is focused, the license packaging tests cover both archive formats and missing-license failure, and the PR reports Windows/WSL decoder suites passing. Local diff whitespace, conventions, and registration checks pass; I have not independently run the decoder suites here.
One branch-freshness blocker remains:
tools/check_main_sync.py --base upstream/main --head <head>reports 3 commits ahead / 41 behind currentupstream/main(merge base7b32a842f), though it merges cleanly. CONTRIBUTING requires branches kept up to date. Please merge current main and rerun the decoder suites, packaging tests, and conventions on the resulting head before merge. This is a current-main request only, not a queue or intake objection.