From 5ef60c5af703cd31cf7dc146991b93bb8762c2f3 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Wed, 18 Nov 2026 23:12:47 -0800 Subject: [PATCH 1/2] test: mirror type catalog enumeration against Rust stub (Refs #5202) --- rust/obs-core/src/lib.rs | 1 + rust/obs-core/src/type_catalog_enum.rs | 11 +++ rust/obs-core/tests/obs_core/main.rs | 1 + .../tests/obs_core/type_catalog_enum.rs | 73 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 rust/obs-core/src/type_catalog_enum.rs create mode 100644 rust/obs-core/tests/obs_core/type_catalog_enum.rs diff --git a/rust/obs-core/src/lib.rs b/rust/obs-core/src/lib.rs index cf877a2f34..561713a0d9 100644 --- a/rust/obs-core/src/lib.rs +++ b/rust/obs-core/src/lib.rs @@ -178,6 +178,7 @@ pub mod source_load; pub mod source_profiler; pub mod source_type_enum; pub mod tick_callbacks; +pub mod type_catalog_enum; pub mod ui_task_handler; pub mod video_copy_plan; pub mod video_frame_copy; diff --git a/rust/obs-core/src/type_catalog_enum.rs b/rust/obs-core/src/type_catalog_enum.rs new file mode 100644 index 0000000000..39061bc5dd --- /dev/null +++ b/rust/obs-core/src/type_catalog_enum.rs @@ -0,0 +1,11 @@ +//! Bounds and borrowed output for the six independent registered type catalogs. + +pub fn enumerate( + count: usize, + index: usize, + read: impl FnOnce(usize) -> T, + write: impl FnOnce(T), +) -> bool { + let _ = (count, index, read, write); + todo!("#5202: swap type catalog enumeration") +} diff --git a/rust/obs-core/tests/obs_core/main.rs b/rust/obs-core/tests/obs_core/main.rs index 4add90442f..f0d07f2135 100644 --- a/rust/obs-core/tests/obs_core/main.rs +++ b/rust/obs-core/tests/obs_core/main.rs @@ -141,6 +141,7 @@ mod source_type_enum; mod source_type_enum_parity; mod tick_callbacks; mod tick_callbacks_parity; +mod type_catalog_enum; mod ui_task_handler; mod ui_task_handler_parity; mod video_copy_plan; diff --git a/rust/obs-core/tests/obs_core/type_catalog_enum.rs b/rust/obs-core/tests/obs_core/type_catalog_enum.rs new file mode 100644 index 0000000000..021ae183a1 --- /dev/null +++ b/rust/obs-core/tests/obs_core/type_catalog_enum.rs @@ -0,0 +1,73 @@ +//! Tier 1 mirrors test_type_catalog_enum.c using only test-owned IDs. +use obs_core::type_catalog_enum; +use std::cell::Cell; + +const IDS: [[&str; 2]; 6] = [ + ["catalog_input_z", "catalog_input_a"], + ["catalog_filter_z", "catalog_filter_a"], + ["catalog_transition_z", "catalog_transition_a"], + ["catalog_output_z", "catalog_output_a"], + ["catalog_encoder_z", "catalog_encoder_a"], + ["catalog_service_z", "catalog_service_a"], +]; +const SENTINELS: [&str; 6] = [ + "input untouched", "filter untouched", "transition untouched", + "output untouched", "encoder untouched", "service untouched", +]; + +fn query<'a>(registry: &[&'a str], index: usize, output: Option<&Cell<&'a str>>) -> bool { + type_catalog_enum::enumerate( + registry.len(), index, |i| registry[i], + |id| output.expect("success requires output").set(id), + ) +} +fn end(registry: &[&str], index: usize, sentinel: &str) { + let id = Cell::new(sentinel); + assert!(!query(registry, index, Some(&id))); + assert!(std::ptr::eq(id.get(), sentinel)); + assert!(!query(registry, index, None)); +} +fn count(registry: &[&str]) -> usize { + let output = Cell::new(""); + (0..=registry.len()).take_while(|&i| query(registry, i, Some(&output))).count() +} +#[test] +fn test_type_catalog_enum_empty_catalogs() { + for sentinel in SENTINELS { + for index in [0, usize::MAX] { end(&[], index, sentinel); } + } +} +#[test] +fn test_type_catalog_enum_populated_catalogs() { + // Source registration owns a versioned copy; the source and per-kind + // catalogs share that ID. Other catalogs borrow the caller's ID. + let source_ids: Vec> = IDS[..3].iter() + .map(|ids| ids.iter().map(|id| (*id).to_owned()).collect()).collect(); + let mut catalogs: [Vec<&str>; 6] = std::array::from_fn(|_| Vec::new()); + let mut added = [0; 6]; + let mut borrowed = [[""; 2]; 6]; + for entry in 0..2 { + for c in 0..6 { + let id = if c < 3 { source_ids[c][entry].as_str() } else { IDS[c][entry] }; + catalogs[c].push(id); + added[c] += 1; + for other in 0..6 { assert_eq!(count(&catalogs[other]), added[other]); } + let output = Cell::new(SENTINELS[c]); + assert!(query(&catalogs[c], entry, Some(&output))); + assert_eq!(output.get(), IDS[c][entry]); + borrowed[c][entry] = output.get(); + } + } + for c in 0..6 { + for entry in 0..2 { + let output = Cell::new(SENTINELS[c]); + assert!(query(&catalogs[c], entry, Some(&output))); + assert!(std::ptr::eq(output.get(), borrowed[c][entry])); + assert_eq!(output.get(), IDS[c][entry]); + let origin = if c < 3 { source_ids[c][entry].as_str() } else { IDS[c][entry] }; + assert!(std::ptr::eq(output.get(), origin)); + } + for index in [2, 3, usize::MAX] { end(&catalogs[c], index, SENTINELS[c]); } + assert_eq!(borrowed[c][0], IDS[c][0]); + } +} From 543b6c9a5a2c5c23db8640186466fa3a097aae71 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Wed, 18 Nov 2026 23:15:02 -0800 Subject: [PATCH 2/2] obs-core: swap six type catalog readers to safe Rust (Refs #5202) Ci-Attestation: {"at":1795084865,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":156,"stamp":"c7280e301cb64bd778e2ee19a5671b4b","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084865,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":156,"stamp":"ea2307feb6077a9cafdb5f074ff7037f","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084865,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":156,"stamp":"09dd43e85779d9a751ca8bc35f058489","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084865,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":156,"stamp":"0a4293c7d7b92209b1e656b03341afa7","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"general/all/client-lint","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"67a81fdf6aacd1ce97c995291e9a398d","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084865,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":156,"stamp":"18a22b8fc447dd8eaed986a4eb25d469","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"2a3591f6a273f7ebbd322ed232a9097b","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084709,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"311724f7ac117ea67da667245e8d4e9a","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"77ba51b59c38308cd9f1b7c91c639aee","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"2ebfa27a8324e164bf2604d713b39ea7","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"55b1f6fd926bee4df21a892e441c7f62","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"9bcb6fa1528fdd3157e75fda63bf82dc","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"23f4c5df461142d6325bb40fb9cb8e5b","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"f0c85ae578b694968a8b561624929895","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"dec52f7704cefa5da7111702758296cc","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"f7c260f5d55cca038b5f2eb4abc19d47","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"f2fa977c88d826e12b729d48f50bece4","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795084708,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"893e9e1419b08eb95677079072b074710011c49c67d600e7375a71aaee7ba880","lane":"client-lint","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":185,"stamp":"55aaebff2cc936b5f0483610488093c3","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Ci-Attestation: {"at":1795085618,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"92275d51d2a2c4976b03ea63f259ce536fbf3568034feeb6e05ab5f736bc46f9","lane":"client-test-x86_64-unknown-linux-gnu","parents":["5ef60c5af703cd31cf7dc146991b93bb8762c2f3"],"secs":751,"stamp":"752e99149229eefe7929d6593cf02e23","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e","v":1,"via":"run"} Client-Checks: {"checks":{"base":"d8f5045f0882951a2806b9decaf82b97cac656b6","coverage":"all-tracked-applicable-files","diff":[".github/workflows/build-project.yaml","ci/test_ci_job_timeouts.py","ci/test_tier2_apt_cache.py","libobs/build/libobs.core+.h.c","libobs/build/libobs.graphics-image-max-size+.h.c","libobs/build/libobs.media+.h.c","libobs/build/libobs.media-image-orientation-fields+.h.c","libobs/build/libobs.media-texture-file-data-convert+.h.c","libobs/build/libobs.media-texture-file-data-session+.h.c","libobs/build/libobs.ported-hotkey-unregister-entry+.h.c","libobs/build/libobs.ported-type-catalog-enum+.h.c","libobs/build/libobs.ported-video-level-queries+.h.c","libobs/build/modules.d/graphics.json","libobs/build/modules.d/media.json","libobs/build/ported-source-sets/hotkey-unregister-entry.json","libobs/build/ported-source-sets/type-catalog-enum.json","libobs/build/ported-source-sets/video-level-queries.json","libobs/build/source-sets.d/LIBOBS_SOURCES.json","libobs/cmake/rust-exports.d/obs-core-type_catalog_enum.txt","libobs/cmake/rust-exports.d/obs-core-video_level_queries.txt","libobs/cmake/rust-exports.d/obs-hotkey-unregister_entry.txt","libobs/cmake/rust-hidden.d/obs-core-video_level_queries.txt","libobs/cmake/rust-hidden.d/obs-hotkey-unregister_entry.txt","libobs/graphics/graphics-ffmpeg.c.h","libobs/graphics/graphics-image-max-size.c.h","libobs/graphics/graphics-texture-file-data-adapter.c.h","libobs/graphics/graphics-texture-file-data-convert.c.h","libobs/graphics/graphics.c.h","libobs/obs-hotkey-unregister-entry-fields.c.h","libobs/obs-type-catalog-enum-fields.c.h","libobs/obs-video-level-queries-fields.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_type_catalog_enum_swap_is_registered.rs","rust/obs-build/tests/native/registration/headless_characterizations_expected.json","rust/obs-build/tests/native/registration/portal_output_expected.json","rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_video_level_queries.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_enum.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_press.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_trigger.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_binding_press_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_getters_characterization.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_load.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_pair_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_press_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_portal_shortcuts.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_wayland_hotkeys.json","rust/obs-build/tests/native/registration/rust_static_entries.rs","rust/obs-c-oracle/oracle.d/hotkey_unregister_entry.list","rust/obs-c-oracle/oracle/hotkey_unregister_entry.c","rust/obs-c-oracle/oracle/hotkey_unregister_entry_links.c","rust/obs-c-oracle/oracle/source_deinterlace_links.c","rust/obs-c-oracle/oracle/type_catalog_enum.c","rust/obs-c-oracle/oracle/video_level_queries.c","rust/obs-core/src/ffi/mod.rs","rust/obs-core/src/ffi/type_catalog_enum.rs","rust/obs-core/src/ffi/video_level_queries.rs","rust/obs-core/src/lib.rs","rust/obs-core/src/type_catalog_enum.rs","rust/obs-core/src/video_level_queries.rs","rust/obs-core/tests/obs_core/main.rs","rust/obs-core/tests/obs_core/type_catalog_enum.rs","rust/obs-core/tests/obs_core/type_catalog_enum_parity.rs","rust/obs-core/tests/obs_core/video_level_queries.rs","rust/obs-core/tests/obs_core/video_level_queries_parity.rs","rust/obs-hotkey/src/ffi/mod.rs","rust/obs-hotkey/src/ffi/unregister_entry.rs","rust/obs-hotkey/src/lib.rs","rust/obs-hotkey/src/unregister_entry.rs","rust/obs-hotkey/tests/hotkey/main.rs","rust/obs-hotkey/tests/hotkey/unregister_entry.rs","rust/obs-hotkey/tests/hotkey/unregister_entry_parity.rs","test/cmocka/build/test-graph.json","test/cmocka/test_image_max_texture_size.c","test/cmocka/tests.d/test_image_max_texture_size.cmake","test/cmocka/tests.d/video_level_queries_link_support.cmake","test/cmocka/video-info-query-link-support.c"],"head":"6fecfcb5ee28b234ad1b9f2b85a3fac1e5e3567d","tools":{"orchestrator-python":"3.13.15 (main, Aug 14 2026, 15:34:59) [Clang 22.1.3 ]","schema-dependencies":"3.13.15 (main, Aug 14 2026, 15:34:59) [Clang 22.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\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ISO8859X Regexps Automata RelaxNG Schemas Modules Debug"},"tracked-digest":"e7bb6e30cb71e420ac294fdcc74e9f37bd464d161d400636c8c5bf524ef9c18e","tree":"9f2cadadcadfdfb8b938e574df7c5b5b5c61fe7e"}} --- libobs/build/libobs.core+.h.c | 2 +- .../libobs.ported-type-catalog-enum+.h.c | 4 + .../ported-source-sets/type-catalog-enum.json | 5 + .../obs-core-type_catalog_enum.txt | 6 + libobs/obs-type-catalog-enum-fields.c.h | 49 ++++++++ rust/README.md | 1 + rust/obs-build/tests/native.rs | 3 + ...al_type_catalog_enum_swap_is_registered.rs | 34 +++++ rust/obs-c-oracle/oracle/type_catalog_enum.c | 118 ++++++++++++++++++ rust/obs-core/src/ffi/mod.rs | 1 + rust/obs-core/src/ffi/type_catalog_enum.rs | 112 +++++++++++++++++ rust/obs-core/src/type_catalog_enum.rs | 3 +- rust/obs-core/tests/obs_core/main.rs | 1 + .../tests/obs_core/type_catalog_enum.rs | 46 +++++-- .../obs_core/type_catalog_enum_parity.rs | 116 +++++++++++++++++ test/cmocka/video-info-query-link-support.c | 1 + 16 files changed, 488 insertions(+), 14 deletions(-) create mode 100644 libobs/build/libobs.ported-type-catalog-enum+.h.c create mode 100644 libobs/build/ported-source-sets/type-catalog-enum.json create mode 100644 libobs/cmake/rust-exports.d/obs-core-type_catalog_enum.txt create mode 100644 libobs/obs-type-catalog-enum-fields.c.h create mode 100644 rust/obs-build/tests/native/registration/canonical_type_catalog_enum_swap_is_registered.rs create mode 100644 rust/obs-c-oracle/oracle/type_catalog_enum.c create mode 100644 rust/obs-core/src/ffi/type_catalog_enum.rs create mode 100644 rust/obs-core/tests/obs_core/type_catalog_enum_parity.rs diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index 2914e6bed7..a980457ecf 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -52,7 +52,7 @@ #include "libobs/obs-set-locale.c.h" #include "libobs/obs-set-output-source-fields.c.h" #include "libobs/obs-shutdown-detach.c.h" -#include "libobs/obs-type-catalog-enum.c.h" +#include "libobs/obs-type-catalog-enum-fields.c.h" #include "libobs/obs-ui-task-handler-fields.c.h" #include "libobs/obs-video-info-query-fields.c.h" #include "libobs/obs-video-level-queries.c.h" diff --git a/libobs/build/libobs.ported-type-catalog-enum+.h.c b/libobs/build/libobs.ported-type-catalog-enum+.h.c new file mode 100644 index 0000000000..2a5ef19880 --- /dev/null +++ b/libobs/build/libobs.ported-type-catalog-enum+.h.c @@ -0,0 +1,4 @@ +/* Unity group (BUILD.md): original type catalog readers for C reference. */ +#include "libobs/build/libobs.pch.h" + +#include "libobs/obs-type-catalog-enum.c.h" diff --git a/libobs/build/ported-source-sets/type-catalog-enum.json b/libobs/build/ported-source-sets/type-catalog-enum.json new file mode 100644 index 0000000000..5b0b695e8a --- /dev/null +++ b/libobs/build/ported-source-sets/type-catalog-enum.json @@ -0,0 +1,5 @@ +{ + "LIBOBS_PORTED_SOURCES": [ + "build/libobs.ported-type-catalog-enum+.h.c" + ] +} diff --git a/libobs/cmake/rust-exports.d/obs-core-type_catalog_enum.txt b/libobs/cmake/rust-exports.d/obs-core-type_catalog_enum.txt new file mode 100644 index 0000000000..b6813bf61f --- /dev/null +++ b/libobs/cmake/rust-exports.d/obs-core-type_catalog_enum.txt @@ -0,0 +1,6 @@ +obs_enum_encoder_types +obs_enum_filter_types +obs_enum_input_types +obs_enum_output_types +obs_enum_service_types +obs_enum_transition_types diff --git a/libobs/obs-type-catalog-enum-fields.c.h b/libobs/obs-type-catalog-enum-fields.c.h new file mode 100644 index 0000000000..3df5dac138 --- /dev/null +++ b/libobs/obs-type-catalog-enum-fields.c.h @@ -0,0 +1,49 @@ +#include "libobs/build/libobs.pch.h" + +/* These adapters only borrow fields of real C layouts. Selection numbers are + * private to the Rust shim; bounds and output writes stay in the safe core. */ +const void *obs_type_catalog_enum_registry_fields(const struct obs_core *core, uint32_t catalog, size_t *count); +const void *obs_type_catalog_enum_registry_fields(const struct obs_core *core, uint32_t catalog, size_t *count) +{ + switch (catalog) { + case 0: + *count = core->input_types.num; + return core->input_types.array; + case 1: + *count = core->filter_types.num; + return core->filter_types.array; + case 2: + *count = core->transition_types.num; + return core->transition_types.array; + case 3: + *count = core->output_types.num; + return core->output_types.array; + case 4: + *count = core->encoder_types.num; + return core->encoder_types.array; + case 5: + *count = core->service_types.num; + return core->service_types.array; + default: + abort(); + } +} + +const char *const *obs_type_catalog_enum_id_fields(const void *array, uint32_t catalog, size_t index); +const char *const *obs_type_catalog_enum_id_fields(const void *array, uint32_t catalog, size_t index) +{ + switch (catalog) { + case 0: + case 1: + case 2: + return &((const struct obs_source_info *)array)[index].id; + case 3: + return &((const struct obs_output_info *)array)[index].id; + case 4: + return &((const struct obs_encoder_info *)array)[index].id; + case 5: + return &((const struct obs_service_info *)array)[index].id; + default: + abort(); + } +} diff --git a/rust/README.md b/rust/README.md index 140c83098f..9ae769b5cf 100644 --- a/rust/README.md +++ b/rust/README.md @@ -550,6 +550,7 @@ and compares their exported symbols. `OBS_LIBOBS_BACKEND=C` is temporary rollbac | `libobs/obs-video-frame-timing.c.h` | `obs-core::video_frame_timing` | Swapped in hybrid `libobs` (group `libobs.ported-video-frame-timing`). Two pure functions on plain values, declared in `obs-video-frame-timing.h` without `EXPORT` and hidden: `obs_video_frame_timing_tick` (`tick_sources()`: the last tick time one interval back on the first frame, the wrapping delta, and its seconds as `(float)((double)delta / 1e9)`) and `obs_video_frame_timing_stats` (the end of `obs_graphics_thread_loop()`: the render time, frame time and frame sums, and at one second of frame time the `double` fps, the average render time and the reset). `obs-video.c` keeps the clock, the tick callbacks and the source list with their mutexes, the profiler and `obs_video_stats_set_timing()`. Intentional difference, unreachable: a report with the frame count wrapped to 0 gives an average of 0 (the C divides by zero). Tier 1 ports `test_video_frame_timing_steps`; Tier 3 parity compares the float and double results bit for bit (#2754). | | `libobs/obs-video-graphics-tasks.c.h` | `obs-core::video_graphics_tasks` | Swapped in hybrid `libobs` (group `libobs.ported-video-graphics-tasks`, the original C as the C reference). `execute_graphics_tasks()`, the graphics thread's per-frame drain of the `OBS_TASK_GRAPHICS` queue, is a C bridge to `obs_video_graphics_tasks_execute`, declared in `obs-video-graphics-tasks.h` without `EXPORT` and hidden. The bridge passes the core and accessors for `task_mutex`, `tasks.size` and a pop of one `struct obs_task_info`, so the deque and its mutex stay C-owned and the Rust reads no private layout. The Rust takes the mutex; while the queue is not empty it pops the oldest task, releases the mutex, runs the task and takes the mutex again; then it releases it, so a task queued meanwhile runs in the same pass. The unchanged `test_video_graphics_tasks` runs against hybrid `libobs` and the C reference. Tier 3 runs the original C and the Rust over the same real core, mutex and deque with trees of tasks that queue tasks, and compares the tasks run, in order, whether the mutex was held for each, the drained queue and the released mutex. One intentional difference: a NULL task, which `obs_queue_task()` does not refuse and the C calls and crashes on, is skipped, as the audio task drain does (`null_task_is_skipped`). | | `libobs/obs-shutdown-detach.c.h` | `obs-core::shutdown_detach` | Swapped in hybrid `libobs` (group `libobs.ported-shutdown-detach`, the original C as the C reference). `obs_shutdown_detach_scene_items()`, which `obs_free_data()` calls once at shutdown so a scene the host left alive releases what its items hold before the source tables are walked (#3458), is a C bridge to `obs_shutdown_detach_scene_items_run`, declared in `obs-shutdown-detach.h` without `EXPORT` and hidden. The bridge passes the core's `struct obs_core_data` and a table of calls: the lock and unlock of `sources_mutex`, a walk of the UUID source table (the `HASH_ITER` stays in C), `obs_source_get_ref`, `obs_scene_from_source`, `obs_group_from_source`, `obs_scene_enum_items`, `obs_sceneitem_remove`, `obs_source_release` and the wait on `obs->destruction_task_thread`, so the Rust reads no private layout and names no libobs symbol. The Rust keeps the C's order: under the lock, a strong reference to every table member it can get (a failed one is skipped); then, unlocked, each member's items removed when it is a scene, or else a group (`obs_shutdown_remove_scene_item` always continues); then every snapshot reference released, only after all removals; then waits until the queue reports no work, with no bound. The unchanged `test_shutdown_detach` runs against hybrid `libobs` and the C reference. Tier 3 runs the original C and the Rust, through the production bridge, over the same real UUID table, with the libobs calls going to one model of sources, scenes, groups and the destruction queue, and compares every call (locks, references, checks, enumerations, removals, releases, waits) and the end state over random graphs with failed references, any table order and a queue that reports more work. No intentional differences. | +| `libobs/obs-type-catalog-enum.c.h` | `obs-core::type_catalog_enum` | Six independent ordered borrowed-ID catalogs reuse source enumeration bounds/output machinery. Private C field adapters preserve layout; unchanged characterization, safe mirrors and original-C differential/mutation coverage preserve pointer identity and no-write failures. No intentional differences; Tier 4 inapplicable. | | `libobs/obs-video-info-query.c.h` | `obs-core::video_info_query` | Swapped in hybrid libobs (#5179): core, graphics and main-mix gates retain their short-circuit order and leave output untouched on failure; success copies the complete stored struct and borrowed module pointer. Unchanged C characterization, real-header layout and differential parity. No intentional differences; Tier 4 does not apply. | | `libobs/obs-video-output-step.c.h` | `obs-core::video_output_step` | Swapped in hybrid `libobs` (group `libobs.ported-video-output-step`). Ten pure functions on plain values, declared in `obs-video-output-step.h` without `EXPORT` and hidden: `obs_video_step_activation` (`update_active_state()`: a counter above 0 is active; the base, raw and GPU frame data clears for each that was not active and is now, and the new was flags), `obs_video_step_stage` (`stage_output_texture()`: copy surface 0 from the output texture without GPU conversion, `channel_count` surfaces from the convert textures once converted, else nothing), `obs_video_step_queue`, `_queue_copy_uv` and `_queue_count` (`queue_frame()`: a duplicate when no frame is free or a repeat finds one queued, else a copy for raw output or a repeat, else a swap; the separate UV copy unless the host's NV12 planes share a texture; the count left), `obs_video_step_render_targets` and `obs_video_step_render` (`render_video()`: outputs for raw or GPU, from the encode textures for GPU; then convert, encode, stage), and `obs_video_step_ring`, `_download` and `_output` (`output_frame()`: the texture before and after `cur_texture`, wrapping at exactly `NUM_TEXTURES`; download and output for raw output). `obs-video.c.h` keeps every `gs_*` call in its order and under its conditions, the deques (and the `deque_data()` NULL check when texture-based encoding stops), `os_sem_post()`, the texture-frame host calls, `obs_host_nv12_planes_share_texture()` and `obs_host_gpu_encode_surfaces()` (it passes their answers, asked where they were), `download_frame()`'s maps, the mix list and its mutex, and both atomic loads (it passes the loaded `long`s). The decisions are split where the C asked a host or read a field between them, so no call moves. The six structs cross as `#[repr(C)]` mirrors whose layout Tier 3 checks; the queue action as its C value. Intentional difference, unreachable: where the C's `int` arithmetic overflows (undefined: `--count` at `INT_MIN`, the ring's prev of `INT_MIN` and next of `INT_MAX`), the port wraps. `test_video_output_step_steps` compiles the C into itself; it has no `_rust` variant, for the reason `test_video_copy_plan_steps` has none (the shims' archive member needs libobs). `test_video_output_formats`, `test_raw_output_video_reset`, `test_encoding_lag_rescale`, `test_scaled_mix_alpha`, `test_video_output_plan` and the texture encoder tests see the swap through the hybrid libobs. Tier 3 compares every result exactly over every flag, the counters at the `long` and `int` edges, channel counts and queue sizes at the `size_t` edges, counts and ring values over every `int` from -200,000 to 200,000 and the ends, and proptests over full-range values. | | `libobs/obs-video-pacing.c.h` | `obs-core::video_pacing` | Swapped in hybrid `libobs` (group `libobs.ported-video-pacing`). Two pure functions on plain values, declared in `obs-video-pacing.h` without `EXPORT` and hidden: `obs_video_pacing_step` (`video_sleep()`: after a sleep that reached the next frame time, the next frame time and 1; after a late wake-up, the clock difference read as `int64_t`, at least one interval, the whole intervals truncated to `int` as the C cast does, and the frame time that many intervals on, wrapping) and `obs_video_pacing_group_starts` (all encoders of a ready encoder's group started and no start timestamp yet). `obs-video.c` keeps the sleep, the clock read, the stats, the encoder groups and their mutexes, and the frame info pushes. Intentional difference, unreachable: an interval of 0 after a late wake-up gives a count of 0 and the frame time unchanged (the C divides by zero; libobs computes the interval from the frame rate). Tier 1 ports `test_video_pacing_steps`; Tier 3 parity is exhaustive over the edges and full range by proptest (#2738). | diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index 9c663eda48..a056e3aa52 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -5510,3 +5510,6 @@ pub(crate) mod core_module_manifest; #[path = "native/registration/canonical_source_update_properties_swap_is_registered.rs"] mod canonical_source_update_properties_swap_is_registered; + +#[path = "native/registration/canonical_type_catalog_enum_swap_is_registered.rs"] +mod canonical_type_catalog_enum_swap_is_registered; diff --git a/rust/obs-build/tests/native/registration/canonical_type_catalog_enum_swap_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_type_catalog_enum_swap_is_registered.rs new file mode 100644 index 0000000000..2fba6dd650 --- /dev/null +++ b/rust/obs-build/tests/native/registration/canonical_type_catalog_enum_swap_is_registered.rs @@ -0,0 +1,34 @@ +use super::*; + +#[test] +fn canonical_type_catalog_enum_swap_is_registered() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + let graph = + obs_build::validation::graph::Graph::load(&root.join("test/cmocka/build/test-graph.json")) + .unwrap(); + let characterization = &graph.targets["test_type_catalog_enum"]; + assert!( + matches!(&characterization.sources[0], obs_build::validation::graph::Source::Path(p) + if p == "test/cmocka/test_type_catalog_enum.c") + ); + let core = fs::read_to_string(root.join("libobs/build/libobs.core+.h.c")).unwrap(); + assert!(core.contains("obs-type-catalog-enum-fields.c.h")); + assert!(!core.contains("\"libobs/obs-type-catalog-enum.c.h\"")); + let unit: serde_json::Value = serde_json::from_str( + &fs::read_to_string(root.join("libobs/build/ported-source-sets/type-catalog-enum.json")) + .unwrap(), + ) + .unwrap(); + assert_eq!( + unit["LIBOBS_PORTED_SOURCES"], + serde_json::json!(["build/libobs.ported-type-catalog-enum+.h.c"]) + ); + let reference = + fs::read_to_string(root.join("libobs/build/libobs.ported-type-catalog-enum+.h.c")).unwrap(); + assert!(reference.contains("\"libobs/obs-type-catalog-enum.c.h\"")); + // #5190's shared archive and canonical graph already consume this real + // wrapper. Adding a port must not introduce another fixed consumer list. + let support = + fs::read_to_string(root.join("test/cmocka/video-info-query-link-support.c")).unwrap(); + assert!(support.contains("\"libobs/obs-type-catalog-enum-fields.c.h\"")); +} diff --git a/rust/obs-c-oracle/oracle/type_catalog_enum.c b/rust/obs-c-oracle/oracle/type_catalog_enum.c new file mode 100644 index 0000000000..93bac0dc6f --- /dev/null +++ b/rust/obs-c-oracle/oracle/type_catalog_enum.c @@ -0,0 +1,118 @@ +/* Original six bodies, real-header catalog fixtures and production adapters. */ +#include "libobs/build/libobs.pch.h" +#include +extern struct obs_core *core_texture_activity_oracle_core; +bool oracle_obs_enum_input_types(size_t index, const char **id); +bool oracle_obs_enum_filter_types(size_t index, const char **id); +bool oracle_obs_enum_transition_types(size_t index, const char **id); +bool oracle_obs_enum_output_types(size_t index, const char **id); +bool oracle_obs_enum_encoder_types(size_t index, const char **id); +bool oracle_obs_enum_service_types(size_t index, const char **id); +#define obs core_texture_activity_oracle_core +#define obs_enum_input_types oracle_obs_enum_input_types +#define obs_enum_filter_types oracle_obs_enum_filter_types +#define obs_enum_transition_types oracle_obs_enum_transition_types +#define obs_enum_output_types oracle_obs_enum_output_types +#define obs_enum_encoder_types oracle_obs_enum_encoder_types +#define obs_enum_service_types oracle_obs_enum_service_types +#include "libobs/obs-type-catalog-enum.c.h" +#undef obs_enum_input_types +#undef obs_enum_filter_types +#undef obs_enum_transition_types +#undef obs_enum_output_types +#undef obs_enum_encoder_types +#undef obs_enum_service_types +#undef obs +#include "type_catalog_enum_fields.inc" + +typedef bool (*catalog_query)(size_t, const char **); +bool oracle_type_catalog_enum_check(const char *const *ids, const size_t *counts, size_t index, + const catalog_query *queries, const char *const *safe_ids, + const bool *safe_results); +bool oracle_type_catalog_enum_check(const char *const *ids, const size_t *counts, size_t index, + const catalog_query *queries, const char *const *safe_ids, const bool *safe_results) +{ + for (size_t c = 0; c < 6; ++c) + if (counts[c] > 8) + return false; + struct obs_core core = {0}, before_core; + struct obs_source_info input[8] = {0}, before_input[8]; + for (size_t i = 0; i < counts[0]; ++i) + input[i].id = ids[0 * 8 + i]; + core.input_types.array = counts[0] ? input : NULL; + core.input_types.num = counts[0]; + core.input_types.capacity = counts[0]; + memcpy(before_input, input, sizeof(input)); + struct obs_source_info filter[8] = {0}, before_filter[8]; + for (size_t i = 0; i < counts[1]; ++i) + filter[i].id = ids[1 * 8 + i]; + core.filter_types.array = counts[1] ? filter : NULL; + core.filter_types.num = counts[1]; + core.filter_types.capacity = counts[1]; + memcpy(before_filter, filter, sizeof(filter)); + struct obs_source_info transition[8] = {0}, before_transition[8]; + for (size_t i = 0; i < counts[2]; ++i) + transition[i].id = ids[2 * 8 + i]; + core.transition_types.array = counts[2] ? transition : NULL; + core.transition_types.num = counts[2]; + core.transition_types.capacity = counts[2]; + memcpy(before_transition, transition, sizeof(transition)); + struct obs_output_info output[8] = {0}, before_output[8]; + for (size_t i = 0; i < counts[3]; ++i) + output[i].id = ids[3 * 8 + i]; + core.output_types.array = counts[3] ? output : NULL; + core.output_types.num = counts[3]; + core.output_types.capacity = counts[3]; + memcpy(before_output, output, sizeof(output)); + struct obs_encoder_info encoder[8] = {0}, before_encoder[8]; + for (size_t i = 0; i < counts[4]; ++i) + encoder[i].id = ids[4 * 8 + i]; + core.encoder_types.array = counts[4] ? encoder : NULL; + core.encoder_types.num = counts[4]; + core.encoder_types.capacity = counts[4]; + memcpy(before_encoder, encoder, sizeof(encoder)); + struct obs_service_info service[8] = {0}, before_service[8]; + for (size_t i = 0; i < counts[5]; ++i) + service[i].id = ids[5 * 8 + i]; + core.service_types.array = counts[5] ? service : NULL; + core.service_types.num = counts[5]; + core.service_types.capacity = counts[5]; + memcpy(before_service, service, sizeof(service)); + memcpy(&before_core, &core, sizeof(core)); + struct obs_core *previous = core_texture_activity_oracle_core; + core_texture_activity_oracle_core = &core; + const catalog_query originals[] = { + oracle_obs_enum_input_types, oracle_obs_enum_filter_types, oracle_obs_enum_transition_types, + oracle_obs_enum_output_types, oracle_obs_enum_encoder_types, oracle_obs_enum_service_types, + }; + bool valid = true; + for (uint32_t c = 0; c < 6; ++c) { + size_t count = SIZE_MAX; + const void *array = obs_type_catalog_enum_registry_fields(&core, c, &count); + valid = valid && count == counts[c]; + const void *arrays[] = {core.input_types.array, core.filter_types.array, core.transition_types.array, + core.output_types.array, core.encoder_types.array, core.service_types.array}; + valid = valid && array == arrays[c]; + for (size_t i = 0; i < count; ++i) { + const char *const *fields[] = {&input[i].id, &filter[i].id, &transition[i].id, + &output[i].id, &encoder[i].id, &service[i].id}; + valid = valid && obs_type_catalog_enum_id_fields(array, c, i) == fields[c]; + } + const char *sentinel = ids[48 + c]; + const char *actual = sentinel, *original = sentinel; + bool a = queries[c](index, &actual); + bool b = originals[c](index, &original); + valid = valid && a == b && a == safe_results[c] && actual == original && actual == safe_ids[c]; + if (index >= count) + valid = valid && actual == sentinel && !queries[c](index, NULL) && !originals[c](index, NULL); + } + valid = valid && memcmp(&before_core, &core, sizeof(core)) == 0; + valid = valid && memcmp(before_input, input, sizeof(input)) == 0; + valid = valid && memcmp(before_filter, filter, sizeof(filter)) == 0; + valid = valid && memcmp(before_transition, transition, sizeof(transition)) == 0; + valid = valid && memcmp(before_output, output, sizeof(output)) == 0; + valid = valid && memcmp(before_encoder, encoder, sizeof(encoder)) == 0; + valid = valid && memcmp(before_service, service, sizeof(service)) == 0; + core_texture_activity_oracle_core = previous; + return valid; +} diff --git a/rust/obs-core/src/ffi/mod.rs b/rust/obs-core/src/ffi/mod.rs index 069bf6afe2..c79321770a 100644 --- a/rust/obs-core/src/ffi/mod.rs +++ b/rust/obs-core/src/ffi/mod.rs @@ -68,6 +68,7 @@ pub mod source_load; pub mod source_profiler; pub mod source_type_enum; pub mod tick_callbacks; +pub mod type_catalog_enum; pub mod ui_task_handler; pub mod video_copy_plan; pub mod video_frame_copy; diff --git a/rust/obs-core/src/ffi/type_catalog_enum.rs b/rust/obs-core/src/ffi/type_catalog_enum.rs new file mode 100644 index 0000000000..4c0bca7ee9 --- /dev/null +++ b/rust/obs-core/src/ffi/type_catalog_enum.rs @@ -0,0 +1,112 @@ +//! C ABI over private registry field adapters. No registry layout crosses into Rust. +use crate::type_catalog_enum; +use core::ffi::{c_char, c_void}; +use core::ptr::NonNull; + +unsafe extern "C" { + fn obs_core_texture_activity_core() -> *const c_void; + fn obs_type_catalog_enum_registry_fields( + core: *const c_void, + catalog: u32, + count: *mut usize, + ) -> *const c_void; + fn obs_type_catalog_enum_id_fields( + array: *const c_void, + catalog: u32, + index: usize, + ) -> *const *const c_char; +} + +unsafe fn enumerate(catalog: u32, index: usize, output: *mut *const c_char) -> bool { + // SAFETY: reading the owner token does not dereference it. + let core = unsafe { obs_core_texture_activity_core() }; + let core = NonNull::new(core.cast_mut()).expect("catalog enumeration requires a live core"); + let mut count = 0; + // SAFETY: NULL is rejected before forming any field addresses. The caller + // guarantees the core and registry remain live and synchronized. + let array = + unsafe { obs_type_catalog_enum_registry_fields(core.as_ptr(), catalog, &mut count) }; + type_catalog_enum::enumerate( + count, + index, + |i| { + let array = NonNull::new(array.cast_mut()).expect("a nonempty catalog has storage"); + // SAFETY: the safe core checks the index before this field access. + unsafe { *obs_type_catalog_enum_id_fields(array.as_ptr(), catalog, i) } + }, + |id| { + // SAFETY: success requires a writable output slot. Failed lookups do + // not call this closure, so their output may be NULL. + unsafe { output.write(id) }; + }, + ) +} + +/// Return the borrowed registered input ID at `index`. +/// +/// # Safety +/// A live synchronized core is required. On success `output` must be writable +/// and non-NULL. Registration owns the returned ID storage. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_enum_input_types(index: usize, output: *mut *const c_char) -> bool { + // SAFETY: the caller supplies the live registry and output contract. + unsafe { enumerate(0, index, output) } +} + +/// Return the borrowed registered filter ID at `index`. +/// +/// # Safety +/// A live synchronized core is required. On success `output` must be writable +/// and non-NULL. Registration owns the returned ID storage. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_enum_filter_types(index: usize, output: *mut *const c_char) -> bool { + // SAFETY: the caller supplies the live registry and output contract. + unsafe { enumerate(1, index, output) } +} + +/// Return the borrowed registered transition ID at `index`. +/// +/// # Safety +/// A live synchronized core is required. On success `output` must be writable +/// and non-NULL. Registration owns the returned ID storage. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_enum_transition_types( + index: usize, + output: *mut *const c_char, +) -> bool { + // SAFETY: the caller supplies the live registry and output contract. + unsafe { enumerate(2, index, output) } +} + +/// Return the borrowed registered output ID at `index`. +/// +/// # Safety +/// A live synchronized core is required. On success `output` must be writable +/// and non-NULL. Registration owns the returned ID storage. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_enum_output_types(index: usize, output: *mut *const c_char) -> bool { + // SAFETY: the caller supplies the live registry and output contract. + unsafe { enumerate(3, index, output) } +} + +/// Return the borrowed registered encoder ID at `index`. +/// +/// # Safety +/// A live synchronized core is required. On success `output` must be writable +/// and non-NULL. Registration owns the returned ID storage. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_enum_encoder_types(index: usize, output: *mut *const c_char) -> bool { + // SAFETY: the caller supplies the live registry and output contract. + unsafe { enumerate(4, index, output) } +} + +/// Return the borrowed registered service ID at `index`. +/// +/// # Safety +/// A live synchronized core is required. On success `output` must be writable +/// and non-NULL. Registration owns the returned ID storage. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_enum_service_types(index: usize, output: *mut *const c_char) -> bool { + // SAFETY: the caller supplies the live registry and output contract. + unsafe { enumerate(5, index, output) } +} diff --git a/rust/obs-core/src/type_catalog_enum.rs b/rust/obs-core/src/type_catalog_enum.rs index 39061bc5dd..2f027128c6 100644 --- a/rust/obs-core/src/type_catalog_enum.rs +++ b/rust/obs-core/src/type_catalog_enum.rs @@ -6,6 +6,5 @@ pub fn enumerate( read: impl FnOnce(usize) -> T, write: impl FnOnce(T), ) -> bool { - let _ = (count, index, read, write); - todo!("#5202: swap type catalog enumeration") + crate::source_type_enum::source(count, index, read, write) } diff --git a/rust/obs-core/tests/obs_core/main.rs b/rust/obs-core/tests/obs_core/main.rs index f0d07f2135..e92cf3ad36 100644 --- a/rust/obs-core/tests/obs_core/main.rs +++ b/rust/obs-core/tests/obs_core/main.rs @@ -142,6 +142,7 @@ mod source_type_enum_parity; mod tick_callbacks; mod tick_callbacks_parity; mod type_catalog_enum; +mod type_catalog_enum_parity; mod ui_task_handler; mod ui_task_handler_parity; mod video_copy_plan; diff --git a/rust/obs-core/tests/obs_core/type_catalog_enum.rs b/rust/obs-core/tests/obs_core/type_catalog_enum.rs index 021ae183a1..b11ce51319 100644 --- a/rust/obs-core/tests/obs_core/type_catalog_enum.rs +++ b/rust/obs-core/tests/obs_core/type_catalog_enum.rs @@ -11,13 +11,19 @@ const IDS: [[&str; 2]; 6] = [ ["catalog_service_z", "catalog_service_a"], ]; const SENTINELS: [&str; 6] = [ - "input untouched", "filter untouched", "transition untouched", - "output untouched", "encoder untouched", "service untouched", + "input untouched", + "filter untouched", + "transition untouched", + "output untouched", + "encoder untouched", + "service untouched", ]; fn query<'a>(registry: &[&'a str], index: usize, output: Option<&Cell<&'a str>>) -> bool { type_catalog_enum::enumerate( - registry.len(), index, |i| registry[i], + registry.len(), + index, + |i| registry[i], |id| output.expect("success requires output").set(id), ) } @@ -29,29 +35,41 @@ fn end(registry: &[&str], index: usize, sentinel: &str) { } fn count(registry: &[&str]) -> usize { let output = Cell::new(""); - (0..=registry.len()).take_while(|&i| query(registry, i, Some(&output))).count() + (0..=registry.len()) + .take_while(|&i| query(registry, i, Some(&output))) + .count() } #[test] fn test_type_catalog_enum_empty_catalogs() { for sentinel in SENTINELS { - for index in [0, usize::MAX] { end(&[], index, sentinel); } + for index in [0, usize::MAX] { + end(&[], index, sentinel); + } } } #[test] fn test_type_catalog_enum_populated_catalogs() { // Source registration owns a versioned copy; the source and per-kind // catalogs share that ID. Other catalogs borrow the caller's ID. - let source_ids: Vec> = IDS[..3].iter() - .map(|ids| ids.iter().map(|id| (*id).to_owned()).collect()).collect(); + let source_ids: Vec> = IDS[..3] + .iter() + .map(|ids| ids.iter().map(|id| (*id).to_owned()).collect()) + .collect(); let mut catalogs: [Vec<&str>; 6] = std::array::from_fn(|_| Vec::new()); let mut added = [0; 6]; let mut borrowed = [[""; 2]; 6]; for entry in 0..2 { for c in 0..6 { - let id = if c < 3 { source_ids[c][entry].as_str() } else { IDS[c][entry] }; + let id = if c < 3 { + source_ids[c][entry].as_str() + } else { + IDS[c][entry] + }; catalogs[c].push(id); added[c] += 1; - for other in 0..6 { assert_eq!(count(&catalogs[other]), added[other]); } + for other in 0..6 { + assert_eq!(count(&catalogs[other]), added[other]); + } let output = Cell::new(SENTINELS[c]); assert!(query(&catalogs[c], entry, Some(&output))); assert_eq!(output.get(), IDS[c][entry]); @@ -64,10 +82,16 @@ fn test_type_catalog_enum_populated_catalogs() { assert!(query(&catalogs[c], entry, Some(&output))); assert!(std::ptr::eq(output.get(), borrowed[c][entry])); assert_eq!(output.get(), IDS[c][entry]); - let origin = if c < 3 { source_ids[c][entry].as_str() } else { IDS[c][entry] }; + let origin = if c < 3 { + source_ids[c][entry].as_str() + } else { + IDS[c][entry] + }; assert!(std::ptr::eq(output.get(), origin)); } - for index in [2, 3, usize::MAX] { end(&catalogs[c], index, SENTINELS[c]); } + for index in [2, 3, usize::MAX] { + end(&catalogs[c], index, SENTINELS[c]); + } assert_eq!(borrowed[c][0], IDS[c][0]); } } diff --git a/rust/obs-core/tests/obs_core/type_catalog_enum_parity.rs b/rust/obs-core/tests/obs_core/type_catalog_enum_parity.rs new file mode 100644 index 0000000000..ab7b0291d4 --- /dev/null +++ b/rust/obs-core/tests/obs_core/type_catalog_enum_parity.rs @@ -0,0 +1,116 @@ +//! Original C vs ABI shim vs safe core. No-core and successful NULL output +//! are outside the C contract. No intentional differences. +use core::ffi::c_char; +use obs_core::{ffi::type_catalog_enum::*, type_catalog_enum}; +use proptest::prelude::*; +use proptest::test_runner::{Config, TestRunner}; +use std::cell::Cell; + +type Query = unsafe extern "C" fn(usize, *mut *const c_char) -> bool; +unsafe extern "C" { + fn oracle_type_catalog_enum_check( + ids: *const *const c_char, + counts: *const usize, + index: usize, + queries: *const Query, + safe_ids: *const *const c_char, + safe_results: *const bool, + ) -> bool; +} +fn check(catalogs: &[Vec>], index: usize) { + let mut ids = [std::ptr::null(); 54]; + let counts: [usize; 6] = std::array::from_fn(|c| catalogs[c].len()); + let sentinels = [ + c"input untouched", + c"filter untouched", + c"transition untouched", + c"output untouched", + c"encoder untouched", + c"service untouched", + ]; + for c in 0..6 { + for (i, id) in catalogs[c].iter().enumerate() { + ids[c * 8 + i] = id.as_ptr().cast(); + } + ids[48 + c] = sentinels[c].as_ptr(); + } + let queries: [Query; 6] = [ + obs_enum_input_types, + obs_enum_filter_types, + obs_enum_transition_types, + obs_enum_output_types, + obs_enum_encoder_types, + obs_enum_service_types, + ]; + let output: [Cell<*const c_char>; 6] = std::array::from_fn(|c| Cell::new(ids[48 + c])); + let results: [bool; 6] = std::array::from_fn(|c| { + type_catalog_enum::enumerate(counts[c], index, |i| ids[c * 8 + i], |id| output[c].set(id)) + }); + let output: [*const c_char; 6] = output.map(Cell::into_inner); + let before = catalogs.to_vec(); + // SAFETY: six catalogs each have at most eight live byte arrays. C never + // dereferences strings; it compares the exact borrowed pointers. The child + // process exclusively lends the existing global fixture and C restores it. + assert!(unsafe { + oracle_type_catalog_enum_check( + ids.as_ptr(), + counts.as_ptr(), + index, + queries.as_ptr(), + output.as_ptr(), + results.as_ptr(), + ) + }); + assert_eq!(catalogs, before); +} +#[test] +fn type_catalog_enum_matches_original_c() { + const CHILD: &str = "OBS_TYPE_CATALOG_ENUM_PARITY_CHILD"; + if std::env::var_os(CHILD).is_none() { + let selector = format!( + "{}::type_catalog_enum_matches_original_c", + module_path!().split_once("::").unwrap().1 + ); + let status = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", &selector, "--test-threads=1"]) + .env(CHILD, "1") + .status() + .unwrap(); + assert!(status.success()); + return; + } + let empty = vec![vec![]; 6]; + let catalogs: Vec<_> = (0..6) + .map(|c| (0..=c).map(|i| vec![c as u8, i as u8, 255, 0]).collect()) + .collect(); + for index in [0, 1, 2, 3, 4, 5, 6, 7, 8, u32::MAX as usize, usize::MAX] { + check(&empty, index); + check(&catalogs, index); + for c in 0..6 { + let mut one = empty.clone(); + one[c] = catalogs[c].clone(); + check(&one, index); + } + } + let strategy = ( + prop::collection::vec( + prop::collection::vec(prop::collection::vec(any::(), 1..25), 0..9), + 6, + ), + any::(), + ); + TestRunner::new(Config { + cases: obs_c_oracle::parity::cases(128), + failure_persistence: None, + ..Config::default() + }) + .run(&strategy, |(catalogs, index)| { + check(&catalogs, index); + for i in 0..=8 { + check(&catalogs, i); + } + check(&catalogs, usize::MAX); + Ok(()) + }) + .unwrap(); +} diff --git a/test/cmocka/video-info-query-link-support.c b/test/cmocka/video-info-query-link-support.c index 7d2b9cd0e8..b9d1335f2f 100644 --- a/test/cmocka/video-info-query-link-support.c +++ b/test/cmocka/video-info-query-link-support.c @@ -1,2 +1,3 @@ /* Link the real private-layout adapter; the fixture owns its core. */ #include "libobs/obs-video-info-query-fields.c.h" +#include "libobs/obs-type-catalog-enum-fields.c.h"