Repository navigation
obs-core: Port the task queue's route - #3405
Merged
Merged
Conversation
Behaviour-neutral extraction before the Rust port. The route of obs_queue_task(), the thread choice of obs_in_task_thread() and the level checks of obs_set_video_levels() move, as written, into four functions in the new obs-core-setup-rules-task.c.h, declared without EXPORT in obs-core-setup-rules.h beside the other setup rules: - obs_core_setup_rules_task_step(): the route, one read at a time, as obs_core_setup_rules_mix_step() does it. A UI task asks only whether there is a handler; any other asks obs_in_task_thread(), then wait, then is pushed to its queue or dropped; - obs_core_setup_rules_task_thread(): the thread obs_in_task_thread() asks about, or -1, which still reaches its assert; - obs_core_setup_rules_levels_core(): true with or without a core, as today; - obs_core_setup_rules_level_ok(): isfinite(level) && level > 0.f. obs.c keeps every read (the handler, the three thread flags, os_task_queue_inside()), every call (the handler, the task, the wait event and its fallback, the recursive call, the locks and pushes, os_task_queue_queue_task()), the assert and every log, at the same points. The two log calls behind levels_core() and the UNKNOWN route are not reached yet. The header copies the four OBS_TASK_* values, checked by _Static_asserts in obs.c. The new file has its own live group, libobs.core-setup-rules-task, in the core lib-module, with a precompiled header of math.h and obs-core-setup-rules.h only. No Rust: the hybrid libobs compiles the C too. The C, hybrid and C reference builds export the same 1767 symbols, the four new functions local (t) in each. Move harness (scratch, not committed): origin/master's three functions and the moved ones over a logging stand-in, for 11 type values from INT_MIN to INT_MAX, both waits and 64 worlds (each thread flag, the handler, the wait event), and 450 level pairs with and without graphics, in 8 builds (GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery): identical logs, 11797 lines. Eight planted mutants (unknown types refused, graphics and audio pushes swapped, the thread answer inverted, level >= 0, no isfinite(), the UI thread lost, a UI call without a handler, a wait dropped) are all caught. The 22 existing tests that reach these functions (test_task, test_core_setup_rules_steps, test_pthread_init_failures, test_video_levels_range, test_video_output_formats and the rest) pass on the C, hybrid and C reference builds, none skipped. Refs #3397. Co-authored-by: Lain <[email protected]> Co-authored-by: jpark37 <[email protected]>
test_core_setup_rules_task_steps compiles the moved obs-core-setup-rules-task.c.h into itself, with ASan and UBSan, and pins its four functions: - obs_core_setup_rules_task_step(): every step on its own for the four task types and for -1, 4 and INT_MAX with each value, a route coming back unchanged, and the whole walk for each type over every handler, thread and wait answer, with the steps it asks: a UI task reads only the handler, any other the thread and then the wait; - obs_core_setup_rules_task_thread(): each type, and -1 for the rest; - obs_core_setup_rules_levels_core(): true with or without a core; - obs_core_setup_rules_level_ok(): 0, -0, the smallest denormal, FLT_MIN, 1, 300, 1000, FLT_MAX, negative values, both infinities and both NaNs. Two cases are characterized, not endorsed: an unknown type goes on to obs_in_task_thread(), which asserts, and then, asked to wait, waits for a task it never queues; and obs_set_video_levels() goes on with no core. The test pins the route only and never runs a task or a wait. It is a new test; the existing ones are unchanged. 6 of 6 pass on the C and Rust build trees. Refs #3397.
RED for #3397. core_setup_rules gains TASK_UI, TASK_GRAPHICS, TASK_AUDIO and TASK_DESTROY, the Task steps and routes, and task_step(), task_thread(), levels_core() and level_ok(), todo!() stubs, with their Tier 1 tests: - six tests mirror test_core_setup_rules_task_steps one to one: the constants, each step, the walk of every type with the steps it asks, the thread, the core check and the levels; - but for the C test's two cases marked characterized, not endorsed, which the port fixes: an unknown task type's first step is Task::Unknown, whatever the answers, so obs_queue_task() never asks obs_in_task_thread() or waits for it; and levels_core(false) is false, so obs_set_video_levels() stops before it reads obs->video (unknown_type_never_asks_the_thread, and the each_step, routes and levels_core mirrors); - proptests: task_step_any over every step, any type and both values, and level_ok_any over every f32 bit pattern against is_finite() && > 0. OBS_PARITY_CASES=reduced soldr cargo nextest run -p obs-data --test obs-tests-core -E 'test(/obs_core::core_setup_rules::/)': 40 pass, 8 fail on "not yet implemented". Refs #3397.
GREEN for #3397. Ports libobs/obs-core-setup-rules-task.c.h to core_setup_rules::task_step, task_thread, levels_core and level_ok in rust/obs-core. obs.c stays C around them: the handler read, the thread flags, os_task_queue_inside(), the handler call, the task, the wait event and its fallback, the recursive call, the locks and pushes, os_task_queue_queue_task(), the assert and every log. Two intentional differences: - the type step routes a type outside the four to Task::Unknown, whatever the answers, and obs_queue_task() logs "obs_queue_task: unknown task type N, the task was not queued" and returns. It no longer asks obs_in_task_thread(), which asserts, and no longer waits forever for a task it never queued, or drops it silently. A direct obs_in_task_thread() call with an unknown type still asserts and returns false; - levels_core(false) is false, so obs_set_video_levels() with no core warns "obs_set_video_levels: no core, ignoring the levels" and returns before it reads obs->video. With a core but no graphics the levels are stored as before. Debug builds no longer abort on an unknown type in obs_queue_task(): the log replaces the assert there, not the check. C side: the file leaves its live group for the existing ported group, libobs.ported-core-setup-rules, whose precompiled header gains math.h for isfinite(); libobs.core-setup-rules-task, its PCH and its core lib-module entry go. The functions are not EXPORT, so the shims are hidden: rust-hidden.d's obs-core-core_setup_rules.txt fragment. Through the real libobs, headless, with no core and after obs_startup(): - obs_set_video_levels(300, 1000) with no core: libobs-c-reference dies with SIGSEGV; the hybrid libobs logs the warning and returns; - obs_queue_task(7, task, NULL, true): libobs-c-reference never returns (killed after 10 s); the hybrid logs the error and returns, and the task does not run; - obs_queue_task(7, task, NULL, false): libobs-c-reference returns without a word; the hybrid logs the error. The 48 core_setup_rules Tier 1 tests and the 19 parity tests pass. test_core_setup_rules_task_steps and the 22 tests that reach these functions pass on the C, hybrid and C reference builds, none skipped. The three libraries export the same 1767 symbols, the four new ones local in each. docs/features.md extends the no-core line and adds the unknown task type. Refs #3397.
Tier 3 for the task queue's route and the video level checks. The oracle compiles obs-core-setup-rules-task.c.h beside the other setup rules, with its four entry points renamed, and exports the task type copies, OBS_TASK_*, the enum's values and its size. The parity tests compare: - task_step for every step the enum names and past it, with the type values -2 to 5 and the edges of i32, and both values; - every walk of obs_queue_task() over the handler, thread and wait answers, with the steps it asks; - task_thread for the same types, and levels_core(true); - level_ok over both zeros, the denormal and normal edges, 1, 300, 1000, FLT_MAX, both infinities and quiet and signalling NaNs of both signs, exactly; - proptests over any step, type and value, and every f32 bit pattern. The intentional differences (#3397) are listed in the file header: an unknown type at the type step, and levels_core(false). Those two skip the oracle and are checked against the fixed contract; every later step and every other input are compared. Mutation check: dropping a type, swapping two pushes, inverting the thread answer, level >= 0, dropping is_finite(), losing the UI thread, a UI call without a handler, a wait dropped, levels_core always true and a route that moves each fail 1 to 3 of the 26 parity tests. Refs #3397.
rust/README.md's core_setup_rules row names libobs/obs-core-setup-rules-task.c.h, the four new functions, the OBS_TASK_* copies, what obs.c keeps around them, the new characterization test and the two intentional differences (#3397). The obs-core crate row, its Cargo.toml description, lib.rs and the naming.md row list the new file. The port_comparison bench gains core_setup_rules_task/task_step, in its own core_setup_rules_task.rs (#1997): a walk of four tasks on different routes. Fixes #3397.
rdoupe
force-pushed
the
fix/rust-port-the-task-queue-s-route-440
branch
from
November 1, 2026 11:01
11994da to
921e9d4
Compare
rdoupe
marked this pull request as ready for review
November 1, 2026 11:28
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 #3397
What and why
obs_queue_task()decides where a task goes: to the UI task handler, run in place on its own thread, a wait for itself, or the graphics, audio or destruction queue.obs_in_task_thread()picks the thread it asks about, andobs_set_video_levels()checks the SDR white and HDR peak levels (#2209). These are pure decisions next to the setup rules already ported torust/obs-core(core_setup_rules), so they are moved out and ported there. Two bugs are fixed in the Rust:obs_queue_task()with a type outside the four asksobs_in_task_thread(), which hitsassert(false)in a debug build and answers false otherwise. Withwait, the inner call then queues nothing and the caller waits forever; without it, the task is dropped without a word.obs_set_video_levels()beforeobs_startup(). It takes&obs->videoand readsvideo->graphicswith no core check, so a call with no core dereferences NULL.libobs: Move the task queue's route out of obs.c): four hidden functions in the newlibobs/obs-core-setup-rules-task.c.h, declared inobs-core-setup-rules.hbeside the other setup rules:obs_core_setup_rules_task_step()(the route, one read at a time, asobs_core_setup_rules_mix_step()does it),obs_core_setup_rules_task_thread(),obs_core_setup_rules_levels_core()andobs_core_setup_rules_level_ok(). The header copies the fourOBS_TASK_*values, checked by_Static_asserts inobs.c.h. The file has its own live group (libobs.core-setup-rules-task, in the core lib-module, with a PCH ofmath.handobs-core-setup-rules.h). No Rust.obs.c.hkeeps every read (the handler pointer, the three thread flags,os_task_queue_inside()), every call (the handler, the task, the wait event and its polling fallback, the recursiveobs_queue_task(type, task_wait_callback, &info, false), the locks and pushes,os_task_queue_queue_task()), the assert and every log, at the same points and under the same conditions. A UI task still reads only the handler and never asksobs_in_task_thread().Move harness: master's three functions and the moved ones over a logging stand-in, for 11 type values from
INT_MINtoINT_MAX, both waits and 64 worlds (each thread flag, the handler, the wait event), and 450 level pairs with and without graphics, built with gcc and clang at -O0 and -O2, plain and with ASan/UBSan: identical logs in all eight. Eight planted mutants (unknown types refused, the graphics and audio pushes swapped, the thread answer inverted,level >= 0, noisfinite(), the UI thread lost, a UI call without a handler, a wait dropped) are all caught. The 22 existing tests that reach these functions pass unchanged on all three libraries.test: Characterize the task queue's route): the newtest_core_setup_rules_task_stepscompiles the moved file with ASan and UBSan: every step for the four types and for -1, 4 andINT_MAXwith each value, the whole walk with the steps each type asks, the thread choice, the core check and the levels (0, -0, the smallest denormal,FLT_MAX, both infinities, NaN). It pins the two bugs as characterized, not endorsed, and never runs a task or a wait. No existing C test changes.obs-core: Test the task queue's route port):todo!()cores and their Tier 1 tests.obs-core: Port the task queue's route): the cores and their shims. The file moves into the existing ported grouplibobs.ported-core-setup-rules, whose PCH gainsmath.hforisfinite(); its live group, PCH and core lib-module entry go. The hidden shims are inrust-hidden.d/obs-core-core_setup_rules.txt.obs-core: Compare the task queue's route with C).docs: Record the task queue's route port): rust/README.md, the crate description,lib.rs, naming.md and acore_setup_rules_task/task_stepbench in its ownbenches/port_comparison/core_setup_rules_task.rs.Intentional differences from C (in the parity test header and rust/README.md):
UNKNOWN, whatever the answers, andobs_queue_task()logsobs_queue_task: unknown task type N, the task was not queuedand returns: noobs_in_task_thread()call, no wait, no task run. Debug builds used to abort here onassert(false)inobs_in_task_thread(); they now log instead, fromobs_queue_task()only. That is not a lost check: the error is logged in every build. A directobs_in_task_thread()call with an unknown type still asserts and returns false, as before;obs_set_video_levels()with no core logsobs_set_video_levels: no core, ignoring the levelsand returns before it touchesobs->video. With a core but no graphics, the levels are still stored as before.libobs-c-reference keeps the C behaviour.
Exported symbols: the C, hybrid and libobs-c-reference builds export the same 1767 symbols at the Move and at GREEN, the four new functions local (
t) in each.The moved code is Lain's (the task queue, 2019) and jpark37's (the video levels, 2022); both are credited on the Move commit. Upstream OBS has the same code; there is no upstream issue, and the bugs were found while planning this port.
RED → GREEN
RED commit: 60dff5d (
obs-core: Test the task queue's route port).OBS_PARITY_CASES=reduced soldr cargo nextest run -p obs-data --test obs-tests-core -E 'test(/obs_core::core_setup_rules::/)': 40 pass, 8 fail on "not yet implemented" (the five mirrors of the C cases that call the new functions,unknown_type_never_asks_the_thread,task_step_any,level_ok_any).--test-diffon RED fails only those 8; the lint lane passed.GREEN: the 48
core_setup_rulesTier 1 tests and 26 parity tests pass (OBS_PARITY_CASES=reducedand full). Tier 2:test_core_setup_rules_task_steps(6) and the 22 tests that reach these functions (test_task,test_core_setup_rules_steps,test_pthread_init_failures,test_video_levels_range,test_video_output_formats,test_source_profiler,test_audio_controlsand the rest) pass on the C build (23), the hybrid libobs (24, with the_rustvariant) and libobs-c-reference (24), none skipped. Tier 3 mutation check: dropping a type, swapping two pushes, inverting the thread answer,level >= 0, droppingis_finite(), losing the UI thread, a UI call without a handler, a wait dropped,levels_corealways true and a route that moves each fail 1 to 3 of the 26 parity tests. Local gates:--test-diff6060 passed, 0 failed, 6 skipped;--lane lintok;--lane crossok;soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warningsclean;soldr cargo test -p obs-c-oracle --locked --bench port_comparisonpasses. The Docker Tier 2 lane and the stamp were not run on this host, so PR CI runs the full suite. Runs were on 921e9d4 (Tier 2, the export comparison, the gates, Windows clippy and the bench check; the headless real run on the earlier GREEN, which the later rebases did not change). Both libobs unity groups the PR touches also compile with Clang and-Werrorunder the Linux Clang flags.Real app (UI, protocol output or logging changes): a small program through the real libobs, headless (private Xvfb and D-Bus, fresh HOME):
obs_set_video_levels(300, 1000)beforeobs_startup()obs_set_video_levels: no core, ignoring the levels, returnsobs_queue_task(7, task, NULL, true)afterobs_startup()obs_queue_task: unknown task type 7, the task was not queued, returns; the task does not runobs_queue_task(7, task, NULL, false)Test cost: new tests: longest 0.032 s at the full level, peak RSS 16.7 MB over 25 runs of the four new proptests, no own threads, no allocation in the cores.
Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC