Commit e7ea2e48 authored by conrad's avatar conrad

add serialno argument to oggz_read_page callbacks

git-svn-id: http://svn.annodex.net/liboggz/trunk@588 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 1f31e50b
......@@ -104,24 +104,31 @@ int oggz_set_read_callback (OGGZ * oggz, long serialno,
* \returns 0 to continue, non-zero to instruct OGGZ to stop.
*/
typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og,
void * user_data);
long serialno, void * user_data);
/**
* Set a callback for Oggz to call when a new Ogg page is found in the
* stream.
*
* \param oggz An OGGZ handle previously opened for reading
* \param serialno Identify the logical bitstream in \a oggz to attach
* this callback to, or -1 to attach this callback to all unattached
* logical bitstreams in \a oggz.
* \param read_page Your OggzReadPage callback function
* \param user_data Arbitrary data you wish to pass to your callback
* \retval 0 Success
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
*
* \note Values of \a serialno other than -1 allows you to specify different
* callback functions for each logical bitstream.
*
* \note It is safe to call this callback from within an OggzReadPage
* function, in order to specify that subsequent pages should be handled
* by a different OggzReadPage function.
*/
int oggz_set_read_page (OGGZ * oggz, OggzReadPage read_page, void * user_data);
int oggz_set_read_page (OGGZ * oggz, long serialno,
OggzReadPage read_page, void * user_data);
/**
......
......@@ -273,6 +273,8 @@ oggz_add_stream (OGGZ * oggz, long serialno)
stream->order_user_data = NULL;
stream->read_packet = NULL;
stream->read_user_data = NULL;
stream->read_page = NULL;
stream->read_page_user_data = NULL;
oggz_vector_insert_p (oggz->streams, stream);
......
......@@ -49,7 +49,7 @@ typedef struct _OggzWriter OggzWriter;
typedef int (*OggzReadPacket) (OGGZ * oggz, ogg_packet * op, long serialno,
void * user_data);
typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og,
typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og, long serialno,
void * user_data);
typedef ogg_int64_t (*OggzMetric) (OGGZ * oggz, long serialno,
......@@ -88,6 +88,9 @@ typedef struct {
OggzReadPacket read_packet;
void * read_user_data;
OggzReadPage read_page;
void * read_page_user_data;
} oggz_stream_t;
struct _OggzReader {
......
......@@ -136,9 +136,11 @@ oggz_set_read_callback (OGGZ * oggz, long serialno,
}
int
oggz_set_read_page (OGGZ * oggz, OggzReadPage read_page, void * user_data)
oggz_set_read_page (OGGZ * oggz, long serialno, OggzReadPage read_page,
void * user_data)
{
OggzReader * reader;
oggz_stream_t * stream;
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
......@@ -148,8 +150,21 @@ oggz_set_read_page (OGGZ * oggz, OggzReadPage read_page, void * user_data)
return OGGZ_ERR_INVALID;
}
reader->read_page = read_page;
reader->read_page_user_data = user_data;
if (serialno == -1) {
reader->read_page = read_page;
reader->read_page_user_data = user_data;
} else {
stream = oggz_get_stream (oggz, serialno);
#if 0
if (stream == NULL) return OGGZ_ERR_BAD_SERIALNO;
#else
if (stream == NULL)
stream = oggz_add_stream (oggz, serialno);
#endif
stream->read_page = read_page;
stream->read_page_user_data = user_data;
}
return 0;
}
......@@ -333,8 +348,12 @@ oggz_read_sync (OGGZ * oggz)
}
}
if (reader->read_page) {
cb_ret = reader->read_page (oggz, &og, reader->read_page_user_data);
if (stream->read_page) {
cb_ret =
stream->read_page (oggz, &og, serialno, stream->read_page_user_data);
} else if (reader->read_page) {
cb_ret = reader->read_page (oggz, &og, serialno,
reader->read_page_user_data);
}
#if 0
......
......@@ -43,9 +43,6 @@
#define READ_SIZE 4096
static int
read_page (OGGZ * oggz, const ogg_page * og, void * user_data);
static void
usage (char * progname)
{
......@@ -138,6 +135,16 @@ omdata_delete (OMData * omdata)
free (omdata);
}
static int
read_page (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
{
OMInput * input = (OMInput *) user_data;
input->og = _ogg_page_copy (og);
return OGGZ_STOP_OK;
}
static int
omdata_add_input (OMData * omdata, FILE * infile)
{
......@@ -151,7 +158,7 @@ omdata_add_input (OMData * omdata, FILE * infile)
input->reader = oggz_open_stdio (infile, OGGZ_READ|OGGZ_AUTO);
input->og = NULL;
oggz_set_read_page (input->reader, read_page, input);
oggz_set_read_page (input->reader, -1, read_page, input);
nfiles = oggz_table_size (omdata->inputs);
if (!oggz_table_insert (omdata->inputs, nfiles++, input)) {
......@@ -162,16 +169,6 @@ omdata_add_input (OMData * omdata, FILE * infile)
return 0;
}
static int
read_page (OGGZ * oggz, const ogg_page * og, void * user_data)
{
OMInput * input = (OMInput *) user_data;
input->og = _ogg_page_copy (og);
return OGGZ_STOP_OK;
}
static int
oggz_merge (OMData * omdata, FILE * outfile)
{
......
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