Skip to content

obs-media-io: Port the resampler drift loop - #3143

Merged
zackees merged 7 commits into
masterfrom
fix/rust-port-resampler-clock-drift-358
Oct 31, 2026
Merged

zackees merged 7 commits into
masterfrom
fix/rust-port-resampler-clock-drift-358

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3139

What and why

Port of the clock drift compensation loop and the output size plan of the libswresample resampler (libobs/media-io/audio-resampler-ffmpeg.c.h) to rust/obs-media-io, as a new module audio_resampler_drift, next to audio_io and format_conversion. Every audio source and output converts through this resampler. The loop is what keeps a capture device on its own clock in sync: the source reports how far the device's samples run ahead of or behind their timestamps, errors within 10 ms are ignored, and a lag-lead loop filter turns the rest into a resampling correction of up to 1000 ppm, handed to swr_set_compensation().

Commits:

  1. libobs: Move the resampler drift decisions (behaviour-neutral): seven hidden functions on plain values and the compensation state in libobs/media-io/audio-resampler-drift.c.h, declared without EXPORT in audio-resampler-drift.h, in their own unity group with no FFmpeg header: the sample format, the mono upmix row, the dead band, the loop filter step (Idle, Engage or Set with the delta), the output frame padding, the sample counters and the drift report. audio-resampler-ffmpeg.c keeps every swr_* and av_* call, the output buffer, its size and the grow decision, the output pointer copies and every log, in their places and under their conditions. The sample formats are given as values that audio-resampler-ffmpeg.c checks against libavutil's with _Static_asserts.
  2. test: Characterize the resampler drift loop (test_audio_resampler_drift_steps, 16 cases, every platform, built with -ffp-contract=off because it compares doubles bit for bit).
  3. obs-media-io: Test the resampler drift port (RED).
  4. obs-media-io: Port the resampler drift loop (GREEN: core, shims, group libobs.ported-audio-resampler-drift registered in libobs/build/ported-source-sets/audio-resampler-drift.json on every host and built with -ffp-contract=off, the three hidden-symbol lists, ci/test_ported_sources.py).
  5. obs-media-io: Compare resampler drift to C (oracle, Tier 3, port_comparison, mutation check).
  6. docs: Record the resampler drift loop port.
  7. libobs: Read the drift delta after its log (review fix): the step and the drift report are each split in two, so every read is back where master has it (obs-source: Port the deinterlace draw decisions #2153). audio_resampler_comp_step() gives only the action and audio_resampler_comp_delta() the delta, asked after the engage log, right before swr_set_compensation(); audio_resampler_comp_reports_drift() is the report's gate and audio_resampler_comp_input_rate() its rate, so output_freq is read only when the report is due. Core, shims, oracle, tests and bench follow; nine hidden functions in all.

The doubles are the C's operations in the C's order; Rust never fuses a multiply and an add, and the C group now builds with -ffp-contract=off (GCC and Clang; MSVC doesn't contract), so both sides agree bit for bit on every host, arm64 included.

Kept and characterized, not endorsed: a format past the last is S16; the drift report divides first (48,048 over 48,000 samples at 48 kHz reports a hair under 48,048 Hz); a negative estimate is padded toward 0.

No intentional difference. Left out of Tier 3, as the C never meets them: a zero input rate (NaN states; swr_init() rejects it first, and Tier 1 pins the core's answer) and a padding that overflows int. Null pointers, which the C dereferences, are neither read nor written.

There is no test_audio_resampler_drift_steps_rust: the shims' archive member holds the rest of obs-media-io, which needs obs-util (bcrash, libuuid), 238 undefined references on its own. Tier 3 compares the shims with the C instead, and the real-libobs tests run the hybrid.

The moved code is upstream's (Lain's resampler, pkv's mono upmix matrix) and the fork's own drift compensation, after Norihiro Kamae's upstream obs-studio PR 6351; Lain and pkv are credited in the move commit. No upstream issue.

RED → GREEN

  • RED commit: b702dcf. soldr cargo test -p obs-media-io --lib -- audio::audio_resampler_drift:: passes 1 of 27 (the constants) and fails 26 with "not yet implemented". On the RED commit, local_gate.py --lane lint passed and --test-diff origin/master failed only those 26 (5555 of 5581 passed, 6 skipped).
  • GREEN: Tier 1 audio::audio_resampler_drift 27/27; Tier 3 audio::audio_resampler_drift_parity 12/12. Linux x86_64 (GCC): test_audio_resampler_drift_steps (17/17), test_audio_clock_drift (6/6) and test_audio_restart_resampler_tail (4/4) pass against the C build, the hybrid libobs and libobs-c-reference, none skipped, under a private Xvfb; the 40 audio|resampl tests pass against the hybrid, none skipped. Exported symbols identical on the C, hybrid and C reference builds (1767 each, as on master), the nine shims local (t); only libobs-c-reference compiles the ported group.
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol output or logging change.

Runs were on cd80558ef for the Tier 1 and Tier 3 tests, the three C tests on all three builds, the export comparison, the move harness, the bench, ./lint and the quick CI guard tests. Local gates (runs were on 88cc9e7, after the rebase onto current master): ./lint, local_gate.py --lane lint and --lane cross ok; ./unittest Rust tiers 5618/5618 and 862/862 passed, 6 skipped; soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings clean; soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes; the quick CI guard tests (build groups, ported sources, oracle stand-ins and MSVC, sorted shared lists, test graph sorted, cmocka Rust-static guard, Windows diagnostics and includes, naming) pass; the three resampler C tests pass on the C, hybrid and C reference builds, none skipped, and the exported symbols are identical on all three (1767, the nine shims local). Not run locally: Tier 2 in Docker (./unittest's tier2-linux lane), and so the local-gate stamp: this host's build account can't reach the Docker socket, and ci-lint local-gate run passes lint, rust-test and cross and stops at tier2-linux. The head is unstamped, so PR CI runs the full suite. Nothing has run on Windows or macOS yet.

Test cost: new tests (39): longest 0.04 s at the reduced parity level (the loop proptest; 0.30 s for all 39 at the full level), peak RSS 6.6 MB over 25 runs, no threads of their own.

Move check (runs were on the move commit's tree, and again on cd80558ef with the same result): master's audio-resampler-ffmpeg.c.h and the moved one, over logging stand-ins for libswresample, libavutil, bmalloc, bfree and blog (with injected failures), built with gcc and clang at -O0 and -O2, with and without ASan and UBSan: 10,000 resampler runs over 5 seeds give identical logs in all 8 builds (8,816,852 lines each side, with 959,178 compensation calls, 5,514 engagements, 5,443 drift reports and 4,452 upmix matrices). 22 of 24 planted mutants change the log; the two that don't cannot change what the caller does (a first error that keeps vc2, which is still zero from bzalloc(); no row for one channel, never asked), and the characterization test catches both.

Mutation check of the port: 31 mutants (22 in the core, 9 in the shims), all killed; table in commit 5. After the review fix, 5 more in the new functions and their shims, all killed. The shim mutants are killed by Tier 3, the tier that reaches the shims; two that change only the last bit of a state are killed by both tiers.

port_comparison (audio_resampler_drift/packets/64, Linux x86_64): Rust 896 ns, C 866 ns for 64 packets' step, delta, padding and count (833 and 802 ns before the review fix, on a quieter machine).

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC

The flag change is -ffp-contract=off on the one ported group, libobs.ported-audio-resampler-drift, for GCC, Clang and AppleClang (MSVC doesn't contract under /fp:precise, so the generator expression leaves it off). Cross-checked (runs were on cd80558ef): the C reference's compile command for the group carries the flag under GCC, and the same command with Clang builds it with -Werror; libobs.media+, the caller, builds with Clang too; clang-cl /W4 /WX against the Windows SDK accepts the ported group. Not done yet: a scripting-ON build (this host has no SWIG, and installing it is a host change) and the full app builds; gh workflow run ci.yml --ref fix/rust-port-resampler-clock-drift-358 follows once this head is pushed. Scripting compiles nothing from this group.

  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

rdoupe and others added 7 commits October 31, 2026 07:34
Behaviour-neutral extraction before the Rust port. The decisions of
media-io/audio-resampler-ffmpeg.c.h move to the new
media-io/audio-resampler-drift.c.h, as hidden functions on plain values
and the compensation state, declared without EXPORT in
audio-resampler-drift.h:

- audio_resampler_sample_format(): convert_audio_format(), returning
  the libavutil value as an int;
- audio_resampler_upmix_row(): the mono upmix row of
  audio_resampler_create() (false, writing nothing, for 0 or more than
  MAX_AUDIO_CHANNELS channels, where the C indexed past the table);
- audio_resampler_comp_set_error(): the first-call reset and the dead
  band of audio_resampler_set_compensation_error();
- audio_resampler_comp_step(): clamp_drift() and the loop filter step of
  update_compensation(), returning IDLE, ENGAGE or SET with the delta;
- audio_resampler_output_frames(): the padding while engaged;
- audio_resampler_comp_count(): the sample counters while engaged;
- audio_resampler_comp_drift_report(): the report's gate and its
  estimated input rate.

struct compensation becomes struct audio_resampler_comp in the header,
and the COMP_* constants become AUDIO_RESAMPLER_COMP_* there with the
design comment (the caller still passes the distance to
swr_set_compensation()), so their #undefs go. The header includes no
FFmpeg header: the eight sample formats are AUDIO_RESAMPLER_FMT_*
values, and audio-resampler-ffmpeg.c checks each against its
AV_SAMPLE_FMT_* with a _Static_assert.

audio-resampler-ffmpeg.c keeps every swr_* and av_* call, the output
buffer, its size and the grow decision, the output pointer copies,
convert_speaker_layout() and every log, in their places and under
their conditions: the engage log still comes before
swr_set_compensation(), and swr_set_matrix() is still asked only for a
mono input to more than one channel.

Checked in a scratch harness (not committed). It builds
origin/master's audio-resampler-ffmpeg.c.h verbatim, and this branch's
with the moved file, each over logging stand-ins for libswresample and
libavutil (allocation, channel layouts, rescale, delay, matrix,
compensation and convert, with injected failures) and for bmalloc,
bfree and blog. Each run is one resampler: every audio format and one
past the last, every speaker layout (mono inputs favoured), rates from
1 to 192000, up to 400 calls of 0 to 4096 frames, and compensation
errors at the dead band's edges, at the ends of int64_t, ramping, or
noisy around a drift, plus short runs that engage and end at once.
10,000 runs over 5 seeds in 8 builds (GCC and Clang, -O0 and -O2,
with and without ASan and UBSan without recovery): the logs are
identical, 8,816,852 lines each side in every build, with 959,178
compensation calls, 5,514 engagements, 5,443 drift reports and 4,452
upmix matrices.

24 broken moves were planted, and the harness fails 22: the dead band
1 ns narrower or moved the wrong way on the negative side, compensation
never enabled, the C2 current reversed, vc2 unclamped, no lower clamp,
never engaged, the idle check reordered, the delta's sign, truncation
for lround(), a 10,000 ppm bound, padding by 1/256 or when not engaged,
counting when not engaged, the report without output counted, the 7.1
row feeding the LFE, float planar as packed, and in the caller the
engage log on every step, no delta on the engage step, the counts
swapped, padding when only enabled and the step at the output rate. The
two it passes cannot change what the caller does: the first error
leaving vc2 as it was (it is still zero from bzalloc() then) and no row
for one channel (asked only above one). The characterization test
catches both.

The new file has its own group, libobs.audio-resampler-drift, with a
precompiled header of audio-resampler-drift.h (with audio-io.h),
<math.h> and <stddef.h>, so the C oracle and a C test can compile it
without FFmpeg; libobs-media.pch.h includes the header for
audio-resampler-ffmpeg.c. The exported symbol set of the Linux C build
is unchanged (1767); the seven functions are local (t).
test_audio_clock_drift and test_audio_restart_resampler_tail pass on
it (6 and 4 cases, none skipped).

git blame on the moved lines shows Lain's resampler and pkv's mono
upmix matrix, and the fork's own drift compensation.

Refs #3139.

Co-authored-by: Lain <[email protected]>
Co-authored-by: pkv <[email protected]>
test_audio_resampler_drift_steps compiles
libobs/media-io/audio-resampler-drift.c.h (ASan and UBSan,
-ffp-contract=off) and calls only its hidden functions through
audio-resampler-drift.h, with no swr context and no FFmpeg header, so
it runs on every platform (16 cases):

- the constants: the 10 ms dead band, 1000 ppm, the 2^24 distance, the
  gain and both capacitors, the action values and MAX_AUDIO_CHANNELS;
- every audio format to its libavutil value;
- the mono upmix row for 1 to 8 channels (front pair and centre, no
  LFE), and no row, nothing written, for 0, 9, 64 and UINT32_MAX;
- the first error enabling compensation and clearing both filter
  states, a later one keeping them;
- the dead band at 0, +-1, +-(band - 1), +-band, +-(band + 1),
  +-50 ms and the ends of int64_t;
- an error that stays in the band: 10,000 idle steps, no delta;
- 10,000 steps of 480 frames at 48 kHz with a constant +50 ms and
  -50 ms error: engaged on the first step, each step's delta (an FNV-1a
  hash and their sum), both states bit for bit at eleven steps, and the
  1000 ppm clamp (a delta of 16,777) reached at step 880;
- steps of 1024 frames (the clamp at step 412), an error 1 ns past the
  band at 44.1 kHz (engaged, but never a delta), an error leaving the
  band after 100 idle steps (engaged then, once), an error back in the
  band (still engaged, the correction decays) and zero frames;
- the output frame padding with and without engagement, at the
  multiples of 512;
- the counters only while engaged, wrapping as uint64_t;
- the drift report's gate (engaged, output counted) and its rate.

Characterized, not endorsed:
- an audio format past the last is S16;
- the report divides first, so 48,048 input samples over 48,000 output
  at 48 kHz report a hair under 48,048 Hz;
- a negative estimate (av_rescale_rnd() overflowing, cast) is padded
  toward 0.

The doubles are compared bit for bit, so the test turns floating-point
contraction off, as the shipped file will be when it is ported: GCC and
Clang could otherwise fuse vc1 + ic1 / C1 * in_frames into an FMA where
the hardware has one. MSVC does not contract under /fp:precise.

It is in the native test graph, in name order, on every platform, with
the header as a watch input and libm outside MSVC. No assert_in_range
or fail_msg, so it builds with cmocka 1.x and 2.x and links on
Windows. Passes on the C libobs build (16/16), and with GCC and Clang
at -O0 and -O2 under ASan and UBSan. The real-libobs tests of the
compensation are test_audio_clock_drift and
test_audio_restart_resampler_tail.

Refs #3139.
RED for the port of libobs/media-io/audio-resampler-drift.c.h to a new
audio_resampler_drift module of rust/obs-media-io, next to audio_io and
format_conversion. The safe core is a stub (todo!()): sample_format(),
upmix_row(), set_error() (the dead band), step() (one step of the loop
filter, an Action: Idle, Engage or Set with the delta),
output_frames(), count() and drift_report(), over Compensation, a
#[repr(C)] mirror of struct audio_resampler_comp. The constants
(DEAD_BAND_NS, MAX_PPM, DISTANCE, GAIN, C1, C2 and the eight sample
formats in fmt) are real.

tests/audio/audio_resampler_drift.rs ports
test_audio_resampler_drift_steps 1:1: its 16 cases under the same
names (steps_*), in the same order, with the same values and
expectations (the pinned doubles as their bits), the
characterized-not-endorsed cases included.

Edge cases (edge_*) check the core against a model of the
origin/master C, its expressions inline: the dead band over 21 errors
(around the band, +-1 s, +-10 s and the ends of int64_t), enabled or
not; eight steps from each of those errors at rates of 1 Hz to
UINT32_MAX and 0 to UINT32_MAX frames, engaged or not, both states
bit for bit; the delta rounding half away from zero, as lround() does;
a zero input rate (NaN states and a delta of 0, as glibc's lround()
cast to int); the padding at the ends of int (wrapping where the C
overflows); the counters wrapping; and the report over counts around
0, 48,000, 2^53 and UINT64_MAX. Four proptests: the dead band over
every int64_t, the loop over runs of up to 16 errors within +-10 s at
8 to 192 kHz with 1 to 4096 frames per step, the padding up to 2^20,
and the counters.

The tests are a module of the existing obs-media-io library harness,
the media category's binary; no new test binary.

soldr cargo test -p obs-media-io --lib -- audio::audio_resampler_drift::
passes 1 of 27 (the constants) and fails 26 with "not yet
implemented".

Refs #3139.
GREEN for #3139. Ports libobs/media-io/audio-resampler-drift.c.h, the
decisions of the libswresample resampler, to the audio_resampler_drift
module of rust/obs-media-io. audio-resampler-ffmpeg.c stays C around
it: every swr_* and av_* call (swr_set_matrix() and
swr_set_compensation() among them), the output buffer, its size and the
grow decision, the output pointer copies and every log. The hybrid
libobs drops the C file and links the Rust shims in its place.

Safe core (src/audio_resampler_drift.rs):
- sample_format(): enum audio_format to the libavutil value, S16 for
  unknown and anything outside the enum;
- upmix_row(): the mono upmix row for 1 to 8 channels, None otherwise;
- set_error(): the first call enables and clears the filter, then the
  error less the 10 ms dead band;
- step(): the lag-lead filter, operation for operation as the C (the
  charge pump, the C2 and C1 currents, both states advanced by the frame
  count and clamped to 1000 ppm of the input rate), then Idle, or
  Engage once and Set after, with the delta rounded half away from zero
  as lround() does;
- output_frames(), count() and drift_report().
Compensation is a #[repr(C)] mirror of struct audio_resampler_comp,
which stays in the resampler. The module denies clippy's arithmetic,
as (allowed on the three casts the C makes), indexing, unwrap, expect,
panic, todo, unimplemented and unreachable lints, keeps no state, takes
no lock and allocates nothing. Rust never fuses a multiply and an add,
and the C group is now built with -ffp-contract=off (GCC and Clang;
MSVC does not contract), so the doubles agree bit for bit on every
host.

No intentional difference. The inputs the C never meets: a zero input
rate (NaN states and a delta of 0, as glibc's lround() cast to int;
swr_init() rejects the rate first) and an estimate whose padding
overflows int (wrapped).

Shims (src/ffi/audio_resampler_drift.rs): the seven functions keep the
C signatures; enum audio_format crosses as int, the action (0 to 2) as
unsigned int, the state as Compensation. A null pointer, which the C
dereferences, is neither read nor written; audio-resampler-ffmpeg.c
always passes the resampler's own state and its locals.

C side: the file leaves libobs.audio-resampler-drift for its own ported
group, libobs.ported-audio-resampler-drift, registered in
libobs/build/ported-source-sets/audio-resampler-drift.json on every
host, with the same precompiled header contents and -ffp-contract=off.
The functions are not EXPORT, so the shims are hidden: rust-hidden.txt,
the local: list of rust-exports.map and rust-unexports-macos.txt.
libobs-rust already links the crate's ffi. ci/test_ported_sources.py
checks the group is ported on every host.

test_audio_resampler_drift_steps still compiles the C file into
itself, unchanged. There is no _rust variant against
libobs_rust-static: the shims' archive member holds the rest of
obs-media-io, which needs obs-util (bcrash, libuuid), 238 undefined
references on its own; Tier 3 compares the shims with the C instead.

soldr cargo test -p obs-media-io --lib -- audio::audio_resampler_drift::
passes 27 of 27. test_audio_resampler_drift_steps (16/16),
test_audio_clock_drift (6/6) and test_audio_restart_resampler_tail
(4/4) pass against the C, hybrid and C reference builds, none skipped,
and the 40 audio and resampler tests against the hybrid. The exported
symbols are identical on the Linux C, hybrid and C reference builds
(1767 each, as on master), the seven shims local (t); only
libobs-c-reference compiles the ported group.

Refs #3139.

Co-authored-by: Lain <[email protected]>
Co-authored-by: pkv <[email protected]>
Tier 3 for the audio_resampler_drift port. The oracle
(rust/obs-c-oracle/oracle/audio_resampler_drift.c) compiles the
unchanged libobs/media-io/audio-resampler-drift.c.h with its seven
functions renamed to oracle_*, and gives its constants (the dead band,
the distance, the eight sample formats, MAX_AUDIO_CHANNELS, the action
values, the four doubles) and the size, alignment and every field
offset of struct audio_resampler_comp; bound in
src/audio_resampler_drift.rs. It is built with -ffp-contract=off, as
libobs now builds the file, and calls nothing but lround().

tests/audio/audio_resampler_drift_parity.rs compares the oracle, the
shims and the core exactly, the doubles bit for bit, all three sides:
- the constants and the layout;
- every sample format from -2 to 20 and the ends of int;
- the upmix row for 0 to 9, 64 and UINT32_MAX channels, written or
  not;
- the dead band over 21 edge errors (enabled or not) and, by proptest,
  every int64_t;
- eight steps from each edge error at rates of 1 Hz to UINT32_MAX and
  0 to UINT32_MAX frames, engaged or not, both states and every delta;
- half-way deltas, rounded away from zero on every side;
- the padding over every estimate from 0 to 2^20 and the ends of int
  that do not overflow, engaged or not;
- the counters and the drift report over counts around 0, 48,000, 2^53
  and UINT64_MAX, at output rates of 0 to UINT32_MAX;
- the resampler's own order by proptest (700 runs at the full level,
  about 100,000 steps): errors within +-10 s or near the band every few
  packets, input rates of 8,000 to 192,000 Hz, 1 to 4096 frames per
  step, the count of each conversion, the report at the end, and the
  engagement exactly once.

No intentional difference. Left out, as the C never meets them: a zero
input rate (NaN states; swr_init() rejects it, and Tier 1 pins the
core's answer) and a padding that overflows int. Null pointers, which
the C dereferences, are checked on the Rust side only.

port_comparison gets benches/port_comparison/audio_resampler_drift.rs:
64 packets of 480 frames at 48 kHz, each a step, the padding and the
count, with an error ramping out of the dead band and back every fourth
packet, folded into a checksum both sides must match. Linux x86_64:
Rust 833 ns, C 802 ns. It allocates nothing with bmalloc.

Mutation check (done once, not committed); failing tests per mutant:

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| sample_format: float as planar | 1 | 1 |
| sample_format: outside the enum as U8 | 1 | 1 |
| upmix: 7.1 feeds the LFE | 1 | 1 |
| upmix: off by one | 1 | 2 |
| set_error: vc2 kept | 3 | 2 |
| set_error: band 1 ns narrower | 3 | 2 |
| set_error: negative side away from 0 | 6 | 4 |
| clamp: lower bound to +max | 3 | 3 |
| step: C2 current reversed | 8 | 2 |
| step: C1 term reassociated (last bit) | 4 | 2 |
| step: C1 for C2 | 8 | 2 |
| step: gain reassociated (last bit) | 7 | 2 |
| step: never engaged | 9 | 3 |
| step: idle while at rest | 2 | 1 |
| step: delta sign | 8 | 3 |
| round: ties to even | 1 | 1 |
| step: engage and set swapped | 11 | 4 |
| output_frames: 1 frame, not 2 | 3 | 1 |
| output_frames: 1/256 | 3 | 1 |
| count: when enabled | 3 | 2 |
| drift_report: without output counted | 2 | 1 |
| drift_report: multiplied first | 2 | 2 |
| shim upmix: row not written | 0 | 1 |
| shim set_error: error + 1 | 0 | 4 |
| shim step: arguments swapped | 0 | 3 |
| shim step: delta not written | 0 | 3 |
| shim step: set reported as engage | 0 | 3 |
| shim output_frames: always engaged | 0 | 1 |
| shim count: swapped | 0 | 2 |
| shim report: rate not written | 0 | 2 |
| shim sample_format: off by one | 0 | 1 |

All 31 are killed; the shim mutants by Tier 3, the tier that reaches
the shims. The two "last bit" mutants reassociate a product, which
changes only the last bit of a state: both tiers catch them. The
proptest regression files keep seeds the mutants failed on.

Tier 1 and Tier 3 pass (27/27 and 11/11). At the reduced parity level
the longest new test takes 0.04 s (the loop proptest; 0.28 s for all 38
at the full level); peak RSS 6.6 MB over 25 runs; no threads of their
own.

Refs #3139.
rust/README.md's port table has a row for
libobs/media-io/audio-resampler-drift.c.h, after the media remux job:
the seven functions (the sample format, the mono upmix row, the dead
band, the loop filter step, the padding, the counters and the drift
report), what stays C in audio-resampler-ffmpeg.c (every swr_* and av_*
call, the buffer, its size and the grow decision, and every log), the
_Static_asserts on the sample formats, the mirrored state, the
-ffp-contract=off build, what is characterized, the inputs left out of
Tier 3, the null pointers, and the tests that cover it. The crate table
row already reads "Ports of libobs/media-io/*". The crate's description
and its lib.rs module docs name the new module. naming.md's
libobs/media-io/ row already maps the directory to the crate.

No docs/features.md line: a port with no change in behaviour.

Fixes #3139.
Review fix. The move made audio_resampler_comp_step() compute the delta
before audio_resampler_resample() logged the engagement, and
audio_resampler_destroy() read output_freq for the drift report before
the report's gate. Master reads the correction (vc1) for the delta only
after the engage log, and output_freq only when the report is due. Each
decision is now split in two, so every read is back in its place
(#2153):

- audio_resampler_comp_step() gives only the action (IDLE, ENGAGE or
  SET); audio_resampler_comp_delta() gives the delta, and
  update_compensation() asks it after the engage log, right before
  swr_set_compensation();
- audio_resampler_comp_reports_drift() is the report's gate and
  audio_resampler_comp_input_rate() its rate, asked inside the blog()
  call only when the gate is open.

The Rust core follows: step() returns Action (Idle, Engage, Set) with
no delta, and delta(), reports_drift() and input_rate() are new; the
shims, the oracle and the bench follow, and the hidden-symbol lists
swap audio_resampler_comp_drift_report for the three new functions.

test_audio_resampler_drift_steps asks the delta and the rate as the
caller does (17 cases: delta_rounding is new, half-way corrections
rounded away from zero). The Tier 1 tests do the same through a local
helper, with every pinned value unchanged (27/27). Tier 3 compares the
three new functions on all three sides and adds a proptest of the delta
over every correction the clamp allows at any rate (12/12); five new
mutants in the new functions and their shims are killed.

The scratch move harness, rerun on this tree against origin/master:
identical logs in all 8 builds (8,816,852 lines each side). The
exported symbols are unchanged on the C, hybrid and C reference builds
(1767 each), the nine functions local; test_audio_resampler_drift_steps,
test_audio_clock_drift and test_audio_restart_resampler_tail pass on
all three, none skipped.

Refs #3139.
@rdoupe
rdoupe force-pushed the fix/rust-port-resampler-clock-drift-358 branch from 04c4ae0 to 88cc9e7 Compare October 31, 2026 11:56
@rdoupe
rdoupe marked this pull request as ready for review October 31, 2026 12:51
@rdoupe
rdoupe requested a review from zackees as a code owner October 31, 2026 12:51
@zackees
zackees added this pull request to the merge queue Oct 31, 2026
Merged via the queue into master with commit ac36ac8 Oct 31, 2026
41 checks passed
@zackees
zackees deleted the fix/rust-port-resampler-clock-drift-358 branch October 31, 2026 13:12
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.

rust: Port the resampler clock drift loop

2 participants