#[non_exhaustive]pub struct Config {
pub sample_rate: u32,
pub channel_count: u32,
pub pre_skip: u16,
}Expand description
Typed Opus configuration mirroring the parsed fields of an OpusHead packet.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.sample_rate: u32Original input sample rate in Hz.
channel_count: u32Number of encoded channels.
pre_skip: u16Number of decoded 48 kHz samples to discard at stream start.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new(sample_rate: u32, channel_count: u32) -> Self
pub fn new(sample_rate: u32, channel_count: u32) -> Self
Build a mono/stereo Opus config with no pre-skip.
Sourcepub fn with_pre_skip(self, pre_skip: u16) -> Self
pub fn with_pre_skip(self, pre_skip: u16) -> Self
Set the number of decoded 48 kHz samples to discard at stream start.
Sourcepub fn parse<T: Buf>(buf: &mut T) -> Result<Self>
pub fn parse<T: Buf>(buf: &mut T) -> Result<Self>
Parse an OpusHead buffer (RFC 7845 §5.1).
Verifies the magic signature; reads channel count, pre-skip, and sample rate; ignores gain and channel mapping. Any trailing bytes are consumed.
Sourcepub fn encode(&self) -> Result<Bytes>
pub fn encode(&self) -> Result<Bytes>
Encode the minimal OpusHead packet (19 bytes; channel mapping family 0 and zero gain).
Errors with Error::UnsupportedChannelCount unless channel_count is 1
or 2, since mapping family 0 is only defined for mono/stereo per RFC 7845 §5.1.
Multi-channel streams need family 1 with a channel mapping table, which
this helper does not emit.