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
6 changes: 4 additions & 2 deletions ci/test_bench_libobs_stand_ins.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
# The encoder name getter is absent too: #5253 exports it from obs-encoder;
# the synthetic interleaver replaces only its private name seam.
# The key-name store is absent: #5321 exports it from obs-hotkey (hidden in
# libobs, defined by the workspace).
# libobs, defined by the workspace). The output name getter is absent as
# well: #5302 exports it from obs-output, and the interleaver names its
# output through a private seam too.
SYMBOLS = (
"obs_encoder_group_num_started",
"obs_encoder_interleave_info",
Expand Down Expand Up @@ -68,14 +70,14 @@
"obs_output_caption_track_fields",
"obs_output_delay_fields",
"obs_output_delay_signal",
"obs_output_get_name",
"obs_output_initialize_encoders",
"obs_output_interleave_active",
"obs_output_interleave_add_caption",
"obs_output_interleave_encoder_name",
"obs_output_interleave_fields",
"obs_output_interleave_first_audio_encoder_index",
"obs_output_interleave_first_video_encoder_index",
"obs_output_interleave_output_name",
)


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 @@ -52,7 +52,7 @@
#include "libobs/obs-output-enum-types-with-protocol.c.h"
#include "libobs/obs-output-flags-fields.c.h"
#include "libobs/obs-output-frames-dropped-fields.c.h"
#include "libobs/obs-output-get-name.c.h"
#include "libobs/obs-output-get-name-fields.c.h"
#include "libobs/obs-output-handler-getters-fields.c.h"
#include "libobs/obs-output-identity-fields.c.h"
#include "libobs/obs-output-interleave-name-fields.c.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-output-get-name+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): original output name getter, C reference only. */

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

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

const char *obs_output_get_name_context_name(const obs_output_t *output);

const char *obs_output_get_name_context_name(const obs_output_t *output)
{
return output->context.name;
}
11 changes: 9 additions & 2 deletions libobs/obs-output-interleave-name-fields.c.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include "libobs/build/libobs.pch.h"

/* A private seam lets synthetic interleaver fixtures supply their own names
* without replacing the public encoder getter or its native-layout projection. */
/* Private seams let synthetic interleaver fixtures supply their own names
* without replacing the public output and encoder getters or their
* native-layout projections. */
const char *obs_output_interleave_encoder_name(const obs_encoder_t *encoder);
const char *obs_output_interleave_output_name(const obs_output_t *output);

const char *obs_output_interleave_encoder_name(const obs_encoder_t *encoder)
{
return obs_encoder_get_name(encoder);
}

const char *obs_output_interleave_output_name(const obs_output_t *output)
{
return obs_output_get_name(output);
}
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-output-protocol-getter.c.h` | `obs-output::output_protocols` | Public borrowed protocol metadata getter swapped in hybrid libobs (#4062). Preserves service flags, NULL diagnostics, missing/empty and arbitrary-byte metadata, pointer identity and unchanged state. Real-header layout, Tier 1, differential mutation coverage and unchanged actual-library Tier 2. No intentional differences. |
| `libobs/obs-output-set-last-error.c.h` | `obs-output::output_last_error` | Public error setter with a private writable-slot adapter. Preserves NULL diagnostics, replacement/clearing and empty or arbitrary-byte strings using libobs allocator ownership. Tier 1 mirrors existing C characterization; Tier 3 compares replacement sequences and untouched output state. Aliasing the old allocation is excluded as undefined in C. |
| `libobs/obs-output-get-last-error.c.h` | `obs-output::output_get_last_error` | Swapped in hybrid `libobs` (group `libobs.ported-output-get-last-error` keeps the original for the C reference). After `obs_output_valid()`'s exact NULL diagnostic, safe Rust returns the output's own `last_error_message`, else the first error of the video encoder slots in ascending order, else of the audio slots, else NULL. Each field is read lazily, so nothing below a hit is read; the pointer is borrowed unchanged (empty and non-UTF-8 strings included), with no copy, cache, reference or lock. Reads go through the existing production adapters (`obs-output-last-error-fields`, `obs-output-video-encoder-getter-fields`, `obs-output-encoder-getters-fields`, `obs-encoder-last-error-fields`), no new layout crosses the ABI. Tier 1 mirrors every assertion of the unchanged `test_output_get_last_error` with read-order traces; Tier 3 compares the original and the shim on real-layout output/encoder fixtures (identity, untouched state, NULL diagnostic, no allocation), checks each adapter addresses the original's field, and catches five mutants. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-output-get-name.c.h` | `obs-output::output_get_name` | Swapped in hybrid `libobs` (group `libobs.ported-output-get-name` keeps the original for the C reference). After `obs_output_valid()`'s exact NULL diagnostic, safe Rust returns the output's borrowed `context.name` pointer, read once through the private `obs-output-get-name-fields` adapter: no copy, cache, reference or lock, and NULL, empty and non-UTF-8 names unchanged. The interleaver names its output through the private `obs_output_interleave_output_name` seam, so its synthetic fixture no longer defines the public getter. Tier 1 mirrors every case of the unchanged `test_output_get_name`; Tier 3 compares the original and the shim on a real-layout output (identity, repeated and renamed reads, exact NULL log, untouched bytes), checks the adapter addresses the original's field, and catches four mutants. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-output-supported-codecs.c.h` | `obs-output::output_supported_codecs` | Public borrowed video/audio codec metadata getters swapped in hybrid libobs (#3958). Preserves NULL diagnostics, absent/empty and arbitrary-byte metadata, pointer identity and unchanged output state. Private field-address adapter with real-header layout checks, Tier 1, differential mutation coverage and unchanged actual-library Tier 2. No intentional differences. |
| `libobs/obs-output-size-getters.c.h` | `obs-output::output_size_getters` | Width/height and indexed wrappers through opaque private accessors. Preserves NULL/non-video diagnostics before bounds checks, encoder versus video fallback, independent scaled axes and unchanged output state. Tier 1 and original-C differential coverage; unchanged Tier 2 characterization. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-output-type-info.c.h` | `obs-output::output_type_info` | #4678: borrowed type display name, exact flag bits and raw supported codec pointers through the shared existing output-type lookup. Real-header snapshots, Tier 1 characterization, original-C differential/mutation checks and unchanged Tier 2 replay. No intentional differences; Tier 4 inapplicable. |
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 @@ -391,6 +391,8 @@ mod canonical_object_validity_query_is_registered;
mod canonical_output_flags_is_registered;
#[path = "native/registration/canonical_output_get_last_error_swap_is_registered.rs"]
mod canonical_output_get_last_error_swap_is_registered;
#[path = "native/registration/canonical_output_get_name_swap_is_registered.rs"]
mod canonical_output_get_name_swap_is_registered;
#[path = "native/registration/canonical_output_handler_getters_is_registered.rs"]
mod canonical_output_handler_getters_is_registered;
#[path = "native/registration/canonical_output_identity_getters_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use super::*;

#[test]
fn canonical_output_get_name_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_output_get_name";
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();
assert!(
matches!(selected.targets[name].sources.as_slice(), [Source::Path(path)]
if path == "test/cmocka/test_output_get_name.c")
);
assert_eq!(selected.tests[name].target, name);
}
let ported =
fs::read_to_string(root.join("libobs/build/ported-source-sets/output-get-name.json"))
.unwrap();
assert!(ported.contains("build/libobs.ported-output-get-name+.h.c"));
let original = "#include \"libobs/obs-output-get-name.c.h\"";
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-output-get-name+.h.c")).unwrap();
assert!(group.contains(original));
let hybrid = fs::read_to_string(root.join("libobs/build/libobs.core-output+.h.c")).unwrap();
assert!(!hybrid.contains(original));
// The context-name adapter and the interleaver's name seams stay in the core.
for adapter in [
"obs-output-get-name-fields.c.h",
"obs-output-interleave-name-fields.c.h",
] {
assert!(hybrid.contains(&format!("#include \"libobs/{adapter}\"")));
}
let support =
fs::read_to_string(root.join("test/cmocka/build/rust-static-support.json")).unwrap();
assert!(support.contains("\"test/cmocka/output-get-name-link-support.c\""));
let exports =
fs::read_to_string(root.join("libobs/cmake/rust-exports.d/obs-output-output_get_name.txt"))
.unwrap();
assert_eq!(exports.lines().collect::<Vec<_>>(), ["obs_output_get_name"]);
}
4 changes: 2 additions & 2 deletions rust/obs-c-oracle/benches/port_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ mod libobs_stand_ins {
}

#[unsafe(no_mangle)]
pub extern "C" fn obs_output_get_name() -> ! {
called("obs_output_get_name")
pub extern "C" fn obs_output_interleave_output_name() -> ! {
called("obs_output_interleave_output_name")
}

#[unsafe(no_mangle)]
Expand Down
98 changes: 98 additions & 0 deletions rust/obs-c-oracle/oracle/output_get_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* Original output name getter and its production context-name adapter, over
* the real private output layout.
*
* The MSVC UCRT headers define snprintf and friends inline in every object
* that includes them, which lets a COFF link pull this member into an
* unrelated test. _NO_CRT_STDIO_INLINE keeps them declarations only, and the
* log capture below reads its arguments without formatting them. */
#define _NO_CRT_STDIO_INLINE
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#define obs_output_get_name oracle_obs_output_get_name
#include "obs-output-get-name.c.h"
#undef obs_output_get_name
#include "obs-output-get-name-fields.c.h"

struct ogn_log {
unsigned count;
int level;
const char *format;
const char *function;
const char *parameter;
};

static void ogn_capture(int level, const char *format, va_list args, void *param)
{
struct ogn_log *log = param;
log->count++;
log->level = level;
log->format = format;
log->function = va_arg(args, const char *);
log->parameter = va_arg(args, const char *);
}

static bool ogn_exact_null_log(const struct ogn_log *log)
{
return log->count == 1 && log->level == LOG_DEBUG && strcmp(log->format, "%s: Null '%s' parameter") == 0 &&
strcmp(log->function, "obs_output_get_name") == 0 && strcmp(log->parameter, "output") == 0;
}

typedef const char *(*output_name_getter)(const obs_output_t *output);

/* The original runs on one capture and the candidate on another: same
* borrowed pointer, and either no log (a live output) or exactly
* obs_output_valid()'s diagnostic (NULL). */
static bool ogn_compare(const obs_output_t *output, output_name_getter candidate)
{
struct ogn_log original = {0}, rust = {0};
base_set_log_handler(ogn_capture, &original);
const char *expected = oracle_obs_output_get_name(output);
base_set_log_handler(ogn_capture, &rust);
const char *actual = candidate(output);
if (actual != expected)
return false;
if (output)
return original.count == 0 && rust.count == 0;
return !actual && ogn_exact_null_log(&original) && ogn_exact_null_log(&rust);
}

static bool ogn_copy(char *dst, size_t size, const char *src)
{
size_t len = strlen(src);
if (len >= size)
return false;
memcpy(dst, src, len + 1);
return true;
}

/* NULL, then a live real-layout output read twice, then the same output
* after its context-name slot changes. The output's bytes must be untouched
* by every read, and the production adapter must address the original's
* field. */
bool oracle_output_get_name_probe(output_name_getter candidate, const char *name, const char *renamed, bool null_name);
bool oracle_output_get_name_probe(output_name_getter candidate, const char *name, const char *renamed, bool null_name)
{
log_handler_t saved_handler;
void *saved_param;
char first[256], second[256];
if (!ogn_copy(first, sizeof(first), name) || !ogn_copy(second, sizeof(second), renamed))
return false;

base_get_log_handler(&saved_handler, &saved_param);
static struct obs_output output;
memset(&output, 0, sizeof(output));
output.context.name = null_name ? NULL : first;
static unsigned char before[sizeof(output)];
memcpy(before, &output, sizeof(output));
bool equal = ogn_compare(NULL, candidate) && ogn_compare(&output, candidate) &&
ogn_compare(&output, candidate) && memcmp(before, &output, sizeof(output)) == 0 &&
obs_output_get_name_context_name(&output) == output.context.name;
output.context.name = second;
memcpy(before, &output, sizeof(output));
equal = equal && ogn_compare(&output, candidate) && memcmp(before, &output, sizeof(output)) == 0 &&
obs_output_get_name_context_name(&output) == second;
base_set_log_handler(saved_handler, saved_param);
return equal;
}
14 changes: 8 additions & 6 deletions rust/obs-c-oracle/oracle/output_interleave.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* obs_encoder_interleave_info() and obs_encoder_group_num_started(), the
* obs-output.c wrappers (obs_output_interleave_active(), the two first
* encoder index helpers and obs_output_interleave_add_caption()),
* obs_encoder_packet_create_instance() and _release(), obs_output_get_name()
* and the private obs_output_interleave_encoder_name() seam. The cargo test that links this file defines
* them, recording each call, and the Rust shim calls the same ones, so both
* sides are seen through the same stubs; the packet copy and release are
* obs-encoder's real exports. pthread, blog and the darray come from the
* real headers and libraries. */
* obs_encoder_packet_create_instance() and _release(), and the private
* obs_output_interleave_output_name() and _encoder_name() seams. The cargo
* test that links this file defines them, recording each call, and the Rust
* shim calls the same ones, so both sides are seen through the same stubs;
* the packet copy and release are obs-encoder's real exports. pthread, blog
* and the darray come from the real headers and libraries. */
/* As libobs is built for release (RelWithDebInfo defines NDEBUG): the
* file's asserts and those of the darray.h inlines it calls are off. One of
* them is reachable: discard_to_idx() pops the packet time of each video
Expand All @@ -31,6 +31,7 @@
#define free_packets oracle_free_packets
#define os_gettime_ns oracle_output_interleave_clock_ns
#define obs_encoder_get_name obs_output_interleave_encoder_name
#define obs_output_get_name obs_output_interleave_output_name

/* send_interleaved() names itself with __FUNCTION__, a GCC, Clang and MSVC
* extension that -Wpedantic rejects, and the file converts between signed
Expand All @@ -48,6 +49,7 @@
#endif
#include "obs-output-interleave.c.h"
#undef obs_encoder_get_name
#undef obs_output_get_name
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
Expand Down
1 change: 1 addition & 0 deletions rust/obs-output/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub mod output_congestion;
pub mod output_delay;
pub mod output_flags;
pub mod output_get_last_error;
pub mod output_get_name;
pub mod output_handler_getters;
pub mod output_identity;
pub mod output_interleave;
Expand Down
37 changes: 37 additions & 0 deletions rust/obs-output/src/ffi/output_get_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! The public output name query over the real private context-name field.
//! The NULL guard lives in the safe core; the field read sits behind a
//! private C adapter, so no output layout crosses the ABI.
use crate::output_get_name::get_name;
use core::ffi::{c_char, c_int, c_void};

unsafe extern "C" {
fn obs_output_get_name_context_name(output: *const c_void) -> *const c_char;
fn blog(level: c_int, format: *const c_char, ...);
}

/// Borrow the output's current context name, or NULL for a NULL output.
///
/// # Safety
/// A non-NULL output must be live and readable during the call. The result
/// borrows its C-owned name, as in C.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn obs_output_get_name(output: *const c_void) -> *const c_char {
get_name(
(!output.is_null()).then_some(|| {
// SAFETY: get_name projects only a non-NULL, live output.
unsafe { obs_output_get_name_context_name(output) }
}),
|| {
// SAFETY: obs_output_valid()'s static format and arguments.
unsafe {
blog(
400,
c"%s: Null '%s' parameter".as_ptr(),
c"obs_output_get_name".as_ptr(),
c"output".as_ptr(),
)
}
},
)
.unwrap_or(core::ptr::null())
}
5 changes: 3 additions & 2 deletions rust/obs-output/src/ffi/output_interleave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ unsafe extern "C" {
fn obs_encoder_packet_create_instance(dst: *mut encoder_packet, src: *const encoder_packet);
// EXPORT.
fn obs_encoder_packet_release(packet: *mut encoder_packet);
fn obs_output_get_name(output: *const c_void) -> *const c_char;
// Private C adapter; synthetic tests replace only this seam.
fn obs_output_interleave_output_name(output: *const c_void) -> *const c_char;
// Private C adapter; synthetic tests replace only this seam.
fn obs_output_interleave_encoder_name(encoder: *const c_void) -> *const c_char;
// libobs's pthread (w32-pthreads on Windows); the mutexes are opaque here.
Expand Down Expand Up @@ -893,7 +894,7 @@ impl InterleaveOutput for COutput {
LOG_WARNING,
c"obs-output '%s': Missing keyframe with pts %lld for encoder '%s' (track: %zu)"
.as_ptr(),
obs_output_get_name(self.output),
obs_output_interleave_output_name(self.output),
pts as c_longlong,
obs_output_interleave_encoder_name(encoder as *const c_void),
track,
Expand Down
1 change: 1 addition & 0 deletions rust/obs-output/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub mod output_caption_queue;
pub mod output_congestion;
pub mod output_flags;
pub mod output_get_last_error;
pub mod output_get_name;
pub mod output_handler_getters;
pub mod output_identity;
pub mod output_last_error;
Expand Down
29 changes: 29 additions & 0 deletions rust/obs-output/src/output_get_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Safe core of `libobs/obs-output-get-name.c.h`: `obs_output_get_name()`
//! borrows the output's current context name.
//!
//! A missing output emits `obs_output_valid()`'s diagnostic and reads
//! nothing. A present output's name is projected exactly once and returned
//! unchanged, NULL, empty and non-UTF-8 names included: no copy, cache,
//! reference or lock.

#![deny(
clippy::arithmetic_side_effects,
clippy::as_conversions,
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::todo,
clippy::unimplemented,
clippy::unreachable
)]

/// `None` is the NULL output: `log_null` runs once and nothing is read.
/// Otherwise `project` reads the live output's name once.
pub fn get_name<T>(output: Option<impl FnOnce() -> T>, log_null: impl FnOnce()) -> Option<T> {
let Some(project) = output else {
log_null();
return None;
};
Some(project())
}
Loading
Loading