Skip to main content

MultistreamDecoder

Struct MultistreamDecoder 

Source
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 channel index of coupled (stereo) stream index / 2 — left if index even, right if odd.
  • 2*M ≤ index < 255 → output is mono stream index − 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

Source

pub fn new(mapping: ChannelMappingTable) -> Self

Build a decoder for the given §5.1.1 channel-mapping table.

Source

pub fn from_head(head: &OpusHead) -> Self

Build a multistream decoder straight from a parsed OpusHead identification header.

Source

pub fn mapping(&self) -> &ChannelMappingTable

The §5.1.1 channel-mapping table this decoder was built with.

Source

pub fn output_channels(&self) -> u8

Number of output channels C.

Source

pub fn reset(&mut self)

Reset every per-stream decoder (the §4.5.2 decoder reset, e.g. after a container seek).

Source

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).

Trait Implementations§

Source§

impl Debug for MultistreamDecoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.