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
impl MSEncoder
Sourcepub fn new(
sample_rate: u32,
streams: u8,
coupled_streams: u8,
mapping: &[u8],
application: Application,
) -> Result<MSEncoder>
pub fn new( sample_rate: u32, streams: u8, coupled_streams: u8, mapping: &[u8], application: Application, ) -> Result<MSEncoder>
Create and initialize a multistream encoder.
Sourcepub fn new_surround(
sample_rate: u32,
channels: u8,
mapping_family: i32,
application: Application,
) -> Result<SurroundEncoder>
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 channels255: 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?
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}Sourcepub fn encode(&mut self, input: &[i16], output: &mut [u8]) -> Result<usize>
pub fn encode(&mut self, input: &[i16], output: &mut [u8]) -> Result<usize>
Encode an Opus frame.
Sourcepub fn encode_float(
&mut self,
input: &[f32],
output: &mut [u8],
) -> Result<usize>
pub fn encode_float( &mut self, input: &[f32], output: &mut [u8], ) -> Result<usize>
Encode an Opus frame from floating point input.
Source§impl MSEncoder
Generic CTLs. See Opus docs.
impl MSEncoder
Generic CTLs. See Opus docs.
Sourcepub fn reset_state(&mut self) -> Result<()>
pub fn reset_state(&mut self) -> Result<()>
Reset the codec state to be equivalent to a freshly initialized state.
Sourcepub fn get_final_range(&mut self) -> Result<u32>
pub fn get_final_range(&mut self) -> Result<u32>
Get the final range of the codec’s entropy coder.
Sourcepub fn get_bandwidth(&mut self) -> Result<Bandwidth>
pub fn get_bandwidth(&mut self) -> Result<Bandwidth>
Get the encoder’s configured bandpass.
Sourcepub fn get_sample_rate(&mut self) -> Result<u32>
pub fn get_sample_rate(&mut self) -> Result<u32>
Get the samping rate the encoder was intialized with.
Sourcepub fn set_phase_inversion_disabled(&mut self, disabled: bool) -> Result<()>
pub fn set_phase_inversion_disabled(&mut self, disabled: bool) -> Result<()>
If set to true, disables the use of phase inversion for intensity stereo.
Sourcepub fn get_phase_inversion_disabled(&mut self) -> Result<bool>
pub fn get_phase_inversion_disabled(&mut self) -> Result<bool>
Get the encoder’s configured phase inversion status.
Sourcepub fn get_in_dtx(&mut self) -> Result<bool>
pub fn get_in_dtx(&mut self) -> Result<bool>
Get the DTX state of the encoder.
Source§impl MSEncoder
Encoder CTLs. See Opus docs.
impl MSEncoder
Encoder CTLs. See Opus docs.
Sourcepub fn set_complexity(&mut self, value: i32) -> Result<()>
pub fn set_complexity(&mut self, value: i32) -> Result<()>
Configures the encoder’s computational complexity.
Sourcepub fn get_complexity(&mut self) -> Result<i32>
pub fn get_complexity(&mut self) -> Result<i32>
Gets the encoder’s complexity configuration.
Sourcepub fn set_bitrate(&mut self, value: Bitrate) -> Result<()>
pub fn set_bitrate(&mut self, value: Bitrate) -> Result<()>
Set the encoder’s bitrate.
Sourcepub fn get_bitrate(&mut self) -> Result<Bitrate>
pub fn get_bitrate(&mut self) -> Result<Bitrate>
Get the encoder’s bitrate.
Sourcepub fn set_vbr_constraint(&mut self, vbr: bool) -> Result<()>
pub fn set_vbr_constraint(&mut self, vbr: bool) -> Result<()>
Enable or disable constrained VBR.
Sourcepub fn get_vbr_constraint(&mut self) -> Result<bool>
pub fn get_vbr_constraint(&mut self) -> Result<bool>
Determine if constrained VBR is enabled.
Sourcepub fn set_force_channels(&mut self, value: Option<Channels>) -> Result<()>
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.
Sourcepub fn get_force_channels(&mut self) -> Result<Option<Channels>>
pub fn get_force_channels(&mut self) -> Result<Option<Channels>>
Gets the encoder’s forced channel configuration.
Sourcepub fn set_max_bandwidth(&mut self, bandwidth: Bandwidth) -> Result<()>
pub fn set_max_bandwidth(&mut self, bandwidth: Bandwidth) -> Result<()>
Configure the maximum bandpass that the encoder will select automatically.
Sourcepub fn get_max_bandwidth(&mut self) -> Result<Bandwidth>
pub fn get_max_bandwidth(&mut self) -> Result<Bandwidth>
Get the encoder’s configured maximum allowed bandpass.
Sourcepub fn set_bandwidth(&mut self, bandwidth: Bandwidth) -> Result<()>
pub fn set_bandwidth(&mut self, bandwidth: Bandwidth) -> Result<()>
Set the encoder’s bandpass to a specific value.
Sourcepub fn set_signal(&mut self, signal: Signal) -> Result<()>
pub fn set_signal(&mut self, signal: Signal) -> Result<()>
Configure the type of signal being encoded.
Sourcepub fn get_signal(&mut self) -> Result<Signal>
pub fn get_signal(&mut self) -> Result<Signal>
Gets the encoder’s configured signal type.
Sourcepub fn set_application(&mut self, application: Application) -> Result<()>
pub fn set_application(&mut self, application: Application) -> Result<()>
Configure the encoder’s intended application.
Sourcepub fn get_application(&mut self) -> Result<Application>
pub fn get_application(&mut self) -> Result<Application>
Get the encoder’s configured application.
Sourcepub fn get_lookahead(&mut self) -> Result<i32>
pub fn get_lookahead(&mut self) -> Result<i32>
Gets the total samples of delay added by the entire codec.
Sourcepub fn set_inband_fec(&mut self, value: bool) -> Result<()>
pub fn set_inband_fec(&mut self, value: bool) -> Result<()>
Configures the encoder’s use of inband forward error correction (FEC).
Sourcepub fn get_inband_fec(&mut self) -> Result<bool>
pub fn get_inband_fec(&mut self) -> Result<bool>
Gets encoder’s configured use of inband forward error correction.
Sourcepub fn set_packet_loss_perc(&mut self, value: i32) -> Result<()>
pub fn set_packet_loss_perc(&mut self, value: i32) -> Result<()>
Sets the encoder’s expected packet loss percentage.
Sourcepub fn get_packet_loss_perc(&mut self) -> Result<i32>
pub fn get_packet_loss_perc(&mut self) -> Result<i32>
Gets the encoder’s expected packet loss percentage.
Sourcepub fn set_dtx(&mut self, value: bool) -> Result<()>
pub fn set_dtx(&mut self, value: bool) -> Result<()>
Configures the encoder’s use of discontinuous transmission (DTX).
Sourcepub fn get_dtx(&mut self) -> Result<bool>
pub fn get_dtx(&mut self) -> Result<bool>
Gets encoder’s configured use of discontinuous transmission (DTX).
Sourcepub fn set_lsb_depth(&mut self, depth: i32) -> Result<()>
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.
Sourcepub fn get_lsb_depth(&mut self) -> Result<i32>
pub fn get_lsb_depth(&mut self) -> Result<i32>
Gets the encoder’s configured signal depth.
Sourcepub fn set_expert_frame_duration(&mut self, framesize: FrameSize) -> Result<()>
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.
Sourcepub fn get_expert_frame_duration(&mut self) -> Result<FrameSize>
pub fn get_expert_frame_duration(&mut self) -> Result<FrameSize>
Gets the encoder’s configured use of variable duration frames.
Sourcepub fn set_prediction_disabled(&mut self, disabled: bool) -> Result<()>
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.
Sourcepub fn get_prediction_disabled(&mut self) -> Result<bool>
pub fn get_prediction_disabled(&mut self) -> Result<bool>
Gets the encoder’s configured prediction status.
Sourcepub fn set_dred_duration(&mut self, duration_ms: i32) -> Result<()>
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.
Sourcepub fn get_dred_duration(&mut self) -> Result<i32>
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.
Sourcepub fn set_dnn_blob(&mut self, blob: &[u8]) -> Result<()>
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.