Skip to content

vlc-video: Hand audio to libobs as it plays - #405

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/2406-vlc-audio-block-split
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/2406-vlc-audio-block-split

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

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.

  • libVLC 3 decodes up to 2 s ahead of its clock and passes the audio to the source's 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.92 s (Ogg) or 0.25 s (MP4). The blocks are small (20-50 ms); their timing is the problem.
  • vlcs_audio_play() (vlc-video-source.c lines 483-502) forwarded every block to obs_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.c line 1719). The meter resets after 0.5 s without new data.

The fix, in plugins/vlc-video only: 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.

  1. test/cmocka: VLC source must hand its audio over as it plays (RED): test_vlc_audio_pacing generates 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.
  2. 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_LIBOBS OFF 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 -V shows all six cases run with no skips, 34 s.
  • The existing VLC tests pass at GREEN: test_vlc_playlist_gap (4 of 4, including stop_at_track_end_is_prompt), test_vlc_audio_track (3 of 3), test_vlc_channel_order (6 of 6).
  • Full ctest: 135 of 135 at GREEN in each lane (rebased on current master).
  • Flakiness check: test_vlc_playlist_gap failed 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). Its stop_at_track_end_is_prompt case 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.
  • Without a display the cases skip (exit 77); without libVLC the test is skipped, like the other VLC tests. The VLC tests skip in CI's Tier 2 lane, so this one runs locally only.
  • Configuring with ENABLE_VLC=OFF still works; the test is not registered then.
  • clang-format, gersemi and ci/test_registration.py are clean.

Not tested:

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 and others added 2 commits October 12, 2026 11:53
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"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally (Tier 2 image + libvlc-dev, libvlc5, vlc-plugin-base, under xvfb-run):

  • RED f1c2cc4: 3 of 6 fail (opus_in_ogg, vorbis_in_ogg, aac_in_mp4 _is_handed_over_as_it_plays)
  • GREEN 61fdec1: 6/6
  • The Tier 2 image has no libVLC, so plain CI skips this test. Rebased on master, local gate passed; pushed as 600f03e.

@zackees
zackees force-pushed the fix/2406-vlc-audio-block-split branch from 61fdec1 to 600f03e Compare October 12, 2026 18:56
@zackees
zackees merged commit d720bb2 into obs-rust:master Oct 12, 2026
23 checks passed
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.
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: audio meters, filters and capture callbacks see VLC audio 1-2 s early, in bursts (upstream #2406)

2 participants