Repository navigation
perf(obs-outputs): write an RTMP message to the socket in one call (#3207) - #3375
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3207
RED 3ccf152: a new cmocka test,
test_rtmp_send_batch(Linux), builds librtmp and points anRTMPat anAF_UNIXSOCK_SEQPACKETsocketpair. The peer receives one record persend(), 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 a0xc0|channeltype-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_writeandexact_chunk_multiplefail with one record per chunk (3 != 1for three chunks).GREEN d55e394:
RTMP_SendPacketalready built the whole chunked message in one buffer and made oneWriteNfor 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 oneTLS_writeper 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/
sendmsgpath 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
tbufby 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, andextended_timestampcovers it.Measured:
sendcalls 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 thestrace -con 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.
./lintpasses.