Skip to main content

Encoder

Struct Encoder 

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

Audio encoder over the PCM layout declared in Config::input.

Build one with Encoder::new, feed full PCM frames via encode, then pass the trailing partial frame to finish. Publish every packet either call returns and apply the terminal Finish::discard_padding when the container supports it.

Implementations§

Source§

impl Encoder

Source

pub fn new(config: &Config) -> Result<Self, Error>

Open an encoder for config.

Source

pub fn config(&self) -> &Config

The encoder config, including the latest accepted runtime bitrate.

Source

pub fn codec(&self) -> Codec

The codec this encoder emits. A Producer must be built for the same codec to publish its packets.

Source

pub fn codec_rate(&self) -> u32

Sample rate the codec actually runs at, which is Config::sample_rate resolved.

Source

pub fn codec_channels(&self) -> u32

Channel count the codec actually runs at, which is Config::channels resolved.

Source

pub fn frame_size(&self) -> usize

Number of samples per channel the codec consumes per call to encode.

Source

pub fn bitrate(&self) -> u64

Current target bitrate in bits per second.

Source

pub fn set_bitrate(&mut self, bitrate: u64) -> Result<(), Error>

Retune the live Opus encoder to bitrate bits per second.

Source

pub fn encode(&mut self, pcm: &[f32]) -> Result<Bytes, Error>

Encode one frame of interleaved f32 PCM at codec_rate.

pcm.len() must equal frame_size() * codec_channels(). The Producer handles format conversion and resampling before calling this; for direct use, the caller does the same.

Source

pub fn finish(self, pcm: &[f32]) -> Result<Finish, Error>

Finish encoding, zero-padding pcm as the final partial frame and returning every packet needed to drain codec lookahead.

pcm is interleaved at codec_rate, may be empty, and must contain at most one frame. Silence added here only drains audio already supplied; Finish::discard_padding reports how much of the decoded tail is artificial and must not count as source duration. Consuming the encoder prevents encoding across the artificial terminal padding.

Source

pub fn catalog(&self) -> AudioConfig

hang catalog entry describing this encoder’s output stream.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

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

Source§

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

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more