You can add packets to the Oggz packet queue only when it is "hungry" by providing an OggzHungry callback.
More...
You can add packets to the Oggz packet queue only when it is "hungry" by providing an OggzHungry callback.
An OggzHungry callback will:
Once you have set such a callback with oggz_write_set_hungry_callback(), simply call oggz_write() or oggz_write_output() repeatedly, and Oggz will call your callback to provide packets when it is hungry.
This process is illustrated in the following diagram:
The following example code generates a stream of ten packets, each containing a single byte ('A', 'B', ... , 'J'):
#include <stdlib.h>
static long serialno;
static ogg_int64_t granulepos = 0;
static ogg_int64_t packetno = 0;
static int
hungry (
OGGZ * oggz,
int empty,
void * user_data)
{
ogg_packet op;
unsigned char buf[1];
buf[0] = 'A' + (int)packetno;
op.packet = buf;
op.bytes = 1;
op.granulepos = granulepos;
op.packetno = packetno;
if (packetno == 0) op.b_o_s = 1;
else op.b_o_s = 0;
if (packetno == 9) op.e_o_s = 1;
else op.e_o_s = 0;
granulepos += 100;
packetno++;
return 0;
}
int
main (int argc, char * argv[])
{
char * progname, * filename = NULL;
long n;
progname = argv[0];
if (argc > 1) filename = argv[1];
if (filename) {
} else {
}
if (oggz == NULL) {
fprintf (stderr, "%s: Error creating oggz\n", progname);
exit (1);
}
fprintf (stderr, "%s: Error setting OggzHungry callback\n", progname);
exit (1);
}
exit (0);
}