Skip to content

obs-output: port obs_output_get_video_conversion to Rust (#6104) - #6106

Merged
zackees merged 6 commits into
obs-rust:masterfrom
KelboLive:port/6104-output-conversion
Dec 3, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
KelboLive:port/6104-output-conversion

Conversation

@KelboLive

@KelboLive KelboLive commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Unit

obs_output_get_video_conversion() from libobs/obs-output.c.h (~39 lines). Free: the open PRs on this file touch encoder setters/start-stop/audio/service in separate hunks. Already characterized in test/cmocka/test_output_input_checks.c. Closes #6104.

Function

const struct video_scale_info *obs_output_get_video_conversion(struct obs_output *output)

  1. log_flag_encoded(output, __func__, true) || !log_flag_video(output, __func__) → NULL.
  2. Build obs_output_conversion_sizes from video_conversion_set, the current video_conversion.width/height, scaled_width/height and video_output_get_width/height, then ask the already-ported obs_output_conversion_plan().
  3. SET: write the plan's width/height into output->video_conversion and return its address.
  4. SCALED: video_output_get_info(); NULL (scaled size but no video) → NULL; else write format, VIDEO_CS_DEFAULT/VIDEO_RANGE_DEFAULT, plan width/height, return the same address.
  5. Other kinds: NULL, no writes. The returned pointer is the output's own field, never a copy.

Design

  • Verbatim extraction: the function moves to libobs/obs-output-get-video-conversion.c.h (original body unchanged), with the two log_flag_* inlines copied into -support.c.h for the isolated reference unit; obs-output.c.h keeps its own copies for its other callers. The C reference group libobs.ported-output-video-conversion compiles the extraction; the hybrid group swaps in the adapter.
  • Safe core rust/obs-output/src/video_conversion.rs with a Host trait for the flag gates, the size reads, the plan and the in-place writes.
  • Private adapter obs-output-get-video-conversion-fields.c.h: the private layout, both warning lines, the read/write fields and the field address.
  • FFI ffi/get_video_conversion.rs; export fragment obs-output-get_video_conversion.txt; rust/README.md and naming rows; native registration test.
  • Link support test/cmocka/output-video-conversion-link-support.c + tests.d/output_video_conversion_link_support.cmake.

Tests

  • Tier 1 output::output_video_conversion (obs-tests-core): the cmocka cases plus pointer identity, NULL video with a scaled size, no side effects for other plan kinds, and the flag-gate log lines.
  • Tier 3 output::output_video_conversion_parity: original C vs shim with identical fixtures, comparing the returned pointer, every conversion field, the video-info lookups and exact log lines; a mutation (set-plan width/height swapped) failed both parity tests.
  • Tier 2 is the unchanged test_output_input_checks on hybrid libobs and libobs-c-reference.

Verification

  • RED: 7 failed on todo!(); GREEN focused 9 passed, 0 failed.
  • Full obs-tests-core: 7968 passed, 0 failed, 5 ignored.
  • Export-list guard (4 passed), registration test (1 passed), port-metadata and build-group guards pass.
  • cmake --build --preset windows-x64: success (the hybrid unity group with the adapter include).
  • lint: ok.

Unverified on this Windows host (CI covers them): the cmocka Tier 2 run and its link-support fragment (tests disabled in the local preset), the explicit OBS_BUILD_C_REFERENCE=ON build, and linux-validate.

Fixes #6104.

Test cost: new tests: longest 0.01 s, peak RSS 5 MB, no own threads (10 tests added as modules of the existing obs-tests-core binary; no new test executable).

Add the safe core for obs_output_get_video_conversion() as a todo!()
stub and its Tier 1 tests in the core category binary. They port
test_output_input_checks' conversion_with_video, conversion_no_video_*
cases over a model output, plus the pointer identity (the answer is the
output's own video_conversion), the plans that must write nothing, and
the two flag warnings that test cannot see.

Refs obs-rust#6104.
Extract obs_output_get_video_conversion() verbatim from obs-output.c.h
into its own unit, keep it for the C reference in the ported group
libobs.ported-output-video-conversion with the original flag helpers, and
swap hybrid libobs to the Rust shim.

The safe core refuses an encoded output (log_flag_encoded with
inverse_log) and then a non-video one, in the C's short-circuit order,
builds obs_output_conversion_sizes from the set conversion, the scaled
size and the video's size, and asks the ported conversion plan. A set
plan writes its planned width and height. A scaled plan writes the
video's format with VIDEO_CS_DEFAULT/VIDEO_RANGE_DEFAULT and the planned
size, but a scaled size with no video returns NULL and writes nothing
(obs-rust#2127). Any other plan writes nothing. Every success is the address of
the output's own video_conversion, never a copy.

The private layout, the warnings, the video's size and info and every
write stay in C behind obs-output-get-video-conversion-fields.c.h; the
shim takes the sizes from obs-media-io's Rust video queries. Register the
export fragment, the core group's adapter and the registration contract.

Tier 3 runs the original C and the shim on one real-header output: the
returned pointer, every conversion field, the whole output and the exact
warnings over the flags, a live and a NULL video, stored conversions and
scaled sizes. A deliberate width/height swap in the set plan kills both
parity tests. The full core category binary passes (7968 tests).

Refs obs-rust#6104.
…ic tests

Every test_* target linking libobs_rust-static can pull the
obs_output_get_video_conversion shim into unrelated source-step tests,
so attach the real private-layout adapter next to the test sources, as
the device-queries and viewport link support do. The exec fragment is
discovered by the existing tests.d glob; no graph or shared list changes.

Refs obs-rust#6104.
@KelboLive
KelboLive requested a review from zackees as a code owner December 3, 2026 14:49
@KelboLive KelboLive changed the title test(cmocka): link the output video conversion adapter into Rust-static tests obs-output: port obs_output_get_video_conversion to Rust (#6104) Dec 3, 2026
The standalone adapter's fields header only forward-declares the flag
readers, so the link-support translation unit now includes the support
header that defines them (MSVC C2129, undefined at link elsewhere).

Link the adapter as its own lazy static archive, like the device-query
and viewport link support, instead of compiling it into every test
target that links libobs_rust-static.

The parity probe compares the conversion field by field rather than by
memcmp over the whole struct, whose padding is unspecified, and plants a
mutant that skips the video-info NULL check so the Tier 3 claim is held
by a test.

Refs obs-rust#6104.

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: LGTM. It ports obs_output_get_video_conversion with Tier 1 and Tier 3 coverage. The two new memcmp calls compare the output object with a byte snapshot of itself outside the field under test, so padding matches by construction and #6035 isn't repeated. No existing C test, oracle stub or public header is touched, it has a Test cost line, and it merges cleanly. I've approved the held runs. Auto-merge on.

@zackees
zackees enabled auto-merge December 3, 2026 18:13

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: clean port of obs_output_get_video_conversion preserving C field-address return and scaling/flag ordering, FFI adapter, rust-exports.d, Tier 1/3 parity tests, RED→GREEN commits, and Test cost. Held CI runs approved.

@zackees

zackees commented Dec 3, 2026

Copy link
Copy Markdown
Member

Pushed mechanical fixups 0ad3d3c5b + e562d54ee:

  • Declared oracle_obs_output_get_video_conversion prototype in rust/obs-c-oracle/oracle/output_get_video_conversion.c (fixes macOS -Wmissing-prototypes).
  • Added ${CMAKE_BINARY_DIR}/config to target_include_directories in test/cmocka/tests.d/output_video_conversion_link_support.cmake so output-video-conversion-link-support.c finds obsconfig.h.
    Both formatted with clang-format / gersemi.

@zackees
zackees added this pull request to the merge queue Dec 3, 2026
Merged via the queue into obs-rust:master with commit c38a5d0 Dec 3, 2026
51 checks passed
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rust: Port obs_output_get_video_conversion to obs-output

2 participants