Skip to content

obs-media-io: Port media-io/media-remux.c.h - #1928

Merged
zackees merged 4 commits into
masterfrom
port/media-remux
Oct 23, 2026
Merged

zackees merged 4 commits into
masterfrom
port/media-remux

Conversation

@zackees

@zackees zackees commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #1927 (unit 7 of #1846).

libobs/media-io/media-remux.c.h (Tools > Remux Recordings) now lives in obs-media-io: media_remux_job_create, _process, _destroy.

Commits

  1. test: Characterize media_remux_job_* before its port: test/cmocka/test_media_remux.c, 13 cases with WAV inputs written by hand (refused jobs, NULL job, every sample kept, 5 channels written as 4.1 and 6 as 5.1(back), progress 0..100, a callback that stops the remux, a muxer that rejects the stream). Passes against the C (local Tier 2, mode OFF).
  2. RED obs-media-io: Test the remux job against stubs: Tier 1 over a scripted Host; Job::create/process/destroy were todo!(), 35 of 36 cases failed.
  3. GREEN obs-media-io: Port media-io/media-remux.c.h.

Design

Tiers

  • Tier 1: 36 cases (tests/remux/media_remux.rs), the cmocka cases plus the error paths and the libobs: Keep audio frames sample accurate when remuxing #360 audio timestamps.
  • Tier 2: test_media_remux (new) and test_remux_audio_timestamps, unchanged, against real FFmpeg; layout test for the two adapter structs.
  • Tier 3 (tests/remux/media_remux_parity.rs): the original C is built in the oracle crate against a recording FFmpeg stand-in (oracle/ffmpeg-shim/, oracle/media_remux_ffmpeg.c; the Rust test runners have no FFmpeg), and the real adapter over the same stand-in; results, progress reports and the log of every FFmpeg call and blog line must match over chosen cases and 256 random scripts. Mutation checks: the progress throttle (> 9 for > 10) and the input tick's rounding (NEAR_INF for UP) both fail it.
  • Tier 4: does not apply.
  • port_comparison media_remux/job_60_aac_frames: Rust 77.6 µs, C 70.2 µs (both over the same stand-in, which dominates).

Intentional differences

  • A failed create sets *job to NULL; the C leaves it pointing at the job it just freed (characterized in the cmocka test's comments, not asserted; the frontend only destroys a created job).
  • A NULL output name fails (C: strcmp(NULL)).
  • A packet whose stream index has no stream is written unchanged (C: out of bounds; FFmpeg never returns one).
  • On Windows the size is read through a UTF-8 path (C: _stat64 in the ANSI code page, so progress was infinite for other names).
  • The job is a Rust allocation, not bzalloc.

Kept, characterized, not endorsed: a callback that returns false stops the remux and the job still succeeds; AVERROR_INVALIDDATA/EINVAL writes drop the packet and continue.

Refs #1927. Refused jobs, progress, channel layouts and a muxer that rejects
the stream, with WAV inputs written by hand. Pins the C as it is: a callback
that stops the remux still reports success.
Refs #1927. Tier 1 for media-io/media-remux.c.h over a scripted Host: the
cases of test_media_remux.c and test_remux_audio_timestamps.c, and the error
paths FFmpeg rarely takes. Job::create, process and destroy are todo!():
35 of 36 cases fail.
Fixes #1927. media_remux_job_create, _process and _destroy now live in
obs-media-io. The safe core decides every FFmpeg call in the C's order over a
Host trait; FFmpeg's struct layouts stay in C, in the private adapter
media-io/media-remux-ffmpeg.c.h (hidden obs_media_remux_*, in the FFmpeg
group libobs.media), so no Rust crate links FFmpeg. media-remux.c.h moves to
its own ported group, libobs.ported-media-remux. The input size comes from
os_get_file_size, which drops the file's _MSC_VER stat/_stat64 conditional
(#870).

Intentional differences: a failed create sets *job to NULL (the C leaves it
pointing at the freed job); a NULL output name fails (C: strcmp(NULL)); a
packet of a stream index with no stream is written unchanged (C: out of
bounds); on Windows the size is read through a UTF-8 path.

Tier 3 builds the original C over a recording FFmpeg stand-in in the oracle
crate (oracle/ffmpeg-shim, oracle/media_remux_ffmpeg.c) and the adapter over
the same stand-in, and compares results, progress reports and the log of
every FFmpeg call and blog line over chosen and 256 random scripts. Mutation
checks: the progress throttle (> 9 instead of > 10) and the rounding of the
input tick (NEAR_INF instead of UP) both fail it. Layout test for the two
adapter structs. port_comparison: one 60-frame AAC job, Rust 77.6 us, C
70.2 us (same stand-in work on both sides).
@zackees
zackees marked this pull request as ready for review October 23, 2026 11:34
MSVC /W4 /WX rejects an uninitialized const object (C4132).
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into master with commit 9a20f0b Oct 23, 2026
32 checks passed
@zackees
zackees deleted the port/media-remux branch October 26, 2026 15:46
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…-rust#1997) (obs-rust#2554)

* test: require the port_comparison units to be discovered, not listed (obs-rust#1997)

RED: the ci test demanded the hand-kept `#[path] mod` lines and the
`modules![...]` call in `port_comparison.rs` stay sorted. It now fails if
either list exists and requires the two generated includes instead.

`uv run -m unittest discover -s ci -p test_sorted_shared_lists.py`:
test_port_comparison_units_are_discovered FAILs, assertNotRegex matched
`#[path = "port_comparison/audio.rs"]`.

* build: Generate the port_comparison unit list from the directory (obs-rust#1997)

GREEN: build.rs enumerates benches/port_comparison/*.rs and writes the
#[path] module lines and the run_units() call list into OUT_DIR, so a port
adds its own file and edits nothing shared. That was the last hand-kept
list every port appended to; two ports on one file collided in the merge
queue (obs-rust#1922 vs obs-rust#1928, obs-rust#1929 vs obs-rust#1922).

The file stem is the module name, so core.rs becomes core_units.rs (a
`mod core` at the crate root would make the units' `use core::ffi` paths
ambiguous). Absolute #[path] rather than `mod x { include!() }` because
the units open with //! inner docs, which include! cannot carry.

Verified: `soldr cargo check -p obs-c-oracle --benches` is clean, and a
throwaway zzz_probe.rs appeared in the generated run_units() and compiled
with no edit to a shared file. ci/test_sorted_shared_lists.py passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rust: Port media-io/media-remux.c.h to obs-media-io

1 participant