pub struct OpusDecoder { /* private fields */ }Expand description
Stateful Opus decoder for one inbound stream.
Also not Copy — the decoder state is what makes
conceal and decode_fec
possible, so it must see every packet of its stream in order.
Implementations§
Source§impl OpusDecoder
impl OpusDecoder
Sourcepub fn decode(
&mut self,
payload: &[u8],
out: &mut Vec<i16>,
) -> Result<usize, CoreError>
pub fn decode( &mut self, payload: &[u8], out: &mut Vec<i16>, ) -> Result<usize, CoreError>
Decode one received Opus packet. Appends the PCM samples to out
and returns how many were produced.
The count is normally OPUS_FRAME_SAMPLES but the far end
chooses its own frame size — up to OPUS_MAX_FRAME_SAMPLES —
so consumers must use the returned length, not assume 20 ms.
Sourcepub fn decode_fec(
&mut self,
next_payload: &[u8],
out: &mut Vec<i16>,
) -> Result<usize, CoreError>
pub fn decode_fec( &mut self, next_payload: &[u8], out: &mut Vec<i16>, ) -> Result<usize, CoreError>
Recover a lost frame from the packet that followed it.
Call this when a sequence gap shows exactly one packet was lost:
pass the packet after the gap, and the decoder reconstructs the
missing frame from that packet’s embedded redundancy (falling
back to concealment when the sender embedded none). Then decode
the passed packet normally with decode — this
call consumes only its redundancy, not its own frame.
Sourcepub fn conceal(&mut self, out: &mut Vec<i16>) -> Result<usize, CoreError>
pub fn conceal(&mut self, out: &mut Vec<i16>) -> Result<usize, CoreError>
Produce one concealment frame for a packet that never arrived and can’t be recovered (no follow-up packet yet, or a multi-packet gap). The decoder extrapolates from what it last heard, which sounds far better than a gap of silence.