Skip to content

vlc-video: Drain audio before starting the next playlist item - #302

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/9345-vlc-playlist-gap
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/9345-vlc-playlist-gap

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Description

A VLC Video Source playing a playlist of audio files no longer cuts the last second of every track.

The source registered no audio drain callback with libVLC (libvlc_audio_set_callbacks_(..., vlcs_audio_play, NULL, NULL, NULL, NULL, c)). libVLC hands audio to the play callback about 1.15 s ahead of its pts and calls drain at the end of an item so the output can play out what it was given; without a drain callback the item counts as finished as soon as its last block is handed over (EndReached fires about 1.05 s before that audio is due), and the next item opens at once with its first pts about 1.04 s before the previous item's audio ends. In libobs that jump is under MAX_TS_VAR, so it takes the "exceeded TS_SMOOTHING_THRESHOLD" path in source_output_audio_data() and source_output_audio_place() puts the new item inside the buffered tail, truncating it. libobs and libVLC both behave as documented; the plugin was missing the callback.

  1. test: Cover VLC playlist track boundaries in the program mix: test_vlc_playlist_gap plays generated 3.0 s WAV tracks through the real vlc_source and measures, on program audio, when each track is heard:

    • 2 files: track 1 is heard only to 1.96 s (1.04 s missing) — fails;
    • 3 files: tracks 1 and 2 each lose their last 1.053-1.054 s — fails;
    • single file, and a stop near a track's end (must stay prompt): pass and guard the fix.

    2 of 4 fail. Skipped without libVLC or a display.

  2. vlc-video: Drain audio before starting the next playlist item: a new vlcs_audio_drain callback waits on the libVLC clock until the audio handed over so far is due (capped at 3 s), as a real audio device drains its buffer. A manual-reset drain_abort event ends a pending drain at once; it is signalled before stop, restart, next, previous, settings updates, deactivation and destroy, and reset when the next item opens. With it every track is heard from ~0.0 s to ~2.99-3.00 s, and the stop guard stays at ~0.02 s (with the abort path disabled, stop took ~1 s and the guard failed). 4 of 4 pass.

Files with video are not affected (libVLC already waits for the video output to drain there), and this does not change that path. A single file with looping on lost the same second at each repeat; the same fix covers it, though no committed case tests that.

Motivation and Context

Fixes #301 (upstream obsproject/obs-studio#9345, reported by COOLIGUAY; earlier obsproject/obs-studio#3712 and #11984)

Why this one: people use VLC playlists for music and intermission loops; every track losing its last second is audible in every recording and stream, and has been reported repeatedly since 2020. No upstream fix exists.

How Has This Been Tested?

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), rebased on current master, with libVLC 3.0.23:

  • test_vlc_playlist_gap: 2 of 4 fail at the RED commit, 4 of 4 pass at GREEN.
  • Full ctest at GREEN: 96 of 96 in each lane under a private Xvfb, test_vlc_channel_order and the new test both running; without a display or without libVLC the new test is skipped.
  • clang-format, gersemi and ci/test_registration.py are clean; the registration has the same MODULE_LIBRARY guard as test_vlc_channel_order, so ENABLE_VLC=OFF still configures.

Not tested:

  • Audio monitoring of the track starts (the reporter also mentions the monitor), mp3/AAC files (the test's libVLC has no decoders for them; WAV takes the same libVLC audio output path), pausing in a track's last second, Windows and macOS, other libVLC versions.
  • At the first boundary after libobs starts, up to ~0.08 s of the next track's head can still be lost to libobs's initial audio buffering; later boundaries are clean. The test allows 0.15 s per edge against the ~1 s bug.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner October 12, 2026 02:37
rdoupe and others added 2 commits October 11, 2026 19:44
Plays generated stereo WAV files as a VLC Video Source playlist through
the real vlc-video module and measures the program mix. Each file is a
tone whose peak rises linearly over the file, so the level of a mix
block tells which file it came from and how far into that file it is.
The cases check that every file reaches the mix from its start to its
end, for two and three files, plus guards: a single file plays
completely, and stopping while a track is finishing returns promptly.

On master (libVLC 3.0.23) the last 1.05 s of every file but the last is
missing: with two files, file 1 is heard only up to 1.948 s of 3.0 s
(1.963 s of it in the mix); with three, files 1 and 2 each lose their
last 1.056 s. The next item's audio arrives timestamped 1.039 s before
the previous one ends. The single-file and stop guards pass.

The cases need core video and libVLC; they skip (exit 77) without a
display or when libVLC is not installed.

Reported upstream in obsproject/obs-studio#9345 by COOLIGUAY.

Refs obs-rust#301.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The source gave libVLC no audio drain callback. libVLC hands decoded
audio to the play callback about 1.15 s ahead of its presentation time,
and without a drain callback it treats a track as finished as soon as
the last samples have been handed over. The playlist then starts the
next item at once, timestamped from the current libVLC clock, i.e.
about 1.04 s before the end of the audio libobs still has buffered for
the previous track. libobs places the new audio at its timestamp, which
overwrites and truncates that buffered tail, so the last second of every
track is missing from outputs and recordings.

Implement the drain callback, which libVLC calls when a track's decoded
audio ends: wait until the audio handed over so far is due, as an audio
device drains its buffer. The next item then starts after the previous
one has played out. Stop, restart, next, previous, settings updates,
deactivation and destruction signal an event that ends a pending drain
at once, so they are not held up by up to a second.

With the fix the tests' files reach the mix from 0.000-0.079 s to
2.97-3.00 s of 3.0 s at every boundary (master: the last 1.04-1.06 s
of every file but the last is missing). Files with video were not
affected: libVLC already waits for the video output to drain.

Fixes obs-rust#301.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=4d08e6ac67f9786d90c8c588b8b890372070d465 secs=143 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791773219,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9933052b5d798aaab03c4833407c5ec6bab26e09ce6251cd89826d9625676237","lane":"lint","parents":["f05953d5aad12e93090faea3b212f04d3863d945"],"secs":49,"stamp":"a4422ac46c865efc8ffd8b61265f764c","tree":"4d08e6ac67f9786d90c8c588b8b890372070d465","v":1,"via":"run"}
Ci-Attestation: {"at":1791773219,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9933052b5d798aaab03c4833407c5ec6bab26e09ce6251cd89826d9625676237","lane":"lint","parents":["f05953d5aad12e93090faea3b212f04d3863d945"],"secs":49,"stamp":"16873c0cb1a8b84620d2419f4adde738","tree":"4d08e6ac67f9786d90c8c588b8b890372070d465","v":1,"via":"run"}
Ci-Attestation: {"at":1791773219,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a48537ef36b67d58a30cb0cc19bbf10cec1547e2f4db6e379098314cf229b450","lane":"rust-test","parents":["f05953d5aad12e93090faea3b212f04d3863d945"],"secs":43,"stamp":"e6efc6d380b138987e112055a4d48764","tree":"4d08e6ac67f9786d90c8c588b8b890372070d465","v":1,"via":"run"}
Ci-Attestation: {"at":1791773219,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"856c516649ce24527e86733221a503d9cd7c4fdc707d7345642898e2ddeb3128","lane":"tier2-linux","parents":["f05953d5aad12e93090faea3b212f04d3863d945"],"secs":51,"stamp":"b2328822545a3907246bd22024b78400","tree":"4d08e6ac67f9786d90c8c588b8b890372070d465","v":1,"via":"run"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. The test needs a display and libVLC, so I ran it with xvfb-run ctest plus libvlc5 and vlc-plugin-base on each commit's Tier 2 build:

  • RED (198b5c80a): 2 of 4 passed. playlist_plays_every_file_to_the_end and playlist_of_three_plays_every_file_to_the_end failed.
  • GREEN (360f503c5): the test passed. Plain Tier 2 passed 95 of 95 with ENABLE_RUST_LIBOBS OFF and 95 of 95 with it ON, and the local gate passed.

Merging once CI is green.

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: playlist cuts the last second of every track (upstream #9345)

2 participants