Skip to content

perf(obs-ffmpeg): send a mux packet up to 64 KiB in one pipe write (#3211) - #3361

Merged
zackees merged 2 commits into
masterfrom
perf/3211-mux-one-write
Nov 1, 2026
Merged

zackees merged 2 commits into
masterfrom
perf/3211-mux-one-write

Conversation

@zackees

@zackees zackees commented Nov 1, 2026

Copy link
Copy Markdown
Member

Fixes #3211

RED b7993d7: a new cmocka test, test_ffmpeg_mux_write_packet, builds obs-ffmpeg-mux.c and wraps os_process_pipe_write (--wrap) to count calls and capture bytes. Against unchanged code it fails with 2 != 1 for a 400-byte packet and a 64 KiB packet; the 150 KB case passes.

GREEN e3a9abe: write_packet copies the ffm_packet_info header and a packet of up to 64 KiB into a reused per-stream buffer (packet_buf, freed in destroy) and makes one os_process_pipe_write. Larger packets keep two writes, since copying them costs more than the syscall saved. The helper receives the same byte stream either way; the test checks the header fields and the data byte for byte. All 3 cases pass.

Why it matters: the shipped os_process_pipe_write is Rust (rust/obs-util/src/platform/unix/pipe.rs) and writes straight to the child's stdin with no buffering. Each call is one write(2). C's fwrite used to batch small packets in the stdio buffer.

Measured: write calls per packet drop from 2 to 1 for packets of up to 64 KiB. That covers every audio packet and most video P-frames at common bitrates. I did not run the strace -c over a 60 s recording that the issue asks for: this box can't run a headless OBS recording session. The per-packet syscall count above is what the test verifies.

Tiers: plugin C only, no public header or libobs change. Tier 2: the new test; it runs on Linux. Tiers 1, 3 and 4 do not apply (no Rust or protocol change). ./lint passes.

@zackees
zackees enabled auto-merge November 1, 2026 05:40
@zackees
zackees added this pull request to the merge queue Nov 1, 2026
Merged via the queue into master with commit fd6cb05 Nov 1, 2026
42 checks passed
@zackees
zackees deleted the perf/3211-mux-one-write branch November 1, 2026 07:04
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.

perf: obs-ffmpeg-mux: one write per packet on the mux pipe

1 participant