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
impl OpusDecoder
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a fresh decoder with no carried state (equivalent to the
post-reset state of §4.5.2).
Sourcepub fn reset(&mut self)
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.
Sourcepub fn decode_packet(&mut self, packet: &[u8]) -> Result<DecodedAudio, Error>
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.
Sourcepub fn decode_self_delimited_packet(
&mut self,
packet: &[u8],
) -> Result<DecodedAudio, Error>
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.
Sourcepub fn decode_packet_fec(
&mut self,
packet: &[u8],
) -> Result<FecRecovered, Error>
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.