fix(ajm): honor Opus gapless resets #6040

Merged
Ondra97 merged 1 commit from upstream-pr/6040 into main 2026-10-17 04:11:49 +00:00
Ondra97 commented 2026-10-14 20:15:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T20:15:38Z.


What

After an Opus segment reaches its gapless sample limit, sceAjmBatchJobSetGaplessDecode with reset=1 does not restore output on main: the next valid packet is consumed with result 0, but produces no PCM. For a 500-sample stereo S16 segment, the first segment writes 2000 bytes and the second writes 0 instead of 2000.

The gapless reset clears segmentSamples, while RunOpus compares the limit with the lifetime totalDecodedSamples. Opus now counts and clips against the existing segment counter, as the other AJM decoders do, and keeps the cumulative stream sideband count.

Tested

Windows 11 Pro, build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Release, BUILD_TESTING=ON, full build-runtime configuration.

  • Main 411e5e6d9, production unchanged: existing guest_ajm passed. With the new public-API regression, the second segment failed with Opus gapless segment 1 wrote 0 bytes, expected 2000 (0.19 s).
  • The regression checks three consecutive gapless resets, PCM equality against an unlimited reference decoder, input consumption, cumulative decoded counts, skip reporting and output canaries. It covers 960-frame buffers, 128-frame buffers with pending PCM drained through empty-input jobs, a control with reset=0, and 2x resampling without clearing the decoder or resampler.
  • Full Windows build passed before and after rebase onto f785b88a6. The final audio suite and patched-library audit passed 33/33 in 5.53 s, without skips. Conventions, whitespace and test registration checks passed. The repository overlap checker reports no overlap with open pull requests, on the same current main.
  • I manually compared the exact source and test changes in #5517 (911e6c83): it extends multichannel Opus mapping family 255 and does not implement this gapless fix. The adjacent ATRAC9 configuration fix #5658 is also separate. All open-PR file lists were checked, including older and large PRs beyond the first 100 files.
  • Retail titles, Linux, ASan and PS5 hardware were not tested. This PR claims a reproduced runtime API correction; no title unblock or console timing result.

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
  • Unblocks: none
  • GPUs tested: n/a (AJM audio decoder only)
  • AI-assisted: yes (Codex); I reviewed the change and ran the local validation.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4863922897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6040). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-14T20:15:38Z. --- ### What After an Opus segment reaches its gapless sample limit, `sceAjmBatchJobSetGaplessDecode` with `reset=1` does not restore output on `main`: the next valid packet is consumed with result 0, but produces no PCM. For a 500-sample stereo S16 segment, the first segment writes 2000 bytes and the second writes 0 instead of 2000. The gapless reset clears `segmentSamples`, while `RunOpus` compares the limit with the lifetime `totalDecodedSamples`. Opus now counts and clips against the existing segment counter, as the other AJM decoders do, and keeps the cumulative stream sideband count. ### Tested Windows 11 Pro, build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Release, `BUILD_TESTING=ON`, full `build-runtime` configuration. - Main `411e5e6d9`, production unchanged: existing `guest_ajm` passed. With the new public-API regression, the second segment failed with `Opus gapless segment 1 wrote 0 bytes, expected 2000` (0.19 s). - The regression checks three consecutive gapless resets, PCM equality against an unlimited reference decoder, input consumption, cumulative decoded counts, skip reporting and output canaries. It covers 960-frame buffers, 128-frame buffers with pending PCM drained through empty-input jobs, a control with `reset=0`, and 2x resampling without clearing the decoder or resampler. - Full Windows build passed before and after rebase onto `f785b88a6`. The final audio suite and patched-library audit passed 33/33 in 5.53 s, without skips. Conventions, whitespace and test registration checks passed. The repository overlap checker reports no overlap with open pull requests, on the same current main. - I manually compared the exact source and test changes in #5517 (`911e6c83`): it extends multichannel Opus mapping family 255 and does not implement this gapless fix. The adjacent ATRAC9 configuration fix #5658 is also separate. All open-PR file lists were checked, including older and large PRs beyond the first 100 files. - Retail titles, Linux, ASan and PS5 hardware were not tested. This PR claims a reproduced runtime API correction; no title unblock or console timing result. ### Checklist - [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 - [x] Unblocks: none - [x] GPUs tested: n/a (AJM audio decoder only) - [x] AI-assisted: yes (Codex); I reviewed the change and ran the local validation.
github-actions[bot] commented 2026-10-15 12:13:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:13:46Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestAjm.cpp
PR 6721 core/libs/prx/libSceAjm.native/src/Ajm.cpp
PR 6841 core/libs/prx/libSceAjm.native/src/Ajm.cpp
core/libs/tests/GuestAjm.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191778107 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6040#issuecomment-6191778107). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:13:46Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestAjm.cpp` | | [PR 6721](https://www.github.com/boykopovar/AnyPS5/pull/6721) | `core/libs/prx/libSceAjm.native/src/Ajm.cpp` | | [PR 6841](https://www.github.com/boykopovar/AnyPS5/pull/6841) | `core/libs/prx/libSceAjm.native/src/Ajm.cpp`<br>`core/libs/tests/GuestAjm.cpp` |
MarcZX10 commented 2026-10-16 21:01:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T21:01:44Z.


The overlap bot flags #6841 at the same GuestAjm.cpp insertion point. The new test covers codec-23 resampling, while yours covers Opus gapless resets; the behaviors are separate, so the merge should retain both test blocks. #6841 is also behind current main and has been asked to rebase and coordinate. Please agree with its author on merge order and preserve both tests during integration.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224623415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6040#issuecomment-6224623415). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T21:01:44Z. --- The overlap bot flags #6841 at the same `GuestAjm.cpp` insertion point. The new test covers codec-23 resampling, while yours covers Opus gapless resets; the behaviors are separate, so the merge should retain both test blocks. #6841 is also behind current `main` and has been asked to rebase and coordinate. Please agree with its author on merge order and preserve both tests during integration.
adriadam10 commented 2026-10-16 21:27:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T21:27:50Z.


Checked RunOpus now clips and counts against segmentSamples like the other AJM decoders, keeping totalDecodedSamples cumulative. guest_ajm passes and fails without the Ajm.cpp change (three gapless resets, 960/128-frame buffers, reset=0 control, 2x resampling). The overlap with #6841 is only adjacent test blocks in GuestAjm.cpp; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225033994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6040#issuecomment-6225033994). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T21:27:50Z. --- Checked `RunOpus` now clips and counts against `segmentSamples` like the other AJM decoders, keeping `totalDecodedSamples` cumulative. `guest_ajm` passes and fails without the `Ajm.cpp` change (three gapless resets, 960/128-frame buffers, `reset=0` control, 2x resampling). The overlap with #6841 is only adjacent test blocks in `GuestAjm.cpp`; merging.
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!6040
No description provided.