Repository navigation
vlc-video: Hand audio to libobs as it plays - #405
Merged
Merged
Conversation
Upstream obsproject/obs-studio#2406 (reported by univrsal): with an Opus file, the VLC Video Source's volume meter shows a level for a moment and then resets about every second, although the audio plays and records fine. CodyJung traced it to libVLC handing the audio over in bursts and the meter resetting after 0.5 s without new data; kkartaltepe noted that audio capture callbacks get async audio exactly as the source delivers it. The test generates files with FFmpeg (checking by demuxing what they actually hold), plays them through the built vlc-video module and records every hand-over to libobs with an audio capture callback, plus the program mix. During playback no hand-over may carry more than 50 ms, hand-overs may be at most 100 ms apart, timestamps must run on without jumps and the whole file must reach the mix. On master libVLC 3.0.23 hands Opus and Vorbis in Ogg over in bursts 0.92 s apart and AAC in MP4 in bursts 0.25 s apart, up to 2 s ahead of the mix: those three cases fail. WAV and Opus in WebM are handed over steadily and pass, as does a pause/resume guard. Skips without a display, without libVLC, without an encoder or when libVLC cannot play the file, like the other VLC tests. Refs obs-rust#404 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
libVLC decodes up to two seconds ahead of its clock and passes the audio to the amem callback as soon as it is decoded. With its Ogg and MP4 demuxers that comes in bursts: about a second of audio at once, then nothing for 0.9 s (0.25 s for MP4). vlcs_audio_play() forwarded every block to obs_source_output_audio() immediately. libobs places the audio by its timestamps, so playback was fine, but volume meters and every other audio capture callback see the audio when it is handed over: the meter jumped, then reset after 0.5 s without data, and ran up to 2 s ahead of what is heard. Hold each block in vlcs_audio_play() until it is due to play in 100 ms, as an audio device's blocking write does. The wait uses the drain abort event, so stopping or moving to the next playlist item still cuts it short. Timestamps are unchanged. Fixes obs-rust#404 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Local-Gate: v1 tree=42f778f639a64d8332e5bd6097d4c05ab4f74430 secs=181 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791831376,"gate":"rust/all/fmt","host":"linux-x86_64","key":"8fe96ec471c867f28e8878002154c3f82e7e44b5108faa5d5a58c1a89a45e150","lane":"lint","parents":["df53bc7731643955cfa6fc50ccdf7dfbd06f3977"],"secs":54,"stamp":"2cf1ead060eb40adaa05f375c3a73413","tree":"42f778f639a64d8332e5bd6097d4c05ab4f74430","v":1,"via":"run"} Ci-Attestation: {"at":1791831376,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"8fe96ec471c867f28e8878002154c3f82e7e44b5108faa5d5a58c1a89a45e150","lane":"lint","parents":["df53bc7731643955cfa6fc50ccdf7dfbd06f3977"],"secs":54,"stamp":"d4e00627582002dfb3fe2b5acce1a162","tree":"42f778f639a64d8332e5bd6097d4c05ab4f74430","v":1,"via":"run"} Ci-Attestation: {"at":1791831376,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8b2fc9460d05546b4a6f1541002e3db5cf83695eed174460e52bf173be19c4ed","lane":"rust-test","parents":["df53bc7731643955cfa6fc50ccdf7dfbd06f3977"],"secs":58,"stamp":"a905090c94846652ada878b0b2f7d055","tree":"42f778f639a64d8332e5bd6097d4c05ab4f74430","v":1,"via":"run"} Ci-Attestation: {"at":1791831376,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"716775ed0d04f13f0648bf2c4ceeda94d0f58473045ae06ef36f766b83da1225","lane":"tier2-linux","parents":["df53bc7731643955cfa6fc50ccdf7dfbd06f3977"],"secs":69,"stamp":"f0152a6b5a321a068564b8e44ca87b56","tree":"42f778f639a64d8332e5bd6097d4c05ab4f74430","v":1,"via":"run"}
Member
|
Verified locally (Tier 2 image + libvlc-dev, libvlc5, vlc-plugin-base, under xvfb-run): |
zackees
force-pushed
the
fix/2406-vlc-audio-block-split
branch
from
October 12, 2026 18:56
61fdec1 to
600f03e
Compare
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 23, 2026
…obs-rust#1854) (obs-rust#1867) * test(ci): RED merge queue ends with the cache janitor at the obs-rust#405 pin (obs-rust#1854) * ci: GREEN sweep caches at the end of the merge queue under the 10 GB budget (obs-rust#1854) ci.yml's final cache-janitor job needs every other job, runs on always() for merge_group only, and holds the non-cancelling cache-janitor group. At the forge-ci/ci.yml#405 pin it evicts least recently used caches down to [cache].budget, so GitHub's eviction never picks. ci-pre.yml's sweep now runs on master pushes only. CI Gate never waits on the sweep.
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 now hands its audio to libobs as it plays. Before, with Opus or Vorbis files (.opus, .ogg) its volume meter showed a level for a moment and then reset about every second, and for every file type the meter ran up to 2 s ahead of what is heard.
vlcs_audio_play()(vlc-video-source.clines 483-502) forwarded every block toobs_source_output_audio()at once. libobs places the audio by its timestamps, so playback and recordings were right, but volume meters and every other audio capture callback (obs-websocket's InputVolumeMeters too) see the audio when it is handed over (obs-source.cline 1719). The meter resets after 0.5 s without new data.The fix, in
plugins/vlc-videoonly:vlcs_audio_play()holds each block until it is due to play in 100 ms (AUDIO_LEAD_US), as an audio device's blocking write does. Timestamps are unchanged. The wait uses the drain abort event from #302, so stopping or moving to the next playlist item still cuts it short. No decoder or hardware decoding choice changes.test/cmocka: VLC source must hand its audio over as it plays (RED):test_vlc_audio_pacinggenerates files with FFmpeg (and checks by demuxing that they hold 4 s of the intended codec), plays them through the built vlc-video module and records every hand-over with an audio capture callback, plus the program mix. During playback no hand-over may carry more than 50 ms, hand-overs may be at most 100 ms apart, timestamps must run on without jumps and the whole file must reach the mix.opus_in_ogg_is_handed_over_as_it_plays(the report): fails, bursts 920 ms apart.vorbis_in_ogg_is_handed_over_as_it_plays: fails, bursts 921 ms apart.aac_in_mp4_is_handed_over_as_it_plays: fails, bursts 250 ms apart.wav_is_handed_over_as_it_plays,opus_in_webm_is_handed_over_as_it_plays: controls that libVLC already hands over steadily. Pass.opus_in_ogg_pause_and_resume: guard that no audio is lost around a pause. Passes.vlc-video: Hand audio to libobs as it plays: 6 of 6 pass. Hand-overs are at most 23 ms apart, and at most 0.17 s ahead of the mix (was 1.2 to 2.1 s).Motivation and Context
Fixes #404 (upstream obsproject/obs-studio#2406, reported by univrsal; reproduced twice by WizardCM, traced by CodyJung and kkartaltepe).
Why this one: the volume meter is how users check a source's audio at a glance, and for Opus and Vorbis files in the VLC Video Source it is unusable. Upstream verified it twice and two contributors traced it, but it was closed as stale with no fix. The change also brings the meter of every VLC Video Source in line with what is heard. It may help obsproject/obs-studio#11711 (a compressor on a VLC Video Source, sidechained to a microphone, ducks about a second late), because async audio filters also run when the audio is handed over; that was not tested here.
How Has This Been Tested?
Automated, with libVLC 3.0.23 (its Ogg, Matroska and Opus plugins and the FFmpeg codec plugin), in both libobs lanes (
ENABLE_RUST_LIBOBSOFF and ON; the plugin is C in both), on current master:test_vlc_audio_pacing: 3 of 6 fail at the RED commit, 6 of 6 pass at GREEN.ctest -Vshows all six cases run with no skips, 34 s.test_vlc_playlist_gap(4 of 4, includingstop_at_track_end_is_prompt),test_vlc_audio_track(3 of 3),test_vlc_channel_order(6 of 6).test_vlc_playlist_gapfailed once in 35 runs at GREEN (in a sequential run of all four VLC tests; that log was not kept) and passed the other 34 (10 alone, 18 with the other VLC tests, 6 of them in parallel). Itsstop_at_track_end_is_promptcase now stops during the next item rather than while the first is still being handed over, so its comment about the one-second lead is stale. Watch this test on review.ENABLE_VLC=OFFstill works; the test is not registered then.ci/test_registration.pyare clean.Not tested:
Types of changes
Checklist:
🤖 Generated with Claude Code