fix(avplayer): add decode-ahead buffers for application video output #591

Merged
hamb3r merged 4 commits from upstream-pr/591 into main 2026-10-05 05:13:18 +00:00
hamb3r commented 2026-10-05 00:10:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-05T00:10:25Z.


What

Applications can request as few as 2 video output buffers in AvPlayer settings. When the application holds one buffer for display and uses SyncModeNone (dropping late frames on its own, common in Unity titles), a small decoding or scheduling delay causes playback to fall behind the game clock. The application then drops late frames faster than AvPlayer can recover, starving the video output permanently while audio continues.

Adds 4 internal decode-ahead frames to the video buffer pool (settings.videoBuffers + VideoDecodeAheadFrames) while keeping the application's requested output-buffer retained count semantics unchanged.

Ported from OverkillLabs2/SoS-PS5#13 by @saulob.

Tested

Windows 10 / 11, AMD Ryzen 7 7700, NVIDIA GeForce RTX 3080. Tested with God of War: Sons of Sparta (PPSA28997): verified continuous, stutter-free playback of the intro video sequences and logo sections without freezing or stalls. Built with MinGW-w64 GCC 15.2.0. git diff --check is clean.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. I reviewed and take responsibility for every line.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4738643629 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/591). Originally posted by [hamb3r](https://github.com/hamb3r) on 2026-10-05T00:10:25Z. --- ### What Applications can request as few as 2 video output buffers in AvPlayer settings. When the application holds one buffer for display and uses `SyncModeNone` (dropping late frames on its own, common in Unity titles), a small decoding or scheduling delay causes playback to fall behind the game clock. The application then drops late frames faster than AvPlayer can recover, starving the video output permanently while audio continues. Adds 4 internal decode-ahead frames to the video buffer pool (`settings.videoBuffers + VideoDecodeAheadFrames`) while keeping the application's requested output-buffer retained count semantics unchanged. Ported from OverkillLabs2/SoS-PS5#13 by @saulob. ### Tested Windows 10 / 11, AMD Ryzen 7 7700, NVIDIA GeForce RTX 3080. Tested with God of War: Sons of Sparta (PPSA28997): verified continuous, stutter-free playback of the intro video sequences and logo sections without freezing or stalls. Built with MinGW-w64 GCC 15.2.0. `git diff --check` is clean. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes. I reviewed and take responsibility for every line.
oneandonlydean commented 2026-10-05 01:18:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T01:18:37Z.


Thanks, the problem is real: with the minimum of 2 output buffers and nothing retained, one buffer is the frame the title holds and the decoder has a single spare, so it can only ever be one frame ahead.

One thing before it goes in: the 4 extra buffers come from the title's allocate_texture callback in its memory replacement, each pitch * height * 3 / 2 bytes (about 3 MB at 1080p, so about 12 MB more per player). A title that sizes its AvPlayer memory for the buffer count it asked for would now get SCE_AVPLAYER_ERROR_NO_MEMORY from sceAvPlayerAddSource where it worked before. How many buffers the console's player requests isn't known, so I'd either:

  1. add a line under "Unknown function info" in docs/dev/TechnicalDebt.md saying that the player requests num_output_video_framebuffers + 4 video buffers from the memory replacement and that the console's count is unknown, or
  2. keep the decode-ahead frames in host memory and copy one into an output buffer when it's handed out, which leaves the title's allocations as they are (at the cost of a copy per frame).

Either is fine with me. A test row in guest_avplayer with 2 buffers and sync mode none that takes frames late would also show the stall and the fix, but that's optional.

PPSA21564 plays its intro video through sceAvPlayerInit and sceAvPlayerGetVideoDataEx, so this path matters for my runs; I'll check that video here once it's updated. The CI run still needs workflow approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986483391 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/591#issuecomment-5986483391). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T01:18:37Z. --- Thanks, the problem is real: with the minimum of 2 output buffers and nothing retained, one buffer is the frame the title holds and the decoder has a single spare, so it can only ever be one frame ahead. One thing before it goes in: the 4 extra buffers come from the title's `allocate_texture` callback in its memory replacement, each `pitch * height * 3 / 2` bytes (about 3 MB at 1080p, so about 12 MB more per player). A title that sizes its AvPlayer memory for the buffer count it asked for would now get `SCE_AVPLAYER_ERROR_NO_MEMORY` from `sceAvPlayerAddSource` where it worked before. How many buffers the console's player requests isn't known, so I'd either: 1. add a line under "Unknown function info" in docs/dev/TechnicalDebt.md saying that the player requests `num_output_video_framebuffers` + 4 video buffers from the memory replacement and that the console's count is unknown, or 2. keep the decode-ahead frames in host memory and copy one into an output buffer when it's handed out, which leaves the title's allocations as they are (at the cost of a copy per frame). Either is fine with me. A test row in `guest_avplayer` with 2 buffers and sync mode none that takes frames late would also show the stall and the fix, but that's optional. PPSA21564 plays its intro video through `sceAvPlayerInit` and `sceAvPlayerGetVideoDataEx`, so this path matters for my runs; I'll check that video here once it's updated. The CI run still needs workflow approval.
hamb3r commented 2026-10-05 01:59:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-05T01:59:46Z.


Implemented in commit cf10b5e.

  • The requested video and audio buffers are allocated first.
  • Up to 4 decode-ahead video buffers are attempted only after the mandatory pools succeed.
  • If an optional allocation fails, all partially allocated optional buffers are released and playback continues with the requested video buffer count.
  • Added the behavior to TechnicalDebt.md.
  • Added GuestAvPlayer coverage for texture limits of 2, 4, and 6 buffers, including partial optional allocation rollback.

The Source.cpp and GuestAvPlayer.cpp translation units compile successfully. A full local link is currently blocked by the prebuilt FFmpeg archives referencing MSVC security-cookie symbols that are unavailable in this MinGW link setup; CI should provide the final build result.

@oneandonlydean, this is ready for review. Please verify the memory behavior and the PPSA21564 video path once CI completes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986823381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/591#issuecomment-5986823381). Originally posted by [hamb3r](https://github.com/hamb3r) on 2026-10-05T01:59:46Z. --- Implemented in commit [cf10b5e](https://github.com/boykopovar/AnyPS5/commit/cf10b5e60946a5e940851544c70f96dfb5e7a1f1). - The requested video and audio buffers are allocated first. - Up to 4 decode-ahead video buffers are attempted only after the mandatory pools succeed. - If an optional allocation fails, all partially allocated optional buffers are released and playback continues with the requested video buffer count. - Added the behavior to TechnicalDebt.md. - Added GuestAvPlayer coverage for texture limits of 2, 4, and 6 buffers, including partial optional allocation rollback. The Source.cpp and GuestAvPlayer.cpp translation units compile successfully. A full local link is currently blocked by the prebuilt FFmpeg archives referencing MSVC security-cookie symbols that are unavailable in this MinGW link setup; CI should provide the final build result. @oneandonlydean, this is ready for review. Please verify the memory behavior and the PPSA21564 video path once CI completes.
hamb3r commented 2026-10-05 02:07:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-05T02:07:17Z.


Follow-up fix in bb165d2a fixes the CI regression.

The /app0/missing.mp4 line is intentional: guest_avplayer verifies that a missing source returns OperationFailed. The actual failure was in the new memory-limit test helper: it changed the existing texture allocation counter from cumulative to active, while an older assertion relies on the cumulative count. The helper now counts active texture blocks separately and preserves the existing counter semantics.

The updated branch is pushed and CI is running again.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986888076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/591#issuecomment-5986888076). Originally posted by [hamb3r](https://github.com/hamb3r) on 2026-10-05T02:07:17Z. --- Follow-up fix in [bb165d2a](https://github.com/boykopovar/AnyPS5/commit/bb165d2ab45225a78adcf969545c5dc4cc9a6d14) fixes the CI regression. The /app0/missing.mp4 line is intentional: guest_avplayer verifies that a missing source returns OperationFailed. The actual failure was in the new memory-limit test helper: it changed the existing texture allocation counter from cumulative to active, while an older assertion relies on the cumulative count. The helper now counts active texture blocks separately and preserves the existing counter semantics. The updated branch is pushed and CI is running again.
hamb3r commented 2026-10-05 02:13:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-05T02:13:51Z.


Second follow-up fix in 86e5ae5c fixes the remaining guest_avplayer failure.

The texture limit check was still using the historical allocation counter, so later test cases inherited the count from earlier players and the limited allocator rejected even the mandatory buffers. Both the limit check and the assertion now use the current number of active texture blocks; the existing cumulative counter remains unchanged.

This was a test helper regression, not a CI infrastructure failure. The branch is pushed and CI is running again.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986946449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/591#issuecomment-5986946449). Originally posted by [hamb3r](https://github.com/hamb3r) on 2026-10-05T02:13:51Z. --- Second follow-up fix in [86e5ae5c](https://github.com/boykopovar/AnyPS5/commit/86e5ae5cdb1a33d2f63a816aff06f6aa6d5e2cba) fixes the remaining guest_avplayer failure. The texture limit check was still using the historical allocation counter, so later test cases inherited the count from earlier players and the limited allocator rejected even the mandatory buffers. Both the limit check and the assertion now use the current number of active texture blocks; the existing cumulative counter remains unchanged. This was a test helper regression, not a CI infrastructure failure. The branch is pushed and CI is running again.
oneandonlydean commented 2026-10-05 02:47:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T02:47:21Z.


Thanks, making the extra buffers optional and adding the TechnicalDebt line is what I had in mind, and rolling back a partial set keeps the title's memory exactly as it asked for.

The first push failed guest_avplayer because the new decrement in Release broke main's allocations.textures >= 4 check in TestPlayback; your last commit (86e5ae5) counts the live texture blocks for the limit instead and leaves the total alone, which fixes it. On this head guest_avplayer passes here three times in a row, and your new test fails on main's code (main never allocates more than the 2 buffers, so the 6 buffer case times out), so it covers the change.

Since PPSA21564 plays its intro video through sceAvPlayerAddSource and sceAvPlayerGetVideoDataEx, I'll check that video with this change before it's merged. CI is green on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5987229674 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/591#issuecomment-5987229674). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T02:47:21Z. --- Thanks, making the extra buffers optional and adding the TechnicalDebt line is what I had in mind, and rolling back a partial set keeps the title's memory exactly as it asked for. The first push failed `guest_avplayer` because the new decrement in `Release` broke main's `allocations.textures >= 4` check in `TestPlayback`; your last commit (86e5ae5) counts the live texture blocks for the limit instead and leaves the total alone, which fixes it. On this head `guest_avplayer` passes here three times in a row, and your new test fails on main's code (main never allocates more than the 2 buffers, so the 6 buffer case times out), so it covers the change. Since PPSA21564 plays its intro video through `sceAvPlayerAddSource` and `sceAvPlayerGetVideoDataEx`, I'll check that video with this change before it's merged. CI is green on this head.
oneandonlydean commented 2026-10-05 05:04:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:07Z.


Gated on PPSA21564, whose intro video goes through AvPlayer: the video plays cleanly, no visual or FPS change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5988443000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/591#issuecomment-5988443000). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T05:04:07Z. --- Gated on PPSA21564, whose intro video goes through AvPlayer: the video plays cleanly, no visual or FPS change.
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!591
No description provided.