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: 0 additions & 1 deletion libobs/build/libobs.core-output+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#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-last-error.c.h"
#include "libobs/obs-output-get-name.c.h"
#include "libobs/obs-output-handler-getters-fields.c.h"
#include "libobs/obs-output-identity-fields.c.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-output-get-last-error+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): original output last-error query, C reference only. */

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

#include "libobs/obs-output-get-last-error.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/output-get-last-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-output-get-last-error+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_output_get_last_error
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `libobs/obs-output-properties.c.h` | `obs-output::output_properties` | Output defaults and type/instance properties (#4300), through opaque callback/context snapshots. Preserves NULL type callback data, instance settings application, temporary defaults release and optional callbacks. Tier 1 mirrors C characterization; Tier 3 compares callback/settings traces and allocation balance. |
| `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-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 @@ -385,6 +385,8 @@ mod canonical_object_queries_is_registered;
mod canonical_object_validity_query_is_registered;
#[path = "native/registration/canonical_output_flags_is_registered.rs"]
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_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,47 @@
use super::*;

#[test]
fn canonical_output_get_last_error_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_last_error";
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_last_error.c")
);
assert_eq!(selected.tests[name].target, name);
}
let ported =
fs::read_to_string(root.join("libobs/build/ported-source-sets/output-get-last-error.json"))
.unwrap();
assert!(ported.contains("build/libobs.ported-output-get-last-error+.h.c"));
let original = "#include \"libobs/obs-output-get-last-error.c.h\"";
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-output-get-last-error+.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 production adapters the Rust query reads through stay in the core.
for adapter in [
"obs-output-last-error-fields.c.h",
"obs-output-video-encoder-getter-fields.c.h",
"obs-output-encoder-getters-fields.c.h",
"obs-encoder-last-error-fields.c.h",
] {
assert!(hybrid.contains(&format!("#include \"libobs/{adapter}\"")));
}
let exports = fs::read_to_string(
root.join("libobs/cmake/rust-exports.d/obs-output-output_get_last_error.txt"),
)
.unwrap();
assert_eq!(
exports.lines().collect::<Vec<_>>(),
["obs_output_get_last_error"]
);
}
182 changes: 182 additions & 0 deletions rust/obs-c-oracle/oracle/output_get_last_error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/* Original output last-error query over the real private output and encoder
* layouts. The field adapters it is compared through are the production ones
* of their own oracles (output_last_error.c, output_video_encoder_getter.c,
* output_encoder_getters.c, encoder_last_error.c).
*
* 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 <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define obs_output_get_last_error oracle_obs_output_get_last_error
#include "obs-output-get-last-error.c.h"
#undef obs_output_get_last_error

/* Defined by the production adapters of the oracles named above. */
obs_encoder_t *obs_output_video_encoder_getter_at(const obs_output_t *output, size_t idx);
obs_encoder_t *obs_output_encoder_getters_audio_at(const obs_output_t *output, size_t idx);

#define OGLE_VIDEO MAX_OUTPUT_VIDEO_ENCODERS
#define OGLE_AUDIO MAX_OUTPUT_AUDIO_ENCODERS
/* The output's own error, then each video, then each audio encoder's. */
#define OGLE_FIELDS (1 + OGLE_VIDEO + OGLE_AUDIO)

enum ogle_kind { OGLE_NULL, OGLE_SAME, OGLE_EMPTY, OGLE_BYTES, OGLE_KINDS };

struct output_get_last_error_fixture {
struct obs_output output;
struct obs_encoder video[OGLE_VIDEO];
struct obs_encoder audio[OGLE_AUDIO];
struct obs_output output_before;
struct obs_encoder video_before[OGLE_VIDEO];
struct obs_encoder audio_before[OGLE_AUDIO];
/* Independent storage: equal bytes never share an address. */
char messages[OGLE_FIELDS][16];
char messages_before[OGLE_FIELDS][16];
};

static char *ogle_message(struct output_get_last_error_fixture *f, size_t field, uint8_t kind)
{
static const char bytes[] = "\xff\x80x";
switch (kind % OGLE_KINDS) {
case OGLE_SAME:
memcpy(f->messages[field], "same error", sizeof("same error"));
return f->messages[field];
case OGLE_EMPTY:
return f->messages[field];
case OGLE_BYTES:
memcpy(f->messages[field], bytes, sizeof(bytes));
return f->messages[field];
default:
return NULL;
}
}

/* kinds[OGLE_FIELDS]; bit i of a mask attaches that slot's encoder. Detached
* encoders keep their errors, which the query must never reach. */
void *oracle_output_get_last_error_new(const uint8_t *kinds, uint32_t video, uint32_t audio);
void *oracle_output_get_last_error_new(const uint8_t *kinds, uint32_t video, uint32_t audio)
{
struct output_get_last_error_fixture *f = calloc(1, sizeof(*f));
if (!f)
return NULL;
f->output.context.name = "last-error output";
f->output.mixer_mask = UINT32_C(0x80000001);
f->output.last_error_message = ogle_message(f, 0, kinds[0]);
for (size_t i = 0; i < OGLE_VIDEO; i++) {
f->video[i].context.name = "video";
f->video[i].last_error_message = ogle_message(f, 1 + i, kinds[1 + i]);
f->output.video_encoders[i] = (video >> i) & 1 ? &f->video[i] : NULL;
}
for (size_t i = 0; i < OGLE_AUDIO; i++) {
f->audio[i].context.name = "audio";
f->audio[i].last_error_message = ogle_message(f, 1 + OGLE_VIDEO + i, kinds[1 + OGLE_VIDEO + i]);
f->output.audio_encoders[i] = (audio >> i) & 1 ? &f->audio[i] : NULL;
}
memcpy(&f->output_before, &f->output, sizeof(f->output));
memcpy(f->video_before, f->video, sizeof(f->video));
memcpy(f->audio_before, f->audio, sizeof(f->audio));
memcpy(f->messages_before, f->messages, sizeof(f->messages));
return f;
}

/* The storage of one field's message, whatever its kind. */
const char *oracle_output_get_last_error_storage(const void *fixture, size_t field);
const char *oracle_output_get_last_error_storage(const void *fixture, size_t field)
{
const struct output_get_last_error_fixture *f = fixture;
return field < OGLE_FIELDS ? f->messages[field] : NULL;
}

bool oracle_output_get_last_error_unchanged(const void *fixture);
bool oracle_output_get_last_error_unchanged(const void *fixture)
{
const struct output_get_last_error_fixture *f = fixture;
return memcmp(&f->output, &f->output_before, sizeof(f->output)) == 0 &&
memcmp(f->video, f->video_before, sizeof(f->video)) == 0 &&
memcmp(f->audio, f->audio_before, sizeof(f->audio)) == 0 &&
memcmp(f->messages, f->messages_before, sizeof(f->messages)) == 0;
}

void oracle_output_get_last_error_free(void *fixture);
void oracle_output_get_last_error_free(void *fixture)
{
free(fixture);
}

/* The slot counts the Rust core walks. */
void oracle_output_get_last_error_layout(size_t *out);
void oracle_output_get_last_error_layout(size_t *out)
{
out[0] = MAX_OUTPUT_VIDEO_ENCODERS;
out[1] = MAX_OUTPUT_AUDIO_ENCODERS;
out[2] = OGLE_FIELDS;
}

/* Every adapter the Rust shim reads through addresses exactly the field the
* original reads, on the real private layouts. */
bool oracle_output_get_last_error_adapters(void *fixture);
bool oracle_output_get_last_error_adapters(void *fixture)
{
struct output_get_last_error_fixture *f = fixture;
bool ok = obs_output_last_error_fields(&f->output) == &f->output.last_error_message;
for (size_t i = 0; i < OGLE_VIDEO; i++) {
ok &= obs_output_video_encoder_getter_at(&f->output, i) == f->output.video_encoders[i];
ok &= obs_encoder_last_error_fields(&f->video[i]).message == &f->video[i].last_error_message;
}
for (size_t i = 0; i < OGLE_AUDIO; i++) {
ok &= obs_output_encoder_getters_audio_at(&f->output, i) == f->output.audio_encoders[i];
ok &= obs_encoder_last_error_fields(&f->audio[i]).message == &f->audio[i].last_error_message;
}
return ok;
}

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

static void ogle_capture(int level, const char *format, va_list args, void *param)
{
struct ogle_log *log = param;
log->count++;
log->level = level;
log->format = format;
/* obs_output_valid()'s two %s arguments, read without formatting. */
log->function = va_arg(args, const char *);
log->parameter = va_arg(args, const char *);
}

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

/* A NULL output: NULL, the exact diagnostic once, and no allocation. The
* original runs first on the same capture, so both sides are checked. */
typedef const char *(*output_get_last_error_getter)(obs_output_t *output);
bool oracle_output_get_last_error_null_log(output_get_last_error_getter getter);
bool oracle_output_get_last_error_null_log(output_get_last_error_getter getter)
{
log_handler_t old_handler;
void *old_param;
base_get_log_handler(&old_handler, &old_param);
struct ogle_log original = {0}, candidate = {0};
long allocations = bnum_allocs();
base_set_log_handler(ogle_capture, &original);
const char *original_result = oracle_obs_output_get_last_error(NULL);
base_set_log_handler(ogle_capture, &candidate);
const char *candidate_result = getter(NULL);
base_set_log_handler(old_handler, old_param);
return !original_result && !candidate_result && ogle_exact_null_log(&original) &&
ogle_exact_null_log(&candidate) && bnum_allocs() == allocations;
}
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 @@ -48,6 +48,7 @@ pub mod output_caption_text;
pub mod output_congestion;
pub mod output_delay;
pub mod output_flags;
pub mod output_get_last_error;
pub mod output_handler_getters;
pub mod output_identity;
pub mod output_interleave;
Expand Down
64 changes: 64 additions & 0 deletions rust/obs-output/src/ffi/output_get_last_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//! The public output last-error query over the real private C fields: the
//! existing output error slot, video and audio slot and encoder error
//! adapters. Validation and priority live in the safe core.
use crate::ffi::encoder_last_error::LastErrorFields as EncoderFields;
use crate::output_get_last_error::{LastErrorFields, last_error};
use core::ffi::{c_char, c_int, c_void};
use core::ptr::NonNull;

unsafe extern "C" {
fn obs_output_last_error_fields(output: *mut c_void) -> *mut *mut c_char;
fn obs_output_video_encoder_getter_at(output: *const c_void, idx: usize) -> *mut c_void;
fn obs_output_encoder_getters_audio_at(output: *const c_void, idx: usize) -> *mut c_void;
fn obs_encoder_last_error_fields(encoder: *mut c_void) -> EncoderFields;
fn blog(level: c_int, format: *const c_char, ...);
}

/// A non-NULL output the caller keeps live and readable.
struct Output(*mut c_void);
impl LastErrorFields for Output {
type Encoder = NonNull<c_void>;
type Error = NonNull<c_char>;
fn own(&mut self) -> Option<NonNull<c_char>> {
// SAFETY: the output is non-NULL and live; the adapter returns the
// address of its error field, which is only read here.
NonNull::new(unsafe { *obs_output_last_error_fields(self.0) })
}
fn video(&mut self, idx: usize) -> Option<NonNull<c_void>> {
// SAFETY: the core asks only below MAX_OUTPUT_VIDEO_ENCODERS.
NonNull::new(unsafe { obs_output_video_encoder_getter_at(self.0, idx) })
}
fn audio(&mut self, idx: usize) -> Option<NonNull<c_void>> {
// SAFETY: the core asks only below MAX_OUTPUT_AUDIO_ENCODERS.
NonNull::new(unsafe { obs_output_encoder_getters_audio_at(self.0, idx) })
}
fn encoder_error(&mut self, encoder: NonNull<c_void>) -> Option<NonNull<c_char>> {
// SAFETY: a slot of the live output holds this encoder; for a
// non-NULL encoder the adapter returns its error field's address.
let fields = unsafe { obs_encoder_last_error_fields(encoder.as_ptr()) };
// SAFETY: as above; the field is read without its mutex, as in C.
NonNull::new(unsafe { *fields.message }.cast_mut())
}
}

/// Borrow the output's error, else its first encoder error, else NULL.
///
/// # Safety
/// A non-NULL output and the encoders in its slots must be live and readable
/// during the call. The result borrows C-owned storage, as in C.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn obs_output_get_last_error(output: *mut c_void) -> *const c_char {
let mut fields = (!output.is_null()).then_some(Output(output));
let error = last_error(fields.as_mut(), || {
// SAFETY: obs_output_valid()'s static format and arguments.
unsafe {
blog(
400,
c"%s: Null '%s' parameter".as_ptr(),
c"obs_output_get_last_error".as_ptr(),
c"output".as_ptr(),
)
}
});
error.map_or(core::ptr::null(), |error| error.as_ptr().cast_const())
}
1 change: 1 addition & 0 deletions rust/obs-output/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub mod output_caption;
pub mod output_caption_queue;
pub mod output_congestion;
pub mod output_flags;
pub mod output_get_last_error;
pub mod output_handler_getters;
pub mod output_identity;
pub mod output_last_error;
Expand Down
Loading
Loading