These mechanisms are illustrated in src/examples/print-lots.c:
#include <stdio.h> #include <string.h> #include <annodex/annodex.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.