Skip to content

rust: Port the WASAPI monitor delay decisions to obs-audio-monitoring #3105

Closed

Description

@rdoupe

Unit

Port the delay decisions of process_audio_delay() in libobs/audio-monitoring/win32/wasapi-output.c.h (45-116) to rust/obs-audio-monitoring, as a new module monitor_delay, next to pulse_monitor. On Windows they decide, for every packet of a monitored source that has video, whether its audio is held back, cut or played to stay in step with the source's video:

  • the stale cut (57-59): more than 1 s since the last packet arrived empties the delay buffer, and the receive time is stored;
  • the front judgement (75-78, 81, 100): the front packet's timestamp minus the device padding, its difference from the source's last video timestamp, and the verdict: play when there is no video timestamp yet, when they are more than 5 s apart or when the video has stood still past AUDIO_MONITOR_VIDEO_STALL_NS; otherwise hold the queue when the audio is more than 75 ms ahead (rushing), drop the packet when it is more than 75 ms behind and more are queued (dragging), and play it otherwise.

These stay in C: every deque_* call and da_resize, os_gettime_ns, the reads of last_frame_ts, sync_offset, the sample rate and the stall count where they are today, both util_mul_div64 calls, the "more are queued" test after the pops, the two DEBUG_AUDIO logs, the loop and its returns, and all of on_audio_playback() (the lock, the WASAPI calls, the resample, the volume).

audio_monitor_track_video_ts() (the video stall tracking) stays a static inline in monitor-video-sync.h: the existing tests test_monitor_video_sync and test_media_cover_art_monitor include the header and call it, and they stay unchanged.

Phase and position

Phase 6, Windows host code in the windows+ unity group; the WASAPI counterpart of the PulseAudio monitor steps port (#2470). Tracking: #4.

Dependencies and existing tests

  • No dependency; no open PR touches wasapi-output.c.h or the windows+ group.
  • Real libobs: the WASAPI monitor runs only on Windows, and no test reaches process_audio_delay(). test_monitor_video_sync and test_media_cover_art_monitor cover the stall tracking, which this port leaves alone.
  • No characterization: test_audio_monitor_delay_steps lands first in the same PR. The moved file includes no Windows header, so it builds and runs on every OS.

Notes

One PR, separate commits: the behaviour-neutral move into libobs/audio-monitoring/monitor-delay.c.h (hidden functions on plain integers, the thresholds as named constants), characterization, RED, GREEN (group libobs.ported-monitor-delay), Tier 3 (grids around every threshold and a proptest over packet runs), docs.

No intentional difference is expected. The C subtracts in uint64_t and casts to int64_t; Rust wraps the same way. llabs(INT64_MIN) is undefined in C, so the parity test leaves out that one difference.

Activity

  1. added
    enhancement
    port
    on Oct 30, 2026
  2. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #3105

    Plan, one PR with separate commits:

    1. libobs: Move the stale cut and the front judgement of process_audio_delay() into libobs/audio-monitoring/monitor-delay.c.h: hidden functions on plain integers, declared in a new monitor-delay.h with the 1 s, 5 s and 75 ms thresholds named; behaviour-neutral, checked by building master's and the moved code side by side over logging stand-ins on the same inputs, with planted mutants.
    2. Characterization: test_audio_monitor_delay_steps, building the moved file on its own (no Windows header), on every OS.
    3. RED: Tier 1 obs_audio_monitoring::monitor_delay against todo!() stubs.
    4. GREEN: the safe core and src/ffi/monitor_delay.rs, group libobs.ported-monitor-delay in the Windows ported sources.
    5. Tier 3 parity against the C, with a mutation check.
    6. Docs.

    Decisions:

    • The video stall tracking (audio_monitor_track_video_ts()) stays a static inline in monitor-video-sync.h, unported: test_monitor_video_sync and test_media_cover_art_monitor include the header and call it, and existing C tests stay unchanged.
    • Both util_mul_div64() calls (the packet's and the padding's duration) stay in C at their call sites, so the core takes nanoseconds and never divides. The "more are queued" test also stays in C, after the pops, where it is read today.

    I expect the draft PR today, within a few hours.

  3. added
    ready
    on Oct 30, 2026
  4. moved this from In progress to In review in obs-rust Multiviewon Oct 31, 2026
  5. rdoupe commented on Oct 31, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by PR #3107, merged through the queue as c717200.

    The WASAPI monitor's delay decisions (the 1 s stale cut and the front packet's verdict: hold at 75 ms ahead, drop at 75 ms behind with more queued, play on no video timestamp, 5 s apart or a stalled video) now run from rust/obs-audio-monitoring (monitor_delay), with no change in behaviour. Tier 3 parity against the C and a 24-mutant check are in.

    Left, by decision and not as work: the delay queue calls, the two util_mul_div64() calls, the "more are queued" test, the DEBUG_AUDIO logs and on_audio_playback() stay in C, and so does the video stall tracking (audio_monitor_track_video_ts()), which existing C tests call. Nothing has run on a Windows machine yet beyond PR CI.

    Follow-up issue: none; nothing in this unit's scope is left. Its tracking issue (#4) has no checkbox for this unit, so none was ticked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementportready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions