Repository navigation
libobs: Keep a timing of its own for audio on its own clock - #4049
Conversation
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 #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 #3747. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for finding this. The cause makes sense to me: since #3752 an own-clock packet is not continuous, but it still compared against the video's One question about the new own timing: The case I mean:
If that reading is right, clearing |
Proof(a) Repeat runs, local, Tier 2 harness build tree,
Interleaved A/B (same container, master and fix
The same-clock guard read 93 % in all 32 runs. Caveat: the test still measures a real-time mix, so at roughly 4× CPU overload every case degrades, the untouched path included. This PR removes the own-clock path's extra sensitivity; it does not make the test immune to starvation. PR CI run 42502627932: (c) Non-vacuity: draft #4050 = this PR plus one commit forcing
Forcing the flag also undoes #3752, so CI shows the full 0 % bug. The load-only part of the RED is the A/B above. #4050 is closed now that the run is recorded. (d) Ruleset before enqueue (ruleset 25065309): required = |
Post-merge proof(b) merge_group run 42505884746 (head 26b6b9a), job list from the API:
Merged 2026-11-08T18:01:06Z as 26b6b9a. (d) Ruleset 25065309 re-read after merge, identical to before: required (e) Master push CI: the queue landed a batch (731a4eb → 26b6b9a → 835ce00 → d66a0fd), and Push concurrency cancels runs for intermediate commits. The run covering this change is 42507829200 on d66a0fd. It was still pending when this comment was written. |
…elay (#4143) (#4202) * test(libobs): own-clock audio from a fast sender must not build up delay (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]> * fix(libobs): take the own-clock timing again when audio runs ahead (GREEN) #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]> * docs(features): own-clock audio from a fast sender stays in sync (#4143) Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Why
test_async_audio_own_clockejected the merge queue twice. Both times it was theRust Tier 2 Linux 🐧 (tests OFF, all)job, and the only failure wassmall_packets_audio_ahead_of_video_is_heard:1024-frame packets, audio +14400 s from video: tone in 84 % of the program→heard_percent(1024, …) >= 90 is not true(test_async_audio_own_clock.c:361)tone in 87 %Diagnosis: a load-sensitive libobs bug, not #4019 and not the test
source->timing_adjust.obs_source_update_async_video()(libobs/obs-source.c.h:1933) rewrites that field to the video's timing on every shown frame, so nearly every audio packet hitunder_lock'sMAX_TS_VARreset. Each packet was then placed atos_gettime_ns(), i.e. by when it arrived, not by its timestamp. Scheduling jitter on a busy runner then becomes gaps and overlaps in the mix. 21 ms packets suffer more than 100 ms packets.Local measurement, Tier 2 harness build tree,
test_async_audio_own_clockrun directly, 16 busy loops on 16 CPUs:The same-clock guard holds at 93 % on master under the same load, so the load starves only the own-clock path. That isolates the bug, not the machine.
Fix
This changes production code. The test is not changed: same assertions, bar and timeout.
own_clock_timing_adjust/own_clock_timing_set(underaudio_buf_mutex). The first such packet seeds them from the system clock, asreset_audio_timing()does. Later packets are appended where their own timing puts them, and video frames no longer move it.libobs/obs-source-audio-output.c.h, plus two seam getter/setter pairs. Rust:obs_source::audio_outputand theobs-source-seamFFI.last_output_frame_tsand the own timing, plus a deterministic own-clock case. Parity fails against the old Rust.docs/features.md.Validation
./lintclean.soldr cargo test -p obs-data --test obs-tests-core audio_output: 33 passed.Local gate: both Tier 2 modes ran
test_async_audio_own_clockgreen (30.40 s / 30.34 s). The gate did not stamp, for two reasons unrelated to this change:test_pulse_stream_restartfailure;check_test_binary_inventorygot soldr porcelain JSON instead ofcargo metadataoutput (KeyError: 'workspace_members').So PR CI runs the full suite.
Proof runs (repeat, merge_group, non-vacuity red run, master after merge) are added in comments below as they finish.
Refs #3747.
🤖 Generated with Claude Code