Skip to content

rust: Port the video output conversion plan in obs.c to obs-core #1713

Closed

Description

@rdoupe

Unit

Port the video output conversion plan of libobs/obs.c.h to a new crate, rust/obs-core, as a module video_plan. It is the pure computation that obs_reset_video() and the per-canvas video mix setup run before they touch the graphics device: what output size is accepted, how the output size is aligned, and, for each output format and color space, the GPU conversion (the shader technique names and the texel sizes), the size and gs_color_format of each conversion plane, and the format and color space of the render textures.

From libobs/obs.c.h:

  • calc_gpu_conversion_sizes() (format x colorspace -> three technique names, conversion_needed, conversion_width_i, conversion_height_i);
  • the per-format plane table inside obs_init_gpu_conversion() and obs_init_gpu_copy_surfaces() (each plane's width, height and gs_color_format: GS_R8/R8G8 for 8-bit, GS_R16/RG16 for the 10/16-bit formats, chroma divided per subsampling);
  • the render-texture format (GS_BGRA, or GS_RGBA16F for the high-precision formats) and color space (GS_CS_709_EXTENDED for PQ/HLG, GS_CS_SRGB_16F for the SDR 16-bit formats, else GS_CS_SRGB) of obs_init_textures();
  • size_valid() with OBS_SIZE_MIN/MAX, the output-size alignment masks of obs_reset_video_internal(), and the scale-type name switch of its log.

About 170 lines. All of it is our code (the conversion rebind chain #1109/#470, the HDR formats #1565). It is pure: the inputs are a video_format, a video_colorspace and the width and height; the output is a by-value plan struct. The gs_texture_create/gs_stagesurface_create calls, the NV12/P010 texture decision (which asks the device), graphics init, mix creation, canvases, encoder rebinding, logging and obs_init_video() stay C.

Phase and position

Phase 6 (#444), libobs core through opaque seams. libobs/obs.c.h is one of our modified files and has no Rust yet, so this unit starts a new crate. It is part of a very large file, so it enters through function extraction (testing-policy.md, "Extracting a function before porting it"), as the caption text, the interleaver and the hotkey units did. Its Rust tests join the new crate's tests/ harness; no new C test binary.

Crate name

Coordinator decided on #444 (2026-10-20) that a libobs area gets one crate named after it, with a module per extracted file, and that per-file crates (obs-scene-bounds, obs-scene-blend) are the exceptions to fold away. By that rule libobs/obs.c.h's pieces belong in one crate for the libobs core. naming.md's table maps each top-level file to its own obs-<area> crate (obs-data, obs-properties, obs-output, obs-scene), so the natural name for obs.c.h is rust/obs-core, with later obs.c.h units joining it as modules. This is a layout question, not a design one; this plan uses rust/obs-core and adds the naming.md row in PR 2 (the port). If the coordinator wants another name (for example obs-video split out later), say so on the claim comment before PR 2 lands; PR 1 adds no crate, so it does not depend on the answer.

What to ask on the claim comment: "Starting libobs/obs.c.h: PR 1 is a behaviour-neutral C extraction (no crate). The port (PR 2) wants a crate; by the #444 one-crate-per-area rule I will use rust/obs-core for obs.c.h, later obs.c.h units joining it as modules, unless you would rather carve obs-video out now."

Dependencies and existing tests

  • It writes struct obs_core_video_mix fields conversion_techs[3], conversion_needed, conversion_width_i, conversion_height_i, and feeds the gs_texture_create/gs_stagesurface_create and render-texture calls. No accessor is needed: the moved C returns struct obs_video_output_plan by value (declared in obs-internal.h, not EXPORT), and obs.c copies the techniques and sizes into the mix and creates the textures and surfaces from planes[].
  • The technique names are read later by obs-video.c.h (render_convert_texture), so they are 'static NUL-terminated strings that must match libobs/data/format_conversion.effect exactly.
  • Enum values (video_format, video_colorspace, gs_color_format, gs_color_space, obs_scale_type) come from the public headers (obs-sys bindings).
  • About 70 real-libobs tests call obs_reset_video(), but their output formats are only NV12 (52), BGRA (15) and RGBA (3). I420, I444, I010, P010, P216, P416 are covered by nothing. test_texture_encoder_raw_format and test_scaled_mix_alpha come closest. PR 1 adds both a pure characterization that pins the plan for every format, color space and edge size, and a real-libobs test that runs obs_reset_video() once per output format and checks the frames.

Plan

  1. Extraction and characterization PR (behaviour-neutral, as in libobs: Move the caption text wrap into obs-output-caption-text.c #1618/libobs: Move the hotkey key-name translations into obs-hotkey-translations.c #1657):
    • The functions above move verbatim from obs.c.h into libobs/obs-video-plan.c.h, which exposes one entry point, struct obs_video_output_plan obs_video_output_plan(format, colorspace, width, height), plus obs_video_size_valid(), obs_video_align_output_size() and obs_video_scale_type_name(). They are declared in obs-internal.h without EXPORT, so they are hidden; obs.c calls them. The new file joins the existing libobs.core unity group (just before obs.c.h, alphabetical), with libobs.pch.h. The exported symbols are unchanged.
    • New test test_video_output_plan, which compiles the moved file into itself (C only, ASan and UBSan, no libobs core and no display). It pins the plan for every video_format (and one past the end), every video_colorspace (and one past), odd and even sizes, the minimum (2), the 1366-that-aligns-to-1364 case and the maximum (32768), comparing every field; the size check at its edges; the alignment masks; and the scale-type names. The width-2/3 edge (bug 4 below) is pinned here as "characterized, not endorsed".
    • New test test_video_output_formats, which links the real libobs and its OpenGL renderer and runs obs_reset_video() once per output format with a GPU conversion (I420, NV12, I444, I010, P010, P216, P416, each with its color spaces and both ranges) and BGRA/RGBA, checking each frame's plane sizes and sample values (so a wrong plane size or technique shows). It also checks the output-size alignment through obs_get_video_info() (1366 -> 1364) and that an out-of-range size is refused before the old video is freed. It uses the public API only, so with the hybrid libobs it covers the Rust port once there is one. Linux only (needs a display; skips without one, under xvfb-run).
  2. A C fix for bug 4, and bug 6 (RED, then GREEN; see below for reachability). size_valid() accepts an output width of 2 or 3, and the alignment then masks it to 0. Validate after the alignment (or lift the minimum to 4 for the output width), so obs_reset_video() refuses it with OBS_VIDEO_INVALID_PARAM before it frees the old video, instead of failing with no video. It gives API callers a new return code, so it is its own PR with a test change.
  3. Port PR (RED, then GREEN):
    • obs_core::video_plan gets the safe core (the enum lookups and the 1.f / (float)w reciprocals), and src/ffi/video_plan.rs the C ABI shim returning struct obs_video_output_plan. The C file moves to its own ported group, libobs.ported-video-plan, with its own .pch.h, source-sets.json entry and export fragment (rust-exports.map, rust-hidden.txt, rust-unexports-macos.txt).
    • Parity: an exhaustive oracle over every enum value (there are few) and a proptest over sizes, comparing the floats bit for bit. Tier 2 with OBS_LIBOBS_BACKEND=C and HYBRID + libobs-c-reference unchanged; test_video_output_formats sees the swap. Tier 4 does not apply.
    • Docs: the new rust/README.md row and the docs/rust-port/naming.md row (libobs/obs.c.h -> rust/obs-core).

Bugs found while reading (characterized, not fixed in PR 1)

  • Bug 4 (output width 2 or 3). size_valid() (OBS_SIZE_MIN 2) accepts an output width of 2 or 3, and obs_reset_video_internal() then masks the width to a multiple of 4, which gives 0. The 0-wide video_output_open() fails, but by then obs_reset_video() has freed the old video, so the call returns with no video at all, and a later reset of that core crashes. Only API/script callers can reach it: the Settings dialog minimum is 32, obs-websocket SetVideoSettings requires >= 8. Characterized in test_video_output_plan (the size check passes, the alignment makes 0); PR 2 validates after the alignment. Severity: low.
  • Bug 6 (pthread_mutex_init(...) < 0). obs_init_video() checks pthread_mutex_init(...) < 0 for its three mutexes. pthread returns a positive errno on failure, so a failure is never caught. Cosmetic/robustness; fix alongside bug 4 or in a small follow-up, as != 0. Severity: very low.

Activity

  1. rdoupe commented on Oct 22, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #1713

    1. Characterization and extraction PR: the per-format plan moved into libobs/obs-video-plan.c.h (behaviour-neutral, no crate), with test_video_output_plan (pure, every format and colorspace) and test_video_output_formats (real libobs). Opening it now.
    2. A C fix for the output-size validation and the pthread_mutex_init check.
    3. The port. By the meta: Phase 6 libobs core migration through opaque C seams #444 one-crate-per-area rule I'll use rust/obs-core for obs.c.h, with later obs.c.h units joining it as modules, unless you'd rather carve out an obs-video crate now.
  2. added
    claimed
    on Oct 22, 2026
  3. zackees commented on Oct 22, 2026

    @zackees
    Member

    Observed Windows Tier2 build blocker in #1269's defined full experiment on446a12945 (base9f2253334, which includes #1714). Job119662888783 completed FAILURE before CTest:

    test_video_output_plan.obj : error LNK2019: unresolved external symbol cm_print_error referenced in function check_plan
    ...test_video_output_plan.exe : fatal error LNK1120: 1 unresolved externals
    

    test/cmocka/test_video_output_plan.c:220 uses fail_msg in check_plan; additional fail_msg sites are416/444. #1580 documents the same cmocka diagnostic-symbol link contract for a different test, fixed in #1591 via fprintf(stderr,...) plus plain fail while retaining all conditions/arguments/assertions. #1580 itself is CLOSED/resolved and is not reopened by this distinct test regression. #1714 introduced this test (07988d6).

    Please address under the existing #1713 ownership with focused RED→GREEN diagnostic-link coverage and real Windows Tier2. This is evidence/coordination, not a claim of #1713 or a proposal to weaken assertions. My #1269 branch changes no existing C test/public header or WebSocket plugin. No workflow retry or guessed source fix. The full experiment remains live; its Flatpak probe result is a separate observation.

  4. rdoupe commented on Oct 22, 2026

    @rdoupe
    CollaboratorAuthor

    Windows link fix for test_video_output_plan is up in #1743. #1741 converted three of the four fail_msg() calls, but the one in output_size_check_edges (from #1734) is still on master, so the Windows link still fails. #1743 converts it (fprintf(stderr) + fail(), same as #1591) and adds a CI check that catches fail_msg() in any cmocka test Windows builds. It carries ci-full so the Windows Tier 2 run proves the link.

  5. removed
    claimed
    on Oct 24, 2026
  6. zackees commented on Oct 24, 2026

    @zackees
    Member

    Claiming: the last part of #1713, rejecting fps 0 (#1773 left it out). obs_reset_video() passes fps_num to util_mul_div64 as the divisor (obs.c.h:471) without checking it. Plan: (1) RED: a cmocka test that calls obs_reset_video with fps_num 0 and with fps_den 0 and expects OBS_VIDEO_INVALID_PARAM; (2) GREEN: reject both next to the existing size checks. Then close #1713. PR within the hour.

  7. added
    claimed
    on Oct 24, 2026
  8. zackees commented on Oct 24, 2026

    @zackees
    Member

    Closed by #2174: obs_reset_video() now refuses a zero fps_num or fps_den with OBS_VIDEO_INVALID_PARAM before teardown (test_video_reset_fps). With #1714, #1734, #1743 and #1773 that completes this unit; nothing left.

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

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions