Skip to content

Phase 5 remaining: graphics math, media-io, parsers, obs-websocket Tier 4 #45

Closed

Description

@zackees

#8 closed when feature PR #33 merged, but PR #39 ported only vec2 (new obs-graphics crate).

Remaining:

Refs #4, #8, #39

Activity

  1. b7216309-jpg commented on Oct 10, 2026

    @b7216309-jpg
    Contributor

    I'd like to take the AVC/HEVC/AV1 parser item. Plan, one PR per C file, each following the testing policy (C characterization first where missing, then RED, then GREEN):

    1. libobs/obs-nal.c: obs_nal_find_startcode, the FFmpeg start-code search that AVC and HEVC share. It scans word by word after an alignment prologue, so parity calls it at every pointer alignment and around the 4-byte start-code adjustment.
    2. libobs/obs-avc.c: the 6 exports. Notes: obs_parse_avc_packet prefixes its output with a long refcount (4 bytes on Windows, 8 elsewhere), obs_parse_avc_header truncates SPS/PPS sizes to uint16_t, and the SPS reader keeps the get_ue_golomb cap from fix(libobs): get_ue_golomb UB on a truncated SPS (1 << 32) #17. struct encoder_packet gets a layout test.
    3. libobs/obs-hevc.c
    4. libobs/obs-av1.c (OBU parsing)

    Fuzz parity. Each port gets proptest parity against the C oracle on structured inputs (start codes, emulation-prevention bytes, truncated NALs and SPS) and arbitrary bytes. I also plan a cargo-fuzz target per parser that runs the Rust and C sides on the same input and asserts equal results. cargo-fuzz needs nightly and libFuzzer, so I'd keep those targets out of the default workspace and the required CI. They would be run on demand, or in a separate job if you want one.

    Starting with obs-nal.c now. Please say if you'd rather split or order this differently.

  2. swilk19 commented on Oct 10, 2026

    @swilk19
    Contributor

    I'd like to take the media-io item, starting with the two smallest pure-function files. One PR per file, each following the testing policy: a C characterization test first, then a failing (RED) test against stubs, then the port (GREEN).

    1. libobs/media-io/video-fourcc.c: video_format_from_fourcc, in a new obs-media-io crate (per the testing policy). A cmocka test pins every mapped fourcc, plus unknown codes going to VIDEO_FORMAT_NONE. Parity runs against the C oracle over the full u32 range, and the result enum gets a layout test.

    2. libobs/media-io/video-matrices.c: video_format_get_parameters and video_format_get_parameters_for_format. Things to note:

      • The matrices are built lazily behind a plain static bool, so two threads calling at the same time race on the initialization. The Rust side would use OnceLock.
      • bpc is clamped to 8–16.
      • DEFAULT/SRGB map to 709 and 2100_HLG maps to 2100_PQ.
      • The range_min/range_max out-pointers can be NULL.

      Parity compares every colorspace × range × format (and bpc) combination with the C output, bit for bit.

    initialize_matrix calls vec3_rotate, so I'll start the matrices port once #75 (vec3) lands and build on obs-graphics' Vec3, so it doesn't duplicate that work. fourcc doesn't depend on anything, so I'll start there now.

    I'm only taking these two files. The rest of media-io (format-conversion.c, video-frame.c, video-io.c, audio-io.c, the ffmpeg scaler/resampler, media-remux.c) is still open for anyone. Please say if you'd rather split or order this differently.

  3. swilk19 commented on Oct 10, 2026

    @swilk19
    Contributor

    Both files from my first claim are in: video-fourcc.c (#97) and video-matrices.c (#106). Thanks for the rebases and the Windows fix.

    I'd like to take the rest of media-io's pure, deterministic units next. Same workflow as before: one PR per unit, each with a C characterization test first, then RED, then GREEN.

    1. video-io.h inlines + frame-rate.h: header-inline, so they use the policy's header-inline exemption. That means a layout test for every public struct plus oracle_* wrappers and parity. There's no symbol swap, and the headers are left untouched.
    2. audio-io.h inlines + structs: header-inline as well.
    3. audio-math.h: mul_to_db / db_to_mul.
    4. video-frame.c: video_frame_init, video_frame_copy and related functions, in obs-media-io.
    5. format-conversion.c: the pixel-packing conversions, after video-frame.c.

    I'll keep at most two of these PRs open at a time, since they all touch obs-media-io's lib.rs, ffi/mod.rs and video_io.rs.

    Not taking yet, and why:

    • video-io.c, audio-io.c: these are the stateful core: worker threads, os_sem/os_event, recursive mutexes, atomics, and the profiler name store. audio-io's loop is driven by the wall clock. obs-util: port util/task.c to Rust #87 shows a way to handle the threading, by reimplementing the primitives with Mutex/Condvar inside the port. But both files also call into profiler.c, which is still C, and each needs a deterministic characterization test first. I'd like to finish the pure units before taking these on.
    • video-scaler-ffmpeg.c, audio-resampler-ffmpeg.c, media-remux.c: these are thin FFmpeg wrappers, so I'd leave them in C for now and port them via ffmpeg-sys-next alongside video-io/audio-io. Pure-Rust replacements aren't bit-exact with FFmpeg, so they would be a separate behaviour change, not a port.

    Please say if you'd rather split or order this differently, and let me know if you have a preferred approach on any of these.

  4. zackees commented on Oct 10, 2026

    @zackees
    MemberAuthor

    Approved, with one added unit and some notes per item. No one else has claimed any of these: there are no open PRs touching libobs/media-io/, and the only other claim on this issue (the parsers) is done. Go ahead and start with item 1.

    Order

    1. video-io.h inlines + frame-rate.h: as proposed.
    2. New, before audio-io.h: util/util_uint64.h (util_mul_div64) in obs-util. audio_frames_to_ns and ns_to_audio_frames are thin wrappers around it, and it is a util header, so it belongs in obs-util, not obs-media-io. It doesn't touch the obs-media-io files, so it can be open alongside the others without counting toward your two-PR limit.
    3. audio-io.h inlines + structs.
    4. audio-math.h: keep it separate or fold it into 3, whichever you prefer.
    5. video-frame.c.
    6. format-conversion.c.

    video-frame.c doesn't need item 1, and format-conversion.c doesn't include video-frame.h or call into it. The order above is just to limit conflicts, so swap them if that's more convenient.

    Header-inline units (1-4)

    Your reading of the exemption is right: a layout test for every public struct, the unchanged C tests passing OFF and ON, no symbol swap, and the header left alone. Tier 1 and Tier 3 still apply, against oracle_* wrappers. Please still land the cmocka characterization test first. Tier 1 needs a C test to port 1:1, and without one, "unchanged C tests pass OFF/ON" doesn't check anything.

    • Item 1 structs: video_data, video_output_info, video_scale_info, media_frames_per_second. Also add enum video_trc and enum video_scale_type to video_io.rs, with size/align/enumerator checks like rust: Port media-io/video-matrices.c to obs-media-io #106 did for colorspace and range. video_output_info has a pointer and a size_t, so take the offsets from the oracle rather than hardcoding them.
    • get_video_format_name returns "v210" and "R10l" (not all upper case), and every out-of-range value goes to the default result (false / "None" / "Unknown" / "Partial"). Parity should cover values outside the enums as well, through *_from_c returning None.
    • frame-rate.h has no includes of its own. The oracle wrapper has to include c99defs.h first. A zero numerator or denominator gives inf or NaN, and parity compares those bit for bit too.
    • util_mul_div64 does different math on different platforms. MSVC x64 uses _umul128/_udiv128, which is exact 128-bit math. Every other platform uses (num / div) * mul + (rem * mul) / div with u64 wrapping. The results differ once rem * mul overflows. The Rust code has to match each platform: a u128 path under cfg(all(target_env = "msvc", target_arch = "x86_64")) and wrapping_* everywhere else. Exclude, and list, div == 0 (UB on both paths) and, on MSVC, quotients ≥ 2^64 (_udiv128 faults).
    • audio-math.h is header-inline too and defines no struct, so its Tier 2 is just the C test passing OFF/ON. It's scalar, so Tier 3 is exact bit equality per the Phase 5 rule, with no ULP tolerance. log10f/powf come from the platform libm, which is the same libm on both sides of the parity test, so exact bits are achievable. Keep the cmocka test to portable values, though: exact cases like 0 and -0.0 → -inf, 1 → 0, db_to_mul(0) → 1, ±inf/NaN → 0, a negative input → NaN, and a tolerance for everything else, because glibc, UCRT and libSystem differ in the last bit. Keep 10.0f32.powf(db / 20.0) as written. If you hit a last-bit mismatch, check whether one compiler rewrote pow(10, x) into exp10 before suspecting anything else.

    video-frame.c

    • In the same PR, include video-frame.h's inlines (video_frame_free / _create / _destroy) and the struct video_frame layout test, under the header-inline rule.
    • bmalloc and base_get_alignment are already Rust, so nothing blocks this.
    • video_frame_get_linesizes / video_frame_get_plane_heights aren't static, but they have no header declaration and no caller outside video-frame.c, and libobs builds with hidden visibility. Keep them in the safe core with no C symbol. Only video_frame_init and video_frame_copy go in rust-exports.txt.
    • Characterize, not endorse: the V210 case calls align_uint32(&width, 48), but ALIGN masks with ~(alignment - 1), which only works for powers of two. Width 1 aligns to 16 (linesize 48), width 47 aligns to 80 (224), and width 1280 gives 3424 instead of 3456. It never comes out smaller than the width, so nothing overruns. Port it as is. Fixing it would be a separate C change with its own RED test.
    • A zero-size frame (VIDEO_FORMAT_NONE, an out-of-range format, or width/height 0) ends in bmalloc(0), which bcrashes. Leave those out of the cmocka test and list them as parity exclusions.
    • The u32 math has to wrap like C does: width * 4, HALF(UINT32_MAX) = 0, and the u32 linesize * heights length in video_frame_copy.

    format-conversion.c

    • Its SIMD is SSE2 integer only, with no float. The ULP allowance in the policy covers float SIMD (vec3/vec4/matrix4), so this one is exact byte equality. Write a scalar safe core with no core::arch. Each lane works out to plain integer math: luma and chroma byte extraction, and chroma averaged as (a + b + c + d) >> 2.
    • The oracle's sse-shim/simde/x86/sse2.h only defines the float __m128 ops for non-x86. Including format-conversion.c in the oracle will fail on the macOS arm64 Rust job unless you add the __m128i ops it uses, lane by lane: _mm_set1_epi32/epi16, _mm_and_si128, _mm_srli_si128, _mm_packs_epi32, _mm_packus_epi16, _mm_add_epi64, _mm_shuffle_epi32, _mm_shufflelo_epi16, _mm_srai_epi16, _mm_load_si128, and __m128i itself.
    • _mm_load_si128 is an aligned load. The UYVX functions also step 4 pixels and 2 rows at a time, reading row y+1. Generate 16-byte-aligned input with in_linesize % 16 == 0, widths that are multiples of 4, and even row ranges. Inputs outside that read or write past the line in C, so exclude and list them.
    • Fill output buffers with a canary pattern and compare the whole buffer, so writes outside the expected area also show up as mismatches. decompress_* stores native-endian uint32_t, so use to_ne_bytes.
    • Nothing in the tree calls these six functions. They're exported API only, so your characterization test is the only Tier 2 coverage.

    Not taking yet

    I agree on video-io.c / audio-io.c. Besides profiler.c, they call obs_get_profiler_name_store() in obs.c, plus the scaler and resampler, so they aren't leaf units.

    On the FFmpeg wrappers, I agree that a pure-Rust replacement would be a behaviour change, not a port. But the wrappers don't need porting for video-io/audio-io to be ported: a Rust video-io can call video_scaler_* / audio_resampler_* through their existing C API. ffmpeg-sys-next would add an FFmpeg build dependency to the Rust workspace and to every rust-tests job, for very little gain. Leave the wrappers in C. If you still want them later, write it up under ## Decisions here first.

  5. swilk19 commented on Oct 11, 2026

    @swilk19
    Contributor

    The media-io part 2 plan approved above (#45 (comment)) is done. All six units are merged:

    1. video-io.h inlines + frame-rate.h: rust: Port media-io video-io.h and frame-rate.h inlines to obs-media-io #114
    2. util/util_uint64.h (util_mul_div64) in obs-util: rust: Port util/util_uint64.h (util_mul_div64) to obs-util #122
    3. audio-io.h inlines + structs: rust: Port media-io audio-io.h inlines + structs to obs-media-io #129
    4. audio-math.h: rust: Port media-io/audio-math.h to obs-media-io #179
    5. video-frame.c (+ video-frame.h inlines): rust: Port media-io/video-frame.c to obs-media-io #182, closes rust: Port media-io/video-frame.c to obs-media-io #151
    6. format-conversion.c: rust: Port media-io/format-conversion.c to obs-media-io #184, closes rust: Port libobs/media-io/format-conversion.c to obs-media-io #183. The oracle's sse-shim now has the __m128i integer ops. Parity also runs them on x86 against native SSE2, through a second oracle build with OBS_ORACLE_SCALAR_SSE.

    Still open in media-io, and not claimed by me:

    • audio-io.c and video-io.c: the stateful core. As agreed above, these aren't leaf units, because they call profiler.c, obs_get_profiler_name_store() in obs.c, and the scaler/resampler. test: characterize audio-io.c before media-io port #120 has the audio-io characterization test (draft).
    • The FFmpeg wrappers stay in C, as decided above.

    Thanks for the reviews, rebases and merges.

    From here on, I'll file and claim a separate issue for each unit, as docs/rust-port/coordination.md describes, instead of claiming items here.

  6. nathan-v commented on Oct 12, 2026

    @nathan-v
    Contributor

    Claiming: libobs/graphics/math-extra.c

    1. Characterization commit: test/cmocka/test_math_extra.c pins the current exports. Header-inline get_percentage and get_percentagei stay C. The test does not read w after polar_to_cart or a non-zero cart_to_polar (that lane is uninitialized in C).
    2. RED: Tier 1 tests against empty stubs (zero vectors and 0.0).
    3. GREEN: safe core, C shims, Tier 3 parity against obs-c-oracle, ENABLE_RUST_LIBOBS drops graphics/math-extra.c, export fragment libobs/cmake/rust-exports.d/obs-graphics-math_extra.txt. Remove the oracle's unrenamed rand_float host so the Rust shim provides it for vec3_rand.
  7. nathan-v commented on Oct 13, 2026

    @nathan-v
    Contributor

    Claiming: libobs/media-io/video-io.c (characterization + port)

    1. Characterization PR, no Rust: test/cmocka/test_video_io.c pins open/close, invalid params, getters, connect/disconnect, lock/unlock delivery, the frame-rate divisor, a full cache, texture-encoder refcounts, and the shallow video_output_create_with_frame_rate_divisor copy. test_video_io_inlines.c stays as it is. Odd cases are marked characterized, not endorsed.
    2. Port PR, RED: Tier 1 copies those assertions onto todo!() stubs in obs-media-io.
    3. GREEN: safe core, C shims, Tier 3 parity against the C file, and ENABLE_RUST_LIBOBS drops media-io/video-io.c. video_scaler_* stays the FFmpeg C file. close on a divisor child stops the root and frees only the child; the C path frees the parent's cache and mutexes too.
    4. First PR today.

    Please add the claimed label. I cannot.

    Refs #45

  8. 9 remaining items

  9. nathan-v commented on Oct 14, 2026

    @nathan-v
    Contributor

    Claiming: the Windows half of libobs/media-io/audio-io.c.

    Tracked in #728. The Unix port stays as it is. Please add the claimed label on #728; I cannot.

  10. nathan-v commented on Oct 15, 2026

    @nathan-v
    Contributor

    audio-io port landed in #745 (1b61353). #728 is closed. I can't edit this checklist.

  11. zackees commented on Oct 25, 2026

    @zackees
    MemberAuthor

    Triage (coordinator): tracker. #148-#151 are closed but unchecked here; the open items (plane, bounds, math-extra, video-frame/video-io/audio-io follow-ups) have no issues of their own, so there are no children to attach as sub-issues. Suggest: tick the closed ones and file one issue per remaining item when someone is ready to claim it (as #153 says).

  12. zackees commented on Oct 30, 2026

    @zackees
    MemberAuthor

    Triage on current master: this tracker is already implemented; its checklist was not updated after the ports landed.

    Evidence:

    No source changes are required. I did not rerun Tier 4 here because it requires a full OBS build plus Xvfb; this triage run verified its checked-in suite and prior completion evidence.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions