Skip to content

obs-source: port obs_source_video_render and its source_render_video, source_draw_route and get_type_format steps to Rust (Fixes #5962) - #5963

Merged
zackees merged 3 commits into
masterfrom
port/5962-video-render
Nov 29, 2026
Merged

zackees merged 3 commits into
masterfrom
port/5962-video-render

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5962.

This ports obs_source_video_render() and its three static steps, source_render_video(), source_draw_route() and get_type_format(), to obs-source, in the shape of #5943 and #5954. It is the call every scene item, projector and preview makes to draw a source: check the source, hold a reference, run the async update (and the deinterlacer's), skip a disabled or inactive source, then draw through the filter chain, the main render, the filter target, the deinterlacer or the async frame. The route decision was already Rust (render_route::draw_next()); what moves now is the glue: the reference, the field reads in order, and the one draw.

What changes

  1. Extraction, no behavior change (libobs: extract obs_source_video_render and its steps verbatim). The four functions move unchanged into libobs/obs-source-video-render.c.h (live group libobs.core-source). The two static draws they call, obs_source_render_filters() and obs_source_main_render(), are reached through hidden wrappers in obs-source.c.h; deinterlacing_enabled() is a file-local copy, as obs-source-skip-video-filter.c.h does. The registration tests of the async update and draw ports now find their caller in the new file. The new cmocka test_source_video_render characterizes it through the real libobs, rendering inside the graphics context: NULL (one LOG_DEBUG line), a plain source (one main render, one more reference held), a source being destroyed, no OBS_SOURCE_VIDEO, disabled, no video_render and no frame, one filter (filter first, rendering_filter set on its parent), a disabled filter, a filter without video_render, two filters, an async frame, and the deinterlacer with Discard.
  2. Tier 1, RED: the safe core's Host trait and todo!() steps, with 18 Tier 1 tests over a recording model of four sources, including every combination of type and ten fields drawing at most once and giving back every reference.
  3. GREEN: the safe core in obs-source::video_render, the export in obs-source::ffi::source_video_render (rust-exports.d, it is public API), one-access adapters in libobs/obs-source-video-render-fields.c.h, and the original moved to the reference-only group libobs.ported-source-video-render. Debug markers stay off as in the C (GS_USE_DEBUG_MARKERS 0, pinned by a _Static_assert). Tier 3 in obs-c-oracle (oracle/source_video_render.c) runs the original C against the Rust export on four noise-filled real-layout sources over shared stand-ins; clobbers flip enabled, context.data, filters.num, rendering_filter, video_render, filter_target, the deinterlace mode and filter_parent mid-call. It compares the call log (with references held and every node's rendering_filter), the references left and every byte over a grid and a proptest, pins the logs of the C test's cases, and rejects eleven mutants. The view oracle's own obs_source_video_render() double, now a duplicate symbol, becomes oracle_view_render_step().

No intentional differences. The rust/README.md row is added; no user-visible change, so no docs/features.md line.

Evidence

RED, at the RED commit:

soldr cargo test -p obs-data --test obs-tests-core video_render::
test result: FAILED. 1 passed; 17 failed
(not yet implemented: obs_source_video_render / source_render_video / source_draw_route / get_type_format;
 the_marker_is_off_as_in_the_c passes, it checks a constant)

GREEN, at the head (rerun after rebasing on master f2cd9f7):

soldr cargo test -p obs-data --test obs-tests-core video_render
test result: ok. 32 passed; 0 failed   (Tier 1 + Tier 3 grid, proptest, pinned logs, 11 mutants rejected)

soldr cargo test -p obs-studio-rust --test obs-tests-app canonical_source
test canonical_source_video_render_swap_is_registered ... ok
test result: ok. 71 passed; 0 failed

Tier 2, test_source_video_render in the linux-validate build volume (xvfb-run -a), against both libraries, at the extraction commit and at the head: 12/12 passed on the hybrid libobs and on the C reference; the existing render tests pass too.

OBS_CMOCKA_LINK=false uv run --no-project ci/windows_link_check.py links every test binary. ./lint passes.

Test cost

new tests: longest 0.24 s wall for all 32 together (debug, filtered binary), peak RSS 52 MB (the whole cargo test process), no own threads. The new cmocka test takes a few seconds per library.

🤖 Generated with Claude Code

rdoupe and others added 3 commits November 29, 2026 16:38
…5962)

Move obs_source_video_render() and its three static steps,
source_render_video(), source_draw_route() and get_type_format() (debug
markers only), out of obs-source.c.h into obs-source-video-render.c.h
(live group libobs.core-source), unchanged. The two static draws they
make, obs_source_render_filters() and obs_source_main_render(), are
reached through new hidden wrappers in obs-source.c.h, mapped onto their
original names for this file, and deinterlacing_enabled() is a
file-local copy, as obs-source-skip-video-filter.c.h does. The async
update and draw keep their declarations (no EXPORT). The registration
tests of the async update and draw ports now find their caller in the
new file. No behavior change.

The new test_source_video_render characterizes them through the real
libobs, rendering on the test thread inside the graphics context: a NULL
source logs one LOG_DEBUG line; a plain source draws once through its
main render holding one more reference; a source being destroyed (refs
at -1) draws nothing; nothing for a source without OBS_SOURCE_VIDEO, a
disabled one, or a video source without video_render and no frame; with
a filter, the filter first (rendering_filter set on its parent, two more
references) then the parent; a disabled filter skips to the parent; a
filter without video_render draws its target; two filters draw down the
chain; an async source draws its frame, and through the deinterlacer
with Discard one field only. 12/12 against hybrid and the C reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#5962)

The safe core's Host trait (the validity check, obs_source_get_ref() and
obs_source_release(), info.type, info.output_flags, filter_parent,
obs_source_skip_video_filter(), rendering_filter, the deinterlace mode,
deinterlace_update_async_video(), obs_source_update_async_video(),
context.data, enabled, filters.num, info.video_render, filter_target,
the five draws and the debug marker) and todo!() steps, with 18 Tier 1
tests over a recording model of four sources: NULL only checked; a
source being destroyed not drawn; a plain input's main render inside its
reference; no video (a filter with a parent skips); a filter never
reading its flags; scenes and transitions reading their flags once; the
async update, with the deinterlacer, and not while its filters draw;
without data enabled not read; disabled (a filter skips); each route's
reads in order and only when asked; each route's one draw (the target
read twice); the type formats of get_type_format(); the marker bracket
with markers on; the filter chain and the target drawing through the
core again (the model recurses), and over every combination of type and
ten fields at most one draw and every reference given back.

  soldr cargo test -p obs-data --test obs-tests-core video_render::
  test result: FAILED. 1 passed; 17 failed (not yet implemented:
  obs_source_video_render / source_render_video / source_draw_route /
  get_type_format); the_marker_is_off_as_in_the_c passes (a constant).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Fixes #5962)

The safe core in obs-source::video_render: obs_source_video_render()
checks the source with obs_source_valid() (its LOG_DEBUG line for NULL),
then runs source_render_video() between obs_source_get_ref() and
obs_source_release(), and draws nothing when no reference can be taken.
source_render_video() reads the type, and the output flags unless it is
a filter, for the "no video" check (a filter with a parent skips
itself); the type and the flags again for the async check (flags only
for an input), rendering_filter only for an async input, then
deinterlace_update_async_video() (deinterlacing on) and
obs_source_update_async_video(); context.data, and enabled only with
data, for the inactive check (a filter with a parent skips); then the
debug marker bracket (only with GS_USE_DEBUG_MARKERS, 0:
video_render::DEBUG_MARKERS, checked by a _Static_assert) around the one
draw source_draw_route() picks, reading filters.num, rendering_filter,
video_render, filter_target and the deinterlace mode one at a time and
only when render_route::draw_next() asks: the filter chain, the main
render, the filter target (read again for the draw), the deinterlacer or
the async frame. type_format() is get_type_format().

The export is in obs-source::ffi::source_video_render (rust-exports.d),
with one-access adapters for the check, the reference, the fields, the
skip, the updates, the draws and the marker in
libobs/obs-source-video-render-fields.c.h (live group
libobs.core-source, no EXPORT); the two static draws through the hidden
wrappers in obs-source.c.h. The extracted original moves to the
reference-only group libobs.ported-source-video-render.

Tier 3 in obs-c-oracle runs the original C (with the oracle's original
route) against the Rust export on four noise-filled real-layout sources
over shared stand-ins of the check, the reference, the skip, the updates
and the draws; the filter chain's stand-in sets rendering_filter around
the first filter's render and, like the filter target, draws through
each side's own entry again. Clobbers flip enabled, context.data,
filters.num, rendering_filter, video_render, filter_target, the
deinterlace mode and filter_parent in the async update, and the mode in
the deinterlace update. It compares the log (with the references held
and every node's rendering_filter), the references left and every byte
over a grid of types, flags and node states and a proptest, pins the
logs of the C test's cases, and rejects eleven mutants. The view
oracle's obs_source_video_render() double, now a duplicate of the
export, becomes oracle_view_render_step(), which the new validity
stand-in calls for a source no fixture holds. test_source_video_render
passes 12/12 against the hybrid and the C reference, as do the existing
render tests. No intentional differences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ci-Attestation: {"at":1795989058,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":76,"stamp":"8468044070aff3e039cc33c37ee5e274","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795989058,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":76,"stamp":"2e05c8871106d2bcbb7ac5ca852e0319","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795989058,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":76,"stamp":"ffc5cf0eda97a67eacc280ecba5c17fa","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795989058,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":76,"stamp":"8a57a3389c00a3c016f05aa940b4d20e","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"general/all/client-lint","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"5a1c9e45e998b94c75aa41193f9f6c2f","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795989058,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":76,"stamp":"9086fe6019b65489463991ca2d119654","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"8e317b0bd86dd1ecba1a776ae661969f","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"91a58f3a08c0b6348fc04bd7c0e9c34e","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"8b4205b8b3c154f16730f924f03b37b0","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"faa62f6b9df6223074dd423c02634b2c","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"823f8ab4b3163f39baadd57b402bd1b9","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"e3653b4013224b9908209c270df96be5","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"209f05b7b96a56a73e26b6ef70dffda2","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"9806c05af12a370694c417a0b9325f53","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"cb56901b902185f07396fc81f95e7f67","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"b62ff80e75df44bfc385d087de2385e4","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"77a959f07a9aea12fa7b21ac46072a76","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795988981,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"1184e06324a1319a1b4adda51f618d439ff721dfd62af32022775e5ae01cbcbe","lane":"client-lint","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":58,"stamp":"b621c117fe67f468f03a973753101fa3","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}
Ci-Attestation: {"at":1795989371,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"8d31ba7bf1c93e0c7135cc31bbf623469940f9e267c3977c80e0e8e849921671","lane":"client-test-x86_64-unknown-linux-gnu","parents":["650fdb09bfdfa985d5f0fb06c9c58da819fa6121"],"secs":312,"stamp":"2d3110cb9c5b4705786778133d62f7b5","tree":"37c440f9a079e6222890713b525323d94844a460","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"f2cd9f7f7e2e071a725c9f9d380a8dcd3b7aaf2c","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-video-render+.h.c","libobs/build/ported-source-sets/source-video-render.json","libobs/cmake/rust-exports.d/obs-source-source_video_render.txt","libobs/obs-source-video-render-fields.c.h","libobs/obs-source-video-render.c.h","libobs/obs-source.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_source_async_render_swap_is_registered.rs","rust/obs-build/tests/native/registration/canonical_source_async_update_swap_is_registered.rs","rust/obs-build/tests/native/registration/canonical_source_video_render_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-video-render.list","rust/obs-c-oracle/oracle/source_video_render.c","rust/obs-c-oracle/oracle/view.c","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_video_render.rs","rust/obs-source/src/lib.rs","rust/obs-source/src/video_render.rs","rust/obs-source/tests/source/main.rs","rust/obs-source/tests/source/video_render.rs","rust/obs-source/tests/source/video_render_parity.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_video_render.c","test/cmocka/tests.d/test_source_video_render.cmake"],"head":"63898b69073bec0e84c2c6a787e16e714f80c886","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"454cb1b7e36319ca6442efd1db226cd3d3b899de0754e5a859a9b605a722cc21","tree":"37c440f9a079e6222890713b525323d94844a460"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 29, 2026 21:56
@rdoupe rdoupe changed the title obs-source: port obs_source_video_render and its steps to Rust, GREEN (Fixes #5962) obs-source: port obs_source_video_render and its source_render_video, source_draw_route and get_type_format steps to Rust (Fixes #5962) Nov 29, 2026

@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 has the usual port shape:

  • Base: three commits on master: a verbatim extraction, then RED, then GREEN.
  • Tests: a new Tier 2 test_source_video_render.c and Tier 3 video_render_parity.rs against the oracle.
  • Export: obs_source_video_render is public EXPORT API, so there's no rust-hidden.d fragment, which is correct.
  • Rules: a Test cost line, and no existing C test or public header edited.
  • Windows (#5919): no util_mul_div64 and no wide usize inputs.
  • Status: queuing.

@zackees
zackees added this pull request to the merge queue Nov 29, 2026
Merged via the queue into master with commit 130e601 Nov 29, 2026
53 checks passed
@zackees
zackees deleted the port/5962-video-render branch November 29, 2026 22:43
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_source_video_render and its source_render_video and source_draw_route steps to obs-source

2 participants