Skip to main content

Encoder

Enum Encoder 

Source
pub enum Encoder {
    G711(G711Codec),
    Opus(OpusEncoder),
}
Expand description

The encode half of a negotiated call codec.

G.711 is a stateless table lookup (the enum just carries the μ-law/A-law choice); Opus owns a heap-backed encoder with inter-frame state. Either way: feed one 20 ms frame at pcm_sample_rate per call, in order.

Variants§

§

G711(G711Codec)

PCMU or PCMA.

§

Opus(OpusEncoder)

Opus, wideband voice profile.

Implementations§

Source§

impl Encoder

Source

pub fn pcm_sample_rate(&self) -> u32

The PCM rate this encoder consumes: 8 kHz for G.711, 16 kHz for Opus. Resample the microphone to this, not to a global constant.

Source

pub fn frame_samples(&self) -> usize

Samples in one 20 ms frame at pcm_sample_rate: 160 for G.711, 320 for Opus.

Source

pub fn encode( &mut self, pcm: &[i16], out: &mut Vec<u8>, ) -> Result<usize, CoreError>

Encode one 20 ms frame, appending the payload bytes to out and returning the payload length. G.711 cannot fail; Opus errors surface (wrong frame length, libopus failure).

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.