From c7dcdc80f37db93bca477b558d3ab11d66d31279 Mon Sep 17 00:00:00 2001 From: mnovak Date: Fri, 4 Dec 2026 15:49:04 +0100 Subject: [PATCH] [domistream] Video packetizer: even FEC block split; control host: refused input names its type; PROTOCOL 5.2/5.3 host facts (S-26); version 0.2.2 --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/domistream/src/control/host.rs | 9 ++++++++- crates/domistream/src/video/packetizer.rs | 14 +++++++------- docs/CLEAN_ROOM.md | 1 + docs/HANDOVER.md | 7 +++++++ docs/PROTOCOL.md | 17 ++++++++++------- fuzz/Cargo.lock | 2 +- tools/gs-probe/Cargo.lock | 2 +- 9 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce380e2..855fb47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -241,7 +241,7 @@ dependencies = [ [[package]] name = "domistream" -version = "0.2.1" +version = "0.2.2" dependencies = [ "aes", "aes-gcm", diff --git a/Cargo.toml b/Cargo.toml index 08e5753..be6625a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ exclude = ["fuzz"] resolver = "3" [workspace.package] -version = "0.2.1" +version = "0.2.2" edition = "2024" rust-version = "1.89" license = "CPAL-1.0" diff --git a/crates/domistream/src/control/host.rs b/crates/domistream/src/control/host.rs index 86cf126..6ffd041 100644 --- a/crates/domistream/src/control/host.rs +++ b/crates/domistream/src/control/host.rs @@ -63,6 +63,9 @@ pub enum ClientControlMessage { InputRejected { /// Body length. body_len: usize, + /// The input type field (body bytes 4..8, little-endian, PROTOCOL.md 4) when the body is long enough: for the + /// logs, so a host can name what a client sends. + input_type: Option, /// Why. error: Error, }, @@ -111,7 +114,11 @@ pub fn parse_client_message(message: &[u8]) -> Result { t if t == MessageType::FrameStats as u16 => ClientControlMessage::FrameStats(b.to_vec()), t if t == MessageType::InputData as u16 => match crate::input::parse_input(message) { Ok(e) => ClientControlMessage::Input(e), - Err(error) => ClientControlMessage::InputRejected { body_len: b.len(), error }, + Err(error) => ClientControlMessage::InputRejected { + body_len: b.len(), + input_type: b.get(4..8).and_then(|t| <[u8; 4]>::try_from(t).ok()).map(u32::from_le_bytes), + error, + }, }, other => ClientControlMessage::Unknown { message_type: other, body_len: b.len() }, }) diff --git a/crates/domistream/src/video/packetizer.rs b/crates/domistream/src/video/packetizer.rs index a5a783f..89517a8 100644 --- a/crates/domistream/src/video/packetizer.rs +++ b/crates/domistream/src/video/packetizer.rs @@ -183,14 +183,14 @@ pub fn plan_fec_blocks(data_shards: usize, fec_percentage: u8, min_parity: u8) - let blocks = (1..=MAX_FEC_BLOCKS) .find(|&b| wished_percentage(data_shards.div_ceil(b), fec_percentage, min_parity).is_some()) .unwrap_or(MAX_FEC_BLOCKS); - let k_full = data_shards.div_ceil(blocks); - let count = data_shards.div_ceil(k_full); - let mut plan = Vec::with_capacity(count); - let mut left = data_shards; - while left > 0 { - let k = left.min(k_full); + // Even split (RFC 5052 9.1, as a BSD-2 host does it; PROTOCOL.md 5.3): the first `r` blocks carry one shard + // more, so block sizes differ by at most one and the largest is `ceil(n / blocks)`, the size checked above. + let blocks = blocks.min(data_shards); + let (q, r) = (data_shards / blocks, data_shards % blocks); + let mut plan = Vec::with_capacity(blocks); + for i in 0..blocks { + let k = if i < r { q + 1 } else { q }; plan.push(block(k, fec_percentage, min_parity)?); - left -= k; } Ok(plan) } diff --git a/docs/CLEAN_ROOM.md b/docs/CLEAN_ROOM.md index 332f640..05dab00 100644 --- a/docs/CLEAN_ROOM.md +++ b/docs/CLEAN_ROOM.md @@ -97,3 +97,4 @@ All entries by the DomiStream protocol engineer. Pinned commits are the ones rea | S-31 | 2026-12-04 | Moonshine at `f184d5e`: `src/session/stream/mod.rs`, `src/session/stream/video/mod.rs`; the repository tree listing (GitHub API) | BSD-2, facts only. `bitStreamFormat` 0 H.264 (default), 1 HEVC, 2 AV1, others invalid; dynamic range 0 SDR (default), 1 HDR; chroma 0 4:2:0 (default), 1 4:4:4; valid video packet size 200..=65471 (one stream packet in an IPv6 UDP datagram), below 200 refused; FEC default 20 %. The bitrate comment citing Sunshine is logged above and not used. | | S-32 | 2026-12-04 | [Wolf: RTSP](https://games-on-whales.github.io/wolf/stable/protocols/rtsp.html) again (as S-3); [RFC 2326](https://www.rfc-editor.org/rfc/rfc2326.txt) | Wolf: nothing new for the host (no per-method answers, no ANNOUNCE list). RFC 2326: reason phrases of 400, 451, 454, 455, 501 (7.1.1); a missing `Content-Length` means zero (4.4); OPTIONS may be sent at any time (10.1); session ids at least 8 random octets (3.4); `Public` as a comma-separated list (10.1 example). | | S-34 | 2026-12-04 | [Stock ENet](https://github.com/lsalzman/enet) v1.3.18 (`2662c0d`, same pin as S-17), read again for the host side: `protocol.c` (`enet_protocol_handle_connect`, `_verify_connect`, `_disconnect`, `_ping`, `_bandwidth_limit`, `_throttle_configure`, `_acknowledge`, `_send_unsequenced`, `_send_unreliable_fragment`, `_send_reliable`/`_send_fragment` state checks, the acknowledgement rules of `_handle_incoming_commands`, the ping condition of `_send_outgoing_commands`) and `include/enet/enet.h` (peer window constants) | MIT. Facts for PROTOCOL.md 3.1 "The accepting side" and `enet::host`: a CONNECT is answered by a reliable verify on channel 0xFF and is not itself acknowledged; repeated connects from a live peer are refused; session id derivation (offered id or the slot's, plus one mod 4, skipping the slot's previous id) and which verify field carries which; MTU, window and channel clamping, bandwidths are the host's own, throttle echoed, connect data reported with the connect event; connected on the acknowledgement of the verify; acknowledgements only while connected and only with a sent time, a failing command ends the datagram; ping, bandwidth and throttle need the connected state; unsequenced window 1024 groups, 32 free windows; pings when nothing was received for the ping interval and nothing reliable is in flight. Read through an automated summary of the raw files at the pinned commit; no code copied. | +| S-26 | 2026-12-04 | [Moonshine](https://github.com/hgaiser/moonshine) at `f184d5e` (same pin as S-9): `src/session/stream/video/packetizer.rs` and `src/session/stream/video/mod.rs` again, read for the host after the L2 demo | BSD-2, facts only. The raised FEC percentage for a minimum parity count (`(minimum - 1) * 100 / k + 1`, capped by 255 and the 255-shard limit), parity rounded up; the even block split (RFC 5052 9.1); per-block data shards from `255 * 100 / (100 + percentage)`, at most 4 blocks; which parity header fields it patches; the 8-byte frame header and last-shard length; the encryption prefix order (IV, frame number, tag). A comment in `video/mod.rs`: a fresh Moonlight session expects frame numbers to start at 1 (a client behaviour, no Sunshine or moonlight-common-c value; to be confirmed by our measurement). No comment in these parts cites Sunshine or moonlight-common-c for a packetizer value. | diff --git a/docs/HANDOVER.md b/docs/HANDOVER.md index ac18062..065dbb1 100644 --- a/docs/HANDOVER.md +++ b/docs/HANDOVER.md @@ -1,5 +1,12 @@ # DomiStream — handover +## stream-v0.2.2 (2026-12-04) + +After the L2 demo (Arena Domi Remote crashed at Lumen's first video frame): the video packetizer splits FEC blocks +evenly, larger blocks first (RFC 5052 9.1, as Moonshine's host does it), and a refused INPUT_DATA names its input +type for the logs (`ClientControlMessage::InputRejected::input_type`). The frame index starting at 1 is the caller's +(Lumen's) job; PROTOCOL.md 5.2 records it. Tests first; workspace 424 passed, 0 failed. + ## stream-v0.2.1 (2026-12-04) Patch for Lumen L2: the client's `ControlStream` sends `START_B`, `PERIODIC_PING` and the IDR request with empty diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md index aa4039a..fad8372 100644 --- a/docs/PROTOCOL.md +++ b/docs/PROTOCOL.md @@ -613,7 +613,7 @@ Each packet is `packetSize + 16` bytes, `packetSize` from ANNOUNCE (default 1024 | 8 | 4 | SSRC, 0 [M] | | 12 | 4 | reserved [W5] | | 16 | 4 | stream packet index, LE (= RTP sequence << 8 [M]) | -| 20 | 4 | frame index, LE [W5][M] | +| 20 | 4 | frame index, LE [W5][M]; **starts at 1** in a fresh session (Moonshine's note on what Moonlight-family clients expect [M], S-26; a host that started at 0 crashed Arena Domi Remote at its first frame, L2 demo) | | 24 | 1 | flags: 0x01 picture data, 0x02 end of frame, 0x04 start of frame [W5] | | 25 | 1 | reserved [W5] | | 26 | 1 | multi-FEC flags, `0x10` [M] (UNKNOWN U15: meaning) | @@ -650,12 +650,15 @@ Reed-Solomon erasure code over GF(2^8), polynomial `0x11D` [F] [W5]: `P = [[8e f4 47 a7], [f4 8e a7 47]]`; `k = 3, m = 1`: `P = [[01 8e f4]]`. The capture settles it without any loss: parity packets are always sent, so our encoder must reproduce the captured parity bytes (offset 32 on) of every block. -- **Host side (Lumen, `video::packetizer`).** Our own choices, not from a source, until a capture compares them - with a real host: the fewest blocks (at most 4) in which every block can carry the requested parity within - `k + m <= 255`, every block but the last carrying `k = ceil(n / blocks)` data shards; per block the least - percentage, at or above the requested one, whose `m` reaches `minRequiredFecPackets`; a frame too big for that - gets the most parity that still fits (counted in the packetizer's stats). Data shards in order, then the block's - parity, block by block; RTP sequence numbers run on across frames, one per packet. +- **Host side (Lumen, `video::packetizer`).** The fewest blocks (at most 4) in which every block can carry the + requested parity within `k + m <= 255`, split **evenly**: sizes differ by at most one, the larger blocks first + (RFC 5052 9.1, as Moonshine's host does it [M], S-26); per block the least percentage, at or above the requested + one, whose `m` reaches `minRequiredFecPackets`; Moonshine computes the same raised percentage + (`(minimum - 1) * 100 / k + 1`, e.g. 101 % for 1 shard, 51 % for 2, 34 % for 3 with a minimum of 2) [M]; a frame + too big for that gets the most parity that still fits (counted in the packetizer's stats). Data shards in order, + then the block's parity, block by block; RTP sequence numbers run on across frames, one per packet. A capture of a + real host still has to confirm the parity header fields: Moonshine patches only the RTP sequence, frame index, + multi-FEC blocks byte and FEC info of a parity packet [M]; we write all header fields. - The audio code is **not** this matrix (section 6.4). ### 5.4 Feedback diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 997dc0a..71f9b0b 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -236,7 +236,7 @@ dependencies = [ [[package]] name = "domistream" -version = "0.2.1" +version = "0.2.2" dependencies = [ "aes", "aes-gcm", diff --git a/tools/gs-probe/Cargo.lock b/tools/gs-probe/Cargo.lock index beec130..589934f 100644 --- a/tools/gs-probe/Cargo.lock +++ b/tools/gs-probe/Cargo.lock @@ -228,7 +228,7 @@ dependencies = [ [[package]] name = "domistream" -version = "0.2.1" +version = "0.2.2" dependencies = [ "aes", "aes-gcm",