Skip to content

perf(obs-outputs): write an RTMP message to the socket in one call (#3207) - #3375

Merged
zackees merged 2 commits into
masterfrom
perf/3207-rtmp-sendmsg
Nov 1, 2026
Merged

zackees merged 2 commits into
masterfrom
perf/3207-rtmp-sendmsg

Conversation

@zackees

@zackees zackees commented Nov 1, 2026

Copy link
Copy Markdown
Member

Fixes #3207

RED 3ccf152: a new cmocka test, test_rtmp_send_batch (Linux), builds librtmp and points an RTMP at an AF_UNIX SOCK_SEQPACKET socketpair. The peer receives one record per send(), so the record count is the syscall count. The test sends a 150 KB video message, a 1000-byte one, an exact multiple of the chunk size, and a 150 KB one with an extended timestamp. It checks the received stream chunk by chunk (type-0 header, then a 0xc0|channel type-3 header before each 4096-byte chunk, plus the 4 extended-timestamp bytes where they apply) and the record count. Against unchanged code: keyframe_is_one_write and exact_chunk_multiple fail with one record per chunk (3 != 1 for three chunks).

GREEN d55e394: RTMP_SendPacket already built the whole chunked message in one buffer and made one WriteN for the HTTP tunnel. It now does that for every connection: plain TCP, TLS, and the custom-send loop alike. So there is no new platform code, and TLS gets one TLS_write per message instead of one per chunk. If the allocation fails on a non-HTTP connection, it falls back to the old chunk-by-chunk write. All 4 cases pass.

This deviates from the plan in my claim (an iovec/sendmsg path in a POSIX host file). Reusing librtmp's existing batching covers TLS and Windows too, and needs no #ifdef. The cost is one malloc and a memcpy of the message.

Also fixed (it now matters): the buffer size didn't count the 4-byte extended timestamp written after each type-3 header when the timestamp delta is ≥ 0xffffff. On the HTTP path that overran tbuf by 4 bytes per chunk. That path is only reached with a local timestamp delta over about 4.6 hours, and nothing remote reaches it. The size now includes those bytes, and extended_timestamp covers it.

Measured: send calls per message, verified by the test: 150 KB keyframe, 37 → 1; 3 chunks, 3 → 1; one chunk, 1 → 1. At OBS's 4096-byte chunk size a message of S bytes went from ⌈S/4096⌉ syscalls to 1: about 4 per 60 fps frame at 6 Mbps (12.5 KB) and about 26 at 50 Mbps (104 KB), now 1 each. That is arithmetic from the chunk size, not the strace -c on a live ingest the issue asks for, which I can't run here.

Tiers: vendored librtmp in the plugin, no libobs or public header change. Tier 2: the new test. Tiers 1, 3 and 4 do not apply. ./lint passes.

@zackees
zackees enabled auto-merge November 1, 2026 06:25
@zackees
zackees added this pull request to the merge queue Nov 1, 2026
Merged via the queue into master with commit 7bb01bc Nov 1, 2026
42 checks passed
@zackees
zackees deleted the perf/3207-rtmp-sendmsg branch November 1, 2026 07:29
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-outputs: batch RTMP chunks into one writev/sendmsg

1 participant