Repository navigation
vlc-video: Drain audio before starting the next playlist item - #302
Merged
Merged
Conversation
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"}
Member
|
Verified locally, rebased onto master and stamped. The test needs a display and libVLC, so I ran it with
Merging once CI is green. |
zackees
force-pushed
the
fix/9345-vlc-playlist-gap
branch
from
October 12, 2026 02:47
360f503 to
d6f5c66
Compare
This was referenced Oct 12, 2026
This was referenced Oct 21, 2026
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.
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 underMAX_TS_VAR, so it takes the "exceeded TS_SMOOTHING_THRESHOLD" path insource_output_audio_data()andsource_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.test: Cover VLC playlist track boundaries in the program mix:test_vlc_playlist_gapplays generated 3.0 s WAV tracks through the realvlc_sourceand measures, on program audio, when each track is heard:2 of 4 fail. Skipped without libVLC or a display.
vlc-video: Drain audio before starting the next playlist item: a newvlcs_audio_draincallback 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-resetdrain_abortevent 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_LIBOBSOFF 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.test_vlc_channel_orderand the new test both running; without a display or without libVLC the new test is skipped.ci/test_registration.pyare clean; the registration has the sameMODULE_LIBRARYguard astest_vlc_channel_order, soENABLE_VLC=OFFstill configures.Not tested:
Types of changes
Checklist:
🤖 Generated with Claude Code