Repository navigation
Description
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(): underasync_mutex, ask the cache step withasync_frames.num, the cache's key (async_cache_width/height, the convert type ofasync_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 withrefs = 1and 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, NULLcur_async_frameandprev_async_frame.
Plan, one PR into obs-source (the shape of #5916, #5926 and #5930):
- Extract the three functions (and the two key helpers) verbatim into
libobs/obs-source-async-cache.c.h(livecore-sourcegroup). No behavior change. - 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. - GREEN: safe core in
obs-source, the exports as C ABI inffi/(hidden, noEXPORT), a field shim, the extracted file moved to a reference-only ported group. - 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. - 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().
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Nov 29, 2026
Claiming: #5934 port of the async frame cache (cache_video, clean_cache, free_async_cache)
Draft PR as soon as the RED test exists.
rdoupe commentedon Nov 29, 2026
/ready
obs-source: port cache_video, clean_cache and free_async_cache to Rus…
obs-source: port cache_video, clean_cache and free_async_cache to Rust (