[domistream] Implementation: HTTP, pairing, RTSP/SDP, ENet, control, input, RTP, FEC, video and audio receivers
Per PROTOCOL.md and the Wolf docs; interop with a real host is unverified. Strict, capped parsers throughout, shared helpers in util.rs. Where PROTOCOL.md says UNKNOWN the Wolf-documented behaviour is used. The audio receiver waits for the jitter budget before rebuilding a missing packet, so a late packet beats a rebuilt one.
This commit is contained in:
@@ -72,16 +72,46 @@ pub struct VideoPacket<'a> {
|
||||
pub payload: &'a [u8],
|
||||
}
|
||||
|
||||
/// Parses one plaintext video packet. Checks the FEC fields are consistent (`shard_index < data + parity`,
|
||||
/// `block_index <= last_block_index`, `data_shards > 0`).
|
||||
/// Parses one plaintext video packet. Checks the FEC fields are consistent (`data_shards > 0`, data + parity
|
||||
/// `<= 255` with parity `= ceil(data × percentage / 100)`, `shard_index < data + parity`,
|
||||
/// `block_index <= last_block_index`).
|
||||
///
|
||||
/// # Errors
|
||||
/// [`crate::Error::TooLarge`] over [`MAX_VIDEO_PACKET_BYTES`], [`crate::Error::Truncated`] under
|
||||
/// [`PAYLOAD_OFFSET`], [`crate::Error::Malformed`] for inconsistent FEC fields. Phase A: always
|
||||
/// [`crate::Error::Unimplemented`].
|
||||
/// [`PAYLOAD_OFFSET`], [`crate::Error::UnexpectedValue`] for an RTP version other than 2,
|
||||
/// [`crate::Error::Malformed`] for inconsistent FEC fields.
|
||||
pub fn parse_video_packet(packet: &[u8]) -> crate::Result<VideoPacket<'_>> {
|
||||
let _ = packet;
|
||||
Err(crate::Error::Unimplemented)
|
||||
use crate::util::{byte, malformed, u32_le};
|
||||
const W: &str = "video packet";
|
||||
crate::util::cap(W, MAX_VIDEO_PACKET_BYTES, packet.len())?;
|
||||
crate::util::need(W, PAYLOAD_OFFSET, packet.len())?;
|
||||
let rtp = crate::rtp::parse_rtp_header(packet)?;
|
||||
let nv = VIDEO_RTP_LEN;
|
||||
let fec_info = u32_le(W, packet, nv + 12)?;
|
||||
let blocks = byte(W, packet, nv + 11)?;
|
||||
let fec = FecInfo {
|
||||
shard_index: ((fec_info >> 12) & 0x3FF) as u16,
|
||||
data_shards: ((fec_info >> 22) & 0x3FF) as u16,
|
||||
fec_percentage: ((fec_info >> 4) & 0xFF) as u8,
|
||||
block_index: (blocks >> 4) & 0x3,
|
||||
last_block_index: (blocks >> 6) & 0x3,
|
||||
};
|
||||
let parity = crate::fec::parity_count(usize::from(fec.data_shards), fec.fec_percentage)
|
||||
.map_err(|_| malformed("video fec shard counts"))?;
|
||||
if usize::from(fec.shard_index) >= usize::from(fec.data_shards) + parity || fec.block_index > fec.last_block_index {
|
||||
return Err(malformed("video fec fields"));
|
||||
}
|
||||
Ok(VideoPacket {
|
||||
rtp,
|
||||
nv: NvVideoHeader {
|
||||
stream_packet_index: u32_le(W, packet, nv)?,
|
||||
frame_index: u32_le(W, packet, nv + 4)?,
|
||||
flags: VideoFlags(byte(W, packet, nv + 8)?),
|
||||
multi_fec_flags: byte(W, packet, nv + 10)?,
|
||||
fec,
|
||||
},
|
||||
payload: packet.get(PAYLOAD_OFFSET..).unwrap_or(&[]),
|
||||
})
|
||||
}
|
||||
|
||||
/// Frame types in the frame header.
|
||||
@@ -116,8 +146,22 @@ pub struct FrameHeader {
|
||||
/// Parses the frame header at the start of a frame's data (the rest is ignored here).
|
||||
///
|
||||
/// # Errors
|
||||
/// [`crate::Error::Truncated`] under [`FRAME_HEADER_LEN`]. Phase A: always [`crate::Error::Unimplemented`].
|
||||
/// [`crate::Error::Truncated`] under [`FRAME_HEADER_LEN`].
|
||||
pub fn parse_frame_header(frame_data: &[u8]) -> crate::Result<FrameHeader> {
|
||||
let _ = frame_data;
|
||||
Err(crate::Error::Unimplemented)
|
||||
const W: &str = "video frame header";
|
||||
let raw = crate::util::array::<FRAME_HEADER_LEN>(W, frame_data, 0)?;
|
||||
let [header_type, l0, l1, kind, a, b, c, d] = raw;
|
||||
let frame_type = match kind {
|
||||
1 => FrameType::Predicted,
|
||||
2 => FrameType::Key,
|
||||
5 => FrameType::Recovery,
|
||||
other => FrameType::Other(other),
|
||||
};
|
||||
Ok(FrameHeader {
|
||||
raw,
|
||||
header_type,
|
||||
processing_latency: u16::from_le_bytes([l0, l1]),
|
||||
frame_type,
|
||||
last_payload_len: u32::from_le_bytes([a, b, c, d]),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user