Commit 718a73d3 authored by conrad's avatar conrad

oggz_read: always set the internal offset to the start of the current page.

This is returned by oggz_tell() and can be queried within a ReadPage callback.
parent 38b6dffb
...@@ -139,6 +139,7 @@ struct _OggzReader { ...@@ -139,6 +139,7 @@ struct _OggzReader {
ogg_int64_t current_unit; ogg_int64_t current_unit;
ogg_int64_t current_granulepos; ogg_int64_t current_granulepos;
long current_page_bytes;
#if 0 #if 0
oggz_off_t offset_page_end; /* offset of end of current page */ oggz_off_t offset_page_end; /* offset of end of current page */
#endif #endif
......
...@@ -86,6 +86,8 @@ oggz_read_init (OGGZ * oggz) ...@@ -86,6 +86,8 @@ oggz_read_init (OGGZ * oggz)
reader->current_unit = 0; reader->current_unit = 0;
reader->current_page_bytes = 0;
return oggz; return oggz;
} }
...@@ -183,26 +185,33 @@ oggz_read_get_next_page (OGGZ * oggz, ogg_page * og) ...@@ -183,26 +185,33 @@ oggz_read_get_next_page (OGGZ * oggz, ogg_page * og)
oggz_off_t page_offset = 0, ret; oggz_off_t page_offset = 0, ret;
int found = 0; int found = 0;
/* Increment oggz->offset by length of the last page processed */
oggz->offset += reader->current_page_bytes;
do { do {
more = ogg_sync_pageseek (&reader->ogg_sync, og); more = ogg_sync_pageseek (&reader->ogg_sync, og);
if (more == 0) { if (more == 0) {
/* No page available */
page_offset = 0; page_offset = 0;
return -2; return -2;
} else if (more < 0) { } else if (more < 0) {
#ifdef DEBUG_VERBOSE #ifdef DEBUG_VERBOSE
printf ("get_next_page: skipped %ld bytes\n", -more); printf ("get_next_page: skipped %ld bytes\n", -more);
#endif #endif
page_offset -= more; page_offset += (-more);
oggz->offset += (-more);
} else { } else {
#ifdef DEBUG_VERBOSE #ifdef DEBUG_VERBOSE
printf ("get_next_page: page has %ld bytes\n", more); printf ("get_next_page: page has %ld bytes\n", more);
#endif #endif
reader->current_page_bytes = more;
found = 1; found = 1;
} }
} while (!found); } while (!found);
#if 0 /* This is now done by the increment at the top of the file */
/* Calculate the byte offset of the page which was found */ /* Calculate the byte offset of the page which was found */
if (bytes > 0) { if (bytes > 0) {
oggz->offset = oggz_io_tell (oggz) - bytes + page_offset; oggz->offset = oggz_io_tell (oggz) - bytes + page_offset;
...@@ -214,6 +223,9 @@ oggz_read_get_next_page (OGGZ * oggz, ogg_page * og) ...@@ -214,6 +223,9 @@ oggz_read_get_next_page (OGGZ * oggz, ogg_page * og)
} }
return ret; return ret;
#else
return oggz->offset;
#endif
} }
typedef struct { typedef struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment