int QccFifoInitialize(QccFifo *fifo);
int QccFifoStart(QccFifo *fifo);
int QccFifoEnd(QccFifo *fifo);
int QccFifoFlush(QccFifo *fifo);
int
QccFifoRestart(QccFifo *fifo);
typedef struct
{
QccBitBuffer output_buffer;
QccBitBuffer input_buffer;
} QccFifo;
The fields of QccFifo are as follows:
QccFifoStart() starts both input_buffer and output_buffer via calls to QccBitBufferStart(3) .
QccFifoEnd() should be called after all accesses (read or write) to fifo are complete. QccFifoEnd() calls QccBitBufferEnd(3) to stop both buffers.
QccFifoFlush() should be called at the end of writing a bitstream after all bits have been written but before QccFifoEnd() is called. QccFifoFlush() ensures that the last byte being packed with bits, which may not be full, is output to the fifo by calling QccBitBufferFlush(3) on both buffers.
Once QccFifoStart(3) has been called, any of the usual bit-buffer routines for reading (e.g., QccBitBufferReadChar(3) , QccBitBufferReadInt(3) ) or writing (e.g., QccBitBufferWriteChar(3) , QccBitBufferWriteInt(3) ) can be called on the input_buffer and output_buffer fields of the fifo. The bits are read out of input_buffer in the same order they were written into output_buffer, so one or more calls to write to output_buffer should precede the first call to read from input_buffer.
QccFifoRestart() restarts fifo by calling QccFifoEnd() and QccFifoStart() in succession. Any data currently held in fifo is lost; that is, the fifo is emptied.
As a consequence of the use of pipe(2) to implement the fifo, there is a limit to amount of bits that may be held in the fifo at any given time. Unfortunately, this limit is system-dependent. On POSIX-compliant systems, the pipe is required to be capable of holding at least PIPE_BUF bytes, and PIPE_BUF must be at least 512 bytes. This means that, on a POSIX-compliant system, at least 4096 bits can be written to a QccFifo structure before bits must be read out.
Attempts to write to a full fifo (one already containing the system-dependent maximum number of bits) will return in error, as will attempts to read from an empty fifo. It is the responsibility of the calling application to avoid fifo overflow and underflow, and the calling application should do so without trying to determine the maximum size of the fifo, as there does not seem to be a reliable system-independent way of doing so.