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> /* exit */ #include <oggz/oggz.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; oggz_write_feed (oggz, &op, serialno, OGGZ_FLUSH_AFTER, NULL); granulepos += 100; packetno++; return 0; } int main (int argc, char * argv[]) { char * progname, * filename = NULL; OGGZ * oggz; long n; progname = argv[0]; if (argc > 1) filename = argv[1]; if (filename) { oggz = oggz_open (filename, OGGZ_WRITE); } else { oggz = oggz_open_stdio (stdout, OGGZ_WRITE); } if (oggz == NULL) { fprintf (stderr, "%s: Error creating oggz\n", progname); exit (1); } serialno = oggz_serialno_new (oggz); if (oggz_write_set_hungry_callback (oggz, hungry, 1, NULL) == -1) { fprintf (stderr, "%s: Error setting OggzHungry callback\n", progname); exit (1); } while ((n = oggz_write (oggz, 32)) > 0); oggz_close (oggz); exit (0); }
00001 00033 #include <stdlib.h> /* exit */ 00034 #include <oggz/oggz.h> 00035 00036 static long serialno; 00037 static ogg_int64_t granulepos = 0; 00038 static ogg_int64_t packetno = 0; 00039 00040 static int 00041 hungry (OGGZ * oggz, int empty, void * user_data) 00042 { 00043 ogg_packet op; 00044 unsigned char buf[1]; 00045 00046 buf[0] = 'A' + (int)packetno; 00047 00048 op.packet = buf; 00049 op.bytes = 1; 00050 op.granulepos = granulepos; 00051 op.packetno = packetno; 00052 00053 if (packetno == 0) op.b_o_s = 1; 00054 else op.b_o_s = 0; 00055 00056 if (packetno == 9) op.e_o_s = 1; 00057 else op.e_o_s = 0; 00058 00059 oggz_write_feed (oggz, &op, serialno, OGGZ_FLUSH_AFTER, NULL); 00060 00061 granulepos += 100; 00062 packetno++; 00063 00064 return 0; 00065 } 00066 00067 int 00068 main (int argc, char * argv[]) 00069 { 00070 char * progname, * filename = NULL; 00071 OGGZ * oggz; 00072 long n; 00073 00074 progname = argv[0]; 00075 if (argc > 1) filename = argv[1]; 00076 00077 if (filename) { 00078 oggz = oggz_open (filename, OGGZ_WRITE); 00079 } else { 00080 oggz = oggz_open_stdio (stdout, OGGZ_WRITE); 00081 } 00082 00083 if (oggz == NULL) { 00084 fprintf (stderr, "%s: Error creating oggz\n", progname); 00085 exit (1); 00086 } 00087 00088 serialno = oggz_serialno_new (oggz); 00089 00090 if (oggz_write_set_hungry_callback (oggz, hungry, 1, NULL) == -1) { 00091 fprintf (stderr, "%s: Error setting OggzHungry callback\n", progname); 00092 exit (1); 00093 } 00094 00095 while ((n = oggz_write (oggz, 32)) > 0); 00096 00097 oggz_close (oggz); 00098 00099 exit (0); 00100 }