MSEncoder

Struct MSEncoder 

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

Combine individual Opus streams in a single packet, up to 255 channels.

See Opus docs.

Implementations§

Source§

impl MSEncoder

Source

pub fn new( sample_rate: u32, streams: u8, coupled_streams: u8, mapping: &[u8], application: Application, ) -> Result<MSEncoder>

Create and initialize a multistream encoder.

Source

pub fn new_surround( sample_rate: u32, channels: u8, mapping_family: i32, application: Application, ) -> Result<SurroundEncoder>

Create and initialize a multistream encoder for surround sound.

This is a convenience function that automatically determines the optimal stream configuration based on the number of channels and mapping family. It eliminates the need to manually calculate the number of streams, coupled streams, and channel mapping.

§Arguments
  • sample_rate - Sampling rate of input signal (Hz). Must be one of 8000, 12000, 16000, 24000, or 48000.
  • channels - Number of channels in the input signal. This must be at most 255.
  • mapping_family - Mapping family for the surround configuration:
    • 0: Mono or stereo (1 or 2 channels)
    • 1: Vorbis channel order for up to 8 channels
    • 255: No predefined channel ordering (up to 255 channels)
  • application - The application type (Voip, Audio, or LowDelay)
§Returns

Returns a SurroundEncoder containing the initialized encoder and its automatically determined stream configuration.

Examples found in repository?
examples/surround.rs (line 5)
3fn main() {
4    // The new struct-based API is much more readable!
5    let surround = MSEncoder::new_surround(48000, 6, 1, Application::Audio)
6        .expect("Failed to create surround encoder");
7
8    println!("=== Surround Encoder Configuration ===");
9    println!("Streams: {}", surround.streams);
10    println!("Coupled streams: {}", surround.coupled_streams);
11    println!("Channel mapping: {:?}", surround.mapping);
12
13    // You can destructure if you want specific fields
14    let opus2::SurroundEncoder {
15        encoder: _encoder,
16        streams,
17        coupled_streams,
18        mapping,
19    } = surround;
20
21    println!("\n=== Destructured Values ===");
22    println!("Streams: {}", streams);
23    println!("Coupled streams: {}", coupled_streams);
24    println!("Mapping: {:?}", mapping);
25
26    // Now you can use the encoder for encoding
27    // encoder.encode(...);
28    
29    println!("\nEncoder is ready for use!");
30}
Source

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

Encode an Opus frame.

Source

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

Encode an Opus frame from floating point input.

Source

pub fn encode_vec(&mut self, input: &[i16], max_size: usize) -> Result<Vec<u8>>

Encode an Opus frame to a new buffer.

Source

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

Encode an Opus frame from floating point input to a new buffer.

Source§

impl MSEncoder

Generic CTLs. See Opus docs.

Source

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

Reset the codec state to be equivalent to a freshly initialized state.

Source

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

Get the final range of the codec’s entropy coder.

Source

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

Get the encoder’s configured bandpass.

Source

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

Get the samping rate the encoder was intialized with.

Source

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

If set to true, disables the use of phase inversion for intensity stereo.

Source

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

Get the encoder’s configured phase inversion status.

Source

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

Get the DTX state of the encoder.

Source§

impl MSEncoder

Encoder CTLs. See Opus docs.

Source

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

Configures the encoder’s computational complexity.

Source

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

Gets the encoder’s complexity configuration.

Source

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

Set the encoder’s bitrate.

Source

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

Get the encoder’s bitrate.

Source

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

Enable or disable variable bitrate.

Source

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

Determine if variable bitrate is enabled.

Source

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

Enable or disable constrained VBR.

Source

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

Determine if constrained VBR is enabled.

Source

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

Configures mono/stereo forcing in the encoder.

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_force_channels(&mut self) -> Result<Option<Channels>>

Gets the encoder’s forced channel configuration.

Source

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

Configure the maximum bandpass that the encoder will select automatically.

Source

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

Get the encoder’s configured maximum allowed bandpass.

Source

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

Set the encoder’s bandpass to a specific value.

Source

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

Configure the type of signal being encoded.

Source

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

Gets the encoder’s configured signal type.

Source

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

Configure the encoder’s intended application.

Source

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

Get the encoder’s configured application.

Source

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

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

Source

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

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

Source

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

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

Source

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

Sets the encoder’s expected packet loss percentage.

Source

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

Gets the encoder’s expected packet loss percentage.

Source

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

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

Source

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

Gets encoder’s configured use of discontinuous transmission (DTX).

Source

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

Configures the depth of signal being encoded.

Depth should be between 8 and 24 inclusive.

Source

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

Gets the encoder’s configured signal depth.

Source

pub fn set_expert_frame_duration(&mut self, framesize: FrameSize) -> Result<()>

Configures the encoder’s use of variable duration frames.

Do not use this option unless you really know what you are doing.

Source

pub fn get_expert_frame_duration(&mut self) -> Result<FrameSize>

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

Source

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

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

Source

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

Gets the encoder’s configured prediction status.

Source

pub fn set_dred_duration(&mut self, duration_ms: i32) -> Result<()>

Set the DRED duration in milliseconds.

The duration must be between 0 and 20000 (20 seconds). DRED (Deep REDundancy) provides additional redundancy information that can be used for packet loss recovery. This feature is available since Opus 1.5.

Source

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

Get the configured DRED duration in milliseconds.

DRED (Deep REDundancy) provides additional redundancy information that can be used for packet loss recovery. This feature is available since Opus 1.5.

Source

pub fn set_dnn_blob(&mut self, blob: &[u8]) -> Result<()>

Set a DNN (Deep Neural Network) model blob for the encoder.

This allows loading custom neural network models for enhanced encoding. The blob should contain a trained DNN model in the format expected by libopus. This feature is available since Opus 1.5.

Trait Implementations§

Source§

impl Debug for MSEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MSEncoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for MSEncoder

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.