Skip to content

vlc-video: Keep a Stop in force when the next playlist item opens - #1037

Merged
zackees merged 2 commits into
masterfrom
fix/1011-vlc-stop-drain-race
Oct 16, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/1011-vlc-stop-drain-race

Conversation

@zackees

@zackees zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member

Fixes #1011.

Bug: drain_abort (manual-reset event) cuts libVLC's audio pacing/drain waits short (up to 3 s each, on libVLC's audio thread) so libVLC's stop isn't held up. vlcs_started reset it on libvlc_MediaPlayerOpening, which libVLC fires on its event thread also when the next playlist item opens. Stopping near a track end could be undone: the audio thread re-entered a wait and libvlc_media_list_player_stop_ waited behind it, so Stop took seconds and the source stayed PLAYING. That's test_vlc_playlist_gap stop_at_track_end_is_prompt failing with took 2.068 s (state 1) in merge-group run 38850208674 (it removed #936 from the queue).

RED (test: A VLC Stop must survive the next item opening right after it): plugins/vlc-video/vlc-drain-gate.h factors the event handling out with today's behavior; test_vlc_drain_gate drives the losing order directly (stop, then opened, then a wait). Local Tier 2: test_stop_survives_the_next_item_opening failed at test_vlc_drain_gate.c:39 (the wait ran its full 2 s); the two cases that the waits still re-arm after play and after a next-item open passed.

GREEN (vlc-video: Keep a Stop in force when the next playlist item opens): a Stop (stop, restart, update, deactivate, destroy) sets a pending flag that the Opening event respects; OBS starting playback (play, restart, update, activate, unpause) clears it. Next/previous only cut the wait short, as before. The plugin uses the gate for every former drain_abort use.

Local Tier 2 (--repeat 3 --tests 'test_vlc_drain_gate|test_vlc_playlist_gap'): OFF 256/256, both tests passing 3 more times each (stop_at_track_end_is_prompt included, against real libVLC). ON: both pass; two unrelated failures, test_media_restart_stale_frame (#1032) and a test_v4l2_busy_signal case whose setup failed on "Unable to open X display" (Xvfb dropping out under parallel tests, see #838).

Note: an earlier local build of GREEN broke two braceless if bodies when the gate's play call was inserted (one failed to compile, the other compiled with wrong control flow); both are braced now and the full diff against master was reviewed line by line.

@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 16, 2026
@zackees
zackees enabled auto-merge October 16, 2026 08:15
@zackees zackees closed this Oct 16, 2026
auto-merge was automatically disabled October 16, 2026 08:19

Pull request was closed

@zackees zackees reopened this Oct 16, 2026
@zackees
zackees force-pushed the fix/1011-vlc-stop-drain-race branch from 2e42a9c to 69eb0b6 Compare October 16, 2026 08:21
@zackees
zackees enabled auto-merge October 16, 2026 08:21
@zackees

zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Correction to my earlier comment: "Unable to open X display" is not evidence that Xvfb was unreachable. It is printed by obs_nix_x11_log_info() (libobs/obs-nix-x11.c:39) whenever obs_get_nix_platform_display() is NULL, i.e. whenever nothing called obs_set_nix_platform_display(), which only the frontend does. Every cmocka test that calls obs_startup logs it, including passing ones (the next test_v4l2_busy_signal case logged it and then registered X11 hotkey keycodes fine). So the "Xvfb dropping out under parallel ctest" explanation I gave is wrong and should be disregarded; the cause of these failures is still unknown. This only affects the PR description's note about the two unrelated ON failures (test_media_restart_stale_frame, a test_v4l2_busy_signal setup failure): they are unrelated to vlc-video, but not for the reason I gave.

zackees added a commit that referenced this pull request Oct 16, 2026
…ng Qt (#1046)

The Fast Gate's "Build Touched Linux Targets" step configured the tree
without Qt, but plugins/frontend-tools is a core module that calls
find_package(Qt6 REQUIRED Widgets). So every PR that touched a plugin failed
at configure (#1031, #1037, #1016). Install the distro Qt packages for that
step so configure passes. Only the touched non-Qt targets are built, and the
Qt build and tests stay in the path-scoped Qt lane.
@zackees zackees closed this Oct 16, 2026
auto-merge was automatically disabled October 16, 2026 08:40

Pull request was closed

@zackees zackees reopened this Oct 16, 2026
zackees added a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 16, 2026
…ix) (obs-rust#1045)

* test: Qt plugins opt out before requiring Qt (RED)

The Fast Gate (obs-rust#1013) configures the touched Linux targets with no Qt.
frontend-tools calls find_package(Qt6 REQUIRED) unconditionally, so that
configure fails on every PR that builds C (obs-rust#1016, obs-rust#1031, obs-rust#1037).

* frontend-tools: Skip the plugin when the frontend is off (GREEN)

frontend-tools is frontend UI and requires Qt. Return before
find_package(Qt6) when ENABLE_FRONTEND is OFF, as the AJA, DeckLink, VST
and websocket plugins do with their own options, so the Fast Gate's
Qt-free configure succeeds.
vlc-drain-gate.h factors the VLC source's drain_abort handling out with
today's behavior: Stop signals the manual-reset event, and libVLC's
Opening event (its event thread, also at a playlist boundary) resets it
unconditionally. test_vlc_drain_gate drives the losing order directly:
stop, then opened, then a wait, which must end at once. With the reset
undoing the stop, the wait runs its full 2 s, as Stop near a track
boundary does in the plugin.

Refs #1011
…EEN)

drain_abort (now struct vlc_drain_gate) cuts libVLC's audio waits short
so libVLC's stop is not held up, but vlcs_started reset it on
libvlc_MediaPlayerOpening, which fires on libVLC's event thread also at
a playlist boundary. A Stop near a track end could be undone that way:
the audio thread re-entered a pacing or drain wait (up to 3 s) and
libVLC's stop waited behind it, so Stop took seconds and the source
stayed PLAYING.

A Stop (stop, restart, update, deactivate, destroy) now sets a pending
flag that the Opening event respects; OBS starting playback (play,
restart, update, activate, unpause) clears it. Next/previous only cut
the wait short, as before.

Fixes #1011
@zackees
zackees force-pushed the fix/1011-vlc-stop-drain-race branch from 69eb0b6 to 2a116b9 Compare October 16, 2026 08:51
@zackees
zackees enabled auto-merge October 16, 2026 08:51
@zackees
zackees added this pull request to the merge queue Oct 16, 2026
Merged via the queue into master with commit 0800069 Oct 16, 2026
25 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 21, 2026
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 added a commit to rdoupe/obs-studio that referenced this pull request Oct 21, 2026
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
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 22, 2026
…t#1678)

* test: A VLC Stop as a playlist track ends must stay in force

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

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

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
@zackees
zackees deleted the fix/1011-vlc-stop-drain-race branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: vlc-video: Stop near a playlist track boundary can take up to 3 s (drain_abort reset races the stop)

1 participant