pub struct EncoderRef<'a> { /* private fields */ }Expand description
Borrowed wrapper around an encoder state.
The owning handle cannot be moved out of this borrowed wrapper:
use opus_codec::encoder::EncoderRef;
use opus_codec::Encoder;
fn extract<'a>(state: &mut EncoderRef<'a>, replacement: Encoder) -> Encoder {
std::mem::replace(&mut **state, replacement)
}Implementations§
Source§impl<'a> EncoderRef<'a>
impl<'a> EncoderRef<'a>
Sourcepub unsafe fn from_raw(
ptr: *mut OpusEncoder,
sample_rate: SampleRate,
channels: Channels,
) -> Self
pub unsafe fn from_raw( ptr: *mut OpusEncoder, sample_rate: SampleRate, channels: Channels, ) -> Self
Wrap an externally-initialized encoder without taking ownership.
§Safety
ptrmust point to valid, initialized memory of at leastEncoder::size()bytesptrmust be aligned to at leastalign_of::<usize>()(malloc-style alignment)sample_rateandchannelsmust exactly match the encoder state already stored atptr- The memory must remain valid for the lifetime
'a - Caller is responsible for freeing the memory after this wrapper is dropped
- If the external state already uses runtime-loaded DNN weights, register that blob again
through
EncoderRef::set_dnn_blobbefore callingEncoderRef::reset
Passing mismatched metadata is undefined behavior: later safe methods may validate buffer sizes against the wrong channel/rate and then call libopus with out-of-bounds buffers.
§Panics
Panics if ptr is null or not pointer-aligned.
Use Encoder::init_in_place to initialize the memory before calling this.
Sourcepub fn init_in(
buf: &'a mut AlignedBuffer,
sample_rate: SampleRate,
channels: Channels,
application: Application,
) -> Result<Self>
pub fn init_in( buf: &'a mut AlignedBuffer, sample_rate: SampleRate, channels: Channels, application: Application, ) -> Result<Self>
Initialize and wrap an externally allocated buffer.
§Errors
Returns Error::BadArg if the buffer is too small, or a mapped libopus error.
Sourcepub fn encode(&mut self, input: &[i16], output: &mut [u8]) -> Result<usize>
pub fn encode(&mut self, input: &[i16], output: &mut [u8]) -> Result<usize>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn encode_limited(
&mut self,
input: &[i16],
output: &mut [u8],
max_data_bytes: usize,
) -> Result<usize>
pub fn encode_limited( &mut self, input: &[i16], output: &mut [u8], max_data_bytes: usize, ) -> Result<usize>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
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>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_inband_fec(&mut self, enabled: bool) -> Result<()>
pub fn set_inband_fec(&mut self, enabled: bool) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn inband_fec(&mut self) -> Result<bool>
pub fn inband_fec(&mut self) -> Result<bool>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_packet_loss_perc(&mut self, perc: i32) -> Result<()>
pub fn set_packet_loss_perc(&mut self, perc: i32) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn packet_loss_perc(&mut self) -> Result<i32>
pub fn packet_loss_perc(&mut self) -> Result<i32>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_dtx(&mut self, enabled: bool) -> Result<()>
pub fn set_dtx(&mut self, enabled: bool) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn dtx(&mut self) -> Result<bool>
pub fn dtx(&mut self) -> Result<bool>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn in_dtx(&mut self) -> Result<bool>
pub fn in_dtx(&mut self) -> Result<bool>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_vbr_constraint(&mut self, constrained: bool) -> Result<()>
pub fn set_vbr_constraint(&mut self, constrained: bool) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn vbr_constraint(&mut self) -> Result<bool>
pub fn vbr_constraint(&mut self) -> Result<bool>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_max_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
pub fn set_max_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn max_bandwidth(&mut self) -> Result<Bandwidth>
pub fn max_bandwidth(&mut self) -> Result<Bandwidth>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
pub fn set_bandwidth(&mut self, bw: Bandwidth) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn bandwidth(&mut self) -> Result<Bandwidth>
pub fn bandwidth(&mut self) -> Result<Bandwidth>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_force_channels(&mut self, channels: Option<Channels>) -> Result<()>
pub fn set_force_channels(&mut self, channels: Option<Channels>) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn force_channels(&mut self) -> Result<Option<Channels>>
pub fn force_channels(&mut self) -> Result<Option<Channels>>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_signal(&mut self, signal: Signal) -> Result<()>
pub fn set_signal(&mut self, signal: Signal) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn signal(&mut self) -> Result<Signal>
pub fn signal(&mut self) -> Result<Signal>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn lookahead(&mut self) -> Result<i32>
pub fn lookahead(&mut self) -> Result<i32>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn final_range(&mut self) -> Result<u32>
pub fn final_range(&mut self) -> Result<u32>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_lsb_depth(&mut self, bits: i32) -> Result<()>
pub fn set_lsb_depth(&mut self, bits: i32) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn lsb_depth(&mut self) -> Result<i32>
pub fn lsb_depth(&mut self) -> Result<i32>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_expert_frame_duration(
&mut self,
dur: ExpertFrameDuration,
) -> Result<()>
pub fn set_expert_frame_duration( &mut self, dur: ExpertFrameDuration, ) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn expert_frame_duration(&mut self) -> Result<ExpertFrameDuration>
pub fn expert_frame_duration(&mut self) -> Result<ExpertFrameDuration>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_prediction_disabled(&mut self, disabled: bool) -> Result<()>
pub fn set_prediction_disabled(&mut self, disabled: bool) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn prediction_disabled(&mut self) -> Result<bool>
pub fn prediction_disabled(&mut self) -> Result<bool>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_phase_inversion_disabled(&mut self, disabled: bool) -> Result<()>
pub fn set_phase_inversion_disabled(&mut self, disabled: bool) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn phase_inversion_disabled(&mut self) -> Result<bool>
pub fn phase_inversion_disabled(&mut self) -> Result<bool>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_bitrate(&mut self, bitrate: Bitrate) -> Result<()>
pub fn set_bitrate(&mut self, bitrate: Bitrate) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn bitrate(&mut self) -> Result<Bitrate>
pub fn bitrate(&mut self) -> Result<Bitrate>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_complexity(&mut self, complexity: Complexity) -> Result<()>
pub fn set_complexity(&mut self, complexity: Complexity) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn complexity(&mut self) -> Result<Complexity>
pub fn complexity(&mut self) -> Result<Complexity>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Sourcepub fn set_vbr(&mut self, enabled: bool) -> Result<()>
pub fn set_vbr(&mut self, enabled: bool) -> Result<()>
Calls the corresponding operation on this borrowed libopus state.
§Errors
Returns the same errors as the corresponding owning-handle method.
Methods from Deref<Target = Encoder>§
Sourcepub fn sample_rate(&self) -> SampleRate
pub fn sample_rate(&self) -> SampleRate
The encoder’s configured sample rate.