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
1 change: 0 additions & 1 deletion libobs/build/libobs.core-source+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "libobs/obs-scene-item-blending-method-fields.c.h"
#include "libobs/obs-scene-item-blending-mode-fields.c.h"
#include "libobs/obs-scene-item-bounds-setters-fields.c.h"
#include "libobs/obs-scene-item-get-group.c.h"
#include "libobs/obs-scene-item-group-scene-fields.c.h"
#include "libobs/obs-scene-item-hotkey-bridge.c.h"
#include "libobs/obs-scene-item-hotkeys-fields.c.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-scene-item-get-group+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): original parent-group query for the C reference. */

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

#include "libobs/obs-scene-item-get-group.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/scene-item-get-group.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-scene-item-get-group+.h.c"
]
}
1 change: 1 addition & 0 deletions libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_sceneitem_get_group
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-scene-ref.c.h` | `obs-scene::refs` | Scene ownership delegates to the existing source API without a separate counter. Preserves NULL no-ops, argument scene identity on successful promotion, one source retain/release and expiry. Tier 1 mirrors unchanged `test_scene_ref`; Tier 3 uses original scene/source C bodies and real private layouts. No intentional differences. |
| `libobs/obs-scene-render-plan.c.h` | `obs-scene::render_plan` | Swapped in hybrid `libobs` (group `libobs.ported-scene-render-plan`). The per-item render decisions of `render_item()` and `render_item_texture()`, one hidden function each, called where the C made the decision with the values it read there: whether the item is drawn through its texrender (`obs_scene_render_texture_enabled`: a crop or bounds crop, a scale filter, sRGB off, a blend mode other than Normal, or a nested scene that is not a group); keep, destroy, create or recreate the texrender; the empty-source gate of #573 (a running show/hide transition is still rendered, at size 0); the clear colour (#1406: white for Darken); the child drawn (show transition, hide transition or source); the linear sRGB state; whether a directly drawn source gets centred texture coordinates (`obs_scene_texcoords_centered`, the C's `memcmp` against the identity with floored x and y translation, so the Rust compares every entry's bits); the effect (Point's sampler, the base dimension, the low-resolution bilinear effect below 0.5, Bicubic, Lanczos, Area and its upscale, with `fabsf(scale - 1) <= EPSILON` in `f32`); the SDR white multiplier; and the technique. `obs-scene.c.h` keeps every `gs_*` call in its order, `obs_source_video_render()`, the texrender objects, `obs_get_video_sdr_white_level()` (passed as a value; now read for every space pair, a plain getter), the blend table (#1521) and `calc_cx`/`calc_cy` (#1947), and maps the effect and technique values to `obs->video.*` and the technique names; `gs_texrender_get_format()` is still asked only with a texrender that is wanted, and each transition only when the item's visibility selects it. `struct obs_scene_render_triggers` and `struct obs_scene_render_effect_plan` are mirrored; the triggers and `&item->draw_transform` (obs-graphics' `matrix4`) are read through pointers. The enum values cross as `int`; `obs-scene.c.h` checks the mirrored constants and the enum sizes at compile time. Kept, characterized, not endorsed: a white level of 0 gives `80.f / 0`, +inf; a NaN output scale is never close to 1 nor below 0.5, so the filter's own effect is used and Area does not upscale; a quiet NaN or infinite translation counts as centred, and a -0.0 anywhere but the translation does not. `test_scene_render_plan_steps` compiles the C into itself, and `test_scene_render_plan_steps_rust` runs the same test source against `libobs_rust-static`; `test_item_transition_empty_source`, `test_darken_transparent`, `test_scene_rotated_scale_filter`, `test_scene_blend`, `test_visibility_transition` and `test_group_hide_transition_audio` see the swap through the hybrid. Tier 3 compares every output field by field, bit for bit, exhaustively over the enums and flags and with proptests over bit-pattern floats and matrices. No intentional differences. |
| `libobs/obs-scene-item-alignment-setter.c.h` | `obs-scene::item_alignment_setter` | Swapped in hybrid `libobs`. Safe Rust stores every alignment bit between the existing C-owned captured-parent fields lock/unlock, then unconditionally calls the C-owned bounds transform update. NULL is silent; unchanged values still update. Tier 1 mirrors the characterization, unchanged Tier 2 covers live dispatch and callbacks, and Tier 3 compares original C whole-item bytes, alignment at update, call counts and mutex state for arbitrary bits and defer counts. No intentional differences; no network protocol (Tier 4 inapplicable). |
| `libobs/obs-scene-item-get-group.c.h` | `obs-scene::item_get_group` | Swapped in hybrid `libobs`. Safe Rust rejects a NULL scene or item before any read, and a group item (read through the existing `obs_sceneitem_group_scene_flag` adapter) before any lock, then takes the C-owned full lock once around the C-owned walk (`obs_sceneitem_parent_group_lookup`, shared with the reorder callers) and returns its result as a borrowed pointer, with no reference taken. Kept, characterized, not endorsed (the walk's behaviour): the removed flag is not consulted and a NULL parent matches a NULL group context. Tier 1 mirrors every assertion of the unchanged `test_sceneitem_get_group`; Tier 2 runs it against both libobs builds; Tier 3 compares the original C wrapper on the same fixture (result pointer, lock/walk trace, every scene and item byte) with mutants for a missing unlock, an unlocked walk, locking a group item, a second flag read and a dropped result. No intentional differences; no network protocol (Tier 4 inapplicable). |
| `libobs/obs-scene-item-audio-actions.c.h` | `obs-scene::item_audio_actions` | Swapped in hybrid `libobs` (group `libobs.ported-scene-item-audio-actions`). The scene item's side of the visibility audio ramp: `apply_scene_item_audio_actions()`, `apply_scene_item_volume()` and `process_all_audio_actions()`, declared in `obs-internal.h` without `EXPORT`, so the shims stay hidden. The safe core works on an `ItemAudio` trait; the shim reaches the item only through the live adapter `obs-scene-item-audio-actions-fields.c.h` (the `actions_mutex` lock and unlock, the queue's address, the atomic `visible` load and store, the atomic `active_refs` decrement, and the two sources of the removal), so `struct obs_scene_item` is not mirrored, and applies the queue with the `audio_actions` shim in place. It keeps the C's order: the visibility copied, passed to the core and written back under the lock; the reference drops and `obs_source_remove_active_child()` after the unlock; the first action copied under the lock and its window checked after it. Kept, characterized, not endorsed: every hide drops a reference, without bound, and the child is removed only on a drop to 0; the window looks at the first action only. Tier 3 runs the original C over the original C core and the same adapter, with every lock, atomic and removal recorded in one trace, and compares the trace, the item, every byte the queue held, the gains and the return value. Intentional difference, where C has undefined behaviour and libobs never gets there: a null item does nothing. The core's own differences (a rate of 0 for the window, `ts` 0 with a buffer) are the only inputs Tier 3 leaves out. `test_scene_audio_action_steps` compiles the C item side into itself and stays the C characterization; the real-libobs `test_scene_audio_actions` covers the swap. |
| `libobs/obs-scene-item-blending-mode.c.h` | `obs-scene::item_blending_mode` | Swapped in hybrid `libobs`; preserves arbitrary blend enum bits, null diagnostics and atomic transform invalidation through private C adapters. Complete real-item byte parity and enum storage layout checks cover the boundary. No intentional differences. |
| `libobs/obs-scene-item-blending-method.c.h` | `obs-scene::item_blending_method` | Stores nonnegative enum values verbatim, preserving NULL diagnostics and every surrounding item byte, including transform dirtiness. Private C field access follows Rust NULL validation; callback-only exact differential parity covers repeated writes. No intentional differences. |
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 @@ -29,6 +29,8 @@ mod canonical_qt_core_filename_is_registered;
mod canonical_rust_static_windows_keys_are_registered;
#[path = "native/registration/canonical_scene_item_alignment_setter_swap_is_registered.rs"]
mod canonical_scene_item_alignment_setter_swap_is_registered;
#[path = "native/registration/canonical_scene_item_get_group_swap_is_registered.rs"]
mod canonical_scene_item_get_group_swap_is_registered;
#[path = "native/registration/canonical_source_canvas_getter_swap_is_registered.rs"]
mod canonical_source_canvas_getter_swap_is_registered;
#[path = "native/registration/canonical_source_configurable_swap_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use super::*;

#[test]
fn canonical_scene_item_get_group_swap_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 name = "test_sceneitem_get_group";
graph.targets.retain(|key, _| key == name);
graph.tests.retain(|key, _| key == name);
for os in ["OS_LINUX", "OS_MACOS", "OS_WINDOWS"] {
let selected = graph.select(&[(os.into(), true)].into()).unwrap();
assert!(
matches!(selected.targets[name].sources.as_slice(), [Source::Path(path)]
if path == "test/cmocka/test_sceneitem_get_group.c")
);
assert_eq!(selected.tests[name].target, name);
}
let ported =
fs::read_to_string(root.join("libobs/build/ported-source-sets/scene-item-get-group.json"))
.unwrap();
assert!(ported.contains("build/libobs.ported-scene-item-get-group+.h.c"));
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-scene-item-get-group+.h.c"))
.unwrap();
assert!(group.contains("#include \"libobs/obs-scene-item-get-group.c.h\""));
let hybrid = fs::read_to_string(root.join("libobs/build/libobs.core-source+.h.c")).unwrap();
assert!(!hybrid.contains("#include \"libobs/obs-scene-item-get-group.c.h\""));
// The C-owned seams stay in the production group: the full lock and the
// shared parent-group walk in obs-scene.c.h, the group-flag adapter beside it.
assert!(hybrid.contains("#include \"libobs/obs-scene.c.h\""));
assert!(hybrid.contains("#include \"libobs/obs-scene-item-group-scene-fields.c.h\""));
let exports =
fs::read_to_string(root.join("libobs/cmake/rust-exports.d/obs-scene-item_get_group.txt"))
.unwrap();
assert_eq!(exports.trim(), "obs_sceneitem_get_group");
}
1 change: 1 addition & 0 deletions rust/obs-c-oracle/oracle.d/scene-item-get-group.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scene-item-get-group.inc|libobs/obs-scene-item-get-group.c.h|auto
9 changes: 7 additions & 2 deletions rust/obs-c-oracle/oracle/scene_atomic_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ void oracle_atomic_source_release(obs_source_t *source)
struct atomic_fixture *f = source->context.data;
atomic_release(&f->scene);
}
/* The one real-named full-lock stand-in: a parent-group probe active on this
* thread (scene_item_get_group.c) owns the call, otherwise this recorder. */
bool oracle_scene_get_group_full_lock(obs_scene_t *scene, bool lock);
void obs_scene_atomic_full_lock(obs_scene_t *scene);
void obs_scene_atomic_full_unlock(obs_scene_t *scene);
void obs_scene_atomic_full_lock(obs_scene_t *scene)
{
oracle_atomic_full_lock(scene);
if (!oracle_scene_get_group_full_lock(scene, true))
oracle_atomic_full_lock(scene);
}
void obs_scene_atomic_full_unlock(obs_scene_t *scene)
{
oracle_atomic_full_unlock(scene);
if (!oracle_scene_get_group_full_lock(scene, false))
oracle_atomic_full_unlock(scene);
}

static void atomic_callback(void *data, obs_scene_t *scene)
Expand Down
177 changes: 177 additions & 0 deletions rust/obs-c-oracle/oracle/scene_item_get_group.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/* Original extracted parent-group wrapper over one recorded lock/walk boundary.
* The Rust shim reaches the same boundary through the real seam names: the
* shared full-lock definition in scene_atomic_update.c dispatches here while a
* probe is active on this thread, and the real group-flag adapter reads the
* fixture item (scene_item_group_scene.c). */
#include "libobs/build/libobs.pch.h"

void oracle_get_group_lock(obs_scene_t *scene);
void oracle_get_group_unlock(obs_scene_t *scene);
obs_sceneitem_t *oracle_obs_sceneitem_get_group(obs_scene_t *scene, obs_sceneitem_t *group_subitem);
#define obs_sceneitem_get_group oracle_obs_sceneitem_get_group
#define obs_scene_atomic_full_lock oracle_get_group_lock
#define obs_scene_atomic_full_unlock oracle_get_group_unlock
#include "scene-item-get-group.inc"
#undef obs_scene_atomic_full_unlock
#undef obs_scene_atomic_full_lock
#undef obs_sceneitem_get_group

enum { GET_GROUP_EVENTS = 8, GET_GROUP_ITEMS = 4 };
enum { EV_LOCK = 1, EV_LOOKUP = 2, EV_UNLOCK = 3, EV_FOREIGN = 0x100, EV_UNLOCKED_LOOKUP = 0x200 };

struct get_group_fixture {
struct obs_scene scene;
struct obs_scene_item item;
struct obs_scene_item groups[GET_GROUP_ITEMS];
struct obs_scene_item foreign;
obs_sceneitem_t *result;
bool clobber;
unsigned depth;
unsigned count;
unsigned events[GET_GROUP_EVENTS];
};

static _Thread_local struct get_group_fixture *get_group_active;

static void get_group_record(struct get_group_fixture *f, unsigned event)
{
if (f->count < GET_GROUP_EVENTS)
f->events[f->count] = event;
f->count++;
}

/* Called by the shared real-named full-lock stand-ins; false when no probe of
* this thread owns the call, so the atomic-update recorder handles it. */
bool oracle_scene_get_group_full_lock(obs_scene_t *scene, bool lock);
bool oracle_scene_get_group_full_lock(obs_scene_t *scene, bool lock)
{
struct get_group_fixture *f = get_group_active;
if (!f)
return false;
unsigned event = lock ? EV_LOCK : EV_UNLOCK;
if (scene != &f->scene)
event |= EV_FOREIGN;
if (lock)
f->depth++;
else if (f->depth)
f->depth--;
else
event |= EV_UNLOCKED_LOOKUP;
get_group_record(f, event);
return true;
}

void oracle_get_group_lock(obs_scene_t *scene)
{
if (!oracle_scene_get_group_full_lock(scene, true))
abort();
}

void oracle_get_group_unlock(obs_scene_t *scene)
{
if (!oracle_scene_get_group_full_lock(scene, false))
abort();
}

/* The C-owned walk stays in obs-scene.c.h; both sides reach this stand-in by
* its real name and get the fixture's chosen, borrowed result. */
obs_sceneitem_t *obs_sceneitem_parent_group_lookup(obs_scene_t *scene, obs_sceneitem_t *group_subitem)
{
struct get_group_fixture *f = get_group_active;
if (!f)
abort();
unsigned event = EV_LOOKUP | (f->depth << 4);
if (scene != &f->scene || group_subitem != &f->item)
event |= EV_FOREIGN;
if (f->depth != 1)
event |= EV_UNLOCKED_LOOKUP;
get_group_record(f, event);
/* A later read of the group flag would now reject; C reads it once. */
if (f->clobber)
f->item.is_group = true;
return f->result;
}

static void get_group_init(struct get_group_fixture *f, unsigned bits)
{
memset(f, 0, sizeof(*f));
f->item.ref = 11;
f->item.is_group = (bits & 4) != 0;
f->item.parent = (bits & 0x100) ? NULL : &f->scene;
f->scene.first_item = &f->groups[0];
for (size_t i = 0; i < GET_GROUP_ITEMS; i++) {
f->groups[i].ref = 17 + (long)i;
f->groups[i].is_group = (bits >> (9 + i)) & 1;
f->groups[i].removed = (bits & 8) != 0;
f->groups[i].parent = &f->scene;
f->groups[i].next = i + 1 < GET_GROUP_ITEMS ? &f->groups[i + 1] : NULL;
}
f->foreign.ref = 23;
f->foreign.is_group = true;
f->clobber = (bits & 0x10) != 0;
unsigned choice = (bits >> 5) & 7;
f->result = choice >= 1 && choice <= GET_GROUP_ITEMS ? &f->groups[choice - 1]
: choice == 5 ? &f->foreign
: choice == 6 ? &f->item
: NULL;
}

typedef obs_sceneitem_t *(*get_group_fn)(obs_scene_t *, obs_sceneitem_t *);

struct get_group_run {
obs_sceneitem_t *result;
unsigned count;
unsigned events[GET_GROUP_EVENTS];
unsigned char objects[offsetof(struct get_group_fixture, result)];
};

static void get_group_run(struct get_group_fixture *f, unsigned bits, get_group_fn getter, struct get_group_run *out)
{
get_group_init(f, bits);
get_group_active = f;
out->result = getter((bits & 1) ? NULL : &f->scene, (bits & 2) ? NULL : &f->item);
get_group_active = NULL;
/* Undo the walk's clobber so the bytes show only what the wrapper wrote. */
f->item.is_group = (bits & 4) != 0;
out->count = f->count;
memcpy(out->events, f->events, sizeof(out->events));
memcpy(out->objects, f, sizeof(out->objects));
}

/* bits: 0 NULL scene, 1 NULL item, 2 group item, 3 removed groups, 4 clobber
* the flag during the walk, 5-7 walk result, 8 NULL item parent, 9-12 group
* flags of the scene's items. Both sides run on the same fixture address, so
* results compare as pointers. Returns 0 when the shim matches the original:
* 1 result identity, 2 trace, 4 any scene/item byte changed (refs included),
* 8 the original's own trace is not empty or exactly lock, lookup, unlock. */
unsigned oracle_scene_item_get_group_probe(unsigned bits, get_group_fn rust);
unsigned oracle_scene_item_get_group_probe(unsigned bits, get_group_fn rust)
{
static _Thread_local struct get_group_fixture fixture;
struct get_group_run expected, actual;
unsigned char before[sizeof(expected.objects)];
get_group_init(&fixture, bits);
memcpy(before, &fixture, sizeof(before));
get_group_run(&fixture, bits, oracle_obs_sceneitem_get_group, &expected);
get_group_run(&fixture, bits, rust, &actual);
unsigned result = 0;
if (expected.result != actual.result)
result |= 1;
if (expected.count != actual.count || memcmp(expected.events, actual.events, sizeof(expected.events)))
result |= 2;
if (memcmp(before, expected.objects, sizeof(before)) || memcmp(before, actual.objects, sizeof(before)))
result |= 4;
bool rejected = (bits & 7) != 0;
if (rejected ? expected.count != 0
: expected.count != 3 || expected.events[0] != EV_LOCK ||
expected.events[1] != (EV_LOOKUP | 0x10) || expected.events[2] != EV_UNLOCK)
result |= 8;
return result;
}

/* Real header layout of the field the shim reads through its adapter. */
size_t oracle_scene_item_get_group_layout(void);
size_t oracle_scene_item_get_group_layout(void)
{
return sizeof(((struct obs_scene_item *)0)->is_group);
}
Loading
Loading