pub struct FfmpegResampler { /* 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 FfmpegResampler
impl FfmpegResampler
Sourcepub fn new(
source: ResampleSpec,
target: ResampleSpec,
) -> Result<Self, ResampleError>
pub fn new( source: ResampleSpec, target: ResampleSpec, ) -> Result<Self, ResampleError>
Opens a resampler between two explicit specs.
Both are required and neither is inferred. The source is what the
decoder will hand over — read it off the track
(ResampleSpec::from_parameters) or off the opened decoder
(ResampleSpec::from_decoder). The target is the caller’s, and
is options: 16 kHz mono for a speech model, 48 kHz for an
audio-event one, both from the same track.
§The choke point
ResampleSpec::new is const and total, so this is where both
ends are checked — every construction route (from_parameters,
from_decoder, the public constructor) passes through here, and
nothing hazardous reaches swr or a staged AVFrame behind it:
- a rate of zero, or one past
c_int(ResampleError::UnsupportedRate); AV_SAMPLE_FMT_NONE(ResampleError::UnsupportedFormat);- a channel layout that is neither native nor unspecified, or one
naming no channels (
ResampleError::UnsupportedLayout).
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 FfmpegResampler
impl AudioResampler for FfmpegResampler
Source§fn flush(&mut self) -> Result<(), ResampleError>
fn flush(&mut self) -> Result<(), ResampleError>
Resets the resampler for another stream on the same two specs.
The swr context is rebuilt, not drained. swresample has no
reset call, and draining it dry cannot be verified from outside: a
swr_convert_frame that makes no progress reports no error, so a
drain loop that gives up and a drain loop that finished are
indistinguishable — and a flush that returned Ok with the old
delay line still inside would let one stream’s tail contaminate
the next. A fresh context is the only reset whose success is a
fact.
The new context is built before the old one is dropped, so a failure leaves the resampler exactly as it was: this call either resets everything or changes nothing.
Source§type Adapter = Ffmpeg
type Adapter = Ffmpeg
Source§type Buffer = FfmpegBuffer
type Buffer = FfmpegBuffer
Source§type Error = ResampleError
type Error = ResampleError
receive_frame
and the mid-stream-change refusal out of
send_frame.Source§fn send_frame(
&mut self,
frame: &AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, FfmpegBuffer>,
) -> Result<(), ResampleError>
fn send_frame( &mut self, frame: &AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, FfmpegBuffer>, ) -> Result<(), ResampleError>
Source§fn receive_frame(
&mut self,
dst: &mut AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, FfmpegBuffer>,
) -> Result<(), ResampleError>
fn receive_frame( &mut self, dst: &mut AudioFrame<SampleFormat, ChannelLayoutDescription, AudioFrameExtra, FfmpegBuffer>, ) -> Result<(), ResampleError>
dst. Implementations signal
“no frame ready” via a backend-specific Error
variant, exactly as
AudioStreamDecoder::receive_frame
does.Source§fn send_eof(&mut self) -> Result<(), ResampleError>
fn send_eof(&mut self) -> Result<(), ResampleError>
receive_frame.