Files
DomiStream/crates/domistream/src/rtp.rs
T
mnovak 30a7b90034 [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.
2026-11-25 14:10:24 +01:00

44 lines
1.6 KiB
Rust

//! The 12-byte RTP header shared by video and audio ([RFC 3550] §5.1, `docs/PROTOCOL.md` 5.2, 6.2).
//!
//! [RFC 3550]: https://www.rfc-editor.org/rfc/rfc3550
/// Length of the fixed RTP header.
pub const RTP_HEADER_LEN: usize = 12;
/// The fixed RTP header. Fields are big-endian on the wire. The first byte is kept raw (version 2 plus flags:
/// `0x90` for video, `0x80` for audio).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct RtpHeader {
/// Byte 0: version, padding, extension, CSRC count.
pub flags: u8,
/// Byte 1: payload type (video 0, audio 97, audio parity 127).
pub payload_type: u8,
/// Sequence number.
pub sequence: u16,
/// Timestamp.
pub timestamp: u32,
/// SSRC.
pub ssrc: u32,
}
/// Parses the first [`RTP_HEADER_LEN`] bytes of `packet` (the rest is ignored here). Refuses a version other
/// than 2.
///
/// # Errors
/// [`crate::Error::Truncated`] for fewer than 12 bytes, [`crate::Error::UnexpectedValue`] for another RTP version.
pub fn parse_rtp_header(packet: &[u8]) -> crate::Result<RtpHeader> {
const W: &str = "rtp header";
crate::util::need(W, RTP_HEADER_LEN, packet.len())?;
let flags = crate::util::byte(W, packet, 0)?;
if flags >> 6 != 2 {
return Err(crate::Error::UnexpectedValue { what: "rtp version", value: (flags >> 6).into() });
}
Ok(RtpHeader {
flags,
payload_type: crate::util::byte(W, packet, 1)?,
sequence: crate::util::u16_be(W, packet, 2)?,
timestamp: crate::util::u32_be(W, packet, 4)?,
ssrc: crate::util::u32_be(W, packet, 8)?,
})
}