Document the H.264 profile ladder and the socket buffers

media.md: H.264 offered as Constrained High then Constrained Baseline,
one encoder per format viewers chose, and the tests that prove it (the
SPS profiles, a Baseline-only viewer, headless Chromium answering the
Baseline entry). The protocol notes and the interop README record what
Chromium 152 does with the ladder; architecture.md the socket buffers
and how losses are repaired, with the measurements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 22:57:23 +03:00
1 parent 52c3dbf34f
commit 675a057153
4 files changed
+52 -22

No files matched your search

+11
View File
@@ -246,6 +246,17 @@ Transport details of our stream (`voelin-stream`):
patch for it (`VOELIN-PATCH.md`). The order is a setting
(`Streams::set_srtp_profiles`, `Command::SetSrtpProfiles`) and applies to
new connections.
- **Losses**: each peer socket asks for 4 MB of receive and send buffer
(`PeerConfig::udp_buffer`; Linux caps it at `net.core.rmem_max`, and
what was granted is logged, with a hint when it is less): the default
208 KB overflowed under a 1440p keyframe on loopback (118-209 datagrams
per 5 s of a 9 Mbit/s stream), the larger buffer dropped none
(`tests/loopback.rs` `high_bitrate_bursts`). What is still lost is
repaired by NACK and retransmission (RTX), which our answers keep for
every video codec; str0m waits up to 30 complete frames for a
retransmission before it hands a frame over as non-contiguous
(`losses_are_repaired_by_retransmission`: one packet in 25 lost, every
frame whole).
- **Bandwidth estimation and pacing**: each viewer connection of our stream
runs str0m's send-side estimation (transport-cc feedback; REMB if a viewer
sends only that) and paces packets to it. Estimates are per viewer
+29 -18
View File
@@ -136,16 +136,20 @@ viewer: Engine::subscribe_frames ─ VideoPipeline (thread) ─ VideoDecoder
retime, the portal renegotiates the rate with the compositor).
- One encoder per codec viewers chose: the offer lists several codecs (see
`peer_config` below), the streamer's peer reports the codec each answer
chose (`PeerEvent::VideoCodec`), and the session sends a video frame only
to viewers of its codec (`StreamerSession::write_frame_in`) and tells the
encoders which codecs are wanted (`LayerFeedback::set_codecs`,
`MediaSink::video_codecs`). Each layer's encoder thread keeps the stream
codec's encoder and makes one more per other wanted codec when a viewer
needs it (with the streamer's current `Codecs` and preference), drops it
when none does, and skips the stream codec while nobody takes it; frames
go out through `MediaSink::send_video(frame, codec)`. Sinks that do not
tell codecs apart (`EncodedSource`, a `FrameSource`) get the stream codec
only, so their offers must list it alone (`voelinctl stream start` does).
chose, H.264 with its profile (`PeerEvent::VideoCodec(VideoFormat)`), and
the session sends a video frame only to viewers of its format
(`StreamerSession::write_frame_in`) and tells the encoders which formats
are wanted (`LayerFeedback::set_codecs`, `MediaSink::video_codecs`).
Each layer's encoder thread keeps the stream codec's encoder and makes
one more per other wanted format when a viewer needs it (with the
streamer's current `Codecs` and preference; for H.264 Constrained
Baseline with `EncoderConfig::h264_profile` set), drops it when none
does, and skips the stream codec while nobody takes it; frames go out
through `MediaSink::send_video(frame, format)`. So an H.264 stream runs a
second H.264 encoder only while a viewer took the Baseline entry of the
offer. Sinks that do not tell formats apart (`EncodedSource`, a
`FrameSource`) get the stream codec only, so their offers must list it
alone, H.264 in Constrained High only (`voelinctl stream start` does).
A studio's outputs count as viewers too: the stream codec always runs
for its recordings and replay buffer, and an output that needs a codec of
its own (RTMP: H.264) gets an encoder of the layer it takes
@@ -179,13 +183,18 @@ viewer: Engine::subscribe_frames ─ VideoPipeline (thread) ─ VideoDecoder
decodes H.264 only with an OpenH264 library it downloads at start-up; when
that fails it still answers H.264 and shows nothing (see
`docs/protocol-notes/ts6-streaming.md`), so H.264 never comes before a
codec it always decodes. H.264 is offered as one variant, Constrained High
(packetization mode 1) at the level the stream needs
(`PeerConfig::set_h264_format(profile, width, height, fps, bitrate)`:
macroblocks per second and per frame, and bitrate, per H.264 Table A-1;
never below 3.1, the level offered before); str0m's other H.264 variants
are only accepted, never offered, so a viewer cannot answer a profile we
do not send.
codec it always decodes. H.264 is offered in two variants, best first:
Constrained High (payload type 112), then Constrained Baseline (108) for
peers that list no High profile (headless Chromium 152's libwebrtc lists
only Baseline, Constrained Baseline and Main), both packetization mode 1
at the level the stream needs (`PeerConfig::h264_profile_level_ids`,
`set_h264_format(width, height, fps, bitrate)`: macroblocks per second
and per frame, and bitrate, per H.264 Table A-1; never below 3.1, the
level offered before). A viewer that takes both answers High (the
streamer writes the first of its own order the answer lists); one that
takes only Baseline gets frames from an encoder in Constrained Baseline
(above). str0m's other H.264 variants are only accepted, never offered,
so a viewer cannot answer a profile we do not send.
- `VideoPipeline` decodes on its own thread. It starts at a keyframe, and
after a lost frame (`contiguous == false`, a lagging frame bus, a queue
longer than 30 frames) or a decoder error it skips to the next keyframe,
@@ -1022,7 +1031,9 @@ has not run on Windows yet.
| AMF never loaded on Linux by default; AMF opens serialised | `ffmpeg::encoder::tests::amf_is_opt_in_on_linux`, `tests/ffmpeg.rs` `probe_reports_every_backend` (no `libamfrt` in `/proc/self/maps`), `amf_encoders_open_in_parallel` (`--ignored`, with `VOELIN_FFMPEG_AMF=1`) | tested: the probe crash (SIGSEGV in `libamfrt64`, 10 of 420 concurrent probes under Xvfb) reproduced, then none in 600 with serialised opens |
| Encoder preference (auto, software, named, hardware off), report ranks | `codec::tests::encoder_preference` | tested |
| An encoder per codec viewers chose (made, dropped, stream codec skipped, preference change) | `voelin-core` `media::tests::an_encoder_per_codec_viewers_chose` | tested |
| Answer's codec reported to the streamer, H.264 level in the offer, HEVC offered | `voelin-stream` `peer::tests::streamer_learns_the_answered_codec`, `h264::tests` | tested (str0m on loopback) |
| An encoder per H.264 profile viewers chose: Constrained High and Baseline side by side (SPS `profile_idc` 100 and 66), High dropped when only Baseline viewers are left | `voelin-core` `media::tests::an_encoder_per_h264_profile_viewers_chose` | tested (FFmpeg's H.264 encoders here) |
| Answer's codec reported to the streamer, H.264 levels and both profiles in the offer, a Baseline-only viewer answering the fallback entry, HEVC offered | `voelin-stream` `peer::tests::streamer_learns_the_answered_codec`, `a_baseline_only_viewer_gets_the_fallback_profile`, `h264::tests` | tested (str0m on loopback) |
| The H.264 ladder against libwebrtc: headless Chromium 152 answers the Constrained Baseline entry and decodes frames from an encoder in that profile | `voelin-core/tests/browser_codecs.rs` `real_encoders_decode_in_browser` (`VOELIN_INTEROP=1`) | tested: `h264_vaapi` (from memory and from DMA-BUFs) and `libx264`, 90 of 90 frames at 1280x720, SPS profile 66 |
| x264 / SVT-AV1 / libaom in the streamer pipeline | `voelinctl stream bench --encoder ...` | 720p30: x264 8.7 ms per frame, SVT-AV1 1.3 ms, libaom 37 ms; 1.1 allocations per encoded frame |
| Hardware encoders VA-API and AMF (H.264, HEVC, AV1) in the streamer pipeline | `voelinctl stream bench` on a Radeon RX 7900 GRE, 1080p60 / 1440p60 / simulcast | tested: full frame rate, 0.20-0.52 cores against 1.16-2.55 for software, 1.02 allocations per encoded frame, every backend within 2 % of the target bitrate once `av1_vaapi` got a two-second buffer (it overshot by 3.5-8 %; see the tables above) |
| Hardware encoders → our decoders: `h264_vaapi` / `h264_amf` → OpenH264, `av1_vaapi` / `av1_amf` → dav1d (PSNR > 28 dB, decoded size, keyframes at start and on request, timestamps, bitrate change) at 320x240 and 1920x1080 | `tests/ffmpeg.rs` `hardware_encoders_roundtrip` (`VOELIN_OPENH264_LIB`, `--features av1`) | tested on the Radeon RX 7900 GRE: it found the AV1 encoder padding 1080 rows to 1082 (and other sizes to 64x16), now cropped (see above). HEVC is not decoded (no decoder here) |
+5 -1
View File
@@ -289,7 +289,11 @@ while it watched a Voelin stream, and the symbols of its binary:
- It answers with the first codec of the offer it lists, like Chromium.
Voelin now offers codecs every client decodes first (`decoded_everywhere`)
and H.264 only in the profile it encodes. The real encoders' streams (VA-API
and H.264 only in the profiles it encodes: Constrained High, then
Constrained Baseline (both packetization mode 1). A client that answers
the Baseline entry (headless Chromium 152; the official client's own
answer above was a Baseline profile too) gets frames from an encoder in
that profile. The real encoders' streams (VA-API
H.264 and AV1, from memory and from DMA-BUFs; libvpx VP8 and VP9; x264,
SVT-AV1, libaom) decode in Chromium 152's libwebrtc at full size
(`crates/voelin-core/tests/browser_codecs.rs`). Watching such a stream with
+7 -3
View File
@@ -12,7 +12,7 @@ TeamSpeak server is involved.
|---|---|
| `rust_streams_to_browser` | Our streamer offer (`PeerConfig::loopback()`, VP8 + Opus, with the `a=x-voelin-layers` line a Voelin streamer with several layers adds, which libwebrtc must skip) answered by an `RTCPeerConnection`; `SyntheticSource` media for 3 s; `inbound-rtp` stats: VP8 packets and bytes, decoded frames (the synthetic frames are real 1x1 VP8 keyframes), Opus packets; the `transport` stats' `srtpCipher` is `AES_CM_128_HMAC_SHA1_80` (our SRTP order, we are the DTLS server); our bandwidth estimation gets estimates from Chromium's transport-cc feedback |
| `browser_streams_to_rust` | Chromium offers a canvas `captureStream` and an oscillator with VP8, VP9, H264 and AV1 preferred in turn (codecs the browser cannot send are skipped); our viewer `Peer::answer` must receive frames of that codec and Opus, over `AES_CM_128_HMAC_SHA1_80`. VP8 also uses trickled browser candidates and checks that a PLI brings a keyframe |
| `real_encoders_decode_in_browser` (voelin-core) | Every encoder this machine has (`Codecs::encoders()`), as a share uses it: the 1280x720 test pattern through the `Streamer`, VA-API encoders also from DMA-BUFs as the ScreenCast portal hands over the screen; our streamer peer offers that codec alone (H.264 as Constrained Baseline, see below); the browser must decode at least 60 frames at 1280x720 in 3 s. Codecs the browser does not answer (HEVC, H.264 in Playwright's Chromium) are skipped |
| `real_encoders_decode_in_browser` (voelin-core) | Every encoder this machine has (`Codecs::encoders()`), as a share uses it: the 1280x720 test pattern through the `Streamer`, VA-API encoders also from DMA-BUFs as the ScreenCast portal hands over the screen; our streamer peer offers that codec alone (H.264 as the ladder of the offer, Constrained High then Constrained Baseline), and the `Streamer` encodes the format the browser's answer chose, as for a viewer of a real stream; the browser must decode at least 60 frames at 1280x720 in 3 s, and H.264 must carry the chosen profile in its SPS. Codecs the browser does not answer (HEVC, H.264 in Playwright's Chromium) are skipped |
| `share_offer_picks_a_codec_every_client_decodes` (voelin-core) | The offer a share makes on this machine (`preferred_codec`, `peer_config`): the browser, answering with the first codec of the offer it lists as the official client does, must pick one every TeamSpeak client decodes (`decoded_everywhere`), and decode it |
| `browser_renegotiates_with_rust` | Chromium streams VP8, then sends a new offer on the same connection with VP9 first (as the official client re-offers when it does not encode the codec we chose); `Peer::renegotiate` answers on the same peer, in the new offer's codec order; VP9 frames must arrive |
| `trickled_candidates_reach_browser` | A server-reflexive candidate (from a fake STUN server) as our sessions trickle it (`iceCandidate` signal with the peer's mid) is accepted by `addIceCandidate` |
@@ -70,8 +70,12 @@ may do the same; see `docs/protocol-notes/ts6-streaming.md`.
- Headless Chromium 152 lists H.264 only in the profiles of libwebrtc's
software decoder (Baseline, Constrained Baseline, Main, packetization modes
0 and 1): it does not answer an offer of Constrained High alone
(`640c1f`, what our streamers offer), yet decodes High profile streams
when it negotiated another profile (its decoder is FFmpeg's).
(`640c1f`), yet decodes High profile streams when it negotiated another
profile (its decoder is FFmpeg's). Our offers now list Constrained
Baseline (`42e01f`) after Constrained High; Chromium 152 answers that
entry and decodes what an encoder in Constrained Baseline makes
(`h264_vaapi`, also from DMA-BUFs, and `libx264`: 90 of 90 frames,
2026-10-03).
- With str0m's bandwidth estimation and pacer on our streamer peer, Chromium's
transport-cc feedback yields estimates within the first second (about
640 kbit/s rising towards the desired bitrate with the 720 kbit/s synthetic