Struct ogg::reading::PacketReader
source · pub struct PacketReader<T: Read + Seek> { /* private fields */ }
Expand description
Reader for packets from an Ogg stream.
This reads codec packets belonging to several different logical streams from one physical Ogg container stream.
This reader is not async ready. It does not keep its internal state
consistent when it encounters the WouldBlock
error kind.
If you desire async functionality, consider enabling the async
feature
and look into the async module.
Implementations§
source§impl<T: Read + Seek> PacketReader<T>
impl<T: Read + Seek> PacketReader<T>
sourcepub fn new(rdr: T) -> PacketReader<T>
pub fn new(rdr: T) -> PacketReader<T>
Constructs a new PacketReader
with a given Read
.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the wrapped reader, consuming the PacketReader
.
sourcepub fn read_packet(&mut self) -> Result<Option<Packet>, OggReadError>
pub fn read_packet(&mut self) -> Result<Option<Packet>, OggReadError>
Reads a packet, and returns it on success.
Ok(None) is returned if the physical stream has ended.
sourcepub fn read_packet_expected(&mut self) -> Result<Packet, OggReadError>
pub fn read_packet_expected(&mut self) -> Result<Packet, OggReadError>
Reads a packet, and returns it on success.
The difference to the read_packet
function is that this function
returns an Err(_) if the physical stream has ended.
This function is useful if you expect a new packet to come.
sourcepub fn seek_bytes(&mut self, pos: SeekFrom) -> Result<u64, Error>
pub fn seek_bytes(&mut self, pos: SeekFrom) -> Result<u64, Error>
Seeks the underlying reader
Seeks the reader that this PacketReader bases on by the specified number of bytes. All new pages will be read from the new position.
This also flushes all the unread packets in the queue.
sourcepub fn seek_absgp(
&mut self,
stream_serial: Option<u32>,
pos_goal: u64
) -> Result<bool, OggReadError>
pub fn seek_absgp( &mut self, stream_serial: Option<u32>, pos_goal: u64 ) -> Result<bool, OggReadError>
Seeks to absolute granule pos
More specifically, it seeks to the first Ogg page
that has an absgp
greater or equal to the specified one.
In the case of continued packets, the seek operation may also end up
at the last page that comes before such a page and has a packet start.
The passed stream_serial
parameter controls the stream
serial number to filter our search for. If it’s None
, no
filtering is applied, but if it is Some(n)
, we filter for
streams with the serial number n
.
Note that the None
case is only intended for streams
where only one logical stream exists, the seek may misbehave
if Ǹone
gets passed when multiple streams exist.
The returned bool indicates whether the seek was successful.
sourcepub fn delete_unread_packets(&mut self)
pub fn delete_unread_packets(&mut self)
Resets the internal state by deleting all unread packets.