pub struct FlacStreamDecoder { /* private fields */ }Expand description
Reads a FLAC stream that arrives in pieces.
The StreamSource half of this module, with the same shape and the same
bounds as WavStreamDecoder and
AiffStreamDecoder. Nothing is buffered in
proportion to a size the file declared: the signature and block headers
are buffered, the streaminfo body is buffered at its fixed 34 bytes, every
other metadata body is discarded as it flows past, and one frame at a time
is held while it is assembled, capped at 2,101,216 bytes, which is the
largest frame the format can express plus room for its headers, and is a
figure stated in this crate rather than read from a file.
The MD5 is computed as frames are decoded and verified by
finish, so a streaming decode has the same
end-to-end check a whole-file decode has.
§Example
use decibri_decode::{FlacStreamDecoder, StreamSource};
// `file` is RFC 9639 appendix D.3's worked example.
let mut stream = FlacStreamDecoder::new();
let mut samples = Vec::new();
for piece in file.chunks(5) {
let mut offset = 0;
while offset < piece.len() {
offset += stream.push(&piece[offset..])?;
while stream.pull(&mut samples, usize::MAX)? > 0 {}
}
}
stream.finish(&mut samples)?;
assert_eq!(stream.spec().map(|spec| spec.sample_rate), Some(32_000));
assert_eq!(samples.len(), 24);Implementations§
Source§impl FlacStreamDecoder
impl FlacStreamDecoder
Sourcepub fn frames() -> Self
pub fn frames() -> Self
A reader for a bare frame stream: no fLaC signature and no
metadata, the first byte pushed is the first byte of a frame header.
The streaming half of FlacFrameReader, with the same properties
and the same two escape-code rejections. spec
and stream_info answer None until the first
frame header has arrived, which is what they already mean on this type
and why a bare stream needs no separate way of saying it.
Sourcepub fn frames_with_stream_info(info: FlacStreamInfo) -> Self
pub fn frames_with_stream_info(info: FlacStreamInfo) -> Self
A reader for a bare frame stream described by a streaminfo block the caller obtained elsewhere.
This is the Ogg and Matroska shape: streaminfo in the container’s
codec-private header, bare frames in the packets. The block’s bytes
become an info through FlacStreamInfo::from_block. It resolves
the two escape codes and restores the MD5 check to a path that
otherwise has none. See md5_check, which is how
a caller finds out whether that check actually ran.
Sourcepub const fn stream_info(&self) -> Option<FlacStreamInfo>
pub const fn stream_info(&self) -> Option<FlacStreamInfo>
What the streaminfo metadata block declared, once it has arrived.
For a bare frame stream this is the description derived from the first frame, or the one the caller supplied.
Sourcepub const fn md5_check(&self) -> Option<Md5Check>
pub const fn md5_check(&self) -> Option<Md5Check>
What finish did about the streaminfo MD5, or
None before it has run.
None is not a verdict. The check happens at the end of the stream
and this reports what happened, never what is expected to happen, so a
caller cannot read a guarantee off a decode that has not finished.
Sourcepub fn ready_samples(&self) -> usize
pub fn ready_samples(&self) -> usize
How many interleaved samples are decoded and waiting to be pulled: frames times channels, which is the length a caller’s output vector grows by when they are.
Interleaved samples, not the frames pull
counts; the two figures differ by the channel count.
Trait Implementations§
Source§impl Debug for FlacStreamDecoder
impl Debug for FlacStreamDecoder
Source§impl Default for FlacStreamDecoder
impl Default for FlacStreamDecoder
Source§impl StreamSource for FlacStreamDecoder
impl StreamSource for FlacStreamDecoder
Source§fn push(&mut self, bytes: &[u8]) -> Result<usize, DecodeError>
fn push(&mut self, bytes: &[u8]) -> Result<usize, DecodeError>
bytes to the stream and returns how many were taken. Read moreSource§fn pull(
&mut self,
output: &mut Vec<f32>,
max_frames: usize,
) -> Result<usize, DecodeError>
fn pull( &mut self, output: &mut Vec<f32>, max_frames: usize, ) -> Result<usize, DecodeError>
max_frames frames of decoded samples to output, and
returns how many frames it appended. Read more