Skip to content

vlc-video: Let libVLC's playlist move finish before stopping - #1678

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/vlc-stop-at-track-end
Oct 22, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/vlc-stop-at-track-end

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1677

What and why

A Stop pressed just as a VLC Video Source playlist track ends now takes effect. Before, the next item could start playing after the Stop, or OBS could abort. Restart, settings changes, "Stop when not visible", removing the source, and Next/Previous could hit the same race. Our load tests of the #1037 guard stop_at_track_end_is_prompt failed now and then, in two ways: a Stop that took 2 s and left the source PLAYING, and a SIGABRT with no message. Both come from this one race.

  • libVLC 3's media list player moves to the next item on its own thread after EndReached. That move detaches and re-attaches the list player's end-of-track listener while it holds only its callback lock. libvlc_media_list_player_stop() also drops that lock while it detaches the same listener, and it doesn't clear the pending move.
  • When a Stop met the move, one of two things happened. The move could run after the Stop: libVLC replayed the first item and then the next, and the source stayed PLAYING, unpaced, because vlc-video: Keep a Stop in force when the next playlist item opens #1037 keeps the audio-wait gate open while a Stop is pending. Or both threads detached the listener, and libvlc_event_detach() found nothing and called abort(). In the backtrace, the abort is on libVLC's playlist thread in set_current_playing_item → libvlc_event_detach, while libobs' graphics thread is in vlcs_stop → libvlc_media_list_player_stop. It is not a Rust panic or a C assert, and it happens in both libobs lanes.
  • The source now tracks the move. EndReached marks it as under way, and the list player's NextItemSet, Played or Stopped event marks it as done. stop_playback() stops the media player first, which ends the track's input thread, so no further end-of-track report can come. It then waits up to 1 s for a move that is under way, and repeats if that move started an item. Only then does it call the list player's stop. Stop, Restart, update, deactivate and destroy all use it. Next and Previous wait for a move under way before they call the list player.
  • An item that opens while a Stop is pending no longer emits media_started, and its audio is dropped instead of reaching the mix a second early.

Headless (private Xvfb, private D-Bus, fresh HOME), libVLC 3.0.24:

Build Case Result
master + test only, C lane stop_at_track_end_is_prompt, 240 runs under load 1 Stop took 2.04 s, still PLAYING
master + test only, hybrid lane same, 200 runs under load 1 Stop took 2.12 s, still PLAYING; 1 SIGABRT
master + new case stop_as_track_ends_stays_stopped, 6 runs 1 lost Stop, 5 SIGABRT
This branch, C lane whole test, 200 runs under load both stop cases 200/200, no abort
This branch, hybrid lane whole test, 200 runs under load both stop cases 200/200, no abort

RED → GREEN

  • RED commit: 8f8acc5 test: A VLC Stop as a playlist track ends must stay in force (RED). The new case stop_as_track_ends_stays_stopped sends a Stop from the source's media_ended handler and holds that report for 150 ms, so the Stop and libVLC's move to the next item meet. One second later the source must be STOPPED, with no item started after the Stop. On master, 6 of 6 runs fail (C and hybrid lanes): 1 ends PLAYING with an item started after the Stop, and 5 abort with SIGABRT.
  • GREEN: 2b7df33. The new case passes 6/6 (state STOPPED, 0 items started). Under load, 200 runs per lane of the whole test_vlc_playlist_gap: both stop cases pass 200/200 in hybrid libobs and libobs-c-reference, with no abort. The only other failures are 2 hybrid-lane playlist_of_three_plays_every_file_to_the_end mix-analysis flakes that the open playlist-analysis PR addresses. test_vlc_drain_gate covers the new vlc_drain_gate_opened() return value and vlc_drain_gate_stopping(). Full ctest, both lanes: 362/362 in each lane, none skipped. uv run ci/local_gate.py --lane lint: ok.
  • Real app: not run by hand, because the window around a track end is a few milliseconds. The cmocka case drives the real vlc-video module and libVLC.

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
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Sources and filters)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not applicable

libVLC 3's media list player moves to the next item on its own thread
after the end of a track is reported. stop_as_track_ends_stays_stopped
issues a Stop from the "media_ended" handler and holds that report until
the Stop is under way, so the Stop and the move to the next item meet,
as a Stop pressed just as a track ends does. One second later the source
must be stopped, and no item may have started after the Stop.

On master the two meet inside libVLC: the move to the next item runs
while the Stop has the end-of-track listener detached, so either the
next item starts after the Stop (state PLAYING, the Stop is lost) or
libvlc_event_detach() finds no listener to remove and calls abort().
Headless, 6 runs: 1 lost Stop and 5 aborts (SIGABRT, both libobs lanes).

Refs obs-rust#1677
@rdoupe
rdoupe requested a review from zackees as a code owner October 21, 2026 23:56
libVLC 3's media list player moves on to the next playlist item on a
thread of its own once the end of a track is reported. That move
detaches and re-attaches the list player's end-of-track listener while
holding only its callback lock, which libvlc_media_list_player_stop()
also drops while it detaches the same listener. A Stop (or restart,
settings update, deactivation, destruction, next or previous) that met
the move lost the race in one of two ways: the move started the next
item after the Stop, which left the source PLAYING with the Stop lost
(the item then plays without audio pacing, since obs-rust#1037 keeps the drain
gate open while a Stop is pending); or the second detach found no
listener and libvlc_event_detach() called abort(), taking OBS down.

The source now tracks the move: the end-of-track event marks it under
way, and the list player's NextItemSet, Played and Stopped events mark it
done. Before calling the list player, stop_playback() stops the media
player, which ends the track's input thread and so any further
end-of-track report, waits (up to 1 s) for a move under way to finish,
and repeats that if the move started an item; the list player's stop
then stops whatever the move started. Next and previous wait for a move
under way too. An item that opens while a Stop is pending no longer
emits media_started, and its audio is dropped.

Headless, the new case: 6/6 pass in both libobs lanes (state STOPPED,
no item started after the Stop), against 1 lost Stop and 5 aborts in 6
runs before.

Fixes obs-rust#1677
@rdoupe
rdoupe force-pushed the fix/vlc-stop-at-track-end branch from 47b353f to 2b7df33 Compare October 21, 2026 23:56
@zackees
zackees added this pull request to the merge queue Oct 22, 2026
Merged via the queue into obs-rust:master with commit 1fc26df Oct 22, 2026
23 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.

bug: vlc-video: a Stop as a playlist track ends is lost, or aborts OBS (libVLC 3 list-player race)

2 participants