Skip to content

bug: libobs: audio on its own clock from a fast sender plays later and later since #4049 #4143

Closed

Description

@vpacher

Summary

Since #4049, audio on a clock of its own (NDI through DistroAV, #3747) is placed at its own timestamps plus a fixed offset, which the first packet sets. Nothing moves the offset after that. If the sender's audio clock runs faster than the system clock, the audio arrives faster than the mix plays it, and the delay between arrival and playout grows without a limit. Before #4049 the delay stayed at 0.

With a sender clock 50 ppm fast (a normal crystal error), that is about 0.18 s per hour, about 4.3 s per day: audio and video go out of sync on a long-running NDI source.

Steps to reproduce

A probe on test_async_audio_own_clock (local only, not pushed): the source sends its audio packets rate times as fast as real time, stamped consistently with their samples (a sender whose audio clock runs rate times as fast as the system clock), 4 h from its video. Every 20th 100 ms packet is silent. The probe records when each packet is sent (os_gettime_ns()) and when its silence starts in the mixed program audio (obs_add_raw_audio_callback, the timestamp of the first silent sample). Linux Tier 2 harness, C reference build.

Expected and actual

Delay = silence start in the program minus the send time of its packet, over 24 s:

Sender clock Before #4049 (731a4eb) After #4049 (26b6b9a)
1.00 (control) 0 ms 0 ms
1.10 (fast) 0 ms at every marker +182 ms per marker, +2.2 s after 24 s
0.90 (slow) -11 to +0 ms -19 to +15 ms
0.90, audio on the video clock (control) -8 to +16 ms -18 to +16 ms

The 10 % rates compress the time: the growth is (rate - 1) x elapsed time, so 2.2 s in 24 s at 10 % is the same delay as about 12 h at 50 ppm. The share of program samples with the tone did not change (83 to 93 % per second, before and after), so the existing heard_percent assertions do not see this.

Cause

own_clock_timing_adjust is set once, by the first own-clock packet (libobs/obs-source-audio-output.c.h:192, and the Rust in obs_source::audio_output). After that:

  • under_lock changes it only when a packet is more than MAX_TS_VAR from next_audio_sys_ts_min. Both carry the same offset, so a continuous packet never is.
  • A fast sender's audio is never late, so the discard path (obs-audio-discard.c.h:82) that clears timing_set never runs. It would not reach the own timing in any case.
  • The placement does not compare with os_time, so the growing gap between a packet's placement and its arrival is never seen.

Before #4049, every own-clock packet took the MAX_TS_VAR reset (it compared against the video's timing) and was placed at its arrival time. That had no drift, but jitter, which #4049 fixed.

A slow sender does not drift: its audio comes late, and the late-audio path places it again.

Possible fixes (to decide)

  1. Re-seed own_clock_timing_adjust when a packet's placement is more than a threshold ahead of its arrival (data->timestamp + own_clock_timing_adjust - os_time), for example TS_SMOOTHING_THRESHOLD (70 ms). Small and local; the delay then saws between 0 and the threshold, with a jump in the audio at each re-seed (about every 23 min at 50 ppm for 70 ms).
  2. Feed that gap to the resampler as compensation, as the code already does for samples against timestamps (audio_resampler_set_compensation_error), so the audio keeps pace with the system clock with no jumps. Larger: it needs a smoothed drift estimate, and the resampler is set up only when a source's format or rate differs from the mix's.

I suggest 1 first, with the probe as a RED Tier 2 case (shorter, about 10 s at 10 %), and 2 as a follow-up if the saw is audible.

Activity

  1. added
    bug
    on Nov 9, 2026
  2. vpacher commented on Nov 9, 2026

    @vpacher
    MemberAuthor

    Claiming: #4143

    1. One PR. RED: a case in test_async_audio_own_clock with a sender clock 10 % fast and silence markers every 2 s; it expects the delay from send to program to stay under 200 ms over about 10 s. Today it grows by about 100 ms per second. GREEN: fix 1 of the issue, in C and in Rust (obs_source::audio_output): re-seed own_clock_timing_adjust when a packet's placement is more than TS_SMOOTHING_THRESHOLD ahead of its arrival.
    2. Fix 2 (resampler compensation) only as a follow-up issue, if the saw of fix 1 is audible.

    First PR today.

  3. added
    ready
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions