fix(libSceVideodec2): decode after a flush without a reset #7252

Merged
thuanquang merged 1 commit from upstream-pr/7252 into main 2026-10-17 21:38:59 +00:00
thuanquang commented 2026-10-17 19:45:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-17T19:45:22Z.


What

TEKKEN DARK RESURRECTION (PPSA31371) runs in Sony's PSP emulator. With its first stop (#7118, #7251) cleared locally, the reporter's run reaches the Bandai Namco logo, starts a 480x272 H.264 video and aborts with Videodec2: reset required after flushing (#7118).

sceVideodec2Decode threw whenever it was called after sceVideodec2Flush without a sceVideodec2Reset in between, so the title makes that call. Since the title runs on the console, the console's library accepts it.

sceVideodec2Decode now restarts FFmpeg's decoder after a flush (avcodec_flush_buffers, which FFmpeg requires before a drained decoder takes new packets) and decodes the unit. The decoder keeps what sceVideodec2Reset would clear:

  • pictures the flush already decoded but has not returned yet, which come out before the new ones;
  • picture ownership;
  • held parameter-set units;
  • VP9 references.

shadPS4's VdecDecoder::Decode does the same when FFmpeg reports end of stream (videodec2_impl.cpp).

A technical debt entry records that what the console returns for pictures still queued at that point, and for a stream that continues across the flush without a new IDR picture, is not measured.

Tested

Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON:

  • guest_videodec2 has a new case, testDecodeAfterFlush. It flushes a new H.264 decoder that has decoded nothing, then twice decodes the 6-picture fixture clip and flushes it until no picture is left, with no reset in between. Every picture must come out in display order with its timestamps and match the reference NV12 hash.
    • With sceVideodec2Decode as on main it fails with the title's message: Videodec2: reset required after flushing.
    • With this change it passes, and so do the existing decode, HEVC, VP9, 10-bit and ownership cases.
  • Full ctest --parallel 4 --timeout 120 on main 922dc8999 with this change: 1400 tests. Only agc_driver_lds_mixed_width_atomics (#5271, fixed by #6976) and agc_driver_layered_volume_vertex_no_gpl (#4768) fail, as on main here.
  • python tools/check_conventions.py --base origin/main with this title and body passes.
  • Not tested:
    • the title itself, which I don't have (@cavazzatommaso could rerun with #7251);
    • Linux and macOS (CI runs guest_videodec2 there).

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: the second stop of TEKKEN DARK RESURRECTION (PPSA31371), #7118 (its first is #7251)
  • GPUs tested: none needed (CPU-only change)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4903361220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7252). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-17T19:45:22Z. --- ### What TEKKEN DARK RESURRECTION (PPSA31371) runs in Sony's PSP emulator. With its first stop (#7118, #7251) cleared locally, the reporter's run reaches the Bandai Namco logo, starts a 480x272 H.264 video and aborts with `Videodec2: reset required after flushing` (#7118). `sceVideodec2Decode` threw whenever it was called after `sceVideodec2Flush` without a `sceVideodec2Reset` in between, so the title makes that call. Since the title runs on the console, the console's library accepts it. `sceVideodec2Decode` now restarts FFmpeg's decoder after a flush (`avcodec_flush_buffers`, which FFmpeg requires before a drained decoder takes new packets) and decodes the unit. The decoder keeps what `sceVideodec2Reset` would clear: - pictures the flush already decoded but has not returned yet, which come out before the new ones; - picture ownership; - held parameter-set units; - VP9 references. shadPS4's `VdecDecoder::Decode` does the same when FFmpeg reports end of stream ([videodec2_impl.cpp](https://github.com/shadps4-emu/shadPS4/blob/4d3853fe48833e765574737fd3293c36b852f089/src/core/libraries/videodec/videodec2_impl.cpp#L65-L70)). A technical debt entry records that what the console returns for pictures still queued at that point, and for a stream that continues across the flush without a new IDR picture, is not measured. ### Tested Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`: - `guest_videodec2` has a new case, `testDecodeAfterFlush`. It flushes a new H.264 decoder that has decoded nothing, then twice decodes the 6-picture fixture clip and flushes it until no picture is left, with no reset in between. Every picture must come out in display order with its timestamps and match the reference NV12 hash. - With `sceVideodec2Decode` as on `main` it fails with the title's message: `Videodec2: reset required after flushing`. - With this change it passes, and so do the existing decode, HEVC, VP9, 10-bit and ownership cases. - Full `ctest --parallel 4 --timeout 120` on `main` `922dc8999` with this change: 1400 tests. Only `agc_driver_lds_mixed_width_atomics` (#5271, fixed by #6976) and `agc_driver_layered_volume_vertex_no_gpl` (#4768) fail, as on `main` here. - `python tools/check_conventions.py --base origin/main` with this title and body passes. - Not tested: - the title itself, which I don't have (@cavazzatommaso could rerun with #7251); - Linux and macOS (CI runs `guest_videodec2` there). ### 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: the second stop of TEKKEN DARK RESURRECTION (PPSA31371), #7118 (its first is #7251) - [x] GPUs tested: none needed (CPU-only change) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-17 20:34:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T20:34:21Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6709 docs/dev/debt/libSceVideodec2.md L13

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/GuestVideodec2.cpp
PR 6414 core/libs/prx/libSceVideodec2/Export.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6240589833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7252#issuecomment-6240589833). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T20:34:21Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6709](https://www.github.com/boykopovar/AnyPS5/pull/6709) | `docs/dev/debt/libSceVideodec2.md` [L13](https://github.com/boykopovar/AnyPS5/blob/922dc8999ea024c9d5bce46049aa22d6dd72f534/docs/dev/debt/libSceVideodec2.md#L13) | | | 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/GuestVideodec2.cpp` | | [PR 6414](https://www.github.com/boykopovar/AnyPS5/pull/6414) | `core/libs/prx/libSceVideodec2/Export.cpp` |
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!7252
No description provided.