pub struct CafPacketReader<T>{
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>
impl<T> CafPacketReader<T>
Sourcepub fn new(rdr: T, filter_by: Vec<ChunkType>) -> Result<Self, CafError>
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
.
Sourcepub fn from_chunk_reader(
ch_rdr: CafChunkReader<T>,
filter_by: Vec<ChunkType>,
) -> Result<Self, CafError>
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.
pub fn into_inner(self) -> CafChunkReader<T>
Sourcepub fn packet_size_is_constant(&self) -> bool
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).
Sourcepub fn next_packet_size(&self) -> Option<usize>
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.
Sourcepub fn next_packet(&mut self) -> Result<Option<Vec<u8>>, CafError>
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.
Sourcepub fn read_packet_into(&mut self, data: &mut [u8]) -> Result<(), CafError>
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
.
Sourcepub fn get_packet_count(&self) -> Option<usize>
pub fn get_packet_count(&self) -> Option<usize>
Gets the number of packets if its known.
Sourcepub fn get_packet_idx(&self) -> usize
pub fn get_packet_idx(&self) -> usize
Returns the index of the currently read packet