pub struct MultistreamDecoder { /* private fields */ }Expand description
A stateful multistream (multichannel) Opus decoder — RFC 7845 §3 + §5.1.1.
Wraps N independent crate::decoder::OpusDecoder instances (one
per coded stream) and the ChannelMappingTable that ties their
outputs to the stream’s C output channels. Each Ogg packet is split
by split_multistream_packet, every sub-stream is decoded by its
own decoder (so each carries its own inter-frame state), and the
per-stream PCM is assembled into the C-channel interleaved output
per the §5.1.1 mapping rule:
index < 2*M→ output is decoded channelindexof coupled (stereo) streamindex / 2— left ifindexeven, right if odd.2*M ≤ index < 255→ output is mono streamindex − M.index == 255→ pure silence.
The same decoded channel MAY be routed to several output channels; some decoded channels MAY be unused — the §5.1.1 mapping is arbitrary.
Implementations§
Source§impl MultistreamDecoder
impl MultistreamDecoder
Sourcepub fn new(mapping: ChannelMappingTable) -> Self
pub fn new(mapping: ChannelMappingTable) -> Self
Build a decoder for the given §5.1.1 channel-mapping table.
Sourcepub fn from_head(head: &OpusHead) -> Self
pub fn from_head(head: &OpusHead) -> Self
Build a multistream decoder straight from a parsed
OpusHead identification header.
Sourcepub fn mapping(&self) -> &ChannelMappingTable
pub fn mapping(&self) -> &ChannelMappingTable
The §5.1.1 channel-mapping table this decoder was built with.
Sourcepub fn output_channels(&self) -> u8
pub fn output_channels(&self) -> u8
Number of output channels C.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset every per-stream decoder (the §4.5.2 decoder reset, e.g. after a container seek).
Sourcepub fn decode_packet(
&mut self,
packet: &[u8],
) -> Result<MultistreamAudio, Error>
pub fn decode_packet( &mut self, packet: &[u8], ) -> Result<MultistreamAudio, Error>
Decode one multistream Ogg packet into C-channel interleaved
48 kHz PCM.
Splits the packet into its N per-stream Opus packets, decodes
each through its own decoder, and assembles the C output
channels per the §5.1.1 mapping. Index-255 output channels are
filled with silence.
Returns Error::MalformedPacket if the split fails or if a
sub-stream decode fails; the output sample count is taken from the
first stream (RFC 7845 §3 requires every stream in a packet to
have the same duration).