From faf149d08eb4af322a8bbaa8ce83324d691a7737 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 31 Jan 2020 19:32:38 +0100 Subject: [PATCH] lib/xiph/OggVisitor: add method ReadGranulepos() --- src/lib/xiph/OggVisitor.cxx | 11 +++++++++++ src/lib/xiph/OggVisitor.hxx | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/lib/xiph/OggVisitor.cxx b/src/lib/xiph/OggVisitor.cxx index 153d20b7d..9f6d91dc5 100644 --- a/src/lib/xiph/OggVisitor.cxx +++ b/src/lib/xiph/OggVisitor.cxx @@ -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; +} diff --git a/src/lib/xiph/OggVisitor.hxx b/src/lib/xiph/OggVisitor.hxx index fd21313a6..20f7dcf2e 100644 --- a/src/lib/xiph/OggVisitor.hxx +++ b/src/lib/xiph/OggVisitor.hxx @@ -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();