Streaminfo

Struct Streaminfo 

Source
pub struct Streaminfo {
    pub minimum_block_size: u16,
    pub maximum_block_size: u16,
    pub minimum_frame_size: Option<NonZero<u32>>,
    pub maximum_frame_size: Option<NonZero<u32>>,
    pub sample_rate: u32,
    pub channels: NonZero<u8>,
    pub bits_per_sample: SignedBitCount<32>,
    pub total_samples: Option<NonZero<u64>>,
    pub md5: Option<[u8; 16]>,
}
Expand description

A STREAMINFO metadata block

This block contains metadata about the stream’s contents.

It must always be present in a FLAC file, must always be the first metadata block in the stream, and must not be present more than once.

BitsFieldMeaning
16minimum_block_sizeminimum block size (in samples) in the stream
16maximum_block_sizemaximum block size (in samples) in the stream
24minimum_frame_sizeminimum frame size (in bytes) in the stream
24maximum_frame_sizemaximum frame size (in bytes) in the stream
20sample_ratestream’s sample rate, in Hz
3channelsstream’s channel count (+1)
5bits_per_samplestream’s bits-per-sample (+1)
36total_samplesstream’s total channel-independent samples
16×8md5decoded stream’s MD5 sum hash

§Example

use bitstream_io::{BitReader, BitRead, BigEndian, SignedBitCount};
use flac_codec::metadata::Streaminfo;
use std::num::NonZero;

let data: &[u8] = &[
    0x10, 0x00,
    0x10, 0x00,
    0x00, 0x00, 0x0c,
    0x00, 0x00, 0x0c,
    0b00001010, 0b11000100, 0b0100_000_0, 0b1111_0000,
    0b00000000, 0b00000000, 0b00000000, 0b01010000,
    0xf5, 0x3f, 0x86, 0x87, 0x6d, 0xcd, 0x77, 0x83,
    0x22, 0x5c, 0x93, 0xba, 0x8a, 0x93, 0x8c, 0x7d,
];

let mut r = BitReader::endian(data, BigEndian);
assert_eq!(
    r.parse::<Streaminfo>().unwrap(),
    Streaminfo {
        minimum_block_size: 0x10_00,                    // 4096 samples
        maximum_block_size: 0x10_00,                    // 4096 samples
        minimum_frame_size: NonZero::new(0x00_00_0c),   // 12 bytes
        maximum_frame_size: NonZero::new(0x00_00_0c),   // 12 bytes
        sample_rate: 0b00001010_11000100_0100,          // 44100 Hz
        channels: NonZero::new(0b000 + 1).unwrap(),     // 1 channel
        bits_per_sample:
            SignedBitCount::new::<{0b0_1111 + 1}>(),    // 16 bps
        total_samples: NonZero::new(
            0b0000_00000000_00000000_00000000_01010000  // 80 samples
        ),
        md5: Some([
            0xf5, 0x3f, 0x86, 0x87, 0x6d, 0xcd, 0x77, 0x83,
            0x22, 0x5c, 0x93, 0xba, 0x8a, 0x93, 0x8c, 0x7d,
        ]),
    },
);

§Important

Changing any of these values to something that differs from the values of the file’s frame headers will render it unplayable, as will moving it anywhere but the first metadata block in the file. Avoid modifying the position and contents of this block unless you know exactly what you are doing.

Fields§

§minimum_block_size: u16

The minimum block size (in samples) used in the stream, excluding the last block.

§maximum_block_size: u16

The maximum block size (in samples) used in the stream, excluding the last block.

§minimum_frame_size: Option<NonZero<u32>>

The minimum framesize (in bytes) used in the stream.

None indicates the value is unknown.

§maximum_frame_size: Option<NonZero<u32>>

The maximum framesize (in bytes) used in the stream.

None indicates the value is unknown.

§sample_rate: u32

Sample rate in Hz

0 indicates a non-audio stream.

§channels: NonZero<u8>

Number of channels, from 1 to 8

§bits_per_sample: SignedBitCount<32>

Number of bits-per-sample, from 4 to 32

§total_samples: Option<NonZero<u64>>

Total number of interchannel samples in stream.

None indicates the value is unknown.

§md5: Option<[u8; 16]>

MD5 hash of unencoded audio data.

None indicates the value is unknown.

Implementations§

Source§

impl Streaminfo

Source

pub const MAX_FRAME_SIZE: u32 = 16_777_215u32

The maximum size of a frame, in bytes (2²⁴ - 1)

Source

pub const MAX_SAMPLE_RATE: u32 = 1_048_575u32

The maximum sample rate, in Hz (2²⁰ - 1)

Source

pub const MAX_CHANNELS: NonZero<u8>

The maximum number of channels (8)

Source

pub const MAX_TOTAL_SAMPLES: NonZero<u64>

The maximum number of total samples (2³⁶ - 1)

Trait Implementations§

Source§

impl AsBlockRef for Streaminfo

Source§

fn as_block_ref(&self) -> BlockRef<'_>

Returns fresh reference to ourself.
Source§

impl Clone for Streaminfo

Source§

fn clone(&self) -> Streaminfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Streaminfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Streaminfo> for Block

Source§

fn from(b: Streaminfo) -> Self

Converts to this type from the input type.
Source§

impl FromBitStream for Streaminfo

Source§

type Error = Error

Error generated during parsing, such as io::Error
Source§

fn from_reader<R: BitRead + ?Sized>(r: &mut R) -> Result<Self, Self::Error>

Parse Self from reader
Source§

impl Metadata for Streaminfo

Source§

fn channel_count(&self) -> u8

Returns channel count Read more
Source§

fn sample_rate(&self) -> u32

Returns sample rate, in Hz
Source§

fn bits_per_sample(&self) -> u32

Returns decoder’s bits-per-sample Read more
Source§

fn total_samples(&self) -> Option<u64>

Returns total number of channel-independent samples, if known
Source§

fn md5(&self) -> Option<&[u8; 16]>

Returns MD5 of entire stream, if known Read more
Source§

fn channel_mask(&self) -> ChannelMask

Returns channel mask Read more
Source§

fn decoded_len(&self) -> Option<u64>

Returns total length of decoded file, in bytes
Source§

fn duration(&self) -> Option<Duration>

Returns duration of file
Source§

impl MetadataBlock for Streaminfo

Source§

const TYPE: BlockType = BlockType::Streaminfo

The metadata block’s type
Source§

const MULTIPLE: bool = false

Whether the block can occur multiple times in a file
Source§

fn bytes(&self) -> Option<BlockSize>

Size of block, in bytes, not including header
Source§

fn total_size(&self) -> Option<BlockSize>

Size of block, in bytes, including block header
Source§

impl PartialEq for Streaminfo

Source§

fn eq(&self, other: &Streaminfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToBitStream for Streaminfo

Source§

type Error = Error

Error generated during building, such as io::Error
Source§

fn to_writer<W: BitWrite + ?Sized>(&self, w: &mut W) -> Result<(), Self::Error>

Generate self to writer
Source§

fn bits<C>(&self) -> Result<C, Self::Error>
where C: Counter, Self: Sized,

Returns length of self in bits, if possible
Source§

fn bits_len<C, E>(&self) -> Result<C, Self::Error>
where C: Counter, E: Endianness, Self: Sized,

👎Deprecated since 4.0.0: use of bits() is preferred
Returns total length of self, if possible
Source§

impl TryFrom<Block> for Streaminfo

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(block: Block) -> Result<Self, ()>

Performs the conversion.
Source§

impl Eq for Streaminfo

Source§

impl StructuralPartialEq for Streaminfo

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.