[domistream] Audio packetizer: tests first (round trips through AudioDepacketizer, wrap-around, caps, fixed vectors), API stubs
This commit is contained in:
@@ -18,8 +18,10 @@ use crate::util::malformed;
|
||||
use crate::{Error, Instant, Result, SessionKeys};
|
||||
|
||||
pub mod packet;
|
||||
pub mod packetizer;
|
||||
|
||||
pub use packet::{AudioFecHeader, AudioPacket, parse_audio_packet};
|
||||
pub use packetizer::{AudioPacketizer, AudioPacketizerConfig, AudioParity};
|
||||
|
||||
/// Data packets per FEC block.
|
||||
pub const DATA_SHARDS: usize = 4;
|
||||
@@ -78,6 +80,17 @@ impl AudioCipher {
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioCipher {
|
||||
/// Encrypts one payload (host side).
|
||||
///
|
||||
/// # Errors
|
||||
/// [`Error::Unimplemented`] (stub).
|
||||
pub fn encrypt(&self, sequence: u16, plaintext: &[u8]) -> Result<Vec<u8>> {
|
||||
let _ = (sequence, plaintext, &self.key);
|
||||
Err(Error::Unimplemented)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for AudioCipher {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("AudioCipher(<redacted>)")
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//! The audio send path, host side (`docs/PROTOCOL.md` 6.2, 6.3): one Opus packet → one RTP datagram.
|
||||
//!
|
||||
//! Stub: the API is fixed and tested first; the bodies follow.
|
||||
|
||||
use super::AudioCipher;
|
||||
use crate::{Error, Result};
|
||||
|
||||
/// Largest Opus packet sent in the clear: the datagram cap minus the RTP header.
|
||||
pub const MAX_OPUS_PLAIN_BYTES: usize = super::packet::MAX_AUDIO_PACKET_BYTES - crate::rtp::RTP_HEADER_LEN;
|
||||
/// Largest Opus packet sent encrypted: PKCS#7 always adds 1 to 16 bytes, and the ciphertext must fit the cap.
|
||||
pub const MAX_OPUS_ENCRYPTED_BYTES: usize = MAX_OPUS_PLAIN_BYTES / 16 * 16 - 1;
|
||||
|
||||
/// Which audio parity packets are sent.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum AudioParity {
|
||||
/// None.
|
||||
#[default]
|
||||
None,
|
||||
}
|
||||
|
||||
/// Settings of the audio sender.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AudioPacketizerConfig {
|
||||
/// Encrypt payloads with this cipher.
|
||||
pub cipher: Option<AudioCipher>,
|
||||
/// Packet duration in milliseconds (`x-nv-aqos.packetDuration`).
|
||||
pub packet_duration_ms: u8,
|
||||
/// Parity packets.
|
||||
pub parity: AudioParity,
|
||||
/// RTP sequence number of the first packet.
|
||||
pub first_sequence: u16,
|
||||
/// RTP timestamp (milliseconds) of the first packet.
|
||||
pub first_timestamp_ms: u32,
|
||||
}
|
||||
|
||||
/// The audio sender of one stream.
|
||||
#[derive(Debug)]
|
||||
pub struct AudioPacketizer {
|
||||
config: AudioPacketizerConfig,
|
||||
}
|
||||
|
||||
impl AudioPacketizer {
|
||||
/// A sender for one stream.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`Error::Unimplemented`] (stub).
|
||||
pub fn new(config: AudioPacketizerConfig) -> Result<Self> {
|
||||
let _ = config;
|
||||
Err(Error::Unimplemented)
|
||||
}
|
||||
|
||||
/// The largest Opus packet accepted.
|
||||
#[must_use]
|
||||
pub const fn max_opus_len(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
/// Packetizes one Opus packet.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`Error::Unimplemented`] (stub).
|
||||
pub fn packetize(&mut self, opus: &[u8]) -> Result<Vec<Vec<u8>>> {
|
||||
let _ = (opus, &self.config);
|
||||
Err(Error::Unimplemented)
|
||||
}
|
||||
|
||||
/// The RTP sequence number of the next packet.
|
||||
#[must_use]
|
||||
pub const fn next_sequence(&self) -> u16 {
|
||||
0
|
||||
}
|
||||
|
||||
/// The RTP timestamp (milliseconds) of the next packet.
|
||||
#[must_use]
|
||||
pub const fn next_timestamp_ms(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user