Skip to content

rust: port cache_video, clean_cache and free_async_cache to obs-source #5934

Done

Description

@rdoupe

cache_video(), clean_cache() and free_async_cache() in libobs/obs-source.c.h (~1559-1650 on master, 14773a2) are still C. obs_source_output_video_internal() (already Rust, in obs-source::output_video_internal) calls cache_video() once for every frame an async source outputs (media, cameras, capture cards), and free_async_cache() when the queue overflows. Every decision in them is already Rust: the cache step (obs_source_frame_copy_cache_step()) and the per-entry ageing (obs_source_frame_copy_cache_clean()) in obs-source::frame_copy. What is left is the glue on the source's fields, async_mutex, the cache array and the frame refs.

Behavior the port keeps, call for call:

  • cache_video(): under async_mutex, ask the cache step with async_frames.num, the cache's key (async_cache_width/height, the convert type of async_cache_format/full_range/trc) and the frame's key. OVERFLOW: free_async_cache(), unlock, return NULL (the running clock stays). RESET: free_async_cache(), then take the frame's width and height. Then store the frame's format, full range and trc; take the first unused cache entry (format, prev_frame = false, used, unused count 0); clean_cache(); if no entry was free, create a frame of the format and size with refs = 1 and push it; add one ref; unlock; obs_source_frame_copy() outside the lock.
  • clean_cache(): from the last entry to the first, age it; when counted store the unused count, and on drop destroy the frame and erase the entry.
  • free_async_cache(): drop one ref from every cache entry's frame, empty the cache and the frame queue, NULL cur_async_frame and prev_async_frame.

Plan, one PR into obs-source (the shape of #5916, #5926 and #5930):

  1. Extract the three functions (and the two key helpers) verbatim into libobs/obs-source-async-cache.c.h (live core-source group). No behavior change.
  2. Tier 1 RED in obs-source's existing category binary against a todo!() core over a trait for the field reads/writes, the cache array, the mutex and the calls.
  3. GREEN: safe core in obs-source, the exports as C ABI in ffi/ (hidden, no EXPORT), a field shim, the extracted file moved to a reference-only ported group.
  4. Tier 3 parity against the original C in obs-c-oracle: the same caches, queues, keys and frames through both, comparing fields, the cache, refs, calls and their order.
  5. Tier 2: a new cmocka test that outputs async frames through the hybrid libobs and the C reference (first frame, reuse, a size change resetting the cache, overflow past 30 queued frames, entries aged out). The existing async tests run unchanged.

It follows the async tick port (#5930, in the merge queue), whose get_closest_frame() hunk sits right after cache_video().

Activity

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

    @rdoupe
    CollaboratorAuthor

    Claiming: #5934 port of the async frame cache (cache_video, clean_cache, free_async_cache)

    1. Extract verbatim into libobs/obs-source-async-cache.c.h, on top of obs-source: port async_tick and its filter_frame and get_closest_frame steps to Rust (Fixes #5929) #5930 (in the merge queue; its get_closest_frame hunk is next to cache_video).
    2. Tier 1 RED against a todo!() core, then GREEN with the hidden exports and field shim.
    3. Tier 3 parity against the original C, and a new Tier 2 cmocka test through both libraries.
      Draft PR as soon as the RED test exists.
  3. rdoupe commented on Nov 29, 2026

    @rdoupe
    CollaboratorAuthor

    /ready

  4. added
    ready
    on Nov 29, 2026
  5. added a commit that references this issue on Nov 29, 2026
    183f7dc
  6. added a commit that references this issue on Nov 29, 2026
    5234857
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