From 7da52f60813862a28a8005759c8e188c290376e4 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 01:53:55 -0800 Subject: [PATCH 1/3] test(encoder): mirror texture-active characterization against a Rust stub (Refs #5216) --- rust/obs-encoder/src/lib.rs | 1 + rust/obs-encoder/src/video_tex_active.rs | 15 +++ rust/obs-encoder/tests/encoder/main.rs | 1 + .../tests/encoder/video_tex_active.rs | 97 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 rust/obs-encoder/src/video_tex_active.rs create mode 100644 rust/obs-encoder/tests/encoder/video_tex_active.rs diff --git a/rust/obs-encoder/src/lib.rs b/rust/obs-encoder/src/lib.rs index 58a34036fe..f729bea9a2 100644 --- a/rust/obs-encoder/src/lib.rs +++ b/rust/obs-encoder/src/lib.rs @@ -7,3 +7,4 @@ pub mod last_error; pub mod media_getters; pub mod packet_ownership; pub mod type_info; +pub mod video_tex_active; diff --git a/rust/obs-encoder/src/video_tex_active.rs b/rust/obs-encoder/src/video_tex_active.rs new file mode 100644 index 0000000000..c2f344046c --- /dev/null +++ b/rust/obs-encoder/src/video_tex_active.rs @@ -0,0 +1,15 @@ +//! Query C-owned texture-input state after the synchronized mix lookup. + +pub const NV12: i32 = 2; +pub const P010: i32 = 18; + +/// Look up exactly once, then read only the flag matching the requested format. +pub fn video_tex_active( + format: i32, + lookup: impl FnOnce() -> Option, + nv12: impl FnOnce(M) -> bool, + p010: impl FnOnce(M) -> bool, +) -> bool { + let _ = (format, lookup, nv12, p010); + todo!("swap the characterized texture-active query") +} diff --git a/rust/obs-encoder/tests/encoder/main.rs b/rust/obs-encoder/tests/encoder/main.rs index 05112357e9..9810dfaab9 100644 --- a/rust/obs-encoder/tests/encoder/main.rs +++ b/rust/obs-encoder/tests/encoder/main.rs @@ -10,3 +10,4 @@ mod encoder_module; mod encoder_module_parity; mod type_info; mod type_info_parity; +mod video_tex_active; diff --git a/rust/obs-encoder/tests/encoder/video_tex_active.rs b/rust/obs-encoder/tests/encoder/video_tex_active.rs new file mode 100644 index 0000000000..cb982fde7d --- /dev/null +++ b/rust/obs-encoder/tests/encoder/video_tex_active.rs @@ -0,0 +1,97 @@ +//! Tier 1 mirrors test_encoder_video_tex_active.c without private C layouts. +use obs_encoder::video_tex_active::{NV12, P010, video_tex_active}; +use std::cell::{Cell, RefCell}; + +fn check(format: i32, media: Option, mixed: bool, flags: [bool; 2]) { + let encoder = (media, 0x5a_u8); + let before = encoder; + let mix = Cell::new([!flags[0], !flags[1]]); + let events = RefCell::new(Vec::new()); + let result = video_tex_active( + format, + || { + assert_eq!(encoder.0, media); + events.borrow_mut().push("lookup"); + // Like the characterization, make pre-lookup reads observably wrong. + mix.set(flags); + mixed.then_some(&mix) + }, + |selected| { + assert!(std::ptr::eq(selected, &mix)); + events.borrow_mut().push("nv12"); + selected.get()[0] + }, + |selected| { + assert!(std::ptr::eq(selected, &mix)); + events.borrow_mut().push("p010"); + selected.get()[1] + }, + ); + assert_eq!(result, mixed && ((format == NV12 && flags[0]) || (format == P010 && flags[1]))); + let mut expected = vec!["lookup"]; + if mixed && format == NV12 { + expected.push("nv12"); + } else if mixed && format == P010 { + expected.push("p010"); + } + assert_eq!(*events.borrow(), expected); + assert_eq!(encoder, before); + assert_eq!(mix.get(), flags); +} + +#[test] +fn test_encoder_video_tex_active_missing_mix() { + for media in [None, Some(11)] { + for format in [NV12, P010, 6, 0] { + check(format, media, false, [true, true]); + } + } +} + +#[test] +fn test_encoder_video_tex_active_format_and_flag_matrix() { + for flags in [[false, false], [true, false], [false, true], [true, true]] { + for format in 0..=25 { + check(format, Some(11), true, flags); + } + } +} + +#[test] +fn test_encoder_video_tex_active_reads_selected_mix_after_lookup() { + for flags in [[false, false], [true, false], [false, true], [true, true]] { + for format in [NV12, P010] { + check(format, Some(11), true, flags); + } + } +} + +#[test] +fn test_encoder_tex_active_null_no_video_and_canvas_gone() { + // A live encoder before/after video reset, or after its canvas mix is gone. + for media in [None, Some(11)] { + for format in [NV12, P010, 1] { + check(format, media, false, [false, false]); + } + } +} + +#[test] +fn test_encoder_tex_active_null_main_video_capabilities() { + // Model capabilities; make no assertion about any real device's support. + for available in [false, true] { + for (flags, format) in [([available, false], NV12), ([false, available], P010)] { + for requested in [NV12, P010, 1] { + check(requested, Some(11), true, flags); + } + check(format, Some(11), true, flags); + } + } +} + +#[test] +fn other_formats_still_look_up_without_reading_flags() { + for format in [i32::MIN, -1, 26, i32::MAX] { + check(format, None, true, [true, true]); + } +} From b5cf4d778615f9aaf2c1b1cf74fdb297a331acde Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 02:04:18 -0800 Subject: [PATCH 2/3] obs-encoder: swap texture-input activity to safe Rust (Refs #5216) Ci-Attestation: {"at":1795085223,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":181,"stamp":"0ab8cfd8f7fc59c78ac76ce9ca6ecd88","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085223,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":181,"stamp":"bb31b5997bef2c8dedc42a36911384f7","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085223,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":181,"stamp":"b2a36f087de40ff8eed9f58acb87f627","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085223,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":181,"stamp":"21dde596c9cf002e516c39737f8514bf","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"general/all/client-lint","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"2af6902c914a02d7145136de3d841fc0","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085223,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":181,"stamp":"8417e2e6f2a0b7472de32270cceb9193","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085041,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"6384c12064162974b0cc84661cd36945","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085041,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"9aa7c29b1cc526fe44d2e1c558d1f5d8","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"b0a14d7081c53e93c8becb3ab2b9dafa","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085041,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"3125ae5dce02f25c84ede347a4c58e38","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"32523f3d25515daf1c2d596bbe201013","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"04ffbcdfc8f043c828ca0db7c25b176e","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085041,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"78e1c7d269faf8dbb918ccb7706800f4","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085041,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"80bc544c2480a3f255dd8fa0d1e6e087","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"3274129151590b44a3010b5311d441d1","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"77e4b71c8cc24721eb52766b472488f2","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"8c8366ef6b99d116f13da130be677923","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085040,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"93eb9522bc1b267ae86b1c6b513191641e048604c58c4c9426bb0821c5aa6c25","lane":"client-lint","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":216,"stamp":"19f76c12712d90be0451da52be48f1a7","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","v":1,"via":"run"} Ci-Attestation: {"at":1795085891,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"23f39a0455af16f270d666d1e00260b7421b190b2b676f1f23b4d756eb0fcc0d","lane":"client-test-x86_64-unknown-linux-gnu","parents":["32362a079e517b15ff435e99464a0afc69336f1f"],"secs":667,"stamp":"1f8b6baabb648b1bd04021a60baf3792","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e","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.core-output+.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-encoder-video-tex-active+.h.c","libobs/build/libobs.ported-hotkey-unregister-entry+.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/encoder-video-tex-active.json","libobs/build/ported-source-sets/hotkey-unregister-entry.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-video_level_queries.txt","libobs/cmake/rust-exports.d/obs-encoder-video_tex_active.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-encoder-video-tex-active-fields.c.h","libobs/obs-encoder-video-tex-active-mix.c.h","libobs/obs-hotkey-unregister-entry-fields.c.h","libobs/obs-video-level-queries-fields.c.h","libobs/obs.c.h","rust/README.md","rust/obs-build/tests/native/registration/canonical_video_info_query_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/header/test_encoder_video_tex_active.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/encoder-video-tex-active-mix.list","rust/obs-c-oracle/oracle.d/encoder-video-tex-active.list","rust/obs-c-oracle/oracle.d/hotkey_unregister_entry.list","rust/obs-c-oracle/oracle/encoder_video_tex_active.c","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/video_level_queries.c","rust/obs-core/src/ffi/mod.rs","rust/obs-core/src/ffi/video_level_queries.rs","rust/obs-core/src/lib.rs","rust/obs-core/src/video_level_queries.rs","rust/obs-core/tests/obs_core/main.rs","rust/obs-core/tests/obs_core/video_level_queries.rs","rust/obs-core/tests/obs_core/video_level_queries_parity.rs","rust/obs-encoder/src/ffi/mod.rs","rust/obs-encoder/src/ffi/video_tex_active.rs","rust/obs-encoder/src/lib.rs","rust/obs-encoder/src/video_tex_active.rs","rust/obs-encoder/tests/encoder/main.rs","rust/obs-encoder/tests/encoder/video_tex_active.rs","rust/obs-encoder/tests/encoder/video_tex_active_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/encoder-video-tex-active-fields-link-support.c","test/cmocka/encoder-video-tex-active-mix-link-support.c","test/cmocka/test_image_max_texture_size.c","test/cmocka/tests.d/test_image_max_texture_size.cmake","test/cmocka/tests.d/video_info_query_link_support.cmake","test/cmocka/tests.d/video_level_queries_link_support.cmake"],"head":"8b2fe4f9a0898f027a799316e7fa1fdf0c41b707","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":"303e955314cdcca72399bd1f4c42c45ec453778b5d7bb6af55339c26d492ccb0","tree":"7795759d6ac65ea01159d3c93cd5771fbb8ae78e"}} --- libobs/build/libobs.core+.h.c | 1 + libobs/build/libobs.core-output+.h.c | 2 +- ...ibobs.ported-encoder-video-tex-active+.h.c | 4 + .../encoder-video-tex-active.json | 5 + .../obs-encoder-video_tex_active.txt | 1 + .../obs-encoder-video-tex-active-fields.c.h | 20 +++ libobs/obs-encoder-video-tex-active-mix.c.h | 19 +++ libobs/obs.c.h | 18 --- rust/README.md | 1 + ...anonical_video_info_query_is_registered.rs | 6 + .../header/test_encoder_video_tex_active.json | 39 ++++++ .../encoder-video-tex-active-mix.list | 1 + .../oracle.d/encoder-video-tex-active.list | 1 + .../oracle/encoder_video_tex_active.c | 131 ++++++++++++++++++ rust/obs-encoder/src/ffi/mod.rs | 1 + rust/obs-encoder/src/ffi/video_tex_active.rs | 38 +++++ rust/obs-encoder/src/video_tex_active.rs | 10 +- rust/obs-encoder/tests/encoder/main.rs | 1 + .../tests/encoder/video_tex_active.rs | 5 +- .../tests/encoder/video_tex_active_parity.rs | 80 +++++++++++ test/cmocka/build/test-graph.json | 32 +++++ ...der-video-tex-active-fields-link-support.c | 2 + ...ncoder-video-tex-active-mix-link-support.c | 2 + .../video_info_query_link_support.cmake | 2 + 24 files changed, 400 insertions(+), 22 deletions(-) create mode 100644 libobs/build/libobs.ported-encoder-video-tex-active+.h.c create mode 100644 libobs/build/ported-source-sets/encoder-video-tex-active.json create mode 100644 libobs/cmake/rust-exports.d/obs-encoder-video_tex_active.txt create mode 100644 libobs/obs-encoder-video-tex-active-fields.c.h create mode 100644 libobs/obs-encoder-video-tex-active-mix.c.h create mode 100644 rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json create mode 100644 rust/obs-c-oracle/oracle.d/encoder-video-tex-active-mix.list create mode 100644 rust/obs-c-oracle/oracle.d/encoder-video-tex-active.list create mode 100644 rust/obs-c-oracle/oracle/encoder_video_tex_active.c create mode 100644 rust/obs-encoder/src/ffi/video_tex_active.rs create mode 100644 rust/obs-encoder/tests/encoder/video_tex_active_parity.rs create mode 100644 test/cmocka/encoder-video-tex-active-fields-link-support.c create mode 100644 test/cmocka/encoder-video-tex-active-mix-link-support.c diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index f6461dd683..f0b6aed5ba 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -13,6 +13,7 @@ #include "libobs/obs-core-state.c.h" #include "libobs/obs-core-texture-activity-fields.c.h" #include "libobs/obs-core-tick-callbacks-fields.c.h" +#include "libobs/obs-encoder-video-tex-active-mix.c.h" #include "libobs/obs-enum-scenes-fields.c.h" #include "libobs/obs-get-audio-fields.c.h" #include "libobs/obs-get-main-canvas-fields.c.h" diff --git a/libobs/build/libobs.core-output+.h.c b/libobs/build/libobs.core-output+.h.c index ad2821422e..3efdd9c0f7 100644 --- a/libobs/build/libobs.core-output+.h.c +++ b/libobs/build/libobs.core-output+.h.c @@ -37,7 +37,7 @@ #include "libobs/obs-encoder-settings-fields.c.h" #include "libobs/obs-encoder-state-queries-fields.c.h" #include "libobs/obs-encoder-type-info-fields.c.h" -#include "libobs/obs-encoder-video-tex-active.c.h" +#include "libobs/obs-encoder-video-tex-active-fields.c.h" #include "libobs/obs-encoder.c.h" #include "libobs/obs-output-active-fields.c.h" #include "libobs/obs-output-can-pause-fields.c.h" diff --git a/libobs/build/libobs.ported-encoder-video-tex-active+.h.c b/libobs/build/libobs.ported-encoder-video-tex-active+.h.c new file mode 100644 index 0000000000..dca1e46d00 --- /dev/null +++ b/libobs/build/libobs.ported-encoder-video-tex-active+.h.c @@ -0,0 +1,4 @@ +/* Unity group (BUILD.md): original texture-input activity query, reference only. */ +#include "libobs/build/libobs.pch.h" + +#include "libobs/obs-encoder-video-tex-active.c.h" diff --git a/libobs/build/ported-source-sets/encoder-video-tex-active.json b/libobs/build/ported-source-sets/encoder-video-tex-active.json new file mode 100644 index 0000000000..bdeb43ce39 --- /dev/null +++ b/libobs/build/ported-source-sets/encoder-video-tex-active.json @@ -0,0 +1,5 @@ +{ + "LIBOBS_PORTED_SOURCES": [ + "build/libobs.ported-encoder-video-tex-active+.h.c" + ] +} diff --git a/libobs/cmake/rust-exports.d/obs-encoder-video_tex_active.txt b/libobs/cmake/rust-exports.d/obs-encoder-video_tex_active.txt new file mode 100644 index 0000000000..7cac7386ec --- /dev/null +++ b/libobs/cmake/rust-exports.d/obs-encoder-video_tex_active.txt @@ -0,0 +1 @@ +obs_encoder_video_tex_active diff --git a/libobs/obs-encoder-video-tex-active-fields.c.h b/libobs/obs-encoder-video-tex-active-fields.c.h new file mode 100644 index 0000000000..1bbf06cbac --- /dev/null +++ b/libobs/obs-encoder-video-tex-active-fields.c.h @@ -0,0 +1,20 @@ +#include "libobs/build/libobs.pch.h" + +const struct obs_core_video_mix *obs_encoder_video_tex_active_mix(const obs_encoder_t *encoder); +bool obs_encoder_video_tex_active_nv12(const struct obs_core_video_mix *mix); +bool obs_encoder_video_tex_active_p010(const struct obs_core_video_mix *mix); + +const struct obs_core_video_mix *obs_encoder_video_tex_active_mix(const obs_encoder_t *encoder) +{ + return get_mix_for_video(encoder->media); +} + +bool obs_encoder_video_tex_active_nv12(const struct obs_core_video_mix *mix) +{ + return mix->using_nv12_tex; +} + +bool obs_encoder_video_tex_active_p010(const struct obs_core_video_mix *mix) +{ + return mix->using_p010_tex; +} diff --git a/libobs/obs-encoder-video-tex-active-mix.c.h b/libobs/obs-encoder-video-tex-active-mix.c.h new file mode 100644 index 0000000000..06083265ea --- /dev/null +++ b/libobs/obs-encoder-video-tex-active-mix.c.h @@ -0,0 +1,19 @@ +#include "libobs/build/libobs.pch.h" + +struct obs_core_video_mix *get_mix_for_video(video_t *v) +{ + struct obs_core_video_mix *result = NULL; + + pthread_mutex_lock(&obs->video.mixes_mutex); + for (size_t i = 0, num = obs->video.mixes.num; i < num; i++) { + struct obs_core_video_mix *mix = obs->video.mixes.array[i]; + + if (v == mix->video) { + result = mix; + break; + } + } + pthread_mutex_unlock(&obs->video.mixes_mutex); + + return result; +} diff --git a/libobs/obs.c.h b/libobs/obs.c.h index adbc67e9ad..2d61887617 100644 --- a/libobs/obs.c.h +++ b/libobs/obs.c.h @@ -2922,24 +2922,6 @@ void obs_get_video_frame_counts(uint32_t *total, uint32_t *skipped) *skipped = skipped_frames; } -struct obs_core_video_mix *get_mix_for_video(video_t *v) -{ - struct obs_core_video_mix *result = NULL; - - pthread_mutex_lock(&obs->video.mixes_mutex); - for (size_t i = 0, num = obs->video.mixes.num; i < num; i++) { - struct obs_core_video_mix *mix = obs->video.mixes.array[i]; - - if (v == mix->video) { - result = mix; - break; - } - } - pthread_mutex_unlock(&obs->video.mixes_mutex); - - return result; -} - void start_raw_video(video_t *v, const struct video_scale_info *conversion, uint32_t frame_rate_divisor, void (*callback)(void *param, struct video_data *frame), void *param) { diff --git a/rust/README.md b/rust/README.md index 48fc13db21..78f75abecf 100644 --- a/rust/README.md +++ b/rust/README.md @@ -279,6 +279,7 @@ and compares their exported symbols. `OBS_LIBOBS_BACKEND=C` is temporary rollbac | `libobs/obs-encoder-frame-rate-divisor.c.h` (extracted from `obs-encoder.c.h`) | `obs-output::encoder_frame_rate_divisor` | Public frame-rate-divisor getter. Preserves NULL and audio-type defaults, historical setter diagnostics, current-info type selection, full-width divisor and no mutation. Borrowed private fields; real-header layout and callback-based randomized Tier 3 parity; unchanged actual-library Tier 2 on both libraries. No intended differences; Tier 4 inapplicable. | | `libobs/obs-encoder-packet-ownership.c.h` | `obs-encoder::packet_ownership` | Swapped in hybrid `libobs` (group `libobs.ported-encoder-packet-ownership`). `obs_encoder_packet_create_instance` (hidden), `obs_encoder_packet_ref` and `obs_encoder_packet_release` keep the C layout: one bmem block per payload, a native `long` count in front of the data, atomic increments and decrements, the block freed on the last release, then the whole packet zeroed. create copies every field, then allocates `size + sizeof(long)` and copies the payload (an owned source is copied too, never shared); ref of NULL does nothing, and a packet with no data is copied without touching a count. The safe core holds the order behind a host trait; the FFI keeps the pointers. Tier 1 checks the order against a recording host and mirrors every assertion of `test_encoder_packet_ownership` through the exports; Tier 3 runs random create/ref/release/write sequences on four packets per side against the original C, comparing fields, block aliasing, counts, bytes and `bnum_allocs()` after every step. The delay and interleave parity tests now go through these exports instead of their own copies. Excluded as in C: NULL-data or self copies, and refs of buffers with no count. No intentional differences; Tier 4 inapplicable. | | `libobs/obs-encoder-media-getters.c.h` | `obs-encoder::media_getters` | Video, parent-video and audio getters preserve NULL diagnostics, wrong-type warnings, borrowed media identity and FPS override priority, without active/initialized gates or mutation. Real private-layout snapshot adapter, header-derived layout checks, Tier 1 characterization mirrors and original-C randomized differential coverage in obs-tests-core; unchanged public C characterization runs against both libraries. No intentional behavior differences. | +| `libobs/obs-encoder-video-tex-active.c.h` | `obs-encoder::video_tex_active` | Texture-input activity preserves one C mutex-protected mix lookup before the absent-mix guard and only the requested NV12/P010 flag read. Opaque C-owned adapters retain private layouts; safe mirrors, unchanged C characterization, real-walk original-C differential and all Rust-static links cover the swap. No behavior change; Tier 4 inapplicable. | | `libobs/obs-encoder-metadata-getters.c.h` (extracted from `obs-encoder.c.h`) | `obs-output::encoder_metadata` | Five public instance metadata getters: codec/type from current info, ID/type data/caps from original info. No intended differences: NULL defaults and exact diagnostics, borrowed pointer identity, full-width caps, no locks, reference changes or plugin callbacks. Private field-pointer seam avoids mirroring the encoder layout; real-header view/enum layout checks, exact differential parity and unchanged actual-library `test_encoder_metadata_getters` cover both libraries. | | `libobs/obs-encoder-dimensions.c.h` | `obs-output::encoder_dimensions` | Public `obs_encoder_get_width` and `obs_encoder_get_height` swapped in hybrid libobs (group `libobs.ported-encoder-dimensions`). Reuses `encoder_size::video_size_route`; preserves NULL debug logs, wrong-type warnings including the encoder name, media absence before stored axes, independent full-width scaled axes and lazy video fallback. A borrowed field-address adapter keeps the private encoder layout in C. `test_encoder_dimensions` characterizes actual libraries and remains unchanged after its C-only commit. Tier 1 mirrors its assertions; real-header checks cover every view field and encoder type layout. Tier 3 compares both getters, full diagnostics and whole-encoder immutability for edges and randomized fields, using callbacks for media reads and the oracle C size helper. No intentional behavior differences. Tier 4 is inapplicable. | | `libobs/obs-encoder-group-lifecycle.c.h` | `obs-output::encoder_group_lifecycle` | Encoder-group allocation, deferred destruction and ordered locked teardown swapped in hybrid libobs. Native allocation, private fields and mutex primitives stay behind C adapters; the safe core clears each encoder back-pointer before releasing its reference, frees the list, unlocks and destroys the mutex, then frees the group. Tier 1 mirrors the source characterization; real-header view layout and bounded randomized C/Rust operation traces include init failure and the locked stop-path handoff. Actual-library Tier 2 checks zero initialization, deferred requests, back-pointers and strong-reference ownership. No intentional differences; Tier 4 is inapplicable. | diff --git a/rust/obs-build/tests/native/registration/canonical_video_info_query_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_video_info_query_is_registered.rs index ae0a43454c..7ad18c9f39 100644 --- a/rust/obs-build/tests/native/registration/canonical_video_info_query_is_registered.rs +++ b/rust/obs-build/tests/native/registration/canonical_video_info_query_is_registered.rs @@ -75,6 +75,12 @@ target_link_libraries(with_shared PRIVATE OBS::libobs) target_link_libraries(reference PRIVATE OBS::libobs) include("{root}/test/cmocka/tests.d/video_info_query_link_support.cmake") function(check_support) + get_target_property(adapter_sources video_info_query_link_support SOURCES) + foreach(adapter IN ITEMS encoder-video-tex-active-fields encoder-video-tex-active-mix) + if(NOT "{root}/test/cmocka/${{adapter}}-link-support.c" IN_LIST adapter_sources) + message(FATAL_ERROR "missing real encoder adapter source: ${{adapter}}") + endif() + endforeach() foreach(name IN ITEMS standalone with_shared future_consumer reference) get_target_property(links ${{name}} LINK_LIBRARIES) if(name STREQUAL "reference") diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json b/rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json new file mode 100644 index 0000000000..7bce85c32f --- /dev/null +++ b/rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json @@ -0,0 +1,39 @@ +{ + "schema": 1, + "targets": { + "test_encoder_video_tex_active_rust": { + "sources": [ + "test/cmocka/test_encoder_video_tex_active.c", + "test/cmocka/encoder-video-tex-active-fields-link-support.c" + ], + "definitions": [ + "get_mix_for_video=tex_active_recording_mix_lookup" + ], + "libraries": [ + "libobs_rust-static", + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ], + "includes": [ + ".", + "libobs" + ], + "requires": "HAVE_LIBOBS_RUST_STATIC" + } + }, + "tests": { + "test_encoder_video_tex_active_rust": { + "target": "test_encoder_video_tex_active_rust", + "command": [ + "${target}" + ], + "requires": "HAVE_LIBOBS_RUST_STATIC" + } + } +} diff --git a/rust/obs-c-oracle/oracle.d/encoder-video-tex-active-mix.list b/rust/obs-c-oracle/oracle.d/encoder-video-tex-active-mix.list new file mode 100644 index 0000000000..e8016e1a3f --- /dev/null +++ b/rust/obs-c-oracle/oracle.d/encoder-video-tex-active-mix.list @@ -0,0 +1 @@ +encoder-video-tex-active-mix.inc|libobs/obs-encoder-video-tex-active-mix.c.h|auto diff --git a/rust/obs-c-oracle/oracle.d/encoder-video-tex-active.list b/rust/obs-c-oracle/oracle.d/encoder-video-tex-active.list new file mode 100644 index 0000000000..38741b08f2 --- /dev/null +++ b/rust/obs-c-oracle/oracle.d/encoder-video-tex-active.list @@ -0,0 +1 @@ +encoder-video-tex-active.inc|libobs/obs-encoder-video-tex-active.c.h|auto diff --git a/rust/obs-c-oracle/oracle/encoder_video_tex_active.c b/rust/obs-c-oracle/oracle/encoder_video_tex_active.c new file mode 100644 index 0000000000..2ddea16937 --- /dev/null +++ b/rust/obs-c-oracle/oracle/encoder_video_tex_active.c @@ -0,0 +1,131 @@ +/* Original query, unchanged mutex walk and real private field adapters. */ +#include +#include +#include "obs-internal.h" + +struct encoder_tex_fixture { + struct obs_core *core; + video_t *media; + bool flags[3][2]; + unsigned lookups; + bool lookup_ok; +}; +#if defined(_MSC_VER) +#define ENCODER_TEX_THREAD_LOCAL __declspec(thread) +#else +#define ENCODER_TEX_THREAD_LOCAL __thread +#endif +static ENCODER_TEX_THREAD_LOCAL struct encoder_tex_fixture *encoder_tex_current; +#undef ENCODER_TEX_THREAD_LOCAL + +#define obs (encoder_tex_current->core) +struct obs_core_video_mix *oracle_encoder_tex_mix_walk(video_t *video); +#define get_mix_for_video oracle_encoder_tex_mix_walk +#include "encoder-video-tex-active-mix.inc" +#undef get_mix_for_video +#undef obs + +static struct obs_core_video_mix *encoder_tex_lookup(video_t *video) +{ + struct encoder_tex_fixture *fixture = encoder_tex_current; + fixture->lookups++; + fixture->lookup_ok = fixture->lookup_ok && video == fixture->media; + struct obs_core_video_mix *selected = oracle_encoder_tex_mix_walk(video); + for (size_t i = 0; i < fixture->core->video.mixes.num; i++) { + struct obs_core_video_mix *mix = fixture->core->video.mixes.array[i]; + if (mix == selected) { + mix->using_nv12_tex = fixture->flags[i][0]; + mix->using_p010_tex = fixture->flags[i][1]; + break; + } + } + return selected; +} + +#define get_mix_for_video encoder_tex_lookup +bool oracle_encoder_video_tex_active(const obs_encoder_t *encoder, enum video_format format); +#define obs_encoder_video_tex_active oracle_encoder_video_tex_active +#include "encoder-video-tex-active.inc" +#undef obs_encoder_video_tex_active +#include "encoder-video-tex-active-fields.inc" +#undef get_mix_for_video + +void oracle_encoder_tex_format_values(int *values); +void oracle_encoder_tex_format_values(int *values) +{ + values[0] = VIDEO_FORMAT_NV12; + values[1] = VIDEO_FORMAT_P010; + values[2] = VIDEO_FORMAT_R10L; +} + +typedef bool (*encoder_tex_query)(const obs_encoder_t *, enum video_format); +bool oracle_encoder_tex_check(encoder_tex_query candidate, int format, uint8_t media, uint8_t mask, + const uint8_t *videos, const uint8_t *flags); +bool oracle_encoder_tex_check(encoder_tex_query candidate, int format, uint8_t media, uint8_t mask, + const uint8_t *videos, const uint8_t *flags) +{ + struct obs_core *core = calloc(1, sizeof(*core)); + struct obs_core *before = malloc(sizeof(*core)); + struct obs_core *after = malloc(sizeof(*core)); + if (!core || !before || !after) { + free(core); + free(before); + free(after); + return false; + } + if (pthread_mutex_init(&core->video.mixes_mutex, NULL) != 0) { + free(core); + free(before); + free(after); + return false; + } + unsigned char tokens[3] = {11, 22, 33}; + video_t *identities[] = {NULL, (video_t *)&tokens[0], (video_t *)&tokens[1], (video_t *)&tokens[2]}; + struct obs_encoder encoder = {0}, encoder_before; + struct obs_core_video_mix mixes[3] = {0}, initial[3], c_after[3]; + struct obs_core_video_mix *pointers[3] = {0}; + struct encoder_tex_fixture fixture = {.core = core, .media = identities[media % 4], .lookup_ok = true}; + encoder.media = fixture.media; + memcpy(&encoder_before, &encoder, sizeof(encoder)); + for (unsigned i = 0; i < 3; i++) { + mixes[i].video = identities[videos[i] % 4]; + /* Only a matching lookup changes these to the requested values. */ + mixes[i].using_nv12_tex = !(flags[i] & 1); + mixes[i].using_p010_tex = !(flags[i] & 2); + if (mask & (1u << i)) { + size_t slot = core->video.mixes.num++; + pointers[slot] = &mixes[i]; + fixture.flags[slot][0] = (flags[i] & 1) != 0; + fixture.flags[slot][1] = (flags[i] & 2) != 0; + } + } + core->video.mixes.array = pointers; + core->video.mixes.capacity = 3; + memcpy(initial, mixes, sizeof(mixes)); + memcpy(before, core, sizeof(*core)); + /* Mutex internals may change on any platform; compare all other storage. */ + memset(&before->video.mixes_mutex, 0, sizeof(before->video.mixes_mutex)); + encoder_tex_current = &fixture; + bool c = oracle_encoder_video_tex_active(&encoder, (enum video_format)format); + bool equal = fixture.lookups == 1 && fixture.lookup_ok; + memcpy(c_after, mixes, sizeof(mixes)); + memcpy(mixes, initial, sizeof(mixes)); + fixture.lookups = 0; + fixture.lookup_ok = true; + bool rust = candidate(&encoder, (enum video_format)format); + equal = equal && c == rust && fixture.lookups == 1 && fixture.lookup_ok && + memcmp(&encoder, &encoder_before, sizeof(encoder)) == 0 && memcmp(mixes, c_after, sizeof(mixes)) == 0; + memcpy(after, core, sizeof(*core)); + memset(&after->video.mixes_mutex, 0, sizeof(after->video.mixes_mutex)); + equal = equal && memcmp(before, after, sizeof(*core)) == 0; + int locked = pthread_mutex_trylock(&core->video.mixes_mutex); + equal = equal && locked == 0; + if (locked == 0) + pthread_mutex_unlock(&core->video.mixes_mutex); + encoder_tex_current = NULL; + pthread_mutex_destroy(&core->video.mixes_mutex); + free(after); + free(before); + free(core); + return equal; +} diff --git a/rust/obs-encoder/src/ffi/mod.rs b/rust/obs-encoder/src/ffi/mod.rs index 71ff06545c..bdd7d1f88e 100644 --- a/rust/obs-encoder/src/ffi/mod.rs +++ b/rust/obs-encoder/src/ffi/mod.rs @@ -3,3 +3,4 @@ pub mod last_error; pub mod media_getters; pub mod packet_ownership; pub mod type_info; +pub mod video_tex_active; diff --git a/rust/obs-encoder/src/ffi/video_tex_active.rs b/rust/obs-encoder/src/ffi/video_tex_active.rs new file mode 100644 index 0000000000..1ce05bdd94 --- /dev/null +++ b/rust/obs-encoder/src/ffi/video_tex_active.rs @@ -0,0 +1,38 @@ +//! Borrow opaque C owners; never reproduce the encoder or mix layout in Rust. +use core::ffi::{c_int, c_void}; +use core::ptr::NonNull; + +unsafe extern "C" { + fn obs_encoder_video_tex_active_mix(encoder: *const c_void) -> *const c_void; + fn obs_encoder_video_tex_active_nv12(mix: *const c_void) -> bool; + fn obs_encoder_video_tex_active_p010(mix: *const c_void) -> bool; +} + +/// # Safety +/// As in C, the encoder and OBS core must be live and synchronized, and the +/// selected mix must remain readable through the query. NULL encoder is outside +/// the C API's contract; NULL media and an absent mix are valid. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_encoder_video_tex_active( + encoder: *const c_void, + format: c_int, +) -> bool { + // Reject an invalid owner before the C adapter can project encoder->media. + let encoder = NonNull::new(encoder.cast_mut()).expect("the C API requires a live encoder"); + crate::video_tex_active::video_tex_active( + format, + || { + // SAFETY: the owner was checked above; C retains the synchronized + // get_mix_for_video walk and reads the real encoder media field. + NonNull::new(unsafe { obs_encoder_video_tex_active_mix(encoder.as_ptr()) }.cast_mut()) + }, + |mix| { + // SAFETY: the safe core selects only a present mix and the NV12 flag. + unsafe { obs_encoder_video_tex_active_nv12(mix.as_ptr()) } + }, + |mix| { + // SAFETY: the safe core selects only a present mix and the P010 flag. + unsafe { obs_encoder_video_tex_active_p010(mix.as_ptr()) } + }, + ) +} diff --git a/rust/obs-encoder/src/video_tex_active.rs b/rust/obs-encoder/src/video_tex_active.rs index c2f344046c..035805a9bb 100644 --- a/rust/obs-encoder/src/video_tex_active.rs +++ b/rust/obs-encoder/src/video_tex_active.rs @@ -10,6 +10,12 @@ pub fn video_tex_active( nv12: impl FnOnce(M) -> bool, p010: impl FnOnce(M) -> bool, ) -> bool { - let _ = (format, lookup, nv12, p010); - todo!("swap the characterized texture-active query") + let Some(mix) = lookup() else { + return false; + }; + match format { + NV12 => nv12(mix), + P010 => p010(mix), + _ => false, + } } diff --git a/rust/obs-encoder/tests/encoder/main.rs b/rust/obs-encoder/tests/encoder/main.rs index 9810dfaab9..c71aca1cb3 100644 --- a/rust/obs-encoder/tests/encoder/main.rs +++ b/rust/obs-encoder/tests/encoder/main.rs @@ -11,3 +11,4 @@ mod encoder_module_parity; mod type_info; mod type_info_parity; mod video_tex_active; +mod video_tex_active_parity; diff --git a/rust/obs-encoder/tests/encoder/video_tex_active.rs b/rust/obs-encoder/tests/encoder/video_tex_active.rs index cb982fde7d..9863bc10ae 100644 --- a/rust/obs-encoder/tests/encoder/video_tex_active.rs +++ b/rust/obs-encoder/tests/encoder/video_tex_active.rs @@ -27,7 +27,10 @@ fn check(format: i32, media: Option, mixed: bool, flags: [bool; 2]) { selected.get()[1] }, ); - assert_eq!(result, mixed && ((format == NV12 && flags[0]) || (format == P010 && flags[1]))); + assert_eq!( + result, + mixed && ((format == NV12 && flags[0]) || (format == P010 && flags[1])) + ); let mut expected = vec!["lookup"]; if mixed && format == NV12 { expected.push("nv12"); diff --git a/rust/obs-encoder/tests/encoder/video_tex_active_parity.rs b/rust/obs-encoder/tests/encoder/video_tex_active_parity.rs new file mode 100644 index 0000000000..e0fc096c98 --- /dev/null +++ b/rust/obs-encoder/tests/encoder/video_tex_active_parity.rs @@ -0,0 +1,80 @@ +//! Tier 3: original C query and real mutex walk, using actual private layouts. +//! NULL encoders/cores and dangling mixes are excluded as undefined in C. +use core::ffi::{c_int, c_void}; +use obs_encoder::ffi::video_tex_active::obs_encoder_video_tex_active; +use obs_encoder::video_tex_active::{NV12, P010}; +use proptest::prelude::*; + +type Query = unsafe extern "C" fn(*const c_void, c_int) -> bool; +unsafe extern "C" { + fn oracle_encoder_tex_format_values(values: *mut c_int); + fn oracle_encoder_tex_check( + candidate: Query, + format: c_int, + media: u8, + mask: u8, + videos: *const u8, + flags: *const u8, + ) -> bool; +} + +#[test] +fn real_header_format_values() { + let mut values = [0; 3]; + // SAFETY: C writes exactly three integers measured from the real enum. + unsafe { oracle_encoder_tex_format_values(values.as_mut_ptr()) }; + assert_eq!(values, [NV12, P010, 25]); +} + +fn compare(format: i32, media: u8, mask: u8, videos: [u8; 3], flags: [u8; 3]) { + // SAFETY: C creates and snapshots live real-header encoder/core/mix owners, + // initializes the real mutex, calls both implementations, then destroys it. + // Both three-byte inputs remain live; pointers are compared, never dereferenced. + assert!( + unsafe { + oracle_encoder_tex_check( + obs_encoder_video_tex_active, + format, + media, + mask, + videos.as_ptr(), + flags.as_ptr(), + ) + }, + "format={format}, media={media}, mask={mask}, videos={videos:?}, flags={flags:?}" + ); +} + +#[test] +fn characterized_edges_and_first_matching_mix() { + for format in 0..=25 { + for flags in 0..4 { + for media in 0..4 { + for mask in [0, 1, 2, 4, 7] { + compare(format, media, mask, [1, 2, 3], [flags; 3]); + // Duplicate NULL/non-NULL videos select the first present mix. + compare( + format, + media, + mask, + [media; 3], + [flags, flags ^ 3, flags ^ 1], + ); + } + } + } + } +} + +proptest! { + #![proptest_config(ProptestConfig { cases: obs_c_oracle::parity::cases(512), failure_persistence: None, ..ProptestConfig::default() })] + #[test] + fn result_lookup_and_storage_match_original_c( + format in prop_oneof![0i32..=25, any::()], + media in 0u8..4, mask in 0u8..8, + videos in prop::array::uniform3(0u8..4), + flags in prop::array::uniform3(0u8..4), + ) { + compare(format, media, mask, videos, flags); + } +} diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 8a3dffd34e..a6355bbc4b 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -4124,6 +4124,31 @@ } ] }, + "test_encoder_video_tex_active_rust": { + "sources": [ + "test/cmocka/test_encoder_video_tex_active.c", + "test/cmocka/encoder-video-tex-active-fields-link-support.c" + ], + "definitions": [ + "get_mix_for_video=tex_active_recording_mix_lookup" + ], + "libraries": [ + "libobs_rust-static", + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ], + "requires": "HAVE_LIBOBS_RUST_STATIC", + "includes": [ + ".", + "libobs" + ] + }, "test_encoding_lag_rescale": { "sources": [ "test/cmocka/test_encoding_lag_rescale.c" @@ -23461,6 +23486,13 @@ "${target}" ] }, + "test_encoder_video_tex_active_rust": { + "target": "test_encoder_video_tex_active_rust", + "command": [ + "${target}" + ], + "requires": "HAVE_LIBOBS_RUST_STATIC" + }, "test_encoding_lag_rescale": { "target": "test_encoding_lag_rescale", "command": [ diff --git a/test/cmocka/encoder-video-tex-active-fields-link-support.c b/test/cmocka/encoder-video-tex-active-fields-link-support.c new file mode 100644 index 0000000000..6d66beaf1a --- /dev/null +++ b/test/cmocka/encoder-video-tex-active-fields-link-support.c @@ -0,0 +1,2 @@ +/* Real private adapters; the characterization may own the mix lookup. */ +#include "libobs/obs-encoder-video-tex-active-fields.c.h" diff --git a/test/cmocka/encoder-video-tex-active-mix-link-support.c b/test/cmocka/encoder-video-tex-active-mix-link-support.c new file mode 100644 index 0000000000..a3a150564c --- /dev/null +++ b/test/cmocka/encoder-video-tex-active-mix-link-support.c @@ -0,0 +1,2 @@ +/* Real synchronized C lookup, demand-linked alongside the shared core owner. */ +#include "libobs/obs-encoder-video-tex-active-mix.c.h" diff --git a/test/cmocka/tests.d/video_info_query_link_support.cmake b/test/cmocka/tests.d/video_info_query_link_support.cmake index 3dafa2a2d8..8bd1579776 100644 --- a/test/cmocka/tests.d/video_info_query_link_support.cmake +++ b/test/cmocka/tests.d/video_info_query_link_support.cmake @@ -7,6 +7,8 @@ function(_video_info_query_link_support) STATIC "${CMAKE_CURRENT_SOURCE_DIR}/video-info-query-link-support.c" "${CMAKE_CURRENT_SOURCE_DIR}/core-state-link-support.c" + "${CMAKE_CURRENT_SOURCE_DIR}/encoder-video-tex-active-fields-link-support.c" + "${CMAKE_CURRENT_SOURCE_DIR}/encoder-video-tex-active-mix-link-support.c" ) target_include_directories( video_info_query_link_support From 7b9441d31593aa30f4210f48fde3cceb73a67899 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 03:52:40 -0800 Subject: [PATCH 3/3] fix(obs-encoder): bind the static characterization to its Rust entry (Refs #5216) Ci-Attestation: {"at":1795090760,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":147,"stamp":"8698e64c00adcb2cfebadc6bbbbf21d2","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090760,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":147,"stamp":"7fb18f71754c3549f4347886155bdbdd","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090760,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":147,"stamp":"71dce3ccc4d856cff27d3033e665c0de","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090760,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":147,"stamp":"44349b9acd7d6ae53b692eb60b1bc20c","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090610,"gate":"general/all/client-lint","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"5e67daed2a11f962bcca17f4d8086bfd","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090760,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":147,"stamp":"d0ba4ed53778da4b1696eb48bfd4a735","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"f171e52894cf8a1ff7872d2d82bf252d","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090612,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"3a05269b3385422163b00fb2b2afbd77","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"7eb200ba2cc49c24e295216f683cce2e","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"3478a952e9ba0caf33b4e1b83343f41f","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"f4697977557c357dd3929397467cc0c8","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"218fdeac908a86c24a4ebe4a43a81f32","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"b1ffa0511eb79500e4a9cf02a91b5f67","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"9d1c3bed082bd116d64c6865288215fb","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"446e3de8dd71d6567da74a4155b4ce49","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"9abe2d416e62a6522355cdf3565773c5","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"4abd0faad64cfec9665bac777fbedd25","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795090611,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"22fc3c1cf44aafc3858876a0a55cd12fa017994f8c0f48ac7e8da8cce9560e44","lane":"client-lint","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":187,"stamp":"3c4c9e75e306fad27e80a968d4b1a4c7","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Ci-Attestation: {"at":1795091315,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"07957b92756a7944da54784cd78bd1abf4be930b72826a1125ac29f14fec00d9","lane":"client-test-x86_64-unknown-linux-gnu","parents":["b5cf4d778615f9aaf2c1b1cf74fdb297a331acde"],"secs":554,"stamp":"e827d9e0f274082968d7e73697a229f1","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef","v":1,"via":"run"} Client-Checks: {"checks":{"base":"e6942badc9ef36cd7b63a6f4fced41d4aa090e55","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core+.h.c","libobs/build/libobs.core-output+.h.c","libobs/build/libobs.graphics+.h.c","libobs/build/libobs.ported-encoder-video-tex-active+.h.c","libobs/build/libobs.ported-graphics-planar-capability-queries+.h.c","libobs/build/libobs.ported-output-total-bytes+.h.c","libobs/build/ported-source-sets/encoder-video-tex-active.json","libobs/build/ported-source-sets/graphics-planar-capability-queries.json","libobs/build/ported-source-sets/output-total-bytes.json","libobs/cmake/rust-exports.d/obs-encoder-video_tex_active.txt","libobs/cmake/rust-exports.d/obs-graphics-planar_capability_queries.txt","libobs/cmake/rust-exports.d/obs-output-output_total_bytes.txt","libobs/cmake/rust-hidden.d/obs-encoder-video_tex_active.txt","libobs/graphics/graphics-device-queries-fields.c.h","libobs/graphics/graphics-planar-capability-queries.c.h","libobs/obs-encoder-video-tex-active-fields.c.h","libobs/obs-encoder-video-tex-active-mix.c.h","libobs/obs-internal.h","libobs/obs-output-total-bytes-fields.c.h","libobs/obs-output-total-bytes-query-support.c.h","libobs/obs.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_output_total_bytes_swap_is_registered.rs","rust/obs-build/tests/native/registration/canonical_video_info_query_is_registered.rs","rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json","rust/obs-c-oracle/legacy/graphics-planar-capability-queries.c","rust/obs-c-oracle/oracle.d/encoder-video-tex-active-mix.list","rust/obs-c-oracle/oracle.d/encoder-video-tex-active.list","rust/obs-c-oracle/oracle.d/graphics-planar-capability-queries.list","rust/obs-c-oracle/oracle/device_queries.c","rust/obs-c-oracle/oracle/encoder_video_tex_active.c","rust/obs-c-oracle/oracle/output_total_bytes.c","rust/obs-encoder/src/ffi/mod.rs","rust/obs-encoder/src/ffi/video_tex_active.rs","rust/obs-encoder/src/lib.rs","rust/obs-encoder/src/video_tex_active.rs","rust/obs-encoder/tests/encoder/main.rs","rust/obs-encoder/tests/encoder/video_tex_active.rs","rust/obs-encoder/tests/encoder/video_tex_active_parity.rs","rust/obs-graphics/src/ffi/mod.rs","rust/obs-graphics/src/ffi/planar_capability_queries.rs","rust/obs-graphics/src/lib.rs","rust/obs-graphics/src/planar_capability_queries.rs","rust/obs-graphics/tests/render/main.rs","rust/obs-graphics/tests/render/planar_capability_queries.rs","rust/obs-graphics/tests/render/planar_capability_queries_parity.rs","rust/obs-output/src/ffi/mod.rs","rust/obs-output/src/ffi/output_total_bytes.rs","rust/obs-output/src/lib.rs","rust/obs-output/src/output_total_bytes.rs","rust/obs-output/tests/output/main.rs","rust/obs-output/tests/output/output_total_bytes.rs","rust/obs-output/tests/output/output_total_bytes_parity.rs","test/cmocka/build/test-graph.json","test/cmocka/encoder-video-tex-active-fields-link-support.c","test/cmocka/encoder-video-tex-active-mix-link-support.c","test/cmocka/output-total-bytes-link-support.c","test/cmocka/tests.d/output_total_bytes_link_support.cmake","test/cmocka/tests.d/video_info_query_link_support.cmake"],"head":"d97866eb5e02ed6e5198d614e7686b1c0964a415","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":"75049d7298333a25ecc6ecddd251086cb8587e622db5e56e8d6757e669c0c1a8","tree":"bd0a21f90c229d8645d6579c65ccdb627b240aef"}} --- .../rust-hidden.d/obs-encoder-video_tex_active.txt | 1 + .../header/test_encoder_video_tex_active.json | 3 ++- rust/obs-encoder/src/ffi/video_tex_active.rs | 14 ++++++++++++++ test/cmocka/build/test-graph.json | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 libobs/cmake/rust-hidden.d/obs-encoder-video_tex_active.txt diff --git a/libobs/cmake/rust-hidden.d/obs-encoder-video_tex_active.txt b/libobs/cmake/rust-hidden.d/obs-encoder-video_tex_active.txt new file mode 100644 index 0000000000..0bbed21edf --- /dev/null +++ b/libobs/cmake/rust-hidden.d/obs-encoder-video_tex_active.txt @@ -0,0 +1 @@ +obs_encoder_video_tex_active_rust diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json b/rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json index 7bce85c32f..f14204c92f 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/header/test_encoder_video_tex_active.json @@ -7,7 +7,8 @@ "test/cmocka/encoder-video-tex-active-fields-link-support.c" ], "definitions": [ - "get_mix_for_video=tex_active_recording_mix_lookup" + "get_mix_for_video=tex_active_recording_mix_lookup", + "obs_encoder_video_tex_active=obs_encoder_video_tex_active_rust" ], "libraries": [ "libobs_rust-static", diff --git a/rust/obs-encoder/src/ffi/video_tex_active.rs b/rust/obs-encoder/src/ffi/video_tex_active.rs index 1ce05bdd94..1a81940b79 100644 --- a/rust/obs-encoder/src/ffi/video_tex_active.rs +++ b/rust/obs-encoder/src/ffi/video_tex_active.rs @@ -16,6 +16,20 @@ unsafe extern "C" { pub unsafe extern "C" fn obs_encoder_video_tex_active( encoder: *const c_void, format: c_int, +) -> bool { + // SAFETY: the private entry has the same ownership contract as this API. + unsafe { obs_encoder_video_tex_active_rust(encoder, format) } +} + +/// Private static-link entry: shared libobs must never satisfy a fixture's +/// Rust query before its archive member is selected (notably with frameworks). +/// +/// # Safety +/// Identical live-encoder/core/mix contract to obs_encoder_video_tex_active. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_encoder_video_tex_active_rust( + encoder: *const c_void, + format: c_int, ) -> bool { // Reject an invalid owner before the C adapter can project encoder->media. let encoder = NonNull::new(encoder.cast_mut()).expect("the C API requires a live encoder"); diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index a6355bbc4b..4983f85a56 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -4130,7 +4130,8 @@ "test/cmocka/encoder-video-tex-active-fields-link-support.c" ], "definitions": [ - "get_mix_for_video=tex_active_recording_mix_lookup" + "get_mix_for_video=tex_active_recording_mix_lookup", + "obs_encoder_video_tex_active=obs_encoder_video_tex_active_rust" ], "libraries": [ "libobs_rust-static",