From 7e3eaa592141ca9f26a3f18e6a2362b9712d6d49 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 27 Jan 2020 20:43:29 +0100 Subject: [PATCH] lib/xiph/OggSyncState: keep track of the Reader offset --- src/lib/xiph/OggSyncState.cxx | 13 +++++++++++-- src/lib/xiph/OggSyncState.hxx | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/lib/xiph/OggSyncState.cxx b/src/lib/xiph/OggSyncState.cxx index b62dac001..f8d7aa67c 100644 --- a/src/lib/xiph/OggSyncState.cxx +++ b/src/lib/xiph/OggSyncState.cxx @@ -40,8 +40,13 @@ OggSyncState::ExpectPage(ogg_page &page) { while (true) { int r = ogg_sync_pageout(&oy, &page); - if (r != 0) + if (r != 0) { + if (r > 0) { + start_offset = offset; + offset += r; + } return r > 0; + } if (!Feed(1024)) return false; @@ -66,12 +71,16 @@ OggSyncState::ExpectPageSeek(ogg_page &page) while (true) { int r = ogg_sync_pageseek(&oy, &page); - if (r > 0) + if (r > 0) { + start_offset = offset; + offset += r; return true; + } if (r < 0) { /* skipped -r bytes */ size_t nbytes = -r; + offset += nbytes; if (nbytes > remaining_skipped) /* still no ogg page - we lost our patience, abort */ diff --git a/src/lib/xiph/OggSyncState.hxx b/src/lib/xiph/OggSyncState.hxx index 5efca7fd1..bfb84b7e7 100644 --- a/src/lib/xiph/OggSyncState.hxx +++ b/src/lib/xiph/OggSyncState.hxx @@ -23,6 +23,7 @@ #include #include +#include class Reader; @@ -34,6 +35,17 @@ class OggSyncState { Reader &reader; + /** + * Keeps track of the end offset of the most recently returned + * page. + */ + uint64_t offset = 0; + + /** + * The start offset of the most recently returned page. + */ + uint64_t start_offset = 0; + public: explicit OggSyncState(Reader &_reader) :reader(_reader) { @@ -51,6 +63,14 @@ public: ogg_sync_reset(&oy); } + void SetOffset(uint64_t _offset) noexcept { + offset = _offset; + } + + uint64_t GetStartOffset() const noexcept { + return start_offset; + } + bool Feed(size_t size); bool ExpectPage(ogg_page &page);