Skip to content

libobs: Move the video output conversion plan into obs-video-plan.c - #1714

Merged
zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:refactor/video-plan-move
Oct 22, 2026
Merged

zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:refactor/video-plan-move

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Refs #1713 (PR 1 of the plan: the characterization and the extraction. The bug-4 fix and the port follow.)

What and why

This is a behaviour-neutral extraction before the Rust port, as the testing policy asks for part of a large file. The video output conversion plan moves from libobs/obs.c.h into libobs/obs-video-plan.c.h: the pure computation obs_reset_video() and the per-canvas video mix setup run before they touch the graphics device. There is no Rust, no behaviour change and no public header change.

  • What moves: calc_gpu_conversion_sizes(), the per-format plane table of obs_init_gpu_conversion() and obs_init_gpu_copy_surfaces(), the render-texture format and color-space choice of obs_init_textures(), size_valid() with OBS_SIZE_MIN/MAX, the output-size alignment masks of obs_reset_video_internal(), and its scale-type name switch. They become one by-value entry point, obs_video_output_plan(format, colorspace, width, height), returning struct obs_video_output_plan (the techniques, the texel sizes, each plane's size and gs_color_format, and the render format and space), plus obs_video_size_valid(), obs_video_align_output_size() and obs_video_scale_type_name().
  • What stays: the gs_texture_create/gs_stagesurface_create and render-texture calls (now driven by plan.planes[] and plan.texture_format/plan.render_space), the NV12/P010 texture decision (it asks the device), graphics init, mix creation, canvases, encoder rebinding, logging and obs_init_video(). obs.c copies the plan into the mix, exactly the fields it set before.
  • Struct, not EXPORT: struct obs_video_output_plan, struct obs_video_plane and the four functions are declared in obs-internal.h without EXPORT, so they are hidden. The caller is the only user; no struct internals reach the public API.
  • Build: the new file joins the existing libobs.core group just before obs.c.h, in alphabetical order, with libobs.pch.h. The group, the PCH, source-sets.json and the CMake source lists are unchanged.
  • Exported symbols: unchanged, 1766 in libobs with the C backend, in the hybrid libobs and in libobs-c-reference. The four new functions are local (t) symbols.

Behaviour-neutral refactor note: obs_init_gpu_conversion() and obs_init_gpu_copy_surfaces() now loop over plan.planes[] instead of a per-format switch. The plan writes a plane for exactly the channels each format used before (I420/I444/I010 three, NV12/P010/P216/P416 two, the rest none), with the same sizes and gs_color_format, so the same textures and surfaces are created in the same order. A scratch differential over every format x colorspace x a range of sizes (42525 cases) shows the plan's techniques, texel sizes, plane sizes (as gs_* call arguments), render format and render space are identical to the master code; a deliberate one-line mistake in the extracted copy makes 1575 of them differ.

Tests

test_video_output_plan compiles the moved file into itself (C only, ASan and UBSan, no libobs core, no display), so it checks the C and runs on every platform. 9 cases:

  • Every combination: every video_format (and one past the end) x every video_colorspace (and one past) x odd, even, minimum (2), the 1366-aligns-to-1364 size and maximum (32768) widths and heights, each compared field by field against an expectation written out from the code (42875 plans).
  • Written-out sizes: NV12, I420, I444, P010 (PQ), I010 (HLG), P216, P416 at common sizes, so a reader sees the techniques, plane sizes and formats.
  • Odd sizes round the chroma planes down; a 1x1 output gives empty chroma planes.
  • Formats without a conversion (NONE, the 4:2:2 packed, RGBA/BGRA/BGRX, Y800, the alpha and the un-GPU'd 10/12-bit) get no techniques and no planes, only a render format and space; the SDR 16-bit formats (I210, I412, YA2L) render GS_RGBA16F in GS_CS_SRGB; an 8-bit format with an HDR color space still renders in GS_CS_709_EXTENDED.
  • Every technique the plan names is a technique of format_conversion.effect (the CMake build passes the effect path; the cc-build and the real-libobs test cover it otherwise).
  • The size check at its edges (2..32768), the alignment masks (independent, width to a multiple of 4, height to even), and the scale-type names.
  • Characterized, not endorsed: an output width of 2 or 3 passes the size check and the alignment then masks it to 0 (bug 4).

test_video_output_formats links the real libobs and its OpenGL renderer (Linux, under xvfb-run; skips without a display). It drives obs_reset_video() and reads frames through obs_add_raw_video_callback(), using the public API only, so it covers the Rust port in the hybrid build. 3 cases:

  • Every format with a GPU conversion (I420, NV12, I444, I010, P010, P216, P416, each with its color spaces and both ranges) and BGRA/RGBA, 44 in all: each plane is present at the format's size and uniform over exactly that size (a wrong plane size shows as part of it that is not), and its sample values match the ones the C conversion produces (a wrong technique gives other values; measured on the C libobs with llvmpipe, with a per-format tolerance for renderer rounding).
  • The output size is aligned (70x35 -> 68x34, the base kept; the smallest surviving output 4x2), through obs_get_video_info() and the chroma-plane sizes.
  • An out-of-range size is refused before the old video is freed, and the old video keeps running.
  • The width-2/3 edge (bug 4) is left to test_video_output_plan: driving it through real libobs frees the old video and then fails, and the core cannot be reset again (it crashes), so this file does not drive it.

RED → GREEN

  • RED commit: none. This is a move plus two characterization tests, which pass on the moved code and on master. The commit is bd622f2a7 libobs: Move the video output conversion plan into obs-video-plan.c.
  • test_video_output_plan passes 9/9 and test_video_output_formats 3/3, run 3 times against each of libobs with the C backend, the hybrid libobs and libobs-c-reference. Both also pass against a libobs built from master's obs.c.h (the libobs change reverted, the tests kept), so the move changes nothing they can see.
  • Scratch differential (kept in local scratch, not in the PR): the plan matches the master code over 42525 cases; 1575 differ under a deliberate mutation.
  • Local, two build trees: OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON, both full builds. Full ctest -j4, headless (private Xvfb, private D-Bus, fresh HOME):
Lane Library ctest Exported symbols
OBS_LIBOBS_BACKEND=C libobs 360/360 IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON hybrid libobs 361/361 IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference 361/361 IDENTICAL (1766)

Nothing was skipped or failed to run. The tests were run on a885f89; the final rebase onto 51569f9 (#1709) brought in commits that touch none of the changed files (PulseAudio, CI and docs only), and ci/test_build_groups.py passes on the rebased head.

  • Also run: uv run ci/local_gate.py --lane lint passed, and --lane cross passed. clang-format 23.1 and gersemi clean on the changed files. ci/test_build_groups.py and ci/platform_ifdef_ratchet.py pass.
  • Real app (UI, protocol output or logging changes): not applicable (no behaviour change).

Windows/macOS: not built here. The moved code has no host conditional. test_video_output_plan is portable C (no cmocka range assertions) and builds everywhere; test_video_output_formats is Linux-only (it needs the OpenGL renderer and a display).

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (this is the extraction with its characterization; the bug-4 fix and the port follow)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): not applicable (no warning or flag change; no platform conditional moved)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: no port here)

Behavior-neutral extraction before the Rust port: the video output
conversion plan moves from libobs/obs.c.h into libobs/obs-video-plan.c.h,
the pure computation obs_reset_video() and the per-canvas video mix setup
run before they touch the graphics device.

calc_gpu_conversion_sizes(), the per-format plane table of
obs_init_gpu_conversion() and obs_init_gpu_copy_surfaces(), the
render-texture format and color-space choice of obs_init_textures(),
size_valid() with OBS_SIZE_MIN/MAX, the output-size alignment masks of
obs_reset_video_internal() and its scale-type name switch become one
by-value entry point, obs_video_output_plan(format, colorspace, width,
height) returning struct obs_video_output_plan (the techniques, texel
sizes, each plane's size and gs_color_format, and the render format and
space), 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; obs.c is the only caller.

obs_init_gpu_conversion() and obs_init_gpu_copy_surfaces() now loop over
plan.planes[] instead of a per-format switch, writing a plane for exactly
the channels each format used before, at the same sizes and formats, in
the same order; obs.c copies the rest of the plan into the mix. The
gs_texture_create/gs_stagesurface_create calls, the NV12/P010 texture
decision, graphics init, mix creation, canvases, encoder rebinding,
logging and obs_init_video() stay in obs.c.

The new file joins libobs.core just before obs.c.h (alphabetical), with
libobs.pch.h. No group, PCH or source-sets.json change; the exported
symbols are unchanged (1766) and the new functions are local.

New test test_video_output_plan compiles the moved file into itself (C
only, ASan and UBSan, no core, no display). It pins the plan for every
video_format and video_colorspace (and one past each), odd/even/minimum/
alignment/maximum sizes, the written-out numbers for common formats, the
formats without a conversion, that every technique it names is in
format_conversion.effect, the size check edges, the alignment masks and
the scale-type names.

New test test_video_output_formats links the real libobs and its OpenGL
renderer (Linux, under xvfb-run) and runs obs_reset_video() once per
output format with a GPU conversion (I420, NV12, I444, I010, P010, P216,
P416, with color spaces and both ranges) and BGRA/RGBA, checking each
frame's plane sizes and sample values, the output-size alignment through
obs_get_video_info(), and that an out-of-range size is refused before the
old video is freed. Public API only, so it covers the Rust port in the
hybrid build.

Characterized, not endorsed: size_valid() accepts an output width of 2 or
3, and the alignment then masks it to 0.

Refs obs-rust#1713
@rdoupe
rdoupe requested a review from zackees as a code owner October 22, 2026 04:36
@zackees
zackees enabled auto-merge October 22, 2026 04:41
@zackees
zackees added this pull request to the merge queue Oct 22, 2026
Merged via the queue into obs-rust:master with commit 07988d6 Oct 22, 2026
25 checks passed
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 22, 2026
…ust#1734)

* test: Expect obs_reset_video() to refuse an output width that aligns to 0

An output width of 2 or 3 passes the 2..32768 size check of
obs_reset_video(), and the output alignment to a multiple of 4 then makes
it 0. The reset has freed the old video by then, so it fails with no video
left, and obs_get_video() then crashes on the missing main mix. obs-rust#1714
pinned this as characterized, not endorsed.

test_video_output_plan now expects the new obs_video_output_size_valid()
to refuse the widths 2 and 3 (any height) and to agree with
obs_video_size_valid() for every other size, including the sizes just
above the maximum. The alignment assertions are unchanged.

test_video_output_formats gets a real-libobs case: a reset to a valid
size, then to an output width of 2 or 3, which must return
OBS_VIDEO_INVALID_PARAM and leave the old video running, then a later
reset to a valid size, which must work.

Refs obs-rust#1713

* libobs: Refuse an output size that the alignment makes invalid

obs_reset_video() checked the output size (2..32768) before aligning the
width down to a multiple of 4 and the height to a multiple of 2. An
output width of 2 or 3 passed the check and was aligned to 0. By then the
reset had freed the old video, so video_output_open() failed with no
video left, and obs_get_video() then crashed on the missing main mix.

The output size is now checked as given and once aligned, by the new
hidden obs_video_output_size_valid() in obs-video-plan.c.h, before
anything is freed. A width of 2 or 3 now returns OBS_VIDEO_INVALID_PARAM
and the old video keeps running. Every other size is accepted or refused
exactly as before: heights of 2 and 3 align to 2 and stay valid, and the
alignment only lowers a size, so no size above the maximum becomes valid.
The base size is not aligned and keeps its check. The Settings dialog
(minimum 32) and obs-websocket SetVideoSettings (minimum 8) never send
such a width; plugins and scripts can.

obs_init_video() also checked pthread_mutex_init() for its three mutexes
with < 0. pthread returns a positive error number, so a failure was never
caught; it checks != 0 now, like the rest of obs.c.h.

Refs obs-rust#1713
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 22, 2026
The Windows Tier 2 build stops before CTest with LNK2019, unresolved
cm_print_error in check_plan: test_video_output_plan (from obs-rust#1714) calls
fail_msg(), which expands to that private cmocka printer, and the Windows
cmocka does not export it. obs-rust#1580 was the same failure in
test_output_delay_e2e; obs-rust#1591 fixed it with fprintf(stderr, ...) and plain
fail(), and added a check for that one file.

ci/test_cmocka_windows_diagnostics.py generalizes that check. It reads
every add_executable() in test/cmocka/CMakeLists.txt and tests.d/*.cmake,
skips the ones an enclosing if() keeps off Windows (OS_LINUX, UNIX,
NOT WIN32, or a plugin target that plugins/CMakeLists.txt only adds on
other platforms; else() counts as Windows), and fails if any of their
sources calls fail_msg(). Comments that mention fail_msg() do not count.
As in obs-rust#1591, it also compiles the actual diagnostic helpers of
test_video_output_plan (check_plan, techniques_exist_in_the_effect,
size_check_edges, output_size_check_edges) against a model of the
Windows link contract, a cm_print_error declaration with no definition,
and expects each forced failure to print its diagnostic and fail.

On master it fails twice: the scan finds four fail_msg() calls in
test_video_output_plan.c and three in test_settings_track_rows.cpp (a
Qt6::Widgets test that Windows builds), and the probe does not link
(undefined reference to cm_print_error in all four helpers).

Refs obs-rust#1713
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 22, 2026
The Windows Tier 2 build stops before CTest with LNK2019, unresolved
cm_print_error in check_plan: test_video_output_plan (from obs-rust#1714) calls
fail_msg(), which expands to that private cmocka printer, and the Windows
cmocka does not export it. obs-rust#1580 was the same failure in
test_output_delay_e2e; obs-rust#1591 fixed it with fprintf(stderr, ...) and plain
fail(), and added a check for that one file.

ci/test_cmocka_windows_diagnostics.py generalizes that check. It reads
every add_executable() in test/cmocka/CMakeLists.txt and tests.d/*.cmake,
skips the ones an enclosing if() keeps off Windows (OS_LINUX, UNIX,
NOT WIN32, or a plugin target that plugins/CMakeLists.txt only adds on
other platforms; else() counts as Windows), and fails if any of their
sources calls fail_msg(). Comments that mention fail_msg() do not count.
As in obs-rust#1591, it also compiles the actual diagnostic helpers of
test_video_output_plan (check_plan, techniques_exist_in_the_effect,
size_check_edges, output_size_check_edges) against a model of the
Windows link contract, a cm_print_error declaration with no definition,
and expects each forced failure to print its diagnostic and fail.

On master it fails twice: the scan finds four fail_msg() calls in
test_video_output_plan.c and three in test_settings_track_rows.cpp (a
Qt6::Widgets test that Windows builds), and the probe does not link
(undefined reference to cm_print_error in all four helpers).

Refs obs-rust#1713
zackees pushed a commit to rdoupe/obs-studio that referenced this pull request Oct 22, 2026
The Windows Tier 2 build stops before CTest with LNK2019, unresolved
cm_print_error in check_plan: test_video_output_plan (from obs-rust#1714) calls
fail_msg(), which expands to that private cmocka printer, and the Windows
cmocka does not export it. obs-rust#1580 was the same failure in
test_output_delay_e2e; obs-rust#1591 fixed it with fprintf(stderr, ...) and plain
fail(), and added a check for that one file.

ci/test_cmocka_windows_diagnostics.py generalizes that check. It reads
every add_executable() in test/cmocka/CMakeLists.txt and tests.d/*.cmake,
skips the ones an enclosing if() keeps off Windows (OS_LINUX, UNIX,
NOT WIN32, or a plugin target that plugins/CMakeLists.txt only adds on
other platforms; else() counts as Windows), and fails if any of their
sources calls fail_msg(). Comments that mention fail_msg() do not count.
As in obs-rust#1591, it also compiles the actual diagnostic helpers of
test_video_output_plan (check_plan, techniques_exist_in_the_effect,
size_check_edges, output_size_check_edges) against a model of the
Windows link contract, a cm_print_error declaration with no definition,
and expects each forced failure to print its diagnostic and fail.

On master it fails twice: the scan finds four fail_msg() calls in
test_video_output_plan.c and three in test_settings_track_rows.cpp (a
Qt6::Widgets test that Windows builds), and the probe does not link
(undefined reference to cm_print_error in all four helpers).

Refs obs-rust#1713
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 22, 2026
* ci: Catch fail_msg() in cmocka tests that Windows builds

The Windows Tier 2 build stops before CTest with LNK2019, unresolved
cm_print_error in check_plan: test_video_output_plan (from obs-rust#1714) calls
fail_msg(), which expands to that private cmocka printer, and the Windows
cmocka does not export it. obs-rust#1580 was the same failure in
test_output_delay_e2e; obs-rust#1591 fixed it with fprintf(stderr, ...) and plain
fail(), and added a check for that one file.

ci/test_cmocka_windows_diagnostics.py generalizes that check. It reads
every add_executable() in test/cmocka/CMakeLists.txt and tests.d/*.cmake,
skips the ones an enclosing if() keeps off Windows (OS_LINUX, UNIX,
NOT WIN32, or a plugin target that plugins/CMakeLists.txt only adds on
other platforms; else() counts as Windows), and fails if any of their
sources calls fail_msg(). Comments that mention fail_msg() do not count.
As in obs-rust#1591, it also compiles the actual diagnostic helpers of
test_video_output_plan (check_plan, techniques_exist_in_the_effect,
size_check_edges, output_size_check_edges) against a model of the
Windows link contract, a cm_print_error declaration with no definition,
and expects each forced failure to print its diagnostic and fail.

On master it fails twice: the scan finds four fail_msg() calls in
test_video_output_plan.c and three in test_settings_track_rows.cpp (a
Qt6::Widgets test that Windows builds), and the probe does not link
(undefined reference to cm_print_error in all four helpers).

Refs obs-rust#1713

* test: Report track-row failures without fail_msg()

The Windows cmocka does not export cm_print_error(), which fail_msg()
expands to there, so a Windows-built test that calls it stops the
Windows Tier 2 build with LNK2019 before CTest runs (obs-rust#1713: obs-rust#1741,
obs-rust#1745 and obs-rust#1762 fixed test_video_output_plan).

test_settings_track_rows (Qt6::Widgets only, so Windows builds it too)
still had three such calls. It links on Windows today, but it is the
only Windows-built test left that calls fail_msg(), and the new check
holds every such test to the same rule. Each becomes fprintf(stderr,
...) with the same format and arguments and a terminating newline, then
a plain fail(), under the same condition. No condition, loop, case or
assertion changes.

Refs obs-rust#1713
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.

2 participants