pub struct SwrContext { /* private fields */ }Implementations§
Source§impl SwrContext
impl SwrContext
pub fn as_ptr(&self) -> *const SwrContext
pub fn as_mut_ptr(&mut self) -> *mut SwrContext
Sourcepub unsafe fn set_ptr(&mut self, ptr: NonNull<SwrContext>)
pub unsafe fn set_ptr(&mut self, ptr: NonNull<SwrContext>)
§Safety
This function should only be called when the pointer is valid and the data it’s pointing to can be dropped.
Sourcepub unsafe fn from_raw(raw: NonNull<SwrContext>) -> Self
pub unsafe fn from_raw(raw: NonNull<SwrContext>) -> Self
§Safety
This function should only be called when the pointer is valid and the data it’s pointing to can be dropped.
pub fn into_raw(self) -> NonNull<SwrContext>
Source§impl SwrContext
impl SwrContext
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check whether an swr context has been initialized or not.
Sourcepub fn new(
out_ch_layout: &AVChannelLayout,
out_sample_fmt: AVSampleFormat,
out_sample_rate: i32,
in_ch_layout: &AVChannelLayout,
in_sample_fmt: AVSampleFormat,
in_sample_rate: i32,
) -> Result<Self>
pub fn new( out_ch_layout: &AVChannelLayout, out_sample_fmt: AVSampleFormat, out_sample_rate: i32, in_ch_layout: &AVChannelLayout, in_sample_fmt: AVSampleFormat, in_sample_rate: i32, ) -> Result<Self>
Allocate SwrContext if needed and set/reset common parameters.
This function does not require s to be allocated with swr_alloc(). On the other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters on the allocated context.
out_ch_layout output channel layout (AV_CH_LAYOUT_)
out_sample_fmt output sample format (AV_SAMPLE_FMT_).
out_sample_rate output sample rate (frequency in Hz)
in_ch_layout input channel layout (AV_CH_LAYOUT_)
in_sample_fmt input sample format (AV_SAMPLE_FMT_).
in_sample_rate input sample rate (frequency in Hz)
Returns None on invalid parameters or insufficient parameters.
Sourcepub fn get_out_samples(&self, in_samples: i32) -> i32
pub fn get_out_samples(&self, in_samples: i32) -> i32
Find an upper bound on the number of samples that the next
SwrContext::convert call will output, if called with in_samples of
input samples.
This depends on the internal state, and anything changing the internal
state (like further SwrContext::convert calls) will may change the
number of samples current function returns for the same number of input
samples.
Sourcepub fn get_delay(&self, base: usize) -> usize
pub fn get_delay(&self, base: usize) -> usize
Gets the delay the next input sample will experience relative to the next output sample.
SwrContext can buffer data if more input has been provided than available
output space, also converting between sample rates needs a delay. This
function returns the sum of all such delays. The exact delay is not
necessarily an integer value in either input or output sample rate.
Especially when downsampling by a large value, the output sample rate may be
a poor choice to represent the delay, similarly for upsampling and the input
sample rate.
base: timebase in which the returned delay will be:
- if it’s set to 1 the returned delay is in seconds
- if it’s set to 1000 the returned delay is in milliseconds
- if it’s set to the input sample rate then the returned delay is in input samples
- if it’s set to the output sample rate then the returned
delay is in output samples - if it’s the least common multiple of in_sample_rate and out_sample_rate then an exact rounding-free delay will be returned
returns the delay in 1 / base base units.
Sourcepub unsafe fn convert(
&mut self,
out_buffer: *mut *mut u8,
out_count: i32,
in_buffer: *const *const u8,
in_count: i32,
) -> Result<i32>
pub unsafe fn convert( &mut self, out_buffer: *mut *mut u8, out_count: i32, in_buffer: *const *const u8, in_count: i32, ) -> Result<i32>
Convert audio.
in_buffer and in_count can be set to 0 to flush the last few samples
out at the end. If more input is provided than output space, then the
input will be buffered. You can avoid this buffering by using
SwrContext::get_out_samples to retrieve an upper bound on the
required number of output samples for the given number of input samples.
Conversion will run directly without copying whenever possible.
out_buffer output buffers, only the first one need be set in case of packed audio
out_count amount of space available for output in samples per channel
in input buffers, only the first one need to be set in case of packed audio
in_count number of input samples available in one channel
Returns number of samples output per channel.
§Safety
Only safe when the in_buffer is valid.
Sourcepub fn convert_frame(
&self,
input: Option<&AVFrame>,
output: &mut AVFrame,
) -> Result<()>
pub fn convert_frame( &self, input: Option<&AVFrame>, output: &mut AVFrame, ) -> Result<()>
Convert the samples in the input AVFrame and write them to the output
AVFrame.
Input and output AVFrame must have channel_layout, sample_rate and
format set.
If the output AVFrame does not have the data pointers allocated. The nb_samples field will be set by allocating the frame.
The output AVFrame::nb_samples can be 0 or have fewer allocated samples
than required. In this case, any remaining samples not written to the
output will be added to an internal FIFO buffer, to be returned at the next
call to this function or to SwrContext::convert.
If converting sample rate, there may be data remaining in the internal
resampling delay buffer. SwrContext::get_delay tells the number of remaining
samples. To get this data as output, call this function or swr_convert()
with NULL input.
If the SwrContext configuration does not match the output and input AVFrame
settings, the conversion does not take place and error is returned.