Struct ogg::reading::BasePacketReader
source · pub struct BasePacketReader { /* private fields */ }
Expand description
Low level struct for reading from an Ogg stream.
Note that most times you’ll want the higher level PacketReader
struct.
It takes care of most of the internal parsing and logic, you will only have to take care of handing over your data.
Essentially, it manages a cache of package data for each logical
bitstream, and when the cache of every logical bistream is empty,
it asks for a fresh page. You will then need to feed the struct
one via the push_page
function.
All functions on this struct are async ready. They get their data fed, instead of calling and blocking in order to get it.
Implementations§
source§impl BasePacketReader
impl BasePacketReader
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new blank BasePacketReader
.
You can feed it data using the push_page
function, and
obtain data using the read_packet
function.
sourcepub fn read_packet(&mut self) -> Option<Packet>
pub fn read_packet(&mut self) -> Option<Packet>
Extracts a packet from the cache, if the cache contains valid packet data,
otherwise it returns None
.
If this function returns None
, you’ll need to add a page to the cache
by using the push_page
function.
sourcepub fn push_page(&mut self, page: OggPage) -> Result<(), OggReadError>
pub fn push_page(&mut self, page: OggPage) -> Result<(), OggReadError>
Pushes a given Ogg page, updating the internal structures with its contents.
If you want the code to function properly, you should first call
parse_segments
, then parse_packet_data
on a PageParser
before passing the resulting OggPage
to this function.
sourcepub fn update_after_seek(&mut self)
pub fn update_after_seek(&mut self)
Reset the internal state after a seek
It flushes the cache so that no partial data is left inside. It also tells the parsing logic to expect little inconsistencies due to the read position not being at the start.