Skip to content
Closed
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-source+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "libobs/obs-scene-ref-fields.c.h"
#include "libobs/obs-scene-source-fields.c.h"
#include "libobs/obs-scene.c.h"
#include "libobs/obs-sceneitem-defer-update.c.h"
#include "libobs/obs-sceneitem-defer-update-fields.c.h"
#include "libobs/obs-shader-param-introspection-fields.c.h"
#include "libobs/obs-source-async-compensation-fields.c.h"
#include "libobs/obs-source-async-decoupled-fields.c.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-sceneitem-defer-update+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): C reference for scene-item transform deferral. */

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

#include "libobs/obs-sceneitem-defer-update.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/sceneitem-defer-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-sceneitem-defer-update+.h.c"
]
}
2 changes: 2 additions & 0 deletions libobs/cmake/rust-exports.d/obs-scene-item_defer_update.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
obs_sceneitem_defer_update_begin
obs_sceneitem_defer_update_end
16 changes: 16 additions & 0 deletions libobs/obs-sceneitem-defer-update-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "libobs/build/libobs.pch.h"

/* C owns the counter layout and the platform's atomic long implementation.
* Return the RMW result: a separate load could observe another caller. */
long obs_sceneitem_defer_update_increment(obs_sceneitem_t *item);
long obs_sceneitem_defer_update_decrement(obs_sceneitem_t *item);

long obs_sceneitem_defer_update_increment(obs_sceneitem_t *item)
{
return os_atomic_inc_long(&item->defer_update);
}

long obs_sceneitem_defer_update_decrement(obs_sceneitem_t *item)
{
return os_atomic_dec_long(&item->defer_update);
}
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-scene-item-crop-fields.c.h` | `obs-scene::item_crop_getter` | The crop getter preserves item-before-output debug diagnostics, all four signed integers and the captured parent video mutex. Complete output/state byte parity, real-header layout, integer extremes, recursive ownership and concurrent publication are covered. No intentional differences. |
| `libobs/obs-scene-item-crop-setter.c.h` | `obs-scene::item_crop_setter` | Swapped in hybrid `libobs` (group `libobs.ported-scene-item-crop-setter`). Public `obs_sceneitem_set_crop` reuses the crop getter's layout-checked item prefix and the existing item fields lock, so it needs no new C adapter. It clamps the input before the lock, compares the raw input (not the clamped crop) with the stored one under the lock, stores the clamped crop and sets `update_transform` after the unlock; a negative input therefore stores and marks every time (characterized, not endorsed). Null item and crop keep their debug diagnostics, item first. The unchanged C characterization runs against hybrid and C reference; Tier 3 compares whole-item bytes, the lock release and lock waiting against the verbatim C with the original clamp. No intentional differences. |
| `libobs/obs-scene-item-group-resize-defer.c.h` | `obs-scene::group_resize_defer` | Atomic begin/end preserve nesting and unmatched-end underflow. Only an end whose decrement returns zero schedules a resize; neither entry point takes the scene mutex, emits signals or runs transforms. The existing update walk consumes the flag later. Native C field operations retain platform long widths and atomic ordering; no item layout is mirrored. NULL diagnostics and bounded operation sequences compare every real-header item byte against the unchanged C reference. |
| `libobs/obs-sceneitem-defer-update.c.h` | `obs-scene::item_defer_update` | Atomic begin/end retain the C-owned long counter and native ordering. Only an end whose decrement returns zero calls the existing bounds-transform adapter; begin reaching zero and negative counts remain quiet. Exact NULL diagnostics are preserved. Unchanged actual-library Tier 2 and per-operation C differential traces cover the swap. No intentional differences. |
| `libobs/obs-scene-item-id.c.h` | `obs-scene::item_id` | Scene item ID getter: exact signed 64-bit C parity, including zero and the original debug diagnostic for null. Leaves every item byte unchanged, with no intended behavior differences. Real-header prefix layout, differential ID/state and unchanged actual-library characterization coverage. |
| `libobs/obs-scene-item-scale-fields.c.h` | `obs-scene::item_scale_getter` | Synchronized vec2 scale getter preserves NULL output storage and exact stored float bits. Relative coordinates retain the existing C canvas conversion under the captured parent video mutex, with no Rust lock. Actual-library C characterization, real-header layout, callback-only differential/mutation and concurrent publication tests cover the seam. No intended differences. |
| `libobs/obs-scene-item-scale-filter-setter.c.h` | `obs-scene::item_scale_filter` | Swapped in hybrid `libobs`. Preserves NULL pointer diagnostics, every stored enum bit and sequentially consistent atomic transform invalidation, including repeated filters. Reuses the render-prefix real-header layout test; complete-item differential parity covers enum edges, random values and NULL. Existing `test_scene_rotated_scale_filter` remains unchanged. No intended differences. |
Expand Down
1 change: 1 addition & 0 deletions rust/obs-c-oracle/oracle.d/sceneitem-defer-update.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sceneitem-defer-update.inc|libobs/obs-sceneitem-defer-update.c.h|auto
49 changes: 49 additions & 0 deletions rust/obs-c-oracle/oracle/scene_item_bounds_setters.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,52 @@ unsigned oracle_scene_bounds_alignment_probe(alignment_setter original, alignmen
abort();
return result;
}

/* Deferral calls the same transform adapter. Reuse its recorder so the
* amalgamated category has one definition and one native fixture layout.
* Every operation compares the whole item and callback trace, while the
* caller owns a nonrecursive mutex (begin/end must not acquire it). */
typedef void (*defer_operation)(obs_sceneitem_t *);
unsigned oracle_scene_bounds_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count,
defer_operation c_begin, defer_operation c_end, defer_operation begin,
defer_operation end);

unsigned oracle_scene_bounds_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count,
defer_operation c_begin, defer_operation c_end, defer_operation begin,
defer_operation end)
{
struct obs_scene scene = {0};
if (pthread_mutex_init(&scene.video_mutex, NULL))
abort();
scene.is_group = (flags & 2) != 0;
struct obs_scene *parent = (flags & 1) ? &scene : NULL;
struct bounds_item expected, actual;
bounds_item_init(&expected, parent, 0);
expected.item.align = 37;
os_atomic_store_long(&expected.item.defer_update, initial);
os_atomic_store_bool(&expected.item.update_transform, (flags & 4) != 0);
memcpy(&actual, &expected, sizeof(actual));
pthread_mutex_lock(&scene.video_mutex);
unsigned result = 0;
for (size_t i = 0; i < count; i++) {
expected.count = actual.count = 0;
memset(expected.events, 0, sizeof(expected.events));
memset(actual.events, 0, sizeof(actual.events));
if (ops[i]) {
c_begin(&expected.item);
begin(&actual.item);
} else {
c_end(&expected.item);
end(&actual.item);
}
if (memcmp(&expected.item, &actual.item, sizeof(expected.item)) || expected.count != actual.count ||
memcmp(expected.events, actual.events, sizeof(expected.events))) {
result = (unsigned)i + 1;
break;
}
}
pthread_mutex_unlock(&scene.video_mutex);
if (pthread_mutex_destroy(&scene.video_mutex))
abort();
return result;
}
13 changes: 1 addition & 12 deletions rust/obs-c-oracle/oracle/scene_transform_states_links.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* Test-only link stand-ins: obs_get_source_by_uuid(),
* obs_sceneitem_set_info2(),
* obs_sceneitem_defer_update_begin() and obs_sceneitem_defer_update_end()
* obs_sceneitem_set_info2()
* under libobs's own names, for the test
* binaries that link the obs-scene shims without libobs.
* obs_sceneitem_get_info2() is the obs-scene shim itself now
Expand Down Expand Up @@ -30,13 +29,3 @@ void obs_sceneitem_set_info2(obs_sceneitem_t *item, const struct obs_transform_i
UNUSED_PARAMETER(item);
UNUSED_PARAMETER(info);
}

void obs_sceneitem_defer_update_begin(obs_sceneitem_t *item)
{
UNUSED_PARAMETER(item);
}

void obs_sceneitem_defer_update_end(obs_sceneitem_t *item)
{
UNUSED_PARAMETER(item);
}
66 changes: 66 additions & 0 deletions rust/obs-c-oracle/oracle/sceneitem_defer_update.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Original extracted C and the real production atomic adapters. The bounds
* oracle owns the shared transform recorder and its complete native items. */
#define obs_sceneitem_defer_update_begin oracle_obs_sceneitem_defer_update_begin
#define obs_sceneitem_defer_update_end oracle_obs_sceneitem_defer_update_end
#include "libobs/build/libobs.pch.h"
#include "sceneitem-defer-update.inc"
#undef obs_sceneitem_defer_update_begin
#undef obs_sceneitem_defer_update_end
#include "sceneitem_defer_update_fields.inc"

typedef void (*defer_operation)(obs_sceneitem_t *);
unsigned oracle_scene_bounds_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count,
defer_operation c_begin, defer_operation c_end, defer_operation begin,
defer_operation end);
unsigned oracle_sceneitem_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count,
defer_operation begin, defer_operation end);
unsigned oracle_sceneitem_defer_null(defer_operation begin, defer_operation end);

unsigned oracle_sceneitem_defer_probe(long initial, unsigned flags, const unsigned char *ops, size_t count,
defer_operation begin, defer_operation end)
{
return oracle_scene_bounds_defer_probe(initial, flags, ops, count, oracle_obs_sceneitem_defer_update_begin,
oracle_obs_sceneitem_defer_update_end, begin, end);
}

struct defer_log {
unsigned count;
int level;
char text[128];
};
#if defined(__GNUC__) || defined(__clang__)
static void defer_capture(int level, const char *format, va_list args, void *param)
__attribute__((format(printf, 2, 0)));
#endif
static void defer_capture(int level, const char *format, va_list args, void *param)
{
struct defer_log *log = param;
log->count++;
log->level = level;
vsnprintf(log->text, sizeof(log->text), format, args);
}

unsigned oracle_sceneitem_defer_null(defer_operation begin, defer_operation end)
{
log_handler_t previous;
void *param;
base_get_log_handler(&previous, &param);
defer_operation c[] = {oracle_obs_sceneitem_defer_update_begin, oracle_obs_sceneitem_defer_update_end};
defer_operation rust[] = {begin, end};
const char *messages[] = {"obs_sceneitem_defer_update_begin: Null 'item' parameter",
"obs_sceneitem_defer_update_end: Null 'item' parameter"};
unsigned result = 0;
for (unsigned i = 0; i < 2; i++) {
struct defer_log expected = {0}, actual = {0};
base_set_log_handler(defer_capture, &expected);
c[i](NULL);
base_set_log_handler(defer_capture, &actual);
rust[i](NULL);
if (expected.count != 1 || expected.level != LOG_DEBUG || strcmp(expected.text, messages[i]) ||
actual.count != expected.count || actual.level != expected.level ||
strcmp(actual.text, expected.text))
result |= 1u << i;
}
base_set_log_handler(previous, param);
return result;
}
62 changes: 62 additions & 0 deletions rust/obs-scene/src/ffi/item_defer_update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! Opaque scene items: C retains the layout, atomic width and ordering.
use super::item_bounds_getters::SceneItemPrefix;
use crate::item_defer_update::{self, TransformDeferral};
use core::ffi::{CStr, c_char, c_int, c_long, c_void};
use core::ptr::NonNull;

unsafe extern "C" {
fn obs_sceneitem_defer_update_increment(item: *mut c_void) -> c_long;
fn obs_sceneitem_defer_update_decrement(item: *mut c_void) -> c_long;
fn obs_sceneitem_bounds_update_transform(item: *mut SceneItemPrefix);
fn blog(level: c_int, format: *const c_char, ...);
}

struct Item(NonNull<c_void>);
impl TransformDeferral for Item {
fn increment(&self) {
// SAFETY: validated live item; C performs the original atomic RMW.
unsafe { obs_sceneitem_defer_update_increment(self.0.as_ptr()) };
}
fn decrement(&self) -> isize {
// SAFETY: same live item. C long fits isize on all supported targets.
unsafe { obs_sceneitem_defer_update_decrement(self.0.as_ptr()) as isize }
}
fn update_transform(&self) {
// SAFETY: same live item; reuse the existing scene dispatch adapter.
unsafe { obs_sceneitem_bounds_update_transform(self.0.as_ptr().cast()) };
}
}

fn validated(item: *mut c_void, function: &CStr) -> Option<Item> {
let item = NonNull::new(item);
if item.is_none() {
// SAFETY: static NUL-terminated format and string arguments.
unsafe {
blog(
400,
c"%s: Null '%s' parameter".as_ptr(),
function.as_ptr(),
c"item".as_ptr(),
);
}
}
item.map(Item)
}

/// # Safety
/// A non-null item must remain live for the call, as in the original C API.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn obs_sceneitem_defer_update_begin(item: *mut c_void) {
if let Some(item) = validated(item, c"obs_sceneitem_defer_update_begin") {
item_defer_update::begin(&item);
}
}

/// # Safety
/// A non-null item must remain live for the call, as in the original C API.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn obs_sceneitem_defer_update_end(item: *mut c_void) {
if let Some(item) = validated(item, c"obs_sceneitem_defer_update_end") {
item_defer_update::end(&item);
}
}
1 change: 1 addition & 0 deletions rust/obs-scene/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod group_enum;
pub mod group_queries;
pub mod group_resize_defer;
pub mod item_audio_actions;
pub mod item_defer_update;
pub mod item_id;
pub mod item_parent_getter;
pub mod item_private_settings;
Expand Down
20 changes: 20 additions & 0 deletions rust/obs-scene/src/item_defer_update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Transform deferral over a C-owned atomic counter. The transform adapter
//! retains ordinary, group-child and parentless dispatch behavior.

/// Native operations on a live item, without borrowing its private layout.
pub trait TransformDeferral {
fn increment(&self);
/// Return this atomic decrement's result, never a later load.
fn decrement(&self) -> isize;
fn update_transform(&self);
}

pub fn begin(item: &impl TransformDeferral) {
item.increment();
}

pub fn end(item: &impl TransformDeferral) {
if item.decrement() == 0 {
item.update_transform();
}
}
1 change: 1 addition & 0 deletions rust/obs-scene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub mod group_queries;
pub mod group_resize_defer;
pub mod group_transform;
pub mod item_audio_actions;
pub mod item_defer_update;
pub mod item_id;
pub mod item_names;
pub mod item_order;
Expand Down
Loading
Loading