Repository navigation
vlc-video: Let libVLC's playlist move finish before stopping - #1678
Merged
Merged
Conversation
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
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
force-pushed
the
fix/vlc-stop-at-track-end
branch
from
October 21, 2026 23:56
47b353f to
2b7df33
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_promptfailed 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.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.libvlc_event_detach()found nothing and calledabort(). In the backtrace, the abort is on libVLC's playlist thread inset_current_playing_item→libvlc_event_detach, while libobs' graphics thread is invlcs_stop→libvlc_media_list_player_stop. It is not a Rust panic or a C assert, and it happens in both libobs lanes.EndReachedmarks 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.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:
stop_at_track_end_is_prompt, 240 runs under loadstop_as_track_ends_stays_stopped, 6 runsRED → GREEN
test: A VLC Stop as a playlist track ends must stay in force (RED). The new casestop_as_track_ends_stays_stoppedsends a Stop from the source'smedia_endedhandler 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.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-laneplaylist_of_three_plays_every_file_to_the_endmix-analysis flakes that the open playlist-analysis PR addresses.test_vlc_drain_gatecovers the newvlc_drain_gate_opened()return value andvlc_drain_gate_stopping(). Full ctest, both lanes: 362/362 in each lane, none skipped.uv run ci/local_gate.py --lane lint: ok.Checklist
masterdocs/features.mdis added (Fixed upstream bugs, Sources and filters)-W..., ratchets): not applicable