fix(avplayer): resume the presentation clock when the source restarts after a pause #4652

Merged
xXPBSXx merged 1 commit from upstream-pr/4652 into main 2026-10-14 05:04:10 +00:00
xXPBSXx commented 2026-10-12 17:55:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T17:55:51Z.


What

Clock::Reset in libSceAvPlayer did not clear the paused flag that Clock::Pause sets. After sceAvPlayerPause the player was restarted by sceAvPlayerStart (which stops and restarts the source from the Pause state), the presentation clock stayed frozen at the start position: the first frame (pts 0) was delivered, every later frame was held back by the default A/V sync (frame timestamp > Now()), so video stood still.

Sequence observed in Cult of the Lamb (PPSA06465), cutscene Update_Video.mp4: SetAvSyncMode(1), Start (T+28879), SetAvSyncMode(0), Start (T+29007), Pause (T+29008), SetLooping(1), JumpToTime(0) (T+29169), Start (T+29278). The failing step is the last Start, called from the Pause state. Trace (AVPTRC, timestamps in ms after process start): 6 frames pts 0..100 before the pause, then one frame pts 0 at T+29304 after that last Start, then only GetVideoDataEx returning false for 20 s until the user skipped (Stop at T+52247).

The fix resets paused together with the clock in Clock::Reset. The new test TestRestartAfterPausedJumpKeepsClockRunning (Start, frame, Pause, SetLooping, JumpToTime(0), Start, expects frames up to pts 200 and a running CurrentTime) uses the existing synthetic movie in GuestAvPlayer.cpp and checks frame delivery and CurrentTime, not real-time pace; it fails without the change and passes with it (results below).

Overlap: open #1601 (keep handed-out video frames) changes Source.cpp but not Clock, so it is not a duplicate. git merge-tree of the two heads (a671dc4ed, 91f77a455) conflicts in core/libs/tests/GuestAvPlayer.cpp and docs/dev/TechnicalDebt.md; Source.cpp merges. #1601 already conflicts with main 30f961266 in those two files on its own, so whichever lands second rebases its test and debt entry. Merged avplayer PRs (#893 jump while paused, #2896 title-started playback) do not cover this.

Tested

Windows 10, MinGW Release, built on main 2a5eca11c (not rebuilt on current main: the new 3rdparty/libusb-cmake submodule is not available here; git merge-tree of the current head a671dc4ed against main 30f961266 shows no conflict), guest_avplayer_tests: ctest -R guest_avplayer (new test TestRestartAfterPausedJumpKeepsClockRunning plus the existing AvPlayer tests): without the Clock::Reset change the run fails with "playback froze after a restart that followed a paused jump"; with the change it passes (4.7 s). python tools/check_conventions.py --base upstream/main passes.

Tested with the fix in Cult of the Lamb (Windows, extended AvPlayer trace): the cutscene now plays at real-time pace (video position against wall clock 1.00). The title then ends the video itself at a video position of about 22.8 s (it calls Pause, Stop, Close); the reason is not known and is not changed by this PR.

Not recorded: whether this was run on Linux or on a console; the text above names only Windows. The Cult of the Lamb run is described above as it was recorded; a later hand observation on Windows 10 (video stays on one frame without this change, plays with it, then ends early at about the same point as before) is in the comment on this pull request; the early end of the cutscene is not explained and is not part of this change.

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; silent stubs are listed in TechnicalDebt (n/a, none added)

  • No notes, investigation .md files or images added to the repository

  • New third-party code is a submodule built from source (n/a, none added)

  • Generic behaviour, not specific to one title

  • Depends on: none

  • Unblocks: PPSA06465 Cult of the Lamb, cutscene frozen on its first frame (no Game bring-up discussion exists; the video plays now, it still ends early for a reason not established)

  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833118387 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4652). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T17:55:51Z. --- ### What `Clock::Reset` in `libSceAvPlayer` did not clear the `paused` flag that `Clock::Pause` sets. After `sceAvPlayerPause` the player was restarted by `sceAvPlayerStart` (which stops and restarts the source from the Pause state), the presentation clock stayed frozen at the start position: the first frame (pts 0) was delivered, every later frame was held back by the default A/V sync (`frame timestamp > Now()`), so video stood still. Sequence observed in Cult of the Lamb (PPSA06465), cutscene `Update_Video.mp4`: `SetAvSyncMode(1)`, `Start` (T+28879), `SetAvSyncMode(0)`, `Start` (T+29007), `Pause` (T+29008), `SetLooping(1)`, `JumpToTime(0)` (T+29169), `Start` (T+29278). The failing step is the last `Start`, called from the Pause state. Trace (`AVPTRC`, timestamps in ms after process start): 6 frames pts 0..100 before the pause, then one frame pts 0 at T+29304 after that last `Start`, then only `GetVideoDataEx` returning false for 20 s until the user skipped (`Stop` at T+52247). The fix resets `paused` together with the clock in `Clock::Reset`. The new test `TestRestartAfterPausedJumpKeepsClockRunning` (`Start`, frame, `Pause`, `SetLooping`, `JumpToTime(0)`, `Start`, expects frames up to pts 200 and a running `CurrentTime`) uses the existing synthetic movie in `GuestAvPlayer.cpp` and checks frame delivery and `CurrentTime`, not real-time pace; it fails without the change and passes with it (results below). Overlap: open #1601 (keep handed-out video frames) changes `Source.cpp` but not `Clock`, so it is not a duplicate. `git merge-tree` of the two heads (`a671dc4ed`, `91f77a455`) conflicts in `core/libs/tests/GuestAvPlayer.cpp` and `docs/dev/TechnicalDebt.md`; `Source.cpp` merges. #1601 already conflicts with `main` `30f961266` in those two files on its own, so whichever lands second rebases its test and debt entry. Merged avplayer PRs (#893 jump while paused, #2896 title-started playback) do not cover this. ### Tested Windows 10, MinGW Release, built on main `2a5eca11c` (not rebuilt on current main: the new `3rdparty/libusb-cmake` submodule is not available here; `git merge-tree` of the current head `a671dc4ed` against `main` `30f961266` shows no conflict), `guest_avplayer_tests`: `ctest -R guest_avplayer` (new test `TestRestartAfterPausedJumpKeepsClockRunning` plus the existing AvPlayer tests): without the `Clock::Reset` change the run fails with "playback froze after a restart that followed a paused jump"; with the change it passes (4.7 s). `python tools/check_conventions.py --base upstream/main` passes. Tested with the fix in Cult of the Lamb (Windows, extended AvPlayer trace): the cutscene now plays at real-time pace (video position against wall clock 1.00). The title then ends the video itself at a video position of about 22.8 s (it calls `Pause`, `Stop`, `Close`); the reason is not known and is not changed by this PR. Not recorded: whether this was run on Linux or on a console; the text above names only Windows. The Cult of the Lamb run is described above as it was recorded; a later hand observation on Windows 10 (video stays on one frame without this change, plays with it, then ends early at about the same point as before) is in the comment on this pull request; the early end of the cutscene is not explained and is not part of this change. ### 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; silent stubs are listed in TechnicalDebt (n/a, none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (n/a, none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA06465 Cult of the Lamb, cutscene frozen on its first frame (no Game bring-up discussion exists; the video plays now, it still ends early for a reason not established) - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-13 14:54:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:54:49Z.


Checked the Clock::Reset change against Source::Stop/Start (the source's own paused was already cleared on stop, the clock's wasn't), ran guest_avplayer with the PR (passes) and with Source.cpp reverted (the new test fails as expected), plus the rest of the libs ctest (26/26). Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148398811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4652#issuecomment-6148398811). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:54:49Z. --- Checked the `Clock::Reset` change against `Source::Stop`/`Start` (the source's own `paused` was already cleared on stop, the clock's wasn't), ran `guest_avplayer` with the PR (passes) and with `Source.cpp` reverted (the new test fails as expected), plus the rest of the libs ctest (26/26). Merging once the full Build is green.
xXPBSXx commented 2026-10-13 15:05:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T15:05:50Z.


Observation on Windows 10 (not a CI run): Cult of the Lamb (PPSA06465), watched by hand with the libraries of main 2890f9549 and of main + this change (01bd0157b):

  • Without the change, the video of the update sequence stays on one frame while the sound continues.
  • With the change, the video plays. It then ends early, at about the same point as before (roughly 22 to 23 s); the cause of that early end is not known and is not part of this pull request.
  • In the logs of both runs Update_Video.mp4 is opened once. After that open the run with the change logs more texture activity (78 versus 21 lines); the logs contain no AvPlayer lines, so this is only a count, not a frame measurement.

The libraries differ in libSceAvPlayer (and libSceAvPlayer.native); libSceAgc, libSceAgcDriver and libSceVideoOut also differ, probably only in the embedded revision (not checked).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148621879 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4652#issuecomment-6148621879). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T15:05:50Z. --- Observation on Windows 10 (not a CI run): Cult of the Lamb (PPSA06465), watched by hand with the libraries of `main` `2890f9549` and of `main` + this change (`01bd0157b`): - Without the change, the video of the update sequence stays on one frame while the sound continues. - With the change, the video plays. It then ends early, at about the same point as before (roughly 22 to 23 s); the cause of that early end is not known and is not part of this pull request. - In the logs of both runs `Update_Video.mp4` is opened once. After that open the run with the change logs more texture activity (78 versus 21 lines); the logs contain no AvPlayer lines, so this is only a count, not a frame measurement. The libraries differ in `libSceAvPlayer` (and `libSceAvPlayer.native`); `libSceAgc`, `libSceAgcDriver` and `libSceVideoOut` also differ, probably only in the embedded revision (not checked). AI-assisted (Claude Code).
adriadam10 commented 2026-10-13 15:16:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:16:30Z.


Checked Clock::Reset against Source::Stop/Start (the source's paused was cleared on stop, the clock's wasn't). guest_avplayer passes with the PR and fails with Source.cpp reverted; the rest of the scoped libs ctest is green (27/27). Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148837755 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4652#issuecomment-6148837755). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T15:16:30Z. --- Checked `Clock::Reset` against `Source::Stop`/`Start` (the source's `paused` was cleared on stop, the clock's wasn't). `guest_avplayer` passes with the PR and fails with `Source.cpp` reverted; the rest of the scoped libs ctest is green (27/27). Merging once the full Build is green.
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!4652
No description provided.