Repository navigation
rust: Port media-io audio-io.h inlines + structs to obs-media-io - #129
Merged
Merged
Conversation
swilk19
force-pushed
the
port/audio-io-inlines
branch
from
October 10, 2026 23:14
f45274b to
13a0c19
Compare
Pins the header-inline helpers before the Rust port: get_audio_channels for every enum speaker_layout value, get_audio_bytes_per_channel and is_audio_planar for every enum audio_format value, get_audio_planes for every format and layout pair, get_audio_size and get_total_audio_size (including TOTAL_AUDIO_SIZE), and the audio_frames_to_ns and ns_to_audio_frames conversions. Values outside the enums are characterized: an unknown layout, including 7 (the gap before SPEAKERS_7POINT1 = 8), has 0 channels, and an unknown format has 0 bytes per channel and is interleaved, so it has one plane. Planar sizes ignore the layout, even an unknown one. The conversions truncate, so a frames -> ns -> frames round trip can lose a frame. ns_to_audio_frames takes a sample rate of 0 (it is the multiplier) and returns 0. The large-value cases are inputs where both util_mul_div64 paths agree; the per-platform differences and division by zero stay with test_util_uint64.c. Nothing is swapped, so the test passes with ENABLE_RUST_LIBOBS OFF and ON alike. It is separate from the audio-io.c characterization in obs-rust#120 (test_audio_io.c), which needs a running obs core. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 1, Tier 2 layout and Tier 3 parity tests for the static inline helpers in media-io/audio-io.h (get_audio_channels, get_audio_bytes_per_channel, is_audio_planar, get_audio_planes, get_audio_size, get_total_audio_size, audio_frames_to_ns and ns_to_audio_frames), against todo!() cores. The helpers are header-inline, so nothing is swapped or exported and the header-inline exemption applies: Tier 2 is a layout test of every struct the header defines plus the unchanged cmocka test passing OFF and ON. ffi::audio_io mirrors struct audio_data, struct audio_output_data, struct audio_output_info (with audio_input_callback_t as an Option of an extern "C" fn, so NULL is None) and struct audio_convert_info, with the enums as c_ints. The layout test checks size, alignment and every field offset against the oracle, MAX_AV_PLANES and MAX_AUDIO_CHANNELS against the array lengths, and the size macros (MAX_AUDIO_MIXES, MAX_AUDIO_CHANNELS, MAX_DEVICE_INPUT_CHANNELS, AUDIO_OUTPUT_FRAMES, TOTAL_AUDIO_SIZE). audio_io.rs adds enum audio_format and enum speaker_layout (AudioFormat, SpeakerLayout) with *_to_c / *_from_c like the other media-io enums. speaker_layout skips 7 (SPEAKERS_7POINT1 is 8), so speaker_layout_from_c(7) is None; the layout test checks every enumerator's value against the oracle. ffi::audio_io also has the helpers for C enum values, for later shims that receive them as c_ints. No C case matches a value outside the enums, so they map it to the enum's Unknown: 0 channels, 0 bytes per channel, not planar. audio_frames_to_ns and ns_to_audio_frames will call obs_util::util_uint64::mul_div64, so obs-media-io now depends on obs-util. Parity runs against each platform's own C and excludes what mul_div64 excludes: a sample rate of 0 to audio_frames_to_ns, and on MSVC x64 results past 64 bits. The oracle wraps the header in non-inline oracle_* functions (oracle/audio_io_inlines.c) with its own binding module. Parity sweeps every enumerator plus values just outside each enum (7 included) over edge frame counts, compares the conversions over edge rates and values, and adds proptest over arbitrary c_ints, u32 frame counts, sample rates and u64s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
get_audio_channels, get_audio_bytes_per_channel, is_audio_planar, get_audio_planes, get_audio_size, get_total_audio_size, audio_frames_to_ns and ns_to_audio_frames, as safe Rust that later media-io ports (audio-io.c, audio-resampler) use when they handle these enums and structs. The C helpers are static inline and stay compiled into every C caller; nothing is swapped or exported, so there is no ENABLE_RUST_LIBOBS guard. No intentional differences. The switches become exhaustive matches, so a new enum value fails to compile instead of falling through to the C's default. The size helpers wrap like the C's size_t arithmetic. The conversions are thin wrappers over obs_util::util_uint64::mul_div64, so they inherit its per-platform math and panic where it does: a sample rate of 0 to audio_frames_to_ns, and on MSVC x64 a result past 64 bits. Mutation check: giving SPEAKERS_7POINT1 7 channels, and reporting AUDIO_FORMAT_32BIT_PLANAR as interleaved, each fail Tier 1 and the enumerator sweep; computing ns_to_audio_frames exactly in u128 fails the edge-value and proptest parity tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=a0486750dadbb37edf7b72870f6581b958dee202 secs=114 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791677497,"gate":"rust/all/fmt","host":"linux-x86_64","key":"5c3da106582c7fcd2acde8a9d734fd10f8b8a2db933a20d165dac70b82607097","lane":"lint","parents":["edaa87b96a97e7d8733e289e5739cf19376857b6"],"secs":18,"stamp":"98934ae8867a27f3651dd31b9ab5897e","tree":"a0486750dadbb37edf7b72870f6581b958dee202","v":1,"via":"run"} Ci-Attestation: {"at":1791677497,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"5c3da106582c7fcd2acde8a9d734fd10f8b8a2db933a20d165dac70b82607097","lane":"lint","parents":["edaa87b96a97e7d8733e289e5739cf19376857b6"],"secs":18,"stamp":"649000bcd6f4dbdef27cdc720777302c","tree":"a0486750dadbb37edf7b72870f6581b958dee202","v":1,"via":"run"} Ci-Attestation: {"at":1791677497,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"73c295560e121eb8e88805ceb02d9fceda38638d050e83c6442c175c697570fd","lane":"rust-test","parents":["edaa87b96a97e7d8733e289e5739cf19376857b6"],"secs":35,"stamp":"ca64531306b48721cd9434eb0f0fa3ef","tree":"a0486750dadbb37edf7b72870f6581b958dee202","v":1,"via":"run"} Ci-Attestation: {"at":1791677497,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"3f34096abb565fbfbe68190c6a79f014ed2728242c3d107a3cf624792fcdb5a1","lane":"tier2-linux","parents":["edaa87b96a97e7d8733e289e5739cf19376857b6"],"secs":61,"stamp":"81a9038c3c9dadd90a15282038e93d4c","tree":"a0486750dadbb37edf7b72870f6581b958dee202","v":1,"via":"run"}
Member
|
Rebased onto master (old head 13a0c19, replaced with --force-with-lease). #168 just split the shared registration lists into per-unit files, so this PR follows the new layout:
RED→GREEN, checked with soldr's cache disabled: |
zackees
force-pushed
the
port/audio-io-inlines
branch
from
October 11, 2026 00:11
13a0c19 to
9354e55
Compare
This was referenced Oct 11, 2026
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.
Description
Ports the
static inlinehelpers inlibobs/media-io/audio-io.htoobs-media-io(obs_media_io::audio_io), as item 3 of the media-io part 2 order on #45:get_audio_channels,get_audio_bytes_per_channel,is_audio_planar,get_audio_planes,get_audio_size,get_total_audio_size,audio_frames_to_nsandns_to_audio_frames. No intentional differences.Header-inline exemption. The helpers are
static inline, so nothing is swapped or exported. There is noENABLE_RUST_LIBOBSguard and norust-exports.txtentry, and the header is unmodified. Tier 2 has two parts:struct audio_datastruct audio_output_datastruct audio_output_info, whoseaudio_input_callback_tis anOption<unsafe extern "C" fn>so NULL isNonestruct audio_convert_info, which ends in aboolThe layout test also checks
MAX_AV_PLANESandMAX_AUDIO_CHANNELSagainst the array lengths, and the size macros (MAX_AUDIO_MIXES,MAX_DEVICE_INPUT_CHANNELS,AUDIO_OUTPUT_FRAMES,TOTAL_AUDIO_SIZE). Tier 1 and Tier 3 run against non-inlineoracle_*wrappers.Enums.
enum audio_formatandenum speaker_layoutbecomeAudioFormatandSpeakerLayout, with*_to_c/*_from_clike the other media-io enums, and get the same size, alignment and enumerator checks that #106 did for colorspace and range.speaker_layoutskips 7 (SPEAKERS_7POINT1 = 8), sospeaker_layout_from_c(7)isNone.ffi::audio_iohas the helpers for C enum values. No Ccasematches a value outside the enums, so they map it to the enum'sUnknown, which gives the C's results: 0 channels, 0 bytes per channel, and not planar (one plane).Conversions. As agreed on #45,
audio_frames_to_ns/ns_to_audio_framesare thin wrappers overobs_util::util_uint64::mul_div64(#122), soobs-media-ionow depends onobs-util. They inherit its per-platform math and its exclusions. The port panics instead of guessing on:audio_frames_to_nswithsample_rate == 0: division by zero, UB in C.ns_to_audio_framestakes 0 as the multiplier and returns 0._udiv128faults. Off MSVC they wrap, and are compared.These are listed in
tests/audio_io_inlines_parity.rs, in the README row and here for #45.Oracle.
oracle/audio_io_inlines.cwith its own binding module (src/audio_io_inlines.rs). Itsbuild.rsentries are inserted in the media-io group.Relation to #120. #120 characterizes
audio-io.cintest_audio_io.c. This PR's test istest_audio_io_inlines.c, followingtest_video_io_inlines.c, and its CMake block sits aftertest_video_io_inlinesrather than at the end of the file, so the two don't conflict. The header is unchanged, so the struct fields #120 fills in (audio_output_info,audio_convert_info) are exactly what the layout test checks. #120's getter values (float stereo: 1 plane, 2 channels, 8-byte block; planar 16-bit 5.1: 6/6/2) are among the cmocka cases.audio-math.h(item 4) is not folded in; it will be a separate PR.Motivation and Context
Item 3 of the order approved on #45 (#45 (comment)). Later media-io ports (
audio-io.c) will use these types and helpers.Refs #45
How Has This Been Tested?
Linux x86_64 (WSL2), Rust via soldr.
Commits follow the policy:
test/cmocka/test_audio_io_inlines.c(C characterization, passes OFF and ON before any Rust), then RED (todo!()cores), then GREEN.cmocka test. It pins:
get_audio_size/get_total_audio_size, includingUINT32_MAXframes andTOTAL_AUDIO_SIZEutil_mul_div64paths agreeValues outside the enums (-1, the gap at 7, last + 1, 1000) are characterized, not endorsed. Per-platform differences and division by zero stay in
test_util_uint64.c.soldr cargo test -p obs-media-io:sample_rate == 0panic, and whole-second round trips at common rates.c_ints andu32frame counts, and runs 20,000 cases each over edge-biased and arbitrary rates andu64s.RED→GREEN, checked with soldr's cache disabled and a fresh target dir: at the RED commit
audio_io_inlinesfails 12/13 (the passing test is the enum values) andaudio_io_inlines_parityfails 10/10. The layout test passes there, since the structs and enums are declarations. At head everything passes.Mutation check: each of these fails Tier 1 and/or parity, and all were reverted:
SPEAKERS_7POINT17 channelsAUDIO_FORMAT_32BIT_PLANARas interleavedns_to_audio_framesexactly inu128Local checks:
./lintand./unittestpass. tier2-linux rantest_audio_io_inlineswith ENABLE_RUST_LIBOBS OFF and ON (48/48 each). The libobs exported symbols are identical OFF vs ON (1752). HEAD carries the local-gate stamp.Not run locally: macOS and Windows; the Rust Tests and
rust-tier2CI jobs cover them (Windows covers the MSVCmul_div64path).Types of changes
Checklist:
🤖 Generated with Claude Code