Struct CafPacketReader

Source
pub struct CafPacketReader<T>
where T: Read + Seek,
{ pub audio_desc: AudioDescription, pub packet_table: Option<PacketTable>, pub chunks: Vec<CafChunk>, pub edit_count: u32, /* private fields */ }
Expand description

High level Packet reading

Provides a very convenient iterator over the packets of the audio chunk.

Fields§

§audio_desc: AudioDescription§packet_table: Option<PacketTable>§chunks: Vec<CafChunk>§edit_count: u32

The edit count value stored in the audio chunk.

Implementations§

Source§

impl<T> CafPacketReader<T>
where T: Read + Seek,

Source

pub fn new(rdr: T, filter_by: Vec<ChunkType>) -> Result<Self, CafError>

Creates a new CAF packet reader struct from a given reader.

With the filter_by argument you can pass a list of chunk types that are important for you. You shouldn’t specify three chunk types though: AudioData, AudioDescription and PacketTable. These are implicitly retrieved, and you can extract the content through iterating over the packets (which are all small parts of the AudioData chunk), and through the audio_desc and packet_table members.

Equal to calling CafChunkReader::new and passing its result to from_chunk_reader.

Source

pub fn from_chunk_reader( ch_rdr: CafChunkReader<T>, filter_by: Vec<ChunkType>, ) -> Result<Self, CafError>

Creates a new CAF packet reader struct from a given chunk reader.

With the filter_by argument you can pass a list of chunk types that are important for you. You shouldn’t specify three chunk types though: AudioData, AudioDescription and PacketTable. These are implicitly retrieved, and you can extract the content through iterating over the packets (which are all small parts of the AudioData chunk), and through the audio_desc and packet_table members.

Source

pub fn into_inner(self) -> CafChunkReader<T>

Source

pub fn packet_size_is_constant(&self) -> bool

Returns whether the size of the packets doesn’t change

Some formats have a constant, not changing packet size (mostly the uncompressed ones).

Source

pub fn next_packet_size(&self) -> Option<usize>

Returns the size of the next packet in bytes.

Returns None if all packets were read, Some(_) otherwise.

Very useful if you want to allocate the packet slice yourself.

Source

pub fn next_packet(&mut self) -> Result<Option<Vec<u8>>, CafError>

Read one packet from the audio chunk

Returns Ok(Some(v)) if the next packet could be read successfully, Ok(None) if its the last chunk.

Source

pub fn read_packet_into(&mut self, data: &mut [u8]) -> Result<(), CafError>

Read one packet from the audio chunk into a pre-allocated array

The method doesn’t check whether the size of the passed slice matches the actual next packet length, it uses the length blindly. For correct operation, only use sizes returned from the next_packet_size function, and only if it didn’t return None.

Source

pub fn get_packet_count(&self) -> Option<usize>

Gets the number of packets if its known.

Source

pub fn get_packet_idx(&self) -> usize

Returns the index of the currently read packet

Source

pub fn seek_to_packet(&mut self, packet_idx: usize) -> Result<(), CafError>

Seeks to the packet with the given index

This function never has been tested. If there are bugs please report them.

Auto Trait Implementations§

§

impl<T> Freeze for CafPacketReader<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for CafPacketReader<T>
where T: RefUnwindSafe,

§

impl<T> Send for CafPacketReader<T>
where T: Send,

§

impl<T> Sync for CafPacketReader<T>
where T: Sync,

§

impl<T> Unpin for CafPacketReader<T>
where T: Unpin,

§

impl<T> UnwindSafe for CafPacketReader<T>
where T: 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.