Main Page | Modules | File List | Globals

Writing by force feeding OGGZ

forcefeed.png

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; int main (int argc, char * argv[]) { char * progname, * filename = NULL; OGGZ * oggz; ogg_packet op; unsigned char buf[1]; 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); for (packetno = 0; packetno < 10; packetno++) { /* Create a packet */ 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; /* Feed it to the Oggz packet queue */ oggz_write_feed (oggz, &op, serialno, OGGZ_FLUSH_AFTER, NULL); granulepos += 100; packetno++; /* Write bytes from packetized bitstream to the output file */ 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 int 00041 main (int argc, char * argv[]) 00042 { 00043 char * progname, * filename = NULL; 00044 OGGZ * oggz; 00045 ogg_packet op; 00046 unsigned char buf[1]; 00047 long n; 00048 00049 progname = argv[0]; 00050 if (argc > 1) filename = argv[1]; 00051 00052 if (filename) { 00053 oggz = oggz_open (filename, OGGZ_WRITE); 00054 } else { 00055 oggz = oggz_open_stdio (stdout, OGGZ_WRITE); 00056 } 00057 00058 if (oggz == NULL) { 00059 fprintf (stderr, "%s: Error creating oggz\n", progname); 00060 exit (1); 00061 } 00062 00063 serialno = oggz_serialno_new (oggz); 00064 00065 for (packetno = 0; packetno < 10; packetno++) { 00066 00067 /* Create a packet */ 00068 00069 buf[0] = 'A' + (int)packetno; 00070 00071 op.packet = buf; 00072 op.bytes = 1; 00073 op.granulepos = granulepos; 00074 op.packetno = packetno; 00075 00076 if (packetno == 0) op.b_o_s = 1; 00077 else op.b_o_s = 0; 00078 00079 if (packetno == 9) op.e_o_s = 1; 00080 else op.e_o_s = 0; 00081 00082 /* Feed it to the Oggz packet queue */ 00083 00084 oggz_write_feed (oggz, &op, serialno, OGGZ_FLUSH_AFTER, NULL); 00085 00086 granulepos += 100; 00087 packetno++; 00088 00089 /* Write bytes from packetized bitstream to the output file */ 00090 00091 while ((n = oggz_write (oggz, 32)) > 0); 00092 } 00093 00094 oggz_close (oggz); 00095 00096 exit (0); 00097 }


Generated on Fri Aug 13 11:47:52 2004 for liboggz by doxygen 1.3.7