pub struct ResampleSpec { /* private fields */ }resample only.Expand description
One end of a conversion: sample rate, sample format, channel layout.
Spelled in FFmpeg’s own vocabulary because construction is off the
AudioResampler trait and this is the backend that has to be
handed to swr_alloc_set_opts2. FfmpegResampler restates the
source spec in the vocabulary a decoded frame carries, so the
mid-stream check compares like with like without the caller ever
seeing two dialects.
Implementations§
Source§impl ResampleSpec
impl ResampleSpec
Sourcepub const fn new(rate: u32, format: Sample, layout: ChannelLayout) -> Self
pub const fn new(rate: u32, format: Sample, layout: ChannelLayout) -> Self
Constructs a spec from its three parts.
Deliberately total and const: a spec is a description, and
describing something swr cannot convert is not itself an error.
FfmpegResampler::new is the choke point every construction
route passes through, and it is what refuses a rate, a format or a
channel layout this backend cannot honour — see
FfmpegResampler::new for the roster and
ResampleError::UnsupportedLayout for why a layout can be
refused at all.
Sourcepub fn from_parameters(parameters: &Parameters) -> Option<Self>
pub fn from_parameters(parameters: &Parameters) -> Option<Self>
The spec a track declares, read off the codec parameters a
crate::FfmpegDemuxer track row carries
(track.extra().parameters()) — the “source from TrackInfo”
path.
Returns None for a non-audio track, for one whose declared
sample format is AV_SAMPLE_FMT_NONE (a codec whose format is
only known once its decoder opens), and for a custom or ambisonic
channel layout — see Self::from_decoder for the first case and
the note on [unspecified_layout] for the last.
Sourcepub fn from_decoder(decoder: &Audio) -> Option<Self>
pub fn from_decoder(decoder: &Audio) -> Option<Self>
The spec an opened decoder will actually produce — its rate, sample format and channel layout, straight off the codec context.
Reach it through
FfmpegAudioStreamDecoder::inner.
None on a custom or ambisonic layout, and on a context whose
sample format is still unset (a decoder that has not been opened).
Sourcepub fn unspecified_layout(channels: i32) -> ChannelLayout
pub fn unspecified_layout(channels: i32) -> ChannelLayout
A layout that names a channel count and nothing else —
AV_CHANNEL_ORDER_UNSPEC.
Not a degenerate case: a WAV file without a WAVE_FORMAT_EXTENSIBLE
channel mask genuinely declares no layout, and FFmpeg faithfully
reports it as unspecified in the codec parameters, in the codec
context, and on every decoded frame. Substituting a default layout
would make the source spec disagree with the frames it is supposed
to describe, and every send_frame would be refused as a
mid-stream change. swr accepts an unspecified layout at either
end and maps the channels positionally.
Sourcepub const fn layout(&self) -> ChannelLayout
pub const fn layout(&self) -> ChannelLayout
Channel layout.
Trait Implementations§
Source§impl Clone for ResampleSpec
impl Clone for ResampleSpec
Source§fn clone(&self) -> ResampleSpec
fn clone(&self) -> ResampleSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more