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 @@ -80,6 +80,7 @@
#include "libobs/obs-source-filter-relationship-fields.c.h"
#include "libobs/obs-source-flags-mixers-fields.c.h"
#include "libobs/obs-source-frame-wrappers-fields.c.h"
#include "libobs/obs-source-get-release-frame-fields.c.h"
#include "libobs/obs-source-get-weak-fields.c.h"
#include "libobs/obs-source-handler-getters-fields.c.h"
#include "libobs/obs-source-hidden-setter-fields.c.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-source-get-release-frame+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): original obs_source_get_frame and obs_source_release_frame for C reference. */

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

#include "libobs/obs-source-get-release-frame.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/source-get-release-frame.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-source-get-release-frame+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
obs_source_get_frame
obs_source_release_frame
10 changes: 10 additions & 0 deletions libobs/obs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,16 @@ extern bool obs_source_frame_wrappers_destroying(obs_source_t *source);
extern void obs_source_frame_wrappers_output(obs_source_t *source, const struct obs_source_frame *frame);
extern void obs_source_frame_wrappers_preload(obs_source_t *source, const struct obs_source_frame *frame);
extern void obs_source_frame_wrappers_set(obs_source_t *source, const struct obs_source_frame *frame);
/* Async frame adapters for the Rust obs_source_get_frame() and
* obs_source_release_frame() (obs-source-get-release-frame-fields.c.h).
* Non-NULL only. */
extern void obs_source_async_frame_lock(obs_source_t *source);
extern void obs_source_async_frame_unlock(obs_source_t *source);
extern struct obs_source_frame *obs_source_async_frame_take_current(obs_source_t *source);
extern void obs_source_async_frame_addref(struct obs_source_frame *frame);
extern bool obs_source_async_frame_release_ref(struct obs_source_frame *frame);
extern void obs_source_async_frame_destroy(struct obs_source_frame *frame);
extern void obs_source_async_frame_return(obs_source_t *source, struct obs_source_frame *frame);

extern void set_deinterlace_texture_size(obs_source_t *source);
extern void deinterlace_process_last_frame(obs_source_t *source, uint64_t sys_time);
Expand Down
59 changes: 59 additions & 0 deletions libobs/obs-source-get-release-frame-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "libobs/build/libobs.pch.h"

/* Private adapters of the Rust obs_source_get_frame() and
* obs_source_release_frame() (obs-internal.h), each the line of
* obs-source-get-release-frame.c.h it stands for. NULL is rejected first. */

void obs_source_async_frame_lock(obs_source_t *source)
{
pthread_mutex_lock(&source->async_mutex);
}

void obs_source_async_frame_unlock(obs_source_t *source)
{
pthread_mutex_unlock(&source->async_mutex);
}

struct obs_source_frame *obs_source_async_frame_take_current(obs_source_t *source)
{
struct obs_source_frame *frame = source->cur_async_frame;
source->cur_async_frame = NULL;
return frame;
}

void obs_source_async_frame_addref(struct obs_source_frame *frame)
{
os_atomic_inc_long(&frame->refs);
}

bool obs_source_async_frame_release_ref(struct obs_source_frame *frame)
{
return os_atomic_dec_long(&frame->refs) == 0;
}

void obs_source_async_frame_destroy(struct obs_source_frame *frame)
{
obs_source_frame_destroy(frame);
}

void obs_source_async_frame_return(obs_source_t *source, struct obs_source_frame *frame)
{
remove_async_frame(source, frame);
}

/* Moved unchanged from obs-source.c.h, so the adapters' closure is one
* file for Rust-static consumers. */
void remove_async_frame(obs_source_t *source, struct obs_source_frame *frame)
{
if (frame)
frame->prev_frame = false;

for (size_t i = 0; i < source->async_cache.num; i++) {
struct async_frame *f = &source->async_cache.array[i];

if (f->frame == frame) {
f->used = false;
break;
}
}
}
47 changes: 47 additions & 0 deletions libobs/obs-source-get-release-frame.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "libobs/build/libobs.pch.h"

/*
* Ensures that cached frames are displayed on time. If multiple frames
* were cached between renders, then releases the unnecessary frames and uses
* the frame with the closest timing to ensure sync. Also ensures that timing
* with audio is synchronized.
*/
struct obs_source_frame *obs_source_get_frame(obs_source_t *source)
{
struct obs_source_frame *frame = NULL;

if (!obs_source_valid(source, "obs_source_get_frame"))
return NULL;

pthread_mutex_lock(&source->async_mutex);

frame = source->cur_async_frame;
source->cur_async_frame = NULL;

if (frame) {
os_atomic_inc_long(&frame->refs);
}

pthread_mutex_unlock(&source->async_mutex);

return frame;
}

void obs_source_release_frame(obs_source_t *source, struct obs_source_frame *frame)
{
if (!frame)
return;

if (!source) {
obs_source_frame_destroy(frame);
} else {
pthread_mutex_lock(&source->async_mutex);

if (os_atomic_dec_long(&frame->refs) == 0)
obs_source_frame_destroy(frame);
else
remove_async_frame(source, frame);

pthread_mutex_unlock(&source->async_mutex);
}
}
61 changes: 0 additions & 61 deletions libobs/obs-source.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2461,21 +2461,6 @@ _Static_assert(OBS_SOURCE_AUDIO_INPUT_LINEAR == OBS_BALANCE_TYPE_LINEAR, "OBS_BA
_Static_assert(sizeof(enum audio_format) == sizeof(int), "enum audio_format is passed as int");
_Static_assert(sizeof(enum speaker_layout) == sizeof(int), "enum speaker_layout is passed as int");

void remove_async_frame(obs_source_t *source, struct obs_source_frame *frame)
{
if (frame)
frame->prev_frame = false;

for (size_t i = 0; i < source->async_cache.num; i++) {
struct async_frame *f = &source->async_cache.array[i];

if (f->frame == frame) {
f->used = false;
break;
}
}
}

/* obs-source-async-pacing.c decides with the same threshold */
_Static_assert(OBS_SOURCE_ASYNC_PACING_MAX_TS_VAR == MAX_TS_VAR, "MAX_TS_VAR");

Expand Down Expand Up @@ -2525,52 +2510,6 @@ static inline struct obs_source_frame *get_closest_frame(obs_source_t *source, u
return frame;
}

/*
* Ensures that cached frames are displayed on time. If multiple frames
* were cached between renders, then releases the unnecessary frames and uses
* the frame with the closest timing to ensure sync. Also ensures that timing
* with audio is synchronized.
*/
struct obs_source_frame *obs_source_get_frame(obs_source_t *source)
{
struct obs_source_frame *frame = NULL;

if (!obs_source_valid(source, "obs_source_get_frame"))
return NULL;

pthread_mutex_lock(&source->async_mutex);

frame = source->cur_async_frame;
source->cur_async_frame = NULL;

if (frame) {
os_atomic_inc_long(&frame->refs);
}

pthread_mutex_unlock(&source->async_mutex);

return frame;
}

void obs_source_release_frame(obs_source_t *source, struct obs_source_frame *frame)
{
if (!frame)
return;

if (!source) {
obs_source_frame_destroy(frame);
} else {
pthread_mutex_lock(&source->async_mutex);

if (os_atomic_dec_long(&frame->refs) == 0)
obs_source_frame_destroy(frame);
else
remove_async_frame(source, frame);

pthread_mutex_unlock(&source->async_mutex);
}
}

static inline void render_filter_bypass(obs_source_t *target, gs_effect_t *effect, const char *tech_name)
{
gs_technique_t *tech = gs_effect_get_technique(effect, tech_name);
Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-source-frame-copy.c.h` | `obs-source::frame_copy` | Swapped in hybrid `libobs` (group `libobs.ported-source-frame-copy`). The async frame copy plan and cache decisions of `obs-source.c`, as six functions on plain values: `obs_source_frame_copy_plan()` (`copy_frame_data()`, `copy_frame_data_plane()` and `copy_frame_data_line()`: the colour range only when the frame is not full range, 065379b; then per format each plane's rows, `(height + 1) / 2` for 4:2:0 chroma, 8440a53; one copy of line size x rows in `size_t` when the two line sizes are equal, else rows of the smaller line size; no plane for P216, P416 and values outside the enum), `obs_source_frame_copy_cache_step()` (`cache_video()`'s queue limit at `MAX_ASYNC_FRAMES`, 7f7901b, which clears the cache and refuses the frame, then `async_texture_changed()`'s reset on a new size or convert type), `obs_source_frame_copy_cache_clean()` (one entry of `clean_cache()`: an unused entry counts one more call and is dropped at `MAX_UNUSED_FRAME_DURATION`, 3a90be3, 0815d5c), `obs_source_frame_copy_full_range()` and `_full_range2()` (a frame given to `obs_source_output_video()`, `obs_source_preload_video()` or `obs_source_set_video_frame()` that is not YUV is full range, 8d125dc; their `*2()` variants are full range when `resolve_video_range()` gives `VIDEO_RANGE_FULL`) and `obs_source_frame_copy_preload_changed()` (`preload_frame_changed()`). They are declared in `obs-source-frame-copy.h` without `EXPORT`, so the shims stay hidden. `obs-source.c.h` keeps every `memcpy()` (it runs the plan, each row at `y * line size` in `uint32_t`), the metadata copy, `obs_source_frame_create()` and `_destroy()`, the `async_cache` and `async_frames` darrays and the walk that picks the first unused entry (with #2048's `prev_frame` reset, #2009), `async_mutex`, the refcount atomics, and `get_convert_type()` (it passes the two convert types). Everything crosses by value, as `#[repr(C)]` mirrors of the header's structs: no pointer crosses. The formats and ranges cross as `int`, so values outside the enums take the C's paths. The arithmetic is the C's, wrap for wrap: `(height + 1) / 2` in `u32` and the one copy's size as a `usize` product. Kept, characterized, not endorsed: P216 and P416 copy no plane ("Unimplemented"); `UINT32_MAX` rows have 0 chroma rows; an unused count past 5 is never dropped (unreachable); the `*2()` rule keeps an explicit `VIDEO_RANGE_PARTIAL` on an RGB frame, which the first rule would make full range. Intentional difference, unreachable: `clean_cache()`'s `++unused_count` overflows a `long` at `LONG_MAX`, which is undefined in C; the port wraps. No entry gets past 5. `test_source_frame_copy_steps` compiles the C into itself, and `test_source_frame_copy_steps_rust` runs the same test source against `libobs_rust-static`; `test_video_frame`, the media restart tests, the v4l2 and PipeWire camera tests, `test_async_rotation_normalize` and the deinterlace tests see the swap through the real libobs. Tier 3 compares every field of every result over every C format value against every pattern of the four planes' line sizes (equal, smaller, larger, 0, or a destination of 0) at the `u32` height edges (2,280,000 plans), real frame line sizes, the queue limit over every length up to 64 with each key field changed alone, every count from -1000 to 1000 and the `c_long` ends but `LONG_MAX`, the range rules over formats -300 to 300 and every range from -10 to 10 with the `i32` ends, every preload combination around the edges, and proptests over each. |
| `libobs/obs-source-frame-wrappers.c.h` | `obs-source::frame_wrappers`, shim in `obs-source::ffi::source_frame_wrappers` | #5760: the six async-frame entry points `obs_source_output_video()`, `obs_source_preload_video()`, `obs_source_set_video_frame()` and their `*2()` variants, swapped in hybrid `libobs` (group `libobs.ported-source-frame-wrappers`). A source being destroyed returns at once, before the NULL check; a NULL frame goes to the worker as NULL, and the two `set_video_frame` entries hand it to the preload worker (upstream quirk, characterized, not endorsed). An `obs_source_frame` is copied whole with only `full_range` replaced by `frame_copy::full_range`; an `obs_source_frame2` gives a zeroed frame of its planes, size, timestamp, format, flip, flags, transfer and colour matrix and range, with `full_range` from `frame_copy::full_range2` and `max_luminance` 0. The worker gets the local copy; the caller's frame is only read. `destroying()` and the three workers (`obs_source_output_video_internal()`, `_preload_video_internal()`, `_set_video_frame_internal()`, no longer `static`, declared in `obs-internal.h`) stay C behind `obs-source-frame-wrappers-fields.c.h`. The new `test_source_frame_wrappers` runs against hybrid and reference libraries; Tier 3 runs the original C and the Rust exports on a real private source with `destroying()` and the workers recorded, comparing which worker runs, the source, the frame pointer (NULL, the caller's or a copy) and every field of the frame it gets as bits, with the layouts of both frame structs checked, four export mutants and a proptest over random frames. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-source-get-name.c.h` | `obs-source::source_name` | Borrowed source context name getter (#4505): unchanged NULL debug diagnostic, private nameless NULL, pointer identity and original lifetime. Lazy safe core, opaque C field adapter and real standalone link support; Tier 1 getter assertions, original-C differential and mutation checks, unchanged context-name Tier 2. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-source-get-release-frame.c.h` | `obs-source::get_release_frame`, shim in `obs-source::ffi::source_get_release_frame` | #5757: `obs_source_get_frame()` and `obs_source_release_frame()` swapped in hybrid `libobs` (group `libobs.ported-source-get-release-frame`). A NULL source logs the `obs_source_valid()` line and returns NULL from get; otherwise `cur_async_frame` is taken under `async_mutex` (the slot left NULL) with one added reference. Release ignores a NULL frame, destroys the frame of a NULL source without locking, and otherwise, under `async_mutex`, drops one reference and destroys at zero, else returns the frame to the async cache through `remove_async_frame()`. The mutex, slot, atomics, destroy and `remove_async_frame()` (moved unchanged from `obs-source.c.h`) stay C in `obs-source-get-release-frame-fields.c.h`, which also reaches Rust-static consumers through `source-get-release-frame-link-support.c`; the do-nothing release and cache stand-ins of `oracle/source_deinterlace_links.c` are gone. The new `test_source_get_release_frame` runs against hybrid and reference libraries; Tier 3 runs the original C and the Rust exports over real sources and frames on the same adapters, comparing results, recorded lock, unlock and destroy calls, the diagnostic and the state left, with four export mutants and a proptest over call sequences. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-source-get-weak.c.h` | `obs-source::get_weak` | #5228: `obs_source_get_weak_source()` swapped in hybrid `libobs` (group `libobs.ported-source-get-weak`). A NULL source returns NULL without reading anything or logging; otherwise the source's own `context.control`, read through the narrow private adapter `obs-source-get-weak-fields.c.h`, goes once through the C-owned `obs_weak_source_addref()` (also for a NULL control, a no-op there) and is returned. The strong count, the control and the source bytes stay untouched; release and the atomics stay in C. The unchanged `test_source_get_weak` runs against hybrid and reference libraries; Tier 3 runs the original C and the Rust export over present/absent sources and controls, noise-filled layouts and repeated calls, comparing returns, addref calls and arguments, weak and strong counts and source bytes. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-source-handler-getters.c.h`, `libobs/obs-source-signal-handler.c.h` | `obs-source::handler_getters` | Borrowed procedure handler getter (#4073) and signal handler getter (#5591), preserving pointer identity, absent handlers, NULL diagnostics and unchanged state. Both originals are in the reference-only group `libobs.ported-source-handler-getters`. Live discovered field adapter (signal and procedure addresses) for standalone consumers, real-header layout, Tier 1, differential mutation coverage and unchanged actual-library Tier 2 (`test_source_handler_getters`, `test_source_signal_handler_getter`). The audio-controls oracle's NULL-answering signal handler stand-in is renamed to `oracle_audio_controls_get_signal_handler` so it no longer collides with the Rust export in `obs-tests-core`. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-source-hidden-setter.c.h` | `obs-source::hidden_setter` | Hidden-state assignment through a borrowed boolean and thin ABI shim; real private field adapter, full-object C oracle parity, repeated assignments and unchanged `test_source_boolean_queries` coverage. NULL is checked before any field accessor; excluded from C differential inputs. |
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 @@ -57,6 +57,8 @@ mod canonical_source_flags_mixers_swap_is_registered;
mod canonical_source_frame_copy_data_swap_is_registered;
#[path = "native/registration/canonical_source_frame_wrappers_swap_is_registered.rs"]
mod canonical_source_frame_wrappers_swap_is_registered;
#[path = "native/registration/canonical_source_get_release_frame_swap_is_registered.rs"]
mod canonical_source_get_release_frame_swap_is_registered;
#[path = "native/registration/canonical_source_get_weak_swap_is_registered.rs"]
mod canonical_source_get_weak_swap_is_registered;
#[path = "native/registration/canonical_source_last_async_ts_swap_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use super::*;

#[test]
fn canonical_source_get_release_frame_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_get_release_frame";
graph.targets.retain(|key, _| key == name);
graph.tests.retain(|key, _| key == name);
let selected = graph
.select(&[("OS_LINUX".into(), true), ("OS_WINDOWS".into(), false)].into())
.unwrap();
// The unchanged test compiles no copy of the C: it calls the exported
// obs_source_get_frame() and obs_source_release_frame() 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_get_release_frame.c")
);
assert_eq!(selected.tests[name].target, name);
let ported = fs::read_to_string(
root.join("libobs/build/ported-source-sets/source-get-release-frame.json"),
)
.unwrap();
assert!(ported.contains("build/libobs.ported-source-get-release-frame+.h.c"));
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-source-get-release-frame+.h.c"))
.unwrap();
assert!(group.contains("#include \"libobs/obs-source-get-release-frame.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-get-release-frame.c.h\""));
assert!(hybrid.contains("#include \"libobs/obs-source-get-release-frame-fields.c.h\""));
let support =
fs::read_to_string(root.join("test/cmocka/build/rust-static-support.json")).unwrap();
assert!(support.contains("test/cmocka/source-get-release-frame-link-support.c"));
let exports = fs::read_to_string(
root.join("libobs/cmake/rust-exports.d/obs-source-source_get_release_frame.txt"),
)
.unwrap();
assert_eq!(
exports.lines().collect::<Vec<_>>(),
["obs_source_get_frame", "obs_source_release_frame"]
);
}
1 change: 1 addition & 0 deletions rust/obs-c-oracle/oracle.d/source-get-release-frame.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-get-release-frame.inc|libobs/obs-source-get-release-frame.c.h|auto
Loading
Loading