Skip to content

obs-core: Port the core setup rules - #2881

Merged
zackees merged 12 commits into
masterfrom
fix/1837-libobs-move-the-hotkey-binding-p
Oct 29, 2026
Merged

zackees merged 12 commits into
masterfrom
fix/1837-libobs-move-the-hotkey-binding-p

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2878

What and why

Round 13's next slice of obs.c: the pure setup decisions move to rust/obs-core (core_setup_rules), and the hybrid libobs takes them from Rust. No upstream issue; no change in behaviour.

The decisions, each asked where obs.c made it, from the value it reads at that point:

  • obs_reset_video(): no core, video active, outputs starting, the output size, the base size (the fps gate stays C);
  • obs_reset_audio2(): no core, then an active audio output (asked only when there is one); the buffering ticks (45 for 0 ms, else ms * rate / 1000 frames rounded up to ticks of 1024, in uint32_t);
  • obs_set_cmdline_args(): set once, and the copy's string and pointer-table sizes;
  • obs_find_data_file(): the libobs data directory first, then each added path in order; the first hit wins;
  • obs_remove_data_path(): the first equal path;
  • obs_get_latest_input_type_id(): the version compare, as int;
  • check_all_aoc_sources(): the OBS_SOURCE_DO_NOT_SELF_MONITOR flag;
  • obs_set_audio_monitoring_device(): the NULL/empty and availability refusals, and the same-id shortcut;
  • obs_get_video_frame_counts(): a mix counts when it is the main mix, or an encoder-only mix of the main view, and has a video.

obs.c keeps every lock, read and call: a decision made from several reads is asked one read at a time, so nothing moves out of its branch or out from under its lock. It also keeps the fps gate, every allocation, copy, free and signal, every divide by a variable and every log message. The NULL-oai return of obs_reset_audio2() stays C: it only guards the dereference.

Commits:

  1. libobs: Move the core setup rules: behaviour-neutral move to libobs/obs-core-setup-rules.c.h (hidden functions, constants checked with _Static_assert). A harness ran master's eight functions and the moved ones over a logging stand-in (every call logged with its arguments; each gate combination, 20,000 buffering inputs, 200 command lines, every path removal, 3,000 type lists, every monitoring case, 4,000 mix lists) with GCC and Clang at -O0 and -O2, with and without ASan/UBSan: identical logs in all 8 builds, on master before and after the explicit-conversions change (build(libobs): make the conversions explicit (#2625) #2877). It caught 23 of 23 planted mutants.
  2. test: Characterize the core setup rules: test_core_setup_rules_steps, with the steps compiled from the moved file and the callers exercised through the public API. Odd cases are pinned as "characterized, not endorsed": the buffering product wraps in uint32_t (22370 ms at 192 kHz buffers one tick), a version above INT_MAX is never the latest, and a negative stored argc counts as set.
  3. obs-core: Test the core_setup_rules port: Tier 1 against todo!() stubs.
  4. obs-core: Port the core setup rules: the core and the shims, in libobs.ported-core-setup-rules.
  5. obs-core: Check core_setup_rules against the C: Tier 3 with a mutation check, and the port_comparison bench.
  6. docs: Record the core_setup_rules port.
  7. test: Characterize the data file search order: test_find_data_file_order pins obs_find_data_file() through the public API. Nothing is found before a path is added; the first added path with the file wins and one without it is passed over; a removed path is no longer searched, and when added again it comes last. On Linux and the BSDs, a file in the libobs data directory is found there before any added path.
  8. obs-core: Test the data file search rule: second RED, data_file_found() against a todo!() stub.
  9. libobs: Sort the core setup rules symbol lists: the new blocks in rust-exports.map, rust-hidden.txt and rust-unexports-macos.txt are sorted.
  10. obs-core: Port the data file search rule: obs_find_data_file() asks obs_core_setup_rules_data_file_found() after the libobs lookup and after each added path. The move harness covers it as well: 512 search combinations, identical logs in all 8 builds, and both planted mutants caught.
  11. obs-core: Check the data file search against C: parity over every search across up to eight added paths.
  12. docs: Record the data file search rule.

No intentional difference from the C.

RED → GREEN

  • RED commits:
    • ab161f9 (obs-core: Test the core_setup_rules port): soldr cargo test -p obs-data --test obs-tests-core -- core_setup_rules:: fails 30 of 30 with "not yet implemented". The local test-diff gate on it ran 4937 tests: 4907 passed, 6 skipped (as on master), and only those 30 failed.
    • dfba7ac (obs-core: Test the data file search rule): the same command fails 2 of 32 (data_file_found_each_value and test_find_data_file_order) with "not yet implemented". Test-diff on it ran 4952 tests: 4950 passed, 6 skipped, and only those 2 failed.
  • GREEN:
    • Tier 1: 32/32.
    • Tier 2: test_core_setup_rules_steps 19/19 under ASan/UBSan, plus the neighbouring tests (test_obs_core_info_characterization, test_encoding_lag_rescale, test_scene_audio_actions, test_pulse_monitor_reset, test_video_reset_fps, test_main_mix_before_video, test_canvas_rules_callers, test_register_partial_callbacks, test_module_register_copy_steps): 10/10 tests, 105 cases, 0 skipped, on the C build, the hybrid libobs and libobs-c-reference.
    • Linux export sets: 1766 symbols on all three builds, the same set as master, with the 15 functions local.
    • Tier 3: 14 parity tests pass; a mutation check planted 24 mutants in the core and the parity tests caught all 24. The bench test passes.
  • Real app (UI, protocol output or logging changes): not applicable (no change in behaviour).

Runs were on b9fd397 and d2813a2 (the GREEN and Tier 3 heads, on 6577709), and the gates on the pushed head 2e3e30f: ./lint, the lint and cross lanes, the Rust tiers of ./unittest (4973 tests, 6 skipped as on master), the Windows clippy on --all-targets and the bench test pass. The Docker Tier 2 lane can't run on the build host (no access to the Docker socket), so the head isn't stamped and PR CI runs the full suite; the Tier 2 tests above ran natively. libobs-c-reference was built with ENABLE_WAYLAND=OFF: on master it still trips one conversion in obs-nix-portal-shortcut-ids.c.h, which #2894 fixes.

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): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): none

rdoupe added 12 commits October 29, 2026 05:35
Moves the pure setup decisions of obs.c.h to
libobs/obs-core-setup-rules.c.h, ahead of their port to obs-core.
Behaviour-neutral: no public function, header or signature changes.

Fourteen hidden entry points, declared in obs-core-setup-rules.h
without EXPORT (the header copies the OBS_VIDEO_* codes,
OBS_SOURCE_DO_NOT_SELF_MONITOR and AUDIO_OUTPUT_FRAMES, and obs.c
checks them with _Static_assert):
- obs_core_setup_rules_video_gate(): obs_reset_video()'s gates, one
  step at a time: no core, video active, outputs starting, the output
  size, the base size;
- obs_core_setup_rules_audio_refused(): obs_reset_audio2()'s gates, no
  core, then an active audio output (asked only when there is one);
- obs_core_setup_rules_buffer_set(), _buffer_ticks() and
  _buffer_default_ticks(): the buffering in ticks (45 for 0 ms, else
  the frames rounded up, in uint32_t);
- obs_core_setup_rules_cmdline_set(), _cmdline_len() and
  _cmdline_table(): the command line is set once, and its copy's
  string and pointer-table sizes;
- obs_core_setup_rules_data_path_match(): the data path removed;
- obs_core_setup_rules_latest_newer(): the latest input type's
  version compare, as int;
- obs_core_setup_rules_aoc_check(): the capture device check's flag;
- obs_core_setup_rules_monitor_missing() and _monitor_same(): the
  monitoring device's refusals and its same-id shortcut;
- obs_core_setup_rules_mix_step(): the frame-count rule, one read of
  the mix at a time.

obs.c keeps every lock, every read and call (each still made only
where and when it was: a decision made from several reads is asked
after each one), the fps gate, every allocation, copy, free and
signal, every divide by a variable and every log message. The file
joins libobs.core for now, as the earlier slices did before their
ports.

A scratch harness extracted master's eight functions and the moved
ones over a logging stand-in (every call they make logged with its
arguments) and ran each reset gate combination, 20,000 random
buffering inputs, 200 command lines, every data path removal, 3,000
type lists, every monitoring device case and 4,000 mix lists, with
GCC and Clang at -O0 and -O2, with and without ASan and UBSan:
identical logs in all 8 builds (184,778 lines). The one sanitizer
report, the same in both, is master's &obs->audio taken through a
NULL obs in obs_reset_audio2(). 23 of 23 planted mutants were caught.

Refs #2878.
test_core_setup_rules_steps pins the current setup rules of obs.c
before their port, in two parts.

The steps, compiled from the moved obs-core-setup-rules.c: each video
gate and their order (no core, active, starting, output size, base
size); the audio gates; the buffering ticks at 0 ms (45), below one
frame, at 1 ms, at an exact multiple of 1024 frames and past it, and
with a product above UINT32_MAX (22370 ms at 192 kHz wraps to one
tick: characterized, not endorsed); the command line set rule (a
negative argc counts as set) and its copy sizes (an argc of -1 gives
an empty table: characterized, not endorsed); the data path match;
the latest version compare, where the first of equal versions is kept
and a version above INT_MAX is never chosen (characterized, not
endorsed); the capture device flag for each bit; the monitoring
checks; and the frame-count rule for each kind of mix, with the reads
it makes.

The callers, through the public API: obs_reset_video() and
obs_reset_audio2() before obs_startup(); the size and fps gates of
obs_reset_video(); the buffering obs_reset_audio2() keeps, read back
through obs_get_audio_info2(); a command line set twice (the second
ignored) and laid out in one block; the data path removal with two
equal paths; the latest input type of registered versions 0, 2, 1,
of INT_MAX and of 0x80000000; the monitoring device refusals, the
same id and a new id; and the frame counts with no main mix. The
command line set first with an argc of 0 is pinned on the steps only:
through libobs the later copy leaks the first block, which this
sanitized test's leak checker reports.

Passes 17/17 under ASan and UBSan on libobs with the C backend, the
hybrid libobs and libobs-c-reference.

Refs #2878.
Tier 1 for the core setup rules, against todo!() stubs in a new
obs_core::core_setup_rules: video_gate(), audio_refused(),
buffer_set(), buffer_ticks(), buffer_default_ticks(), cmdline_set(),
cmdline_len(), cmdline_table(), data_path_match(), latest_newer(),
aoc_check(), monitor_missing(), monitor_same() and mix_step().

The first seventeen tests mirror test_core_setup_rules_steps one to
one: the eleven steps call the rules directly; the six caller cases
make the decisions obs_reset_video(), obs_reset_audio2(),
obs_set_cmdline_args(), obs_get_latest_input_type_id(),
obs_set_audio_monitoring_device() and obs_get_video_frame_counts()
make for the C test's calls. Edge tests cover every step and value of
the video gate and the mix rule and every combination of their
inputs, the tick bound, and the command line sizes and latest compare
at the edges of their types. Proptests check the ticks, the command
line sizes, the latest walk and the flag and compare rules for any
input.

soldr cargo test -p obs-data --test obs-tests-core --
core_setup_rules:: fails 30 of 30 with "not yet implemented".

Refs #2878.
The safe core of obs_core::core_setup_rules and its C ABI:
- video_gate(): no core fails, an active video or a starting output
  is busy, a bad output or base size is an invalid parameter;
- audio_refused(): no core, or an active audio output;
- buffer_set(), buffer_ticks(), buffer_default_ticks(): 0 ms takes
  45 ticks, any other is ms * rate / 1000 frames (wrapping in u32, as
  the C) rounded up to ticks of 1024;
- cmdline_set(), cmdline_len(), cmdline_table(): set once, and the
  copy's sizes, wrapping as the C's size_t (argc + 1 is taken as C
  converts it, so -1 gives an empty table);
- data_path_match(), monitor_same(): a compare of 0;
- latest_newer(): the version as i32 above the best so far;
- aoc_check(): OBS_SOURCE_DO_NOT_SELF_MONITOR;
- monitor_missing(): a missing name, id, character or backend;
- mix_step(): the frame-count rule, one read at a time.

The shims in src/ffi/core_setup_rules.rs only convert: the C enums
cross as 32-bit integers, and a step the C enum does not name is
answered as the C's switch falls through (the video gate goes on, the
audio gate does not refuse, the mix step comes back unchanged). They
are declared without EXPORT, so they are hidden like the C functions
(rust-exports.map, rust-hidden.txt, rust-unexports-macos.txt).

obs-core-setup-rules.c.h moves to its own ported group,
libobs.ported-core-setup-rules, with a precompiled header of its
declarations only, so the C oracle and the C test compile it alone.

Tier 1 passes 30/30. Linux export sets: 1766 symbols on the C build,
the hybrid libobs and libobs-c-reference, the same set as master on
all three, with the fourteen functions local. On the hybrid and on
libobs-c-reference, test_core_setup_rules_steps (17/17),
test_encoding_lag_rescale (6/6), test_scene_audio_actions (4/4),
test_obs_core_info_characterization, test_pulse_monitor_reset,
test_video_reset_fps, test_main_mix_before_video,
test_canvas_rules_callers, test_register_partial_callbacks and
test_module_register_copy_steps pass, none skipped.

Refs #2878.
Tier 3 for the core setup rules. oracle/core_setup_rules.c compiles
the original obs-core-setup-rules.c.h with its fourteen entry points
renamed to oracle_*, and reports the header's constants and enum
values, the obs-defs.h, obs-source.h and audio-io.h values they copy,
and the enum sizes, as the C sees them.

core_setup_rules_parity compares each shim with its oracle twin:
every step the C enums name and steps they do not, with both values;
every gate order of obs_reset_video() and every mix of
obs_get_video_frame_counts(), with the reads each makes; the ticks at
the edges of u32 and around whole ticks; the command line sizes,
compares, latest version and capture device flag at the edges of
their types; the constants; and 20,000-case proptests over any input
and over argument length lists and version lists. Nothing is excluded:
there is no intentional difference.

A mutation check planted 22 mutants in the core (each gate and step,
the audio gates, the tick rounding and wrap, the default, the
command line rules and sizes, the compares, the latest compare and
the flag): the parity tests catch all 22.

port_comparison gains core_setup_rules (buffer_ticks, latest_newer,
mix_step) in its own file; it allocates nothing, and the bench test
passes.

Refs #2878.
rust/README.md gains the libobs/obs-core-setup-rules.c.h row (the
rules, what obs.c keeps, the characterized cases, the intentional
difference and the tiers) and the unit in the obs-core row;
docs/rust-port/naming.md lists obs-core-setup-rules.c.h among the
units extracted from obs.c.h; the obs-core description and the lib.rs
module docs name the new module.

Fixes #2878.
test_core_setup_rules_steps gains test_find_data_file_order, which
pins obs_find_data_file() through the public API before its first-hit
rule moves to the core setup rules: nothing is found before a path is
added; the first added path that has the file wins; a path without it
is passed over; a removed path is no longer searched, and added again
it comes last; and on Linux and the BSDs a file in the libobs data
directory (OBS_DATA_PATH, relative in a build tree) is found there
before any added path. macOS, where find_libobs_data_file() never
fails, skips the case, as test_obs_core_info_characterization does.

Passes 18/18 under ASan and UBSan on libobs with the C backend, the
hybrid libobs and libobs-c-reference.

Refs #2878.
Tier 1 for the first-hit rule of obs_find_data_file(), against a
todo!() stub in obs_core::core_setup_rules: data_file_found(), which
obs.c will ask after the libobs data directory and after each added
path. test_find_data_file_order mirrors the new C case one to one:
the search walks the libobs directory and then the added paths in
order, stops at the first place that has the file, and looks no
further; data_file_found_each_value pins both answers.

soldr cargo test -p obs-data --test obs-tests-core --
core_setup_rules:: fails 2 of 32 (the two new tests) with "not yet
implemented".

Refs #2878.
The obs-core-setup-rules.c blocks of rust-exports.map, rust-hidden.txt
and rust-unexports-macos.txt listed the fourteen hidden functions in
header order; they are now sorted, as the shared lists ask. No change
in what is hidden or exported.

Refs #2878.
obs_find_data_file() now asks obs_core_setup_rules_data_file_found()
after find_libobs_data_file() and after each check_path(), and stops
at the first hit, as before: the libobs data directory first, then
each added path in order. obs.c keeps both lookups, the walk of the
added paths, the log message and the free; the rule only answers
whether the search ends.

data_file_found() in obs_core::core_setup_rules and its shim, hidden
like the other fourteen (rust-exports.map, rust-hidden.txt,
rust-unexports-macos.txt, in sorted place). The C test gains its steps
case, test_data_file_found, and the C oracle renames the new entry
point to oracle_obs_core_setup_rules_data_file_found, as it does the
others.

The move harness, now with obs_find_data_file() over stand-ins of both
lookups (512 combinations of where the file is and how many paths are
added), gives identical logs for master and this head with GCC and
Clang at -O0 and -O2, with and without ASan and UBSan, and catches
both planted mutants of the new rule.

Tier 1 passes 32/32. Linux export sets: 1766 symbols on the C build,
the hybrid libobs and libobs-c-reference, the same set as master,
with the fifteen functions local. test_core_setup_rules_steps (19/19)
and the nine neighbouring tests pass on the hybrid and on
libobs-c-reference, none skipped.

Refs #2878.
core_setup_rules_parity gains every_data_file_search_matches: the
shim and its oracle twin for both values, and every search
obs_find_data_file() can make over the libobs directory and up to
eight added paths (each with the file or without it) walked through
each side, with where it stopped and how many places it looked in.

A mutation check planted both wrong answers in data_file_found()
(always found, never found as found): the parity tests catch both.

Refs #2878.
The libobs/obs-core-setup-rules.c.h row of rust/README.md names
obs_core_setup_rules_data_file_found() (obs_find_data_file(): the
libobs data directory first, then each added path in order, the first
hit wins), its Tier 2 case and its Tier 3 comparison; the obs-core
row and the lib.rs module docs list the data file search.

Fixes #2878.
@rdoupe
rdoupe force-pushed the fix/1837-libobs-move-the-hotkey-binding-p branch from 85f40db to 2e3e30f Compare October 29, 2026 09:54
@rdoupe
rdoupe marked this pull request as ready for review October 29, 2026 10:24
@rdoupe
rdoupe requested a review from zackees as a code owner October 29, 2026 10:24
@zackees
zackees added this pull request to the merge queue Oct 29, 2026
Merged via the queue into master with commit 904d6eb Oct 29, 2026
38 checks passed
@zackees
zackees deleted the fix/1837-libobs-move-the-hotkey-binding-p branch October 29, 2026 11:09
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Oct 29, 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 the core setup rules in obs.c to obs-core

2 participants