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+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "libobs/obs-core-state.c.h"
#include "libobs/obs-core-texture-activity-fields.c.h"
#include "libobs/obs-core-tick-callbacks-fields.c.h"
#include "libobs/obs-encoder-video-tex-active-mix.c.h"
#include "libobs/obs-enum-scenes-fields.c.h"
#include "libobs/obs-get-audio-fields.c.h"
#include "libobs/obs-get-main-canvas-fields.c.h"
Expand Down
2 changes: 1 addition & 1 deletion libobs/build/libobs.core-output+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "libobs/obs-encoder-settings-fields.c.h"
#include "libobs/obs-encoder-state-queries-fields.c.h"
#include "libobs/obs-encoder-type-info-fields.c.h"
#include "libobs/obs-encoder-video-tex-active.c.h"
#include "libobs/obs-encoder-video-tex-active-fields.c.h"
#include "libobs/obs-encoder.c.h"
#include "libobs/obs-output-active-fields.c.h"
#include "libobs/obs-output-can-pause-fields.c.h"
Expand Down
4 changes: 4 additions & 0 deletions libobs/build/libobs.ported-encoder-video-tex-active+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Unity group (BUILD.md): original texture-input activity query, reference only. */
#include "libobs/build/libobs.pch.h"

#include "libobs/obs-encoder-video-tex-active.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/encoder-video-tex-active.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-encoder-video-tex-active+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_encoder_video_tex_active
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_encoder_video_tex_active_rust
20 changes: 20 additions & 0 deletions libobs/obs-encoder-video-tex-active-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "libobs/build/libobs.pch.h"

const struct obs_core_video_mix *obs_encoder_video_tex_active_mix(const obs_encoder_t *encoder);
bool obs_encoder_video_tex_active_nv12(const struct obs_core_video_mix *mix);
bool obs_encoder_video_tex_active_p010(const struct obs_core_video_mix *mix);

const struct obs_core_video_mix *obs_encoder_video_tex_active_mix(const obs_encoder_t *encoder)
{
return get_mix_for_video(encoder->media);
}

bool obs_encoder_video_tex_active_nv12(const struct obs_core_video_mix *mix)
{
return mix->using_nv12_tex;
}

bool obs_encoder_video_tex_active_p010(const struct obs_core_video_mix *mix)
{
return mix->using_p010_tex;
}
19 changes: 19 additions & 0 deletions libobs/obs-encoder-video-tex-active-mix.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "libobs/build/libobs.pch.h"

struct obs_core_video_mix *get_mix_for_video(video_t *v)
{
struct obs_core_video_mix *result = NULL;

pthread_mutex_lock(&obs->video.mixes_mutex);
for (size_t i = 0, num = obs->video.mixes.num; i < num; i++) {
struct obs_core_video_mix *mix = obs->video.mixes.array[i];

if (v == mix->video) {
result = mix;
break;
}
}
pthread_mutex_unlock(&obs->video.mixes_mutex);

return result;
}
18 changes: 0 additions & 18 deletions libobs/obs.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2922,24 +2922,6 @@ void obs_get_video_frame_counts(uint32_t *total, uint32_t *skipped)
*skipped = skipped_frames;
}

struct obs_core_video_mix *get_mix_for_video(video_t *v)
{
struct obs_core_video_mix *result = NULL;

pthread_mutex_lock(&obs->video.mixes_mutex);
for (size_t i = 0, num = obs->video.mixes.num; i < num; i++) {
struct obs_core_video_mix *mix = obs->video.mixes.array[i];

if (v == mix->video) {
result = mix;
break;
}
}
pthread_mutex_unlock(&obs->video.mixes_mutex);

return result;
}

void start_raw_video(video_t *v, const struct video_scale_info *conversion, uint32_t frame_rate_divisor,
void (*callback)(void *param, struct video_data *frame), void *param)
{
Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ and compares their exported symbols. `OBS_LIBOBS_BACKEND=C` is temporary rollbac
| `libobs/obs-encoder-frame-rate-divisor.c.h` (extracted from `obs-encoder.c.h`) | `obs-output::encoder_frame_rate_divisor` | Public frame-rate-divisor getter. Preserves NULL and audio-type defaults, historical setter diagnostics, current-info type selection, full-width divisor and no mutation. Borrowed private fields; real-header layout and callback-based randomized Tier 3 parity; unchanged actual-library Tier 2 on both libraries. No intended differences; Tier 4 inapplicable. |
| `libobs/obs-encoder-packet-ownership.c.h` | `obs-encoder::packet_ownership` | Swapped in hybrid `libobs` (group `libobs.ported-encoder-packet-ownership`). `obs_encoder_packet_create_instance` (hidden), `obs_encoder_packet_ref` and `obs_encoder_packet_release` keep the C layout: one bmem block per payload, a native `long` count in front of the data, atomic increments and decrements, the block freed on the last release, then the whole packet zeroed. create copies every field, then allocates `size + sizeof(long)` and copies the payload (an owned source is copied too, never shared); ref of NULL does nothing, and a packet with no data is copied without touching a count. The safe core holds the order behind a host trait; the FFI keeps the pointers. Tier 1 checks the order against a recording host and mirrors every assertion of `test_encoder_packet_ownership` through the exports; Tier 3 runs random create/ref/release/write sequences on four packets per side against the original C, comparing fields, block aliasing, counts, bytes and `bnum_allocs()` after every step. The delay and interleave parity tests now go through these exports instead of their own copies. Excluded as in C: NULL-data or self copies, and refs of buffers with no count. No intentional differences; Tier 4 inapplicable. |
| `libobs/obs-encoder-media-getters.c.h` | `obs-encoder::media_getters` | Video, parent-video and audio getters preserve NULL diagnostics, wrong-type warnings, borrowed media identity and FPS override priority, without active/initialized gates or mutation. Real private-layout snapshot adapter, header-derived layout checks, Tier 1 characterization mirrors and original-C randomized differential coverage in obs-tests-core; unchanged public C characterization runs against both libraries. No intentional behavior differences. |
| `libobs/obs-encoder-video-tex-active.c.h` | `obs-encoder::video_tex_active` | Texture-input activity preserves one C mutex-protected mix lookup before the absent-mix guard and only the requested NV12/P010 flag read. Opaque C-owned adapters retain private layouts; safe mirrors, unchanged C characterization, real-walk original-C differential and all Rust-static links cover the swap. No behavior change; Tier 4 inapplicable. |
| `libobs/obs-encoder-metadata-getters.c.h` (extracted from `obs-encoder.c.h`) | `obs-output::encoder_metadata` | Five public instance metadata getters: codec/type from current info, ID/type data/caps from original info. No intended differences: NULL defaults and exact diagnostics, borrowed pointer identity, full-width caps, no locks, reference changes or plugin callbacks. Private field-pointer seam avoids mirroring the encoder layout; real-header view/enum layout checks, exact differential parity and unchanged actual-library `test_encoder_metadata_getters` cover both libraries. |
| `libobs/obs-encoder-dimensions.c.h` | `obs-output::encoder_dimensions` | Public `obs_encoder_get_width` and `obs_encoder_get_height` swapped in hybrid libobs (group `libobs.ported-encoder-dimensions`). Reuses `encoder_size::video_size_route`; preserves NULL debug logs, wrong-type warnings including the encoder name, media absence before stored axes, independent full-width scaled axes and lazy video fallback. A borrowed field-address adapter keeps the private encoder layout in C. `test_encoder_dimensions` characterizes actual libraries and remains unchanged after its C-only commit. Tier 1 mirrors its assertions; real-header checks cover every view field and encoder type layout. Tier 3 compares both getters, full diagnostics and whole-encoder immutability for edges and randomized fields, using callbacks for media reads and the oracle C size helper. No intentional behavior differences. Tier 4 is inapplicable. |
| `libobs/obs-encoder-group-lifecycle.c.h` | `obs-output::encoder_group_lifecycle` | Encoder-group allocation, deferred destruction and ordered locked teardown swapped in hybrid libobs. Native allocation, private fields and mutex primitives stay behind C adapters; the safe core clears each encoder back-pointer before releasing its reference, frees the list, unlocks and destroys the mutex, then frees the group. Tier 1 mirrors the source characterization; real-header view layout and bounded randomized C/Rust operation traces include init failure and the locked stop-path handoff. Actual-library Tier 2 checks zero initialization, deferred requests, back-pointers and strong-reference ownership. No intentional differences; Tier 4 is inapplicable. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ target_link_libraries(with_shared PRIVATE OBS::libobs)
target_link_libraries(reference PRIVATE OBS::libobs)
include("{root}/test/cmocka/tests.d/video_info_query_link_support.cmake")
function(check_support)
get_target_property(adapter_sources video_info_query_link_support SOURCES)
foreach(adapter IN ITEMS encoder-video-tex-active-fields encoder-video-tex-active-mix)
if(NOT "{root}/test/cmocka/${{adapter}}-link-support.c" IN_LIST adapter_sources)
message(FATAL_ERROR "missing real encoder adapter source: ${{adapter}}")
endif()
endforeach()
foreach(name IN ITEMS standalone with_shared future_consumer reference)
get_target_property(links ${{name}} LINK_LIBRARIES)
if(name STREQUAL "reference")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"schema": 1,
"targets": {
"test_encoder_video_tex_active_rust": {
"sources": [
"test/cmocka/test_encoder_video_tex_active.c",
"test/cmocka/encoder-video-tex-active-fields-link-support.c"
],
"definitions": [
"get_mix_for_video=tex_active_recording_mix_lookup",
"obs_encoder_video_tex_active=obs_encoder_video_tex_active_rust"
],
"libraries": [
"libobs_rust-static",
"OBS::libobs",
"OBS::caption",
"Uthash::Uthash",
"OBS::native-test-cmocka",
{
"name": "OBS::w32-pthreads",
"requires": "OS_WINDOWS"
}
],
"includes": [
".",
"libobs"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
},
"tests": {
"test_encoder_video_tex_active_rust": {
"target": "test_encoder_video_tex_active_rust",
"command": [
"${target}"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
encoder-video-tex-active-mix.inc|libobs/obs-encoder-video-tex-active-mix.c.h|auto
1 change: 1 addition & 0 deletions rust/obs-c-oracle/oracle.d/encoder-video-tex-active.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
encoder-video-tex-active.inc|libobs/obs-encoder-video-tex-active.c.h|auto
131 changes: 131 additions & 0 deletions rust/obs-c-oracle/oracle/encoder_video_tex_active.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* Original query, unchanged mutex walk and real private field adapters. */
#include <stdlib.h>
#include <string.h>
#include "obs-internal.h"

struct encoder_tex_fixture {
struct obs_core *core;
video_t *media;
bool flags[3][2];
unsigned lookups;
bool lookup_ok;
};
#if defined(_MSC_VER)
#define ENCODER_TEX_THREAD_LOCAL __declspec(thread)
#else
#define ENCODER_TEX_THREAD_LOCAL __thread
#endif
static ENCODER_TEX_THREAD_LOCAL struct encoder_tex_fixture *encoder_tex_current;
#undef ENCODER_TEX_THREAD_LOCAL

#define obs (encoder_tex_current->core)
struct obs_core_video_mix *oracle_encoder_tex_mix_walk(video_t *video);
#define get_mix_for_video oracle_encoder_tex_mix_walk
#include "encoder-video-tex-active-mix.inc"
#undef get_mix_for_video
#undef obs

static struct obs_core_video_mix *encoder_tex_lookup(video_t *video)
{
struct encoder_tex_fixture *fixture = encoder_tex_current;
fixture->lookups++;
fixture->lookup_ok = fixture->lookup_ok && video == fixture->media;
struct obs_core_video_mix *selected = oracle_encoder_tex_mix_walk(video);
for (size_t i = 0; i < fixture->core->video.mixes.num; i++) {
struct obs_core_video_mix *mix = fixture->core->video.mixes.array[i];
if (mix == selected) {
mix->using_nv12_tex = fixture->flags[i][0];
mix->using_p010_tex = fixture->flags[i][1];
break;
}
}
return selected;
}

#define get_mix_for_video encoder_tex_lookup
bool oracle_encoder_video_tex_active(const obs_encoder_t *encoder, enum video_format format);
#define obs_encoder_video_tex_active oracle_encoder_video_tex_active
#include "encoder-video-tex-active.inc"
#undef obs_encoder_video_tex_active
#include "encoder-video-tex-active-fields.inc"
#undef get_mix_for_video

void oracle_encoder_tex_format_values(int *values);
void oracle_encoder_tex_format_values(int *values)
{
values[0] = VIDEO_FORMAT_NV12;
values[1] = VIDEO_FORMAT_P010;
values[2] = VIDEO_FORMAT_R10L;
}

typedef bool (*encoder_tex_query)(const obs_encoder_t *, enum video_format);
bool oracle_encoder_tex_check(encoder_tex_query candidate, int format, uint8_t media, uint8_t mask,
const uint8_t *videos, const uint8_t *flags);
bool oracle_encoder_tex_check(encoder_tex_query candidate, int format, uint8_t media, uint8_t mask,
const uint8_t *videos, const uint8_t *flags)
{
struct obs_core *core = calloc(1, sizeof(*core));
struct obs_core *before = malloc(sizeof(*core));
struct obs_core *after = malloc(sizeof(*core));
if (!core || !before || !after) {
free(core);
free(before);
free(after);
return false;
}
if (pthread_mutex_init(&core->video.mixes_mutex, NULL) != 0) {
free(core);
free(before);
free(after);
return false;
}
unsigned char tokens[3] = {11, 22, 33};
video_t *identities[] = {NULL, (video_t *)&tokens[0], (video_t *)&tokens[1], (video_t *)&tokens[2]};
struct obs_encoder encoder = {0}, encoder_before;
struct obs_core_video_mix mixes[3] = {0}, initial[3], c_after[3];
struct obs_core_video_mix *pointers[3] = {0};
struct encoder_tex_fixture fixture = {.core = core, .media = identities[media % 4], .lookup_ok = true};
encoder.media = fixture.media;
memcpy(&encoder_before, &encoder, sizeof(encoder));
for (unsigned i = 0; i < 3; i++) {
mixes[i].video = identities[videos[i] % 4];
/* Only a matching lookup changes these to the requested values. */
mixes[i].using_nv12_tex = !(flags[i] & 1);
mixes[i].using_p010_tex = !(flags[i] & 2);
if (mask & (1u << i)) {
size_t slot = core->video.mixes.num++;
pointers[slot] = &mixes[i];
fixture.flags[slot][0] = (flags[i] & 1) != 0;
fixture.flags[slot][1] = (flags[i] & 2) != 0;
}
}
core->video.mixes.array = pointers;
core->video.mixes.capacity = 3;
memcpy(initial, mixes, sizeof(mixes));
memcpy(before, core, sizeof(*core));
/* Mutex internals may change on any platform; compare all other storage. */
memset(&before->video.mixes_mutex, 0, sizeof(before->video.mixes_mutex));
encoder_tex_current = &fixture;
bool c = oracle_encoder_video_tex_active(&encoder, (enum video_format)format);
bool equal = fixture.lookups == 1 && fixture.lookup_ok;
memcpy(c_after, mixes, sizeof(mixes));
memcpy(mixes, initial, sizeof(mixes));
fixture.lookups = 0;
fixture.lookup_ok = true;
bool rust = candidate(&encoder, (enum video_format)format);
equal = equal && c == rust && fixture.lookups == 1 && fixture.lookup_ok &&
memcmp(&encoder, &encoder_before, sizeof(encoder)) == 0 && memcmp(mixes, c_after, sizeof(mixes)) == 0;
memcpy(after, core, sizeof(*core));
memset(&after->video.mixes_mutex, 0, sizeof(after->video.mixes_mutex));
equal = equal && memcmp(before, after, sizeof(*core)) == 0;
int locked = pthread_mutex_trylock(&core->video.mixes_mutex);
equal = equal && locked == 0;
if (locked == 0)
pthread_mutex_unlock(&core->video.mixes_mutex);
encoder_tex_current = NULL;
pthread_mutex_destroy(&core->video.mixes_mutex);
free(after);
free(before);
free(core);
return equal;
}
1 change: 1 addition & 0 deletions rust/obs-encoder/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod last_error;
pub mod media_getters;
pub mod packet_ownership;
pub mod type_info;
pub mod video_tex_active;
52 changes: 52 additions & 0 deletions rust/obs-encoder/src/ffi/video_tex_active.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! Borrow opaque C owners; never reproduce the encoder or mix layout in Rust.
use core::ffi::{c_int, c_void};
use core::ptr::NonNull;

unsafe extern "C" {
fn obs_encoder_video_tex_active_mix(encoder: *const c_void) -> *const c_void;
fn obs_encoder_video_tex_active_nv12(mix: *const c_void) -> bool;
fn obs_encoder_video_tex_active_p010(mix: *const c_void) -> bool;
}

/// # Safety
/// As in C, the encoder and OBS core must be live and synchronized, and the
/// selected mix must remain readable through the query. NULL encoder is outside
/// the C API's contract; NULL media and an absent mix are valid.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn obs_encoder_video_tex_active(
encoder: *const c_void,
format: c_int,
) -> bool {
// SAFETY: the private entry has the same ownership contract as this API.
unsafe { obs_encoder_video_tex_active_rust(encoder, format) }
}

/// Private static-link entry: shared libobs must never satisfy a fixture's
/// Rust query before its archive member is selected (notably with frameworks).
///
/// # Safety
/// Identical live-encoder/core/mix contract to obs_encoder_video_tex_active.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn obs_encoder_video_tex_active_rust(
encoder: *const c_void,
format: c_int,
) -> bool {
// Reject an invalid owner before the C adapter can project encoder->media.
let encoder = NonNull::new(encoder.cast_mut()).expect("the C API requires a live encoder");
crate::video_tex_active::video_tex_active(
format,
|| {
// SAFETY: the owner was checked above; C retains the synchronized
// get_mix_for_video walk and reads the real encoder media field.
NonNull::new(unsafe { obs_encoder_video_tex_active_mix(encoder.as_ptr()) }.cast_mut())
},
|mix| {
// SAFETY: the safe core selects only a present mix and the NV12 flag.
unsafe { obs_encoder_video_tex_active_nv12(mix.as_ptr()) }
},
|mix| {
// SAFETY: the safe core selects only a present mix and the P010 flag.
unsafe { obs_encoder_video_tex_active_p010(mix.as_ptr()) }
},
)
}
1 change: 1 addition & 0 deletions rust/obs-encoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod last_error;
pub mod media_getters;
pub mod packet_ownership;
pub mod type_info;
pub mod video_tex_active;
21 changes: 21 additions & 0 deletions rust/obs-encoder/src/video_tex_active.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Query C-owned texture-input state after the synchronized mix lookup.

pub const NV12: i32 = 2;
pub const P010: i32 = 18;

/// Look up exactly once, then read only the flag matching the requested format.
pub fn video_tex_active<M>(
format: i32,
lookup: impl FnOnce() -> Option<M>,
nv12: impl FnOnce(M) -> bool,
p010: impl FnOnce(M) -> bool,
) -> bool {
let Some(mix) = lookup() else {
return false;
};
match format {
NV12 => nv12(mix),
P010 => p010(mix),
_ => false,
}
}
2 changes: 2 additions & 0 deletions rust/obs-encoder/tests/encoder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ mod encoder_module;
mod encoder_module_parity;
mod type_info;
mod type_info_parity;
mod video_tex_active;
mod video_tex_active_parity;
Loading
Loading