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
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-source-frame-copy-data+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): original obs_source_frame_copy for C reference. */

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

#include "libobs/obs-source-frame-copy-data.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/source-frame-copy-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-source-frame-copy-data+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_source_frame_copy
58 changes: 58 additions & 0 deletions libobs/obs-source-frame-copy-data.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "libobs/build/libobs.pch.h"

_Static_assert(OBS_SOURCE_FRAME_COPY_PLANES <= MAX_AV_PLANES, "a copy plan's planes are frame planes");

static inline struct obs_source_frame_copy_lines frame_copy_lines(const struct obs_source_frame *frame)
{
struct obs_source_frame_copy_lines lines;

for (size_t i = 0; i < OBS_SOURCE_FRAME_COPY_PLANES; i++)
lines.linesize[i] = frame->linesize[i];

return lines;
}

/* Runs one copy of the plan: copy_frame_data_plane() and
* copy_frame_data_line(). */
static inline void copy_frame_data_plane(struct obs_source_frame *dst, const struct obs_source_frame *src, size_t plane,
const struct obs_source_frame_plane_copy *copy)
{
if (!copy->whole) {
for (uint32_t y = 0; y < copy->rows; y++) {
uint32_t pos_src = y * copy->src_stride;
uint32_t pos_dst = y * copy->dst_stride;

memcpy(dst->data[plane] + pos_dst, src->data[plane] + pos_src, copy->bytes);
}
} else {
memcpy(dst->data[plane], src->data[plane], copy->bytes);
}
}

static void copy_frame_data(struct obs_source_frame *dst, const struct obs_source_frame *src)
{
dst->flip = src->flip;
dst->flags = src->flags;
dst->trc = src->trc;
dst->full_range = src->full_range;
dst->max_luminance = src->max_luminance;
dst->timestamp = src->timestamp;
memcpy(dst->color_matrix, src->color_matrix, sizeof(float) * 16);

const struct obs_source_frame_copy_plan plan = obs_source_frame_copy_plan(
(int)src->format, dst->full_range, dst->height, frame_copy_lines(src), frame_copy_lines(dst));

if (plan.color_range) {
size_t const size = sizeof(float) * 3;
memcpy(dst->color_range_min, src->color_range_min, size);
memcpy(dst->color_range_max, src->color_range_max, size);
}

for (size_t i = 0; i < plan.count && i < OBS_SOURCE_FRAME_COPY_PLANES; i++)
copy_frame_data_plane(dst, src, i, &plan.planes[i]);
}

void obs_source_frame_copy(struct obs_source_frame *dst, const struct obs_source_frame *src)
{
copy_frame_data(dst, src);
}
63 changes: 3 additions & 60 deletions libobs/obs-source.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2201,63 +2201,6 @@ struct obs_source_frame *filter_async_video(obs_source_t *source, struct obs_sou
return in;
}

_Static_assert(OBS_SOURCE_FRAME_COPY_PLANES <= MAX_AV_PLANES, "a copy plan's planes are frame planes");

static inline struct obs_source_frame_copy_lines frame_copy_lines(const struct obs_source_frame *frame)
{
struct obs_source_frame_copy_lines lines;

for (size_t i = 0; i < OBS_SOURCE_FRAME_COPY_PLANES; i++)
lines.linesize[i] = frame->linesize[i];

return lines;
}

/* Runs one copy of the plan: copy_frame_data_plane() and
* copy_frame_data_line(). */
static inline void copy_frame_data_plane(struct obs_source_frame *dst, const struct obs_source_frame *src, size_t plane,
const struct obs_source_frame_plane_copy *copy)
{
if (!copy->whole) {
for (uint32_t y = 0; y < copy->rows; y++) {
uint32_t pos_src = y * copy->src_stride;
uint32_t pos_dst = y * copy->dst_stride;

memcpy(dst->data[plane] + pos_dst, src->data[plane] + pos_src, copy->bytes);
}
} else {
memcpy(dst->data[plane], src->data[plane], copy->bytes);
}
}

static void copy_frame_data(struct obs_source_frame *dst, const struct obs_source_frame *src)
{
dst->flip = src->flip;
dst->flags = src->flags;
dst->trc = src->trc;
dst->full_range = src->full_range;
dst->max_luminance = src->max_luminance;
dst->timestamp = src->timestamp;
memcpy(dst->color_matrix, src->color_matrix, sizeof(float) * 16);

const struct obs_source_frame_copy_plan plan = obs_source_frame_copy_plan(
(int)src->format, dst->full_range, dst->height, frame_copy_lines(src), frame_copy_lines(dst));

if (plan.color_range) {
size_t const size = sizeof(float) * 3;
memcpy(dst->color_range_min, src->color_range_min, size);
memcpy(dst->color_range_max, src->color_range_max, size);
}

for (size_t i = 0; i < plan.count && i < OBS_SOURCE_FRAME_COPY_PLANES; i++)
copy_frame_data_plane(dst, src, i, &plan.planes[i]);
}

void obs_source_frame_copy(struct obs_source_frame *dst, const struct obs_source_frame *src)
{
copy_frame_data(dst, src);
}

/* What async_texture_changed() compared: the cache's size and convert type,
* and the frame's. */
static inline struct obs_source_frame_copy_key async_cache_key(const struct obs_source *source)
Expand Down Expand Up @@ -2377,7 +2320,7 @@ static inline struct obs_source_frame *cache_video(struct obs_source *source, co

pthread_mutex_unlock(&source->async_mutex);

copy_frame_data(new_frame, frame);
obs_source_frame_copy(new_frame, frame);

return new_frame;
}
Expand Down Expand Up @@ -2523,7 +2466,7 @@ static void obs_source_preload_video_internal(obs_source_t *source, const struct
source->async_preload_frame = obs_source_frame_create(frame->format, frame->width, frame->height);
}

copy_frame_data(source->async_preload_frame, frame);
obs_source_frame_copy(source->async_preload_frame, frame);

pthread_mutex_lock(&source->async_mutex);
source->last_frame_ts = frame->timestamp;
Expand Down Expand Up @@ -2624,7 +2567,7 @@ static void obs_source_set_video_frame_internal(obs_source_t *source, const stru
source->async_preload_frame = obs_source_frame_create(frame->format, frame->width, frame->height);
}

copy_frame_data(source->async_preload_frame, frame);
obs_source_frame_copy(source->async_preload_frame, frame);
set_async_texture_size(source, source->async_preload_frame);
update_async_textures(source, source->async_preload_frame, source->async_textures, source->async_texrender);
os_atomic_set_bool(&source->async_textures_stale, false);
Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-source-filter-index.c.h` | `obs-source::filter_index` | Pointer-identity lookup under the original filter mutex, first duplicate wins, absent/empty returns -1. Preserves NULL validation order and exact debug logs. Private C adapters retain field access and locking; unchanged C characterization and real-header differential tests cover state and mutex release. No intentional differences; Tier 4 inapplicable. |
| `libobs/obs-source-filter-relationship-getters.c.h` | `obs-source::filter_relationship_getters` | Borrowed parent/target getters preserve pointer identity, NULL defaults and exact debug logs. No source-type validation, lock or reference acquisition. Private field-pointer seam avoids mirroring `obs_source`. Unchanged actual-library C characterization, real-header view layout and Tier 3 check pointer identity and complete fixture immutability. No intentional differences; Tier 4 not applicable. |
| `libobs/obs-source-flags-mixers.c.h` | `obs-source::flags_mixers`, shims in `obs-source::ffi::source_flags_mixers` | #5610: swapped in hybrid `libobs` (group `libobs.ported-source-flags-mixers`). `obs_source_set_flags()` stores a changed value, then emits `update_flags` with the source and the stored flags; an unchanged value stores and emits nothing. `obs_source_set_audio_mixers()` leaves a source without `OBS_SOURCE_AUDIO` that does not own its info id alone; on a change it emits `audio_mixers` before the store (handlers see the old field and getter answer and may rewrite `mixers`), then stores the low 32 bits of what the calldata holds afterwards (0 when a handler left it with another size). Both signals go through libobs's signal handler on a fixed 128-byte calldata. A NULL source logs one `LOG_DEBUG` line naming the function. The same-value, audio and truncation rules are `obs-source::monitoring`'s. Safe core over a `Source` trait; the shims reject NULL before calling the adapters of `obs-source-flags-mixers-fields.c.h` (live group `libobs.core-source`, no `EXPORT`). `signal_flags_updated()` moved with its only caller. The unchanged `test_source_flags_mixers` 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 with a real signal handler, over handlers that leave, rewrite, resize or re-set the value from inside (every event, value, field seen, calldata shape, stored fields, every other byte, NULL log lines), a proptest, and rejects five mutants. | None. |
| `libobs/obs-source-frame-copy-data.c.h` | `obs-source::frame_copy_data` | #5714: `obs_source_frame_copy()` and the `copy_frame_data()` behind it, which `cache_video()` and the two preload paths now reach through the exported function. Swapped in hybrid `libobs` (group `libobs.ported-source-frame-copy-data`). Safe core `frame_copy_data::copy_frame_data` writes the metadata (flip, flags, transfer, range, maximum luminance, timestamp, colour matrix bit for bit), asks the existing `frame_copy::copy_plan` (no new plan logic), writes the colour range only when the plan says so (the source is not full range), then runs each plane: one copy for equal line sizes, else row by row at each stride with the smaller line size, row starts in `u32` as the C computes them. The shim mirrors the public `struct obs_source_frame`, writes each field through the pointer and builds each plane's slices from `plane_extent`; `format`, size, `data`, line sizes, `refs` and `prev_frame` are never written. Unchanged C characterization `test_source_frame_copy` (every format, equal and unequal line sizes, metadata and colour range, same-shape frames) runs against hybrid and reference libraries; Tier 3 compares the original C over every format, seven sizes and six line-size patterns, and a proptest over same-shape frames, fields as bits and plane bytes with guards. No intentional differences; Tier 4 does not apply. |
| `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-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-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. |
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 @@ -53,6 +53,8 @@ mod canonical_source_draw_swap_is_registered;
mod canonical_source_enum_filters_swap_is_registered;
#[path = "native/registration/canonical_source_flags_mixers_swap_is_registered.rs"]
mod canonical_source_flags_mixers_swap_is_registered;
#[path = "native/registration/canonical_source_frame_copy_data_swap_is_registered.rs"]
mod canonical_source_frame_copy_data_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_media_controls_swap_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use super::*;

#[test]
fn canonical_source_frame_copy_data_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_frame_copy";
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 unchanged test compiles no copy of the C: it calls the exported
// obs_source_frame_copy() 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_frame_copy.c")
);
assert_eq!(selected.tests[name].target, name);
}
let ported = fs::read_to_string(
root.join("libobs/build/ported-source-sets/source-frame-copy-data.json"),
)
.unwrap();
assert!(ported.contains("build/libobs.ported-source-frame-copy-data+.h.c"));
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-source-frame-copy-data+.h.c"))
.unwrap();
assert!(group.contains("#include \"libobs/obs-source-frame-copy-data.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-frame-copy-data.c.h\""));
assert!(hybrid.contains("#include \"libobs/obs-source.c.h\""));
let exports = fs::read_to_string(
root.join("libobs/cmake/rust-exports.d/obs-source-source_frame_copy_data.txt"),
)
.unwrap();
assert_eq!(
exports.lines().collect::<Vec<_>>(),
["obs_source_frame_copy"]
);
}
1 change: 1 addition & 0 deletions rust/obs-c-oracle/oracle.d/source-frame-copy-data.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source-frame-copy-data.inc|libobs/obs-source-frame-copy-data.c.h|auto
46 changes: 46 additions & 0 deletions rust/obs-c-oracle/oracle/source_frame_copy_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Tier 3: the unchanged extracted obs_source_frame_copy() (copy_frame_data()
* and its helpers) against the Rust export. Both ask the same
* obs_source_frame_copy_plan() (the Rust one; its own parity is
* source_frame_copy.c), so this compares running the plan: the fields
* written and the bytes copied. */
#define _NO_CRT_STDIO_INLINE
#include <stddef.h>
#include <stdint.h>
#define obs_source_frame_copy oracle_obs_source_frame_copy
#include "libobs/build/libobs.pch.h"
#include "source-frame-copy-data.inc"
#undef obs_source_frame_copy

/* The layout of struct obs_source_frame, in the order of
* rust/obs-source/tests/source/frame_copy_data_parity.rs; SIZE_MAX past
* the end. */
size_t oracle_source_frame_copy_data_layout(size_t which);

#define OFF(member) offsetof(struct obs_source_frame, member)

size_t oracle_source_frame_copy_data_layout(size_t which)
{
const size_t values[] = {
sizeof(struct obs_source_frame),
_Alignof(struct obs_source_frame),
OFF(data),
OFF(linesize),
OFF(width),
OFF(height),
OFF(timestamp),
OFF(format),
OFF(color_matrix),
OFF(full_range),
OFF(max_luminance),
OFF(color_range_min),
OFF(color_range_max),
OFF(flip),
OFF(flags),
OFF(trc),
OFF(refs),
OFF(prev_frame),
sizeof(enum video_format),
MAX_AV_PLANES,
};
return which < sizeof(values) / sizeof(values[0]) ? values[which] : SIZE_MAX;
}
Loading
Loading