lib/xiph/OggVisitor: add method ReadGranulepos()

This commit is contained in:
Max Kellermann 2020-01-31 19:32:38 +01:00
parent e01bbad7bb
commit faf149d08e
2 changed files with 27 additions and 0 deletions

View File

@ -108,3 +108,14 @@ OggVisitor::PostSeek(uint64_t offset)
post_seek = true;
}
ogg_int64_t
OggVisitor::ReadGranulepos() noexcept
{
ogg_packet packet;
while (stream.PacketOut(packet) == 1)
if (packet.granulepos >= 0)
return packet.granulepos;
return -1;
}

View File

@ -66,6 +66,22 @@ public:
*/
void PostSeek(uint64_t offset);
/**
* Skip packets (#ogg_packet) from the #OggStreamState until a
* packet with a valid granulepos is found or until the stream
* has run dry.
*
* Since this will discard pending packets and will disturb
* this object, this should only be used while seeking.
*
* This method must not be called from within one of the
* virtual methods.
*
* @return the granulepos or -1 if no valid granulepos was
* found
*/
ogg_int64_t ReadGranulepos() noexcept;
private:
void EndStream();
bool ReadNextPage();