Skip to content

media-io: Port audio-io to Rust - #289

Merged
zackees merged 31 commits into
obs-rust:masterfrom
chriscoveries:port/audio-io
Oct 12, 2026
Merged

zackees merged 31 commits into
obs-rust:masterfrom
chriscoveries:port/audio-io

Conversation

@chriscoveries

Copy link
Copy Markdown
Contributor

Refs #153.

Problem

libobs/media-io/audio-io.c drives every audible output in OBS: it owns the audio thread, the mix inputs, the resamplers and the conversion taps. It was one of the last whole-file units of media-io/ still in C, so nothing in the audio path could use the Rust port conventions (safe core + ffi shim + C-oracle parity).

Root cause

Not a defect — a port. The unit is a clean boundary: the C file owns one struct audio_output per handle, one worker thread per handle, and a DARRAY of inputs per mix, with 10 exported entry points and no shared global state.

Fix

What is ported. rust/obs-media-io/src/audio_io.rs is the safe core (worker loop, AudioMix, input dispatch, resampler tap, Stop/Drop), rust/obs-media-io/src/ffi/audio_io.rs is the thin extern "C" shim. All 10 entry points are ported: audio_output_open, close, connect, disconnect, active, get_info, get_block_size, get_channels, get_planes, get_sample_rate. The port lives in #[cfg(unix)] mod port because the thread/timer surface is POSIX-only; Windows keeps the C source. The upstream media-io/audio-io.h static inline helpers are Rust helpers, not C boundary entry points — nothing is exported and nothing is swapped (ffi/audio_io.rs:1, and libobs/cmake/rust-exports.d/obs-media-io-audio_io.txt contains only the 10 audio_output_* names). The enum-conversion helpers live in src/ffi/audio_io.rs:90-118 over the C c_int values, and the frame/time helpers (audio_frames_to_ns, ns_to_audio_frames) live in src/audio_io.rs:224-236.

CMake. libobs/CMakeLists.txt guards media-io/audio-io.c as ON-only on non-Windows ($<$<NOT:$<AND:$<BOOL:${ENABLE_RUST_LIBOBS},$<NOT:$<PLATFORM_ID:Windows>>>>:media-io/audio-io.c> (libobs/CMakeLists.txt:166, pasted verbatim)), and the 10 symbols are exported through libobs/cmake/rust-exports.d/obs-media-io-audio_io.txt.

C quirks mirrored deliberately, not fixed

Each is cited in both languages, because a reviewer should not have to trust the port's word for "same behaviour":

  • Resampler residue and the derived ts_offset. The decoder keeps a carried remainder so a non-integer rate ratio does not drift: in libobs the resampler returns ts_offset = swr_get_delay(context, 1e9) and the caller applies data->timestamp -= offset (libobs/media-io/audio-io.c:95, :101); in the test oracle the equivalent is an explicit remainder, acc = residue + in_frames*dst_rate; out = acc / src_rate; residue = acc % src_rate, with ts_offset = residue * 1e9 / src_rate / dst_rate (rust/obs-c-oracle/oracle/audio_io_posix.c:156-180). Both are zero for integer ratios, and the port mirrors the subtraction at rust/obs-media-io/src/audio_io.rs:505 (data.timestamp = data.timestamp.wrapping_sub(offset)). Pinned by a test at an exact non-integer ratio, resample_ts_offset_parity (tests/audio_io_parity.rs:825): a 48000 Hz mix buffer resampled into a 44100 Hz input, so 1024 in → 940 out (1024×44100/48000 = 940.8) with the carried remainder giving an 18140 ns offset shifted off new_ts.
  • Resampler creation fails when it cannot serve the conversion. audio_input_init treats a null resampler as a failed connect rather than a pass-through (libobs/media-io/audio-io.c:276-283, blog(LOG_ERROR, "audio_input_init: Failed to create resampler")), and the port mirrors that in rust/obs-media-io/src/audio_io.rs:728-735.
  • Re-entrant close is undefined, exactly as in C. libobs/media-io/audio-io.c:392-414 signals the stop event and calls pthread_join(audio->thread, …) with no re-entrancy guard, so a close issued from inside a callback joins the calling worker thread. pthread_join on the calling thread is undefined, so re-entrant close is undefined on both sides and the port does not promise what C never kept. Documented at rust/obs-media-io/src/ffi/audio_io.rs:189-195.
  • Three documented deviations, all on unreachable-but-defined inputs (rust/obs-media-io/src/audio_io.rs:272-281):
    • a NULL input_callback: the C calls the pointer unconditionally and faults, while the port treats the tick as failed and returns;
    • a NULL output callback: the C accepts the connect (same return value) but faults on the next dispatch, while the port skips the dead call and keeps the input active;
    • a mid-dispatch removal that shrinks the list below the loop's current index: the C reads the stale darray tail and invokes it, while the port skips — there is no defined C equivalent to reproduce.
      Each is listed in the port's module docs, and none is reachable through a well-formed caller.

Options considered and rejected: porting the Windows worker too in the same PR (the thread and timer surface is POSIX-only, so Windows would be untested); keeping a C shim window (nothing gains, and the export list already isolates the symbols).

Evidence

  • Tier 1 (this head): audio_io 6/6, audio_io_core 6/6, audio_io_inlines 13/13, audio_io_inlines_layout 9/9, audio_io_layout 4/4.
  • Tier 3 (this head): audio_io_parity 14/14, compared against a C oracle compiled from libobs/media-io/audio-io.c in the same binary. Ticks are driven explicitly on NO-WORKER fixtures (oracle_audio_output_open_no_thread / AudioOutput::open_no_worker, tests/audio_io_parity.rs:184-193) so no state is racing the real thread; the only test that starts a real worker is real_worker_close_join (tests/audio_io_parity.rs:1554-1608), which exercises the close ordering the C callers get. State compared includes cur_pos, frames, bytes, timestamps, and per-input dispatch.
  • Parity ×20 (this head): audio_io_parity 14/14 on arm64 macOS and on claw x86_64 Linux, zero flakes.
  • Both build profiles: cargo test and cargo test --release both pass. A release-only failure in fresh_clamp_snapshot_parity was root-caused to identical-code folding, not float math: fs_new_*/fs_clamped_* had byte-identical bodies, the linker merged them, and the C's per-mix (callback, param) duplicate check then refused the second connect — so the clamped sibling never existed. Distinct black_box immediates keep the two callbacks' pointers distinct (tests/audio_io_parity.rs:523-549); the recorded behaviour is unchanged.
  • Mutations, each run and reverted: replacing the ts_offset subtraction with an addition makes resample_ts_offset_parity fail at its assert_eq!(c_log, [(0, 940, MAGIC + 21_000_000 - 18140)]) (tests/audio_io_parity.rs:865); disabling the null-resampler rejection makes resample_failure_parity fail at its assert!(!c_ok) (tests/audio_io_parity.rs:785, inside resample_failure_parity at :757). Removing the oracle's own rejection as well is what confused an earlier pass — both sides reject, so the test still passes; the discriminating case is the Rust one and it is the one pinned here.
  • compile_fail doctests: AudioOutput::open and AudioOutput::connect each fail to compile with error[E0133]: call to unsafe function ... requires unsafe function or block — the contract is that these are unsafe under the lifetime rules, and the test fails for that stated reason rather than incidentally.
  • Tier 2: the cmocka suite ran 71 passed / 1 skipped (test_svt_av1, a build-time skip) both with ENABLE_RUST_LIBOBS OFF and ON, with 1,752 identical exported symbols each way, in run 38184928372 on this PR's head f15a6827a.
  • Fork review: a source review on our fork (media-io: port audio-io.c to obs-media-io chriscoveries/obsrust-fork#35, refreshed to 28ff3237e) found an aliasing hole in the close path, fixed on this branch — see "Close ordering" in the Status section.

How this was tested

  • RED → GREEN: shown with the target's own CMake flags, not a locally-added sanitizer — the audio_io targets are built with ASan and are UBSan-clean under the Tier 2 flags, and the -fsigned-char modelling on arm64 is local to this machine's runs rather than something CI applies. The parity tests compare against a C oracle compiled from libobs/media-io/audio-io.c in the same cargo test binary, so "matching C" is checked at runtime. The mutations above show the tests discriminate: each one fails with its fix reverted and passes with it restored.
  • Our own CI, pinned to this PR's head f15a6827a: run 38184928372 is green. The gate (lint and Rust Tiers 1–3) ran on an RD box, and Tier 2 ran natively on Debian 13 (claw, GCC 14). The report-only release-profile step showed only the two failures that current master already has (mul_dst_aliases_q1, utf8_to_wchar_matches_c_oracle), and nothing from this change. Also run on arm64 macOS: the release suite (0 failures) and ×20 parity. git merge-tree --write-tree upstream/master f15a6827a is clean.
  • Real runs: not applicable yet — OBS was not run with this port enabled. The audio-io port has been exercised only through the Rust test suite, the C-oracle differential tests, and the cmocka Tier 2 runs. A real-app run (a recording with audio on macOS arm64 and x86_64 Linux, comparing dropped-frame counts against master) has not been performed for this change and would need to be before the port ships.
  • Cross-platform: tested on macOS arm64 (native) and x86_64 Linux (claw). Windows was not tested — the port is #[cfg(unix)] and Windows builds keep the C source, so nothing in this change is exercised there.
  • Review before posting: I wrote this description from source while gating the branch; a second reviewer (Codex sol) checks that each test proves its claim, and the owner approves every post.

Compatibility & risk

  • C API/ABI: unchanged — 10 exported names with unchanged signatures, verified by the identical 1,752-symbol export list OFF and ON.
  • Wire protocol / on-disk format: none. Audio never crosses a wire.
  • Behaviour: the observable behaviour of an audio_output is unchanged within the limits above; the deliberate differences are the ones listed under "C quirks", and the real-run gap is the material one.
  • Not tested: Windows (port is Unix-only), and any real-app audio run.

Status

Ready for review.

Close ordering (fork-review finding, fixed on this branch)

The fork's source review flagged that the first draft's close rebuilt the owning Box before joining, so Drop's &mut AudioOutput was live for the whole join while a callback already in flight could still hold &Shared through a re-entrant disconnect — &/&mut aliasing that C has no rule against, but Rust does. Fixed at 2785f6a0a: audio_output_close now sets stop and joins through the raw pointer only (AudioOutput::stop_and_join, rust/obs-media-io/src/audio_io.rs:1050), and reconstructs the Box only after the worker is dead and every callback has returned, so no &mut ever overlaps a live & (rust/obs-media-io/src/ffi/audio_io.rs:196-208). Re-entrant close from inside a callback stays UB (self-join), exactly as pthread_join on the calling thread is UB in the C — documented at rust/obs-media-io/src/ffi/audio_io.rs:189-195.

Evidence:

  • close_overlap::close_join_overlaps_inflight_disconnect (tests/audio_io.rs:371, module at :313) forces the exact interleaving without sleeps: the callback parks until a #[cfg(debug_assertions)] seam (stop_and_join_begins, rust/obs-media-io/src/audio_io.rs:1029) proves close is inside the join, then the callback runs a re-entrant disconnect, then close must complete before a 30 s deadline that fails otherwise. It demonstrates the overlap rather than merely allowing it: the callback records the seam at the moment it calls disconnect and the test asserts it was already inside the join — removing the barrier wait makes the test fail on that assertion (checked and reverted), and reverting close to drop(Box::from_raw(..)) makes it fail on the deadline (checked and reverted). What the test does not do is observe the aliasing UB itself, which has no runtime signature; soundness rests on the construction — no &mut exists until after the join. (The seam is debug-only, so the test is gated; cargo test --release compiles and runs everything else.)
  • real_worker_close_join (tests/audio_io_parity.rs:1439, close at :1499-1500) now closes through the real FFI path (Box::into_raw → audio_output_close) so the parity suite exercises the same ordering the C callers get.
  • Miri is not used: the worker calls C ABI functions (os_sleepto_ns_fast, blog, profile_start) on every tick, so Miri cannot run the real path — the guarantee rests on the by-construction ordering plus the forced-interleaving test.


Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.


Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.

cmocka test pinning the current C behavior of libobs/media-io/
audio-io.c ahead of the obs-media-io port (Phase 5). audio-io.c is the
smallest media-io unit not already claimed by an open port order.

- open(): AUDIO_OUTPUT_INVALIDPARAM for unset format/name/rate/speakers
  (no thread spawned, *audio untouched); getters mirror audio_output_info
  (interleaved float stereo: 1 plane / 2 ch / 8-byte block; planar
  16-bit 5.1: 6 planes / 6 ch / 2-byte block).
- connect(): NULL/zero conversion fields fall back to the output info;
  duplicate (callback, param) on one mix is refused while the same
  callback with a different param registers a second input; out-of-range
  mix index and NULL audio return false.
- active(): tracks registered mix inputs through connect/disconnect.
- Thread model: open() spawns the input thread immediately and the
  callback fires on the audio clock.
- Characterized crashes (not endorsed): the unguarded NULL getters and,
  with no obs core running, audio_output_open itself die by signal
  (the spawned thread dereferences obs->name_store on entry) - each
  pinned in a forked child with cmocka's signal handlers reset.

The behavioral pins need a running obs core (obs_startup), which needs
a display on Linux; they skip in the headless gate and run under
xvfb-run.

Refs #45

Local-Gate: v1 tree=f3d2e26bde1bcfec8370af8c615fa43998fc9ae9 secs=350 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791672334,"gate":"rust/all/fmt","host":"linux-x86_64","key":"f06beafdad8c0e6401d54ec504cdbb4c6ff8cc9c99298d7770b1042156188009","lane":"lint","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":199,"stamp":"68289f5197c34c3b485811e11aef0a06","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Ci-Attestation: {"at":1791672334,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"f06beafdad8c0e6401d54ec504cdbb4c6ff8cc9c99298d7770b1042156188009","lane":"lint","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":199,"stamp":"ea4878636b524b67d0b5a5c00246cd9b","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Ci-Attestation: {"at":1791672334,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"9b440df8274dd21e1d86abf9f72adc95f209321fa7b3613730625747620dda42","lane":"rust-test","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":78,"stamp":"9a81bd835884cc8f59413b7b65a44cac","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Ci-Attestation: {"at":1791672334,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b6e993eabe33d303d6a813f6a7b6c6c5edf09ddebf517c252f712b9d95b33f63","lane":"tier2-linux","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":71,"stamp":"8e4d35b0e6cf8b077f8de1178e0f2bfa","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Local-Gate: v1 tree=18904b28bd85ff6ff08ce80f10dae94dda139a76 secs=38 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791675132,"gate":"rust/all/fmt","host":"linux-x86_64","key":"ba65b923f501ad750e65692f42aaa0a23a3021236d6ae0efd3f1c94918d7cee1","lane":"lint","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":5,"stamp":"db7e536db53a4bb710d35628331746f3","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
Ci-Attestation: {"at":1791675132,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"ba65b923f501ad750e65692f42aaa0a23a3021236d6ae0efd3f1c94918d7cee1","lane":"lint","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":5,"stamp":"62b64d1aa0d162a22ecf50075452742a","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
Ci-Attestation: {"at":1791675132,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8ab76ba0fdab0ca2f07ef85c35d69bdce29faac588a2f8d7b312b2cd664d174e","lane":"rust-test","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":21,"stamp":"eb5d4333df52d26eb3ebf743f506d30b","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
Ci-Attestation: {"at":1791675132,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"ee43101ce8b5a6c42ef660cf7f6f55c3532aaadab25c2ee4811df6d285c824a2","lane":"tier2-linux","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":12,"stamp":"2fa187fac20ed6705d15911748c303f8","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
…ports, CMake guard

Local-Gate: v1 tree=b0d37c50648fedd90d45a53a68682687375723fd secs=38 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791676261,"gate":"rust/all/fmt","host":"linux-x86_64","key":"513bbe2674affe21c0e4bb62291449daf078db08f0afd1a8231ba5359326d7fb","lane":"lint","parents":["0777204d9f936a2e9741dfefb798b605cd1a6de2"],"secs":6,"stamp":"860600ead55f5d4135241a44f340641a","tree":"b0d37c50648fedd90d45a53a68682687375723fd","v":1,"via":"run"}
Ci-Attestation: {"at":1791676261,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"513bbe2674affe21c0e4bb62291449daf078db08f0afd1a8231ba5359326d7fb","lane":"lint","parents":["0777204d9f936a2e9741dfefb798b605cd1a6de2"],"secs":6,"stamp":"f2f120d298dd824d6b5a0fd3248193d0","tree":"b0d37c50648fedd90d45a53a68682687375723fd","v":1,"via":"run"}
Ci-Attestation: {"at":1791676261,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"b26e7cff950126054ff8e439b9048491024a6da880c204bcda54f049530fdae9","lane":"rust-test","parents":["0777204d9f936a2e9741dfefb798b605cd1a6de2"],"secs":23,"stamp":"055233e0bff991cfc781e1ad9c94fd28","tree":"b0d37c50648fedd90d45a53a68682687375723fd","v":1,"via":"run"}
Ci-Attestation: {"at":1791676261,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"3e0d14b2277d8ea03c5a75043d7c71df4d74b33b758b590a4bc921ef80ede97e","lane":"tier2-linux","parents":["0777204d9f936a2e9741dfefb798b605cd1a6de2"],"secs":9,"stamp":"05076951ef38cb25cdaf8189056f21e4","tree":"b0d37c50648fedd90d45a53a68682687375723fd","v":1,"via":"run"}
…loud Tier2

Codex-review-driven additions, all failing on the current port:
- tests/audio_io_core.rs: safe-API core tests (does not compile — the core
  is still unsafe-FFI-shaped), incl. the output-dispatch mutation guard,
  NULL output-callback connect (accepted, skipped — documented deviation
  from the C's crash), NULL input_callback no-op tick (currently panics on
  unwrap), re-entrant disconnect/connect inside an output callback, and an
  allow_clipping clamp check.
- tests/audio_io_parity.rs: proptest over marker values (NaN/out-of-range),
  timestamp deltas, and 1-3 inputs comparing the full output sequence.
- test/cmocka/test_audio_io.c: the four obs_startup-gated cases assert
  instead of skipping so headless Tier 2 can't pass silently.
open() spawns a real audio thread on both sides, whose ~21 ms worker
ticks race the driver's explicit oracle_audio_tick/tick_for_test calls
and the shared TICK recorder. Review comment on fork PR #35:
- DRIVER mutex held for every test body so parallel #[test]s cannot
  interleave into TICK/ORDER.
- Every recorded action now gates on the timestamp: input callbacks
  already filtered start_ts==MAGIC, but output callbacks pushed into
  TICK whenever it was Some; record_output and output_full_* now also
  require data.timestamp in [MAGIC, MAGIC+1e9), which real worker
  ticks (os_gettime_ns ~1e18) never enter.
No production-code change; all 4 tests still pass.
Deterministic C-vs-Rust regressions (fork PR #35 acceptance):
- self_disconnect_parity: oracle removes only itself, the port's
  iter_mut().rev() drops the whole tail — 1 vs 0 inputs left.
- earlier_input_removal_parity: [A,B,C] with B removing A => order
  [3,2,2] (shifted element re-invoked) — locks the index-read
  semantics in for the rewrite.
- vec_growth_parity: a callback connects a 5th input; the oracle's
  fixed bound yields [4,3,2,1], the port yields [4,3,2].
- concurrent_connect_disconnect_parity: churn from another thread
  across 10 driven ticks + quiesced final-tick order.
- audio_io_core.rs call sites move to the new safe API (connect takes
  Option<&audio_convert_info>, disconnect is &self) — fails to compile
  on the current unsafe-FFI-shaped core: RED.
Fork PR #35 review: the worker held &mut AudioOutput for its whole life
while connect/disconnect shims minted another &mut — aliasing UB ahead of
the lock. And do_audio_output held mix.inputs.iter_mut().rev() across
the callback, so a re-entrant connect could realloc the Vec under a live
iterator (self-disconnect dropped the tail: oracle 1 vs port 0 inputs;
push mid-tick lost the last element: [4,3,2] vs oracle [4,3,2,1]).

Restructure, matching the C one-for-one:
- AudioOutput is the owner (info getters, JoinHandle, initialized); the
  state the thread and FFI callers share lives in a Box<Shared> created
  before the recursive pthread mutex is initialized at its final
  address (POSIX forbids moving an initialized mutex).
- The worker gets a &Shared only — no &mut AudioOutput or &mut Shared
  exists after open. connect/disconnect/active/tick_for_test are &self;
  mixes sit behind input_mutex + UnsafeCell with borrows scoped to a
  single statement.
- do_audio_output keeps C's reverse-index traversal: bound fixed at
  entry, inputs[i-1] re-read per iteration, callback/param/resampler/
  allow_clipping copied into locals, every borrow ended, callback
  invoked while still holding the recursive lock. Mid-dispatch removal
  past the loop index is skipped instead of calling freed tail memory
  (documented deviation; the C's stale-tail call has no defined
  equivalent).
- Drop: stop + join complete before the shared box is freed, and the
  join never runs under the input lock.
- NULL input_cb: tick treated as failed (C faults). NULL output cb:
  connect accepted, dead call skipped (C faults next tick). Both
  documented at the top of audio_io.rs.
- Test determinism: a shared DRIVER mutex serializes MAGIC-stamped
  manual ticks in both test files (the real worker never produces MAGIC
  timestamps); the parity TICK record is replaced per driven tick so a
  test that never takes its record cannot poison the next case.

unsafe stays confined to the UnsafeCell/FFI sites with SAFETY comments;
the exception is recorded for the tracking issue.
Unix-first portability per fork PR #35 review: libc exposes no pthread
API on Windows, so the port, its shims, oracle and tests are
#[cfg(unix)] / #![cfg(unix)] and libobs keeps building
media-io/audio-io.c on Windows (same ENABLE_RUST_LIBOBS +
PLATFORM_ID:Windows guard shape as util/utf8.c). The 10 audio_output_*
exports get the ' unix' marker so rust.cmake does not /EXPORT them on
Windows — enforced by obs-util's export_list scan. A Windows backend
behind the same safe API is separate work (noted in audio_io.rs).

Also pins the audio_io_parity proptest-regressions file (repo
convention: bitstream/config_file ship theirs).
- ffi shims wrapped in the scan-visible #[cfg(unix)] mod unix { } block
  with pub use unix::* (export_list.rs finds markers this way)
- unused mut on &self call sites, drop(ctx) -> final borrow, unsafe
  fn record -> fn, range loop -> enumerate().take(n), nested unsafe
  blocks flattened
obs_startup needs an X display; on headless Linux every obs-dependent
case silently skipped (!obs_up -> skip). The fork PR #35 review requires
a Tier 2 that cannot skip: the cases now assert obs_up loudly, and the
test is registered via xvfb-run -a where xvfb exists (validate image
gains the xvfb package) so they actually run — failures like an
always-false audio_output_connect can no longer hide behind a skip.

Local-Gate: v1 tree=c8db6ae56f567359dffd12caa5966158ab439936 secs=33 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791693456,"gate":"rust/all/fmt","host":"linux-x86_64","key":"cd423e03662fdf0d13cd05a924d8451ac1dcaa75ee035f6f256a7b48857f7b95","lane":"lint","parents":["f03b6ed91acbb9db863d37858469f1995b248ad9"],"secs":5,"stamp":"5d0ec5461ad708d9efedb55ff851aefd","tree":"c8db6ae56f567359dffd12caa5966158ab439936","v":1,"via":"run"}
Ci-Attestation: {"at":1791693456,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"cd423e03662fdf0d13cd05a924d8451ac1dcaa75ee035f6f256a7b48857f7b95","lane":"lint","parents":["f03b6ed91acbb9db863d37858469f1995b248ad9"],"secs":5,"stamp":"2127baeef10d9722e392e4e1d8f43ff9","tree":"c8db6ae56f567359dffd12caa5966158ab439936","v":1,"via":"run"}
Ci-Attestation: {"at":1791693456,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"e53b1970f5af9aa3341c8c5341de995d6153585e927c48db3af11d6a8ffd5f3d","lane":"rust-test","parents":["f03b6ed91acbb9db863d37858469f1995b248ad9"],"secs":20,"stamp":"3fcd1fe0ce7b781cbcaf03ea972473c9","tree":"c8db6ae56f567359dffd12caa5966158ab439936","v":1,"via":"run"}
Ci-Attestation: {"at":1791693456,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"2add412b2ec51597e865ca2744b1b89e7e1d3a898d52de9f57597c5ba43a02c1","lane":"tier2-linux","parents":["f03b6ed91acbb9db863d37858469f1995b248ad9"],"secs":8,"stamp":"af2df4e9aa76ea57216a87a6d914f2b6","tree":"c8db6ae56f567359dffd12caa5966158ab439936","v":1,"via":"run"}
Fork PR #35 review items:
- fresh_clamp_snapshot_parity: input cb connects an allow_clipping input
  to a mix that was empty at the active_mixes snapshot. C re-checks
  !mix->inputs.num at clamp time, so the new mix is clamped and the
  unclamped row carries the marker (recorded 2.5f); the port skips it
  behind the stale mask (recorded 0.0).
- resample_parity: a rate-differing conversion must create a resampler
  and run the resample path; the NULL stub refuses the connect on both
  sides, so the assertion fails until a real resampler exists.
The C's clamp pass checks !mix->inputs.num at clamp time — after the
input callback ran — so a mix that gained an input mid-callback is
clamped anyway. The port reused the mask snapshotted for the callback,
skipping the fresh mix and leaving its buffer_unclamped zeroed.
input_and_output now takes a second locked snapshot for the clamp pass;
active_mixes stays the callback's mask. fresh_clamp_snapshot_parity goes
RED->GREEN (2.5f marker now reaches the unclamped row on both sides).
A single UnsafeCell<[AudioMix;6]> meant a &mut on the input registry and
an unlocked &mut on a mix buffer came from one cell — a broad mutable
borrow pattern that overlapped the tick's buffer fill/clamp. Each mix
field is now its own cell: inputs (registry, only under input_mutex)
and buffer/buffer_unclamped (touched only by the thread running the
tick, outside the lock). Cell pointers are taken as raw pointers where
no borrow is needed (do_audio_output's buf_ptr). No behavior change:
all non-RED tests stay green.
Fork PR #35 items 3+4: explicit test ticks raced the real audio thread —
a worker tick could interleave between an oracle tick and the matching
port tick, mutating buffers and the registry under the same state the
test was reading. Every driven-tick test now runs on a no-worker pair:
oracle_audio_output_open_no_thread (same object minus stop_event and
pthread; close destroys the mutex then frees inputs like the C) and
AudioOutput::open_no_worker (open minus spawn). The concurrent test
still exercises cross-thread connect/disconnect through the hammer
threads; only the tick is exclusive. Shared TICK/ORDER statics are
drained after closes via close_pair so nothing leaks between tests.
audio_io.rs's input_thread_runs keeps the real worker — the thread is
its subject.
… update

Replace the NULL resampler stubs with a deterministic nearest-sample
resampler (rate-scaled frame count, growable per-plane buffers) so the
parity suite exercises the real resample path: resample_parity connects
a 24k input on a 48k output and observes 512 frames of the 1024 tick,
proving conversion ran identically on both sides. Tier-1
connect_disconnect now expects the differing-conversion connect to
succeed (resampler exists) and disconnects the extra input.

Local-Gate: v1 tree=b49fdf74aa9dbf095b003123e5427c66b13acb7f secs=32 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791698572,"gate":"rust/all/fmt","host":"linux-x86_64","key":"82c20578a8d5f5274fcf050c859f0f952ff67f2e1c3853bee3359a61ed3b002a","lane":"lint","parents":["9bf4117ebc284940925be6aab89d55dd53ad03ed"],"secs":5,"stamp":"5f891de347cb6072efc902ed6436d868","tree":"b49fdf74aa9dbf095b003123e5427c66b13acb7f","v":1,"via":"run"}
Ci-Attestation: {"at":1791698572,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"82c20578a8d5f5274fcf050c859f0f952ff67f2e1c3853bee3359a61ed3b002a","lane":"lint","parents":["9bf4117ebc284940925be6aab89d55dd53ad03ed"],"secs":5,"stamp":"5391fc479d9be49eae07d5c668e8afda","tree":"b49fdf74aa9dbf095b003123e5427c66b13acb7f","v":1,"via":"run"}
Ci-Attestation: {"at":1791698572,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"4d1f436d4c7ccc8af42591f1fd35945e2eef7cefa0117c9645dc46ba630ef6cb","lane":"rust-test","parents":["9bf4117ebc284940925be6aab89d55dd53ad03ed"],"secs":16,"stamp":"236331555a6a7ad8284d4ba974f4a8ce","tree":"b49fdf74aa9dbf095b003123e5427c66b13acb7f","v":1,"via":"run"}
Ci-Attestation: {"at":1791698572,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"54ef1a4927d255af7c83c658dca360627fe7d1ba65a20db8c0db3763fa9cd738","lane":"tier2-linux","parents":["9bf4117ebc284940925be6aab89d55dd53ad03ed"],"secs":12,"stamp":"052a4f5fc7fca78448936f58610510cb","tree":"b49fdf74aa9dbf095b003123e5427c66b13acb7f","v":1,"via":"run"}
input_thread_runs destroyed g_input_event and read the callback's
counter before audio_output_close — a late callback could signal a
freed event. Close (stop+join) first, then destroy.

Lane: rd4
open/open_no_worker/connect/tick_for_test take pointers whose validity
outlives the call (name, input_param, callback context) or impose a
single-driver rule the type system can't express — mark them unsafe
with per-function contracts and compile_fail doctests proving the
unchecked call does not compile. FFI docs state the same contract;
disconnect/active/drop retain nothing and stay safe.

Lane: rd4
…se parity

Oracle double now carries a sub-frame remainder (residue -> nonzero
ts_offset on non-integer ratios) and rejects format/speaker changes at
create like a real converter — resample_ts_offset_parity pins the
data.timestamp -= offset shift, resample_failure_parity the rejection.

- activation_during_input_parity: a connect inside input_cb dispatches
  on the same tick while the mask already handed out predates it.
- concurrent_connect_disconnect_parity: churn is gated to the locked
  dispatch window (callback ran -> recursive mutex held) and joined
  before the next tick, so ops never race the unlocked clamp reads.
- real_worker_close_join: a live worker + self-disconnecting callback;
  close stops and joins before any context is freed.

Lane: rd4
Local-Gate: v1 tree=3deaf202caebba49a31df72328003393bff9d424 secs=40 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791709931,"gate":"rust/all/fmt","host":"linux-x86_64","key":"12e2db5dcec2ad5866f75b7049c539447c5923940dfab27c21ef8e4f51413601","lane":"lint","parents":["5a934b5307bb7e1fc82406eafd01e72d3a4c95e1"],"secs":5,"stamp":"b267001d4913f2398c18d9e9032a88be","tree":"3deaf202caebba49a31df72328003393bff9d424","v":1,"via":"run"}
Ci-Attestation: {"at":1791709931,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"12e2db5dcec2ad5866f75b7049c539447c5923940dfab27c21ef8e4f51413601","lane":"lint","parents":["5a934b5307bb7e1fc82406eafd01e72d3a4c95e1"],"secs":5,"stamp":"e8f64cfe304bd441143e080343e010a4","tree":"3deaf202caebba49a31df72328003393bff9d424","v":1,"via":"run"}
Ci-Attestation: {"at":1791709931,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a497b4d6be21863cb6ffb8b5cbbdff534add660faaf07d92b2406dc78ae6aca6","lane":"rust-test","parents":["5a934b5307bb7e1fc82406eafd01e72d3a4c95e1"],"secs":21,"stamp":"69db5bda5c33f9101fc53a1959086976","tree":"3deaf202caebba49a31df72328003393bff9d424","v":1,"via":"run"}
Ci-Attestation: {"at":1791709931,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"d0acbd63cb2072143fbe1785e852c09316d659cc48fe36fda31b449c4d173ae4","lane":"tier2-linux","parents":["5a934b5307bb7e1fc82406eafd01e72d3a4c95e1"],"secs":14,"stamp":"2f9e75980b1f251aa19e3008c37c5cd6","tree":"3deaf202caebba49a31df72328003393bff9d424","v":1,"via":"run"}
GCC 14 makes -Wincompatible-pointer-types an error: the double's own
struct type mismatched audio_resampler_t at create/destroy/resample.
The struct now completes the opaque declaration from audio-resampler.h,
so the types are identical and no casts are needed. Verified under
gcc -Werror=incompatible-pointer-types and clang -Werror=incompatible-pointer-types.

Lane: rd4
Local-Gate: v1 tree=883acc0ae187962834897dfa736ac97fdc0f2ba1 secs=38 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791712047,"gate":"rust/all/fmt","host":"linux-x86_64","key":"d87b23f69ab124aef39668b39ec6e01d97c751d68b1a4171250b92066aebcdc6","lane":"lint","parents":["df347c1bbee63de4abab59a3ee8bfda079be14a3"],"secs":7,"stamp":"515326def0c3ec53832985b776bf7f1b","tree":"883acc0ae187962834897dfa736ac97fdc0f2ba1","v":1,"via":"run"}
Ci-Attestation: {"at":1791712047,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"d87b23f69ab124aef39668b39ec6e01d97c751d68b1a4171250b92066aebcdc6","lane":"lint","parents":["df347c1bbee63de4abab59a3ee8bfda079be14a3"],"secs":7,"stamp":"1514157836b8068cc4bb5ba40165cbae","tree":"883acc0ae187962834897dfa736ac97fdc0f2ba1","v":1,"via":"run"}
Ci-Attestation: {"at":1791712047,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"d652d839e07c699e3ee620d45561731af845a7bc28e51e5c9d4642813dbda4f8","lane":"rust-test","parents":["df347c1bbee63de4abab59a3ee8bfda079be14a3"],"secs":19,"stamp":"bcf30e46b6b31179519c89a1b26ee877","tree":"883acc0ae187962834897dfa736ac97fdc0f2ba1","v":1,"via":"run"}
Ci-Attestation: {"at":1791712047,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b41e9dc66337249891789424c3096e1811ff13a739b9fc3bfe7d7a89c9974f6b","lane":"tier2-linux","parents":["df347c1bbee63de4abab59a3ee8bfda079be14a3"],"secs":12,"stamp":"55193fb14542f25b4fd170a0bd1a3870","tree":"883acc0ae187962834897dfa736ac97fdc0f2ba1","v":1,"via":"run"}
Adopt the rust-exports.d and tests.d fragment layouts (obs-rust#137):
the 10 audio_output_* exports move to
libobs/cmake/rust-exports.d/obs-media-io-audio_io.txt, and the cmocka
registration (with its xvfb wrapper) to tests.d/test_audio_io.cmake.
The oracle's audio_io.c is audio_io_posix.c so the oracle glob's
*_posix.c Unix gate keeps it off Windows, matching the cfg(unix) module.
The oracle glob compiles it automatically; build.rs drops the explicit
file list.

rust/obs-media-io merges both audio_io.rs sides: the upstream header
types and static-inline helpers stay platform-neutral, and the
audio-io.c port lives in the same file under #[cfg(unix)] mod port,
re-exported flat. The ffi module likewise keeps the upstream struct
mirrors and enum helpers and adds the ten EXPORTed shims in
#[cfg(unix)] mod unix. Duplicated consts, struct mirrors and inline
helpers collapse to the upstream copies; the port calls the shared
c_int->enum helpers and obs_util::util_uint64::mul_div64.

Lane: rd4
The oracle's layout accessors duplicated the audio_io_inlines oracle's:
upstream's owns them, so audio_io_layout.rs reads those. And rustfmt
indents the port module's body.

Lane: rd4
Local-Gate: v1 tree=fd7b032aaeaa4a20a3f4fac726aa88ebd0c96d68 secs=117 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791714967,"gate":"rust/all/fmt","host":"linux-x86_64","key":"ce9fa2fc8a0a057375c497b89b5b42a6379142f8897dbb2df02f2e1ac69b9776","lane":"lint","parents":["dc768fd2d99009cba95ccec8d8ccd97531804fc2"],"secs":10,"stamp":"7c5555b53bdba314cf70c09bd9f02bf9","tree":"fd7b032aaeaa4a20a3f4fac726aa88ebd0c96d68","v":1,"via":"run"}
Ci-Attestation: {"at":1791714967,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"ce9fa2fc8a0a057375c497b89b5b42a6379142f8897dbb2df02f2e1ac69b9776","lane":"lint","parents":["dc768fd2d99009cba95ccec8d8ccd97531804fc2"],"secs":10,"stamp":"6ae0156b3e0c8350fa0777dee40ffe5c","tree":"fd7b032aaeaa4a20a3f4fac726aa88ebd0c96d68","v":1,"via":"run"}
Ci-Attestation: {"at":1791714967,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8df9729e655d9f89bf7ab970b1aa69dd376a73708ca83aae6018ef14581d83ba","lane":"rust-test","parents":["dc768fd2d99009cba95ccec8d8ccd97531804fc2"],"secs":18,"stamp":"71700460c8159f5190b87fda3e587c22","tree":"fd7b032aaeaa4a20a3f4fac726aa88ebd0c96d68","v":1,"via":"run"}
Ci-Attestation: {"at":1791714967,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"4c1ee537dfc4bb7e4f53a8a4cb931dcf2abcb039f0e162a3043e8a826d5f9aae","lane":"tier2-linux","parents":["dc768fd2d99009cba95ccec8d8ccd97531804fc2"],"secs":88,"stamp":"00c890af3e4e607853663c9617233823","tree":"fd7b032aaeaa4a20a3f4fac726aa88ebd0c96d68","v":1,"via":"run"}
…lose contract

- wait_churn and both churn-thread dispatch gates now assert on a 30s
  deadline instead of silently proceeding when the gate never arrives.
- RealCtx.audio is an AtomicPtr published before connect; the callback
  reads it under the held input lock — no torn post-open write.
- real_worker_close_join spins on the callback counters (bounded, fails
  on timeout) instead of fixed sleeps; a post-close alarm window stays.
- FFI close/connect Safety docs narrowed: re-entrant audio_output_close
  from inside a callback is UB (joining the calling worker thread), as
  pthread_join on the calling thread is UB in the C. Docs now state that
  the join is a full barrier so no callback can run during/after close.

Lane: rd4
Local-Gate: v1 tree=4c73a4f40e383b3d5acae87d73d1fc6de5e4b12a secs=63 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791718243,"gate":"rust/all/fmt","host":"linux-x86_64","key":"d62db07db9fcb5b392320283755c59eee1365cb9245facd2f82cb4dd0bcd38ea","lane":"lint","parents":["c5af339d2226f22ec85fae4cf7f4955880573aa6"],"secs":11,"stamp":"cc1cfb5df1655b82d83d20ea8af85e29","tree":"4c73a4f40e383b3d5acae87d73d1fc6de5e4b12a","v":1,"via":"run"}
Ci-Attestation: {"at":1791718243,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"d62db07db9fcb5b392320283755c59eee1365cb9245facd2f82cb4dd0bcd38ea","lane":"lint","parents":["c5af339d2226f22ec85fae4cf7f4955880573aa6"],"secs":11,"stamp":"362cafe3bc7c21aa69cba838f7cd6de4","tree":"4c73a4f40e383b3d5acae87d73d1fc6de5e4b12a","v":1,"via":"run"}
Ci-Attestation: {"at":1791718243,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"1b3f94e3965519b8db69df13ddfd4df77dc85b2e168d0e4a4e764db52f275823","lane":"rust-test","parents":["c5af339d2226f22ec85fae4cf7f4955880573aa6"],"secs":18,"stamp":"f82fd7ff7d60d17584b6057b697ec756","tree":"4c73a4f40e383b3d5acae87d73d1fc6de5e4b12a","v":1,"via":"run"}
Ci-Attestation: {"at":1791718243,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"400f42cab778f7c7dc7372636b2f28dc5e15887e60bf81a59653f52bf66d32a0","lane":"tier2-linux","parents":["c5af339d2226f22ec85fae4cf7f4955880573aa6"],"secs":34,"stamp":"a75490453eb982e8935a62988124052b","tree":"4c73a4f40e383b3d5acae87d73d1fc6de5e4b12a","v":1,"via":"run"}
audio_output_close rebuilt the owning Box first, so Drop's &mut
AudioOutput was live for the whole join while an in-flight callback
could still hold &Shared through re-entrant connect/disconnect —
aliasing UB the C does not have. Stop and join through the raw pointer
instead; only then reconstruct the Box, so Drop's join is a no-op on the
FFI path and only frees resamplers.

Adds a debug-only stop_and_join_begins seam and a forced-interleaving
test: the callback parks until close reaches its join point, then runs
a re-entrant disconnect. Under the old close the test fails on a 30 s
deadline (the seam is never observed); with the fix it passes.
… ICF

fresh_clamp_snapshot_parity failed only under --release: fs_new_* and
fs_clamped_* had byte-identical bodies, the linker folded them into one
function pointer, and the C's per-mix (callback, param) duplicate check
then refused the second connect — the clamped sibling never existed, so
only the raw-2.5 call was recorded. Not a float divergence. Distinct
black_box immediates keep each callback's code distinct; the recorded
behaviour is unchanged. Debug and release both pass.
…w it

Record stop_and_join_begins() at the moment the callback calls
disconnect and assert >= 1: the test now fails if disconnect ever runs
before close reaches its join, instead of merely passing when the
overlap happens. Removing the barrier wait makes it fail — checked and
reverted.
zackees and others added 2 commits October 11, 2026 16:51
Since obs-rust#248, obs-util exports the Rust profile_start, profile_end and
profile_reenable_thread, and the audio-io oracle's no-op hooks of the
same names collided at link time (rust-lld: duplicate symbol:
profile_start, in every obs-media-io test binary). Rename the oracle's
hooks before audio-io.c is included.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
oracle/profiler.c (obs-rust#248) defines a scripted os_gettime_ns for the
profiler parity tests, and the audio-io oracle defined the real one,
so profiler_parity failed to link (duplicate symbol: os_gettime_ns).
Audio-io keeps the real clock under private names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=4186644fea8923a5acfe9827b0d1724c6c4382ee secs=112 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791764047,"gate":"rust/all/fmt","host":"linux-x86_64","key":"15f0038c088e377d14cd58325a0e46f280243c729ff086205ac29805a56209e7","lane":"lint","parents":["6806dc73038a88c9265e5cc4deb58ef37cda1ddd"],"secs":16,"stamp":"d50d30a484537a6bc9ad91aef46d7b0b","tree":"4186644fea8923a5acfe9827b0d1724c6c4382ee","v":1,"via":"run"}
Ci-Attestation: {"at":1791764047,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"15f0038c088e377d14cd58325a0e46f280243c729ff086205ac29805a56209e7","lane":"lint","parents":["6806dc73038a88c9265e5cc4deb58ef37cda1ddd"],"secs":16,"stamp":"d1de8177ce400889c11035a11705397a","tree":"4186644fea8923a5acfe9827b0d1724c6c4382ee","v":1,"via":"run"}
Ci-Attestation: {"at":1791764047,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"36a0373dcf8c96780d5585411d8541906456a1362bfc70845691c22a19f1b3e5","lane":"rust-test","parents":["6806dc73038a88c9265e5cc4deb58ef37cda1ddd"],"secs":46,"stamp":"b5f961a801e226b4e43233150736f25c","tree":"4186644fea8923a5acfe9827b0d1724c6c4382ee","v":1,"via":"run"}
Ci-Attestation: {"at":1791764047,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"11b51f291675aaf52fe851484317638db6be7a1fb637e16059a64ec9f2676e79","lane":"tier2-linux","parents":["6806dc73038a88c9265e5cc4deb58ef37cda1ddd"],"secs":50,"stamp":"95692a6eeb235b95cf404f1d19dd69f6","tree":"4186644fea8923a5acfe9827b0d1724c6c4382ee","v":1,"via":"run"}
chriscoveries added a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 12, 2026
Validation on obs-rust#289's head showed the merged tree's duplicate-symbol link
error only inside the report-only release step, which still passed, and
the format failure skipped the gate's Rust tests. Keep release test
failures report-only, but fail on 'could not compile'.
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally and stamped. The new head is 321553647. I merged current master into the branch instead of rebasing, because the branch already has a merge and #153's layout.

Two link breaks against master (#248, the profiler port), fixed in two commits on top:

  1. oracle/audio_io_posix.c defined no-op profile_start, profile_end and profile_reenable_thread. obs-util now exports the Rust profiler under those names, so every obs-media-io test binary hit rust-lld: duplicate symbol: profile_start. They're renamed to private oracle_aio_* names before audio-io.c is included.
  2. It also defined the real os_gettime_ns and os_sleepto_ns, while oracle/profiler.c defines a scripted os_gettime_ns. obs-util's profiler_parity failed to link. Both are renamed the same way.

Evidence:

  • RED (c0f50297a): tests/audio_io.rs passed 0 of 5 against the stubs.
  • GREEN: audio_io 6 of 6, audio_io_core 6 of 6, audio_io_layout 4 of 4 and audio_io_parity 14 of 14 (real resampler) passed. All 83 obs-util and obs-media-io suites passed.
  • Local gate: lint, rust-test and tier2-linux all passed, 92 of 92 with ENABLE_RUST_LIBOBS OFF and 92 of 92 with it ON. audio-io.c is now among the 36 objects swapped out under ON.
  • --repeat until-fail:30 -R 'audio|media|replay|pulse|task' passed 30 of 30 with ENABLE_RUST_LIBOBS OFF and 30 of 30 with it ON (15 tests each).
  • The test_audio_io.c changes only tighten the test (skip() becomes assert_true(obs_up), and the counter is read after the join), and xvfb is added to the Tier 2 image. That's fine. Watch for CI runners without a display or xvfb.

Because this replaces the audio thread under ENABLE_RUST_LIBOBS=ON, I'm holding the merge for a maintainer OK once CI is green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=da8bce5d222fc0594ee349d165bc45f056b94a3b secs=111 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791765194,"gate":"rust/all/fmt","host":"linux-x86_64","key":"61723c392b744dcf5dd0d872e98c720a3a3ebf9dab3ee5a744338e7421b669b4","lane":"lint","parents":["321553647a716a2ed64d8bbabda00f1ad6059f0e"],"secs":16,"stamp":"f7a031b4e5a87868473aff01a4d434e6","tree":"da8bce5d222fc0594ee349d165bc45f056b94a3b","v":1,"via":"run"}
Ci-Attestation: {"at":1791765194,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"61723c392b744dcf5dd0d872e98c720a3a3ebf9dab3ee5a744338e7421b669b4","lane":"lint","parents":["321553647a716a2ed64d8bbabda00f1ad6059f0e"],"secs":16,"stamp":"8e540d2bab851c46c1d9036cb34dd602","tree":"da8bce5d222fc0594ee349d165bc45f056b94a3b","v":1,"via":"run"}
Ci-Attestation: {"at":1791765194,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a140a99da7931f55eb2b52900a065cb71ff0898e7103b752e4fb72786808cdd2","lane":"rust-test","parents":["321553647a716a2ed64d8bbabda00f1ad6059f0e"],"secs":43,"stamp":"c928c47a925685e3f0230feea905b022","tree":"da8bce5d222fc0594ee349d165bc45f056b94a3b","v":1,"via":"run"}
Ci-Attestation: {"at":1791765194,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"7c54ee86eb093250664fe994db9c197ce73dd4cf1fab73ee09faa05715bc9bfa","lane":"tier2-linux","parents":["321553647a716a2ed64d8bbabda00f1ad6059f0e"],"secs":51,"stamp":"bcedad477dd02c3be83483fda3ef78df","tree":"da8bce5d222fc0594ee349d165bc45f056b94a3b","v":1,"via":"run"}
@zackees
zackees merged commit 1873bd1 into obs-rust:master Oct 12, 2026
23 checks passed
@chriscoveries

Copy link
Copy Markdown
Contributor Author

@zackees, thank you for picking this up and fixing it yourself. Both link breaks were ours. We tested the branch alone, not merged with current master, so the profiler port (#248) never showed up on our side. The os_gettime_ns collision you found is one we'd have hit next.

How #289 came together. We build with AI coding agents: Claude Opus 5.5 coordinates, and Codex Sol (now 6.1) does the independent reviews and the hardest problems. I sign off on everything before it's posted here.

  1. test: characterize audio-io.c before media-io port #120 pinned audio-io.c with cmocka characterization tests before any Rust existed.
  2. We ported it on our fork as a safe core plus an ffi shim, with parity tests against the real audio-io.c compiled into the same binary.
  3. A fork review found the close-ordering aliasing hole. It's fixed, with a test that forces that interleaving.
  4. Mutation checks, such as flipping the ts_offset sign, confirmed the parity tests catch real breakage.
  5. An independent review checked every claim in the PR description against the code, and fixed seven inaccuracies before posting.
  6. Self-hosted CI ran on the exact head. This is where we slipped: it never merged master. It now merges current obs-rust master and runs your clang-format 22.1.3, and it reproduces both failures you fixed.

Our CI, for your advice. It's dispatch-only on our fork, on self-hosted runners we own, with no PR-triggered events.

  • Gate: a Xeon Platinum 8559C (8 vCPU, AVX-512 with VNNI, Ubuntu) runs the merge, ./lint, clang-format and cargo test --workspace.
  • Tier 2: claw, a Debian 13 VM (Xeon Skylake-SP with AVX-512, 8 vCPU, 15 GB RAM, GCC 14.2), running as an unprivileged ghrunner user. It runs the release Rust tests (report-only for master's two known release failures; fixes are coming) and a Docker-free validate.sh: the cmocka suite with ENABLE_RUST_LIBOBS OFF and ON, export parity, and a check that ON really swaps the C objects out.
  • macOS: an M1 Max (macOS 27) lane that builds and runs ctest with the Rust port ON.

What do you think? In particular:

  • Is a whole-file port this size reviewable, or would you rather have units this big split?
  • Mirroring C quirks exactly and listing them, or fixing obvious C bugs in the same PR?
  • What would you like to see before replacing the audio thread under ENABLE_RUST_LIBOBS=ON? A real-app recording run is our obvious gap.
  • On CI: anything in your matrix we should mirror first, and is a better way to reproduce your PR CI than merge-then-test? Would an AVX-512 or Apple Silicon runner be useful to the project?

zackees added a commit to MCPVOT/obs-studio that referenced this pull request Oct 12, 2026
The audio-io port (obs-rust#289) merged with 54 unsafe sites in its safe core,
which the new deny(unsafe_code) rejects. Allow it on the module with a
pointer to obs-rust#294, which moves that code into src/ffi; every other module
stays under the lint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=63a892fb6ff84969dfc38d23be2f2b9923ce553a secs=114 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791769092,"gate":"rust/all/fmt","host":"linux-x86_64","key":"1ab3f600ca0050bca59f435d6ac45dde91181ac092d7b4c93a504c64ca7415ca","lane":"lint","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":14,"stamp":"5ad062e4a22509f1f532eeea1e502669","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"}
Ci-Attestation: {"at":1791769092,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"1ab3f600ca0050bca59f435d6ac45dde91181ac092d7b4c93a504c64ca7415ca","lane":"lint","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":14,"stamp":"6f07834adae2cd0f49955dab4643f20d","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"}
Ci-Attestation: {"at":1791769092,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"313badc9388c6f37a20dfac00209e8950e9008b086a82482e43137ddafc03b89","lane":"rust-test","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":47,"stamp":"27ba81a320fbccbcb6b31e042abfe257","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"}
Ci-Attestation: {"at":1791769092,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"217841ec98a6c6f2d928fc014925c0eec19795d829d8080fc907b2c7dd9bcf77","lane":"tier2-linux","parents":["2260b8992d1aeb76f94aacdc152fe1667d64b494"],"secs":53,"stamp":"d8ca05bee2805bf43c4f3bc60f9f5239","tree":"63a892fb6ff84969dfc38d23be2f2b9923ce553a","v":1,"via":"run"}
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.

2 participants