Encoder  4.4
VC-5 Sample Encoder
bitstream.c File Reference

Functions

BITWORD BitMask (int n)
 Return a mask with the specified number of bits set to one.
 
CODEC_ERROR InitBitstream (BITSTREAM *bitstream)
 Initialize a bitstream data structure. More...
 
CODEC_ERROR AttachBitstream (struct _bitstream *bitstream, struct _stream *stream)
 Attach a bitstream to a byte stream. More...
 
CODEC_ERROR ReleaseBitstream (BITSTREAM *bitstream)
 Detach a bitstream from a byte stream. More...
 
CODEC_ERROR PutBits (BITSTREAM *stream, BITWORD bits, BITCOUNT count)
 Write the specified number of bits to the bitstream.
 
CODEC_ERROR PutBuffer (BITSTREAM *bitstream)
 Write the internal bitstream buffer to a byte stream. More...
 
CODEC_ERROR PutLong (BITSTREAM *stream, BITWORD longword)
 Write a longword (32 bits) to the stream.
 
CODEC_ERROR RewindBitstream (BITSTREAM *bitstream)
 Reset the bitstream. More...
 
CODEC_ERROR BitstreamCodecError (BITSTREAM *bitstream)
 Convert a bitstream error code into a codec error code. More...
 
size_t GetBitstreamPosition (BITSTREAM *bitstream)
 Get the current position in the byte stream. More...
 
CODEC_ERROR AlignBitsByte (BITSTREAM *bitstream)
 Align the bitstream to a byte boundary. More...
 
CODEC_ERROR AlignBitsWord (BITSTREAM *bitstream)
 Align the bitstream to the next word boundary. More...
 
CODEC_ERROR FlushBitstream (BITSTREAM *bitstream)
 Write any bits in the buffer to the byte stream.
 
uint32_t PopSampleOffsetStack (BITSTREAM *bitstream)
 Pop the top value from the sample offset stack.
 
CODEC_ERROR PutByteArray (BITSTREAM *bitstream, const uint8_t *array, size_t size)
 Write a block of bytes into the bitstream.
 

Detailed Description

Implementation of a bitstream for reading bits from a stream.

The bitstream is connected to a stream to read bytes from an input source. The stream may be a binary file, memory buffer, or a track in a media container. The bitstream data structure stores the last word read from the byte stream and the count of the number of bits that remains in the buffer.

(c) 2013-2017 Society of Motion Picture & Television Engineers LLC and Woodman Labs, Inc. All rights reserved–use subject to compliance with end user license agreement.

Function Documentation

◆ AlignBitsByte()

CODEC_ERROR AlignBitsByte ( BITSTREAM bitstream)

Align the bitstream to a byte boundary.

Enough bits are written to the bitstream to align the bitstream to the next byte.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AlignBitsWord()

CODEC_ERROR AlignBitsWord ( BITSTREAM bitstream)

Align the bitstream to the next word boundary.

Enough bits are written to the bitstream to align the bitstream to the next word.

◆ AttachBitstream()

CODEC_ERROR AttachBitstream ( struct _bitstream bitstream,
struct _stream stream 
)

Attach a bitstream to a byte stream.

It is permitted for the byte stream to be NULL, in which case the bitstream will not be able to replenish its internal buffer, but the consequences are undefined.

Here is the caller graph for this function:

◆ BitstreamCodecError()

CODEC_ERROR BitstreamCodecError ( BITSTREAM bitstream)

Convert a bitstream error code into a codec error code.

The bitstream and byte stream modules might be used in other applications and have their own errors codes. This routine embeds a bitstream error code into a codec error code. The bitstream error code is carried in the low bits of the codec error code.

Todo:
Eliminate separate error codes for bitstreams?
Here is the call graph for this function:

◆ GetBitstreamPosition()

size_t GetBitstreamPosition ( BITSTREAM bitstream)

Get the current position in the byte stream.

The current position in the byte stream associated with the bitstream is returned. The intent is to allow the bitstream (and the associated byte stream) to be restored to the saved position.

Todo:
Need to record the state of the bitstream buffer and bit count so that the entire bitstream state can be restored.
Here is the caller graph for this function:

◆ InitBitstream()

CODEC_ERROR InitBitstream ( BITSTREAM bitstream)

Initialize a bitstream data structure.

This routine is the constructor for the bitstream data type.

The sample offset stack is used to mark the offset to a position in the bitstream for computing the size field of sample chunks.

Here is the caller graph for this function:

◆ PutBuffer()

CODEC_ERROR PutBuffer ( BITSTREAM bitstream)

Write the internal bitstream buffer to a byte stream.

Todo:
Need to modify this routine to return an error code if it cannot write to the byte stream associated with the bitstream.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReleaseBitstream()

CODEC_ERROR ReleaseBitstream ( BITSTREAM bitstream)

Detach a bitstream from a byte stream.

Any resources allocated by the bitstream are released without deallocating the bitstream data structure itself. The byte stream associated with the bitstream is not closed by this routine. The byte stream must be closed, if and when appropriate, by the caller.

◆ RewindBitstream()

CODEC_ERROR RewindBitstream ( BITSTREAM bitstream)

Reset the bitstream.

This routine resets the bitstream to the beginning of the byte stream that has been attached to the bitstream. The byte stream is also reset.

If the byte stream could not be reset, then the internal bitstream state is not reset.

Here is the call graph for this function: