Repository navigation
obs-core: Port the core setup rules - #2881
Merged
Merged
Conversation
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
force-pushed
the
fix/1837-libobs-move-the-hotkey-binding-p
branch
from
October 29, 2026 09:54
85f40db to
2e3e30f
Compare
rdoupe
marked this pull request as ready for review
October 29, 2026 10:24
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2878
What and why
Round 13's next slice of
obs.c: the pure setup decisions move torust/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.cmade 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, elsems * rate / 1000frames rounded up to ticks of 1024, inuint32_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, asint;check_all_aoc_sources(): theOBS_SOURCE_DO_NOT_SELF_MONITORflag;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.ckeeps 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-oaireturn ofobs_reset_audio2()stays C: it only guards the dereference.Commits:
libobs: Move the core setup rules: behaviour-neutral move tolibobs/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.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 inuint32_t(22370 ms at 192 kHz buffers one tick), a version aboveINT_MAXis never the latest, and a negative storedargccounts as set.obs-core: Test the core_setup_rules port: Tier 1 againsttodo!()stubs.obs-core: Port the core setup rules: the core and the shims, inlibobs.ported-core-setup-rules.obs-core: Check core_setup_rules against the C: Tier 3 with a mutation check, and theport_comparisonbench.docs: Record the core_setup_rules port.test: Characterize the data file search order:test_find_data_file_orderpinsobs_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.obs-core: Test the data file search rule: second RED,data_file_found()against atodo!()stub.libobs: Sort the core setup rules symbol lists: the new blocks inrust-exports.map,rust-hidden.txtandrust-unexports-macos.txtare sorted.obs-core: Port the data file search rule:obs_find_data_file()asksobs_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.obs-core: Check the data file search against C: parity over every search across up to eight added paths.docs: Record the data file search rule.No intentional difference from the C.
RED → GREEN
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.obs-core: Test the data file search rule): the same command fails 2 of 32 (data_file_found_each_valueandtest_find_data_file_order) with "not yet implemented". Test-diff on it ran 4952 tests: 4950 passed, 6 skipped, and only those 2 failed.test_core_setup_rules_steps19/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.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-targetsand 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 withENABLE_WAYLAND=OFF: on master it still trips one conversion inobs-nix-portal-shortcut-ids.c.h, which #2894 fixes.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable