Skip to content

fix(libSceVideodec2): flush without draining when no picture is pending - #8660

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:fix/videodec2-flush-without-pending
Oct 22, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:fix/videodec2-flush-without-pending

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What

sceVideodec2Flush drained libavcodec with an empty packet whenever the decoder was not already flushing. The next sceVideodec2Decode then restarted the decoder with avcodec_flush_buffers, which drops its reference pictures. After such a restart, libavcodec's H.264 decoder withholds pictures until it reaches a keyframe.

Sony's PSP emulator (PSPHD 1.7, used by Daxter PPSA09695) calls sceVideodec2Decode and then sceVideodec2Flush for every access unit of its H.264 movies (480x272 Main, no B pictures). With APS5_TRACE_VIDEODEC=1 and a temporary log of each call, the sequence is Decode, Flush, Decode, Flush, ... (461 flushes in 70 s). Only the IDR pictures came back: 8 pictures from 459 access units. The emulator logged (TextureCache) WARN : Failed to obtain a video frame. for every other frame, and the intro movie was a black screen.

  • sceVideodec2Flush now drains only when a decoded access unit has not produced its picture yet. With nothing pending there is nothing to return, so the decoder keeps its references and the units that follow decode normally.
  • A flush with pictures pending (for example a stream with B pictures) drains as before. A Decode after it restarts the decoder as before.

The access units the title submitted, dumped and decoded offline with the same libavcodec settings (AV_EF_EXPLODE, slice threads), give 8 of 459 pictures with a drain-and-restart after every unit and 459 of 459 without it. The FFmpeg command line decodes all 459 from the concatenated units.

Tested

Linux 7.2.9-arch1-1, Ryzen 9 7950X, AMD Radeon RX 6650 XT, RADV Mesa 26.2.4.

  • New testFlushAfterEveryUnit in guest_videodec2: a 658-byte 64x48 constrained-baseline IPPP stream (x264, no B pictures, SEI removed). It is decoded once without flushes and once with sceVideodec2Flush after every unit, and both must return the same 4 pictures (NV12 hashes). It fails without the library change (a flush after each access unit lost or changed the pictures that follow it) and passes with it.

  • guest_videodec2, guest_vdecsw, guest_avplayer, guest_avplayer_callback_close and guest_avplayer_paused_first_video pass. That includes the existing testDecodeAfterFlush (flush on an empty decoder, and decoding a reordered stream after a draining flush).

  • PPSA09695 01.000.003 natively on main 434e965d46 + fix(libSceCommonDialog): return ALREADY_SYSTEM_INITIALIZED from a second sceCommonDialogInitialize #8618 (Daxter stops at startup without it, on sceCommonDialogInitialize). Same runtime and scripted input, without and with this change:

    • without: the intro movie is black, with 450 Failed to obtain a video frame lines in 100 s.
    • with: the movie plays ("In collaboration with Naughty Dog, Inc.") with no such line, then gameplay at 30 FPS.
  • Not verified on a console: what the console returns from a flush with pictures pending, and whether it keeps references across one.

  • Independent Windows data point (Windows 10 19045, MinGW GCC 15.2): the new test passes with the change and fails with the library files restored to main, 3 of 3 each (comment).

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: PPSA09695 Daxter (PPSA09695) #8661
  • GPUs tested: AMD Radeon RX 6650 XT, RADV Mesa 26.2.4, Linux 7.2.9-arch1-1
  • AI-assisted: yes

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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 7517 core/libs/tests/GuestVideodec2.cpp L127-211

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

@xXPBSXx

xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Windows data point for 604737426 merged onto main 57fdffd91 (clean, git merge-tree rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. ctest -N -R '^guest_videodec2$' lists exactly that one test; ctest --no-tests=error -R '^guest_videodec2$' was run three times per tree.

  • With the PR: passes 3 of 3 (0.2-1.1 s).
  • Same tree with core/libs/prx/libSceVideodec2/Export.cpp restored to main (the new test cases kept): fails 3 of 3 (ordinary test failure, not a crash).
    Not tested: other platforms, a title run.
    AI-assisted (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@JJenkx
JJenkx force-pushed the fix/videodec2-flush-without-pending branch from 6047374 to 1f79743 Compare October 21, 2026 09:20
@JJenkx

JJenkx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 27c88a8d75 (new head 1f7974377b). The only conflict was the docs/dev/debt/libSceVideodec2.md debt entry, where main's VP9 picture-info entry from #8839 is kept as merged and only the flush entry carries this PR's text. The code and test are unchanged.

Rerun on Linux, Release build:

  • guest_videodec2 passes 3 of 3 runs.
  • With Export.cpp restored to main and the new test kept, it fails.
  • The video library tests all pass: guest_videodec, guest_videodec2, guest_vdecsw, the three guest_avplayer* tests and the seven guest_video_out_* tests (13 of 13).

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 21, 2026
@JJenkx
JJenkx force-pushed the fix/videodec2-flush-without-pending branch from 1f79743 to 4af7e24 Compare October 21, 2026 12:41
@JJenkx

JJenkx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebased again onto main 7280a17ec0 (new head 4af7e24d07). The conflict was only in core/libs/tests/GuestVideodec2.cpp, where main moved the VP9 stream data to Vp9Fixture.hpp (#8360). The test now keeps only its own AvcIpppStream array; the test and the library change are unchanged.

Rerun on Linux, Release build:

  • guest_videodec2 passes 3 of 3 runs.
  • With Export.cpp restored to main, it fails.
  • The video library tests pass 14 of 14: guest_videodec, guest_videodec2, guest_vdecsw, guest_avplayer* and guest_video_out_*.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@JJenkx
JJenkx force-pushed the fix/videodec2-flush-without-pending branch from 4af7e24 to 5f4b2b9 Compare October 22, 2026 06:01
sceVideodec2Flush drained libavcodec with an empty packet whenever the decoder
was not already flushing, and the next sceVideodec2Decode then restarted the
decoder with avcodec_flush_buffers, dropping its reference pictures. A caller
that flushes after every access unit, as Sony's PSP emulator does for its
H.264 movies, lost every P picture after the first: libavcodec withholds
pictures after a restart until it reaches a keyframe, so Daxter (PPSA09695)
got 8 pictures from 459 access units and showed a black screen ("Failed to
obtain a video frame") instead of its intro movie.

Flush now drains only when a decoded access unit has not produced its picture
yet. With nothing pending there is nothing to return, and the decoder keeps its
references for the units that follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx
JJenkx force-pushed the fix/videodec2-flush-without-pending branch from 5f4b2b9 to 28d9f26 Compare October 22, 2026 06:01
@JJenkx

JJenkx commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main b27924d851 as 28d9f26bdd. #8122 added testEmptyAccessUnit at the same place in GuestVideodec2.cpp. Both tests are kept, testEmptyAccessUnit first; the library code merged without conflict.

guest_videodec2 passes on the rebased head (Linux 7.2.9, GCC, Release). This is a CPU-only decoder test, so there is no GPU or validation-layer run.

I also shortened the debt entry by about a dozen characters, because the conventions checker flagged it at 1011 characters. It now passes tools/check_conventions.py --base origin/main.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 22, 2026
@oneandonlydean
oneandonlydean merged commit 44602d6 into boykopovar:main Oct 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs prx unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants