claxon

Struct FlacReader

Source
pub struct FlacReader<R: Read> { /* private fields */ }
Expand description

A FLAC decoder that can decode the stream from the underlying reader.

TODO: Add an example.

Implementations§

Source§

impl<R: Read> FlacReader<R>

Source

pub fn new(reader: R) -> Result<FlacReader<R>>

Create a reader that reads the FLAC format.

The header and metadata blocks are read immediately. Audio frames will be read on demand.

Claxon rejects files that claim to contain excessively large metadata blocks, to protect against denial of service attacks where a small damaged or malicous file could cause gigabytes of memory to be allocated. Error::Unsupported is returned in that case.

Source

pub fn new_ext(reader: R, options: FlacReaderOptions) -> Result<FlacReader<R>>

Create a reader that reads the FLAC format, with reader options.

The header and metadata blocks are read immediately, but only as much as specified in the options. See FlacReaderOptions for more details.

Claxon rejects files that claim to contain excessively large metadata blocks, to protect against denial of service attacks where a small damaged or malicous file could cause gigabytes of memory to be allocated. Error::Unsupported is returned in that case.

Source

pub fn streaminfo(&self) -> StreamInfo

Returns the streaminfo metadata.

This contains information like the sample rate and number of channels.

Source

pub fn vendor(&self) -> Option<&str>

Returns the vendor string of the Vorbis comment block, if present.

This string usually contains the name and version of the program that encoded the FLAC stream, such as reference libFLAC 1.3.2 20170101 or Lavf57.25.100.

Source

pub fn tags<'a>(&'a self) -> Tags<'a>

Returns name-value pairs of Vorbis comments, such as ("ARTIST", "Queen").

The name is supposed to be interpreted case-insensitively, and is guaranteed to consist of ASCII characters. Claxon does not normalize the casing of the name. Use get_tag() to do a case-insensitive lookup.

Names need not be unique. For instance, multiple ARTIST comments might be present on a collaboration track.

See https://www.xiph.org/vorbis/doc/v-comment.html for more details.

Source

pub fn get_tag<'a>(&'a self, tag_name: &'a str) -> GetTag<'a>

Look up a Vorbis comment such as ARTIST in a case-insensitive way.

Returns an iterator, because tags may occur more than once. There could be multiple ARTIST tags on a collaboration track, for instance.

Note that tag names are ASCII and never contain '='; trying to look up a non-ASCII tag will return no results. Furthermore, the Vorbis comment spec dictates that tag names should be handled case-insensitively, so this method performs a case-insensitive lookup.

See also tags() for access to the raw tags. See https://www.xiph.org/vorbis/doc/v-comment.html for more details.

Source

pub fn blocks<'r>(&'r mut self) -> FrameReader<&'r mut BufferedReader<R>>

Returns an iterator that decodes a single frame on every iteration. TODO: It is not an iterator.

This is a low-level primitive that gives you control over when decoding happens. The representation of the decoded audio is somewhat specific to the FLAC format. For a higher-level interface, see samples().

Source

pub fn samples<'r>(&'r mut self) -> FlacSamples<&'r mut BufferedReader<R>>

Returns an iterator over all samples.

The channel data is is interleaved. The iterator is streaming. That is, if you call this method once, read a few samples, and call this method again, the second iterator will not start again from the beginning of the file. It will continue somewhere after where the first iterator stopped, and it might skip some samples. (This is because FLAC divides a stream into blocks, which have to be decoded entirely. If you drop the iterator, you lose the unread samples in that block.)

This is a user-friendly interface that trades performance for ease of use. If performance is an issue, consider using blocks() instead.

This is a high-level interface to the decoder. The cost of retrieving the next sample can vary significantly, as sometimes a new block has to be decoded. Additionally, there is a cost to every iteration returning a Result. When a block has been decoded, iterating the samples in that block can never fail, but a match on every sample is required nonetheless. For more control over when decoding happens, and less error handling overhead, use blocks().

Source

pub fn into_inner(self) -> R

Destroys the FLAC reader and returns the underlying reader.

Because the reader employs buffering internally, anything in the buffer will be lost.

Source§

impl FlacReader<File>

Source

pub fn open<P: AsRef<Path>>(filename: P) -> Result<FlacReader<File>>

Attempts to create a reader that reads from the specified file.

This is a convenience constructor that opens a File, and constructs a FlacReader from it. There is no need to wrap the file in a BufReader, as the FlacReader employs buffering already.

Source

pub fn open_ext<P: AsRef<Path>>( filename: P, options: FlacReaderOptions, ) -> Result<FlacReader<File>>

Attemps to create a reader that reads from the specified file.

This is a convenience constructor that opens a File, and constructs a FlacReader from it. There is no need to wrap the file in a BufReader, as the FlacReader employs buffering already.

Auto Trait Implementations§

§

impl<R> Freeze for FlacReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for FlacReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for FlacReader<R>
where R: Send,

§

impl<R> Sync for FlacReader<R>
where R: Sync,

§

impl<R> Unpin for FlacReader<R>
where R: Unpin,

§

impl<R> UnwindSafe for FlacReader<R>
where R: UnwindSafe,

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

Source§

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

Source§

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.