pub struct MultistreamEncoder { /* private fields */ }Expand description
Safe wrapper around OpusMSEncoder.
Implementations§
Source§impl MultistreamEncoder
impl MultistreamEncoder
Sourcepub fn size(streams: u8, coupled_streams: u8) -> Result<usize>
pub fn size(streams: u8, coupled_streams: u8) -> Result<usize>
Size in bytes of a multistream encoder state for external allocation.
§Errors
Returns Error::BadArg if the stream counts are invalid or libopus reports
an impossible size.
Sourcepub fn surround_size(channels: u8, mapping_family: i32) -> Result<usize>
pub fn surround_size(channels: u8, mapping_family: i32) -> Result<usize>
Size in bytes of a surround multistream encoder state for external allocation.
§Errors
Returns Error::BadArg if the channel/mapping configuration is invalid.
Sourcepub unsafe fn init_in_place(
ptr: *mut OpusMSEncoder,
sr: SampleRate,
app: Application,
mapping: Mapping<'_>,
) -> Result<()>
pub unsafe fn init_in_place( ptr: *mut OpusMSEncoder, sr: SampleRate, app: Application, mapping: Mapping<'_>, ) -> Result<()>
Initialize a previously allocated multistream encoder state.
§Safety
The caller must provide a valid pointer to MultistreamEncoder::size() bytes,
aligned to at least align_of::<usize>() (malloc-style alignment).
§Errors
Returns Error::BadArg if the mapping is invalid or ptr is null, or a
mapped libopus error on failure.
Sourcepub unsafe fn init_surround_in_place(
ptr: *mut OpusMSEncoder,
sr: SampleRate,
channels: u8,
mapping_family: i32,
app: Application,
) -> Result<(u8, u8, Vec<u8>)>
pub unsafe fn init_surround_in_place( ptr: *mut OpusMSEncoder, sr: SampleRate, channels: u8, mapping_family: i32, app: Application, ) -> Result<(u8, u8, Vec<u8>)>
Initialize a previously allocated surround multistream encoder state.
§Safety
The caller must provide a valid pointer to MultistreamEncoder::surround_size() bytes,
aligned to at least align_of::<usize>() (malloc-style alignment).
§Errors
Returns Error::BadArg for invalid channel counts or a mapped libopus error.
Sourcepub fn new(
sr: SampleRate,
app: Application,
mapping: Mapping<'_>,
) -> Result<Self>
pub fn new( sr: SampleRate, app: Application, mapping: Mapping<'_>, ) -> Result<Self>
Create a new multistream encoder.
The mapping.mapping array describes how input channels are assigned to streams.
See libopus docs for standard surround layouts.
§Errors
Returns Error::BadArg when the mapping dimensions are inconsistent, or
propagates allocation/configuration failures from libopus.
Sourcepub fn encode(
&mut self,
pcm: &[i16],
frame_size_per_ch: usize,
out: &mut [u8],
) -> Result<usize>
pub fn encode( &mut self, pcm: &[i16], frame_size_per_ch: usize, out: &mut [u8], ) -> Result<usize>
Encode interleaved i16 PCM into a multistream Opus packet.
§Errors
Returns Error::InvalidState if the encoder handle is invalid, Error::BadArg
for buffer mismatches, or the mapped libopus error code.
Sourcepub fn encode_float(
&mut self,
pcm: &[f32],
frame_size_per_ch: usize,
out: &mut [u8],
) -> Result<usize>
pub fn encode_float( &mut self, pcm: &[f32], frame_size_per_ch: usize, out: &mut [u8], ) -> Result<usize>
Encode interleaved f32 PCM into a multistream Opus packet.
§Errors
Returns Error::InvalidState if the encoder handle is invalid, Error::BadArg
for buffer mismatches, or the mapped libopus error code.
Sourcepub fn final_range(&mut self) -> Result<u32>
pub fn final_range(&mut self) -> Result<u32>
Final RNG state from the last encode.
§Errors
Returns Error::InvalidState when the encoder handle is null or
propagates the libopus error.
Sourcepub fn set_bitrate(&mut self, bitrate: Bitrate) -> Result<()>
pub fn set_bitrate(&mut self, bitrate: Bitrate) -> Result<()>
Set target bitrate for the encoder.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn bitrate(&mut self) -> Result<Bitrate>
pub fn bitrate(&mut self) -> Result<Bitrate>
Query the current bitrate target.
§Errors
Returns Error::InvalidState if the encoder handle is null, Error::InternalError
if the returned value cannot be represented, or propagates any error reported by
libopus.
Sourcepub fn set_complexity(&mut self, complexity: Complexity) -> Result<()>
pub fn set_complexity(&mut self, complexity: Complexity) -> Result<()>
Set encoder complexity in the range 0..=10.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn complexity(&mut self) -> Result<Complexity>
pub fn complexity(&mut self) -> Result<Complexity>
Query encoder complexity.
§Errors
Returns Error::InvalidState if the encoder handle is null, Error::InternalError
if the response is outside the valid range, or propagates any error reported by libopus.
Sourcepub fn set_dtx(&mut self, enabled: bool) -> Result<()>
pub fn set_dtx(&mut self, enabled: bool) -> Result<()>
Enable/disable discontinuous transmission (DTX).
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn dtx(&mut self) -> Result<bool>
pub fn dtx(&mut self) -> Result<bool>
Query whether DTX is enabled.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn in_dtx(&mut self) -> Result<bool>
pub fn in_dtx(&mut self) -> Result<bool>
Query whether the encoder is currently in DTX.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn set_inband_fec(&mut self, enabled: bool) -> Result<()>
pub fn set_inband_fec(&mut self, enabled: bool) -> Result<()>
Enable/disable in-band FEC generation.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn inband_fec(&mut self) -> Result<bool>
pub fn inband_fec(&mut self) -> Result<bool>
Query whether in-band FEC is enabled.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn set_packet_loss_perc(&mut self, perc: i32) -> Result<()>
pub fn set_packet_loss_perc(&mut self, perc: i32) -> Result<()>
Set expected packet loss percentage (0..=100).
§Errors
Returns Error::BadArg when perc is outside 0..=100, Error::InvalidState if
the encoder handle is null, or propagates any error reported by libopus.
Sourcepub fn packet_loss_perc(&mut self) -> Result<i32>
pub fn packet_loss_perc(&mut self) -> Result<i32>
Query expected packet loss percentage.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn set_vbr(&mut self, enabled: bool) -> Result<()>
pub fn set_vbr(&mut self, enabled: bool) -> Result<()>
Enable/disable variable bitrate.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn vbr(&mut self) -> Result<bool>
pub fn vbr(&mut self) -> Result<bool>
Query VBR status.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn set_vbr_constraint(&mut self, constrained: bool) -> Result<()>
pub fn set_vbr_constraint(&mut self, constrained: bool) -> Result<()>
Constrain VBR to reduce instantaneous bitrate swings.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn vbr_constraint(&mut self) -> Result<bool>
pub fn vbr_constraint(&mut self) -> Result<bool>
Query VBR constraint flag.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn set_max_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
pub fn set_max_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
Set the maximum bandwidth the encoder may use.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn max_bandwidth(&mut self) -> Result<Bandwidth>
pub fn max_bandwidth(&mut self) -> Result<Bandwidth>
Query the configured maximum bandwidth.
§Errors
Returns Error::InvalidState if the encoder handle is null, Error::InternalError
if the value cannot be represented, or propagates any error reported by libopus.
Sourcepub fn set_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
pub fn set_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
Force a specific output bandwidth (overrides automatic selection).
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn bandwidth(&mut self) -> Result<Bandwidth>
pub fn bandwidth(&mut self) -> Result<Bandwidth>
Query the current forced bandwidth, if any.
§Errors
Returns Error::InvalidState if the encoder handle is null or Error::InternalError
if the value is outside the known set, and propagates any error reported by libopus.
Sourcepub fn set_force_channels(&mut self, channels: Option<Channels>) -> Result<()>
pub fn set_force_channels(&mut self, channels: Option<Channels>) -> Result<()>
Force mono/stereo output for coupled streams, or None for automatic.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn force_channels(&mut self) -> Result<Option<Channels>>
pub fn force_channels(&mut self) -> Result<Option<Channels>>
Query forced channel configuration (if any).
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn set_signal(&mut self, signal: Signal) -> Result<()>
pub fn set_signal(&mut self, signal: Signal) -> Result<()>
Hint the type of content being encoded (voice/music).
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn signal(&mut self) -> Result<Signal>
pub fn signal(&mut self) -> Result<Signal>
Query the current signal hint.
§Errors
Returns Error::InvalidState if the encoder handle is null, Error::InternalError
if the response is not recognized, or propagates any error reported by libopus.
Sourcepub fn lookahead(&mut self) -> Result<i32>
pub fn lookahead(&mut self) -> Result<i32>
Query the algorithmic lookahead in samples at 48 kHz.
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub fn reset(&mut self) -> Result<()>
pub fn reset(&mut self) -> Result<()>
Reset the encoder state (retaining configuration).
§Errors
Returns Error::InvalidState if the encoder handle is null or propagates any error
reported by libopus.
Sourcepub const fn sample_rate(&self) -> SampleRate
pub const fn sample_rate(&self) -> SampleRate
Input sampling rate.
Sourcepub const fn coupled_streams(&self) -> u8
pub const fn coupled_streams(&self) -> u8
Number of coupled streams.
Sourcepub fn new_surround(
sr: SampleRate,
channels: u8,
mapping_family: i32,
app: Application,
) -> Result<(Self, Vec<u8>)>
pub fn new_surround( sr: SampleRate, channels: u8, mapping_family: i32, app: Application, ) -> Result<(Self, Vec<u8>)>
Create a multistream encoder using libopus surround mapping helpers.
§Errors
Returns Error::BadArg for invalid channel counts or the mapped libopus
error when surround initialisation fails.
Sourcepub unsafe fn encoder_state_ptr(
&mut self,
stream_index: i32,
) -> Result<*mut OpusEncoder>
pub unsafe fn encoder_state_ptr( &mut self, stream_index: i32, ) -> Result<*mut OpusEncoder>
Borrow a pointer to an individual underlying encoder state for CTLs.
§Safety
Caller must not outlive the multistream encoder and must ensure the returned pointer is only used for immediate FFI calls.
§Errors
Returns Error::InvalidState if the encoder handle is invalid or propagates the
libopus error if retrieving the state fails.