Skip to content

rust: Port the source audio timestamp placement in obs-source.c to a new obs-source crate #1932

Closed

Description

@rdoupe

Unit

Port the audio timestamp placement decisions in libobs/obs-source.c.h to Rust. This unit creates a new crate, rust/obs-source, the crate for libobs/obs-source*.c.h units, following the precedent of rust/obs-scene and #444. Please tell me if you'd rather have it as a module somewhere else before anyone else creates that crate.

What moves (on master today):

  • source_output_audio_data: the direct-timestamp detection, the jump/smooth/log choice on next_audio_ts_min (with drift_error and continuous), the push-back/place choice on next_audio_sys_ts_min (with the "no timing reset when the audio was continuous" rule), and the sync-offset arithmetic with its "offset changed → place" rule;
  • reset_audio_timing and uint64_diff;
  • the audio_ts rule of reset_audio_data_at_sys_time.

What stays C: handle_ts_jump (it takes audio_buf_mutex and empties the buffers), audio_resampler_set_compensation_error, conv_frames_to_time (C computes the packet duration, so no sample-rate division reaches Rust), the deque place/push-back, the signals, muting and the lock.

Plan (one PR, separate commits)

  1. Move the decisions into libobs/obs-source-audio-timing.c.h as two hidden pure steps around the lock: one before it, one under it. C reads the fields into a small struct, calls a step, and writes the result back, so the volatile stores of timing_set / timing_adjust stay where they are. This commit is behaviour-neutral.
  2. Characterization (test_source_audio_timing_steps), covering:
    • every branch of both steps;
    • values just under, at and just over the 70 ms smoothing threshold and the 2 s MAX_TS_VAR;
    • direct timestamps, the async-decoupled re-anchor and next_audio_ts_min == 0;
    • a negative sync offset larger than the timestamp, and u64 wrap, pinned as characterized, not endorsed;
    • a sync offset changed between packets.
  3. RED, then GREEN: the safe Rust core plus shims in a libobs.ported-source-audio-timing group, with exported symbols unchanged. The arithmetic wraps exactly where C's unsigned arithmetic does.
  4. Tier 3 parity against the original C: a proptest over full-range u64 timestamps and i64 offsets, every flag combination, and sequences of 2–50 packets. The step outputs and the written-back state must be byte-equal. Plus a deliberate-break check and port_comparison numbers.

These real-libobs tests must stay green on every lane: test_async_delay_audio, test_audio_sync_offset_change, test_media_sync_offset_restart, test_audio_restart_resampler_tail and test_audio_clock_drift.

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions