Repository navigation
obs-source: port cache_video, clean_cache and free_async_cache to Rust (Fixes #5934) - #5935
Merged
Merged
Conversation
…m (Refs #5934) Move cache_video(), free_async_cache() (both declared in obs-internal.h without EXPORT), the static clean_cache() and the two key helpers async_cache_key() and async_frame_key() out of obs-source.c.h into obs-source-async-cache.c.h (live group libobs.core-source), unchanged. The new file comes before obs-source.c.h in the group, so it keeps file-local copies of get_convert_type() (the conversion plan's convert type) and obs_source_frame_decref(). MAX_UNUSED_FRAME_DURATION and MAX_ASYNC_FRAMES stay checked in obs-source.c.h. The output video worker's registration test now finds the cache in the new file. No behavior change. The new test_source_async_cache characterizes the cache through the real libobs (obs_source_output_video() on a private async source, nothing ticking), 8 cases: the first frame makes an entry holding the cache's reference only and sets the cache's key; a frame takes the first unused entry (new format, prev_frame cleared, count 0) while the unused entries left count the call; an unused entry at 5 is destroyed and erased, a used one is not counted, and with no unused entry a new one is pushed after the ageing; a size or convert-type change frees the cache (a frame someone still holds loses one reference and lives on, both slots NULL) and takes the new size, while a YUV range change keeps it; 30 queued frames free the cache and refuse the frame, leaving the key; a NULL frame frees the cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… RED (Refs #5934) The safe core's Host trait (async_mutex, async_frames.num, the cache's key fields and their stores, a frame's size, format, range, trc, prev_frame and refs, the cache array's count, entries, erase, push and resize, the queue's resize, the two frame slots, and obs_source_frame_create(), _destroy() and _copy()) and todo!() steps, with 13 Tier 1 tests over a recording model: the first frame (an empty cache reset by a zero key, a frame created with refs 1 and pushed, one more reference, the copy after the unlock); the first unused entry taken (new format, prev_frame cleared, used, count 0) while the unused entries left count the call; entries at the limit destroyed and erased from the last; used entries passed by and a new entry pushed after the ageing; a reset by width, height or convert type (every entry's frame loses a reference and is destroyed at 0, a held frame lives on, cache, queue and both slots cleared, then the new size) while a YUV range change keeps the cache; the overflow at MAX_ASYNC_FRAMES and past it (the cache freed, the key left, no copy); one below the limit cached; and the loops' count reads (free_async_cache() before each entry, clean_cache() once). The model fails a test on a field, entry or frame touched with async_mutex in the wrong state, or a frame used after its destroy. All 13 fail on the todo!() core. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Ci-Attestation: {"at":1795954254,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":76,"stamp":"ae03d794e89dec7e44262970a8cdb680","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954254,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":76,"stamp":"0db48821697bd4a9f675c961a8cc1738","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954254,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":76,"stamp":"b2613471e4ad77aefbf6c1a4c1bd5a7a","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954254,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":76,"stamp":"8735a7bcf62a5af76bfe9165114dc02b","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"general/all/client-lint","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"d00a844dcbece9a465359eb57e7e7969","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954254,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":76,"stamp":"e4284f636641b6f9037bc8e212e96734","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"a1a572dc1282e3366bda5a966d47b79c","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"2f74652241e70755b43edd81b802b7aa","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"8107244e8f2e740069303163976a67dc","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"5ef0dadfeb24f39c8170a17a76d57c75","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"15f458821c555ef4859cfa2aa7770cbc","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"b31115ee8e5eb0b07ea82ba39009b095","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"afcc85c416dc47e71fe2322dc13b19c3","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"a4fef175cd0e511237dc54435aff0c1b","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"8215e056fa536388d235dab0000aca4e","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"9762b6a97b6ab5d2449abd12d46adeff","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"473cf173c9b1a97d07c6f5364b034c7b","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"} Ci-Attestation: {"at":1795954178,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"43b5d8ef56e29670c64e5438b476aac049ac0e192dad33e0a20109b3aa770963","lane":"client-lint","parents":["7f52e4b39523208f05561cac1015637e60640f2f"],"secs":99,"stamp":"c5c1565860fc0268bbe06b89f522cfa1","tree":"e0dea05bd611cd1f02ffb5f9b17cf287f84f9ab3","v":1,"via":"run"}
rdoupe
marked this pull request as draft
November 29, 2026 12:14
…t, GREEN (Fixes #5934) cache_video(), free_async_cache() and clean_cache() are now the safe core in obs-source::async_cache over a Host trait, exported as the hidden cache_video() and free_async_cache() in obs-source::ffi::source_async_cache (rust-hidden.d). The cache step and the ageing are obs-source::frame_copy's, the convert type obs-source::conversion_plan's. The fields, async_mutex, the cache array, the queue, the frame refs and the calls of obs_source_frame_create(), _destroy() and _copy() stay C, one access per adapter, in obs-source-async-cache-fields.c.h (live group core-source, no EXPORT). The original moves to the reference-only group libobs.ported-source-async-cache. obs_source_output_video_internal()'s adapters still call cache_video() and free_async_cache() by name. Tier 3 runs the original C in obs-c-oracle (with the oracle's original cache step, ageing and conversion plan) against the Rust exports over a grid of keys, queues of 0 to 40, cache layouts, held frames, slots and both exports plus a proptest, with clobbers that rewrite the cache's key and the output frame in each destroy, and rejects ten mutants. No intentional differences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Ci-Attestation: {"at":1795956034,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":77,"stamp":"067f97e307d535d35a39434eadd02a60","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795956034,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":77,"stamp":"ad36923e4ad93f7e1c312af1566a24e1","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795956034,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":77,"stamp":"4a038b923f070dfd768e42dd020a004d","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795956034,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":77,"stamp":"1ce7919a1109f728e5c72ce098705710","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"general/all/client-lint","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"fecd16c4700f66666dc3148336b6206e","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795956034,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":77,"stamp":"0da5797b40d3b569fb88dc48fad32e3b","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955957,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"3960a227c9f39d4cab7b08b66c538315","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955957,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"b19a8f6b16314da80018d59b7e6eeeeb","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"dd623334344b9b09161d1ed3e4c5f4d8","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"11c3ecfb702dfdc6070b7c846d71de14","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"df7bee1832cdf885b28bed626c0d5f80","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"1776bd890dbbcd9eebe09d9f570bbaf1","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"30046cbdddb2314ad81d61efa68ffbb5","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"4abc04f0f4b2218c75c9352d751cde11","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"1402d73c96f8ddcffa855b7570c6131a","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"a0f88c80271c3d6a4726ee8ad2f9c15a","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"0768aee879b70fcb80fa0da94530aef2","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795955956,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"a53f1ad848fb3564fc1b87ef5a528f0992d1482c78d7e4dd97be30521e0b7fc8","lane":"client-lint","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":110,"stamp":"9de592b51a3fdaeb1fa00504839218f9","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Ci-Attestation: {"at":1795956374,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"41bc837a76468cfafdf0cbeb40cfe2086d41d50f092153314ff9661426efe3cd","lane":"client-test-x86_64-unknown-linux-gnu","parents":["ae08cd960ef60401b50b333b92b57392bae149ec"],"secs":339,"stamp":"780e8882954fa4cbe435c6ce7601d02d","tree":"7afd846f25615075519c71d9c3d552635de88b22","v":1,"via":"run"} Client-Checks: {"checks":{"base":"51ea895ba22861c78622b0140f4e8ee2ed7d3979","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-async-cache+.h.c","libobs/build/ported-source-sets/source-async-cache.json","libobs/cmake/rust-hidden.d/obs-source-source_async_cache.txt","libobs/obs-source-async-cache-fields.c.h","libobs/obs-source-async-cache.c.h","libobs/obs-source-output-video-internal-fields.c.h","libobs/obs-source.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_source_async_cache_swap_is_registered.rs","rust/obs-build/tests/native/registration/canonical_source_output_video_internal_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-async-cache.list","rust/obs-c-oracle/oracle/source_async_cache.c","rust/obs-source/src/async_cache.rs","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_async_cache.rs","rust/obs-source/src/lib.rs","rust/obs-source/tests/source/async_cache.rs","rust/obs-source/tests/source/async_cache_parity.rs","rust/obs-source/tests/source/main.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_async_cache.c","test/cmocka/tests.d/test_source_async_cache.cmake"],"head":"276afef50784f164f3c0d99a5f488158ecb3cee5","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"cca36d6c0846e131b66097e6635f191cba7183f840be4f5db23821ba2d9fb9da","tree":"7afd846f25615075519c71d9c3d552635de88b22"}}
zackees
reviewed
Nov 29, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Coordinator review: LGTM. It has the usual port shape:
- Extraction: a verbatim extraction into
obs-source-async-cache.c.hand the fields adapter. Theoutput-video-internaladapter and registration are updated for the moved functions. - Tests: a new Tier 2
test_source_async_cache.c, Tier 1async_cache.rs, Tier 3async_cache_parity.rsagainst the oracle, and canonical-swap registration tests. - Rules: a Test cost line, and no existing C test or public header edited.
- Windows (#5919): no
util_mul_div64and no wideusizeinputs, so the MSVC trap doesn't apply.
This was referenced Nov 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 #5934.
This ports the async frame cache,
cache_video(),free_async_cache()and the staticclean_cache()with theasync_cache_key()andasync_frame_key()helpers, toobs-source, in the shape of #5916, #5926 and #5930.obs_source_output_video_internal()(already Rust) callscache_video()for every frame an async source outputs (media, cameras, capture cards), andfree_async_cache()for a NULL frame. Every decision in them was already Rust: the cache step and the per-entry ageing (obs-source::frame_copy) and the convert type (obs-source::conversion_plan). What moves now is the glue on the source's fields,async_mutex, the cache array and the frame refs.What changes
libobs: extract cache_video, clean_cache and free_async_cache verbatim). The five functions move unchanged intolibobs/obs-source-async-cache.c.h(live grouplibobs.core-source). The file comes beforeobs-source.c.hin the group, so it keeps file-local copies of the 3-lineget_convert_type()andobs_source_frame_decref();MAX_UNUSED_FRAME_DURATIONandMAX_ASYNC_FRAMESstay checked inobs-source.c.h. The output video worker's registration test now finds the cache in the new file. The same commit adds the Tier 2 testtest_source_async_cache, so it first runs against the unchanged C.Hosttrait andtodo!()steps, with 13 Tier 1 tests over a recording model.obs-source::async_cache, the hidden exportscache_videoandfree_async_cacheinobs-source::ffi::source_async_cache(rust-hidden.d), one-access adapters inlibobs/obs-source-async-cache-fields.c.h(live group, noEXPORT), and the original moved to the reference-only grouplibobs.ported-source-async-cache.Kept call for call: under
async_mutex, the cache step withasync_frames.num, the cache's key (async_cache_width,async_cache_height, the convert type ofasync_cache_format,async_cache_full_rangeandasync_cache_trc) and the frame's. An overflow frees the cache, unlocks and returns NULL; the key stays. A reset frees the cache, then stores the frame's width and height. Then the frame's format, range and trc are stored. The first unused entry is taken: its frame gets the format and losesprev_frame, and the entry is marked used with count 0.clean_cache()then ages the entries from the last one. With no entry taken, a frame is created, givenrefs = 1and pushed as a used entry. The frame gets one more reference, the mutex is unlocked, andobs_source_frame_copy()copies the frame outside it.free_async_cache()drops one reference from every entry's frame (destroying it at 0), empties the cache and the queue, and clearscur_async_frameandprev_async_frame. Its loop readsasync_cache.numagain before each entry, as the C's does;clean_cache()reads it once.Callers checked (
git grep -n 'cache_video\|free_async_cache\|clean_cache'):obs_source_output_video_internal()'s adapters inobs-source-output-video-internal-fields.c.hare the only ones, in both libraries, and they call by name (Rust in hybrid, the original in the reference). Theobs-c-oraclestand-ins ofsource_output_video_internal.crename the two symbols with#define, so nothing else defines them.obs_source_frame_copy()(Rust export),obs_source_frame_create()andobs_source_frame_destroy()(static inlineinobs.h) stay calls, through the adapters. The Rust convert type isconversion_plan::convert_type(), which is whatobs_source_conversion_plan_fill()already returns in hybrid. No intentional differences; Tier 4 does not apply. Not user-visible, so no features ledger line.Tiers
Tier 1 (
rust/obs-source/tests/source/async_cache.rs, 13 tests): every access in order on a recording model, covering:MAX_ASYNC_FRAMES, and one frame below it;The model fails a test when anything is touched with
async_mutexin the wrong state, or when a frame is used after its destroy.Tier 2 (new
test_source_async_cache, every OS; it needs no video): 8 cases on a private async source throughobs_source_output_video(), against both libraries:A frame someone still holds survives each free with one reference fewer. The existing
test_source_output_video_internalruns unchanged.Tier 3 (
async_cache_parity.rswithrust/obs-c-oracle/oracle/source_async_cache.c): the original C, with the oracle's original cache step, ageing and conversion plan, against the Rust exports.Evidence
RED, on the RED commit ae08cd9 (Tier 1 against the
todo!()core):GREEN:
On the Windows oracle archive,
llvm-nm --defined-onlyshows thatsource_async_cache.odefines only its ownoracle_*andobs_source_async_cache_*symbols. It carries none of the UCRT stdio inlines, because_NO_CRT_STDIO_INLINEis set, as #5930 needed.Tier 2,
OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'test_source_async_cache|test_source_output_video_internal', which runs the whole suite on both libraries and then those tests:100% tests passed, 0 tests failed out of 1157for the C reference (OFF) and for hybrid (ON), and the repeat100% tests passed, 0 tests failed out of 2on each;100% tests passed, 0 tests failed out of 1157for the C reference (OFF) and hybrid (ON), and the repeat100% tests passed, 0 tests failed out of 2on each.Test cost: the new Rust tests run longest 0.15 s (
rejects_the_mutants, debug; 0.11 s withOBS_PARITY_CASES=reduced), and the full grid takes 0.05 s. Both modules together take 0.19 s withOBS_PARITY_CASES=reduced. Peak RSS over 23 runs of both modules is 22.7 MB (6 to 7 MB typical). The tests start no threads of their own.🤖 Generated with Claude Code