Skip to main content

PcmEncoder

Enum PcmEncoder 

Source
pub(crate) enum PcmEncoder {
    Stereo(Encoder),
    Multi(MultiOpus),
}
Expand description

One encode surface over both Opus APIs: the opus crate for mono/stereo, and the raw multistream C API for 6/8-channel surround.

Variants§

§

Stereo(Encoder)

§

Multi(MultiOpus)

Implementations§

Source§

impl PcmEncoder

Source

pub(crate) fn new( sample_rate: u32, channels: i32, vbr: bool, bitrate: i32, ) -> Result<Self, String>

Build the Opus encoder for a channel count, selecting the API by width.

  • Mono/stereo (channels <= 2): the safe opus crate encoder in LowDelay application mode; a failure to apply the initial bitrate or VBR mode is logged but not fatal.
  • Surround (6/8): the raw multistream C encoder created from multiopus_layout in RESTRICTED_LOWDELAY; an unsupported channel count is a hard error.

Bitrate and VBR are applied at creation and can be retuned live via set_bitrate.

Source

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

Encode one interleaved-PCM frame into out, returning the packet byte length.

Dispatches to the opus crate (mono/stereo) or the raw multistream encode (surround, which needs the explicit frame_size_per_channel). Either error surfaces as a String.

Source

pub(crate) fn set_bitrate(&mut self, bits: i32) -> Result<(), String>

Retune the encoder’s target bitrate live (bits/s), for either API.

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

impl<T> Ungil for T
where T: Send,