Skip to content

libobs: Follow the video timing only for audio on the video's clock - #3752

Merged
vpacher merged 3 commits into
masterfrom
fix/3747-ndi-audio-reset
Nov 6, 2026
Merged

vpacher merged 3 commits into
masterfrom
fix/3747-ndi-audio-reset

Conversation

@vpacher

@vpacher vpacher commented Nov 6, 2026

Copy link
Copy Markdown
Member

Fixes #3747

What and why

Since #522, an audio packet that continues the previous one follows the timing of its source's video when that timing moved more than MAX_TS_VAR (2 s). That lets a Video Delay (Async) filter delay audio by more than 2 s (#521). For audio on a clock of its own it places the audio far from the mix: NDI Test Patterns stamps its audio about 14191 s ahead of its video, and the program lost that audio for minutes at a time.

libobs now keeps the timestamp of the latest frame a source output, before any async filter. A continuous packet follows the video's timing only when it is less than MAX_TS_VAR from that frame, or when the source output no frame. Otherwise the timing resets to the system clock, as before #522.

  • last_output_frame_ts in struct obs_source. obs_source_output_video() writes it under audio_buf_mutex before it takes async_mutex, never nested. The audio path reads it in the lock region it already holds.
  • The decision is a new step, obs_source_audio_timing_follows_video(), in obs-source-audio-timing.c.h and its Rust port obs_source::audio_timing::follows_video(). The output path passes continuous && follows_video to the existing under-lock step, so struct obs_source_audio_timing_under and test_source_audio_timing_steps do not change.
  • The ported output path (obs_source::audio_output) reads the field through a new seam getter.

Risk: a source whose audio timestamps are 2 s or more from its video timestamps, and that has a Video Delay (Async) filter, now resets instead of following the delay. #521's cases stamp audio and video on one clock and still pass.

RED → GREEN

Real app, Linux, DistroAV 6.2.2, NDI Test Patterns as the only source, 10 minutes, share of 5 s blocks of the main recording with the pattern's audio:

Build Present Notes
Upstream 33.0.1 120 of 120
master before this PR 20 of 120 source-record on the pattern starts late or never; quit hangs then
This PR 121 of 121 source-record starts at once; clean quit; 30 fps (25 to 27 before)

How #522 was found: a bisect of libobs/ from 33.0.0-beta6 (100 %) to 10-31 (12 %), with upstream 33.0.1's frontend and modules and our C libobs at each step (#3747).

  • Rust: Tier 1 for the step and for the output path (a continuous packet on another clock resets, on the video's clock it follows), Tier 3 against the C oracle on special values and random inputs.
  • Local gate: all Linux lanes passed (Tier 2 against hybrid and the C reference, with test_async_audio_own_clock at 93 % in all four cases).
  • Windows (local MSVC build, hybrid and C reference): 1795 exports identical, 38 audio and async Tier 2 tests pass on both DLLs, 837 Rust audio_ tests pass. The new cmocka test is Linux only, like test_async_delay_audio.
  • Test cost: the new cmocka test runs about 30 s (4 cases, 7.5 s of audio each), with RESOURCE_LOCK timing like test_async_delay_audio. The new Rust tests are pure.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: its line in docs/features.md is added or updated
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: the C and the Rust change together)

🤖 Generated with Claude Code

vpacher and others added 2 commits November 6, 2026 13:00
NDI Test Patterns stamps its audio about 14191 s ahead of its video. Since
#522, a continuous audio packet follows the timing of the source's video,
which for audio on another clock places it hours from the mix: the program
is silent until a packet that does not continue the previous one resets
the timing.

The test registers an async source whose audio is stamped hours ahead of
or behind its video and checks that the mixed audio carries its tone.
RED: 100 ms packets with audio 4 h ahead and 3 h behind get 0 % on the
current C and hybrid libobs and on 7d47490 (#522); upstream 33.0.1 and
563e9eb (before #522) give 93 %, a clean tone. Guards with 1024-frame
packets and with one clock pass everywhere.

Refs #3747.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #522, an audio packet that continues the previous one follows the
timing of the source's video when that moved more than MAX_TS_VAR, so a
Video Delay (Async) filter can delay audio by more than 2 s (#521). Audio
on a clock of its own then lands far from the mix: NDI Test Patterns
stamps its audio about 14191 s ahead of its video, and the program lost
it until a packet that did not continue the previous one reset the
timing.

libobs now keeps the timestamp of the latest frame a source output, before
any async filter (last_output_frame_ts, under audio_buf_mutex, written
before async_mutex is taken). A continuous packet follows the video's
timing only when it is less than MAX_TS_VAR from that frame, or the source
output no frame; otherwise the timing resets to the system clock, as
before #522. The decision is obs_source_audio_timing_follows_video() in
the C and obs_source::audio_timing::follows_video() in the Rust port; the
ported output path reads the field through a new seam getter.

test_async_audio_own_clock passes (93 % tone in all four cases, was 0 %
with audio hours ahead or behind), and test_async_delay_audio (#521)
still passes 6 of 6 on the C libobs. Rust: Tier 1 for the step and the
output path, Tier 3 against the C oracle on special values and random
inputs.

Fixes #3747.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=f97a7d4c56f12c2948b031ba772e4eaedf839143 secs=399 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793966841,"gate":"rust/all/fmt","host":"linux-x86_64","key":"ab555b7ca8c13baccb8605d25d90f0840154f52de503e555687e77cc5bfb908f","lane":"lint","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":94,"stamp":"4cb9934b866f09b9e4f726e424b78ca9","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"ab555b7ca8c13baccb8605d25d90f0840154f52de503e555687e77cc5bfb908f","lane":"lint","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":94,"stamp":"1a58cf904554207eee6a75d1bfb99346","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"040b0acda8a23182425c05265f3dbfad2dd017d518001414e407141623f994e1","lane":"rust-test","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":120,"stamp":"10d6928b817b930528e826b21ad54aac","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":100,"stamp":"ec3f027e102f6cec6fca4b4a6b473f89","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":100,"stamp":"1620bbc0c98685fcd7fd4b240a31ba93","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":100,"stamp":"fe7d1759117ac1bc0dc31f8e9c88f318","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":100,"stamp":"1e07e8daaf2abb6ec87dc6cf535c76d0","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"81dc5736d38e2625b085e075f8eb7425aa82dc03e2a2ccdfa20137ba28245d51","lane":"tier2-linux","parents":["1b076834fe6bf69e69f7ca2c9a4342a1c1ca1b88"],"secs":399,"stamp":"fc49fbe89bee44fbe61fdae4dbcb40ae","tree":"f97a7d4c56f12c2948b031ba772e4eaedf839143","v":1,"via":"run"}
@vpacher
vpacher requested a review from zackees as a code owner November 6, 2026 12:08
Refs #3747.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=22765573e431d1d7641253e1718dfe08025bc583 secs=32 lanes=lint:run,rust-test:reused@040b0acda8a2,cross:reused@d75feb36b3b6,tier2-linux:reused@81dc5736d38e,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793966985,"gate":"rust/all/fmt","host":"linux-x86_64","key":"1033a8b7f4e7bd6118f1660e2caf6ac2940f6fa5272c5b96741ebc97d9fb9571","lane":"lint","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":32,"stamp":"d0ac6392a40492487adb5fb8b90cbfa7","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"run"}
Ci-Attestation: {"at":1793966985,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"1033a8b7f4e7bd6118f1660e2caf6ac2940f6fa5272c5b96741ebc97d9fb9571","lane":"lint","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":32,"stamp":"24d841613fff5a172701668536d15c25","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"run"}
Ci-Attestation: {"at":1793966841,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"040b0acda8a23182425c05265f3dbfad2dd017d518001414e407141623f994e1","lane":"rust-test","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":null,"stamp":"b6b5fbd8d02c839f2dae65f0e5863d4c","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"reused"}
Ci-Attestation: {"at":1793966841,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":null,"stamp":"2c04bd31973df15c26c0269d38c0bf47","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"reused"}
Ci-Attestation: {"at":1793966841,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":null,"stamp":"4d6e6b78775bc1421d7a82349efd680e","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"reused"}
Ci-Attestation: {"at":1793966841,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":null,"stamp":"fbd5880cf02a1ae5647592523de82fd8","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"reused"}
Ci-Attestation: {"at":1793966841,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"d75feb36b3b6b6b1a60bdda295767e5992fafa320e14cd194303a336e51b51cb","lane":"cross","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":null,"stamp":"8f8ccd8be7b17da4eabfcf082cfe85f4","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"reused"}
Ci-Attestation: {"at":1793966841,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"81dc5736d38e2625b085e075f8eb7425aa82dc03e2a2ccdfa20137ba28245d51","lane":"tier2-linux","parents":["11956f4db194c3397fa7a5998468a0e38af1a3de"],"secs":null,"stamp":"17518e94af3e246378b04b5703450aac","tree":"22765573e431d1d7641253e1718dfe08025bc583","v":1,"via":"reused"}
@vpacher
vpacher enabled auto-merge November 6, 2026 12:10
@vpacher
vpacher added this pull request to the merge queue Nov 6, 2026
Merged via the queue into master with commit 0907522 Nov 6, 2026
68 of 75 checks passed
@vpacher
vpacher deleted the fix/3747-ndi-audio-reset branch November 6, 2026 13:35
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Nov 8, 2026
…#4049)

test_async_audio_own_clock ejected the merge queue twice
(merge_group runs 42488016838 and 42489291203, "tests OFF" job):
small_packets_audio_ahead_of_video_is_heard heard the tone in 84 % and
87 % of the program, under its 90 % bar. Both runs completed in their
normal 30.3 s, so it was not a hang.

The cause is in libobs, not the test. Since obs-rust#3752 a continuous packet
on a clock of its own (hours from last_output_frame_ts) does not follow
the video's timing. But it still read source->timing_adjust, which
obs_source_update_async_video() sets to the video's timing on every
shown frame. So nearly every packet hit under_lock's MAX_TS_VAR
reset and was placed at os_gettime_ns(), when it arrived, instead of
by its timestamp. On a busy machine the arrival jitter turns into gaps
and overlaps in the mix, more so with 21 ms packets than with 100 ms
ones.

Audio on a clock of its own now has own_clock_timing_adjust and
own_clock_timing_set, under audio_buf_mutex. The first such packet
seeds them from the system clock, as reset_audio_timing() does. Later
packets are appended where their own timing puts them, and video
frames do not move it. Audio on the video's clock (or with no frame
yet) is unchanged. C in obs-source-audio-output.c.h, Rust in
obs_source::audio_output through two new seam getter/setter pairs.

RED (local, Tier 2 harness tree, 16 busy loops on 16 CPUs, master
2d6ae72): 6 of 6 runs of the C reference fail an own-clock case
(1024-frame 73-89 %, 4800-frame down to 71 %). The same-clock guard
stays at 93 % in all 6, so the load starves only the own-clock path.
GREEN: 5 of 5 runs each of the C reference and hybrid libobs at the
same load, every case 92-93 %. Rust: Tier 1 covers the seed and a late
continuous packet (both fail with the old wiring). Tier 3 parity
against the C oracle now generates last_output_frame_ts and the own
timing, and fails against the old Rust.

Refs obs-rust#3747.

Co-authored-by: Claude Opus 5.5 <[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: libobs: NDI audio with 100 ms frames drops out of the mix for minutes since #522

1 participant