Skip to content

perf(linux-v4l2): OBS Audio as a native PipeWire node, no 171 ms pipe tunnel (#4119) - #4124

Draft
zackees wants to merge 10 commits into
masterfrom
perf/4119-vmic-pipewire
Draft

zackees wants to merge 10 commits into
masterfrom
perf/4119-vmic-pipewire

Conversation

@zackees

@zackees zackees commented Nov 9, 2026

Copy link
Copy Markdown
Member

Refs #4119 (step 1 of the plan: the PipeWire tunnel delay)

Problem

Under pipewire-pulse, module-pipe-source goes through PipeWire's pipe tunnel. The tunnel buffers a fixed 8192 frames (170.7 ms at 48 kHz), and no argument changes it. Since #4093 the Virtual Camera holds video frames for the same time to stay in sync, so both the camera and the mic pay that delay.

Change

  • With PipeWire found at build time (HAVE_PIPEWIRE, linking PipeWire::PipeWire), "OBS Audio" is a native pw_stream Audio/Source node.
    • Same node name (obs_virtual_microphone, or _2... for a second OBS) and the same description, so existing app selections keep working.
    • virtual_audio writes packets into a lock-free single-producer, single-consumer spa_ringbuffer, under the sync mutex, which vmic_pw_stop clears before freeing. The RT process callback reads from it.
    • The reader drops stale audio only when the backlog passes 3072 frames beyond a cycle's request, then keeps one packet (vmic_pw_skip). libobs's 1024-frame packets never trip this in steady state. When no app is linked, the ring fills and new packets are dropped, so a later reader starts from the newest audio.
    • No AUTOCONNECT: it is a device that apps link to, not a stream to play on the speakers.
  • The frame-sync hold treats the PipeWire mic as running, with no tunnel hold (mic_lead_ns = 0).
  • module-pipe-source stays the fallback when no PipeWire daemon answers within 3 s.

A prototype pw_stream Audio/Source measured 2 to 8 ms from write to a pulse reader. Through module-pipe-source the same probe measured about 150 ms.

Tests

  • RED 6a261cc: stubs, plus three cases:
    • pipewire_reader_skips_only_stale_audio
    • video_waits_for_pipewire_audio
    • pipewire_node_carries_audio, which runs in the new test_v4l2_vmic_pipewire target against the private PipeWire harness. It creates the node, checks it is listed through libpulse, writes a tone through virtual_audio and asserts that a linked capture stream receives it.
  • GREEN 3dc569c + 29aa73c: in local Tier 2, test_v4l2_vcam_audio, test_v4l2_vmic_libpulse, test_v4l2_vmic_pipewire and test_v4l2_vmic_server all pass. The 3 unrelated failures are deinterlace and slideshow-mem-cap.
  • Not run locally: RED itself, because the local gate has no per-test filter. ctest also hides the output of passing tests, so this run doesn't prove pipewire_node_carries_audio ran rather than skipped.
  • Tiers 1, 3 and 4 do not apply: this changes a C plugin.
  • Device measurement to follow.

@zackees

zackees commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

First device run of 29aa73c (verify run 42556236194). The log says started (PipeWire node).

run offset video latency audio latency
1 +29 ms 237 ms 266 ms
2 +28.5 ms 189 ms 218 ms
3 -10 ms 214 ms 204 ms

That's down from about 350 ms on both paths through the pipe source.

Quality regression: the 100 ms beeps came apart into 68 runs instead of 10, with peaks of 0.098 against 0.049 through the pipe source. The reader ran dry: libobs's packets don't arrive evenly enough for a one-packet margin.

RED 5cf75b3 / GREEN d6a538d make the reader a jitter buffer:

  • It starts, and restarts after running dry, only once 2048 frames beyond a cycle's request are waiting.
  • It drops audio only past 4096.
  • It logs underruns and dropped stale frames, at most once a minute.

A device rerun will follow.

@obs-rust-project-manager obs-rust-project-manager Bot moved this to In progress in obs-rust Multiview Nov 9, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In progress to Needs fix in obs-rust Multiview Nov 10, 2026
@vpacher

vpacher commented Nov 13, 2026

Copy link
Copy Markdown
Member

Coordinator check-in: this draft has had no activity since 2026-11-09 06:24 UTC and now conflicts with master (DIRTY). The last device run reported a quality regression: the 100 ms beeps split into 68 runs. Are you still working on it? If you have moved on, reply handed off to the coordinator. The coordinator then keeps the rebase moving, and the regression stays open for the next worker.

@vpacher

vpacher commented Nov 14, 2026

Copy link
Copy Markdown
Member

About the ~300 ms you see through the Virtual Camera, while Zoom with the camera directly has no delay: that difference agrees with what master adds today. The direct path has only the camera chain, so the 300 ms comes from OBS and the vcam path. These numbers come from the code and your earlier runs in #4119, not from a new measurement.

Delay on master (pipe-source path), at 30 fps:

Stage About Where
PipeWire pipe tunnel (fixed 8192 frames) 171 ms VMIC_PIPEWIRE_TUNNEL_FRAMES; video is held the same time through mic_lead_ns
libobs audio buffering 21 to 43 ms clean, more if it grew raw_audio comes after the buffering, and vcam_sync_flush holds video for it
Audio packet size (1024 frames) ~21 ms a frame goes out only when a full packet covers its timestamp
v4l2 input, render, GPU readback (NUM_TEXTURES 2) ~3 to 4 frames, 50 to 130 ms
v4l2loopback and the reader small

That adds up to about 250 to 300 ms. Since #4093 the sync is correct, but every delay on the audio side is also a delay on the video side.

What follows for this PR:

  1. The tunnel is the largest part that can go. Your first run of 29aa73c measured 189 to 266 ms instead of ~350 ms. d6a538d adds back a 2048-frame start threshold (~43 ms) for the jitter buffer, so I expect about 200 to 250 ms. A device run of the current head would show the delay and whether the beeps are whole again (10 runs, not 68).
  2. The branch now conflicts with master, so it needs a rebase before that run.

Two checks that split the rest:

  • Audio buffering: the OBS log line adding N milliseconds of audio buffering. If N grew during the session (for example after a source's timestamps jumped), that is the second-largest part, and the vcam pays it on both paths. "Low latency audio buffering mode" (Advanced settings, libobs fixed_buffer) caps it.
  • OBS vs vcam: film a stopwatch and compare the OBS preview with the Virtual Camera in Zoom. The gap between them is the vcam part (tunnel, hold, packet). The rest is OBS's own video path. The vcam stats from feat(mcp): Virtual Camera, media and pipeline statistics #4452 (now - timestamp per path) give the same split inside OBS.

One thing to expect with a DSLR: a camera's HDMI output often comes 50 to 150 ms after the event. To match it, the usual fix is a positive Sync Offset on the mic. libobs raises its audio buffering to cover a positive offset, and the vcam then holds video for it too. So lip sync can be correct while the total delay grows by that offset.

@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Stalled in obs-rust Multiview Nov 21, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Stalled to Needs fix in obs-rust Multiview Nov 21, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Stalled in obs-rust Multiview Nov 25, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Stalled to Needs fix in obs-rust Multiview Nov 25, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Stalled in obs-rust Multiview Nov 29, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Stalled to Needs fix in obs-rust Multiview Nov 29, 2026
pipewire_reader_skips_only_stale_audio, video_waits_for_pipewire_audio and
pipewire_node_carries_audio (test_v4l2_vmic_pipewire, private PipeWire)
fail against the stubs. A prototype pw_stream Audio/Source measured 2-8 ms
from write to a pulse reader, against ~150 ms through module-pipe-source.
…4119)

With PipeWire the microphone is a pw_stream node fed from a lock-free ring:
no FIFO and no pipe tunnel, whose fixed 8192-frame buffer (170.7 ms) both
the audio and the frame-synced video paid. The reader drops stale audio
only past 3072 frames beyond a cycle's request, then keeps one packet, so
libobs's 1024-frame packets never trip it. module-pipe-source stays the
fallback when no PipeWire daemon answers.
…er (#4119)

On the device the node cut the delay to 190-235 ms but the beeps came
apart into 68 runs instead of 10: libobs's packets arrive too unevenly to
read the ring down to one packet. pipewire_reader_is_a_jitter_buffer fails
against the stub plan.
…runs (#4119)

The reader starts, and restarts after running dry, once 2048 frames beyond
a cycle's request wait, and drops audio only past 4096. Underruns and
dropped stale frames are logged at most once a minute.
…er (#4119)

On the device (d6a538d) the beeps came through whole again (10 runs,
peak 0.046) with audio 215-236 ms and video 170-204 ms, but the audio
trailed by 23-64 ms: the 2048-frame jitter buffer is not in mic_lead_ns.
…4119)

Ci-Attestation: {"at":1796412752,"gate":"general/all/client-lint","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"a8575493ce3e1fb0c4ccb7a7d2739360","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412753,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"7890b8a8b2cf61468787070c7c6173b5","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412753,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"b2fe07217aabf59d7c89ad66bf938352","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412753,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"a739d0579bdf951d770a7531df0c12b0","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412753,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"42c3ffd64c366fa5935abd8bb85c19d5","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412752,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"f4f6a8847fa928da26bc91eda7a93d23","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412752,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"6cd77c1e4afa100d7d76476174f77cf2","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412753,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"e3168715c983076780e2510358479a6d","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412753,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"e99378154e5389320e81408aad4d1a19","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412752,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"5de764e2929ac902c59672debfd5ea54","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412753,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"c657f96c7cba53d2490e0398349823a8","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412752,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"c79e8842d663e732b5f761126815f41a","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
Ci-Attestation: {"at":1796412752,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"bae06c77069357b53a1f22ffbbcef19d9c7899852b0e7acb36a87127448efe23","lane":"client-lint","parents":["f65f316300f536d762561f51eec9ebb86a553dbb"],"secs":177,"stamp":"002b777982606579439fc4e8222548e8","tree":"c570cd7635148e7051a3ab0cd092f0eec0eff3cc","v":1,"via":"run"}
@zackees
zackees force-pushed the perf/4119-vmic-pipewire branch from 31a5cdb to 302fc1a Compare December 4, 2026 19:32

This branch had an error being deployed

1 failed (outdated) deployment
bouf — c80f76bc Deployed Nov 9, 2026 by zackees via Build macos x86_64 🧱 #166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs fix

Development

Successfully merging this pull request may close these issues.

2 participants