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

Go to the source code of this file.

Data Structures

struct  _bitstream
 Declaration of the bitstream data structure. More...
 

Typedefs

typedef enum _bitstream_error BITSTREAM_ERROR
 Bitstream error codes. More...
 
typedef uint32_t BITWORD
 Data type of the internal bitstream buffer.
 
typedef uint_fast8_t BITCOUNT
 Number of bits in the bitsteam buffer.
 
typedef struct _bitstream BITSTREAM
 Declaration of the bitstream data structure. More...
 

Enumerations

enum  _bitstream_error { BITSTREAM_ERROR_OKAY = 0, BITSTREAM_ERROR_UNDERFLOW, BITSTREAM_ERROR_OVERFLOW, BITSTREAM_ERROR_BADTAG }
 Bitstream error codes. More...
 

Functions

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 *stream)
 Detach a bitstream from a byte stream. More...
 
BITWORD GetBits (BITSTREAM *stream, BITCOUNT count)
 
BITWORD GetBuffer (BITSTREAM *stream)
 
CODEC_ERROR PutBits (BITSTREAM *stream, BITWORD bits, BITCOUNT count)
 Write the specified number of bits to the bitstream.
 
CODEC_ERROR PutBuffer (BITSTREAM *stream)
 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...
 
CODEC_ERROR SkipPayload (BITSTREAM *bitstream, int chunk_size)
 
size_t GetBitstreamPosition (BITSTREAM *stream)
 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...
 
BITWORD AddBits (BITSTREAM *stream, BITWORD bits, BITCOUNT count)
 
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 *block, size_t size)
 Write a block of bytes into the bitstream.
 

Detailed Description

Declaration of the bitstream data structure.

(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.

Typedef Documentation

◆ BITSTREAM

typedef struct _bitstream BITSTREAM

Declaration of the bitstream data structure.

The bitstream uses a byte stream to read bytes from a file or a buffer in memory. This isolates that bitstream module from the type of byte stream.

◆ BITSTREAM_ERROR

Bitstream error codes.

The bitstream contains its own enumeration of error codes since this module may be used in other applications.

Enumeration Type Documentation

◆ _bitstream_error

Bitstream error codes.

The bitstream contains its own enumeration of error codes since this module may be used in other applications.

Enumerator
BITSTREAM_ERROR_OKAY 

No error.

BITSTREAM_ERROR_UNDERFLOW 

No unread bits remaining in the bitstream.

BITSTREAM_ERROR_OVERFLOW 

No more bits can be written to the bitstream.

BITSTREAM_ERROR_BADTAG 

Unexpected tag found in the bitstream.

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: