pub struct CarrierResampler<C: FfmpegCarrier> { /* private fields */ }resample only.Expand description
mediadecode::resampler::AudioResampler impl wrapping
swresample.
Construction is Self::new, off the trait, taking both specs —
see the trait’s own documentation for why the target can never be a
constant.
Implementations§
Source§impl CarrierResampler<View>
impl CarrierResampler<View>
Sourcepub fn new(
source: ResampleSpec,
target: ResampleSpec,
limits: FrameLimits,
) -> Result<Self, ResampleError>
pub fn new( source: ResampleSpec, target: ResampleSpec, limits: FrameLimits, ) -> Result<Self, ResampleError>
Opens a resampler between two explicit specs. See
CarrierResampler::new_impl for the full contract.
Sourcepub const fn source(&self) -> &ResampleSpec
pub const fn source(&self) -> &ResampleSpec
The spec frames must arrive in.
Sourcepub const fn target(&self) -> &ResampleSpec
pub const fn target(&self) -> &ResampleSpec
The spec frames leave in.
Source§impl CarrierResampler<Owned>
impl CarrierResampler<Owned>
Sourcepub fn new(
source: ResampleSpec,
target: ResampleSpec,
limits: FrameLimits,
) -> Result<Self, ResampleError>
pub fn new( source: ResampleSpec, target: ResampleSpec, limits: FrameLimits, ) -> Result<Self, ResampleError>
Opens a resampler between two explicit specs. See
CarrierResampler::new_impl for the full contract.
Sourcepub const fn source(&self) -> &ResampleSpec
pub const fn source(&self) -> &ResampleSpec
The spec frames must arrive in.
Sourcepub const fn target(&self) -> &ResampleSpec
pub const fn target(&self) -> &ResampleSpec
The spec frames leave in.
Trait Implementations§
Source§impl AudioResampler for CarrierResampler<View>
impl AudioResampler for CarrierResampler<View>
Source§type Adapter = Ffmpeg
type Adapter = Ffmpeg
Source§type Buffer = <View as FfmpegCarrier>::Buffer
type Buffer = <View as FfmpegCarrier>::Buffer
Source§type Error = ResampleError
type Error = ResampleError
Sent and Received; what travels here
is the mid-stream-change refusal out of
send_frame and whatever else genuinely went
wrong.Source§fn send_frame(
&mut self,
frame: &AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <View as FfmpegCarrier>::Buffer>,
) -> Result<Sent, ResampleError>
fn send_frame( &mut self, frame: &AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <View as FfmpegCarrier>::Buffer>, ) -> Result<Sent, ResampleError>
Source§fn receive_frame(
&mut self,
dst: &mut AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <View as FfmpegCarrier>::Buffer>,
) -> Result<Received, ResampleError>
fn receive_frame( &mut self, dst: &mut AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <View as FfmpegCarrier>::Buffer>, ) -> Result<Received, ResampleError>
dst, answering the same
Received that
AudioStreamDecoder::receive_frame
answers.Source§fn send_eof(&mut self) -> Result<Sent, ResampleError>
fn send_eof(&mut self) -> Result<Sent, ResampleError>
receive_frame.Source§impl AudioResampler for CarrierResampler<Owned>
impl AudioResampler for CarrierResampler<Owned>
Source§type Adapter = Ffmpeg
type Adapter = Ffmpeg
Source§type Buffer = <Owned as FfmpegCarrier>::Buffer
type Buffer = <Owned as FfmpegCarrier>::Buffer
Source§type Error = ResampleError
type Error = ResampleError
Sent and Received; what travels here
is the mid-stream-change refusal out of
send_frame and whatever else genuinely went
wrong.Source§fn send_frame(
&mut self,
frame: &AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <Owned as FfmpegCarrier>::Buffer>,
) -> Result<Sent, ResampleError>
fn send_frame( &mut self, frame: &AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <Owned as FfmpegCarrier>::Buffer>, ) -> Result<Sent, ResampleError>
Source§fn receive_frame(
&mut self,
dst: &mut AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <Owned as FfmpegCarrier>::Buffer>,
) -> Result<Received, ResampleError>
fn receive_frame( &mut self, dst: &mut AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, <Owned as FfmpegCarrier>::Buffer>, ) -> Result<Received, ResampleError>
dst, answering the same
Received that
AudioStreamDecoder::receive_frame
answers.Source§fn send_eof(&mut self) -> Result<Sent, ResampleError>
fn send_eof(&mut self) -> Result<Sent, ResampleError>
receive_frame.impl<C: FfmpegCarrier> Send for CarrierResampler<C>
Send, and deliberately not Sync.
§Safety
The SwrContext behind ctx is owned by this value: it is
allocated in [open_context], never shared, never cloned, and
dropped with the resampler. Every operation that touches it goes
through &mut self — swr_convert_frame, swr_get_delay,
swr_init on the rebuild — so no two threads can be inside
libswresample for this context at once, which is the whole of what
that library requires: it keeps no thread-local or process-global
state of its own, and a context is a plain heap allocation whose
address is meaningful on any thread.
The other fields are ordinary owned values. The two
ffmpeg_next::ChannelLayouts and the two ResampleSpecs wrap an
AVChannelLayout, which holds a pointer only for
AV_CHANNEL_ORDER_CUSTOM — and [preflight_layout] refuses that
order at the one construction choke point, so every layout a live
resampler holds is the u.mask arm: a uint64_t, a plain value.
The staged layouts come from [initialized_layout], which produces
av_channel_layout_default’s mask-only answer. ready holds
Frame<C> values, whose carriers are Send by the carrier
contract.
Not Sync, and that is not an oversight. &self would let two
threads hold the context at once, and nothing in this type
serialises that; the &mut receiver is the serialisation. Moving
the whole resampler to another thread is sound; sharing it is not
offered.