Encoder

Struct Encoder 

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

OPUS encoder

Implementations§

Source§

impl Encoder

Source

pub fn new( channels: Channels, rate: SampleRate, app: Application, ) -> Result<Self, ErrorCode>

Creates new encoder instance

Source

pub fn channels(&self) -> Channels

Returns channels number

When encoding, it is used to determine frame size as input.len() / channels

Source

pub fn encode_to( &mut self, input: &[u16], output: &mut [MaybeUninit<u8>], ) -> Result<usize, ErrorCode>

Encodes an Opus frame, returning number of bytes written.

If more than 1 channel is configured, then input must be interleaved.

Input size must correspond to sampling rate. For example, at 48 kHz allowed frame sizes are 120, 240, 480, 960, 1920, and 2880. Passing in a duration of less than 10 ms (480 samples at 48 kHz) will prevent the encoder from using the LPC or hybrid modes.

Source

pub fn encode_to_slice( &mut self, input: &[u16], output: &mut [u8], ) -> Result<usize, ErrorCode>

Encodes an Opus frame, returning number of bytes written.

Refer to encode_to for details

Source

pub fn encode_to_vec( &mut self, input: &[u16], output: &mut Vec<u8>, ) -> Result<usize, ErrorCode>

Encodes an Opus frame, returning number of bytes written.

Vector will be written into spare capacity, modifying its length on success.

It is user responsibility to reserve correct amount of space

Refer to encode_to for details

Source

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

Encodes an Opus frame, returning number of bytes written.

If more than 1 channel is configured, then input must be interleaved.

Input size must correspond to sampling rate. For example, at 48 kHz allowed frame sizes are 120, 240, 480, 960, 1920, and 2880. Passing in a duration of less than 10 ms (480 samples at 48 kHz) will prevent the encoder from using the LPC or hybrid modes.

§Note

When using float API, input with a normal range of +/-1.0 should be preferred. Samples with a range beyond +/-1.0 are supported but will be clipped by decoders using the integer API and should only be used if it is known that the far end supports extended dynamic range

Source

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

Encodes an Opus frame, returning number of bytes written.

Refer to encode_to for details

Source

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

Encodes an Opus frame, returning number of bytes written.

Vector will be written into spare capacity, modifying its length on success.

It is user responsibility to reserve correct amount of space

Refer to encode_to for details

Source

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

Resets state to initial state

Source

pub fn get_look_ahead(&mut self) -> Result<u32, ErrorCode>

Gets the total samples of delay added by the entire codec.

From the perspective of a decoding application the real data begins this many samples late.

Source

pub fn get_bitrate(&mut self) -> Result<Bitrate, ErrorCode>

Gets the encoder’s bitrate configuration.

Source

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

Configures the encoder’s bitrate

Source

pub fn get_vbr(&mut self) -> Result<bool, ErrorCode>

Determine if variable bitrate (VBR) is enabled in the encoder.

Source

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

Enables or disables variable bitrate (VBR) in the encoder.

The configured bitrate may not be met exactly because frames must be an integer number of bytes in length.

Source

pub fn get_vbr_constraint(&mut self) -> Result<bool, ErrorCode>

Determine if constrained VBR is enabled in the encoder.

Source

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

Enables or disables constrained VBR in the encoder.

This setting is ignored when the encoder is in CBR mode.

§Note

Only the MDCT mode of Opus currently heeds the constraint. Speech mode ignores it completely, hybrid mode may fail to obey it if the LPC layer uses more bitrate than the constraint would have permitted.

Source

pub fn get_force_channels(&mut self) -> Result<Option<Channels>, ErrorCode>

Gets the encoder’s forced channel configuration (if set).

Source

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

Configures mono/stereo forcing in the encoder (or disables it by specifying None).

This can force the encoder to produce packets encoded as either mono or stereo, regardless of the format of the input audio. This is useful when the caller knows that the input signal is currently a mono source embedded in a stereo stream.

Source

pub fn get_complexity(&mut self) -> Result<u8, ErrorCode>

Gets the encoder’s complexity configuration.

Source

pub fn set_complexity(&mut self, value: u8) -> Result<(), ErrorCode>

Configures the encoder’s computational complexity.

The supported range is 0-10 inclusive with 10 representing the highest complexity.

Source

pub fn get_signal(&mut self) -> Result<Signal, ErrorCode>

Gets the encoder’s configured signal type.

Source

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

Configures the type of signal being encoded.

This is a hint which helps the encoder’s mode selection.

Source

pub fn get_application(&mut self) -> Result<Application, ErrorCode>

Gets the encoder’s configured application.

Source

pub fn set_application(&mut self, value: Application) -> Result<(), ErrorCode>

Configures the encoder’s intended application.

The initial value is a mandatory argument to encoder constructor.

Source

pub fn get_bandwidth(&mut self) -> Result<Bandwidth, ErrorCode>

Gets the encoder’s configured bandpass

Source

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

Sets the encoder’s bandpass to a specific value.

This prevents the encoder from automatically selecting the bandpass based on the available bitrate. If an application knows the bandpass of the input audio it is providing, it should normally use set_max_bandwidth instead, which still gives the encoder the freedom to reduce the bandpass when the bitrate becomes too low, for better overall quality.

Source

pub fn get_max_bandwidth(&mut self) -> Result<Bandwidth, ErrorCode>

Gets the encoder’s configured maximum allowed bandpass.

Source

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

Configures the maximum bandpass that the encoder will select automatically.

Applications should normally use this instead of set_bandwidth (leaving that set to the default, Bandwidth::Auto). This allows the application to set an upper bound based on the type of input it is providing, but still gives the encoder the freedom to reduce the bandpass when the bitrate becomes too low, for better overall quality.

Source

pub fn get_inband_fec(&mut self) -> Result<InbandFec, ErrorCode>

Gets encoder’s configured use of inband forward error correction.

Source

pub fn set_inband_fec(&mut self, value: InbandFec) -> Result<(), ErrorCode>

Configures the encoder’s use of inband forward error correction (FEC).

§Note

This is only applicable to the LPC layer

Source

pub fn get_packet_loss(&mut self) -> Result<u8, ErrorCode>

Gets the encoder’s configured packet loss percentage.

Source

pub fn set_packet_loss(&mut self, value: u8) -> Result<(), ErrorCode>

Configures the encoder’s expected packet loss percentage (Allowed values are 0..=100).

Higher values trigger progressively more loss resistant behavior in the encoder at the expense of quality at a given bitrate in the absence of packet loss, but greater quality under loss.

Source

pub fn get_prediction_disabled(&mut self) -> Result<bool, ErrorCode>

Gets the encoder’s configured prediction status.

Source

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

If set to true, disables almost all use of prediction, making frames almost completely independent.

This reduces quality.

Source

pub fn get_lsb_depth(&mut self) -> Result<u8, ErrorCode>

Gets the encoder’s configured signal depth.

Source

pub fn set_lsb_depth(&mut self, value: u8) -> Result<(), ErrorCode>

Configures the depth of signal being encoded (Defaults to 24) in range 8 to 24.

This is a hint which helps the encoder identify silence and near-silence. It represents the number of significant bits of linear intensity below which the signal contains ignorable quantization or other noise.

For example, 14 would be an appropriate setting for G.711 u-law input. 16 would be appropriate for 16-bit linear pcm input with encode_float.

When using encode instead of encode_float, or when libopus is compiled for fixed-point, the encoder uses the minimum of the value set here and the value 16.

Source

pub fn get_frame_duration(&mut self) -> Result<FrameDuration, ErrorCode>

Gets the encoder’s configured use of variable duration frames.

Source

pub fn set_frame_duration( &mut self, value: FrameDuration, ) -> Result<(), ErrorCode>

Configures the encoder’s use of variable duration frames.

When variable duration is enabled, the encoder is free to use a shorter frame size than the one requested in the encode call. It is then the user’s responsibility to verify how much audio was encoded by checking the ToC byte of the encoded packet. The part of the audio that was not encoded needs to be resent to the encoder for the next call. Do not use this option unless you really know what you are doing.

Source

pub fn get_dred_duration(&mut self) -> Result<u8, ErrorCode>

Gets the encoder’s configured Deep Redundancy (DRED) maximum number of frames.

Source

pub fn set_dred_duration(&mut self, value: u8) -> Result<(), ErrorCode>

Configures value of Deep Redundancy (DRED) in range 0..=104

If non-zero, enables DRED and use the specified maximum number of 10-ms redundant frames.

Source

pub fn get_sample_rate(&mut self) -> Result<SampleRate, ErrorCode>

Gets configured sample rate of this instance

Source

pub fn get_dtx(&mut self) -> Result<bool, ErrorCode>

Access encoder’s DTX value

Source

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

Configures the encoder’s use of discontinuous transmission (DTX).

This is only applicable to the LPC layer

Source

pub fn get_phase_inversion_disabled(&mut self) -> Result<bool, ErrorCode>

Gets the encoder’s configured phase inversion status.

Source

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

Configures phase inversion.

If set to true, disables the use of phase inversion for intensity stereo, improving the quality of mono downmixes, but slightly reducing normal stereo quality.

Trait Implementations§

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.