[domistream] Video packetizer: tests first (round trips through VideoDepacketizer, loss up to and beyond m, fixed vectors), API stubs

This commit is contained in:
2026-12-04 12:20:55 +01:00
parent 514565dbd7
commit 7983833ba6
3 changed files with 968 additions and 0 deletions
+136
View File
@@ -0,0 +1,136 @@
//! The video send path, host side (`docs/PROTOCOL.md` 5.2, 5.3, 7): one encoded access unit → the RTP + NV-header
//! datagrams of one frame, in FEC blocks with Reed-Solomon parity, optionally AES-128-GCM sealed.
//!
//! Stub: the API is fixed and tested first; the bodies follow.
use super::VideoCipher;
use super::packet::{FRAME_HEADER_LEN, FrameType};
use crate::{Error, Result};
/// The NV header's multi-FEC flags byte (`docs/PROTOCOL.md` 5.2, UNKNOWN U15: sent as observed, meaning unknown).
pub const MULTI_FEC_FLAGS: u8 = 0x10;
/// Byte 0 of the structured frame header (`docs/PROTOCOL.md` 5.2).
pub const FRAME_HEADER_TYPE: u8 = 0x01;
/// Most data shards one frame can carry: [`super::packet::MAX_FEC_BLOCKS`] blocks of at most
/// [`crate::fec::MAX_SHARDS`] shards.
pub const MAX_DATA_SHARDS_PER_FRAME: usize = super::packet::MAX_FEC_BLOCKS * crate::fec::MAX_SHARDS;
/// Settings of the video sender, from the client's ANNOUNCE (`docs/PROTOCOL.md` 2.4).
#[derive(Clone, Debug)]
pub struct VideoPacketizerConfig {
/// Negotiated `packetSize` (payload + 16-byte NV header; the datagram adds the 16-byte RTP part).
pub packet_size: u16,
/// Requested FEC percentage (`x-nv-vqos[0].fec.repairPercent` or equivalent).
pub fec_percentage: u8,
/// Minimum parity packets per block (`x-nv-vqos[0].fec.minRequiredFecPackets`).
pub min_required_fec_packets: u8,
/// Seal every datagram with this cipher when video encryption was negotiated.
pub cipher: Option<VideoCipher>,
/// RTP sequence number of the first datagram.
pub first_sequence: u16,
}
/// One encoded access unit from the encoder.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct EncodedFrame<'a> {
/// Frame index (NV header bytes 20-23).
pub frame_index: u32,
/// Frame type written into the frame header.
pub frame_type: FrameType,
/// RTP timestamp shared by every datagram of the frame (UNKNOWN U29: clock rate).
pub rtp_timestamp: u32,
/// Host processing latency, frame header bytes 1-2 (unit UNKNOWN, U13).
pub processing_latency: u16,
/// The Annex-B bitstream, start codes included.
pub bitstream: &'a [u8],
}
/// The FEC geometry of one block.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct FecBlock {
/// Data shards `k`.
pub data_shards: u16,
/// Parity shards `m = ceil(k × percentage / 100)`.
pub parity_shards: u16,
/// The percentage written into the block's FEC info.
pub fec_percentage: u8,
/// The requested protection did not fit (`k + m <= 255`) and was lowered.
pub reduced: bool,
}
/// Counters.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct VideoPacketizerStats {
/// Frames packetized.
pub frames: u64,
/// Datagrams produced (data + parity).
pub packets: u64,
/// Parity datagrams among them.
pub parity_packets: u64,
/// Blocks whose FEC was lowered to fit 255 shards.
pub fec_reduced_blocks: u64,
}
/// Writes the structured 8-byte frame header (`docs/PROTOCOL.md` 5.2).
#[must_use]
pub fn write_frame_header(
frame_type: FrameType,
processing_latency: u16,
last_payload_len: u32,
) -> [u8; FRAME_HEADER_LEN] {
let _ = (frame_type, processing_latency, last_payload_len);
[0; FRAME_HEADER_LEN]
}
/// Splits `data_shards` into FEC blocks.
///
/// # Errors
/// [`Error::Unimplemented`] (stub).
pub fn plan_fec_blocks(data_shards: usize, fec_percentage: u8, min_parity: u8) -> Result<Vec<FecBlock>> {
let _ = (data_shards, fec_percentage, min_parity);
Err(Error::Unimplemented)
}
/// The video sender of one stream.
#[derive(Debug)]
pub struct VideoPacketizer {
config: VideoPacketizerConfig,
}
impl VideoPacketizer {
/// A sender for one stream.
///
/// # Errors
/// [`Error::Unimplemented`] (stub).
pub fn new(config: VideoPacketizerConfig) -> Result<Self> {
let _ = config;
Err(Error::Unimplemented)
}
/// The largest bitstream one frame can carry.
#[must_use]
pub const fn max_bitstream_len(&self) -> usize {
0
}
/// Packetizes one frame.
///
/// # Errors
/// [`Error::Unimplemented`] (stub).
pub fn packetize(&mut self, frame: &EncodedFrame<'_>) -> Result<Vec<Vec<u8>>> {
let _ = (frame, &self.config);
Err(Error::Unimplemented)
}
/// The RTP sequence number of the next datagram.
#[must_use]
pub const fn next_sequence(&self) -> u16 {
0
}
/// Counters.
#[must_use]
pub const fn stats(&self) -> VideoPacketizerStats {
VideoPacketizerStats { frames: 0, packets: 0, parity_packets: 0, fec_reduced_blocks: 0 }
}
}