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+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions libobs/build/libobs.ported-type-catalog-enum+.h.c
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/type-catalog-enum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-type-catalog-enum+.h.c"
]
}
6 changes: 6 additions & 0 deletions libobs/cmake/rust-exports.d/obs-core-type_catalog_enum.txt
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions libobs/obs-type-catalog-enum-fields.c.h
Original file line number Diff line number Diff line change
@@ -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();
}
}
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
Expand Down
3 changes: 3 additions & 0 deletions rust/obs-build/tests/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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\""));
}
118 changes: 118 additions & 0 deletions rust/obs-c-oracle/oracle/type_catalog_enum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* Original six bodies, real-header catalog fixtures and production adapters. */
#include "libobs/build/libobs.pch.h"
#include <string.h>
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;
}
1 change: 1 addition & 0 deletions rust/obs-core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading