Skip to content

fix(libobs): own-clock audio from a fast sender no longer builds up delay (#4143) - #4202

Merged
zackees merged 3 commits into
masterfrom
fix/4143-own-clock-drift
Nov 9, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/4143-own-clock-drift

Conversation

@vpacher

@vpacher vpacher commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #4143. The smooth correction (no steps) is #4182.

Problem

Since #4049, audio on a clock of its own is placed at its own timestamps plus an offset that only the first packet sets. A sender whose audio clock runs faster than the system clock delivers more audio than the mix plays, and the delay between a packet's arrival and its playout grows without a limit: about 0.18 s per hour at 50 ppm. Before #4049 it stayed at 0.

Change

When a packet on its own clock would be placed more than TS_SMOOTHING_THRESHOLD (70 ms) after its arrival, own_clock_timing_adjust is taken again from its arrival, as the first packet's is. under_lock then sees a jump of more than the smoothing threshold and places the packet by its timestamp. In C (obs-source-audio-output.c.h: hybrid's C reference and the oracle) and in Rust (obs_source::audio_output).

Side effect, measured: each step overwrites the ~60 ms of audio already buffered past the new position, a short skip. At 50 ppm that is once every 23 minutes. #4182 replaces the steps with resampler compensation.

Tests

  • RED ac00a56:
    • Tier 2, test_async_audio_own_clock, new case fast_sender_clock_does_not_build_up_delay: a sender clock 1.10 times the system clock, a silent marker packet every 10th, the delay from each marker's send to its start in the program audio must stay under 200 ms. C reference: marker delays (ms): 218 309 400 490 581 672 763 854 945 → FAILED. The four existing cases keep rate 1 and no markers and pass unchanged.
    • Tier 1, rust/obs-source/tests/source/audio_output.rs: a_continuous_packet_far_ahead_on_another_clock_takes_its_timing_again FAILED; a_continuous_packet_at_the_threshold_on_another_clock_keeps_its_timing (the boundary) passes.
  • GREEN 88f2cb2:
    • Tier 2, Linux harness, both modes (C reference and hybrid): 819/819, then test_async_audio_own_clock 3 more times in each mode, all passed. The new case: marker delays (ms): 0 18 36 54 0 18 36 54 0 18 36 (11 sent, 11 heard).
    • Tier 1: the 35 audio_output tests pass.
    • Tier 3: source_seam::audio_output_parity 10/10 (the oracle includes the C file, so it carries the change).
    • ./lint passes.
  • Test cost: the Tier 2 test takes 41.7 s instead of about 30 s (the new case listens 10 s plus 1.5 s); it starts one thread of its own, as the other cases do. It keeps its RESOURCE_LOCK timing. No new Rust test threads; the two Tier 1 cases run in under 1 ms.

Stimulus simulation (not in this PR)

A local harness played the 135 s audio-check stimulus through the same own-clock test source at a sender clock 1.01 times the system clock (hybrid build, program audio from obs_add_raw_audio_callback):

Sender clock Delay from send to program Discontinuities in the 60 s 997 Hz sine
1.00 0.0 ms none
1.01, this PR sawtooth 2 to 63 ms, one step every 7.03 s one at each step: notch residual -22 to -24 dBFS over about 85 ms

I did not run the stimulus on master; the tone probe in #4143 shows master without steps but with a delay that grows by the clock difference (+2.2 s in 24 s at 1.10).

🤖 Generated with Claude Code

vpacher and others added 3 commits November 9, 2026 09:06
…lay (RED)

#4143: since #4049, audio on a clock of its own is placed at its own
timestamps plus an offset that only the first packet sets. A sender whose
audio clock runs faster than the system clock delivers more audio than the
mix plays, and the delay between a packet's arrival and its playout grows
without a limit (about 0.18 s per hour at 50 ppm).

The new case sends the own-clock source's packets 1.10 times as fast as
real time, stamped by their samples, with every 10th packet silent as a
marker, and measures how long after its packet was sent each marker
starts in the program audio. It expects every delay under 200 ms. The
existing cases keep rate 1 and no markers, so they run as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…REEN)

#4143: own_clock_timing_adjust, set by the first packet on a clock of its
own, is moved by nothing else: a continuous packet never takes
under_lock's MAX_TS_VAR reset, and a fast sender's audio is never late,
so the discard path never runs. A sender clock faster than the system
clock then places its audio later and later after its arrival.

When a packet on its own clock would be placed more than
TS_SMOOTHING_THRESHOLD (70 ms) after its arrival, its timing is taken
again from its arrival, as the first packet's is. under_lock then sees a
jump of more than the smoothing threshold and places the packet by its
timestamp. In C (obs-source-audio-output.c.h, also the C reference and
the oracle) and in Rust (obs_source::audio_output).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher requested a review from zackees as a code owner November 9, 2026 08:12
@vpacher vpacher changed the title docs(features): own-clock audio from a fast sender stays in sync (#4143) fix(libobs): own-clock audio from a fast sender no longer builds up delay (#4143) Nov 9, 2026
@vpacher
vpacher enabled auto-merge November 9, 2026 08:13
@vpacher
vpacher added this pull request to the merge queue Nov 9, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Nov 9, 2026
@zackees
zackees merged commit 5067539 into master Nov 9, 2026
43 checks passed
@zackees
zackees deleted the fix/4143-own-clock-drift branch November 9, 2026 18:08
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Nov 9, 2026
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: audio on its own clock from a fast sender plays later and later since #4049

2 participants