Repository navigation
libobs: Follow the video timing only for audio on the video's clock - #3752
Merged
Merged
Conversation
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"}
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
enabled auto-merge
November 6, 2026 12:10
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_VARfrom that frame, or when the source output no frame. Otherwise the timing resets to the system clock, as before #522.last_output_frame_tsinstruct obs_source.obs_source_output_video()writes it underaudio_buf_mutexbefore it takesasync_mutex, never nested. The audio path reads it in the lock region it already holds.obs_source_audio_timing_follows_video(), inobs-source-audio-timing.c.hand its Rust portobs_source::audio_timing::follows_video(). The output path passescontinuous && follows_videoto the existing under-lock step, sostruct obs_source_audio_timing_underandtest_source_audio_timing_stepsdo not change.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
test_async_audio_own_clock, an async source with audio stamped hours from its video, 100 ms packets. The mixed audio must carry the tone. With audio 4 h ahead and 3 h behind: 0 % on master (C and hybrid) and on 7d47490 (libobs: Let audio follow a video timing move of more than 2 s #522); 93 %, a clean tone, on upstream 33.0.1 and on 563e9eb (before libobs: Let audio follow a video timing move of more than 2 s #522). Guards with 1024-frame packets and with one clock pass everywhere.test_async_delay_audio(bug: libobs: Video Delay (Async) over 2 s breaks up the source's audio (upstream obsproject/obs-studio#13830) #521) passes 6 of 6 on both, with the same delays as before.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:
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).test_async_audio_own_clockat 93 % in all four cases).audio_tests pass. The new cmocka test is Linux only, liketest_async_delay_audio.RESOURCE_LOCK timingliketest_async_delay_audio. The new Rust tests are pure.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag changes)🤖 Generated with Claude Code