Skip to content

media-playback: Publish cached seek frame only while paused - #731

Merged
zackees merged 6 commits into
obs-rust:masterfrom
chriscoveries:fix/media-paused-cache-seek
Oct 15, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
chriscoveries:fix/media-paused-cache-seek

Conversation

@chriscoveries

Copy link
Copy Markdown
Contributor

Draft. Opened so upstream PR CI can run it. Our own CI is down, so this hasn't been through our usual CI runs: see our note on #699.

Problem

When a local full-decode media source is paused and then sought, the cache selects the requested frame but does not publish it. The displayed video therefore stays on the pre-seek frame until playback resumes. The non-cached path already publishes the seek frame in this case.

Root cause

On master, shared/media-playback/media-playback/cache.c:480-485 handles a seek by setting seek_next_ts, selecting cached indices, and immediately continuing. A paused cache then returns to its semaphore wait before normal video output. The existing seek-frame callback path is in cache.c:285-286, but the seek branch never calls it. The non-cached path (media.c:563) calls mp_media_next_video(m, true) after a seek only when m->pause is set.

Fix

After selecting cached indices, call mp_cache_next_video(c, true) when the cache is paused and has video and a seek callback: if (pause && c->has_video && c->v_seek_cb). This mirrors the pause check at media.c:563. One difference: media.c checks v_preload_cb, while this checks v_seek_cb, the callback it actually calls, so it can never call a NULL seek callback. The only in-tree consumer registers both. The fix reuses the existing seek callback path, only publishes for consumers that requested it, and leaves playback paused. A seek while playing does not call the seek callback; the normal output path shows the landed frame, as before.

  • Alternative: publish on every cached seek. Rejected: the non-cached path does not, and in obs-ffmpeg-source the seek callback (seek_frame) uploads a texture and resets the async frame clock, which is wrong during playback. An earlier revision of this branch did this and the review caught it; the new playing-seek case pins the guard.
  • Alternative: resume playback briefly to produce a normal frame. Rejected because seeking while paused must update the displayed frame without advancing playback.
  • Alternative: duplicate frame copying and callback logic in the seek branch. Rejected because the existing preload-mode path already implements the required seek callback behavior.

Evidence

  • RED: test_media_cached_paused_seek on base ea3df88c79862e1ac01623f24d941f44b8884de6 plus tests-only RED commit 09c994d0250f5aa4112cd5ad54ec8b259a3ecd5e fails both paused cases, with Rust libobs OFF and ON (3/3 runs each): paused seek: normal=3 seek_callbacks=0 seek_luma=0 expected_luma=0 and ... expected_luma=5. The playing case passes on the base (nothing is published there), as it should.

  • GREEN: all three cases pass on 617577a3d448174ba07732984be303fbde59c8e5 (30/30 repeated runs with Rust libobs OFF, 20/20 with ON).

  • The test uses the real full-decode cache API and a local mixed video/audio Matroska fixture. Each case issues its request from the cache thread's own video callback after the third normal frame (luma 10), so no sleeps or libobs test hooks are needed for ordering:

    1. paused seek to 0 ms: v_seek_cb is called exactly once with the first frame (luma 0). Kills "never publish" and "publish the pre-seek frame".
    2. paused seek to 50 ms (a non-zero target): exactly one call with frame 1 (luma 5). Kills "always publish the first frame", which case 1 alone cannot tell apart.
    3. seek while playing: no v_seek_cb call, and the first normal frame after the request is the landed frame (luma 5). The cache thread is sequential, so a normal frame after the request proves the seek was already handled. This case fails on the earlier version of the fix that published on every seek.
  • Negative results are proven by event barriers rather than timeouts. In the paused cases the test waits for the cache thread to take the request (cache.seek cleared under cache.mutex), then calls mp_cache_stop; stop_cb runs on the cache thread in a later loop iteration than the seek, so any seek callback has already run. The condition-variable waits are only a liveness bound.

  • Mutants (macOS, Rust libobs OFF; each fails every run, 3/3):

    Mutant of the seek branch Result
    base, no publish both paused cases fail
    publish on every seek (no pause guard) playing case fails
    inverted guard (!pause) all three fail
    always publish video_frames.array[0] 50 ms case fails
    mp_cache_next_video(c, false) (normal output path) both paused cases fail
    publish before seek_to both paused cases fail
  • Fixture: test/cmocka/data/media_cached_paused_seek.mkv (487 KB: 5 s, 16x16 ffv1 at 10 fps with luma 5 * frame_index, plus 48 kHz mono s16 audio). The same decoded content is committed by the other media-playback test branches under different names. The generator command is in the test header: ffmpeg -f lavfi -i "color=c=black:s=16x16:r=10:d=5,format=yuv420p,geq=lum='5*N':cb=128:cr=128" -f lavfi -i "aevalsrc='500*(floor(t*10)+1)/32768':s=48000:d=5:c=mono" -c:v ffv1 -c:a pcm_s16le -t 5 out.mkv. Decoded frames and samples match the committed file; only container bytes differ between runs.

  • Local build: macOS arm64, Debug, ENABLE_UNIT_TESTS=ON, frontend, scripting, browser and websocket OFF, no sanitizer; ENABLE_RUST_LIBOBS OFF and ON.

  • Real run: no separate full OBS session. The headless test exercises the cache thread, pause, seek, and video callback directly.

  • Fork CI: not run. Our self-hosted CI is down (see our note on #699), so this relies on upstream PR CI.

Compatibility & risk

No C API or ABI changes. A seek while paused, with a registered video seek callback, now publishes the selected cached frame while preserving the paused state, matching the non-cached path. A seek while playing is unchanged from master. One edge case: when seek_to rejects an out-of-range position (cache.c:169-172) it returns early, and a paused seek then re-publishes the frame at the current index. That is harmless. Local validation covered macOS arm64 with Rust libobs OFF and ON; Linux OFF/ON was not run locally and relies on upstream PR CI.

Status

Tests-only RED: 09c994d0250f5aa4112cd5ad54ec8b259a3ecd5e. GREEN: 617577a3d448174ba07732984be303fbde59c8e5. Both are pushed to the fork branch fix/media-paused-cache-seek. Status: draft. Opened so upstream PR CI can run it.

How this was tested

  • RED → GREEN: built the test_media_cached_paused_seek CMocka target in macOS arm64 Debug with ENABLE_RUST_LIBOBS OFF and ON, ENABLE_UNIT_TESTS=ON. On the base both paused cases report seek_callbacks=0; after the fix all three cases pass. The six mutants above were run locally (OFF). No sanitizer was enabled locally.
  • Our own CI: not run. Our self-hosted CI is down (see our note on #699), so this relies on upstream PR CI.
  • Real runs: no full OBS app session; the headless test exercised the actual cache thread, pause, seek, and callback path.

Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.

@zackees

zackees commented Oct 14, 2026

Copy link
Copy Markdown
Member

Two failures here, both from the new test test_media_cached_paused_seek.

1. Format (gersemi), also shows up as "Rust Tests" -> lane lint

test/cmocka/tests.d/test_media_cached_paused_seek.cmake would be reformatted

Fix: uv run ci/local_gate.py --lane lint --fix (or uvx gersemi==0.25.0 -i test/cmocka/tests.d/test_media_cached_paused_seek.cmake) and commit.

2. Tier 2 Linux, ENABLE_RUST_LIBOBS=OFF build: link error

/usr/bin/x86_64-linux-gnu-ld.bfd: /usr/lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
FAILED: [code=1] test/cmocka/test_media_cached_paused_seek

The test (or something it pulls in) uses a libm symbol but the target does not link libm. Likely fix in test_media_cached_paused_seek.cmake: add $<$<PLATFORM_ID:Linux>:m> to target_link_libraries (or link Threads/m the way other tests that use OBS::media-playback do). Reproduce with rust/tools/linux-validate/run.sh.

@zackees
zackees marked this pull request as ready for review October 14, 2026 23:11
@zackees
zackees self-requested a review as a code owner October 14, 2026 23:11
The Linux link failed with "libm.so.6: error adding symbols: DSO missing
from command line".

Local-Gate: v1 tree=92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748 secs=478 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1792021892,"gate":"rust/all/fmt","host":"linux-x86_64","key":"cd3c55520ec6991ec9389948b400db7eb48d025282c5c412e084ed7b0b5ecb10","lane":"lint","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":43,"stamp":"c86703f38ee31b13bdc62d22a7d8a85f","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"cd3c55520ec6991ec9389948b400db7eb48d025282c5c412e084ed7b0b5ecb10","lane":"lint","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":43,"stamp":"06db2ec64bd6e09a78a22405b343ea9a","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"09d590e78c5a7e6d22109c47c83e7ac723db7a11f9215b6e51f0dc69b692cf3f","lane":"rust-test","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":104,"stamp":"38ed4960f4b3dd624121dc2d9ef328c5","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"fecac0f20b5c6e163e995fb8c9bc8fec34bf8c8adc82b5b0fd1b9e8665b58301","lane":"cross","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":74,"stamp":"4cb56a65a43a8ecf72b1a617bacebb4c","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"fecac0f20b5c6e163e995fb8c9bc8fec34bf8c8adc82b5b0fd1b9e8665b58301","lane":"cross","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":74,"stamp":"98c47671124c52ab0f6a60d61c74171a","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"fecac0f20b5c6e163e995fb8c9bc8fec34bf8c8adc82b5b0fd1b9e8665b58301","lane":"cross","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":74,"stamp":"2d165065232b373806a0d1d9f5b3a7c2","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"fecac0f20b5c6e163e995fb8c9bc8fec34bf8c8adc82b5b0fd1b9e8665b58301","lane":"cross","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":74,"stamp":"fbbfba6282bb35a6e4fbfce6cecafe5b","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"fecac0f20b5c6e163e995fb8c9bc8fec34bf8c8adc82b5b0fd1b9e8665b58301","lane":"cross","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":74,"stamp":"75541b54309c468e2943915d9b351f85","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"fecac0f20b5c6e163e995fb8c9bc8fec34bf8c8adc82b5b0fd1b9e8665b58301","lane":"cross","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":74,"stamp":"e80e5aae2bcfb90bf2bfd0e0fdc19194","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
Ci-Attestation: {"at":1792021892,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"e7d521ea5ff112cb8721927bf6bee1de7ad8c6fc399b42605a34b896ec8d8b19","lane":"tier2-linux","parents":["a49c7eee0f50a50d7f43a2cb2058e6fccc5863bb"],"secs":256,"stamp":"1365d3e9e28127e66a9afa687b540255","tree":"92cc4db5b93bcd8b5bff168d91dbb66c2fd7e748","v":1,"via":"run"}
@zackees
zackees merged commit b7787cf into obs-rust:master Oct 15, 2026
22 checks passed
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.

2 participants