Skip to content

image-source: Clear an emptied legacy slideshow in manual, paused and deactivated modes - #735

Merged
zackees merged 5 commits into
obs-rust:masterfrom
chriscoveries:fix/slideshow-manual-empty-clear
Oct 15, 2026
Merged

zackees merged 5 commits into
obs-rust:masterfrom
chriscoveries:fix/slideshow-manual-empty-clear

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

The legacy slideshow source (plugins/image-source/obs-slideshow.c) fades out and reports media_ended when its file list becomes empty, but only in automatic playback. If the list is emptied while the slideshow is in manual mode, paused, stopped, or deactivated with "pause on deactivate", the transition's active child is never cleared and the media state never reaches ENDED.

Fixing that exposes a second problem in the same function. The clear path (and the restart and list-end transitions) ran with the non-recursive ss->mutex held and emitted media_ended and slide_changed synchronously. A signal subscriber that calls obs_source_enum_active_sources() on the slideshow re-enters ss_enum_sources(), which locks the same mutex, and the video thread deadlocks. So the clear has to be decided under the lock and carried out after it is released.

Root cause

All line numbers are upstream/master (a48a9a13d).

  • plugins/image-source/obs-slideshow.c:734 returns through goto finish for pause_on_deactivate || manual || stop || paused. The empty-list block at :739-746 comes after it, so those modes never reach it.
  • That empty-list block calls do_transition(ss, true) (:744) with ss->mutex held (locked at :719). The other tick transitions (:727, :757, :759) are also called under the lock.
  • do_transition (:252-276) emits media_ended (:267) and slide_changed (:275). signal_handler_signal calls each subscriber synchronously (libobs/callback/signal.c:305), and obs_source_media_ended raises the signal at libobs/obs-source.c:6040.
  • A subscriber that calls obs_source_enum_active_sources() reaches source->info.enum_active_sources (libobs/obs-source.c:4695), which is ss_enum_sources (obs-slideshow.c:1058). That function takes ss->mutex (:824), and the mutex is created with default attributes (:689), so it cannot be taken twice. The reproduction is deterministic, not a race.

Fix

Only plugins/image-source/obs-slideshow.c changes (GREEN). do_transition is split into two steps:

  • prepare_transition() runs under the lock and copies the decision into a struct transition_plan (obs-slideshow.c:255-280 on the GREEN commit): referenced transition and destination, a copy of the path, the index, tr_speed, and the use_cut/to_null flags.
  • run_transition() (:282) performs the transition calls and emits the signals, and the tick now calls it after pthread_mutex_unlock (:818-821). do_transition remains for the callers that never hold the mutex (ss_update and the media actions) and is documented "Callers must not hold ss->mutex" (:309).

In ss_video_tick (:755-822):

  • The empty-list block (:779-796) moved above the manual/paused/stop guard (:798). It takes a reference to the transition, releases the mutex (:785), then starts the NULL transition, sets ENDED and emits media_ended with no lock held, and returns. It still only fires when a child is active, so later empty ticks stay quiet.
  • The restart branch (:766-775) and the end-of-list branch (:808-811) now build a plan under the lock and run it after unlock.
  • The restart branch still runs before the empty block, as on base, so re-activating an empty stop_restart slideshow ends it again once per activation.

Alternatives:

  • Move the guard only (smallest). Not enough: a review showed the clear then deadlocks in manual mode when a subscriber enumerates the source.
  • Make ss->mutex recursive. Not taken: it would change the lock type for every path instead of removing the callbacks-under-lock pattern.
  • Fix obs-slideshow-mk2.c too. Not done: see Compatibility & risk.

Evidence

Branch fix/slideshow-manual-empty-clear on the fork, two commits on base 7cf6f3932 (an older upstream/master; the file differs from current upstream/master only in an EPSILON cast and a reformatted obs_missing_file_create call, away from the code touched here):

  • RED, tests only: 86df3c8a0fd8999dcb6731628f48e6fd75a7e689 "image-source: test empty slideshow clearing in paused modes (RED)".
  • GREEN, fix: 3a3717f10bb57cf72364850bd661d6db88188d6a "image-source: clear empty slideshow outside the mutex (GREEN)".

Tests (test/cmocka/test_slideshow_empty.c, registered in test/cmocka/tests.d/test_slideshow_empty.cmake, which is guarded by if(TARGET image-source AND TARGET obs-transitions)). The file is byte-identical in RED and GREEN. It links the real slideshow and cut-transition sources with libobs and drives the registered update, activate and video_tick callbacks synchronously, with no video thread, sleeps or timing.

  • Empty list clears: manual_empty_clears, paused_empty_clears, deactivated_empty_clears (:237, :275, :283), plus automatic_empty_clears (:232) as a control. Each asserts the active child is NULL, state ENDED, exactly one media_ended, and none on a second empty tick.
  • Re-entrant subscribers that call obs_source_enum_active_sources(): manual_empty_callback_reenters (:246), manual_activation_empty_clears (:313, a manual stop_restart slideshow emptied before activation), activation_restart_reenters (:338), list_end_hide_reenters (:356), list_end_keep_reenters (:373).
  • Boundary and ordering controls that also pass on base: manual_one_image_tick_retains_child (:255, a settled one-image manual slideshow is not cleared), empty_reactivation_ends_again (:394, media_ended reaches 2), and restart_reports_slide_payload (:422, the slide_changed index and path after an update and after an activation restart).
  • A hang is reported by name rather than waiting for CTest. On POSIX each case runs in a forked child with alarm(5) (CASE_TIMEOUT_SECONDS, :455; fork at :500, alarm at :507). Windows runs the cases in-process. The CTest timeout is 60 s (tests.d/test_slideshow_empty.cmake:27) so the four bounded hangs fit.

Local results from our review (macOS, Apple Clang, C17, -Werror, the test linked against existing libobs frameworks built with the Rust port OFF and ON; not a CMake/CTest run of CI):

  • RED test on the base slideshow, OFF and ON identical (2 runs each, 22-25 s):

    [  ERROR   ] --- cleared is not true
    [  FAILED  ] manual_empty_clears
    [  ERROR   ] --- cleared is not true
    [  FAILED  ] manual_empty_callback_reenters
    [  ERROR   ] --- cleared is not true
    [  FAILED  ] paused_empty_clears
    [  ERROR   ] --- cleared is not true
    [  FAILED  ] deactivated_empty_clears
    [  FAILED  ] manual_activation_empty_clears: the case died from signal 14 (hang)
    [  FAILED  ] activation_restart_reenters: the case died from signal 14 (hang)
    [  FAILED  ] list_end_hide_reenters: the case died from signal 14 (hang)
    [  FAILED  ] list_end_keep_reenters: the case died from signal 14 (hang)
    8 of 12 case(s) failed
    

    The four controls that pass on base (automatic_empty_clears, manual_one_image_tick_retains_child, empty_reactivation_ends_again, restart_reports_slide_payload) pass.

  • GREEN: 0 of 12 case(s) failed, 3 runs per mode (2.3-3.9 s), OFF and ON, and each case also passes when run alone. Our CTest runs of the same test passed in both modes (100% tests passed out of 1, about 3 s).

  • Mutants against GREEN (OFF), each failing a named case:

    • plan->index = 0: restart_reports_slide_payload, 0 != 1.
    • plan->path taken from the first file: restart_reports_slide_payload, "a.png" != "b.png".
    • Restart block moved below the empty block, or guarded by files.num: empty_reactivation_ends_again, 1 != 6 (state PLAYING instead of ENDED).
    • Restart, list-end or empty block executed with the mutex held: reported as died from signal 14 (hang) for the matching cases (2, 2 and 1 cases).
    • The earlier files.num <= 1 boundary mutant is killed by manual_one_image_tick_retains_child.
  • A review pass on a commit with the same production file as GREEN compared tick traces (media_ended count, media state, cleared child, slide_changed count, index and path) between base and GREEN on seven lifecycle scenarios, in OFF and ON, and found them identical. These were review probes and are not committed tests.

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

  • Real-run evidence: the full app was not run. The cases use the real slideshow and cut-transition code and real libobs signals, but no decoder or renderer.

Compatibility & risk

No C API, ABI, export or Rust change. Rust parity needs nothing: there is no slideshow code under rust/, and ENABLE_RUST_LIBOBS only changes which libobs the test links, so the same C plugin runs in both modes.

Behaviour changes, all in the legacy slideshow tick:

  • An emptied list in manual, paused, stopped or deactivated-paused mode now clears the active child, sets ENDED and emits media_ended once, as automatic mode already did.
  • media_ended and slide_changed subscribers now run after ss->mutex is released and after the tick's flags (restart_on_activate, use_cut, stop) are cleared, so they can enumerate the source. The slide_changed payload comes from the plan's copy of the index and path.
  • With an empty list the tick now returns after the clear block instead of falling through to the slide timer. The fall-through could only queue obs_source_media_next, which ss_next_slide ignores when the list is empty (obs-slideshow.c:543 on upstream/master), and ss_update resets elapsed (:510 on GREEN).

Limits found in review:

  • Legacy slideshow only. plugins/image-source/obs-slideshow-mk2.c, the version-2 source registered next to it (image-source.c:403-404), has the same early return before the empty-list block (obs-slideshow-mk2.c:845-846, empty block at :850). It is not changed here, so this PR must not be read as fixing current slideshows. The legacy source is flagged OBS_SOURCE_CAP_OBSOLETE (obs-slideshow.c:1048). A follow-up for mk2 can reuse the same split if the maintainers want it.
  • The inherited non-looping list-end behaviour is unchanged: with hide set, the end re-fires every slide_time.
  • One survivor was not credited as a test gap: clearing use_cut before prepare_transition in the restart branch. The headless cut-only fixture cannot tell a cut from an automatic start, so it would only show with a real fade.
  • The per-case watchdog uses fork, so on Windows the cases run in-process with only the 60 s CTest bound, and an unknown case name passed as argv[1] runs nothing and exits 0 on POSIX.
  • Tested on macOS only, with no Linux, GCC, detect_leaks or Windows run, and no full ./unittest. The same review's allocation probe showed zero residual allocations for every case in OFF and ON, but that is a review probe, not a committed assertion.

Status

Draft. Opened so upstream PR CI can run it.


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

Tier 2 Linux: one cmocka test fails, 208/209 pass.

172/209 Test #172: test_slideshow_empty ...***Failed    0.05 sec
/usr/bin/xvfb-run: 200: $<TARGET_FILE:test_slideshow_empty>: not found

Cause: in test/cmocka/tests.d/test_slideshow_empty.cmake the old-style add_test(test_slideshow_empty ${XVFB_RUN_EXECUTABLE} -a $<TARGET_FILE:test_slideshow_empty>) does not expand generator expressions, so xvfb-run is handed the literal string. Fix: use the NAME/COMMAND signature:

add_test(NAME test_slideshow_empty COMMAND ${XVFB_RUN_EXECUTABLE} -a $<TARGET_FILE:test_slideshow_empty>)

(and likewise COMMAND for the non-xvfb branch). 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 old add_test(<name> <cmd>) form does not expand generator
expressions, so xvfb-run was given the literal $<TARGET_FILE:...>.

Local-Gate: v1 tree=68604a72309e3d34ca7e9343354d71acd8c1dbc2 secs=409 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1792022409,"gate":"rust/all/fmt","host":"linux-x86_64","key":"d529a945ba00a8902ecd161f348c2352d3b0020e8865c5bef70d9c49246d8328","lane":"lint","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":43,"stamp":"b84ea637ab81b5e21f488b431e0dc00d","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"d529a945ba00a8902ecd161f348c2352d3b0020e8865c5bef70d9c49246d8328","lane":"lint","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":43,"stamp":"19b89ad1096b891a6dc91c79fcb02f54","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"d18ef087d91d45ee61df013cb92b54fc2fd46db87b46df4d75100873524827d3","lane":"rust-test","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":98,"stamp":"88b32901e3605ea26a568a05216489a0","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"68cb8242d6ce328837ed96462bab2b481eab51f3fd501daa5303a2f868807090","lane":"cross","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":72,"stamp":"f1ddde48a8f8f6025f14ba7f56bdffcf","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"68cb8242d6ce328837ed96462bab2b481eab51f3fd501daa5303a2f868807090","lane":"cross","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":72,"stamp":"def621e7d1bbd2716ffb951d9bf48b1e","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"68cb8242d6ce328837ed96462bab2b481eab51f3fd501daa5303a2f868807090","lane":"cross","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":72,"stamp":"e522914472f42391ba3283fc3b7d4e15","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"68cb8242d6ce328837ed96462bab2b481eab51f3fd501daa5303a2f868807090","lane":"cross","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":72,"stamp":"7c4f50189aef6b7f8773ca3c49b45757","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"68cb8242d6ce328837ed96462bab2b481eab51f3fd501daa5303a2f868807090","lane":"cross","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":72,"stamp":"896869ad0572e91f0f8f87d12b32e5c8","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"68cb8242d6ce328837ed96462bab2b481eab51f3fd501daa5303a2f868807090","lane":"cross","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":72,"stamp":"1d07de5a6b4bba540d32bc1ba1483c12","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
Ci-Attestation: {"at":1792022409,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"1c799fad48e8d4397f43103b310a456cd8e669309c147afb3e20db1f09570768","lane":"tier2-linux","parents":["8bd824010e84fd507a1ba10b3ddcec06434565a6"],"secs":196,"stamp":"4a221cac1352e6f44aef9eeec2fe799b","tree":"68604a72309e3d34ca7e9343354d71acd8c1dbc2","v":1,"via":"run"}
@zackees
zackees enabled auto-merge October 15, 2026 00:13
@zackees
zackees added this pull request to the merge queue Oct 15, 2026
Merged via the queue into obs-rust:master with commit c4117c4 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