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
impl Encoder
Sourcepub fn config(&self) -> &Config
pub fn config(&self) -> &Config
The encoder config, including the latest accepted runtime bitrate.
Sourcepub fn codec(&self) -> Codec
pub fn codec(&self) -> Codec
The codec this encoder emits. A Producer must be
built for the same codec to publish its packets.
Sourcepub fn codec_rate(&self) -> u32
pub fn codec_rate(&self) -> u32
Sample rate the codec actually runs at, which is
Config::sample_rate resolved.
Sourcepub fn codec_channels(&self) -> u32
pub fn codec_channels(&self) -> u32
Channel count the codec actually runs at, which is
Config::channels resolved.
Sourcepub fn frame_size(&self) -> usize
pub fn frame_size(&self) -> usize
Number of samples per channel the codec consumes per call to
encode.
Sourcepub fn set_bitrate(&mut self, bitrate: u64) -> Result<(), Error>
pub fn set_bitrate(&mut self, bitrate: u64) -> Result<(), Error>
Retune the live Opus encoder to bitrate bits per second.
Sourcepub fn encode(&mut self, pcm: &[f32]) -> Result<Bytes, Error>
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.
Sourcepub fn finish(self, pcm: &[f32]) -> Result<Finish, Error>
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.
Sourcepub fn catalog(&self) -> AudioConfig
pub fn catalog(&self) -> AudioConfig
hang catalog entry describing this encoder’s output stream.