Repository navigation
obs-source: Port the source audio placement and action timeline - #2469
Merged
Merged
Conversation
Behaviour-neutral extraction before the Rust port. The decisions of get_buf_placement(), source_output_audio_place(), source_output_audio_push_back(), the last step of source_output_audio_data() and apply_audio_actions() in obs-source.c.h move to libobs/obs-source-audio-place.c.h, as eleven functions on plain values declared in the new libobs/obs-source-audio-place.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - _started() (audio_ts != 0) and _older() (timestamp < audio_ts): the place's reset, the push-back rule and the action clamp; - _size(), _offset(), _fits() and _pop_back(): the packet's bytes, its byte placement (util_mul_div64() of the difference, times sizeof(float)), the drop past MAX_BUF_SIZE for the place and the push back, and the bytes popped off the back of each channel; - _outputs(): nothing for a monitor-only source; - _action_frame(), _action_stops(), _fill_end() and _mix_on(): each action's frame, the stop at AUDIO_OUTPUT_FRAMES, how far the previous volume fills and the mixes multiplied. Split per read, as obs-rust#2153 did, so every read stays at its point and under its condition: the C's || and && stay in obs-source.c.h, so audio_ts is read once or twice for the place's reset as before, again after reset_audio_data() for the placement, and in the route only when push_back is set; the action clamp reads it again when it applies, and the frame once more. get_buf_placement() stays C: it takes the two timestamps, read before it asks audio_output_get_sample_rate() as when their difference was its argument. Each channel's size is read after its deque_place(), the first channel's before a push back, monitoring_type before audio_ts, and audio_mixers once per mix. audio_buf_mutex, audio_actions_mutex, reset_audio_data(), deque_place(), deque_pop_back(), deque_push_back(), the DEBUG_AUDIO log, the stores of last_audio_input_buf_size, da_erase(), apply_audio_action(), every get_source_volume() call (before the loop and after each applied action), the volume array and multiply_vol_data() stay in obs-source.c.h. conv_time_to_frames() had no other caller; its expression is _action_frame()'s, so it goes. The expressions move as they were: the uint64_t differences, the (size_t) casts of util_mul_div64(), the size_t sums and products, and the int shift of the mix bit. Checked in a scratch harness (not committed). It compiles origin/master's get_buf_placement(), conv_time_to_frames(), source_output_audio_place(), source_output_audio_push_back(), source_output_audio_data() (whole) and apply_audio_actions() verbatim next to this branch's and the moved file, as C++, over a stand-in source whose fields are wrappers that log every read and write with its value. Every call is logged in order with its arguments: both mutexes, audio_output_get_sample_rate() and _get_channels(), os_gettime_ns(), the two audio timing steps, handle_ts_jump(), the resampler's compensation, every deque call, reset_audio_data() (shared, with its own field accesses), blog(), da_erase(), apply_audio_action(), get_source_volume(), multiply_vol_data() (with a hash of the whole volume array), source_muted() and the audio signal. The stubs answer from one seeded stream in call order, and a concurrent writer may move audio_ts, monitoring_type, audio_mixers or a channel's size at any call. Inputs: audio_ts of 0 and around the packet; packet timestamps at, one to three ns either side of, whole frames and blocks from, and seconds before audio_ts, the ends of int64 and uint64, and random; frames of 0, 1, 480, 1023 to 1025, 4096, around 1024000 and UINT32_MAX; rates of 8000 to 384000 Hz, 0, 1, 1e9 and UINT32_MAX (and any size_t for the actions); 0 to 8 channels; channel sizes empty, around MAX_BUF_SIZE and random; every monitoring type and 7; 0 to 7 actions of each type at those timestamps; any mixer mask. 25,400,000 runs: 10,000,000 each with GCC and Clang at -O2, 2,000,000 each at -O0, 500,000 each under ASan and UBSan with no recovery (GCC -O0, Clang -O2) and 400,000 with gcov. All 1,077,683,735 events match, as does the final state. Every branch of origin/master's functions is taken both ways, but the switch default of the timing action, which the stub never returns. 22 deliberately broken moves were planted. 21 fail it: audio_ts read once for the place's reset, the placement taken before the reset, audio_ts read before push_back, monitoring_type read after audio_ts, audio_ts read once for the action clamp, get_source_volume() before the fill, apply_audio_action() dropped, audio_mixers read once, and thirteen changed decisions (started at > 1, older at <=, the size in uint32_t, the placement in frames, rounded up, the fit at < and as a saturating sum, the pop one short, monitor-only for NONE, the frame's rate and duration swapped, the stop at >, the fill one short, the next mix bit). The 22nd, _fill_end() always the new frame, is equivalent: the C's loop condition fills nothing when it is not past frame_num. git blame on the moved lines shows only upstream commits (c1dd156, bc0b85c, d2934ec, 0e4ea14, 2963959, a1fbf10 and earlier); the fork's one line there (cb8ec4b, the DEBUG_AUDIO #if) stays. The constants AUDIO_OUTPUT_FRAMES, MAX_BUF_SIZE and OBS_MONITORING_TYPE_MONITOR_ONLY are copied into the header, so it needs no core header; obs-source.c.h checks them, and that enum obs_monitoring_type is int-sized, with _Static_assert. The new file joins libobs.core-source with libobs.pch.h, which includes the new header; source-sets.json lists it. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. The exported symbol sets are unchanged; the eleven functions are local. Refs obs-rust#2461
test_source_audio_place_steps compiles libobs/obs-source-audio-place.c.h (ASan and UBSan) and calls only its functions through obs-source-audio-place.h. 13 cases: - the header's copies of AUDIO_OUTPUT_FRAMES, MAX_BUF_SIZE and OBS_MONITORING_TYPE_MONITOR_ONLY, and the enum's size; - the started and older rules over every pair of nine edge timestamps; - the packet's size from 0 to UINT32_MAX frames, in size_t; - the byte placement at 0, just under and at one frame, and one second, at 8000, 44100, 48000 and 384000 Hz, one block short of MAX_BUF_SIZE, a rate of 0, and the wrap of an older timestamp; - the fit just under, at and just over MAX_BUF_SIZE, and the pop off the back, with their size_t wraps; - each monitoring type, and every type from -64 to 64 and the ends of int; - the action frames at, just under and at one frame, at frames 1023 and 1024 and one second for each rate, the unclamped wrap, and the stop; - the fill's end and the mix rule over every 8-bit mask. source_output_audio_place(), source_output_audio_push_back(), the last step of source_output_audio_data() and apply_audio_actions() are also copied onto a stand-in source that counts each channel's bytes, to pin end to end: no audio_ts (reset, placed at 0), one frame later, less than a sample later (on top of the start, cut back), an older packet (reset at its own time) and one second later, at each rate; at 48 kHz a block just under, exactly at and one frame past MAX_BUF_SIZE (placed, placed, dropped); the push back just under, at and over it; every monitoring type with and without push_back and an audio_ts; and actions before, at and after audio_ts, at frames 1023 and 1024 (the second stays queued with everything after it), the fill up to an action, none, out of order, and the mixes. Characterized, not endorsed: - a packet less than one sample after audio_ts is placed at 0, on top of the samples already there, and an action that close applies at frame 0: the conversion rounds down; - a packet larger than MAX_BUF_SIZE on its own is dropped whole, even into an empty buffer; - a push back checks only the first channel's size; - an action before audio_ts applies at frame 0; once one is at frame 1024 or later, the loop stops and every later action waits, even one that is due; a later action at an earlier frame fills nothing; - a monitoring type outside the enum outputs; - the fit's sum and the pop wrap as size_t, and the placement and frame of a timestamp before audio_ts wrap (the callers reset or clamp first). It is in the native test graph, in name order, with the header as a watch input. No assert_in_range or fail_msg, so it builds with cmocka 1.x and 2.x, and no two enum types are compared. The real-libobs tests test_async_delay_audio, test_audio_sync_offset_change, test_audio_clock_drift, test_audio_buffering_subsample, test_media_sync_offset_restart, test_audio_restart_resampler_tail, test_source_volume_mix, test_source_audio_ranges and test_audio_controls cover the callers. Refs obs-rust#2461
RED for the port of libobs/obs-source-audio-place.c.h to a new audio_place module of rust/obs-source, next to audio_timing and volume_apply. The safe core is a stub (todo!()): started(), older(), size(), offset(), fits(), pop_back(), outputs(), action_frame(), action_stops(), fill_end() and mix_on(), with FRAMES, MAX_BUF_SIZE and MONITOR_ONLY. The plan sketched place() -> Reset + Drop | Place, route() -> Skip | PushBack | Place and action_frame() -> Stop | At(n). Those would read audio_ts once where the C reads it twice (the place's reset, the action clamp) and read it in the route when push_back is not set, so each step is its own function, asked at its own point, as obs-rust#2153 did. tests/source/audio_place.rs ports test_source_audio_place_steps 1:1: its 13 cases under the same names (steps_*), in the same order, with the same values and expectations, the characterized-not-endorsed cases and the stand-in source's copies of the callers included. Edge cases (edge_*) check the core against models of the original C: - every pair of 26 special timestamps (around 0, 2^32, 2^63, u64::MAX, one second, one sample and one block at 48 kHz) for the reset rules, the placement and the action frame at ten rates where every host's util_mul_div64() is exact (0, 1, 8000 to 384000 Hz and 1e9); - the size over special frame counts, and the fit, the fill's end and the stop over every pair, the pop over every triple, of 15 special sizes (around a block, MAX_BUF_SIZE, 2^32 and usize::MAX); - every monitoring type from -70,000 to 70,000 and the ends of int; - the mix rule for every low 16-bit mask under four high words at every bit, and indices past the width; - the first nanosecond of every frame from 0 to 1025 at eleven rates; - proptests (4,096 cases each): every decision over full-range values, and packet and action sequences through the stand-in against a copy of the callers with origin/master's expressions inline. soldr cargo test -p obs-data --test obs-tests-core -- source::audio_place passes 1 of 21 (the constants) and fails 20 with "not yet implemented". Refs obs-rust#2461
Ports libobs/obs-source-audio-place.c.h, the source audio placement and action timeline of obs-source.c, to the audio_place module of rust/obs-source. obs-source.c.h stays C around it: every read of the source (audio_ts at each of its points, monitoring_type, the channels' sizes and audio_mixers once per mix), audio_buf_mutex and audio_actions_mutex, audio_output_get_channels() and get_buf_placement() with its audio_output_get_sample_rate() call, reset_audio_data(), the deques, da_erase(), apply_audio_action(), every get_source_volume() call (before the loop and after each applied action), the volume array and multiply_vol_data(). The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/audio_place.rs), eleven functions: - started(): audio_ts != 0; older(): timestamp < audio_ts; - size(): frames times 4, wrapping usize; - offset() and action_frame(): util_mul_div64(timestamp - audio_ts, rate, 1e9) with the difference wrapping, cast to usize as the C casts to size_t; offset() times 4, wrapping; - fits(): the wrapping usize sum at most MAX_BUF_SIZE; pop_back(): the wrapping difference; - outputs(): not MONITOR_ONLY; action_stops(): frame >= FRAMES; fill_end(): the larger frame; - mix_on(): bit mix of the mask, none past the u32's width. The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock. The conversion is transition_render's mul_div64() (now pub(crate), with to_size()): the host's util_mul_div64(), the wrapping uint64_t formula, or on MSVC x64 the exact 128-bit quotient, which in the C faults when it does not fit and there saturates. With a divisor of 1e9 both are the exact quotient for any rate up to 1e9 Hz. Shims (src/ffi/source_audio_place.rs): the eleven C signatures by value; the monitoring type as int. No pointer crosses and no struct is mirrored. Intentional differences, on inputs libobs never passes: mix_on() with a mix at or past 32 (the C's int shift is undefined from 31 on) says no mix; on MSVC x64 a frame count past 64 bits (a rate above 1e9 Hz), where the C faults, saturates. libobs asks mixes 0 to 5 and passes the output's sample rate. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-audio-place (LIBOBS_PORTED_SOURCES), whose PCH is only obs-source-audio-place.h and util/util_uint64.h; libobs.pch.h keeps the header for obs-source.c. 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. The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and libobs-c-reference; the eleven functions are local in all three, and the hybrid's come from the Rust archive. ci/test_ported_sources.py checks the group on every host. test_source_audio_place_steps still compiles the C file into itself, unchanged. The new test_source_audio_place_steps_rust builds the same test source against libobs_rust-static instead, as test_source_video_tick_steps_rust does, and links: the test includes the header and obs.h and calls only the eleven hidden functions. test_async_delay_audio, test_audio_sync_offset_change, test_audio_clock_drift, test_audio_buffering_subsample, test_media_sync_offset_restart, test_audio_restart_resampler_tail, test_source_volume_mix, test_source_audio_ranges, test_audio_controls, test_source_audio_timing_steps and test_source_volume_apply_steps see the swap through the real libobs, and pass on the C backend, the hybrid and libobs-c-reference. soldr cargo test -p obs-data --test obs-tests-core -- source::audio_place passes 21 of 21. No user-visible change, so no docs/features.md line. Refs obs-rust#2461
Tier 3 for the audio_place port. oracle/source_audio_place.c compiles the unchanged libobs/obs-source-audio-place.c.h with its eleven functions renamed to oracle_*, plus the header's values and sizeof(size_t). tests/source/audio_place_parity.rs gives each input to the oracle, to the shim the hybrid links and to the core, and compares each bool as the byte the C returns (it must be 0 or 1) and each number exactly: - the header's values and sizeof(size_t); - the reset rules over every pair of 30 special timestamps, and the placement and the action frame over every pair at 16 rates (0, 1, 8000 to 384000 Hz, 1e9, 1e9 + 1 and UINT32_MAX), and size_t rates past 32 bits for the frame; - the first and last nanosecond of every frame from 0 to 2048 at eleven rates, and a stride of 70,000 differences at five; - the size over every frame count to 100,000 and every 65,521st uint32_t; the fit, the fill's end and the stop over every pair, and the pop over every triple, of 17 special sizes; - every monitoring type from -100,000 to 100,000, every 65,521st int and the ends; - the mix rule for every low 16-bit mask under eight high words at every mix from 0 to 30; - the callers (source_output_audio_place(), source_output_audio_push_back(), the last step of source_output_audio_data() and apply_audio_actions(), as the C test's stand-in source) on the oracle and on the shims: 36,864 packet pairs over rates, starts, channels, monitoring types, push backs, timestamps and sizes around MAX_BUF_SIZE, and 21,316 action lists; every trace, buffer, volume array and mix must match; - proptests (20,000 cases each) of every function over full-range values and of the callers over packet and action sequences from any state. Not compared: on MSVC x64 (cfg!(all(target_env = "msvc", target_arch = "x86_64"))) a placement or frame past 64 bits, where the C's _udiv128() faults, and the callers at a rate above 1e9 Hz, the only way to reach one; and the mix rule at 31 and up, where the C's int shift is undefined. Those are the two intentional differences. Otherwise no input is excluded. Mutation check (once, not committed): 28 mutants, 18 in the core and its conversion and 10 in the shims (failing tests per tier, Tier 1 of 21 and Tier 3 of 11): mutant Tier 1 Tier 3 core: started at > 1 2 1 core: older at <= 4 3 core: size of frames + 1 7 4 core: size in 2-byte samples 7 4 core: offset in frames 7 5 core: difference saturating 4 2 core: rate + 1 6 5 core: fits at < 5 3 core: fits saturating 2 1 core: pop saturating 3 2 core: pop one short 6 4 core: outputs above monitor only 5 4 core: action rate truncated to u32 0 2 core: stop at > 3 2 core: fill to the smaller frame 5 4 core: mix on the next bit 5 4 core: no mix 31 2 0 conversion: exact quotient on every host 0 3 shim: older arguments swapped 0 6 shim: offset timestamps swapped 0 5 shim: outputs inverted 0 4 shim: fits arguments swapped 0 0 shim: pop placement and size swapped 0 0 shim: action rate masked to 32 bits 0 2 shim: mix + 1 0 4 shim: fill_end arguments swapped 0 0 shim: size of frames + 1 0 4 shim: stop asks frame + 1 0 3 25 are killed. Tier 1 stays at rates up to 1e9 and below 2^32, so the rate truncation and the per-host conversion fall to Tier 3; Tier 3 leaves out mix 31 (undefined in the C), so that one falls to Tier 1. The three survivors are equivalent: the fit adds its arguments and the pop adds placement and size, either way round, and the fill's end is the larger of two frames. soldr cargo test -p obs-data --test obs-tests-core -- source::audio_place passes 32 of 32 (Tier 1 21, Tier 3 11). Refs obs-rust#2461
rust/README.md gets the row for libobs/obs-source-audio-place.c.h (obs-source::audio_place), in sorted place: what moved, what stays C and why (every read at its point with the C's && and || around the calls, both mutexes, the deques and every get_source_volume() call), the characterized-not-endorsed behaviours, the two intentional differences, the tests that see the swap and what Tier 3 covers. The obs-source crate row, its Cargo description and the lib.rs crate docs name the new module. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. rust/obs-c-oracle/benches/port_comparison/source_audio_place.rs, in the sorted mod and modules![...] lists, runs 1024 packets around an audio timestamp at 48 kHz (no audio_ts yet, older, at it, a sample, a block and seconds later, near MAX_BUF_SIZE; every monitoring type; push back on and off) through the decisions of the last step of source_output_audio_data() and of source_output_audio_place() with two channels, then one action and its six mixes, on the shims and on the oracle, and checks both checksums match. Release, x86_64 Linux, GCC, a loaded host, median per 1024 packets: Rust 22.12 us, C 20.97 us (1.05x), about 1 ns a packet. The port changes nothing a user can see, so docs/features.md has no line. Fixes obs-rust#2461
Member
|
Coordinator review: a port in the same shape as #2448 and #2457. The audio placement and action-timeline decisions become pure functions with a C reference copy, a C-vs-Rust parity test, a bench and the export maps. A new cmocka test is added, and the only existing test file touched is the test-graph.json entry. Queuing; it merges when CI is green. |
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.
Fixes #2461
What and why
Ports the source audio placement and action timeline of
libobs/obs-source.c.htorust/obs-source, as a new moduleaudio_place, next toaudio_timingandvolume_apply. Every audio packet a source outputs goes through the placement, and every tick with queued audio actions (volume, mute, push-to-talk, push-to-mute) goes through the timeline:source_output_audio_place()withget_buf_placement(): the reset when there is noaudio_tsor the packet is older, the packet's size and byte placement, the drop pastMAX_BUF_SIZE, and how much is popped off the back of each channel after the place;source_output_audio_push_back(): the drop pastMAX_BUF_SIZE;source_output_audio_data(): nothing for a monitor-only source, else push back (with anaudio_ts) or place;apply_audio_actions(): each action's timestamp clamped toaudio_ts, its frame, the stop atAUDIO_OUTPUT_FRAMES, how far the previous volume fills, and the mixes multiplied.The audio timing unit (#1932, which created
rust/obs-source) ported the timestamp decisions ofsource_output_audio_data()and explicitly left "the deque place/push-back" in C, so none of this was covered before.The plan's API was split per step. The plan sketched
place(in) -> Reset + Drop | Place { offset, pop_back },route(monitoring_type, push_back, audio_ts) -> Skip | PushBack | Placeandaction_frame(ts, audio_ts, rate) -> Stop | At(n). Those would readaudio_tsonce where the C reads it twice (the place's reset, the action clamp) and read it in the route whenpush_backis not set. So each step is its own function, asked at its own point (as #2153 did), and eleven functions cross the C ABI:obs_source_audio_place_started()(audio_ts != 0) and_older()(timestamp < audio_ts): the place's reset, the push-back rule and the action clamp;_size(),_offset(),_fits()and_pop_back(): the packet's bytes, its byte placement, the drop for the place and the push back, and the pop;_outputs(): notOBS_MONITORING_TYPE_MONITOR_ONLY;_action_frame(),_action_stops(),_fill_end()and_mix_on().What stays C, at its point and under its condition:
&&and||around the calls:audio_tsonce or twice for the place's reset, again afterreset_audio_data()for the placement, in the route only whenpush_backis set, and in the action loop once for the clamp, again when it applies and again for the frame;monitoring_typebeforeaudio_ts; each channel's size after itsdeque_place(), the first channel's before a push back;audio_mixersonce per mix;audio_buf_mutexandaudio_actions_mutex,audio_output_get_channels(), andget_buf_placement()with itsaudio_output_get_sample_rate()call. It now takes the two timestamps, read before it asks for the rate, as when their difference was its argument;reset_audio_data(),deque_place(),deque_pop_back(),deque_push_back(), theDEBUG_AUDIOlog and the stores oflast_audio_input_buf_size;da_erase(),apply_audio_action(), everyget_source_volume()call (before the loop and after each applied action, so each action's push-to-talk and push-to-mute state is seen, as today), the volume array andmultiply_vol_data().conv_time_to_frames()had no other caller. Its expression is now_action_frame(), so it is deleted. The header copiesAUDIO_OUTPUT_FRAMES,MAX_BUF_SIZEandOBS_MONITORING_TYPE_MONITOR_ONLY, andobs-source.c.hchecks them, and thatenum obs_monitoring_typeisint-sized, with_Static_assert. No pointer crosses and no struct is mirrored.Six commits:
Move (behaviour-neutral,
22a2f4c36): the decisions go tolibobs/obs-source-audio-place.c.h, declared in the newobs-source-audio-place.hwithoutEXPORT, so they are hidden. The file joinslibobs.core-source.git blameon the moved lines shows only upstream commits. The fork's one line there, theDEBUG_AUDIO#if, stays in place.The move was checked against the original code. A scratch harness (not committed) compiles origin/master's
get_buf_placement(),conv_time_to_frames(),source_output_audio_place(),source_output_audio_push_back(),source_output_audio_data()(the whole function) andapply_audio_actions()verbatim, next to this branch's and the moved file, as C++:audio_output_get_sample_rate()and_get_channels(),os_gettime_ns(), both audio timing steps,handle_ts_jump(), the resampler's compensation, every deque call,reset_audio_data()(shared, with its own field accesses),blog(),da_erase(),apply_audio_action(),get_source_volume(),multiply_vol_data()(with a hash of the whole volume array),source_muted()and the audio signal;audio_ts,monitoring_type,audio_mixersor a channel's size at any call;audio_tsof 0 and around the packet; timestamps at it, a few ns, whole frames, blocks and seconds from it, the ends ofint64anduint64, and random; frames of 0 toUINT32_MAXaround a block andMAX_BUF_SIZE; rates of 8000 to 384000 Hz, 0, 1, 1e9 andUINT32_MAX(anysize_tfor the actions); 0 to 8 channels; channel sizes aroundMAX_BUF_SIZE; every monitoring type and 7; 0 to 7 actions of every type; any mixer mask.25,400,000 runs (GCC and Clang
-O2, 10,000,000 each;-O0, 2,000,000 each; ASan with UBSan, no recovery, under GCC-O0and Clang-O2, 500,000 each; gcov, 400,000): all 1,077,683,735 logged events match on both sides, and so does the final state. Every branch of origin/master's functions is taken both ways, except the timing switch's default edge, which the stub never returns.22 deliberately broken moves were tried, and 21 fail the harness:
audio_tsread once for the place's reset; the placement taken before the reset;audio_tsread beforepush_back;monitoring_typeread afteraudio_ts;audio_tsread once for the action clamp;get_source_volume()before the fill;apply_audio_action()dropped;audio_mixersread once for the loop;uint32_t, the placement in frames and rounded up, the fit as a saturating sum, the pop one short, monitor-only for NONE, the frame's rate and duration swapped, the fill one short, the next mix bit.The 22nd,
_fill_end()always returning the new frame, is equivalent: the C's loop condition already fills nothing when the new frame is not pastframe_num.Characterization (
01e5bc174):test_source_audio_place_steps, 13 cases. It compiles the moved file with ASan and UBSan and calls only its functions. It pins every decision over edge values, at 8000, 44100, 48000 and 384000 Hz, and copies the four callers onto a stand-in source:MAX_BUF_SIZE(placed, placed, dropped), and the same for the push back;push_backand anaudio_ts;audio_ts, at frames 1023 and 1024, the fill, none, out of order, and the mixes.It is in the test graph, sorted, with the header as a watch input.
RED (
bab3988c2): Tier 1 againsttodo!(). It ports the 13 C cases 1:1 and adds 8 edge tests: every decision against models of the C over pairs of 26 special timestamps at ten exact rates, pairs and triples of 15 special sizes, the monitoring types from -70,000 to 70,000, every low 16-bit mask at every bit, the first nanosecond of every frame from 0 to 1025 at eleven rates, and proptests over full-range values and over packet and action sequences through the stand-in against origin/master's expressions inline.GREEN (
b9cd6a191): the safe core (eleven functions) and eleven#[no_mangle]shims, in a newlibobs.ported-source-audio-placegroup whose PCH is only the new header andutil/util_uint64.h.source-sets.json, the unity lists, the three export lists andci/test_ported_sources.py, each in sorted place.transition_render's per-hostutil_mul_div64()(madepub(crate), withto_size()), so the crate still depends on no other crate.test_source_audio_place_steps_rustbuilds the unchanged test source againstlibobs_rust-static, astest_source_video_tick_steps_rustdoes.Tier 3 (
5265f2c91): a C oracle of the unchanged file, the parity tests and a mutation check.Docs (
b55677cc6): the README rows, the crate's description,lib.rs, and aport_comparisonbench module in the sorted lists. The port changes nothing a user can see, sodocs/features.mdhas no line.The core denies clippy's arithmetic, indexing,
as, unwrap, expect, panic, todo, unimplemented and unreachable lints. It keeps no state and takes no lock. Every sum, difference and product wraps where the C's unsigned arithmetic does.audio_tsis placed at 0, on top of the samples already there, and an action that close applies at frame 0: the conversion rounds down;MAX_BUF_SIZEon its own (over 21.3 s at 48 kHz) is dropped whole, even into an empty buffer;audio_tsapplies at frame 0. Once one action is at frame 1024 or later, the loop stops and every later action in the queue waits, even one that is already due. A later action at an earlier frame fills nothing;size_t, and the placement and frame of a timestamp beforeaudio_tswrap. The callers reset or clamp first, so neither is reachable._mix_on()with a mix of 32 or more says no mix. The C'sintshift is undefined from 31 on, and libobs asks only 0 to 5;_udiv128()faults. That needs a rate above 1e9 Hz.Bench (x86_64 Linux, GCC, release, not pinned to a core, a loaded host; median per 1024 packets, each through the route, the place with two channels, one action and its six mixes): Rust 22.12 µs, C 20.97 µs (1.05x), about 1 ns a packet.
RED → GREEN
bab3988c2(obs-source: Test the audio_place port).soldr cargo test -p obs-data --test obs-tests-core -- source::audio_place: 1 passed (the constants, which are not stubs), 20 failed, each on atodo!().local_gate --lane lintwas clean, and--test-diff origin/masterran 4266 tests: 4246 passed, 6 skipped, and only those 20 failed.b9cd6a191): Tier 1 21/21.test_source_audio_place_stepspasses 13/13 on the C backend, on hybridlibobsand onlibobs-c-reference, andtest_source_audio_place_steps_rustpasses 13/13 against the Rust archive.test_async_delay_audio,test_audio_sync_offset_change,test_audio_clock_drift,test_audio_buffering_subsample,test_media_sync_offset_restart,test_audio_restart_resampler_tail,test_source_volume_mix,test_source_audio_ranges,test_audio_controls,test_source_audio_timing_stepsandtest_source_volume_apply_stepspass on all three, run through ctest under a private Xvfb, with every case run and none skipped (156 cmocka cases on the C backend, 169 with the_rustvariant on the other two).libobs-c-reference.5265f2c91): 11/11, oracle, shims and core compared exactly.sizeof(size_t).UINT32_MAX, andsize_trates past 32 bits for the frame)._udiv128()fault inputs and the mix rule at 31 and up.fits()andpop_back()with arguments swapped add them the same way, andfill_end()is the larger of two frames either way round.b55677cc6(the head, on7ef75ab02):local_gate --lane lint,--test-diff origin/masterand--lane cross(clippy forx86_64-pc-windows-msvcandaarch64-apple-darwin, withSOLDR_RUSTC_WRAPPER=none) all pass (test-diff: 4277 passed, 6 skipped);SOLDR_RUSTC_WRAPPER=none soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warningsis clean (the cross lane lints only--lib --binswithout the oracle);soldr cargo test -p obs-c-oracle --locked --bench port_comparisonpasses.libobs,libobs-c-reference) onb55677cc6, under a private Xvfb: 100% passed on each: 522/522 (C backend), 551/551 (hybrid), 551/551 (libobs-c-reference), with no reruns. The exported symbol sets of those builds are still identical (1766).Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable)_mix_on()from mix 32 and the MSVC x64 fault inputs