Skip to content

rust: Port the task queue's route #3397

Closed

Description

@rdoupe

Unit

libobs/obs.c.h: the route of obs_queue_task(), the thread choice of obs_in_task_thread() and the level checks of obs_set_video_levels(), moved to a new libobs/obs-core-setup-rules-task.c.h as hidden functions on plain values, and ported to rust/obs-core's core_setup_rules module, beside the setup rules obs.c.h already calls.

What moves, declared in obs-core-setup-rules.h without EXPORT:

  • obs_core_setup_rules_task_step(step, type, value): the route of obs_queue_task(), one read at a time, the way obs_core_setup_rules_mix_step() does it. The steps are TYPE (the type only), UI_HANDLER (obs->ui_task_handler != NULL, asked only for OBS_TASK_UI), IN_THREAD (obs_in_task_thread(type), never asked for OBS_TASK_UI) and WAIT. The routes are UI_CALL, UI_NONE, RUN, WAIT_QUEUE, PUSH_GRAPHICS, PUSH_AUDIO, PUSH_DESTROY, DROP and UNKNOWN;
  • obs_core_setup_rules_task_thread(type): which thread obs_in_task_thread() asks about, or -1;
  • obs_core_setup_rules_levels_core(core): whether obs_set_video_levels() goes on;
  • obs_core_setup_rules_level_ok(level): isfinite(level) && level > 0.f (libobs: obs_set_video_levels accepts 0, negative and NaN white levels #2209).

The four OBS_TASK_* values are copied into the header and _Static_asserted in obs.c.h, as the other constants are.

What stays C, at the same points and under the same conditions: the handler read, the three thread-locals, os_task_queue_inside(), the UI handler call, task(param), the wait event's init, wait and destroy (with the polling fallback), the recursive obs_queue_task(type, task_wait_callback, &info, false), the locks and deque_push_back()s, os_task_queue_queue_task(), every log and the assert(false) in obs_in_task_thread().

Phase and position

Phase 6 style (#444): a behaviour-neutral extraction, then the port. Crate obs-core, module core_setup_rules, after the buffering milliseconds (#3272). Tracking: #4.

Dependencies and existing tests

  • No open PR touches obs.c.h's task code, obs-core-setup-rules.* or core_setup_rules.
  • Builds on the landed core_setup_rules module and its ported-core-setup-rules group.
  • test_task, test_pthread_init_failures, test_core_setup_rules_steps and the source profiler and audio monitoring tests go through obs_queue_task() with the four types and see the route's result, but none pins the route table. A new test_core_setup_rules_task_steps (cmocka, the moved file on its own, ASan and UBSan) lands first: every step for the four types and for -1, 4 and INT_MAX, with each value; the thread for each type; levels_core() for both values; level_ok() for 0, -0, the smallest denormal, 1, 300, 1000, FLT_MAX, both infinities and a NaN.

Notes

Two intentional differences, both fixed in the Rust:

  1. An unknown task type. obs_queue_task() with a type outside the four asks obs_in_task_thread(), which hits assert(false) in a debug build and returns false otherwise. Then, with wait, the inner call queues nothing and the caller waits forever; without wait, the task is dropped without a word. After the port, the TYPE step returns UNKNOWN for such a type, whatever wait is, and obs_queue_task() logs an error naming the type and returns: no task run, no wait, no obs_in_task_thread() call. A direct obs_in_task_thread() call with an unknown type still asserts and returns false, as today.
  2. obs_set_video_levels() before obs_startup(). It takes &obs->video and reads video->graphics with no core check, so a call with no core dereferences NULL. After the port, levels_core(false) is false, and it logs a warning and returns before it touches obs->video. With a core but no graphics, the levels are still stored as today.

Debug builds abort today on an unknown type in obs_queue_task(); after the port they log instead (from obs_queue_task() only).

Tier 3 compares every step over type values -2 to 5 plus random ints with both values, and level_ok() over every special float and random bit patterns, exactly (f32::is_finite() && x > 0.0 against isfinite(x) && x > 0.f, -0.0 and NaN included), with a mutation check.

Threads: obs_queue_task() is called from any thread; nothing moved keeps state. Only ints, bools and a float cross.

No upstream issue.

Activity

  1. added
    enhancement
    port
    on Nov 1, 2026
  2. rdoupe commented on Nov 1, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #3397.

    1. Move: the route of obs_queue_task(), the thread choice of obs_in_task_thread() and the level checks of obs_set_video_levels() into libobs/obs-core-setup-rules-task.c.h (hidden, declared in obs-core-setup-rules.h, its own group), behaviour-neutral; every read, call, lock, push and log stays in obs.c.h in its place. Checked with a move harness (gcc and clang, -O0/-O2, ASan/UBSan, planted mutants).
    2. Characterize: a new test_core_setup_rules_task_steps against the moved C.
    3. RED: obs_core::core_setup_rules Tier 1 on todo!() stubs.
    4. GREEN: the core plus its shims, the file moved into the libobs.ported-core-setup-rules group. Two intentional differences: an unknown task type is logged and refused instead of hanging a waiting caller, and obs_set_video_levels() with no core warns and returns.
    5. Tier 3: every step over type values -2 to 5 and random ints, level_ok() over special floats and random bits, with a mutation check.
    6. Docs: rust/README.md, the crate docs, a port_comparison bench for the route.

    One PR; a draft as soon as the RED commit exists, today.

  3. added
    ready
    on Nov 1, 2026
  4. rdoupe commented on Nov 1, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by PR #3405 (merged through the merge queue, merge commit b106053): the route of obs_queue_task(), the thread choice of obs_in_task_thread() and the level checks of obs_set_video_levels() were moved out of obs.c.h and ported to rust/obs-core's core_setup_rules module, with the characterization test, the Tier 1 and Tier 3 tests and the docs.

    The two intentional differences from the plan landed as written: an unknown task type is now logged and refused instead of hanging a waiting caller, and obs_set_video_levels() before obs_startup() warns and returns instead of dereferencing NULL.

    What's left: nothing from this unit, so there is no follow-up issue. The C side that stays (the handler read, the thread-locals, the queues, locks and logs) is deliberately left in obs.c.h, as the issue said. The unit has no line on the tracking issue (#4), so there was no checkbox to tick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementportready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions