Struct rsmpeg::swresample::SwrContext

source ·
pub struct SwrContext { /* private fields */ }

Implementations§

source§

impl SwrContext

source

pub fn as_ptr(&self) -> *const SwrContext

source

pub fn as_mut_ptr(&mut self) -> *mut SwrContext

source

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.

source

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.

source

pub fn into_raw(self) -> NonNull<SwrContext>

source§

impl SwrContext

source

pub fn is_initialized(&self) -> bool

Check whether an swr context has been initialized or not.

source

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.

source

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

Initialize context after user parameters have been set.

source

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.

source

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.
source

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.

source

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.

Trait Implementations§

source§

impl Deref for SwrContext

§

type Target = SwrContext

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Drop for SwrContext

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl UnsafeDerefMut for SwrContext

source§

unsafe fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value, unsafely. Read more
source§

impl Send for SwrContext

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>,

§

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>,

§

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.