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
3 changes: 2 additions & 1 deletion libobs/build/libobs.core+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "libobs/obs-core-initialized-fields.c.h"
#include "libobs/obs-core-monitoring-device-fields.c.h"
#include "libobs/obs-core-output-protocol-registry-fields.c.h"
#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-enum-scenes-fields.c.h"
Expand Down Expand Up @@ -49,7 +50,7 @@
#include "libobs/obs-set-output-source-fields.c.h"
#include "libobs/obs-shutdown-detach.c.h"
#include "libobs/obs-ui-task-handler-fields.c.h"
#include "libobs/obs-video-info-query.c.h"
#include "libobs/obs-video-info-query-fields.c.h"
#include "libobs/obs-video-level-queries.c.h"
#include "libobs/obs-weak-object-expired-fields.c.h"
#include "libobs/obs-weak-object-identity-fields.c.h"
Expand Down
4 changes: 4 additions & 0 deletions libobs/build/libobs.ported-video-info-query+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Unity group (BUILD.md): original core video-info query, reference only. */
#include "libobs/build/libobs.pch.h"

#include "libobs/obs-video-info-query.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/video-info-query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-video-info-query+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_get_video_info
4 changes: 4 additions & 0 deletions libobs/obs-core-state.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "libobs/build/libobs.pch.h"

/* The production core pointer, also linked by standalone real-adapter tests. */
struct obs_core *obs = NULL;
6 changes: 6 additions & 0 deletions libobs/obs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ extern struct obs_core_texture_activity_fields obs_core_texture_activity_fields(
/* Borrowed argument snapshot; setter/shutdown retain allocation ownership. */
extern struct obs_cmdline_args *obs_core_cmdline_args_field(void);

/* Core video-info seam: every owner must be checked before field access. */
extern const struct obs_core *obs_video_info_query_core(void);
extern graphics_t *const *obs_video_info_query_graphics_field(const struct obs_core *core);
extern struct obs_core_video_mix *const *obs_video_info_query_mix_field(const struct obs_core *core);
extern const struct obs_video_info *obs_video_info_query_value_field(const struct obs_core_video_mix *mix);

/* Frame interval seam: check core presence before obtaining the member address. */
extern const struct obs_core *obs_core_frame_interval_core(void);
extern const uint64_t *obs_core_frame_interval_field(const struct obs_core *core);
Expand Down
21 changes: 21 additions & 0 deletions libobs/obs-video-info-query-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "libobs/build/libobs.pch.h"

const struct obs_core *obs_video_info_query_core(void)
{
return obs;
}

graphics_t *const *obs_video_info_query_graphics_field(const struct obs_core *core)
{
return &core->video.graphics;
}

struct obs_core_video_mix *const *obs_video_info_query_mix_field(const struct obs_core *core)
{
return &core->data.main_canvas->mix;
}

const struct obs_video_info *obs_video_info_query_value_field(const struct obs_core_video_mix *mix)
{
return &mix->ovi;
}
2 changes: 0 additions & 2 deletions libobs/obs.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "libobs/build/libobs.pch.h"

struct obs_core *obs = NULL;

extern char *find_libobs_data_file(const char *file);

static void obs_free_render_textures(struct obs_core_video_mix *video);
Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,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-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). |
| `libobs/obs-video-render-passes.c.h` | `obs-core::video_render_passes` | Mix canvas copy and conversion pass orchestration through synchronous graphics callbacks; hidden ABI with no shared layouts. Preserves ignored begin-pass failure and framebuffer sRGB reset to false. Unchanged C recording assertions exercise the Rust replacement; Tier 3 compares original C and Rust call traces. Internal helpers only: no GPU image-quality or Tier 4 claim. |
Expand Down
2 changes: 2 additions & 0 deletions rust/obs-build/tests/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ mod canonical_transport_helpers_are_registered;
mod canonical_undo_stack_is_registered;
#[path = "native/registration/canonical_vaapi_device_select_is_registered.rs"]
mod canonical_vaapi_device_select_is_registered;
#[path = "native/registration/canonical_video_info_query_is_registered.rs"]
mod canonical_video_info_query_is_registered;
#[path = "native/registration/canonical_video_output_compatibility_is_registered.rs"]
mod canonical_video_output_compatibility_is_registered;
#[path = "native/registration/canonical_video_scaler_direct_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use super::*;

#[test]
fn canonical_video_info_query_is_registered() {
use obs_build::validation::graph::{Graph, Source};
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let mut graph = Graph::load(&root.join("test/cmocka/build/test-graph.json")).unwrap();
let c = &graph.targets["test_video_info_query"];
let rust = &graph.targets["test_video_info_query_rust"];
assert!(
matches!(&c.sources[0], Source::Path(path) if path == "test/cmocka/test_video_info_query.c")
);
assert!(
matches!(&rust.sources[0], Source::Path(path) if path == "test/cmocka/test_video_info_query.c")
);
assert!(
matches!(&c.sources[1], Source::Path(path) if path == "libobs/obs-video-info-query.c.h")
);
assert!(
matches!(&rust.sources[1], Source::Path(path) if path == "test/cmocka/video-info-query-link-support.c")
);
graph
.targets
.retain(|name, _| name.starts_with("test_video_info_query"));
graph
.tests
.retain(|name, _| name.starts_with("test_video_info_query"));
for os in ["OS_LINUX", "OS_MACOS", "OS_WINDOWS"] {
let selected = graph
.select(&[(os.into(), true), ("HAVE_LIBOBS_RUST_STATIC".into(), true)].into())
.unwrap();
for name in ["test_video_info_query", "test_video_info_query_rust"] {
assert!(selected.targets.contains_key(name), "{os}: {name}");
assert!(selected.tests.contains_key(name), "{os}: {name}");
}
assert!(
selected.targets["test_video_info_query_rust"]
.libraries
.iter()
.any(|lib| matches!(lib, obs_build::validation::graph::ConditionalValue::Name(name) if name == "libobs_rust-static"))
);
}
let group = fs::read_to_string(root.join("libobs/build/libobs.core+.h.c")).unwrap();
assert!(group.contains("obs-video-info-query-fields.c.h"));
assert!(!group.contains("\"libobs/obs-video-info-query.c.h\""));
}

/// Private adapters are hidden in shared libobs, so linking it must not exclude
/// a Rust-static consumer from the demand-linked real-adapter support archive.
#[test]
fn video_info_query_support_covers_all_rust_static_consumers() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let temporary = tempfile::tempdir().unwrap();
let source = temporary.path();
fs::write(source.join("main.c"), "int main(void) { return 0; }\n").unwrap();
fs::write(
source.join("CMakeLists.txt"),
format!(
r#"cmake_minimum_required(VERSION 3.28)
project(video_info_query_support C)
set(CMAKE_SOURCE_DIR "{root}")
set(CMAKE_CURRENT_SOURCE_DIR "{root}/test/cmocka")
add_library(libobs_rust-static INTERFACE)
add_library(OBS::libobs INTERFACE IMPORTED)
add_library(OBS::caption INTERFACE IMPORTED)
add_library(Uthash::Uthash INTERFACE IMPORTED)
add_library(OBS::w32-pthreads INTERFACE IMPORTED)
foreach(name IN ITEMS standalone with_shared future_consumer reference)
add_executable(${{name}} "{source}/main.c")
if(NOT name STREQUAL "reference")
target_link_libraries(${{name}} PRIVATE libobs_rust-static)
endif()
endforeach()
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)
foreach(name IN ITEMS standalone with_shared future_consumer reference)
get_target_property(links ${{name}} LINK_LIBRARIES)
if(name STREQUAL "reference")
if("video_info_query_link_support" IN_LIST links)
message(FATAL_ERROR "${{name}}: unexpected Rust adapter support")
endif()
elseif(NOT "video_info_query_link_support" IN_LIST links)
message(FATAL_ERROR "${{name}}: missing private video-info adapters")
endif()
endforeach()
endfunction()
cmake_language(DEFER CALL check_support)
"#,
root = dunce::canonicalize(&root)
.unwrap()
.to_string_lossy()
.replace('\\', "/"),
source = source.to_string_lossy().replace('\\', "/"),
),
)
.unwrap();
let output = std::process::Command::new("cmake")
.arg("-S")
.arg(source)
.arg("-B")
.arg(source.join("build"))
.output()
.unwrap();
assert!(
output.status.success(),
"{}{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"schema": 1,
"targets": {
"test_video_info_query_rust": {
"sources": [
"test/cmocka/test_video_info_query.c",
"test/cmocka/video-info-query-link-support.c",
"libobs/util/base-variadic.c.h"
],
"libraries": [
"libobs_rust-static",
"OBS::caption",
"Uthash::Uthash",
"OBS::native-test-cmocka",
{
"name": "OBS::w32-pthreads",
"requires": "OS_WINDOWS"
},
{
"name": "LibUUID::LibUUID",
"requires": "OS_LINUX"
},
{
"name": "gio::gio",
"requires": "HAVE_PORTAL_TEST_GIO"
},
{
"name": "PkgConfig::PORTAL_TEST_GLIB",
"requires": "HAVE_PORTAL_TEST_GIO"
},
{
"name": "Rpcrt4",
"requires": "OS_WINDOWS"
},
{
"name": "winmm",
"requires": "OS_WINDOWS"
}
],
"header_libraries": [
"OBS::libobs",
"SIMDe::SIMDe"
],
"includes": [
".",
"libobs"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
},
"tests": {
"test_video_info_query_rust": {
"target": "test_video_info_query_rust",
"command": [
"${target}"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
}
}
Loading
Loading