Encoder

Struct Encoder 

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

Safe wrapper around a libopus OpusEncoder.

Implementations§

Source§

impl Encoder

Source

pub fn size(channels: Channels) -> Result<usize>

Size in bytes of an encoder state for external allocation.

§Errors

Returns Error::BadArg if the channel count is invalid or libopus reports an impossible size.

Source

pub unsafe fn init_in_place( ptr: *mut OpusEncoder, sample_rate: SampleRate, channels: Channels, application: Application, ) -> Result<()>

Initialize a previously allocated encoder state.

§Safety

The caller must provide a valid pointer to Encoder::size() bytes, aligned to at least align_of::<usize>() (malloc-style alignment).

§Errors

Returns Error::BadArg if ptr is null, or a mapped libopus error.

Source

pub fn new( sample_rate: SampleRate, channels: Channels, application: Application, ) -> Result<Self>

Create a new encoder.

§Errors

Returns an error if allocation fails or arguments are invalid.

Source

pub fn encode(&mut self, input: &[i16], output: &mut [u8]) -> Result<usize>

Encode 16-bit PCM into an Opus packet.

§Errors

Returns Error::InvalidState if the encoder is invalid, Error::BadArg for invalid buffer sizes or frame size, or a mapped libopus error.

Source

pub fn encode_limited( &mut self, input: &[i16], output: &mut [u8], max_data_bytes: usize, ) -> Result<usize>

Encode 16-bit PCM, capping output to max_data_bytes.

Note: This does not itself enable FEC; use set_inband_fec(true) and set_packet_loss_perc(…) to actually make the encoder produce FEC.

§Errors

Returns Error::InvalidState if the encoder is invalid, Error::BadArg for invalid buffer sizes or frame size, or a mapped libopus error.

Source

pub fn encode_float( &mut self, input: &[f32], output: &mut [u8], ) -> Result<usize>

Encode f32 PCM into an Opus packet.

§Errors

Returns Error::InvalidState if the encoder is invalid, Error::BadArg for invalid buffer sizes or frame size, or a mapped libopus error.

Source

pub fn set_inband_fec(&mut self, enabled: bool) -> Result<()>

Enable/disable in-band FEC generation (decoder can recover from losses).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn inband_fec(&mut self) -> Result<bool>

Query in-band FEC setting.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_packet_loss_perc(&mut self, perc: i32) -> Result<()>

Hint expected packet loss percentage [0..=100].

§Errors

Returns Error::InvalidState if the encoder is invalid, Error::BadArg for out-of-range values, or a mapped libopus error.

Source

pub fn packet_loss_perc(&mut self) -> Result<i32>

Query packet loss percentage hint.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_dtx(&mut self, enabled: bool) -> Result<()>

Enable/disable DTX (discontinuous transmission).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn dtx(&mut self) -> Result<bool>

Query DTX setting.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn in_dtx(&mut self) -> Result<bool>

Returns true if encoder is currently in DTX.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_vbr_constraint(&mut self, constrained: bool) -> Result<()>

Constrain VBR to reduce instant bitrate swings.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn vbr_constraint(&mut self) -> Result<bool>

Query VBR constraint setting.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_max_bandwidth(&mut self, bw: Bandwidth) -> Result<()>

Set maximum audio bandwidth the encoder may use.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn max_bandwidth(&mut self) -> Result<Bandwidth>

Query max bandwidth.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_bandwidth(&mut self, bw: Bandwidth) -> Result<()>

Force a specific bandwidth (overrides automatic).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn bandwidth(&mut self) -> Result<Bandwidth>

Query current forced bandwidth.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_force_channels(&mut self, channels: Option<Channels>) -> Result<()>

Force mono/stereo output, or None for automatic.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn force_channels(&mut self) -> Result<Option<Channels>>

Query forced channels.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_signal(&mut self, signal: Signal) -> Result<()>

Hint content type (voice or music).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn signal(&mut self) -> Result<Signal>

Query current signal hint.

§Errors

Returns Error::InvalidState if the encoder is invalid, Error::InternalError if the response is not recognized, or a mapped libopus error.

Source

pub fn lookahead(&mut self) -> Result<i32>

Encoder algorithmic lookahead (in samples at 48 kHz domain).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn final_range(&mut self) -> Result<u32>

Final RNG state from the last encode (debugging/bitstream id).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_lsb_depth(&mut self, bits: i32) -> Result<()>

Set input LSB depth (typically 16-24 bits).

§Errors

Returns Error::InvalidState if the encoder is invalid, Error::BadArg for an out-of-range bit depth, or a mapped libopus error.

Source

pub fn lsb_depth(&mut self) -> Result<i32>

Query input LSB depth.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_expert_frame_duration( &mut self, dur: ExpertFrameDuration, ) -> Result<()>

Set expert frame duration choice.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn expert_frame_duration(&mut self) -> Result<ExpertFrameDuration>

Query expert frame duration.

§Errors

Returns Error::InvalidState if the encoder is invalid, Error::InternalError if the response is not recognized, or a mapped libopus error.

Source

pub fn set_prediction_disabled(&mut self, disabled: bool) -> Result<()>

Disable/enable inter-frame prediction (expert option).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn prediction_disabled(&mut self) -> Result<bool>

Query prediction disabled flag.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_phase_inversion_disabled(&mut self, disabled: bool) -> Result<()>

Disable/enable phase inversion (stereo decorrelation) in CELT (expert option).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn phase_inversion_disabled(&mut self) -> Result<bool>

Query phase inversion disabled flag.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

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

Set target bitrate.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn bitrate(&mut self) -> Result<Bitrate>

Query current bitrate.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_complexity(&mut self, complexity: Complexity) -> Result<()>

Set encoder complexity [0..=10].

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn complexity(&mut self) -> Result<Complexity>

Query encoder complexity.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn set_vbr(&mut self, enabled: bool) -> Result<()>

Enable or disable VBR.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub fn vbr(&mut self) -> Result<bool>

Query VBR status.

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Source

pub const fn sample_rate(&self) -> SampleRate

The encoder’s configured sample rate.

Source

pub const fn channels(&self) -> Channels

The encoder’s channel configuration.

Source

pub fn reset(&mut self) -> Result<()>

Reset the encoder to its initial state (same config, cleared history).

§Errors

Returns Error::InvalidState if the encoder is invalid, or a mapped libopus error.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.