Skip to content

test: The gif and join-keyframe tests judge playback, not the timing - #1001

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/938-gif-last-frame-load
Oct 16, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/938-gif-last-frame-load

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #938

What and why

Both tests in #938 are ours: test_media_gif_last_frame came with #306, test_encoder_join_keyframe with #598. Under load, neither the media playback nor the encoder misbehaves. Each test has a check that load can trip while the behaviour it guards is fine. Both checks now look at the behaviour itself, and each still fails when the fix it guards is undone. No RUN_SERIAL, no wider tolerances.

test_media_gif_last_frame (video_once_shows_every_frame)

  • The "last frame" that failed was not the clip's. libobs hands a new raw video callback one frame it rendered before the callback was added (its timestamp is 33 ms before obs_add_raw_video_callback). So each case's recording can start with the last picture of the case before.
  • video_once_shows_every_frame runs after the looping case. That case plays for a fixed 2.6 s, so which frame it ends on depends on timing: normally frame 7 (one-shot video: 7x1 0x8 1x3 … 9x5). A 100-150 ms render hitch when a clip starts moves it to frame 9 (one-shot video: 9x1 0x8 1x3 … 8x3 9x5).
  • check_last_frame_held judged the first run of frame 9 it found: that one stale output frame. The clip's own last frame was held for 4-5 output frames in every such run.
  • check_order already skipped pictures before the clip's first frame. It now also returns the run that showed the clip's last frame, and check_last_frame_held judges that run.
  • Playback is fine under load. With 32 busy loops on 16 cores and at ctest -j8, the media thread delivered every frame within 1 ms of its due time, libobs showed every frame 133 ms after it was delivered, no output frames lagged, and the clear came 266-268 ms after the last frame, as bug: media-playback: non-looping media (e.g. a GIF) drops its last frames (upstream #10425) #306 intends.

test_encoder_join_keyframe (real_aom_av1)

  • The real_ cases reckoned the frame the recording joined at from the wall clock since the replay buffer started. The encoder's pts counts the frames the video thread gave it.
  • When that thread is slow (a slow encoder such as AOM AV1, or a busy host), the encoder falls behind the wall clock. The check then failed (-6 frames) while the recording still got its keyframe from the frame the encoder had when it joined (+0/+1 counted in frames).
  • The join frame is now read from video_output_get_total_frames() (frames the video thread handed out since the encoder started), just before and just after obs_output_start(). The first packet must lie within JOIN_FRAMES of that range. The next scheduled keyframe is still 300 frames away.

Measured (16-core host, private Xvfb, system libobs-opengl masked, TMPDIR unset)

The original flake does not show up on this host from CPU load alone. test_media_gif_last_frame on master: 0/20 alone, 0/20 and 0/10 with 16 and 48 busy loops, and it passed in 5 full ctest -j8 runs (2 of them with 32 busy loops). A render hitch when the clip starts (the test holds the graphics lock for N ms when the first frame arrives; local harness, not committed) reproduces it:

master this branch
100 ms hitch at clip start, 20 runs 12/20 fail (video_once_shows_every_frame) 0/20
150 ms hitch at clip start, 20 runs 20/20 fail ("the last frame was shown for only 1 output frame(s)") 0/20
alone, 20 runs 0/20 0/20
32 busy loops on 16 cores, 20 runs 0/20 0/20

test_media_gif_last_frame on this branch is also 0/10 alone in each lane. test_encoder_join_keyframe on this branch: 0/10 alone in each lane and 0/10 with 32 busy loops; the new slowed-video-thread case fails 10/10 with the old check. The new case adds about 2 s (11.5 s in all).

The fixes they guard

Not changed here

  • With the hitch raised to 250 ms, the clip's own last frame really is cut to one output frame, and the fixed test still fails, correctly. libobs anchors an async source's playback at the first frame it renders, while "Show nothing when playback ends" clears on the media's own clock. A long hitch as a one-shot clip starts can therefore shorten its last frame. The load runs above never moved that latency (133 ms throughout), so it is not what test: test_media_gif_last_frame fails under CPU load (last frame held 1 output frame, wants 2) #938 hit. It would need a separate design.
  • The stale first frame a new raw video callback gets is libobs behaviour; this PR only stops the test from counting it.
  • test_texture_encoder_raw_format can hang Tier 2: run_in_child() forks after libobs has started its threads, the child can deadlock on the hotkey mutex in obs_hotkeys_context_release(), and the parent waits with no timeout. Seen once in the Rust lane at -j8 (killed after 27 min). Not changed here; worth its own issue.

RED → GREEN

  • RED commit: f4b46cc test: The gif and join-keyframe tests fail on a busy host (RED).
    • test_media_gif_last_frame: new case video_once_after_last_frame_held plays the video once with "Show nothing when playback ends" off (it ends holding frame 9), then once with it on. It fails every run (20/20): "the last frame was shown for only 1 output frame(s)", judged on the stale 9x1 that opens the recording. The other 3 cases pass.
    • test_encoder_join_keyframe: new case real_x264_video_thread_behind keeps the video thread busy for two frame intervals per frame for the 500 ms before the recording joins x264. It fails every run (10/10) with -6 frames. The other 8 cases pass.
  • GREEN: 64a7068. test_media_gif_last_frame 4/4 cases and test_encoder_join_keyframe 9/9 cases with ENABLE_RUST_LIBOBS OFF and ON. Full ctest at -j8 (private Xvfb, system libobs-opengl masked, TMPDIR unset): C lane 254/254, Rust lane 254/254. Skips: only open_crashes_without_obs_core and test_startup_shutdown_cycles's stress case, as on master. An earlier -j8 run of the C lane, made while the Rust lane was building at -j8, gave 253/254: test_pulse_monitor_device failed once, and both tests here passed with every case run. An earlier Rust-lane run gave 252/254: test_audio_io failed, and test_texture_encoder_raw_format hung in a forked child (a separate issue; see below). Both pass 3/3 alone and are not touched here. clang-format 22.1.3, gersemi 0.25.0 and ci/test_registration.py clean.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): none
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not a port

AI note: Claude Code (Claude Opus 5.5) wrote the code, the tests, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

rdoupe and others added 2 commits October 16, 2026 00:43
Fails, every run: video_once_after_last_frame_held ("the last frame was
shown for only 1 output frame(s)") and real_x264_video_thread_behind
("-6 frames", outside +-JOIN_FRAMES).

test_media_gif_last_frame: libobs hands a new raw video callback one
frame it rendered before the callback was added, so each case's
recording can start with the last picture of the case before.
check_last_frame_held judges the first run of the clip's last frame it
finds, and when the looping case before happens to end on that frame
(timing decides which), that one stale output frame is what it judges.
The new case plays the video once more right after a run that ended on
its last frame, so the stale frame is always the last frame.

test_encoder_join_keyframe: the real_ cases reckon the frame the
recording joined at from the wall clock, but an encoder's pts counts
the frames the video thread gave it. When that thread falls behind (a
slow encoder such as AOM AV1, or a busy host), the two part. The new
case keeps the video thread busy for two frame intervals per frame
before the recording joins x264.

Refs obs-rust#938.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_media_gif_last_frame failed under load with "the last frame was
shown for only 1 output frame(s)" in video_once_shows_every_frame. That
frame was not the clip's: libobs hands a new raw video callback one
frame it rendered before the callback was added, so the recording can
start with the last picture of the case before, and the looping case
before ends on the clip's last frame when timing has it so (a startup
hitch of 100-150 ms is enough). check_last_frame_held judged the first
run of that frame it found. check_order already leaves out pictures
before the clip's first frame; it now also returns the run that showed
the clip's last frame, and check_last_frame_held judges that run. The
media playback is unchanged: the clip's own last frame was held for
4-5 output frames in each of those runs.

test_encoder_join_keyframe's real_ cases reckoned the frame the
recording joined at from the wall clock since the replay buffer
started. The encoder's pts counts the frames the video thread gave it,
which falls behind the wall clock when that thread is slow (AOM AV1
under load), so the check failed while the recording still got a
keyframe made from the frame the encoder had at the join. The join is
now reckoned from the frames the video thread had handed out since the
encoder started (video_output_get_total_frames), read just before and
just after the recording starts.

Both still fail as before when the fix they guard is undone: with
mp_media_hold_last_frame() disabled, every one-shot case shows 8 of 10
frames.

Fixes obs-rust#938.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 16, 2026 06:08
@zackees
zackees enabled auto-merge October 16, 2026 06:11
@zackees
zackees added this pull request to the merge queue Oct 16, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Oct 16, 2026
@zackees
zackees merged commit a4938ab into obs-rust:master Oct 16, 2026
24 checks passed
zackees added a commit that referenced this pull request Oct 17, 2026
#1150 had test_encoder_join_keyframe and test_media_gif_last_frame reserve
half the -j8 slots, from #938's report that they failed under -j8. #1001
already fixed both: the gif check judged a stale frame libobs hands a
new raw video callback, and the join-keyframe cases reckoned the join
frame from the wall clock instead of the frames the video thread
delivered. Both passed 6 of 6 repeats together, unreserved, next to the
other libobs C tests looping at -j6 on a host at load 12-17.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

test: test_media_gif_last_frame fails under CPU load (last frame held 1 output frame, wants 2)

2 participants