fix(libSceAvPlayer): keep the no-sync clock from following audio pulled early #11772
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11772"
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 nekomancer01 on 2026-10-27T07:34:52Z.
What
In
SCE_AVPLAYER_AV_SYNC_MODE_NONE,takeAudiorebased the presentation clock to every audio chunk the title pulled more than 50 ms ahead of it, so the clock followed audio pulled, not audio played. The late-frame skip from #2351 then skips every queued frame older than that clock.Castlevania: Belmont's Curse (PPSA35399) plays a 3-minute 1920x1080 30 fps film after New Game in this mode, and pulls its audio two to four times faster than it plays it. The clock ran seconds ahead and the skip handed out frames past the one the title wanted. The title's video code (Unity) asks for frames until it gets the one whose index equals its own playback index: an earlier frame is dropped, a later one is kept until the playback index reaches it, and only an exact match is uploaded. A frame skipped to from a clock that is too far ahead is passed by the playback index before it can match, so on
mainevery frame is dropped and the film stays black, with sound.TestOptionalVideoBuffersRespectMemoryLimitcovers both modes, including the fallback.TestNoSyncClockIgnoresEarlyAudioinguest_avplayer: no-sync mode, pulls the first 600 ms of audio as fast as it comes, then checks thatsceAvPlayerCurrentTimehas not run ahead of wall time. Onmainthe clock is 578 ms ahead after 29 ms and the test fails; with the change it passes.Each part alone is not enough on PPSA35399: the clock change with 4 decode-ahead frames stayed black in 5 of 5 runs, and 24 decode-ahead frames without the clock change stayed black.
Not fixed by this PR: when the title stalls for more than about 2 s right after the film starts (asset loading, here), its video player falls behind by more than 5 frames and resyncs with seeks that each take about three rendered frames (0.65 s at 4.5 fps), which never land inside its 5-frame tolerance. The picture then stays on the last uploaded frame. That depends on the title's frame rate, not on AvPlayer. It is the likely cause of the 2 black runs below; I saw the loop with logging in earlier runs but did not confirm it in those two.
Tested
Linux (Ubuntu 26.04 distrobox on CachyOS), GCC 15.2.0, Release, RTX 3070 (NVIDIA 615.78.08):
guest_avplayer,guest_avplayer_callback_close,guest_avplayer_paused_first_videoandpublic_headerspass.guest_avplayerfails onmainwith the new test (3 of 3 runs) and passes with the change (5 of 5 repeats).mainthe film is black with its Skip prompt in 3 of 3 runs; with the change it shows and advances in 12 of 14 runs and stays black in 2. The title continues into gameplay after the film as before.mainand this change (at 72.95 s: video 72.93 s, audio 72.90 s, 30 frames handed out per second on both).Checklist
main; no other open PR implements the same functionsNotImplemented_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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-01T17:23:58Z.
Review: COMMENTED
Reviewed head
6b01c577dd06merged locally ontomainf2d874c1fdcc(PR base20cfe359a8b6). Linux, WSL2 Ubuntu 24.04, GCC 13.3, Release, lavapipe.What I ran:
ctest -R '^guest_avplayer'on the merge: 3/3 pass, three times.guest_avplayeralone: 5/5.main'sSource.cppwith onlyTestNoSyncClockIgnoresEarlyAudioadded fails 3/3:no-sync clock followed audio pulled early: 578 ms after 30 ms(also 580/34 and 578/31). With the PR, clock minus first equals wall time (31-33 ms), so the 100 ms margin isn't even used.main: onlyrun(14, 14, true)fails (6 textures, not 14). The other six cases already pass on main, so that one case is the real negative control.tools/check_conventions.py --base origin/main: pass.Read on the merged tree:
takeAudio,takeVideo,addVideoBuffers. Default mode is unchanged (driftedreduces to the old expression, still 4 buffers).SetAvSyncModeonly accepts 0 and 1, sosyncMode != SyncModeDefaultis exactly NONE. The fallback frees a partial 12 before it tries 4, and buffers are only added inStart.One gap, not a regression: at the end of audio, audio pulled early still moves the clock forward in no-sync mode. The
exhaustedterm intakeAudioandreconcileExhaustedAudioClockrebase to the last pulled timestamp with no direction check.Example, a probe on the test movie with this PR: no-sync, pull audio as fast as it comes. All 47 chunks are out after ~7 ms, and
sceAvPlayerCurrentTimereads 1000 at 208 ms wall time (first chunk at 0). The nextsceAvPlayerGetVideoDatareturns the frame at 500 ms. Main gives the same clock, so this PR doesn't cause it. But if PPSA35399 keeps pulling audio 2-4x fast through the whole film, audio runs out well before video, and the picture would jump to the end there. If you want to cover it: in no-sync mode, take the exhausted rebase only when the last timestamp is behind the clock, the same rule asdrifted.Small things:
epoch > clockEpochrebase on a loop or seek.TestNoSyncClockIgnoresEarlyAudiodoesn't checkallocations.blocks.empty()after close, likeTestNoSyncVideoCanLeadAudioClockdoes.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T22:21:55Z.
Review: APPROVED
Reads right. ahmadmuj reviewed this exact head (
6b01c577dd), and that red check stands. Incore/libs/prx/libSceAvPlayer/src/Source.cpp, the no-sync clock now rebases only when audio falls behind it, not when the title pulls audio ahead, and the larger no-sync decode-ahead is all-or-nothing:addVideoBuffersfrees every buffer it took before returningfalse, so the fallback toVideoDecodeAheadFramesstarts clean. That matches the newrun(13, 6, true)andrun(14, 14, true)rows.Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto current
main:guest_avplayer,guest_avplayer_callback_close,guest_avplayer_paused_first_videoandguest_avplayer_httppass, nothing skipped. Withmain'sSource.cpp,guest_avplayerfails atunexpected optional video buffer count(the new buffer rows), which stops the test beforeTestNoSyncClockIgnoresEarlyAudio; ahmadmuj's run covers that one failing onmain.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:57:58Z.
Review: APPROVED
Reviewed — approved
The no-sync clock now only rebases backward, and the 12-then-4 decode-ahead request applies only in
SCE_AVPLAYER_AV_SYNC_MODE_NONE. The AvPlayer tests pass, and each new test part fails when I revert its production change.What I ran
Head
6b01c577dd06399fcdc34291363a1d56b108ee9cmerged intomain5cb015caaaaf83f8ee431414ee6a457b5b307d49(merged tree1c2f0a4b41b10ab6fa71e470631785b58acb90f0). The machine was Debian 13 (VM, Xeon Gold 6136), GCC 14.2.0, Release, Ninja, with lavapipe and no GPU.Results
git diff --checkcheck_conventions.pyguest_avplayer,guest_avplayer_callback_close,guest_avplayer_paused_first_video,guest_avplayer_http,avplayer_http_transport,avplayer_http_patched_modulesguest_avplayer4.5–4.8 s (3 more runs after the restore, all pass)git status --porcelainemptyThe script reported two failures that are not on its baseline list:
agc_driver_image_sample_lod_clamp_shader_laneandunwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group. Neither comes from this PR:ninja -t queryfinds no AvPlayer dependency).main(096c45570f). Between the baseline and themainused here,mainchanged the AGC sampler code, theagc_driver_image_sample_lod_clamp_testsfragment,tools/unwrap_self.pyandtools/tests/test_unwrap_self.py.os.chown(directory, -1, group)with EINVAL, which is a limit of this sandbox.The script also lists
unwrap_selfas fixed, which has nothing to do with this PR either.Negative control
main'sSource.cpp:guest_avplayerfails withunexpected optional video buffer count. This is the new buffer-count rows, and it matches BunnyFl's result. The failure stops the test before the clock test runs.Source.cppwith only thedriftedcondition reverted (Source.cpp:637back totimestamp > currentClock + 50.0without the!unsyncedguard):guest_avplayerfails 3/3 withno-sync clock followed audio pulled early: 578 ms after 29 ms, then578/29and578/30. This isolatesTestNoSyncClockIgnoresEarlyAudio, and it confirms ahmadmuj's red check on a different machine and compiler.Findings
Blocking
None.
Non-blocking
The debt line overstates the new rule (
docs/dev/debt/libSceAvPlayer.md:28). ahmadmuj already raised this; I confirm it by reading the code. The entry says audio pulled ahead "does not move it forward in this mode", but two paths still rebase forward to the last pulled timestamp in no-sync mode:exhaustedterm atcore/libs/prx/libSceAvPlayer/src/Source.cpp:638-643;reconcileExhaustedAudioClockatcore/libs/prx/libSceAvPlayer/src/Source.cpp:579-583.The
epoch > clockEpochrebase at line 639 does the same. A title that pulls audio 2–4× fast for the whole film runs out of audio early, and at that point the clock still jumps to the end of the audio.mainbehaves the same way, so this is not a regression.Suggested fix: limit the end-of-audio rebase to a timestamp behind the clock, like the
driftedrule, or name these exceptions in the debt line.The new test does not check that its allocations were freed (
core/libs/tests/GuestAvPlayer.cpp:1610-1628).TestNoSyncClockIgnoresEarlyAudiodoes not checkallocations.blocks.empty()aftersceAvPlayerClose, unlikeTestNoSyncVideoCanLeadAudioClock. ahmadmuj noted this too. Adding the check costs one line.Other things I checked and found correct:
addVideoDecodeAheadBuffers(Source.cpp:743-747) runs only fromStart(Source.cpp:359). It reads the atomicsyncModethere, whichPlayer.cpp:218forwards before playback starts, so "as playback starts" in the debt entry is accurate.addVideoBuffersfrees a partial request before it returnsfalse, so the fallback to 4 starts clean.SetAvSyncModeaccepts only 0 and 1, sosyncMode != SyncModeDefaultmeans exactly no-sync mode.driftedexpression reduces tomain's expression.Not verified
main. I attribute them tomainbecause their inputs differ from the baseline and do not include any file this PR touches.