Skip to main content

OpusDecoder

Struct OpusDecoder 

Source
pub struct OpusDecoder { /* private fields */ }
Expand description

Stateful Opus packet → PCM decoder.

One OpusDecoder is fed Opus packets in stream order via Self::decode_packet. The decoder is stateful because the SILK and CELT layers carry inter-frame state (LPC / LTP history, MDCT overlap, stereo unmixing memory, the §4.5.2 reset policy); the state lives here and is threaded into the per-frame decode as those paths land. Today the carried state is minimal (it grows as each layer is wired), but the type is the stable home for it.

Implementations§

Source§

impl OpusDecoder

Source

pub fn new() -> Self

Construct a fresh decoder with no carried state (equivalent to the post-reset state of §4.5.2).

Source

pub fn reset(&mut self)

Discard all inter-frame state, as after a container seek (the §4.5.2 decoder reset). Leaves the decoder ready to decode a new bitstream position as if it were the first packet.

Source

pub fn decode_packet(&mut self, packet: &[u8]) -> Result<DecodedAudio, Error>

Decode one complete Opus packet into interleaved 48 kHz PCM.

Performs the §3.1 TOC parse, the §3.2 frame split, and the §4.5 multi-frame loop, dispatching each Opus frame through its OpusFrameRouting to the matching per-mode decode. Returns Error::EmptyPacket for a zero-length packet (§3.1 R1) and Error::MalformedPacket for any §3.2 framing violation.

Source

pub fn decode_self_delimited_packet( &mut self, packet: &[u8], ) -> Result<DecodedAudio, Error>

Decode one complete Opus packet that uses RFC 6716 Appendix-B self-delimited framing (the framing the first N − 1 streams of a multistream packet use, RFC 7845 §3). Behaves exactly like Self::decode_packet otherwise — the only difference is how the frame slices are recovered from the packet bytes.

Source

pub fn decode_packet_fec( &mut self, packet: &[u8], ) -> Result<FecRecovered, Error>

Recover the audio of a lost Opus frame from the in-band FEC (§4.2.5 LBRR) data carried in the next successfully received packet (RFC 6716 §2.1.7).

In-band FEC encodes a low-bitrate redundant copy of the signal immediately prior to a packet as one or more §4.2.5 LBRR frames inside that packet. When the application detects a packet loss and has the following packet in hand, it calls this method on that following packet to reconstruct the lost frame’s audio instead of relying solely on silence / pitch-based concealment.

The recovered PCM is returned at the 48 kHz output rate. The packet passed here is the one after the loss; only its §4.2.5 LBRR frames are decoded and synthesized (the packet’s own regular frames are decoded later by an ordinary Self::decode_packet call).

On success (FecDecodeStatus::Recovered) the SILK synthesis history is advanced to the recovered frame’s state, so a subsequent Self::decode_packet on the same packet continues smoothly from the reconstructed signal. When the packet carries no LBRR data (FecDecodeStatus::NoLbrr), is CELT-only (FecDecodeStatus::NotSilk), or is malformed (FecDecodeStatus::DecodeError), silence of the lost frame’s duration is returned and the caller falls back to its own concealment.

Returns Error::EmptyPacket for a zero-length packet and Error::MalformedPacket for a §3.2 framing violation in the carrier packet.

Trait Implementations§

Source§

impl Debug for OpusDecoder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for OpusDecoder

Source§

fn default() -> OpusDecoder

Returns the “default value” for a type. 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.