\section{Writing by force feeding Oggz}
\label{group__force__feed}\index{Writing by force feeding Oggz@{Writing by force feeding Oggz}}
Force feeding involves synchronously:\begin{itemize}
\item Creating an {\em ogg\_\-packet\/} structure\item Adding it to the packet queue with \doxyref{oggz\_\-write\_\-feed()}{p.}{group__write__api_g6ccaceb107db1fd2eae047dbdbaa5889}\item Calling \doxyref{oggz\_\-write()}{p.}{group__write__api_g3c97d94ea425d64546adf9c368b71904} or \doxyref{oggz\_\-write\_\-output()}{p.}{group__write__api_g5606dff01964caec4582eb172fde0c1c}, repeatedly as necessary, to generate the Ogg bitstream. \end{itemize}
 


Force feeding involves synchronously:\begin{itemize}
\item Creating an {\em ogg\_\-packet\/} structure\item Adding it to the packet queue with \doxyref{oggz\_\-write\_\-feed()}{p.}{group__write__api_g6ccaceb107db1fd2eae047dbdbaa5889}\item Calling \doxyref{oggz\_\-write()}{p.}{group__write__api_g3c97d94ea425d64546adf9c368b71904} or \doxyref{oggz\_\-write\_\-output()}{p.}{group__write__api_g5606dff01964caec4582eb172fde0c1c}, repeatedly as necessary, to generate the Ogg bitstream. \end{itemize}


This process is illustrated in the following diagram:

 \begin{Image}
\begin{center}
\includegraphics[width=10cm]{forcefeed}\caption{Force Feeding Oggz}
\end{center}
\end{Image}


The following example code generates a stream of ten packets, each containing a single byte ('A', 'B', ... , 'J'):



\begin{DocInclude}\begin{verbatim}
#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);
}
\end{verbatim}
\end{DocInclude}
 