[domistream] Audio API: packet parser, CBC decryption, 4+2 FEC depacketizer

This commit is contained in:
2026-11-25 11:48:04 +01:00
parent b4a21dfc10
commit 31d1fc3655
3 changed files with 233 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
//! The audio packet layout (`docs/PROTOCOL.md` 6.2): RTP header, then the Opus payload (payload type 97) or a
//! 12-byte FEC header plus parity (payload type 127). FEC header fields are big-endian.
use crate::rtp::RtpHeader;
/// Payload type of audio data packets.
pub const AUDIO_PAYLOAD_TYPE: u8 = 97;
/// Payload type of audio parity packets.
pub const AUDIO_FEC_PAYLOAD_TYPE: u8 = 127;
/// Length of the FEC header in parity packets.
pub const AUDIO_FEC_HEADER_LEN: usize = 12;
/// Maximum size of one audio packet, in bytes.
pub const MAX_AUDIO_PACKET_BYTES: usize = 2048;
/// The FEC header of a parity packet.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AudioFecHeader {
/// Parity shard index, 0 or 1.
pub shard_index: u8,
/// Payload type of the protected packets (97).
pub payload_type: u8,
/// Sequence number of the block's first data packet.
pub base_sequence: u16,
/// Timestamp of the block's first data packet.
pub base_timestamp: u32,
/// SSRC.
pub ssrc: u32,
}
/// One audio packet.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AudioPacket<'a> {
/// Opus data (still encrypted when audio encryption is on).
Data {
/// RTP header.
rtp: RtpHeader,
/// Payload.
payload: &'a [u8],
},
/// Parity.
Parity {
/// RTP header.
rtp: RtpHeader,
/// FEC header.
fec: AudioFecHeader,
/// Parity bytes.
parity: &'a [u8],
},
}
/// Parses one audio packet.
///
/// # Errors
/// [`crate::Error::TooLarge`] over [`MAX_AUDIO_PACKET_BYTES`], [`crate::Error::Truncated`] for a cut header or an
/// empty payload, [`crate::Error::UnexpectedValue`] for another payload type or a parity shard index above 1.
/// Phase A: always [`crate::Error::Unimplemented`].
pub fn parse_audio_packet(packet: &[u8]) -> crate::Result<AudioPacket<'_>> {
let _ = packet;
Err(crate::Error::Unimplemented)
}