libannodex  0.7.3
Advanced management of AnxRead* callbacks

You retain control of the number of bytes read or input, and the callbacks you provide can instruct libannodex to immediately return control back to your application.

Callbacks

It is not required to implement all callbacks.

Return values

These mechanisms are illustrated in src/examples/print-lots.c:

#include <stdio.h>
#include <string.h>
struct my_data {
char * filename;
long interesting_serialno;
int interesting_raw_packets;
int done;
};
static int
read_stream (ANNODEX * anx, double timebase, char * utc, void * user_data)
{
struct my_data * happy = (struct my_data *) user_data;
printf ("Welcome to %s! The timebase is %f\n", happy->filename, timebase);
return ANX_CONTINUE;
}
static int
read_track (ANNODEX * anx, long serialno, char * id, char * content_type,
anx_int64_t granule_rate_n, anx_int64_t granule_rate_d,
int nr_header_packets, void * user_data)
{
struct my_data * happy = (struct my_data *) user_data;
/* Ignore the annotations track, we don't find it interesting! */
if (!strncmp (content_type, "text/x-cmml", 12)) return ANX_CONTINUE;
printf ("Our first track has content-type %s and granule rate %ld/%ld.\n",
content_type, (long)granule_rate_n, (long)granule_rate_d);
printf ("We will remember it by its serial number %ld "
"and mark it with crosses.\n", serialno);
happy->interesting_serialno = serialno;
/* We don't care about any other tracks! */
anx_set_read_track_callback (anx, NULL, NULL);
return ANX_CONTINUE;
}
static int
read_raw (ANNODEX * annodex, unsigned char * buf, long n,
long serialno, anx_int64_t granulepos, void * user_data)
{
struct my_data * happy = (struct my_data *) user_data;
if (happy->done) {
putchar ('!');
} else if (serialno == happy->interesting_serialno) {
happy->interesting_raw_packets++;
putchar ('+');
} else {
putchar ('.');
}
return ANX_CONTINUE;
}
static int
read_clip3 (ANNODEX * anx, const AnxClip * clip, void * user_data)
{
struct my_data * happy = (struct my_data *) user_data;
printf ("\nAnd the third clip links to %s\n", clip->anchor_href);
happy->done = 1;
printf ("This completes our whirlwind tour of the first three clips!\n");
return ANX_STOP_OK;
}
static int
read_clip2 (ANNODEX * anx, const AnxClip * clip, void * user_data)
{
printf ("\nThe second clip links to %s\n", clip->anchor_href);
anx_set_read_clip_callback (anx, read_clip3, user_data);
return ANX_CONTINUE;
}
static int
read_clip1 (ANNODEX * anx, const AnxClip * clip, void * user_data)
{
printf ("\nThe first clip links to %s\n", clip->anchor_href);
anx_set_read_clip_callback (anx, read_clip2, user_data);
return ANX_CONTINUE;
}
int
main (int argc, char *argv[])
{
ANNODEX * anx = NULL;
struct my_data me;
long n;
if (argc != 2) {
fprintf (stderr, "Usage: %s file.anx\n", argv[0]);
exit (1);
}
me.filename = argv[1];
me.interesting_serialno = -1;
me.interesting_raw_packets = 0;
me.done = 0;
anx = anx_open (me.filename, ANX_READ);
anx_set_read_stream_callback (anx, read_stream, &me);
anx_set_read_track_callback (anx, read_track, &me);
anx_set_read_raw_callback (anx, read_raw, &me);
anx_set_read_clip_callback (anx, read_clip1, &me);
while (!me.done && (n = anx_read (anx, 1024)) > 0);
printf ("%d packets from the first track (serialno %ld) were received\n",
me.interesting_raw_packets, me.interesting_serialno);
printf ("before the third clip.\n");
anx_close (anx);
exit (0);
}

which produces output like:

Welcome to /tmp/alien_song.anx! The timebase is 20.000000
Our first track has mime-type video/x-theora and granule rate 1536/1.
We will remember it by its serial number 1810353996 and mark it with crosses.
+...+++++++++++++++++...................................++++++++++++++..........
......................++++++++++++..............................++++++++++++++++
++++..............................+++++++++++++.................................
...++++++++++++++++++++++................................++++++++++++++.........
........................++++++++++++++++....................................++++
++++++++++.......................................++++++++++++++.................
......+++++++++++++.......................+++++++++++++.........................
...+++++++++++++..................................+++++++++++++.................
......+++++++++++++...............................++++++++++++++................
..........+++++++++++..........................++++++++++++++...................
.....++++++++++++.......................++++++++++++........................++++
++++++++........................+++++++++++++........................+++++++++++
+++++.......................+++++++++++.......................+++++++++++++++++.
......................+++++++++++++........................++++++++++...........
.............+++++++++++.......................++++++++++++++++++...............
........++++++++........................+++++++++++++++++.......................
++++++++.......................+++++++++++++++++........................++++++++
++++++...........................+++++++++++........................++++++++++++
+++........................+++++++++++.......................++++++++++++++.....
.................++++++++++++++..............................++++++++++.........
.........................++++++++++++................................+++++++++++
+++...................................++++++
The first anchor links to http://www.mars.int/
+
The second anchor links to http://www.pluto.int/
+++......................+++++++++++.............................+++++++++++....
...........................+++++++++++..........................................
.......+++++++++++++...........................+++++++++++......................
.......+
And the third anchor links to http://www.venus.int/
This completes our whirlwind tour of the first three anchors!
639 packets from the first track (serialno 1810353996) were received
before the third anchor.
 
annodex.h
anx_set_read_raw_callback
int anx_set_read_raw_callback(ANNODEX *annodex, AnxReadRaw read_raw, void *user_data)
Set the function to call each time a raw data packet is read.
anx_set_read_clip_callback
int anx_set_read_clip_callback(ANNODEX *annodex, AnxReadClip read_clip, void *user_data)
Set the function to call each time a clip is parsed.
ANNODEX
void ANNODEX
An ANNODEX handle.
Definition: anx_types.h:55
anx_open
ANNODEX * anx_open(char *filename, int mode)
Open a file containing Annodex media.
_AnxClip
Definition: anx_types.h:102
anx_int64_t
int64_t anx_int64_t
This typedef was determined on the system on which the documentation was generated.
Definition: anx_int64.h:93
anx_set_read_stream_callback
int anx_set_read_stream_callback(ANNODEX *annodex, AnxReadStream read_stream, void *user_data)
Set the function to call each time an 'Annodex' stream header is parsed.
anx_set_read_track_callback
int anx_set_read_track_callback(ANNODEX *annodex, AnxReadTrack read_track, void *user_data)
Set the function to call each time an 'AnxData' track header is parsed.
anx_read
long anx_read(ANNODEX *annodex, long n)
Read from an annodex opened with anx_open() or anx_open_stdio().
anx_close
ANNODEX * anx_close(ANNODEX *annodex)
Close an annodex.
my_data
Copyright (C) 2003 Commonwealth Scientific and Industrial Research Organisation (CSIRO) Australia.
Definition: print-lots.c:37
_AnxClip::anchor_href
const char * anchor_href
href out of clip
Definition: anx_types.h:114