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: 1 addition & 0 deletions libobs/build/libobs.core-source+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "libobs/obs-sceneitem-addref-fields.c.h"
#include "libobs/obs-sceneitem-defer-update-fields.c.h"
#include "libobs/obs-shader-param-introspection-fields.c.h"
#include "libobs/obs-source-activate-fields.c.h"
#include "libobs/obs-source-active-child-fields.c.h"
#include "libobs/obs-source-async-compensation-fields.c.h"
#include "libobs/obs-source-async-decoupled-fields.c.h"
Expand Down
4 changes: 4 additions & 0 deletions libobs/build/libobs.ported-source-activate+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Unity group (BUILD.md): original source activate and deactivate for C reference. */
#include "libobs/build/libobs.pch.h"

#include "libobs/obs-source-activate.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/source-activate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-source-activate+.h.c"
]
}
5 changes: 5 additions & 0 deletions libobs/cmake/rust-hidden.d/obs-source-source_activate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# obs-source-activate.c.h (#5811): views, canvases, active children and the
# four public show and active counters call them inside libobs. Declared in
# obs-internal.h without EXPORT, so the shims stay hidden.
obs_source_activate
obs_source_deactivate
42 changes: 42 additions & 0 deletions libobs/obs-source-activate-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "libobs/build/libobs.pch.h"

/* What obs_source_activate() and obs_source_deactivate() and their tree
* callbacks change (the obs-source shim): a live source's show_refs and
* activate_refs, each step one atomic increment, decrement or load, as the
* original did it. The caller rejects a NULL source; the tree walk
* (obs_source_enum_active_tree()) passes the children. */
void obs_source_activate_inc_show_refs(obs_source_t *source);
void obs_source_activate_inc_show_refs(obs_source_t *source)
{
os_atomic_inc_long(&source->show_refs);
}

void obs_source_activate_dec_show_refs(obs_source_t *source);
void obs_source_activate_dec_show_refs(obs_source_t *source)
{
os_atomic_dec_long(&source->show_refs);
}

long obs_source_activate_load_show_refs(const obs_source_t *source);
long obs_source_activate_load_show_refs(const obs_source_t *source)
{
return os_atomic_load_long(&source->show_refs);
}

void obs_source_activate_inc_activate_refs(obs_source_t *source);
void obs_source_activate_inc_activate_refs(obs_source_t *source)
{
os_atomic_inc_long(&source->activate_refs);
}

void obs_source_activate_dec_activate_refs(obs_source_t *source);
void obs_source_activate_dec_activate_refs(obs_source_t *source)
{
os_atomic_dec_long(&source->activate_refs);
}

long obs_source_activate_load_activate_refs(const obs_source_t *source);
long obs_source_activate_load_activate_refs(const obs_source_t *source)
{
return os_atomic_load_long(&source->activate_refs);
}
65 changes: 65 additions & 0 deletions libobs/obs-source-activate.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "libobs/build/libobs.pch.h"

static void activate_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_inc_long(&child->activate_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

static void deactivate_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_dec_long(&child->activate_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

static void show_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_inc_long(&child->show_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

static void hide_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_dec_long(&child->show_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

void obs_source_activate(obs_source_t *source, enum view_type type)
{
if (!obs_source_valid(source, "obs_source_activate"))
return;

os_atomic_inc_long(&source->show_refs);
obs_source_enum_active_tree(source, show_tree, NULL);

if (type == MAIN_VIEW) {
os_atomic_inc_long(&source->activate_refs);
obs_source_enum_active_tree(source, activate_tree, NULL);
}
}

void obs_source_deactivate(obs_source_t *source, enum view_type type)
{
if (!obs_source_valid(source, "obs_source_deactivate"))
return;

if (os_atomic_load_long(&source->show_refs) > 0) {
os_atomic_dec_long(&source->show_refs);
obs_source_enum_active_tree(source, hide_tree, NULL);
}

if (type == MAIN_VIEW) {
if (os_atomic_load_long(&source->activate_refs) > 0) {
os_atomic_dec_long(&source->activate_refs);
obs_source_enum_active_tree(source, deactivate_tree, NULL);
}
}
}
64 changes: 0 additions & 64 deletions libobs/obs-source.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,70 +634,6 @@ static void hide_source(obs_source_t *source)
obs_source_dosignal(source, "source_hide", "hide");
}

static void activate_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_inc_long(&child->activate_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

static void deactivate_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_dec_long(&child->activate_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

static void show_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_inc_long(&child->show_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

static void hide_tree(obs_source_t *parent, obs_source_t *child, void *param)
{
os_atomic_dec_long(&child->show_refs);

UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(param);
}

void obs_source_activate(obs_source_t *source, enum view_type type)
{
if (!obs_source_valid(source, "obs_source_activate"))
return;

os_atomic_inc_long(&source->show_refs);
obs_source_enum_active_tree(source, show_tree, NULL);

if (type == MAIN_VIEW) {
os_atomic_inc_long(&source->activate_refs);
obs_source_enum_active_tree(source, activate_tree, NULL);
}
}

void obs_source_deactivate(obs_source_t *source, enum view_type type)
{
if (!obs_source_valid(source, "obs_source_deactivate"))
return;

if (os_atomic_load_long(&source->show_refs) > 0) {
os_atomic_dec_long(&source->show_refs);
obs_source_enum_active_tree(source, hide_tree, NULL);
}

if (type == MAIN_VIEW) {
if (os_atomic_load_long(&source->activate_refs) > 0) {
os_atomic_dec_long(&source->activate_refs);
obs_source_enum_active_tree(source, deactivate_tree, NULL);
}
}
}

static inline struct obs_source_frame *get_closest_frame(obs_source_t *source, uint64_t sys_time);

static void filter_frame(obs_source_t *source, struct obs_source_frame **ref_frame)
Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-scene-transform-update.c.h` | `obs-scene::transform_update` | Swapped in hybrid `libobs` (group `libobs.ported-scene-transform-update`). The transform update decisions of `scene_video_render()` and `update_transforms_and_prune_sources()`, two hidden functions on plain values: `obs_scene_transform_update_scene_size` (`scene_size_changed()`: whether the scene has a new size since its last render; the stored size changes only on a change) and `obs_scene_transform_update_item` (whether an item's transform is computed again on this walk: its `update_transform` flag, a source size that is not the one of its last transform, each dimension compared, or a new scene size). `obs-scene.c.h` keeps the video locks, the item list walk, the recursion into a group's scene, the removed-source check and the removal, the group rebuild flag, `update_item_transform()` (the defer check, the size read, the lock, the signal), `resize_group()` and every size read; it reads the source size only when the flag is clear, as the original `||` stopped at the flag, so a source's `get_width`/`get_height` run as often as before. The scene's stored size crosses as two `uint32_t` pointers (written only on a change), the rest by value; no struct is mirrored. Kept, characterized, not endorsed: a flag set while an item is deferred survives `obs_sceneitem_defer_update_end()`, which computes the transform without clearing it, so the next walk computes it once more. `test_scene_transform_update_steps` compiles the C into itself and `test_scene_transform_update_steps_rust` runs the same test source against `libobs_rust-static`; `test_scene_transform_update_walk` runs the walk through the real libobs with `obs_scene_prune_sources()` (the `item_transform` signals in order and the `get_width`/`get_height` calls: a new item, idle, flagged, resized, deferred and removed items, and a group's child update, resize flag, removed child, deferred child and removed group), and `test_scene_group_transform`, `test_group_child_drift`, `test_group_extent`, `test_group_recursion` and `test_group_teardown_uaf` see the swap through the hybrid. Tier 3 compares the results and the stored size exhaustively over the flags and every pair of edge sizes, with proptests over the `u32` ranges, and runs a walk model of `update_transforms_and_prune_sources()` with the shims against the oracle over random scenes and renders. No intentional differences. |
| `libobs/obs-sceneitem-addref.c.h` | `obs-scene::item_addref` | Swapped in hybrid `libobs` (group `libobs.ported-sceneitem-addref`). Safe Rust makes NULL a silent no-op and otherwise calls the private adapter `obs-sceneitem-addref-fields.c.h` once, which does the original `os_atomic_inc_long(&item->ref)`, so C keeps the counter's layout, its platform `long` width (32-bit on Windows) and the atomic ordering; no item layout is mirrored. `obs_sceneitem_release` is unchanged. Kept, characterized, not endorsed: zero and negative counts also increment, and the native limit wraps. Tier 1 mirrors both cases of the unchanged `test_sceneitem_addref`; Tier 2 runs it against both libobs builds; Tier 3 compares the original C on a real-header item with the shim on a byte copy over fill patterns, native long edges and a proptest, and checks the counter's width in the real header, a silent NULL, and concurrent calls adding exactly one each. No intentional differences; no network protocol (Tier 4 inapplicable). |
| `libobs/obs-sceneitem-private-settings.c.h` | `obs-scene::item_private_settings` | Swapped in hybrid `libobs` (group `libobs.ported-scene-item-private-settings`). Returns the item's stored `private_settings` unchanged, stored NULL included, after exactly one `obs_data_addref` per call; a NULL item logs the original `obs_ptr_valid` LOG_DEBUG diagnostic and returns NULL. The shim reads only that field, unlocked as in C, through a real-header-verified item prefix; no new private adapter. Unchanged actual-library C characterization (`test_sceneitem_private_settings`) covers Tier 2; Tier 3 compares identity, reference counts, every item byte and the NULL log with the unchanged extracted C. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-source-activate.c.h` | `obs-source::activate`, shims in `obs-source::ffi::source_activate` | #5811: swapped in hybrid `libobs` (group `libobs.ported-source-activate`). `obs_source_activate()` and `obs_source_deactivate()` (declared in `obs-internal.h` without `EXPORT`, so the shims are hidden through `rust-hidden.d`), which views, canvases, active children and the four public show and active counters call: a NULL source logs one `LOG_DEBUG` line naming the entry and nothing else happens. Activate: `show_refs` +1, then one `obs_source_enum_active_tree()` walk adding 1 to each child's `show_refs`; only for `MAIN_VIEW`, then `activate_refs` +1 and a second walk for the children's `activate_refs`. Deactivate: only when `show_refs` is above zero, -1 and a walk subtracting 1 from each child's (a child is not floor-checked); then for `MAIN_VIEW`, only when `activate_refs` is above zero, the same for `activate_refs`. The four tree callbacks (`show_tree`, `hide_tree`, `activate_tree`, `deactivate_tree`) are Rust. Safe core over a `Counters` trait; the atomic increments, decrements and loads stay C in `obs-source-activate-fields.c.h` (live group `libobs.core-source`, no `EXPORT`), and the walk is the C `obs_source_enum_active_tree()`. The new `test_source_activate` runs against hybrid and reference libraries through the four public counters on a nested active tree (the entries' own NULL check can't be reached from outside libobs, so Tier 1 and Tier 3 cover it). Tier 3 runs the original C and the Rust exports on noise-filled real-header sources with a scripted walk over every call, source (NULL too), view type, root counter edge and edge set plus a proptest, comparing each walk's root and every counter when it began, the counters after, the log lines and every other byte, and rejects eleven mutants. The tracing doubles of these two symbols in `obs-c-oracle/oracle/view.c` are gone: the view, show-counter and active-child tests reach the Rust exports, whose adapter stand-ins report the same trace for their test sources. | None. |
| `libobs/obs-source-active-child.c.h` | `obs-source::active_child`, shims in `obs-source::ffi::source_active_child` | #5622: swapped in hybrid `libobs` (group `libobs.ported-source-active-child`). `obs_source_add_active_child()` and `obs_source_remove_active_child()`, which scenes, groups and transitions call when a child gains or loses a showing parent. A NULL parent or child logs one `LOG_DEBUG` line naming the function and the parameter (parent first); add returns false. Add refuses `parent == child` with its `LOG_WARNING` line, then walks the child's full tree once with the parent as the walk's stop source and refuses, silently, when the parent is an edge's child or parent anywhere in it (`check_descendant()`). It then loads the parent's `show_refs` and `activate_refs` once each, in that order (#2081), and activates the child `show_refs` times, `MAIN_VIEW` for the first `activate_refs` and `AUX_VIEW` for the rest (none for a count at or below zero). Remove mirrors the loop with deactivations and has no self or cycle check. Safe core over a `Libobs` trait; the shims reach the C walk through `obs_source_active_child_enum_full_tree()` (the hidden wrapper `obs-source.c.h` gained in the extraction), the counter loads through `obs-source-active-child-fields.c.h` (live group `libobs.core-source`, no `EXPORT`), and call `obs_source_activate()` / `obs_source_deactivate()` directly. The unchanged `test_source_active_child` runs against hybrid and reference libraries through the real libobs. Tier 3 runs the original C and the Rust exports on noise-filled real-header sources over a scripted walk (every walk, activation and deactivation in order, the result, the log lines, every other byte; with and without counters changing under the loop), a grid, a proptest, and rejects ten mutants. The test-only `oracle/source_active_child_links.c` stand-ins are gone: the Rust exports define both names in the test binaries now. | None. |
| `libobs/obs-source-async-compensation-setter.c.h`, `libobs/obs-source-async-compensation-getter.c.h` | `obs-source::async_compensation` | Public compensation request setter and getter (#5595), swapped in hybrid libobs (group `libobs.ported-source-async-compensation`). Preserves atomic stores and loads, NULL debug diagnostics (the getter answers false) and all timing/frame state without taking a mutex; NULL is rejected before the field adapter. Real-header atomic layout, original C differential sequences (each stored request read back by both getters, nothing written), unchanged audio-input resampler coverage and the unchanged `test_source_async_flag_pair` on both builds. No intentional differences. |
| `libobs/obs-source-async-decoupled.c.h` | `obs-source::async_decoupled`, `obs-source-seam` | Unconditional flag store and enable-only locked timing invalidation plus the existing audio reset seam, including repeated enable. Unchanged actual-library characterization, safe Tier 1 mirrors and real-source Tier 3 state/order parity. No intentional differences; Tier 4 does not apply. |
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 @@ -35,6 +35,8 @@ mod canonical_scene_item_get_group_swap_is_registered;
mod canonical_scene_item_order_position_swap_is_registered;
#[path = "native/registration/canonical_scene_item_set_order_swap_is_registered.rs"]
mod canonical_scene_item_set_order_swap_is_registered;
#[path = "native/registration/canonical_source_activate_swap_is_registered.rs"]
mod canonical_source_activate_swap_is_registered;
#[path = "native/registration/canonical_source_active_child_swap_is_registered.rs"]
mod canonical_source_active_child_swap_is_registered;
#[path = "native/registration/canonical_source_async_flag_pair_swap_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use super::*;

#[test]
fn canonical_source_activate_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_source_activate";
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();
// The test compiles no copy of the C: it reaches the two hidden
// entries through the exported counters of the real libobs (Rust in
// hybrid, the original C in the reference).
assert!(
matches!(selected.targets[name].sources.as_slice(), [Source::Path(path)]
if path == "test/cmocka/test_source_activate.c")
);
assert!(selected.targets[name].definitions.is_empty());
assert_eq!(selected.tests[name].target, name);
}
let ported =
fs::read_to_string(root.join("libobs/build/ported-source-sets/source-activate.json"))
.unwrap();
assert!(ported.contains("build/libobs.ported-source-activate+.h.c"));
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-source-activate+.h.c")).unwrap();
assert!(group.contains("#include \"libobs/obs-source-activate.c.h\""));
let hybrid = fs::read_to_string(root.join("libobs/build/libobs.core-source+.h.c")).unwrap();
assert!(!hybrid.contains("#include \"libobs/obs-source-activate.c.h\""));
assert!(hybrid.contains("#include \"libobs/obs-source-activate-fields.c.h\""));
// Declared in obs-internal.h without EXPORT: hidden, never exported.
let hidden =
fs::read_to_string(root.join("libobs/cmake/rust-hidden.d/obs-source-source_activate.txt"))
.unwrap();
assert_eq!(
hidden
.lines()
.filter(|line| !line.starts_with('#'))
.collect::<Vec<_>>(),
["obs_source_activate", "obs_source_deactivate"]
);
assert!(
!root
.join("libobs/cmake/rust-exports.d/obs-source-source_activate.txt")
.exists()
);
}
1 change: 1 addition & 0 deletions rust/obs-c-oracle/oracle.d/source-activate.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-activate.inc|libobs/obs-source-activate.c.h|auto
15 changes: 4 additions & 11 deletions rust/obs-c-oracle/oracle/audio_callback_links.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* Test-only link stand-ins: obs_source_audio_render() and
* obs_source_enum_active_tree() under libobs's own names, for the test
* binaries that link the obs-core shims without libobs.
/* Test-only link stand-in: obs_source_audio_render() under libobs's own
* name, for the test binaries that link the obs-core shims without libobs.
*
* The audio tick's shim (rust/obs-core/src/ffi/audio_callback.rs) exports
* audio_callback(), whose libobs calls name them. The MSVC, MinGW and macOS
* audio_callback(), whose libobs calls name it. The MSVC, MinGW and macOS
* linkers want every symbol an object names resolved, used or not, so
* obs-tests-core needs a definition; libobs has the real ones.
* obs_source_active() is the real Rust export of obs-source (#5401), whose
* counter adapters oracle/source_showing_active.c compiles, and
* obs_source_removed() is its export too (#5587), whose flag adapter
* oracle/source_removed.c compiles.
* obs_source_enum_active_tree() is oracle/source_activate.c's (#5811).
* obs_source_get_ref() and obs_source_release() (oracle/view.c),
* obs_source_get_name() (the obs-missing-files tests),
* audio_output_get_sample_rate() and audio_output_get_channels()
Expand All @@ -29,10 +29,3 @@ void obs_source_audio_render(obs_source_t *source, uint32_t mixers, size_t chann
UNUSED_PARAMETER(sample_rate);
UNUSED_PARAMETER(size);
}

void obs_source_enum_active_tree(obs_source_t *source, obs_source_enum_proc_t enum_callback, void *param)
{
UNUSED_PARAMETER(source);
UNUSED_PARAMETER(enum_callback);
UNUSED_PARAMETER(param);
}
Loading
Loading