fix(opus): remove artificial decoder delay with bundled libopus #8739

Merged
p3n1cillin merged 3 commits from upstream-pr/8739 into main 2026-10-23 07:07:52 +00:00
p3n1cillin commented 2026-10-20 23:03:27 +00:00 (Migrated from github.com)

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 libSceOpusDec and libSceOpusCeltDec. 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 import libssp-0.dll. Release archives carry its notice as libs/licenses/opus.txt, from the bundled source. The validation errors and precedence recovered on main are 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 main d2b1c3edd5: Windows full Release build, guest_opus_dec, guest_opus_celt_dec and the packaging tests pass. On WSL Ubuntu both opus tests and test_package_release pass. libopus.a symbols are HIDDEN in the objects, neither PRX exports or imports anything from libopus or libssp, and conventions pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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:4943735634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8739). Originally posted by [p3n1cillin](https://github.com/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](https://github.com/xiph/opus/tree/22244de5a79bd1d6d623c32e72bf1954b56235be), decoding directly at the requested rate for both `libSceOpusDec` and `libSceOpusCeltDec`. 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 import `libssp-0.dll`. Release archives carry its notice as `libs/licenses/opus.txt`, from the bundled source. The validation errors and precedence recovered on `main` are 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 `main` d2b1c3edd5: Windows full Release build, `guest_opus_dec`, `guest_opus_celt_dec` and the packaging tests pass. On WSL Ubuntu both opus tests and `test_package_release` pass. `libopus.a` symbols are `HIDDEN` in the objects, neither PRX exports or imports anything from libopus or libssp, and conventions pass. <!-- 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. --> ### 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 - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-20 23:07:30 +00:00 (Migrated from github.com)

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() sets BUILD_SHARED_LIBS to OFF, 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.a link option in cmake/Opus.cmake is 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5592917224 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8739#pullrequestreview-5592917224). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T23:07:30Z. **Review:** COMMENTED --- One platform-specific check remains for the stated symbol-hiding guarantee. `add_bundled_opus()` sets `BUILD_SHARED_LIBS` to `OFF`, 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.a` link option in `cmake/Opus.cmake` is 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.
MarcZX10 commented 2026-10-20 23:39:16 +00:00 (Migrated from github.com)

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.a is 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 record nm/llvm-nm output for the two PRX libraries (or add an Apple linker export restriction) before claiming the hiding guarantee across hosts.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304265565 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8739#issuecomment-6304265565). Originally posted by [MarcZX10](https://github.com/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.a` is 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 record `nm`/`llvm-nm` output for the two PRX libraries (or add an Apple linker export restriction) before claiming the hiding guarantee across hosts.
oneandonlydean commented 2026-10-21 06:16:19 +00:00 (Migrated from github.com)

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, main has started packaging third-party notices through the licenses list in tools/package_release.py: each one is copied from 3rdparty/<name>/COPYING into libs/licenses/<name>.txt in 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 the configure_file copy in cmake/Opus.cmake and libs/COPYING.opus? The two packaging tests would then check libs/licenses/opus.txt.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309441090 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8739#issuecomment-6309441090). Originally posted by [oneandonlydean](https://github.com/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, `main` has started packaging third-party notices through the `licenses` list in `tools/package_release.py`: each one is copied from `3rdparty/<name>/COPYING` into `libs/licenses/<name>.txt` in 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 the `configure_file` copy in `cmake/Opus.cmake` and `libs/COPYING.opus`? The two packaging tests would then check `libs/licenses/opus.txt`.
hypermoist commented 2026-10-22 13:29:03 +00:00 (Migrated from github.com)

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.cmake turns on -fstack-protector-strong and FORTIFY_SOURCE whenever it finds libssp, and then links ssp. As a result, libSceOpusDec.prx and libSceOpusCeltDec.prx import libssp-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_dec and guest_opus_celt_dec can't start: the loader fails with c0000135 before any test code runs. You can confirm with objdump -p libSceOpusDec.prx | grep "DLL Name".

Setting these two in add_bundled_opus before the add_subdirectory fixes it:

    set(OPUS_STACK_PROTECTOR OFF)
    set(OPUS_FORTIFY_SOURCE OFF)

After that the prx imports only the usual runtime DLLs and both tests pass under Wine. The fix is commit 27c0acabe2 in #9764; feel free to take it here, and I'll drop it from #9764 once this PR has it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341964610 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8739#issuecomment-6341964610). Originally posted by [hypermoist](https://github.com/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.cmake` turns on `-fstack-protector-strong` and `FORTIFY_SOURCE` whenever it finds libssp, and then links `ssp`. As a result, `libSceOpusDec.prx` and `libSceOpusCeltDec.prx` import `libssp-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_dec` and `guest_opus_celt_dec` can't start: the loader fails with c0000135 before any test code runs. You can confirm with `objdump -p libSceOpusDec.prx | grep "DLL Name"`. Setting these two in `add_bundled_opus` before the `add_subdirectory` fixes it: ```cmake set(OPUS_STACK_PROTECTOR OFF) set(OPUS_FORTIFY_SOURCE OFF) ``` After that the prx imports only the usual runtime DLLs and both tests pass under Wine. The fix is commit 27c0acabe2 in #9764; feel free to take it here, and I'll drop it from #9764 once this PR has it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-22 23:44:06 +00:00 (Migrated from github.com)

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. main does not build the PRX libraries on macOS yet, so the tree is #8658 (feat/macos-port) @ 26d6b1197a merged with this PR @ a6e9733c17 (clean merge). Built only libSceOpusDec and libSceOpusCeltDec; I did not run the opus tests.

  • nm -gU and dyld_info -exports: libSceOpusDec.prx exports 14 symbols, libSceOpusCeltDec.prx 11, all sceOpus*Dec* NIDs. 0 opus_*, silk_* or celt_* symbols exported or imported; the decoder is linked in as local symbols (120 t _opus_/_silk_/_celt_ per library).
  • nm -m libopus.a: 448 defined globals, all private external, _opus_decode and _opus_decoder_create included; 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.
  • Control: dropping C_VISIBILITY_PRESET hidden and OPUS_EXPORT= from cmake/Opus.cmake makes each PRX export 247 libopus symbols (52 opus_*, 112 silk_*, 12 celt_*, plus others), opus_decode among 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5622262086 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8739#pullrequestreview-5622262086). Originally posted by [jotitadev](https://github.com/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. `main` does not build the PRX libraries on macOS yet, so the tree is #8658 (`feat/macos-port`) @ 26d6b1197a merged with this PR @ a6e9733c17 (clean merge). Built only `libSceOpusDec` and `libSceOpusCeltDec`; I did not run the opus tests. - `nm -gU` and `dyld_info -exports`: `libSceOpusDec.prx` exports 14 symbols, `libSceOpusCeltDec.prx` 11, all `sceOpus*Dec*` NIDs. 0 `opus_*`, `silk_*` or `celt_*` symbols exported or imported; the decoder is linked in as local symbols (120 `t _opus_/_silk_/_celt_` per library). - `nm -m libopus.a`: 448 defined globals, all `private external`, `_opus_decode` and `_opus_decoder_create` included; 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. - Control: dropping `C_VISIBILITY_PRESET hidden` and `OPUS_EXPORT=` from `cmake/Opus.cmake` makes each PRX export 247 libopus symbols (52 `opus_*`, 112 `silk_*`, 12 `celt_*`, plus others), `opus_decode` among 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.
MarcZX10 commented 2026-10-23 05:17:03 +00:00 (Migrated from github.com)

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 current upstream/main (merge base 7b32a842f), 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624193315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8739#pullrequestreview-5624193315). Originally posted by [MarcZX10](https://github.com/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 current `upstream/main` (merge base `7b32a842f`), 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.
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!8739
No description provided.