Skip to content

obs-scene: Port the scene item names and coordinate keys - #2129

Merged
zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/scene-item-names
Oct 24, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/scene-item-names

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2114

What and why

This PR ports the scene item save/load name tables and the coordinate-key choice of scene_load_item() and scene_save_item() in libobs/obs-scene.c.h to a new item_names module of rust/obs-scene, next to crop (#1947) and render_plan (#2018). A wrong table here would silently reset the scale filter or blend mode of every item on load, so each value is pinned on both sides.

What stays C: every obs_data_* call, in its order; the coordinate conversions (obs-scene-coords.c.h, already ported); the source lookup; the transitions; the private settings; and the crop clamp on load (#1840, unchanged). The hybrid libobs drops the C file and links the Rust shims in its place.

astrcmpi. The names are still matched with astrcmpi, through one implementation. The loaders take the compare as a parameter, and obs-scene.c.h passes libobs's own astrcmpi; in the hybrid, that is obs-util's Rust one. The Rust table logic calls it in the same order and the same number of times as the C did: (name, known) for each known name, stopping at the first match, and not at all for NULL.

  • Calling obs_util::dstr::astrcmpi from the crate was tried first. It broke the link of every obs-scene _rust test: test_scene_bounds_place_rust, test_scene_item_crop_rust, test_scene_render_plan_steps_rust and the new one. The archive member that holds it pulls in obs-util objects that need libuuid, which is the problem the audio_actions row of rust/README.md describes.

  • So rust/obs-scene still depends on no obs-util code. Its Cargo.toml is unchanged except for the description.

  • Move (libobs: Move the scene item names and coordinate keys out, no behaviour change). The tables and the key choice move to libobs/obs-scene-item-names.c.h. They are declared without EXPORT in obs-scene-item-names.h:

    • obs_scene_item_scale_filter_from_name(), obs_scene_item_blend_method_from_name() and obs_scene_item_blend_type_from_name(): the value a saved name loads as, or Disable, Default or Normal. They take the name and the compare (obs_scene_item_name_cmp, astrcmpi's signature).
    • obs_scene_item_scale_filter_name(), obs_scene_item_blend_method_name() and obs_scene_item_blend_type_name(): the name a value is saved under, a static string, with the C's fallbacks (disable, default, normal).
    • obs_scene_item_transform_keys() and obs_scene_item_bounds_keys(): read the relative keys, the absolute keys converted, or the absolute keys as they are (enum obs_scene_item_keys).
    • obs_scene_item_save_relative(): write the relative keys (and the absolute ones for older versions), or the absolute keys alone.

    One read changed. obs_data_has_user_value() of pos_rel, scale_rel and scale_ref is now asked for all three, in that order, before the choice. The old && chain stopped at absolute coordinates or at the first missing key. It is a plain lookup in item_data with no side effect. bounds_rel is still asked where it was.

    The enum values cross as int, so the header needs only stdbool.h. obs-scene.c.h checks at compile time that the mirrored scale filter, blend method and blend type values match obs.h. The file joins libobs.core-source. The exported symbol count is unchanged (1766).

  • Characterization (test_scene_item_names_steps, 14 cases). It compiles the moved file with ASan and UBSan, needs no libobs core, and runs on every platform. Like obs-scene.c.h, it gives the loaders libobs's astrcmpi. It pins:

    • every name in lower, upper and mixed case;
    • unknown names, which load as the default:
      • the empty string, a leading or trailing space, a tab or newline after the name, and a name cut short;
      • the saver's own fallback names, and NULL;
      • bytes above 0x7F: lone 0x80 and 0xFF, and UTF-8 look-alikes (a dotted capital I, a dotless i, a no-break space, a zero-width space);
    • the compare's calls, through a recording wrapper: their order, the stop at the first match, and none for NULL;
    • every enum value on the save side, plus -1, one past the last value, INT_MIN and INT_MAX; every value from -2 to 8 loads back as itself inside the enum and as the default outside it;
    • the transform and bounds keys for all 16 patterns of pos_rel, scale_rel, scale_ref and bounds_rel, with and without absolute_coordinates, and the save choice.
    • Characterized, not endorsed:
      • each table knows only its own names;
      • numbers are names, not values ("1" loads as Disable);
      • the bounds load from bounds_rel without the position's three relative keys.
    • It is registered in test/cmocka/build/test-graph.json, in the core suite, so no pinned count changes. It reports failures with fprintf(stderr, ...) and fail(), not fail_msg(). It uses no assert_in_range and needs no libm. It builds with -Werror and passes 14/14 with cmocka 2.0.2 and with 1.1.7.
  • Safe core (src/item_names.rs): one function per hidden C function.

    • The loaders walk the C's table in order with the given compare, as equal(name, known). None (the C's NULL) gives the default without a compare.
    • The savers are a match giving a &'static CStr.
    • Keys is Relative, FromAbsolute or Absolute.
    • Values from the item are i32, compared as they are.
    • The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, unimplemented and unreachable lints. It allocates nothing and uses no unsafe.
  • Shim (src/ffi/scene_item_names.rs): the nine functions, with the C signatures.

    • The loaders read the name through &CStr and call the C compare with the name's own pointer and a static known name.
    • The savers return the &'static CStr's pointer, so nothing is allocated, and obs_data_set_string() copies it as it copied the C literal.
    • The keys cross as the C's enum values.
    • No item pointer crosses.
  • _rust variant: test_scene_item_names_steps_rust runs the unchanged test source against libobs_rust-static. It links OBS::libobs first, so astrcmpi comes from libobs and the archive gives only the hidden functions, as test_transition_clock_steps_rust does. It is in tests.d/test_scene_item_names_steps.cmake, inside if(TARGET libobs_rust-static).

  • C side:

    • The file leaves libobs.core-source for its own group, libobs.ported-scene-item-names, listed under LIBOBS_PORTED_SOURCES. Its PCH has only obs-scene-item-names.h.
    • libobs.pch.h keeps the header for obs-scene.c.
    • ci/test_ported_sources.py checks the group on Linux, Windows and macOS.
  • Symbols:

    • The nine shims are in rust-hidden.txt, in the local: list of rust-exports.map, and in rust-unexports-macos.txt.
    • nm shows all nine as local (t) in all three libraries. ninja -t query shows that the hybrid does not link the C group and that the c-ref does; addr2line puts the c-ref's in obs-scene-item-names.c.h.
    • The exported symbol sets are unchanged: 1766 in all three libraries, identical.
  • Oracle (oracle/scene_item_names.c): the original file, unmodified, with its nine functions renamed to oracle_*. It also exports the size and values of enum obs_scene_item_keys and the mirrored constants (19 values).

  • Docs:

    • The rust/README.md rows (crate table and port table), the crate's Cargo description and the lib.rs docs are updated.
    • The docs/rust-port/naming.md row (libobs/obs-scene*.c.h) already covers the file.
    • No docs/features.md line: there is no user-visible change.
  • port_comparison (its own file, benches/port_comparison/scene_item_names.rs): 16 items, shim against oracle. Each side's loaders get their own library's astrcmpi. load covers the three loaders and both key choices; save covers the three savers. Pinned to one core, with a load average near 20, so noisy. Medians from two runs:

    Bench Rust C
    load/16 3.25 µs / 2.35 µs 1.68 µs / 896 ns
    save/16 164 / 67 ns 370 / 194 ns

    With the C astrcmpi on both sides, load/16 is 932 ns against 902 ns. So the load gap comes from obs-util's astrcmpi, which the hybrid already uses for every astrcmpi call before this PR, not from the table logic. That is about 90 ns per item when a scene collection loads.

No intentional differences. Every input has defined C behaviour (values outside each enum take the C's fallback), so the parity test excludes nothing.

Seen while porting, not changed here:

  • soldr cargo bench -p obs-c-oracle --bench port_comparison -- --test <anything> fails on origin/master (a63f715ac, and fae97a8e3 before it). The bmem/count fixture assert sees 16 against 0. The fixtures are all checked before the filter applies, so every unit's --test run stops there; the scene_item_names benches are measured and pass before it. It is not caused by this PR: it fails the same way with this bench's call removed, and on a clean origin/master checkout.
  • The C astrcmpi (util/dstr.c.h) passes a plain char to toupper(), which is undefined for bytes above 0x7F in standard C. glibc defines it, and the hybrid uses the Rust one. Only the C backend and libobs-c-reference reach it, and the characterization's high bytes pass there on Linux.

RED → GREEN

  • RED commit: 16d9c8411 obs-scene: Add the scene item names and coordinate keys tests. The core is todo!(). soldr cargo test -p obs-data --test obs-tests-core scene::item_names fails 19 of 20 with "not yet implemented", run on bda1e1d01, the same commit before the rebases (identical tree contents for these files). The one that passes is steps_key_values: it checks only the Keys discriminants and calls no stub.
    • Tier 1 (tests/scene/item_names.rs) ports the 14 cases of test_scene_item_names_steps one for one, under the same names (steps_*), with the same values and expectations. Like the C test, it gives the loaders astrcmpi: obs-util's, which obs-tests-core already depends on.
    • 6 new edge cases:
      • the tables' shape;
      • every upper/lower-case spelling of every name;
      • every name with one byte changed to any other byte, cut short, or with any byte added at either end;
      • the keys' invariants;
      • two 4000-case proptests: the loaders against a model (value and compares) over any byte string with no NUL, and the savers over any i32.
    • The tests are a module of the existing core category binary, obs-tests-core. No new test binary.
  • GREEN: b13efe523 obs-scene: Port the scene item names and coordinate keys. scene::item_names passes 20/20.
  • Tier 3: 01b6dc6a0 obs-scene: Check the scene item names and coordinate keys port against the C (tests/scene/item_names_parity.rs, 9 tests).
    • What is compared:

      • The loaded values and keys as integers, and the saved names byte for byte.
      • The value runs give the shims obs-util's astrcmpi (what the hybrid passes) and the oracle the C dstr.c's (oracle_astrcmpi, what libobs-c-reference passes), so they compare the two libraries' whole name match.
      • The compare runs give both sides one recording compare and check that they ask it the same questions in the same order.
    • Runs:

      • the enum values and constants against the header;
      • the keys and the save choice over all 16 patterns × absolute coordinates;
      • the savers over every value from -4096 to 4096 and the ends of i32;
      • the loaders over NULL, every string of one or two bytes (65,280 strings), every case spelling of the 15 names, and every one-byte change, cut and addition to them;
      • two 10,000-case proptests: the loaders, values and compares, over arbitrary byte strings with no interior NUL, and the savers over any i32.
    • It passed 4 runs in a row with fresh seeds. obs-util's astrcmpi and the C one agree on every byte tried, those above 0x7F included.

    • proptest-regressions/item_names.txt and item_names_parity.txt keep the seeds the mutants failed on.

    • Mutation check (done once, not committed). All 22 mutants fail:

      Mutant Tier 1 failures Tier 3 failures
      scale: bilinear loads as bicubic 4 2
      scale: area loads as Disable 4 2
      blend type: darken misspelt 5 4
      blend method: sRGB off the default 6 5
      load: table tried in reverse 2 4
      load: NULL compared as "" 1 1
      load: compares past the first match 2 2
      load: byte compare instead of the given one 6 4
      save: Area saved as "Area" 2 1
      save: blend type fallback "default" 1 2
      save: any non-zero method is sRGB off 3 2
      save: Disable saved as "" 2 2
      keys: scale_ref ignored 2 1
      keys: absolute converted too 3 1
      keys: bounds need the transform keys 2 1
      save: relative inverted 2 1
      keys: Relative = 3 in the core enum 1 0
      shim: FromAbsolute and Absolute swapped 0 1
      shim: compare arguments swapped 0 4
      shim: <= 0 for == 0 0 4
      shim: blend method and type loaders swapped 0 4
      shim: name copied to a new string for the compare 0 4

      Tier 1 does not reach the shims. Relative = 3 changes only the core enum's discriminant, which the shim maps to the C value explicitly, so only Tier 1 sees it. "table tried in reverse" and "compares past the first match" give the same values, because the names are distinct; the compare-order checks catch them.

  • Local runs used two builds: OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON.
    • They ran headless: a private Xvfb -noreset on a free display, a private D-Bus, a fresh HOME, no core dumps, and TMPDIR unset.
    • The libobs-c-reference target is not in all, so it was built by name before each c-ref run, and its mtime was checked.
  • The final head is 9b5b8c57b, on 1cddf78da.

Full ctest on a5c2e8737; the focused sets and the exported symbols on 9b5b8c57b.

Lane Library Full ctest Focused set Exported symbols
OBS_LIBOBS_BACKEND=C libobs 435/435 5/5 (36 cases) 1766
HYBRID, OBS_BUILD_C_REFERENCE=ON hybrid libobs 448/448 6/6 (50 cases) 1766, identical
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference (focused set only) 6/6 (50 cases) 1766, identical
  • The focused set: test_scene_blend, test_scene_item_crop_load (libobs: Clamp loaded scene item crops and saturate the crop and group size casts #1840), test_scene_duplicate_scale_ref, test_saved_transition, test_scene_item_names_steps (14/14), and test_scene_item_names_steps_rust (hybrid builds only, 14/14). No case was skipped.
  • Full ctest skips: none at the ctest level. Three cmocka cases were skipped in both lanes, none of them related to this PR: test_config_hex_float_rounding's comma-locale case (no such locale is installed) and open_crashes_without_obs_core in test_audio_io and in test_video_io.
  • The move commit on its own (same content, before the rebase onto a63f715ac) passes the focused set on the C lane: 5/5, 36 cases, no skips.
  • soldr cargo test -p obs-data --test obs-tests-core scene::item_names passes 29/29 (20 Tier 1, 9 Tier 3).
  • uv run ci/local_gate.py --test-diff origin/master passes 3319/3319 (on 9b5b8c57b). The 4 skipped are the existing #[ignore] tests (an NVIDIA driver, and three slow exhaustive runs). --lane lint and --lane cross pass.
  • ci/test_build_groups.py, ci/test_ported_sources.py, ci/test_oracle_standins.py, ci/test_sorted_shared_lists.py, ci/test_test_graph_sorted.py, ci/test_cmocka_rust_static_guard.py and ci/test_cmocka_windows_diagnostics.py pass.
  • soldr cargo bench -p obs-c-oracle --bench port_comparison -- --test scene_item_names: the four scene_item_names benches pass, then the run stops at the bmem/count fixture assert, as on origin/master (see above).
  • Real app (UI, protocol output or logging changes): not applicable (no behaviour change for libobs).

Windows/macOS: not built there.

  • The core and the shim have no host conditional.
  • The new header needs only stdbool.h.
  • test_scene_item_names_steps builds the moved file on every platform. It uses no fail_msg() and no libm.
  • test_scene_item_names_steps_rust follows test_transition_clock_steps_rust: OBS::libobs, then the archive.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • 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 (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • 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): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (none)

Behaviour-neutral extraction before the Rust port. The name tables and
the coordinate-key choice of scene_load_item() and scene_save_item() in
obs-scene.c.h move to libobs/obs-scene-item-names.c.h, declared in the
new libobs/obs-scene-item-names.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- obs_scene_item_scale_filter_from_name(),
  obs_scene_item_blend_method_from_name() and
  obs_scene_item_blend_type_from_name(): the value a saved name loads
  as. obs-scene.c.h passes libobs's astrcmpi() as the compare, which is
  called as before: (name, known) for each known name in the old order,
  stopping at the first match, and not at all for NULL. NULL or any
  other name loads as Disable, Default or Normal, as before. Taking the
  compare as a parameter keeps the one astrcmpi implementation for the
  port: the Rust side calls whatever libobs passes, so rust/obs-scene
  needs no obs-util objects (whose system libraries would break the
  obs-scene _rust test links).
- obs_scene_item_scale_filter_name(), obs_scene_item_blend_method_name()
  and obs_scene_item_blend_type_name(): the name a value is saved
  under, a static string, with the old fallbacks ("disable", "default",
  "normal").
- obs_scene_item_transform_keys() and obs_scene_item_bounds_keys():
  read the relative keys, the absolute keys converted, or the absolute
  keys as they are (enum obs_scene_item_keys).
- obs_scene_item_save_relative(): write the relative keys (and the
  absolute ones for older versions) or the absolute keys alone.

obs-scene.c.h keeps every obs_data_* call in its order, the coordinate
conversions (obs-scene-coords.c), the source lookup, the transitions,
the private settings and the crop clamp of obs-rust#1840, and stores the results
in the item.

One read changed: obs_data_has_user_value() of "pos_rel", "scale_rel"
and "scale_ref" is now asked for all three, in that order, before the
choice, where the old && chain stopped at absolute coordinates or at the
first missing key. It is a plain lookup in item_data with no side
effect, and "bounds_rel" is still asked where it was.

The enum values cross as int, so the header needs only stdbool.h;
obs-scene.c.h checks at compile time that the mirrored scale filter,
blend method and blend type values match obs.h.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header. The exported symbol sets are unchanged (1766).

Refs obs-rust#2114
test_scene_item_names_steps compiles libobs/obs-scene-item-names.c.h
(ASan and UBSan, no libobs core) and calls only its hidden functions,
so it runs on every platform. 14 cases, all calling the loaders with
libobs's astrcmpi() as obs-scene.c.h does:

- the loaders: every scale filter, blend method and blend type name in
  lower, upper and mixed case;
- unknown names load as Disable, Default and Normal: the empty string,
  a trailing or leading space, a tab or newline after the name, a name
  cut short or one byte long, "srgb-off", the saver's own fallback names
  ("disable", "default", "normal"), NULL, and bytes above 0x7F (lone
  0x80 and 0xFF, UTF-8 look-alikes such as a dotted capital I, a
  no-break space and a zero-width space);
- each table knows only its own names; numbers are names, not values
  (characterized, not endorsed);
- the compare's calls, through a recording wrapper around astrcmpi():
  (name, known) for each known name in the C's order, stopping at the
  first match, every known name for an unknown one, none for NULL;
- the savers: every value of each enum, and -1, one past the last,
  INT_MIN and INT_MAX (the fallbacks); every value from -2 to 8 loads
  back as itself inside the enum and as the default outside it;
- the transform and bounds keys for all 16 patterns of pos_rel,
  scale_rel, scale_ref and bounds_rel, with and without absolute
  coordinates; bounds_rel is read without the transform's three keys
  (characterized, not endorsed); the save choice; the key values and
  that the enum is int-sized.

It is in the native test graph, in the core suite, so no pinned count
changes. It reports failures with fprintf(stderr, ...) and fail(), not
fail_msg(), and uses no assert_in_range; it needs no libm. It passes
14/14 on the C backend, and builds with -Werror and passes 14/14
against cmocka 2.0.2 and 1.1.7. The real-libobs scene tests
are unchanged.

Refs obs-rust#2114
RED for the port of libobs/obs-scene-item-names.c.h to a new item_names
module of rust/obs-scene. The safe core is a stub (todo!()), one
function per hidden C function: scale_filter_from_name(),
blend_method_from_name() and blend_type_from_name() over Option<&CStr>
(None is the C's NULL) and the compare the caller gives (C passes
libobs's astrcmpi); scale_filter_name(), blend_method_name() and
blend_type_name() giving a &'static CStr; transform_keys() and
bounds_keys() giving a Keys (Relative, FromAbsolute, Absolute); and
save_relative(). The enum values and the three name tables, in the C's
order, are constants.

tests/scene/item_names.rs ports test_scene_item_names_steps 1:1: its 14
cases under the same names (steps_*), in the same order, with the same
inputs and expectations, the characterized-not-endorsed cases included.
Like the C test, it gives the loaders astrcmpi: obs-util's, the one the
hybrid libobs passes (obs-util is already a dev-dependency of the
obs-tests-core binary).

Edge cases (edge_*): the tables' shape (lower-case ASCII names, distinct
names and values, none the default, each saved under its own name);
every upper/lower-case spelling of every name; every name with one byte
changed to any other byte, cut short, or with any byte added at either
end; the keys' invariants over all 16 patterns; and two proptests (4000
cases each): the loaders against a model (the first table entry equal
with ASCII case folded, and the compares made: the table up to and
including that entry) over any byte string with no NUL, biased towards
the names, and the savers over any i32.

The tests are a module of obs-tests-core (rust/obs-data/tests/core.rs),
as the other obs-scene units' are.

soldr cargo test -p obs-data --test obs-tests-core scene::item_names
fails 19 of 20 with "not yet implemented"; steps_key_values, which
checks only the Keys discriminants and calls no stub, passes.

Refs obs-rust#2114
Ports libobs/obs-scene-item-names.c.h, the name tables and the
coordinate-key choice of scene_load_item() and scene_save_item(), to the
item_names module of rust/obs-scene. scene_load_item() and
scene_save_item() stay C in obs-scene.c.h: every obs_data_* call in its
order, the coordinate conversions (obs-scene-coords.c), the source
lookup, the transitions, the private settings and the crop clamp of
obs-rust#1840. The hybrid libobs drops the C file and links the Rust shims in
its place.

Safe core (src/item_names.rs), one function per hidden C function:
- scale_filter_from_name(), blend_method_from_name() and
  blend_type_from_name(): the first entry of the table, in the C's
  order, that the given compare finds equal to the name, else Disable,
  Default or Normal. The compare is asked as (name, known) and not past
  the first match; None (the C's NULL) is the default without a compare.
- scale_filter_name(), blend_method_name() and blend_type_name(): a
  match over the enum value giving a &'static CStr, with the C's
  fallbacks ("disable", "default", "normal") for any other i32.
- transform_keys() and bounds_keys(): Relative when the coordinates are
  not absolute and every relative key is there, FromAbsolute when they
  are not absolute, Absolute otherwise; save_relative().
Values from the item are i32, compared as they are. The module denies
clippy's arithmetic, indexing, as, unwrap, expect, panic, unimplemented
and unreachable lints, allocates nothing, keeps no state and takes no
lock.

astrcmpi: the loaders call the compare C passes, which obs-scene.c.h
gives as libobs's own astrcmpi (in the hybrid, obs-util's Rust one). So
the case rules stay one implementation, called the same number of times
in the same order, and rust/obs-scene still depends on no obs-util code.
Calling obs-util's astrcmpi from the crate was tried first: its archive
member pulls in obs-util objects that need libuuid, and every obs-scene
_rust test (test_scene_bounds_place_rust, test_scene_item_crop_rust,
test_scene_render_plan_steps_rust and the new one) failed to link.

Shim (src/ffi/scene_item_names.rs): the nine functions with the C
signatures. The loaders read the name through &CStr and call the C
compare with the name's own pointer and a static known name; the savers
return the &'static CStr's pointer, so nothing is allocated. Keys cross
as the C's enum values. No item pointer crosses.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-scene-item-names (LIBOBS_PORTED_SOURCES), whose PCH has
only obs-scene-item-names.h; libobs.pch.h keeps the header for
obs-scene.c. The functions are not EXPORT, so the shims are hidden:
rust-hidden.txt, the local: list of rust-exports.map and
rust-unexports-macos.txt. libobs-rust already links the crate's ffi.
ci/test_ported_sources.py checks the group on every host. The exported
symbol sets are unchanged and equal (1766 on the C backend, the hybrid
and libobs-c-reference).

test_scene_item_names_steps still compiles the C file into itself,
unchanged. The new test_scene_item_names_steps_rust builds the same test
source against libobs_rust-static, after OBS::libobs (for astrcmpi), as
test_transition_clock_steps_rust does. The real-libobs scene tests see
the swap through the hybrid.

Tier 1 scene::item_names passes 20/20.

Refs obs-rust#2114
…t the C

Oracle (oracle/scene_item_names.c): the original
obs-scene-item-names.c.h, unmodified, with its nine functions renamed to
oracle_*, plus the size of enum obs_scene_item_keys, its values and the
mirrored scale filter, blend method and blend type values (19 values).
The loaders take the compare as a parameter, so the oracle needs no
renamed astrcmpi of its own.

Tier 3 (tests/scene/item_names_parity.rs, 9 tests). The value runs give
the shims obs-util's astrcmpi (what the hybrid passes) and the oracle the
C dstr.c's (oracle_astrcmpi, what libobs-c-reference passes), so they
compare the two libraries' whole name match. The compare runs give both
sides one recording compare and check that they ask it the same
questions in the same order: the name's own pointer and each known
name's bytes, stopping at the first match, none for NULL.
- the enum values and constants against the C header;
- exhaustive: the transform and bounds keys and the save choice over all
  16 patterns of the four relative keys, with and without absolute
  coordinates; the three savers over every value from -4096 to 4096 and
  the ends of i32 (names compared byte for byte); the loaders over NULL,
  every string of one or two bytes (65,280 strings), every upper/lower
  case spelling of every name (the savers' 15 names, fallbacks
  included), every name with one byte changed to any other byte, cut
  short, or with any byte added at either end, and the
  characterization's other names; the compares for all of them but the
  two-byte strings;
- proptests (10,000 cases each): the loaders, values and compares, over
  arbitrary byte strings with no interior NUL (biased towards the names,
  their case and up to two bytes changed), and the savers over any i32.

The module passed 4 runs in a row with fresh seeds. obs-util's astrcmpi
and the C one agree on every byte tried, those above 0x7F included.

Mutation check (done once, not committed): 22 mutants, 16 in the core
and 6 in the shim; all fail.

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| scale: bilinear loads as bicubic | 4 | 2 |
| scale: area loads as Disable | 4 | 2 |
| blend type: darken misspelt | 5 | 4 |
| blend method: sRGB off the default | 6 | 5 |
| load: table tried in reverse | 2 | 4 |
| load: NULL compared as "" | 1 | 1 |
| load: compares past the first match | 2 | 2 |
| load: byte compare instead of the given one | 6 | 4 |
| save: Area saved as "Area" | 2 | 1 |
| save: blend type fallback "default" | 1 | 2 |
| save: any non-zero method is sRGB off | 3 | 2 |
| save: Disable saved as "" | 2 | 2 |
| keys: scale_ref ignored | 2 | 1 |
| keys: absolute converted too | 3 | 1 |
| keys: bounds need the transform keys | 2 | 1 |
| save: relative inverted | 2 | 1 |
| keys: Relative = 3 in the core enum | 1 | 0 |
| shim: FromAbsolute and Absolute swapped | 0 | 1 |
| shim: compare arguments swapped | 0 | 4 |
| shim: <= 0 for == 0 | 0 | 4 |
| shim: blend method and type loaders swapped | 0 | 4 |
| shim: name copied to a new string for the compare | 0 | 4 |

Tier 1 does not reach the shims, and "Relative = 3" changes only the
core enum's discriminant, which the shim maps to the C value
explicitly, so Tier 3 does not see it. "table tried in reverse" and
"compares past the first match" give the same values (the names are
distinct) and are caught by the compare order. The proptest regression
files keep the seeds the mutants failed on.

Refs obs-rust#2114
The rust/README.md crate table now lists libobs/obs-scene-item-names.c.h
among the rust/obs-scene units, and its port table has a row for it: the
nine functions, what stays C (every obs_data_* call in its order, the
coordinate conversions, the source lookup, the transitions, the private
settings and the obs-rust#1840 crop clamp), the one read that changed (the three
has_user_value lookups asked before the choice), why the loaders take
the compare as a parameter (one astrcmpi, and no obs-util object in the
obs-scene _rust links), the compile-time checks, what the
characterization pins and the port keeps, the _rust variant of the
steps test, the real-libobs tests that see the swap and what Tier 3
compares. The crate's description and lib.rs say what it holds.
docs/rust-port/naming.md already maps libobs/obs-scene*.c.h to
rust/obs-scene. No docs/features.md line: no user-visible change.

port_comparison gets its own bench file,
benches/port_comparison/scene_item_names.rs, for 16 items: the three
loaders and both key choices (load), and the three savers (save), each
folded into a checksum both sides must match. Each loader gets its
library's astrcmpi. On x86_64 Linux (GCC, pinned to one core, load
average near 20, so noisy; medians per 16 items, two runs): load 3.25 /
2.35 us Rust against 1.68 us / 896 ns C, save 164 / 67 ns against 370 /
194 ns. Given the C astrcmpi too, the Rust load is 932 ns against
902 ns: the load gap is obs-util's astrcmpi, which the hybrid already
uses for every astrcmpi call before this port, not the table logic.
About 90 ns per item on scene collection load.

Fixes obs-rust#2114
@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 10:50
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit 57ad296 Oct 24, 2026
37 checks passed
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 the scene item save/load names in obs-scene.c to obs-scene

2 participants