lib/xiph/OggSyncState: keep track of the Reader offset
This commit is contained in:
parent
6fe4068c8e
commit
7e3eaa5921
@ -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 */
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <ogg/ogg.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user