liboggz 1.1.3
Writing by force feeding Oggz

Force feeding involves synchronously:

Force feeding involves synchronously:

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;
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;
/* Write bytes from packetized bitstream to the output file */
while ((n = oggz_write (oggz, 32)) > 0);
}
oggz_close (oggz);
exit (0);
}
long oggz_write(OGGZ *oggz, long n)
Write n bytes from an OGGZ handle.
int oggz_write_feed(OGGZ *oggz, ogg_packet *op, long serialno, int flush, int *guard)
Add a packet to oggz's packet queue.
The liboggz C API.
OGGZ * oggz_open_stdio(FILE *file, int flags)
Create an OGGZ handle associated with a stdio stream.
OGGZ * oggz_open(const char *filename, int flags)
Open an Ogg file, creating an OGGZ handle for it.
void OGGZ
An opaque handle to an Ogg file.
Definition: oggz.h:441
int oggz_close(OGGZ *oggz)
Close an OGGZ handle.
long oggz_serialno_new(OGGZ *oggz)
Request a new serialno, as required for a new stream, ensuring the serialno is not yet used for any o...
@ OGGZ_WRITE
Write only.
Definition: oggz_constants.h:51
@ OGGZ_FLUSH_AFTER
Flush after this packet.
Definition: oggz_constants.h:100