Skip to content

vlc-video: Reorder 5.1 and 7.1 audio into libobs channel order - #252

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/12579-vlc-surround-order
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/12579-vlc-surround-order

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Description

VLC Video Source played 5.1 and 7.1 audio through the wrong speakers. With this change every channel arrives where libobs expects it.

libVLC's audio callbacks deliver interleaved samples in VLC's channel order, L R [SL SR] RL RR C LFE, and vlcs_audio_play() (plugins/vlc-video/vlc-video-source.c:474) handed them to libobs unchanged. libobs reads 5.1 as FL FR FC LFE RL RR and 7.1 as FL FR FC LFE RL RR SL SR, so centre and LFE played from the rear (5.1) or side (7.1) speakers and the other way round.

  1. test: VLC source must deliver 5.1 and 7.1 in libobs channel order (RED): test_vlc_channel_order checks a stub reorder helper for 1 to 6 and 8 channels, then plays generated 5.1 back, 5.1 side and 7.1 WAV files (each channel at its own level) through the real vlc_source module with OBS in 7.1 and identifies each libobs channel by its level. 5 of 6 cases fail on this commit. The end-to-end cases skip without libVLC or a display, and the test then exits 77 so ctest reports it as skipped.
  2. vlc-video: Reorder 5.1 and 7.1 audio into libobs channel order: a small header, vlc-audio-order.h, reorders each frame in place with a fixed table for 6 and 8 channels. Other channel counts are untouched. All 6 cases pass.

libVLC's amem output always delivers interleaved S16 in a layout fixed by the channel count, so a static table is exact. VLC converts 5.1 side sources to its 5.1 layout before the callback, which is why one table covers both. A 5.1 file while OBS runs in 7.1 is covered too.

Motivation and Context

Fixes #251 (upstream obsproject/obs-studio#12579, reported by Ezriilc)

Why this one: surround media plays with the wrong speakers, and the report has clear test files from Ezriilc and theking2. pkviet confirmed and analysed the misordering upstream. His fix (obsproject/obs-studio#12601) rematrixed through swresample and needed new libobs API, which he described as too narrow; it was closed unmerged. This version swaps samples in the plugin, with no libobs change and no extra resampler.

How Has This Been Tested?

Automated: test_vlc_channel_order fails 5 of 6 at the RED commit and passes 6 of 6 at the GREEN commit, 10 of 10 repeated runs, in both the C build and the ENABLE_RUST_LIBOBS=ON build. The full ctest suite passes in both (85 of 85). Without libVLC the test reports as skipped and the unit cases still run. All runs used libVLC 3.0.23 on Linux, under a private Xvfb with software GL. clang-format and gersemi are clean.

Not tested:

  • Windows and macOS VLC builds. The fix is plain C with no platform code, and the amem output module that sets the layout is shared by all platforms.
  • 4.0, 5.0 and 6.1 sources, or OBS set to 4.0 or 4.1. VLC's 4- and 5-channel layouts (L R RL RR [C]) do not match libobs 4.0 and 4.1 (FL FR FC RC, FL FR FC LFE RC), so no reorder can fix them; this change leaves them as they were.

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

libVLC's audio callbacks hand over interleaved samples in VLC's own
channel order (L R [SL SR] RL RR C LFE). vlc_source passes them to libobs
unchanged, but libobs reads 5.1 as FL FR FC LFE RL RR and 7.1 as
FL FR FC LFE RL RR SL SR. With 5.1, centre and LFE play from the rear
speakers and the rear channels from centre and LFE; with 7.1 the same
happens between the side speakers and centre and LFE.

The test adds a stub reorder helper and checks it directly for 1 to 6
and 8 channels, then plays generated 5.1 (back and side) and 7.1 WAV
files (each channel at its own level) through the real vlc_source module
with OBS in 7.1 and checks which file channel arrives on each libobs
channel. The end-to-end cases skip without a display or libVLC, and the
test then exits with 77 so ctest reports it as skipped.

Reported upstream in obsproject/obs-studio#12579 by Ezriilc; pkviet
confirmed the cause in obsproject/obs-studio#12601.

Refs obs-rust#251.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 18:54
libVLC delivers interleaved audio in VLC's channel order
(L R [SL SR] RL RR C LFE), which vlc_source passed straight to libobs.
libobs reads 5.1 as FL FR FC LFE RL RR and 7.1 as FL FR FC LFE RL RR SL
SR, so centre and LFE came out of the rear (or side) speakers and the
other way round.

Rearrange each frame in place into libobs order before output. Mono,
stereo and 2.1 already match and are left alone. Media Source is
unaffected; it already gets FFmpeg's layout.

Upstream obsproject/obs-studio#12579, reported by Ezriilc. Based on
pkviet's analysis in obsproject/obs-studio#12601, which solved it with a
swresample channel matrix and a new libobs API; this version swaps the
samples directly in the plugin, needs no libobs change and also covers a
5.1 file while OBS runs in 7.1.

Fixes obs-rust#251.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=6c1aad0be6bc706359a56d75b20b9c23add752bd secs=124 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791745839,"gate":"rust/all/fmt","host":"linux-x86_64","key":"1d3acb98659f6443fde178ea74825f96bafb7a85263bbf395c45948c4afa90e4","lane":"lint","parents":["ea6e28c30170a5e31c2900c9ec9f47293b2e240d"],"secs":48,"stamp":"a6a844110455113ffb6ef7a3722650fb","tree":"6c1aad0be6bc706359a56d75b20b9c23add752bd","v":1,"via":"run"}
Ci-Attestation: {"at":1791745839,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"1d3acb98659f6443fde178ea74825f96bafb7a85263bbf395c45948c4afa90e4","lane":"lint","parents":["ea6e28c30170a5e31c2900c9ec9f47293b2e240d"],"secs":48,"stamp":"b585886c7c2eca3a7b2b993faa6b5139","tree":"6c1aad0be6bc706359a56d75b20b9c23add752bd","v":1,"via":"run"}
Ci-Attestation: {"at":1791745839,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"76d24570f164ae7b64ddb3cdd5d976a0e410ac3411eeba034d584bc6dbd179b1","lane":"rust-test","parents":["ea6e28c30170a5e31c2900c9ec9f47293b2e240d"],"secs":29,"stamp":"6d9cf424907a2b36f26468e4ca764b7d","tree":"6c1aad0be6bc706359a56d75b20b9c23add752bd","v":1,"via":"run"}
Ci-Attestation: {"at":1791745839,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"07a0c65db4f4a485f47a3a8114de1f624c97fe5ced2e8b319a1c790120c79b84","lane":"tier2-linux","parents":["ea6e28c30170a5e31c2900c9ec9f47293b2e240d"],"secs":46,"stamp":"8865df6b91d62f96e7e5551e139c6c82","tree":"6c1aad0be6bc706359a56d75b20b9c23add752bd","v":1,"via":"run"}
@zackees
zackees force-pushed the fix/12579-vlc-surround-order branch from 783beee to 2e1bbcc Compare October 11, 2026 19:10
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped.

  • RED (ea6e28c30): plain Tier 2 passed 83 of 84. reorder_5_1 and reorder_7_1 failed.
  • GREEN (783beee49): Tier 2 passed 84 of 84 with ENABLE_RUST_LIBOBS OFF and 84 of 84 with it ON. Under xvfb-run with libvlc5 and vlc-plugin-base installed, the whole test passed, including vlc_source_5_1, vlc_source_5_1_side and vlc_source_7_1. The local gate passed.

Non-blocking: under Xvfb without libVLC, the vlc_source_* cases fail with Failed to create source 'vlc' instead of skipping (the skip at :246 only covers the case where there's no display). Treating a NULL source as a skip would make them behave as your comment intends. Merging once CI is green.

@zackees
zackees merged commit 0281a27 into obs-rust:master Oct 11, 2026
23 checks passed
zackees pushed a commit that referenced this pull request Oct 11, 2026
…odule

With ENABLE_VLC=OFF, add_core_module() leaves a dummy custom target named
vlc-video behind. The registration only checked TARGET vlc-video, so it
still evaluated $<TARGET_FILE:vlc-video> and CMake's generate step failed:
any unit-test build without the VLC plugin stopped configuring after #252.

Check that vlc-video is a MODULE_LIBRARY before registering the test.

Fixes #253.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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: 5.1 and 7.1 audio play through the wrong speakers (upstream #12579)

2 participants