Repository navigation
obs-util: Add the darray.h operations the interleaver uses - #1600
Merged
Merged
Conversation
The interleaver port (obs-rust#1594) uses the C darrays that obs-output.c resets and frees (interleaved_packets, encoder_packet_times[] and keyframe_group_tracking) in place, so obs-util's darray equivalent needs the inline operations it uses and does not have yet: insert, erase range, pop front and push back new (the function and the GCC/Clang macro, which do the same steps). obs-rust#1596 characterized them in test_darray_ops. This adds those functions with todo!() bodies, to the raw API that runs on a struct darray with bmem memory (plus darray_push_back, which insert at num calls) and to the safe DArray, and Tier 1: every test_darray_ops case ported 1:1 under the same names on the raw API, as the C test runs the header, including the "characterized, not endorsed" stale slots past num after removal. The bnum_allocs() cases run in their own process. New edge cases: insert at num into a full array, into a reserved empty one and with an odd item size, growth copying the stale tail, push back new zeroing only the new item, pop front on an empty array, the precondition panics (where C asserts), and the same operations on the safe core. 30 of 31 fail with "not yet implemented"; layout passes, as it checks the existing struct mirror. Refs obs-rust#1594
The interleaver port (obs-rust#1594) uses interleaved_packets, encoder_packet_times[] and keyframe_group_tracking in place: C darrays that obs-output.c resets and frees. darray.h is header-inline, so nothing swaps; the Rust equivalent is a library the port calls, and the struct darray layout is the contract. - obs_util::ffi::darray: darray_insert, darray_erase_range, darray_pop_front and darray_push_back_new (the function, and the GCC/Clang da_push_back_new macro, which does the same steps), plus darray_push_back, which insert at num calls. They follow the header step by step on a struct darray with bmem memory, so C and Rust can hand one array back and forth: num grows before the capacity check, growth copies the whole old capacity, removal moves the tail down and leaves the old values past num (characterized, not endorsed), and only the new item of push back new is zeroed. An index or range the header asserts on panics; pop front on an empty array is a no-op, as the C body checks num after its assert. - obs_util::darray::DArray: the same four operations on the safe core. - Oracle: oracle_* wrappers of the five inline functions, and oracle_da_push_back_new, the macro on a typed DARRAY for 1, 4, 12 and 16-byte items. - Tier 3: darray_ops_match_c now covers every Rust function on twin arrays (and the safe core for one-byte items), comparing num, capacity, the null-ness of the buffer, the return values and every determined byte, including the stale slots past num. darray_mixed_in_place_matches_c hands one array to Rust or C at random against a C-only twin; interleaver_patterns_match_c runs the test_darray_ops packet-time and resort patterns that way, and bmem_accounting_matches_c checks the bnum_allocs() deltas of a hand-off in both directions, in its own process. - rust/README.md: the darray row. No intentional differences. Refs obs-rust#1594
6 of 7 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 21, 2026
* libobs: Add Tier 1 tests for the output interleaver port RED for the port of libobs/obs-output-interleave.c.h, the encoded packet interleaver, to obs-output's new interleave module. The pure parts work on a slice of packets (a PacketView trait): the first and last packet of a track, the start index, the premature prune, the insertion position, the offset arithmetic, the streamable count and the catch-up rule, the discard count, the caption timing and the packet-time lookup. The functions named after the C ones are generic over the output (InterleaveOutput): its fields, the queue and the other darrays, the locks, the encoders and the libobs calls the C file makes, so the C ABI shim can run them on the real struct obs_output through the hidden accessors of obs-rust#1599, and the tests on a model. Every function is a todo!() stub. The first thirty cases mirror test_output_interleave 1:1 (same names, same assertions, in order) on a model output that records what the C test's stubs record: each sent packet with whether interleaved_mutex was held, each packet callback call with its packet time and whether pkt_callbacks_mutex was held, each add_caption call with whether the track's caption mutex was held, and every held copy until it is released. The other 23 pin the edges: the dts_usec and encoder duration truncation, the first and last packet of a track, the start index and the premature prune without audio, the duration lookups stopping at the missing track, the insertion position at equal times, the opposing-type test without video encoders, the catch-up boundaries, the discard count, the caption timing at equal times, the first matching packet time, single-encoder and foreign group entries, one lock per packet and none when inactive, a delayed waiting packet released after the unlock, a packet time offset after the start, an audio packet's time going to the same-numbered array, one pir per callback, and a start without video encoders. They are a module of obs-tests-core, so no new test binary (ci/test_binary_cap.py: 8 of 8). soldr cargo test -p obs-data --test obs-tests-core output::interleave:: fails 53 of 53 with "not yet implemented". Refs obs-rust#1594 * libobs: Port the output interleaver to obs-output libobs/obs-output-interleave.c.h moves to obs_output::interleave. It is the encoded packet callback of an output with video and audio: interleave_packets queues the encoders' packets, starts every track together at timestamp 0 and sends the packets in dts order, with their encoder timing, captions and the encoder group keyframe check. interleave_packets, get_encoder_index and free_packets are declared in obs-internal.h without EXPORT; obs-output.c calls them, and passes interleave_packets to the encoders by name, so the Rust symbol replaces the C one the encoder later compares against. The pure parts work on a slice of packets (PacketView): the first and last packet of a track, the start index, the premature prune, the insertion position, the offset arithmetic, the streamable count and the catch-up rule, the discard count, the caption timing and the packet-time lookup. The functions named after the C ones are generic over the output (InterleaveOutput), as the delay core is over DelayOutput, and take interleaved_mutex, pkt_callbacks_mutex and the caption mutex exactly where the C does. The nine behaviours test_output_interleave marks "characterized, not endorsed" are kept, among them the late-audio keyframe drop, the last-track prune difference, the truncating encoder duration, the track-0-only start index, the non-keyframe start, the waiting non-keyframe discard, priming audio at offset 0 and the early return that does not release a delayed packet. The shim never reads struct obs_output or struct obs_encoder: it goes through the hidden accessors and wrappers of obs-rust#1599, and reads and writes each field where the C does. interleaved_packets, encoder_packet_times[] and keyframe_group_tracking stay the C darrays obs-output.c resets and frees; they are changed in place with obs_util::ffi::darray (obs-rust#1596, obs-rust#1600). Queued packets are libobs's reference-counted copies or the delay's. The clock is read once per packet callback, as in C; the *_with_clock entry point and the statics module (the C file's static functions on a live output) are Rust-mangled and are what the parity test drives. The file leaves libobs.core-output for its own group, libobs.ported-output-interleave, whose PCH is obs-internal.h alone, so the oracle and test_output_interleave compile it without the core. The three symbols go in rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. The exported symbol sets are unchanged. Tier 3 (oracle/output_interleave.c) compares the layouts of the keyframe group entry, the packet callback, the caption text, the darray and the three accessor structs, the values the file uses, thirteen characterization scenarios, and 1024 random runs of up to 80 steps over one to two video and audio encoders: packets with random tracks, keyframes, running timestamps and packet times, changes of active, the delay, the batch limit, the captions, add_caption, the callbacks and the encoder group, restarts, get_encoder_index, and the static functions where their C preconditions hold. After every step it compares the return value, every recorded call and whether each lock was held, the log line, the held copies, the caller's packet, every queued packet, packet time and group entry, the darray capacities and every interleaver field. Both sides go through the same accessor and libobs stand-ins. The oracle builds the file with NDEBUG, as libobs is built: darray_pop_front asserts when a video packet without a packet time is discarded, then does nothing, as the Rust darray does. No intentional differences. test_output_interleave compiles the C into itself and is unchanged. Fixes obs-rust#1594
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.
Refs #1594 (step 3, part 2 of 2; part 1, #1596, added the characterization test
test_darray_ops)What and why
The interleaver port (#1594, step 4) uses three C darrays in place:
interleaved_packets,encoder_packet_times[]andkeyframe_group_tracking.obs-output.cresets and frees all three. From Rust, the port has to insert into those arrays, erase ranges, pop from the front and push new items, with the same semantics as the C inlines.obs-util's darray equivalent had push back array, erase, pop back and free, but none of these.libobs/util/darray.his header-inline, so nothing swaps: the Rust equivalent is a library that ports call, and the struct layout is the contract (testing-policy.md, "Header-inline code"). The C inlines and libobs are unchanged.rust/obs-util/src/ffi/darray.rs):darray_insert,darray_erase_range,darray_pop_frontanddarray_push_back_new, plusdarray_push_back, which an insert atnumcalls. They have their C signatures and are plainunsafe fns.darray_push_back_newcovers both the function and the GCC/Clangda_push_back_newmacro. The two take the same steps.struct darraywith bmem memory and follow the header step by step. So C and Rust can hand one array back and forth: C'sdarray_freefrees what Rust allocated, and Rust grows what C allocated.numgrows before the capacity check.num(characterized, not endorsed).push_back_newzeroes only the new item.pop_fronton an empty array does nothing, like the existingpop_back: the C body checksnumagain after its assert.#[no_mangle]), sorust-exports.d,rust-hidden.txtand the export maps are unchanged.rust/obs-util/src/darray.rs): the same four operations onDArray:insert,erase_range,pop_frontandpush_back_new(returns&mut T, zeroed).rust/obs-c-oracle/oracle/darray.c,src/darray.rs):oracle_*wrappers of the five inline functions;oracle_da_push_back_new, the macro itself on a typedDARRAYthat aliases the array, for 1-, 4-, 12- and 16-byte items.rust/README.mddarray row. testing-policy.md already listsutil/darray.has header-inline.test_darray_ops(14 cases) andtest_darrayare unchanged. The functions arestatic inline, so those tests check the C header in both libobs builds and cannot see the Rust side. Tier 3 is the proof.RED → GREEN
16c8ef92fobs-util: Add Tier 1 tests for the darray.h interleaver operations. The new functions aretodo!().soldr cargo test -p obs-util --lib tests::containers::darray_opsfails 30 of 31 with "not yet implemented".layoutpasses, because it checks the existing struct mirror. The threeshould_paniccases fail on the wrong panic message.tests/containers/darray_ops.rs) ports everytest_darray_opscase 1:1, under the same names withouttest_. The cases run on the raw API with bmem memory, as the C test runs on the header.removal_leaves_tail_byteskeeps the stale slots pastnum.layoutkeeps everything except theDARRAY(type)union aliasing, which has no Rust counterpart.alloc_accountingandresort_patternreadbnum_allocs(), so they run in their own process (common::isolated, Flaky: tests that need process-wide isolation race since #978 merged them into shared binaries #1133).numinto a full array, into a reserved empty array, and with a 3-byte item;safe_*cases run the same operations on the safe core, including its two panics.76faf2273obs-util: Add the darray.h operations the interleaver uses.tests::containers::darraypasses 45/45: 31darray_ops, 9darray, 1 layout and 4 Tier 3. Tier 3 (darray_parity.rs):darray_ops_match_c: a proptest over random sequences of up to 64 operations on two twins, the Rust raw functions and the C oracle, plus the safe core for one-byte items. Element sizes are 1, 4, 12 and 16 bytes.da_push_back_newmacro at random.num,capacity, whether the buffer is null, each return value (the push back index, and the offset of the item push back new returns) and every determined byte.numthat removal leaves, which survive growth. A reallocatingreservecopies onlynumitems, so the test stops comparing the slots pastnumafter one. Other bytes are not compared, because C leaves new memory uninitialized.darray_mixed_in_place_matches_c: onestruct darraythat each step hands to the Rust or the C functions at random,darray_freeincluded, against a C-only twin. This is the interleaver's case.interleaver_patterns_match_c: thetest_darray_opspacket-time and resort patterns, run the same mixed way.bmem_accounting_matches_c: thebnum_allocs()deltas of a hand-off in both directions, in its own process. C allocates and Rust grows and frees; Rust allocates and C grows and frees; removal on either side neither allocates nor frees.darray_insertwrites the item atidx + 1: 6 Tier 1 tests and 3 of 4 Tier 3 tests failed. The proptests shrank to short sequences of one-byte items.darray_erase_rangezeroes the slots past the newnum: 4 Tier 1 tests (removal_leaves_tail_bytesamong them) and 3 of 4 Tier 3 tests failed.darray_push_back_newzeroes one byte less: 2 Tier 1 tests and both proptests failed.ENABLE_RUST_LIBOBS=OFFandON). Each runs the tests againstlibobsandlibobs-with-rust, headless (private Xvfb, private D-Bus, fresh HOME). The machine's cmocka package had been removed, so the cmocka tests used an extracted copy of the same cmocka 2.0.2 package.ENABLE_RUST_LIBOBS=OFF), libobs / libobs-with-rustENABLE_RUST_LIBOBS=ON), libobs / libobs-with-rusttest_darray_opstests the C header, so this shows only that nothing around it moved.ci/local_gate.py:--lane lint(clang-format, gersemi, rustfmt, clippy-D warnings, Dylints, ifdef ratchet, test-binary cap): passed.--lane cross(clippy and Dylints forx86_64-pc-windows-msvcandaarch64-apple-darwin, plus a link of every test binary, the oracle included): passed.--lane cross-release: passed.--lane rust-test(soldr cargo test --workspace --locked, plus a--no-runlink forx86_64-pc-windows-gnu): passed, 1766 tests, none failed. The obs-util harness passes 740/740 (706 before, plus the 31 Tier 1 and 3 new Tier 3 tests here). No Rust test binary was added.Checklist
mastertest_darray_opslanded in test/cmocka: Characterize the util/darray.h operations the interleaver uses #1596)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable