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: 3 additions & 2 deletions ci/test_bench_libobs_stand_ins.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
# The key-name store is absent: #5321 exports it from obs-hotkey (hidden in
# 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.
# output through a private seam too. The encoder group started count is
# absent: #5319 exports it from obs-output, and the oracle defines its
# private adapters (oracle/encoder_group_num_started.c).
SYMBOLS = (
"obs_encoder_group_num_started",
"obs_encoder_interleave_info",
"obs_hotkey_binding_fields",
"obs_hotkey_identity_fields",
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 @@ -17,7 +17,7 @@
#include "libobs/obs-encoder-get-name-fields.c.h"
#include "libobs/obs-encoder-gpu-scaling-getters-fields.c.h"
#include "libobs/obs-encoder-group-lifecycle-fields.c.h"
#include "libobs/obs-encoder-group-num-started.c.h"
#include "libobs/obs-encoder-group-num-started-fields.c.h"
#include "libobs/obs-encoder-init-fields.c.h"
#include "libobs/obs-encoder-last-error-fields.c.h"
#include "libobs/obs-encoder-media-getters-fields.c.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-encoder-group-num-started+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): original encoder group started-count query, C reference only. */

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

#include "libobs/obs-encoder-group-num-started.c.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-encoder-group-num-started+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# obs-encoder-group-num-started.c: output interleaving and obs_encoder_set_group
# read a group's started-encoder count inside libobs. Declared in
# obs-internal.h without EXPORT, so the shim stays hidden the same way.
obs_encoder_group_num_started
24 changes: 24 additions & 0 deletions libobs/obs-encoder-group-num-started-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "libobs/build/libobs.pch.h"

/* Private adapters for the Rust obs_encoder_group_num_started(). The group's
* mutex and its num_encoders_started stay in C; Rust decides when each is
* used: the count is read once, between one lock and one unlock, as every
* writer (encoder start and stop, set-group) changes it under the same
* mutex. The group is never NULL here, as in the original. */
void obs_encoder_group_num_started_lock(struct obs_encoder_group *group);
void obs_encoder_group_num_started_lock(struct obs_encoder_group *group)
{
pthread_mutex_lock(&group->mutex);
}

uint32_t obs_encoder_group_num_started_read(const struct obs_encoder_group *group);
uint32_t obs_encoder_group_num_started_read(const struct obs_encoder_group *group)
{
return group->num_encoders_started;
}

void obs_encoder_group_num_started_unlock(struct obs_encoder_group *group);
void obs_encoder_group_num_started_unlock(struct obs_encoder_group *group)
{
pthread_mutex_unlock(&group->mutex);
}
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `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. |
| `libobs/obs-encoder-group-num-started.c.h` | `obs-output::encoder_group_num_started` | Swapped in hybrid `libobs` (group `libobs.ported-encoder-group-num-started` keeps the original for the C reference). The hidden `obs_encoder_group_num_started` (`obs-internal.h`, listed in `rust-hidden.d`), which output interleaving and `obs_encoder_set_group` call. Rust owns the decision: the group's mutex is taken once, `num_encoders_started` read once while it is held, and the mutex released once, so the value seen under the lock is returned over the full `uint32_t` range; the group is never NULL (the C precondition). The mutex and the count stay in C behind private adapters (`obs-encoder-group-num-started-fields.c.h`); Rust never sees the group layout or its pthread mutex. Only the unchanged characterization compiled the original, and the one other C definition of the name (`output_interleave_fields_stub.c`) never links the Rust archive, so no shared Rust-static support member is added. The unchanged `test_encoder_group_num_started` keeps testing the C source; its twin `test_encoder_group_num_started_rust` compiles the same fixture with the same recorder definitions and runs its assertions on the Rust shim through the real adapters. The interleave parity fixture now reaches its groups through the real shim (the oracle's adapters forward them), and the bench's stand-in is gone. Tier 1 mirrors every assertion plus the lock/read/unlock order; Tier 3 runs the original and the shim on two recording fixture groups (result, each lock and unlock, both groups byte for byte, count rewritten in the lock and/or unlock), with real-header layout checks and mutants. No intentional differences; no network protocol (Tier 4 inapplicable). |
| `libobs/obs-encoder-init.c.h` | `obs-output::encoder_init` | Encoder context/mutex initialization swapped through a private C operation table. Rust preserves sentinel setup, immediate failure returns, partial state, recursive lock selection and live defaults callback order. Original C body retained unchanged for the reference and differential oracle; real-header table layout and unchanged public creation characterization cover the boundary. No intentional differences; Tier 4 does not apply. |
| `libobs/obs-encoder-last-error.c.h` | `obs-output::encoder_last_error` | Swapped in hybrid `libobs` (group `libobs.ported-encoder-last-error`). `obs_encoder_get_last_error` preserves the NULL default and exact diagnostic, borrowed NULL/empty/arbitrary-byte message pointer identity, independent encoders and unchanged state. C supplies only the private field address, without a Rust mirror of `struct obs_encoder`. Real-header view layout checks, Tier 3 randomized parity with persistence disabled and a mutation check, and unchanged `test_encoder_last_error_getter` against both actual libraries cover the swap. No intentional differences; no ownership or locking changes. |
| `libobs/obs-encoder-reroute.c.h` (extracted from `obs-encoder.c.h`) | `obs-output::encoder_reroute` | `obs_encoder_create_rerouted` swapped in hybrid `libobs` (group `libobs.ported-encoder-reroute`, Refs #4413). Keeps the NULL debug diagnostics, the create-only permission (the thread-local stays in `obs-encoder.c.h`), the registry lookup through `find_encoder`, matching against the original info's type and case-insensitive codec, installing the whole replacement table before calling its `create` with the current settings, and passing its result back with no rollback on NULL. A borrowed field adapter keeps the private encoder layout in C. Tier 1 mirrors the unchanged `test_encoder_reroute`; Tier 3 compares exact traces against the original C over the characterized cases and random inputs, plus the real-header view layout and the log lines. 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 @@ -317,6 +317,8 @@ mod canonical_encoder_frame_rate_divisor_is_registered;
mod canonical_encoder_gpu_scaling_getters_is_registered;
#[path = "native/registration/canonical_encoder_group_null_is_registered.rs"]
mod canonical_encoder_group_null_is_registered;
#[path = "native/registration/canonical_encoder_group_num_started_swap_is_registered.rs"]
mod canonical_encoder_group_num_started_swap_is_registered;
#[path = "native/registration/canonical_encoder_outputs_swap_is_registered.rs"]
mod canonical_encoder_outputs_swap_is_registered;
#[path = "native/registration/canonical_encoder_preferred_color_setters_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
use super::*;

const ORIGINAL: &str = "libobs/obs-encoder-group-num-started.c.h";
const FIELDS: &str = "libobs/obs-encoder-group-num-started-fields.c.h";
const SHIM: &str = "obs_encoder_group_num_started";
const ADAPTERS: [&str; 3] = [
"obs_encoder_group_num_started_lock",
"obs_encoder_group_num_started_read",
"obs_encoder_group_num_started_unlock",
];
const DEFINITIONS: [&str; 2] = [
"pthread_mutex_lock=encoder_group_count_record_lock",
"pthread_mutex_unlock=encoder_group_count_record_unlock",
];

fn graph_json(root: &Path) -> serde_json::Value {
serde_json::from_str(
&fs::read_to_string(root.join("test/cmocka/build/test-graph.json")).unwrap(),
)
.unwrap()
}

/// No other target compiles the original, and the only cmocka source that
/// defines the shim's name (output_interleave_fields_stub.c, for the
/// interleaver's C fixture) is linked without the Rust archive, so neither
/// collides with the swap and no standalone Rust-static consumer needs a
/// shared copy of the adapters.
#[test]
fn canonical_encoder_group_num_started_original_has_one_consumer() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let graph = graph_json(&root);
let targets = graph["targets"].as_object().unwrap();
let compiles = |target: &serde_json::Value, source: &str| {
let source = serde_json::json!(source);
target["sources"].as_array().unwrap().contains(&source)
|| target["unity_groups"].as_object().is_some_and(|groups| {
groups
.values()
.any(|g| g.as_array().unwrap().contains(&source))
})
};
let consumers: Vec<_> = targets
.iter()
.filter(|(_, target)| compiles(target, ORIGINAL))
.map(|(name, _)| name.as_str())
.collect();
assert_eq!(consumers, ["test_encoder_group_num_started"]);
let stub = "test/cmocka/output_interleave_fields_stub.c";
let stub_text = fs::read_to_string(root.join(stub)).unwrap();
assert!(stub_text.contains(&format!("uint32_t {SHIM}(struct obs_encoder_group *group)")));
for (name, target) in targets {
if compiles(target, stub) {
let libraries = target["libraries"].to_string();
assert!(
!libraries.contains("libobs_rust-static"),
"{name} defines {SHIM} and links the Rust archive"
);
}
}
}

/// The unchanged characterization keeps testing the original; its twin
/// compiles the same fixture with the same recorder definitions, without the
/// original, so the Rust shim locks and reads through the real adapters and
/// the test's recorders.
#[test]
fn canonical_encoder_group_num_started_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 c_test = "test_encoder_group_num_started";
let rust_test = "test_encoder_group_num_started_rust";
graph
.targets
.retain(|key, _| key == c_test || key == rust_test);
graph
.tests
.retain(|key, _| key == c_test || key == rust_test);
let test_source = "test/cmocka/test_encoder_group_num_started.c";
let record = "test/cmocka/encoder-group-num-started-record-support.c";
for os in ["OS_LINUX", "OS_MACOS", "OS_WINDOWS"] {
for available in [false, true] {
let facts = [
(os.into(), true),
("HAVE_LIBOBS_RUST_STATIC".into(), available),
]
.into();
let selected = graph.select(&facts).unwrap();
assert!(matches!(selected.targets[c_test].sources.as_slice(),
[Source::Path(a), Source::Path(b)] if a == test_source && b == ORIGINAL));
assert_eq!(selected.targets[c_test].definitions, DEFINITIONS);
assert_eq!(selected.tests[c_test].target, c_test);
assert_eq!(selected.targets.contains_key(rust_test), available);
if !available {
continue;
}
let target = &selected.targets[rust_test];
assert!(matches!(target.sources.as_slice(),
[Source::Path(a), Source::Path(b)] if a == test_source && b == record));
assert_eq!(target.definitions, DEFINITIONS);
assert_eq!(selected.tests[rust_test].target, rust_test);
}
}
files_are_wired(&root, record);
}

/// Darwin binds an executable's calls by two-level namespace: a name
/// libobs.dylib exports would bind there, past the twin's own definitions
/// (#5226). The shim is hidden in both libraries and the adapters are never
/// exported, so the twin can only take the shim from the Rust archive and
/// the adapters (with the test's recorders) from its own objects.
#[test]
fn canonical_encoder_group_num_started_names_stay_private() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let names = |dir: &str| -> Vec<String> {
let mut names = Vec::new();
for entry in fs::read_dir(root.join(dir)).unwrap() {
let text = fs::read_to_string(entry.unwrap().path()).unwrap();
names.extend(
text.lines()
.map(str::trim)
.filter(|line| !line.starts_with('#') && !line.is_empty())
.map(str::to_owned),
);
}
names
};
let exports = names("libobs/cmake/rust-exports.d");
let hidden = names("libobs/cmake/rust-hidden.d");
assert!(hidden.iter().any(|name| name == SHIM));
for name in std::iter::once(SHIM).chain(ADAPTERS) {
assert!(
!exports.iter().any(|export| export == name),
"{name} exported"
);
}
let internal = fs::read_to_string(root.join("libobs/obs-internal.h")).unwrap();
assert!(internal.contains(&format!(
"extern uint32_t {SHIM}(struct obs_encoder_group *group);"
)));
let fields = fs::read_to_string(root.join(FIELDS)).unwrap();
assert!(!fields.contains("EXPORT"));
for name in ADAPTERS {
assert!(fields.contains(name), "{name} missing from {FIELDS}");
assert!(
!internal.contains(name),
"{name} declared in obs-internal.h"
);
}
}

/// The record support, the ported group, the hybrid group and the hidden list.
fn files_are_wired(root: &Path, record: &str) {
let fields = format!("#include \"{FIELDS}\"");
let record_text = fs::read_to_string(root.join(record)).unwrap();
assert!(record_text.contains(&fields));
let ported = fs::read_to_string(
root.join("libobs/build/ported-source-sets/encoder-group-num-started.json"),
)
.unwrap();
assert!(ported.contains("build/libobs.ported-encoder-group-num-started+.h.c"));
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-encoder-group-num-started+.h.c"))
.unwrap();
let original = format!("#include \"{ORIGINAL}\"");
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 C-owned mutex and count stay in the core group.
assert!(hybrid.contains(&fields));
let hidden = fs::read_to_string(
root.join("libobs/cmake/rust-hidden.d/obs-output-encoder_group_num_started.txt"),
)
.unwrap();
let names: Vec<_> = hidden
.lines()
.filter(|line| !line.starts_with('#') && !line.trim().is_empty())
.collect();
assert_eq!(names, [SHIM]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"schema": 1,
"targets": {
"test_encoder_group_num_started_rust": {
"sources": [
"test/cmocka/test_encoder_group_num_started.c",
"test/cmocka/encoder-group-num-started-record-support.c"
],
"definitions": [
"pthread_mutex_lock=encoder_group_count_record_lock",
"pthread_mutex_unlock=encoder_group_count_record_unlock"
],
"libraries": [
"libobs_rust-static",
"OBS::libobs",
"OBS::caption",
"Uthash::Uthash",
"OBS::native-test-cmocka",
{
"name": "OBS::w32-pthreads",
"requires": "OS_WINDOWS"
}
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
},
"tests": {
"test_encoder_group_num_started_rust": {
"target": "test_encoder_group_num_started_rust",
"command": [
"${target}"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
}
}
5 changes: 0 additions & 5 deletions rust/obs-c-oracle/benches/port_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ mod libobs_stand_ins {
called("obs_output_interleave_encoder_name")
}

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

#[unsafe(no_mangle)]
pub extern "C" fn obs_encoder_interleave_info() -> ! {
called("obs_encoder_interleave_info")
Expand Down
Loading
Loading