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 @@ -109,6 +109,7 @@
#include "libobs/obs-source-push-to-enable-fields.c.h"
#include "libobs/obs-source-remove-fields.c.h"
#include "libobs/obs-source-removed-fields.c.h"
#include "libobs/obs-source-restore-filters-fields.c.h"
#include "libobs/obs-source-save-load-fields.c.h"
#include "libobs/obs-source-set-name-fields.c.h"
#include "libobs/obs-source-settings-getter-fields.c.h"
Expand Down
4 changes: 4 additions & 0 deletions libobs/build/libobs.ported-source-restore-filters+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Unity group (BUILD.md): original source restore filters for C reference. */
#include "libobs/build/libobs.pch.h"

#include "libobs/obs-source-restore-filters.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/source-restore-filters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-source-restore-filters+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_source_restore_filters
114 changes: 114 additions & 0 deletions libobs/obs-source-restore-filters-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "libobs/build/libobs.pch.h"

/* What obs_source_restore_filters() reads, writes, loads and releases (the
* obs-source shim). The caller rejects a NULL source and array, keeps both
* alive, touches the list only between lock and unlock, at indexes below a
* count read under the lock, and holds a reference to every filter it
* passes (an old filter until it releases it, a restored one from its
* reference or load); each call is one read, one write or one libobs
* call. */
void obs_source_restore_filters_lock(obs_source_t *source);
void obs_source_restore_filters_lock(obs_source_t *source)
{
pthread_mutex_lock(&source->filter_mutex);
}

size_t obs_source_restore_filters_count(const obs_source_t *source);
size_t obs_source_restore_filters_count(const obs_source_t *source)
{
return source->filters.num;
}

obs_source_t *obs_source_restore_filters_at(const obs_source_t *source, size_t index);
obs_source_t *obs_source_restore_filters_at(const obs_source_t *source, size_t index)
{
return source->filters.array[index];
}

void obs_source_restore_filters_set_parent(obs_source_t *filter, obs_source_t *parent);
void obs_source_restore_filters_set_parent(obs_source_t *filter, obs_source_t *parent)
{
filter->filter_parent = parent;
}

void obs_source_restore_filters_set_target(obs_source_t *filter, obs_source_t *target);
void obs_source_restore_filters_set_target(obs_source_t *filter, obs_source_t *target)
{
filter->filter_target = target;
}

void obs_source_restore_filters_free_list(obs_source_t *source);
void obs_source_restore_filters_free_list(obs_source_t *source)
{
da_free(source->filters);
}

void obs_source_restore_filters_unlock(obs_source_t *source);
void obs_source_restore_filters_unlock(obs_source_t *source)
{
pthread_mutex_unlock(&source->filter_mutex);
}

size_t obs_source_restore_filters_item_count(obs_data_array_t *array);
size_t obs_source_restore_filters_item_count(obs_data_array_t *array)
{
return obs_data_array_count(array);
}

obs_data_t *obs_source_restore_filters_item(obs_data_array_t *array, size_t index);
obs_data_t *obs_source_restore_filters_item(obs_data_array_t *array, size_t index)
{
return obs_data_array_item(array, index);
}

const char *obs_source_restore_filters_item_name(obs_data_t *item);
const char *obs_source_restore_filters_item_name(obs_data_t *item)
{
return obs_data_get_string(item, "name");
}

const char *obs_source_restore_filters_name(const obs_source_t *filter);
const char *obs_source_restore_filters_name(const obs_source_t *filter)
{
return filter->context.name;
}

obs_source_t *obs_source_restore_filters_get_ref(obs_source_t *filter);
obs_source_t *obs_source_restore_filters_get_ref(obs_source_t *filter)
{
return obs_source_get_ref(filter);
}

obs_source_t *obs_source_restore_filters_load(obs_data_t *item);
obs_source_t *obs_source_restore_filters_load(obs_data_t *item)
{
return obs_load_source(item);
}

obs_source_t *obs_source_restore_filters_load_private(obs_data_t *item);
obs_source_t *obs_source_restore_filters_load_private(obs_data_t *item)
{
return obs_load_private_source(item);
}

/* da_move(source->filters, new_filters) for the shim's list: the old array
* is freed and the source's list becomes a copy of the count filters. */
void obs_source_restore_filters_store(obs_source_t *source, obs_source_t *const *filters, size_t count);
void obs_source_restore_filters_store(obs_source_t *source, obs_source_t *const *filters, size_t count)
{
da_free(source->filters);
if (count)
da_push_back_array(source->filters, filters, count);
}

void obs_source_restore_filters_release_item(obs_data_t *item);
void obs_source_restore_filters_release_item(obs_data_t *item)
{
obs_data_release(item);
}

void obs_source_restore_filters_release(obs_source_t *filter);
void obs_source_restore_filters_release(obs_source_t *filter)
{
obs_source_release(filter);
}
80 changes: 80 additions & 0 deletions libobs/obs-source-restore-filters.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "libobs/build/libobs.pch.h"

void obs_source_restore_filters(obs_source_t *source, obs_data_array_t *array)
{
if (!obs_source_valid(source, "obs_source_restore_filters"))
return;
if (!obs_ptr_valid(array, "obs_source_restore_filters"))
return;

DARRAY(obs_source_t *) cur_filters;
DARRAY(obs_source_t *) new_filters;
obs_source_t *prev = NULL;

da_init(cur_filters);
da_init(new_filters);

pthread_mutex_lock(&source->filter_mutex);

/* clear filter list */
da_reserve(cur_filters, source->filters.num);
da_reserve(new_filters, source->filters.num);
for (size_t i = 0; i < source->filters.num; i++) {
obs_source_t *filter = source->filters.array[i];
da_push_back(cur_filters, &filter);
filter->filter_parent = NULL;
filter->filter_target = NULL;
}

da_free(source->filters);
pthread_mutex_unlock(&source->filter_mutex);

/* add backed up filters */
size_t count = obs_data_array_count(array);
for (size_t i = 0; i < count; i++) {
obs_data_t *data = obs_data_array_item(array, i);
const char *name = obs_data_get_string(data, "name");
obs_source_t *filter = NULL;

/* if backed up filter already exists, don't create */
for (size_t j = 0; j < cur_filters.num; j++) {
obs_source_t *cur = cur_filters.array[j];
const char *cur_name = cur->context.name;
if (obs_source_filter_chain_restore_matches(cur_name, name)) {
filter = obs_source_get_ref(cur);
break;
}
}

int restore_step = obs_source_filter_chain_restore_step(filter != NULL);
if (restore_step == OBS_SOURCE_FILTER_CHAIN_RESTORE_LOAD)
filter = obs_load_source(data);
else if (restore_step == OBS_SOURCE_FILTER_CHAIN_RESTORE_LOAD_PRIVATE)
filter = obs_load_private_source(data);

/* add filter; parents are set once every target is (#2172) */
if (prev)
prev->filter_target = filter;
prev = filter;
da_push_back(new_filters, &filter);

obs_data_release(data);
}

if (prev)
prev->filter_target = source;
for (size_t i = 0; i < new_filters.num; i++)
new_filters.array[i]->filter_parent = source;

pthread_mutex_lock(&source->filter_mutex);
da_move(source->filters, new_filters);
pthread_mutex_unlock(&source->filter_mutex);

/* release filters */
for (size_t i = 0; i < cur_filters.num; i++) {
obs_source_t *filter = cur_filters.array[i];
obs_source_release(filter);
}

da_free(cur_filters);
}
79 changes: 0 additions & 79 deletions libobs/obs-source.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2863,85 +2863,6 @@ _Static_assert(OBS_SOURCE_MEDIA_CONTROLLABLE == OBS_SOURCE_CONTROLLABLE_MEDIA, "
_Static_assert(OBS_SOURCE_MEDIA_STATE_NONE == OBS_MEDIA_STATE_NONE, "OBS_MEDIA_STATE_NONE");
_Static_assert(sizeof(enum obs_media_state) == sizeof(int), "enum obs_media_state is passed as int");

void obs_source_restore_filters(obs_source_t *source, obs_data_array_t *array)
{
if (!obs_source_valid(source, "obs_source_restore_filters"))
return;
if (!obs_ptr_valid(array, "obs_source_restore_filters"))
return;

DARRAY(obs_source_t *) cur_filters;
DARRAY(obs_source_t *) new_filters;
obs_source_t *prev = NULL;

da_init(cur_filters);
da_init(new_filters);

pthread_mutex_lock(&source->filter_mutex);

/* clear filter list */
da_reserve(cur_filters, source->filters.num);
da_reserve(new_filters, source->filters.num);
for (size_t i = 0; i < source->filters.num; i++) {
obs_source_t *filter = source->filters.array[i];
da_push_back(cur_filters, &filter);
filter->filter_parent = NULL;
filter->filter_target = NULL;
}

da_free(source->filters);
pthread_mutex_unlock(&source->filter_mutex);

/* add backed up filters */
size_t count = obs_data_array_count(array);
for (size_t i = 0; i < count; i++) {
obs_data_t *data = obs_data_array_item(array, i);
const char *name = obs_data_get_string(data, "name");
obs_source_t *filter = NULL;

/* if backed up filter already exists, don't create */
for (size_t j = 0; j < cur_filters.num; j++) {
obs_source_t *cur = cur_filters.array[j];
const char *cur_name = cur->context.name;
if (obs_source_filter_chain_restore_matches(cur_name, name)) {
filter = obs_source_get_ref(cur);
break;
}
}

int restore_step = obs_source_filter_chain_restore_step(filter != NULL);
if (restore_step == OBS_SOURCE_FILTER_CHAIN_RESTORE_LOAD)
filter = obs_load_source(data);
else if (restore_step == OBS_SOURCE_FILTER_CHAIN_RESTORE_LOAD_PRIVATE)
filter = obs_load_private_source(data);

/* add filter; parents are set once every target is (#2172) */
if (prev)
prev->filter_target = filter;
prev = filter;
da_push_back(new_filters, &filter);

obs_data_release(data);
}

if (prev)
prev->filter_target = source;
for (size_t i = 0; i < new_filters.num; i++)
new_filters.array[i]->filter_parent = source;

pthread_mutex_lock(&source->filter_mutex);
da_move(source->filters, new_filters);
pthread_mutex_unlock(&source->filter_mutex);

/* release filters */
for (size_t i = 0; i < cur_filters.num; i++) {
obs_source_t *filter = cur_filters.array[i];
obs_source_release(filter);
}

da_free(cur_filters);
}

/* File-local macros: keep them out of the next source of a unity build. */
#undef get_weak

Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-source-removed.c.h` | `obs-source::removed` | #5587: `obs_source_removed()` answers the source's `removed` flag, read once with a sequentially consistent atomic load of the C `volatile bool` (as `os_atomic_load_bool()` does), and changes nothing; a NULL source answers true (a missing source counts as removed), logs its `LOG_DEBUG` line `obs_source_removed: Null 'source' parameter` and reads nothing. Safe Rust core; the shim rejects NULL before calling the new flag address adapter of `obs-source-removed-fields.c.h` (live group `libobs.core-source`, one read, no `EXPORT`). The original moves to the reference-only group `libobs.ported-source-removed`, and the oracle's do-nothing `obs_source_removed()` link stand-in in `audio_callback_links.c` is gone: `obs-tests-core` now links the real Rust export, whose adapter the oracle compiles. The unchanged `test_source_removed` (NULL, the flag alone under 0x00/0xff/0x5a fill with no writes, reads while another thread flips the flag) runs against hybrid and reference libraries through the real libobs. Tier 3 runs the original C and the Rust export on noise-filled sources over both flag values and a proptest, comparing results, logs and every source byte, pins the expected answers and rejects three shim mutants. | None. |
| `libobs/obs-source-render-route.c.h` | `obs-source::render_route` | Swapped in hybrid `libobs` (group `libobs.ported-source-render-route`). The source and filter render routing of `source_render_video()`, `obs_source_main_render()`, `can_bypass()`, `obs_source_process_filter_begin_with_color_space()`, `obs_source_process_filter_tech_end()` and `obs_source_skip_video_filter()`, as 23 functions on plain values: `obs_source_render_route_filter()` (the target and parent check, no target first, #2177), the "no video", async update and inactive checks of `source_render_video()` with a `_reads_` function for each value the old short circuits read on one side only, the draw as a route over `enum obs_source_render_route_draw` (`_draw()`, `_skip()` and `_filter_render()` start it, `_draw_next()` takes the one value a `READ_` step asks for and returns the next step or the draw: default render, filters, main render, filter target, deinterlace or async video), `obs_source_main_render()`'s custom draw, sRGB-aware and default-effect rules, `can_bypass()` (`_bypass_reads_space()`, then `_bypass()`; the SRGB and space rules of #1493's filter colour space class), the zero size skip, the texrender format check, and the tech end's linear sRGB flag, technique name (`"Draw"` for NULL) and bypass or texture. They are declared in `obs-source-render-route.h` without `EXPORT`, so the shims stay hidden. `obs-source.c.h` keeps every `gs_*` call and texrender, the refs, the render calls, `get_base_width()` and `get_base_height()` (it passes the sizes), the debug markers and every field read in its order and under its conditions; that is why the decisions are many small calls and not one plan per function. Types, the direct render choice, colour spaces and formats cross as `int`; `obs-source.c.h` checks the four enums are `int`-sized. A draw step outside the enum comes back unchanged. Kept, characterized, not endorsed: `ASYNC` without `VIDEO` is no video; a direct render choice outside the enum is not direct; a size of 2^31 or more is negative in the C's `int` and does not skip. One pointer crosses: the technique name, returned as given or as a static `"Draw"`, never read. No other intentional differences. `test_source_render_route_steps` compiles the C into itself, and `test_source_render_route_steps_rust` runs the same test source against `libobs_rust-static`; `test_filter_color_space`, `test_filter_skip_removed`, `test_scroll_filter_wide_source`, `test_color_correction_16f`, `test_darken_transparent`, `test_scene_rotated_scale_filter`, `test_slideshow_size` and `test_texture_render` see the swap through the real libobs. Tier 3 compares the result bytes of every function over every boolean, sweeps of types, choices, spaces, formats and sizes over all of `i32`, every 16-bit flag pattern, 17 million bypass inputs, every draw step value, and each caller's decisions in its order (19.9 million filters, 166,400 sources), plus full-range proptests. |
| `libobs/obs-source-replace-missing-file.c.h` | `obs-source::replace_missing_file` | #5635: `obs_source_replace_missing_file()` calls the callback once with the source's private data, the path and the data argument unchanged; a NULL source logs the original debug line, a source without private data does nothing. Safe Rust core with a NULL-checked shim over the missing-files getter's private-layout adapter; unchanged C characterization and original-C differential coverage. No intentional differences (a NULL callback with live data crashes both); Tier 4 does not apply. |
| `libobs/obs-source-restore-filters.c.h` | `obs-source::restore_filters`, shim in `obs-source::ffi::source_restore_filters` | #5801: swapped in hybrid `libobs` (group `libobs.ported-source-restore-filters`). `obs_source_restore_filters()`, the filters dialog's undo and redo and the paste of copied filters: a NULL source or array logs one `LOG_DEBUG` line (source first) and touches nothing. Under `filter_mutex` every current filter is kept aside in order, its `filter_parent` and `filter_target` cleared, and the list freed; then the lock is dropped. For each array item in order, with the lock free: the first current filter whose name matches the item's `name` (`obs-source::source_filter_chain`'s match: an unnamed filter never matches) is reused through `obs_source_get_ref()`; when none matches or the reference fails, the item is loaded as the chain rule's restore step says; each restored filter becomes the previous one's `filter_target`, and the item is released. The last restored filter targets the source, then every restored filter gets the source as `filter_parent` (only after every target, #2172), and the new list is moved into the source under `filter_mutex`. Afterwards each old filter is released once, in old order. No signals; no log line on the success path. A duplicated name lists the same filter twice. Safe Rust core over a `RestoreList` trait; the shim rejects NULL before calling the adapters of `obs-source-restore-filters-fields.c.h` (live group `libobs.core-source`, no `EXPORT`): the lock, the list reads, the unlinks, `da_free()`, the move of the new list, the name reads, `obs_source_get_ref()`, `obs_load_source()` and `obs_load_private_source()`, the parent and target writes, `obs_source_release()` and the `obs_data` array and item calls. The new `test_source_restore_filters` runs against hybrid and reference libraries through the real core (a current filter whose last reference is gone can't be listed there, so Tier 1 and Tier 3 cover it). Tier 3 runs the original C and the Rust export on noise-filled real-header sources with a stand-in array and recording references, loads and releases over every chain of 0 to 6 current filters (an unnamed one, a repeated name) with every array of up to 3 items over 7 names and longer patterns (reusing, loading, duplicating and dropping filters), with each listed filter unreferenceable, plus a proptest of up to 6 items, comparing the new list, every target and parent, each item read, name read and item release, reference, load and release in order with the lock state and the list and links at that moment, the NULL lines, every other byte, the lock and the item holds; it rejects seven mutants. | None of its own; loading an unmatched filter private is `source_filter_chain`'s (#2981). |
| `libobs/obs-source-save-load.c.h` | `obs-source::save_load` | Source save/load callback and signal ordering, invalid plugin-data guards and parent-first reverse direct-filter traversal (#4353). Private live adapter preserves callbacks, settings identity and existing signal privacy. Tier 1 mirrors the C characterization; Tier 3 exercises actual exports against original C. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-source-set-name.c.h` | `obs-source::set_name` | Swapped in hybrid `libobs`; the C reference keeps the unchanged extracted setter (its own ported group). Rejects NULL with its original debug line; a NULL or empty request or a NULL current name always renames. A public source that requires a canvas goes through `obs_canvas_rename_source()`; otherwise the previous name is copied, the context is renamed through the public table (or with none, for private sources), privacy is read again before the global `source_rename`, the local `rename` follows, and the payload and copy are freed after both. C keeps the layouts, name tables, canvas rename and signal delivery behind the live adapter `obs-source-set-name-fields.c.h`. Tier 1 ports `test_source_set_name.c` 1:1 with the read and call order; Tier 3 compares the unchanged C and the Rust ABI over the real private layout with tracing stand-ins, privacy flips and payload edits. No intentional differences or new test binary. |# Rust ports of OBS Studio internals
| `libobs/obs-source-settings-getter.c.h` | `obs-source::settings_getter` | Source settings getter (#4162): stored pointer identity, exactly one added reference, unchanged source/settings and NULL diagnostic. Thin private accessor rejects NULL in Rust first; Tier 1 and original-C Tier 3 with live settings reference counts, unchanged scene Tier 2 tests. No layout mirrored, no protocol changes or 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 @@ -91,6 +91,8 @@ mod canonical_source_remove_swap_is_registered;
mod canonical_source_removed_swap_is_registered;
#[path = "native/registration/canonical_source_replace_missing_file_swap_is_registered.rs"]
mod canonical_source_replace_missing_file_swap_is_registered;
#[path = "native/registration/canonical_source_restore_filters_swap_is_registered.rs"]
mod canonical_source_restore_filters_swap_is_registered;
#[path = "native/registration/canonical_source_show_active_counters_swap_is_registered.rs"]
mod canonical_source_show_active_counters_swap_is_registered;
#[path = "native/registration/canonical_source_show_preloaded_video_swap_is_registered.rs"]
Expand Down
Loading
Loading