Commit 32ef1286 authored by shans's avatar shans

Some improvements to seeking algorithm



git-svn-id: http://svn.annodex.net/liboggz/trunk@3163 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent ec63db2b
......@@ -97,8 +97,8 @@ oggz_tell_raw (OGGZ * oggz)
*/
int
oggz_seek_reset_stream(void *data) {
((oggz_stream_t *)data)->last_granulepos = -1;
oggz_seek_reset_stream(void *data, void *arg) {
((oggz_stream_t *)data)->last_granulepos = (int)arg;
return 0;
}
......@@ -107,8 +107,7 @@ oggz_seek_raw (OGGZ * oggz, oggz_off_t offset, int whence)
{
OggzReader * reader = &oggz->x.reader;
oggz_off_t offset_at;
oggz_vector_foreach(oggz->streams, oggz_seek_reset_stream);
int i;
if (oggz_io_seek (oggz, offset, whence) == -1) {
return -1;
......@@ -120,6 +119,8 @@ oggz_seek_raw (OGGZ * oggz, oggz_off_t offset, int whence)
ogg_sync_reset (&reader->ogg_sync);
oggz_vector_foreach1(oggz->streams, oggz_seek_reset_stream, -1);
return offset_at;
}
......@@ -285,8 +286,9 @@ oggz_get_next_start_page (OGGZ * oggz, ogg_page * og)
* !ogg_page_continued : page contains start of a packet
* ogg_page_packets > 1: page contains start of a packet
*/
if (page_offset <= 0 || !ogg_page_continued (og) ||
ogg_page_packets (og) > 1)
/*if (page_offset <= 0 || !ogg_page_continued (og) ||
ogg_page_packets (og) > 1)*/
if (page_offset <= 0 || ogg_page_granulepos(og) > -1)
found = 1;
}
while (!found);
......@@ -377,8 +379,8 @@ oggz_get_prev_start_page (OGGZ * oggz, ogg_page * og,
offset_at = oggz_reset (oggz, found_offset, unit_at, SEEK_SET);
#ifdef DEBUG
printf ("get_prev_start_page: [C] offset_at: @%" PRI_OGGZ_OFF "d\t"
"found_offset: @%" PRO_OGGZ_OFF "d\tunit_at: %lld\n",
printf ("get_prev_start_page: [C] offset_at: @%" PRI_OGGZ_OFF_T "d\t"
"found_offset: @%" PRI_OGGZ_OFF_T "d\tunit_at: %lld\n",
offset_at, found_offset, unit_at);
#endif
......@@ -484,6 +486,10 @@ oggz_scan_for_page (OGGZ * oggz, ogg_page * og, ogg_int64_t unit_target,
break;
#else
do {
offset_at = oggz_get_prev_start_page(oggz, og, &granule_at, &serialno);
unit_at = oggz_get_unit(oggz, serialno, granule_at);
} while (unit_at > unit_target);
return offset_at;
#endif
} else if (unit_at == unit_target) {
......@@ -753,9 +759,10 @@ oggz_seek_set (OGGZ * oggz, ogg_int64_t unit_target)
}
found:
do {
offset_at = oggz_get_prev_start_page (oggz, og, &granule_at, &serialno);
unit_at = oggz_get_unit (oggz, serialno, granule_at);
} while (unit_at > unit_target);
if (offset_at < 0) {
oggz_reset (oggz, offset_orig, -1, SEEK_SET);
......
......@@ -39,6 +39,7 @@
#include "oggz_macros.h"
typedef int (*OggzFunc) (void * data);
typedef int (*OggzFunc1) (void * data, void * arg);
typedef int (*OggzFindFunc) (void * data, long serialno);
typedef int (*OggzCmpFunc) (const void * a, const void * b, void * user_data);
......@@ -196,6 +197,18 @@ oggz_vector_foreach (OggzVector * vector, OggzFunc func)
return 0;
}
int
oggz_vector_foreach1 (OggzVector * vector, OggzFunc1 func, void *arg)
{
int i;
for (i = 0; i < vector->nr_elements; i++) {
func (vector->data[i].p, arg);
}
return 0;
}
static void
_array_swap (oggz_data_t v[], int i, int j)
{
......
......@@ -36,6 +36,7 @@
typedef void OggzVector;
typedef int (*OggzFunc) (void * data);
typedef int (*OggzFunc1) (void * data, void *arg);
typedef int (*OggzFindFunc) (void * data, long serialno);
typedef int (*OggzCmpFunc) (const void * a, const void * b, void * user_data);
......@@ -63,6 +64,9 @@ oggz_vector_nth_l (OggzVector * vector, int n);
int
oggz_vector_foreach (OggzVector * vector, OggzFunc func);
int
oggz_vector_foreach1 (OggzVector * vector, OggzFunc1 func, void *arg);
int
oggz_vector_size (OggzVector * vector);
......
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