Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libobs/build/libobs.core-output+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
#include "libobs/obs-output-video-encoder-getter-fields.c.h"
#include "libobs/obs-output.c.h"
#include "libobs/obs-service-context-getter-fields.c.h"
#include "libobs/obs-service-find.c.h"
#include "libobs/obs-service-find-fields.c.h"
#include "libobs/obs-service-handler-getters-fields.c.h"
#include "libobs/obs-service-info-accessors-fields.c.h"
#include "libobs/obs-service-state-adapter.c.h"
Expand Down
4 changes: 4 additions & 0 deletions libobs/build/libobs.ported-service-find+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Original C service registry lookup, retained for the C reference. */
#include "libobs/build/libobs.pch.h"

#include "libobs/obs-service-find.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/service-find.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-service-find+.h.c"
]
}
1 change: 1 addition & 0 deletions libobs/cmake/rust-hidden.d/obs-output-service_find.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_service
19 changes: 19 additions & 0 deletions libobs/obs-service-find-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "libobs/build/libobs.pch.h"

size_t obs_service_find_count(void);
size_t obs_service_find_count(void)
{
return obs->service_types.num;
}

const struct obs_service_info *obs_service_find_entry(size_t index);
const struct obs_service_info *obs_service_find_entry(size_t index)
{
return obs->service_types.array + index;
}

const char *obs_service_find_id(const struct obs_service_info *entry);
const char *obs_service_find_id(const struct obs_service_info *entry)
{
return entry->id;
}
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-output-update.c.h` | `obs-output::output_update` | Swapped in hybrid `libobs` (group `libobs.ported-output-update`). `obs_output_update()` merges the incoming settings into the stored ones through `obs_data_apply()`, then calls the type's `update` with the plugin data and the stored settings when it has one; a NULL output logs and does nothing else. The live adapter `obs-output-update-fields.c.h` gives the stored settings, whether the type has an update, and the call. No lock, as in C, and nothing of the output is held across the plugin's callback. Tier 1 mirrors of the unchanged Tier 2 characterization and original-C differential coverage of the merged settings and the callback. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-service-weak-acquire.c.h` | `obs-output::service_weak_acquire` | Swapped in hybrid libobs (#3837): the hidden `obs_weak_service_weak_get_ref` and `obs_weak_service_target` read the unchanged C weak-control layout, using the platform C-long-width SeqCst atomic count. Tier 2 keeps the existing service lifecycle tests; Tier 3 checks both private layouts against the real C header and compares return values, target and both counts. No intended behavior differences for defined C inputs. Acquisition at `LONG_MAX` (signed overflow in C) and NULL controls (invalid in C) are outside the parity domain. Release/free are ported in #3838, module lookup is #3839, and context/state/handlers are #3840. |
| `libobs/obs-service-context-getters.c.h` | `obs-output::service_context_getters` | Hidden borrowed name/settings getters (#4483), using real private C field addresses. No allocation, reference acquisition or mutation. Original C retained in its reference-only group; Tier 3 checks nullable field values, exact pointer identity, field addresses and unchanged service bytes. NULL services remain outside the original caller contract. |
| `libobs/obs-service-find.c.h` | `obs-output::service_find` | Hidden first byte-exact match in the C-owned service registry (#5273). Real private projections retain native layouts and borrowed pointer identity; lookup is lazy safe Rust, with unchanged external C characterization and original-C differential coverage. |
| `libobs/obs-service-getters.c.h` | `obs-output::service` | Swapped in hybrid `libobs` (group `libobs.ported-service-getters`), #1899. The nine exported service getters (`obs_service_get_protocol`, `_get_connect_info`, `_can_try_to_connect`, `_get_preferred_output_type`, `_get_max_fps`, `_get_max_bitrate`, `_get_supported_resolutions` and the two codec lists), moved out of `obs-service.c.h`. `struct obs_service` stays C: the shims reach the plugin's `obs_service_info` table and data through the hidden `obs_service_get_info_table()` and `obs_service_get_plugin_data()` kept beside it, and mirror `struct obs_service_info` (the public plugin ABI) with its layout checked against the C. #1913 moved the settings, properties and identity functions the same way: `obs_service_get_display_name`, `obs_service_defaults` and `obs_get_service_properties` (by id, through `find_service()`), and `obs_service_get_name`, `_get_type`, `_get_id`, `_get_type_data`, `_update`, `_get_settings`, `_properties` and `_apply_encoder_settings`; the context name and settings come through the hidden `obs_service_get_context_name()` and `_get_context_settings()`, and the `obs_data_t` / `obs_properties_t` calls go to libobs. `obs_service_get_signal_handler` and `_get_proc_handler` are now ported separately (see below); neither has a public header declaration. #1920 moved the rest the same way: `obs_service_create`, `_create_private`, `_destroy` (deferred while active), `_release`, the strong and weak reference functions, `obs_service_get_module` and `_load_state`, and the output-side `obs_service_activate`, `_deactivate` and `_initialize` (hidden). `struct obs_service`, its context (`obs_context_data_*`) and its reference counts (`obs_ref_*`, `obs_weak_ref_*`) stay C behind hidden `obs_service_*()` / `obs_weak_service_*()` steps in `obs-service.c.h`; the port keeps their order, the release order (destroy, then the control's weak ref) and the log lines. The C's check-and-zero order is kept, including what `test_service_getters` marks "characterized, not endorsed": `get_max_bitrate` zeroes its out-parameters before checking the service, and the codec getters do not check for NULL. Tier 2 runs `test_service_getters`, `test_service_settings` and `test_service_lifecycle` through the hybrid libobs; for #1913 Tier 3 runs every function on both sides over the 32 tables of its four optional callbacks and type data, comparing returns, settings contents and the plugin call trace; for #1920 Tier 3 runs create, refs, activation and the deferred destroy on both sides over every table of its three optional callbacks, a failing `create()` and both `initialize()` results, comparing results and the trace of every step and plugin call, plus the module lookups over the same module lists; Tier 3 runs every getter on the Rust and the C with the same service over all 256 optional-callback tables, NULL and sentinel out-parameters, comparing returns, out-parameters and the plugin call trace. |
| `libobs/obs-service-handler-getters.c.h` | `obs-output::service_handler_getters` | Hidden borrowed signal/procedure handlers swapped in hybrid libobs (#5002; parent #3840). Preserves exact NULL diagnostics, independent nullable handlers, pointer identity and unchanged service bytes. Guarded real field adapter, real-header layout, Tier 1, C-oracle differential/mutation and unchanged C characterization via declaration-only Rust-static mode. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-service-info-accessors.c.h` | `obs-output::service_info_accessors` | Swapped in hybrid `libobs` (#3840; group `libobs.ported-service-info-accessors` keeps the original for the C reference). The hidden `obs_service_set_info`, `obs_service_get_info_table`, `obs_service_set_plugin_data` and `obs_service_get_plugin_data` (`obs-internal.h`, listed in `rust-hidden.d`), which the service lifecycle and getters call. Rust copies the whole table by value into the service (reading the source first, so a table copied onto itself is unchanged), returns the borrowed address of the service's own copy, and stores and returns the plugin data as it is, NULL included; nothing else in the service changes and nothing is logged. A private field adapter (`obs-service-info-accessors-fields.c.h`) keeps `struct obs_service` in C; the Rust-static support member now supplies that adapter instead of the original, and the service oracle's own copies of the four names are gone. The unchanged `test_service_info_accessors` keeps testing the C source; its twin `test_service_info_accessors_rust` runs the same assertions on the Rust shims. Tier 1 mirrors every assertion; Tier 3 runs the original and the shims on byte-pattern services (characterized and random set/get sequences, self-copy included), comparing results, whole services and source tables, with real-header layout checks and mutants. No intentional differences; Tier 4 does not apply. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static CASES: std::sync::LazyLock<Vec<String>> =
#[test]
fn canonical_rust_static_private_steps_are_registered() {
let graph = rust_static_entries::assert_family(FAMILY);
assert_eq!(CASES.len(), 8);
assert_eq!(CASES.len(), 9);
for windows in [false, true] {
for msvc in [false, true] {
for available in [false, true] {
Expand All @@ -19,8 +19,8 @@ fn canonical_rust_static_private_steps_are_registered() {
]
.into();
let selected = graph.select(&facts).unwrap();
assert_eq!(selected.targets.len(), if available { 8 } else { 0 });
assert_eq!(selected.tests.len(), if available { 8 } else { 0 });
assert_eq!(selected.targets.len(), if available { 9 } else { 0 });
assert_eq!(selected.tests.len(), if available { 9 } else { 0 });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ 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 encoder-get-name
output-interleave-name source-audio-capture-callback)
foreach(adapter IN ITEMS encoder-get-name encoder-video-tex-active-fields encoder-video-tex-active-mix
output-interleave-name service-find source-audio-capture-callback)
if(NOT "{root}/test/cmocka/${{adapter}}-link-support.c" IN_LIST adapter_sources)
message(FATAL_ERROR "missing real private adapter source: ${{adapter}}")
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"schema": 1,
"targets": {
"test_service_find_rust": {
"sources": [
"test/cmocka/test_service_find.c",
"test/cmocka/service-find-registry-adapter.c"
],
"libraries": [
"libobs_rust-static",
"OBS::libobs",
"OBS::caption",
"Uthash::Uthash",
"OBS::native-test-cmocka",
{
"name": "OBS::w32-pthreads",
"requires": "OS_WINDOWS"
}
],
"definitions": [
"SERVICE_FIND_EXTERNAL"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
},
"tests": {
"test_service_find_rust": {
"target": "test_service_find_rust",
"command": [
"${target}"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
}
}
1 change: 1 addition & 0 deletions rust/obs-c-oracle/oracle.d/service-find.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service-find.inc|libobs/obs-service-find.c.h|auto
94 changes: 94 additions & 0 deletions rust/obs-c-oracle/oracle/service_find.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* Original lookup and real field projections, with a controlled C-owned core. */
#include "obs-internal.h"
#include <string.h>

static struct obs_core service_find_oracle_storage;
static struct obs_core *service_find_oracle_core = &service_find_oracle_storage;
#define obs service_find_oracle_core
#define find_service oracle_find_service
const struct obs_service_info *oracle_find_service(const char *id);
#include "service-find.inc"
#undef find_service
#include "service_find_fields.inc"
#undef obs

void oracle_service_set_types(const struct obs_service_info *types, size_t num);
void oracle_service_set_types(const struct obs_service_info *types, size_t num)
{
/* The lookup only borrows this table; it never writes through the C field. */
memcpy(&service_find_oracle_storage.service_types.array, &types, sizeof(types));
service_find_oracle_storage.service_types.num = num;
service_find_oracle_storage.service_types.capacity = num;
}

static unsigned service_find_calls;
static const char *service_find_name(void *data)
{
(void)data;
service_find_calls++;
return "unused";
}
static void *service_find_create(obs_data_t *settings, obs_service_t *service)
{
(void)settings;
(void)service;
service_find_calls++;
return NULL;
}
static void service_find_destroy(void *data)
{
(void)data;
service_find_calls++;
}

typedef const struct obs_service_info *(*service_find_fn)(const char *);
bool oracle_service_find_check(const char *const *ids, size_t num, size_t capacity, const char *query,
service_find_fn rust_find);
bool oracle_service_find_check(const char *const *ids, size_t num, size_t capacity, const char *query,
service_find_fn rust_find)
{
if (num > capacity || capacity > 8)
return false;
struct obs_service_info entries[8] = {0};
struct obs_service_info before[8];
int owners[8] = {0};
unsigned char saved[sizeof(service_find_oracle_storage)];
memcpy(saved, &service_find_oracle_storage, sizeof(saved));
for (size_t i = 0; i < capacity; i++) {
entries[i].id = ids[i];
entries[i].get_name = service_find_name;
entries[i].create = service_find_create;
entries[i].destroy = service_find_destroy;
entries[i].free_type_data = service_find_destroy;
entries[i].type_data = &owners[i];
}
oracle_service_set_types(entries, num);
service_find_oracle_storage.service_types.capacity = capacity;
bool ok = true;
/* Repeat after replacing and moving entries: no stale cached result. */
for (unsigned step = 0; step < 3; step++) {
memcpy(before, entries, sizeof(entries));
unsigned char core_before[sizeof(service_find_oracle_storage)];
memcpy(core_before, &service_find_oracle_storage, sizeof(core_before));
service_find_calls = 0;
const struct obs_service_info *expected = oracle_find_service(query);
const struct obs_service_info *actual = rust_find(query);
ok = ok && actual == expected && service_find_calls == 0 &&
memcmp(entries, before, sizeof(entries)) == 0 &&
memcmp(core_before, &service_find_oracle_storage, sizeof(core_before)) == 0 &&
memcmp(owners, (int[8]){0}, sizeof(owners)) == 0;
if (actual && expected)
ok = ok && actual->id == expected->id && actual->type_data == expected->type_data;
if (num) {
if (step == 0) {
struct obs_service_info swap = entries[0];
entries[0] = entries[num - 1];
entries[num - 1] = swap;
} else {
entries[0].id = "replaced";
}
}
}
memcpy(&service_find_oracle_storage, saved, sizeof(saved));
return ok;
}
32 changes: 7 additions & 25 deletions rust/obs-c-oracle/oracle/service_getters.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* Test-only oracle: the original libobs/obs-service-getters.c.h, unmodified,
* with its exports renamed to oracle_* so it can link next to the Rust
* shims (#1899, #1913, #1920). find_service() and the context accessors are
* test doubles that both sides call. The info-table and plugin-data
* accessors are the Rust port's (#3840), through the real field adapter in
* oracle/service_info_accessors.c, and oracle_service_new() builds the
* struct obs_service both sides read, so the parity tests drive the C and
* the Rust with the same service. */
* shims (#1899, #1913, #1920). The context accessors are
* test doubles that both sides call; registry lookup uses its real seam.
* The info-table and plugin-data accessors are the Rust port's (#3840),
* through the real field adapter in oracle/service_info_accessors.c.
* oracle_service_new() builds the struct obs_service both sides read,
* so the parity tests drive the C and the Rust with the same service. */
#ifndef _WIN32
#define _GNU_SOURCE
#endif
Expand Down Expand Up @@ -231,25 +231,7 @@ void *oracle_service_control(const obs_service_t *service)
return service->context.control;
}

/* obs-service.c's find_service() over obs->service_types, here over one
* table the test sets (NULL: no types). */
static const struct obs_service_info *oracle_types;
static size_t oracle_types_num;

void oracle_service_set_types(const struct obs_service_info *types, size_t num);
void oracle_service_set_types(const struct obs_service_info *types, size_t num)
{
oracle_types = types;
oracle_types_num = num;
}

const struct obs_service_info *find_service(const char *id)
{
for (size_t i = 0; i < oracle_types_num; i++)
if (strcmp(oracle_types[i].id, id) == 0)
return oracle_types + i;
return NULL;
}
/* Registry setup and lookup now use the real service-find C seam. */

/* The context fields #1913 reads; the plugin data and table are set by
* oracle_service_new(). */
Expand Down
1 change: 1 addition & 0 deletions rust/obs-output/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ mod output_type_lookup;
pub mod output_video_checks;
pub mod service;
pub mod service_context_getters;
pub mod service_find;
pub mod service_module_lookup;
pub mod service_state;
pub mod service_weak_acquire;
Expand Down
30 changes: 30 additions & 0 deletions rust/obs-output/src/ffi/service_find.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Private ABI for the service registry lookup. C retains layouts and storage.
use core::ffi::{CStr, c_char, c_void};

unsafe extern "C" {
fn obs_service_find_count() -> usize;
fn obs_service_find_entry(index: usize) -> *const c_void;
fn obs_service_find_id(entry: *const c_void) -> *const c_char;
}

/// Return the first byte-exact match as a borrowed pointer into the live registry.
///
/// # Safety
/// The core must be initialized. `id` and registered IDs must be valid C strings;
/// the C-owned registry must remain live and unmodified throughout the call.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn find_service(id: *const c_char) -> *const c_void {
// SAFETY: the caller preserves the original C lookup preconditions. Each
// index is below the logical count, and C projects its own native layout.
unsafe {
let entries = (0..obs_service_find_count()).filter_map(|index| {
let entry = obs_service_find_entry(index);
if entry.is_null() {
return None;
}
Some((CStr::from_ptr(obs_service_find_id(entry)).to_bytes(), entry))
});
crate::service_find::find(CStr::from_ptr(id).to_bytes(), entries)
.unwrap_or(core::ptr::null())
}
}
1 change: 1 addition & 0 deletions rust/obs-output/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub mod raw_audio;
pub mod raw_audio_trim;
pub mod service;
pub mod service_context_getters;
pub mod service_find;
pub mod service_module_lookup;
pub mod service_state;
pub mod service_weak_acquire;
Expand Down
8 changes: 8 additions & 0 deletions rust/obs-output/src/service_find.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Borrowed, byte-exact lookup in the C-owned service registry.

/// Walk IDs lazily and return the first matching entry without copying it.
pub fn find<'a, T>(id: &[u8], entries: impl IntoIterator<Item = (&'a [u8], T)>) -> Option<T> {
entries
.into_iter()
.find_map(|(entry_id, entry)| (entry_id == id).then_some(entry))
}
2 changes: 2 additions & 0 deletions rust/obs-output/tests/output/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ mod raw_audio_trim_parity;
mod service;
mod service_context_getters;
mod service_context_getters_parity;
mod service_find;
mod service_find_parity;
mod service_lifecycle;
mod service_lifecycle_parity;
mod service_module_lookup;
Expand Down
Loading
Loading