Compare commits

..

5 Commits

11 changed files with 77 additions and 24 deletions
Generated
+1 -1
View File
@@ -241,7 +241,7 @@ dependencies = [
[[package]] [[package]]
name = "domistream" name = "domistream"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"aes", "aes",
"aes-gcm", "aes-gcm",
+1 -1
View File
@@ -5,7 +5,7 @@ exclude = ["fuzz"]
resolver = "3" resolver = "3"
[workspace.package] [workspace.package]
version = "0.2.1" version = "0.2.2"
edition = "2024" edition = "2024"
rust-version = "1.89" rust-version = "1.89"
license = "CPAL-1.0" license = "CPAL-1.0"
+8 -1
View File
@@ -63,6 +63,9 @@ pub enum ClientControlMessage {
InputRejected { InputRejected {
/// Body length. /// Body length.
body_len: usize, 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<u32>,
/// Why. /// Why.
error: Error, error: Error,
}, },
@@ -111,7 +114,11 @@ pub fn parse_client_message(message: &[u8]) -> Result<ClientControlMessage> {
t if t == MessageType::FrameStats as u16 => ClientControlMessage::FrameStats(b.to_vec()), 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) { t if t == MessageType::InputData as u16 => match crate::input::parse_input(message) {
Ok(e) => ClientControlMessage::Input(e), 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() }, other => ClientControlMessage::Unknown { message_type: other, body_len: b.len() },
}) })
+7 -7
View File
@@ -183,14 +183,14 @@ pub fn plan_fec_blocks(data_shards: usize, fec_percentage: u8, min_parity: u8) -
let blocks = (1..=MAX_FEC_BLOCKS) let blocks = (1..=MAX_FEC_BLOCKS)
.find(|&b| wished_percentage(data_shards.div_ceil(b), fec_percentage, min_parity).is_some()) .find(|&b| wished_percentage(data_shards.div_ceil(b), fec_percentage, min_parity).is_some())
.unwrap_or(MAX_FEC_BLOCKS); .unwrap_or(MAX_FEC_BLOCKS);
let k_full = data_shards.div_ceil(blocks); // Even split (RFC 5052 9.1, as a BSD-2 host does it; PROTOCOL.md 5.3): the first `r` blocks carry one shard
let count = data_shards.div_ceil(k_full); // more, so block sizes differ by at most one and the largest is `ceil(n / blocks)`, the size checked above.
let mut plan = Vec::with_capacity(count); let blocks = blocks.min(data_shards);
let mut left = data_shards; let (q, r) = (data_shards / blocks, data_shards % blocks);
while left > 0 { let mut plan = Vec::with_capacity(blocks);
let k = left.min(k_full); for i in 0..blocks {
let k = if i < r { q + 1 } else { q };
plan.push(block(k, fec_percentage, min_parity)?); plan.push(block(k, fec_percentage, min_parity)?);
left -= k;
} }
Ok(plan) Ok(plan)
} }
+24
View File
@@ -784,3 +784,27 @@ proptest! {
prop_assert!(messages <= plains.len()); prop_assert!(messages <= plains.len());
} }
} }
/// Diagnostics (decision D2 on the host): an INPUT_DATA the host cannot read still says which input type it was, so
/// the black-box log can name what a real client sends (L2 demo: one 10-byte body of an unknown layout, U21).
#[test]
fn refused_input_names_its_type() {
// INPUT_DATA (0x0206): length 10, size (BE) 6 = type + 2 data bytes, type TOUCH 0x55000002 (LE), 2 data bytes.
let mut m = vec![0x06, 0x02, 10, 0];
m.extend_from_slice(&6u32.to_be_bytes());
m.extend_from_slice(&0x5500_0002u32.to_le_bytes());
m.extend_from_slice(&[0xAA, 0xBB]);
match parse_client_message(&m) {
Ok(ClientControlMessage::InputRejected { body_len, input_type, .. }) => {
assert_eq!(body_len, 10);
assert_eq!(input_type, Some(0x5500_0002));
}
other => panic!("{other:?}"),
}
// Too short to carry a type: none.
let short = vec![0x06, 0x02, 2, 0, 0, 0];
match parse_client_message(&short) {
Ok(ClientControlMessage::InputRejected { input_type, .. }) => assert_eq!(input_type, None),
other => panic!("{other:?}"),
}
}
+16 -5
View File
@@ -438,16 +438,18 @@ fn fec_plan_properties() {
assert!((1..=MAX_FEC_BLOCKS).contains(&plan.len()), "{ctx}: {} blocks", plan.len()); assert!((1..=MAX_FEC_BLOCKS).contains(&plan.len()), "{ctx}: {} blocks", plan.len());
assert_eq!(plan.iter().map(|b| usize::from(b.data_shards)).sum::<usize>(), n, "{ctx}"); assert_eq!(plan.iter().map(|b| usize::from(b.data_shards)).sum::<usize>(), n, "{ctx}");
let first_k = plan[0].data_shards; let first_k = plan[0].data_shards;
// Even split (RFC 5052 9.1, as a BSD-2 host does it, PROTOCOL.md 5.3): sizes differ by at most one,
// the larger blocks first.
let q = n / plan.len();
let r = n % plan.len();
for (i, b) in plan.iter().enumerate() { for (i, b) in plan.iter().enumerate() {
let (k, m, p) = let (k, m, p) =
(usize::from(b.data_shards), usize::from(b.parity_shards), usize::from(b.fec_percentage)); (usize::from(b.data_shards), usize::from(b.parity_shards), usize::from(b.fec_percentage));
assert!(k >= 1 && k + m <= 255, "{ctx}: k {k} m {m}"); assert!(k >= 1 && k + m <= 255, "{ctx}: k {k} m {m}");
assert_eq!(m, parity_count(k, b.fec_percentage).unwrap(), "{ctx}: m follows from the percentage"); assert_eq!(m, parity_count(k, b.fec_percentage).unwrap(), "{ctx}: m follows from the percentage");
if i + 1 < plan.len() { let want = if i < r { q + 1 } else { q };
assert_eq!(b.data_shards, first_k, "{ctx}: every block but the last carries the same k"); assert_eq!(usize::from(b.data_shards), want, "{ctx}: block {i} of an even split");
} else { assert!(b.data_shards <= first_k, "{ctx}");
assert!(b.data_shards <= first_k, "{ctx}");
}
let t = target(k, pct, min); let t = target(k, pct, min);
assert_eq!( assert_eq!(
b.reduced, b.reduced,
@@ -480,6 +482,15 @@ fn fec_plan_properties() {
); );
} }
#[test]
fn blocks_split_evenly_larger_first() {
// 217 shards at 255 %: at most 72 data shards fit a block (72 + 184 = 256 would not), so 4 blocks, split
// 55, 54, 54, 54 (RFC 5052 9.1), not 55, 55, 55, 52.
let plan = plan_fec_blocks(217, 255, 0).unwrap();
let ks: Vec<u16> = plan.iter().map(|b| b.data_shards).collect();
assert_eq!(ks, vec![55, 54, 54, 54]);
}
#[test] #[test]
fn minimum_parity_raises_the_written_percentage() { fn minimum_parity_raises_the_written_percentage() {
// One data shard at 0 % with at least 2 parity packets: 101 % is the smallest percentage giving // One data shard at 0 % with at least 2 parity packets: 101 % is the smallest percentage giving
+1
View File
@@ -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-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-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-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. |
+7
View File
@@ -1,5 +1,12 @@
# DomiStream — handover # 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) ## 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 Patch for Lumen L2: the client's `ControlStream` sends `START_B`, `PERIODIC_PING` and the IDR request with empty
+10 -7
View File
@@ -613,7 +613,7 @@ Each packet is `packetSize + 16` bytes, `packetSize` from ANNOUNCE (default 1024
| 8 | 4 | SSRC, 0 [M] | | 8 | 4 | SSRC, 0 [M] |
| 12 | 4 | reserved [W5] | | 12 | 4 | reserved [W5] |
| 16 | 4 | stream packet index, LE (= RTP sequence << 8 [M]) | | 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] | | 24 | 1 | flags: 0x01 picture data, 0x02 end of frame, 0x04 start of frame [W5] |
| 25 | 1 | reserved [W5] | | 25 | 1 | reserved [W5] |
| 26 | 1 | multi-FEC flags, `0x10` [M] (UNKNOWN U15: meaning) | | 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]]`. `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 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. 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 - **Host side (Lumen, `video::packetizer`).** The fewest blocks (at most 4) in which every block can carry the
with a real host: the fewest blocks (at most 4) in which every block can carry the requested parity within requested parity within `k + m <= 255`, split **evenly**: sizes differ by at most one, the larger blocks first
`k + m <= 255`, every block but the last carrying `k = ceil(n / blocks)` data shards; per block the least (RFC 5052 9.1, as Moonshine's host does it [M], S-26); per block the least percentage, at or above the requested
percentage, at or above the requested one, whose `m` reaches `minRequiredFecPackets`; a frame too big for that one, whose `m` reaches `minRequiredFecPackets`; Moonshine computes the same raised percentage
gets the most parity that still fits (counted in the packetizer's stats). Data shards in order, then the block's (`(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
parity, block by block; RTP sequence numbers run on across frames, one per packet. 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). - The audio code is **not** this matrix (section 6.4).
### 5.4 Feedback ### 5.4 Feedback
+1 -1
View File
@@ -236,7 +236,7 @@ dependencies = [
[[package]] [[package]]
name = "domistream" name = "domistream"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"aes", "aes",
"aes-gcm", "aes-gcm",
+1 -1
View File
@@ -228,7 +228,7 @@ dependencies = [
[[package]] [[package]]
name = "domistream" name = "domistream"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"aes", "aes",
"aes-gcm", "aes-gcm",