fix(libSceAvPlayer): keep synced video at the presentation clock when the title takes frames slowly #12898
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12898"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-29T13:46:55Z.
What
In the default sync mode, a title that asks for video frames slower than the film's frame rate gets a film that plays in slow motion and never reaches its end.
FfmpegSourcedecodes into the title's output framebuffers. When none is free,acquireBufferwaits until the title takes a frame (takeVideorecycles the queued frames the clock has passed only at that moment). So the decoder can only get a few frames ahead of the last frame the title took, and between twosceAvPlayerGetVideoData(Ex)calls the film position advances by a few frames, however much time passed.takeVideoalready skips the queued frames the clock has passed, but the queue never holds frames near the clock, so the picture handed out falls further behind on every call.PRAGMATA (PPSA02530) shows this in its 245 s opening film (
demo01, 30 fps, video only, 9 output framebuffers,SCE_AVPLAYER_AV_SYNC_MODE_DEFAULT). The title renders at 1-3 fps under AnyPS5 while the film plays and takes about one frame per rendered frame. Withmain'sSource.cpponly 33-73 s of the film have been shown when the title ends it by its own clock, about 250 s after it started (the picture handed out is 176-225 s behind the presentation clock): the title pauses, jumps to 0, stops and closes the player. The player never reaches the end of the file.The change, for the default sync mode at normal speed while the presentation clock runs (not paused, after the first frame was handed out):
No-sync mode, trick speeds, paused players and the first frame after a jump are unchanged. How far the console decodes ahead is unknown; this is recorded under Functional in
docs/dev/debt/libSceAvPlayer.md.Tested
Arch Linux 7.2.11, GCC 16.2.1, Ninja, Release, AMD Ryzen 7 9800X3D, on
mainefc24518bc.New tests in
core/libs/tests/GuestAvPlayer.cpp, run byguest_avplayer, all in default sync mode with video only and a check that the frame handed out is no more than 150 ms behind the presentation clock (the first measures the clock as the wall time since its first frame, the other two readsceAvPlayerCurrentTime):TestSyncedVideoFollowsClockWithSlowConsumer: takes the first frame, then one frame every 400 ms.TestSyncedVideoCatchesUpAfterResume: takes the first frame, pauses for 300 ms so the decoder fills the queue and waits, resumes, and takes the next frame 600 ms later.TestVideoCatchesUpAfterSwitchToSyncedMode: starts inSCE_AVPLAYER_AV_SYNC_MODE_NONE, takes the first frame, waits 300 ms so the decoder fills the queue and waits, switches to the default mode, and takes the next frame 400 ms later.ctest -R '^guest_avplayer'on this branch: 3/3 passed, three times (guest_avplayer,guest_avplayer_callback_close,guest_avplayer_paused_first_video).Negative controls, each three times out of three:
Source.cpprestored frommain:the picture handed out fell 367 ms behind the presentation clock.Source.cpprestored fromb870224b4c(the catch-up without the wake-ups):after resume the picture handed out fell 367 ms behind the presentation clock.SetSyncModewake-up reverted:after switching to default sync the picture handed out fell 467 ms behind the presentation clock.python3 tools/check_conventions.py --base origin/mainandgit diff --check: clean.PRAGMATA (PPSA02530), Linux, RX 9070 XT, 1000 s runs from boot through New Game and the difficulty menu into the opening film, with a local diagnostic log of the player state that is not part of this PR (
lastis the timestamp of the frame handed out,clock nowthe presentation clock,durthe film length, all in ms). Both builds are the same local integration build PRAGMATA needs to reach the film (maine61a7c7e24plus open PRs, including #6565) and differ only inlibSceAvPlayer/src/Source.cpp(the run withmain's code was also relinked with import tracing, which slows the title further).With
main'sSource.cpp, the last state line before the title ends the film, then the title's calls:(A second run of
main's code without #6565 ended the film the same way atlast 72773/clock now 248852.5.)With this change, the state at half the film and just before its end, then the player reaches the end of the file and the title stops and closes it:
Over the 104 state lines logged before the end of the file, the frame handed out was a median of 11 ms behind the clock (90th percentile 30 ms, worst 34 ms), against a median of 81 s on
main's code.droppedLatecounts the decoded frames dropped before conversion.Checklist
main; no other open PR implements the same functions (#1601 changes how long handed-out frames are kept, #11772 the no-sync clock; neither touches decode-ahead in the default sync mode)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)docs/dev/debt/libSceAvPlayer.md(a textual conflict only); #1601 also editsSource.cppandGuestAvPlayer.cpp, on the side that keeps handed-out frames. Whichever lands second rebases; I'll do it here if this one is later.