Project Alice
Loading...
Searching...
No Matches
bitstream.h File Reference
#include "mem.h"
#include "compiler.h"
#include "debug.h"
#include "error_private.h"
#include "bits.h"
Include dependency graph for bitstream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BIT_CStream_t
 
struct  BIT_DStream_t
 

Macros

#define STREAM_ACCUMULATOR_MIN_32   25
 
#define STREAM_ACCUMULATOR_MIN_64   57
 
#define STREAM_ACCUMULATOR_MIN   ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64))
 
#define BIT_MASK_SIZE   (sizeof(BIT_mask) / sizeof(BIT_mask[0]))
 

Typedefs

typedef size_t BitContainerType
 

Enumerations

enum  BIT_DStream_status { BIT_DStream_unfinished = 0 , BIT_DStream_endOfBuffer = 1 , BIT_DStream_completed = 2 , BIT_DStream_overflow = 3 }
 

Functions

MEM_STATIC size_t BIT_initCStream (BIT_CStream_t *bitC, void *dstBuffer, size_t dstCapacity)
 
MEM_STATIC void BIT_addBits (BIT_CStream_t *bitC, size_t value, unsigned nbBits)
 
MEM_STATIC void BIT_flushBits (BIT_CStream_t *bitC)
 
MEM_STATIC size_t BIT_closeCStream (BIT_CStream_t *bitC)
 
MEM_STATIC size_t BIT_initDStream (BIT_DStream_t *bitD, const void *srcBuffer, size_t srcSize)
 
MEM_STATIC size_t BIT_readBits (BIT_DStream_t *bitD, unsigned nbBits)
 
MEM_STATIC BIT_DStream_status BIT_reloadDStream (BIT_DStream_t *bitD)
 
MEM_STATIC unsigned BIT_endOfDStream (const BIT_DStream_t *bitD)
 
MEM_STATIC void BIT_addBitsFast (BIT_CStream_t *bitC, size_t value, unsigned nbBits)
 
MEM_STATIC void BIT_flushBitsFast (BIT_CStream_t *bitC)
 
MEM_STATIC size_t BIT_readBitsFast (BIT_DStream_t *bitD, unsigned nbBits)
 
FORCE_INLINE_TEMPLATE size_t BIT_getLowerBits (size_t bitContainer, U32 const nbBits)
 
FORCE_INLINE_TEMPLATE size_t BIT_getUpperBits (BitContainerType bitContainer, U32 const start)
 
FORCE_INLINE_TEMPLATE size_t BIT_getMiddleBits (BitContainerType bitContainer, U32 const start, U32 const nbBits)
 
FORCE_INLINE_TEMPLATE size_t BIT_lookBits (const BIT_DStream_t *bitD, U32 nbBits)
 
MEM_STATIC size_t BIT_lookBitsFast (const BIT_DStream_t *bitD, U32 nbBits)
 
FORCE_INLINE_TEMPLATE void BIT_skipBits (BIT_DStream_t *bitD, U32 nbBits)
 
MEM_STATIC BIT_DStream_status BIT_reloadDStream_internal (BIT_DStream_t *bitD)
 
MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast (BIT_DStream_t *bitD)
 

Macro Definition Documentation

◆ BIT_MASK_SIZE

#define BIT_MASK_SIZE   (sizeof(BIT_mask) / sizeof(BIT_mask[0]))

Definition at line 145 of file bitstream.h.

◆ STREAM_ACCUMULATOR_MIN

#define STREAM_ACCUMULATOR_MIN   ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64))

Definition at line 49 of file bitstream.h.

◆ STREAM_ACCUMULATOR_MIN_32

#define STREAM_ACCUMULATOR_MIN_32   25

Definition at line 47 of file bitstream.h.

◆ STREAM_ACCUMULATOR_MIN_64

#define STREAM_ACCUMULATOR_MIN_64   57

Definition at line 48 of file bitstream.h.

Typedef Documentation

◆ BitContainerType

typedef size_t BitContainerType

Definition at line 93 of file bitstream.h.

Enumeration Type Documentation

◆ BIT_DStream_status

Enumerator
BIT_DStream_unfinished 
BIT_DStream_endOfBuffer 
BIT_DStream_completed 
BIT_DStream_overflow 

Definition at line 102 of file bitstream.h.

Function Documentation

◆ BIT_addBits()

MEM_STATIC void BIT_addBits ( BIT_CStream_t bitC,
size_t  value,
unsigned  nbBits 
)

BIT_addBits() : can add up to 31 bits into bitC. Note : does not check for register overflow !

Definition at line 179 of file bitstream.h.

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

◆ BIT_addBitsFast()

MEM_STATIC void BIT_addBitsFast ( BIT_CStream_t bitC,
size_t  value,
unsigned  nbBits 
)

BIT_addBitsFast() : works only if value is clean, meaning all high bits above nbBits are 0

Definition at line 192 of file bitstream.h.

Here is the caller graph for this function:

◆ BIT_closeCStream()

MEM_STATIC size_t BIT_closeCStream ( BIT_CStream_t bitC)

BIT_closeCStream() :

Returns
: size of CStream, in bytes, or 0 if it could not fit into dstBuffer

Definition at line 235 of file bitstream.h.

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

◆ BIT_endOfDStream()

MEM_STATIC unsigned BIT_endOfDStream ( const BIT_DStream_t DStream)

BIT_endOfDStream() :

Returns
: 1 if DStream has exactly reached its end (all bits consumed).

Definition at line 448 of file bitstream.h.

Here is the caller graph for this function:

◆ BIT_flushBits()

MEM_STATIC void BIT_flushBits ( BIT_CStream_t bitC)

BIT_flushBits() : assumption : bitContainer has not overflowed safe version; check for buffer overflow, and prevents it. note : does not signal buffer overflow. overflow will be revealed later on using BIT_closeCStream()

Definition at line 220 of file bitstream.h.

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

◆ BIT_flushBitsFast()

MEM_STATIC void BIT_flushBitsFast ( BIT_CStream_t bitC)

BIT_flushBitsFast() : assumption : bitContainer has not overflowed unsafe version; does not check buffer overflow

Definition at line 204 of file bitstream.h.

Here is the call graph for this function:

◆ BIT_getLowerBits()

FORCE_INLINE_TEMPLATE size_t BIT_getLowerBits ( size_t  bitContainer,
U32 const  nbBits 
)

Definition at line 166 of file bitstream.h.

Here is the caller graph for this function:

◆ BIT_getMiddleBits()

FORCE_INLINE_TEMPLATE size_t BIT_getMiddleBits ( BitContainerType  bitContainer,
U32 const  start,
U32 const  nbBits 
)

Definition at line 306 of file bitstream.h.

Here is the caller graph for this function:

◆ BIT_getUpperBits()

FORCE_INLINE_TEMPLATE size_t BIT_getUpperBits ( BitContainerType  bitContainer,
U32 const  start 
)

Definition at line 301 of file bitstream.h.

◆ BIT_initCStream()

MEM_STATIC size_t BIT_initCStream ( BIT_CStream_t bitC,
void *  startPtr,
size_t  dstCapacity 
)

BIT_initCStream() : dstCapacity must be > sizeof(size_t)

Returns
: 0 if success, otherwise an error code (can be tested using ERR_isError())

Definition at line 154 of file bitstream.h.

Here is the caller graph for this function:

◆ BIT_initDStream()

MEM_STATIC size_t BIT_initDStream ( BIT_DStream_t bitD,
const void *  srcBuffer,
size_t  srcSize 
)

BIT_initDStream() : Initialize a BIT_DStream_t. bitD : a pointer to an already allocated BIT_DStream_t structure. srcSize must be the exact size of the bitStream, in bytes.

Returns
: size of stream (== srcSize), or an errorCode if a problem is detected

Definition at line 253 of file bitstream.h.

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

◆ BIT_lookBits()

FORCE_INLINE_TEMPLATE size_t BIT_lookBits ( const BIT_DStream_t bitD,
U32  nbBits 
)

BIT_lookBits() : Provides next n bits from local register. local register is not modified. On 32-bits, maxNbBits==24. On 64-bits, maxNbBits==56.

Returns
: value extracted

Definition at line 329 of file bitstream.h.

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

◆ BIT_lookBitsFast()

MEM_STATIC size_t BIT_lookBitsFast ( const BIT_DStream_t bitD,
U32  nbBits 
)

BIT_lookBitsFast() : unsafe version; only works if nbBits >= 1

Definition at line 345 of file bitstream.h.

Here is the caller graph for this function:

◆ BIT_readBits()

FORCE_INLINE_TEMPLATE size_t BIT_readBits ( BIT_DStream_t bitD,
unsigned  nbBits 
)

BIT_readBits() : Read (consume) next n bits from local register and update. Pay attention to not read more than nbBits contained into local register.

Returns
: extracted value.

Definition at line 361 of file bitstream.h.

Here is the call graph for this function:

◆ BIT_readBitsFast()

MEM_STATIC size_t BIT_readBitsFast ( BIT_DStream_t bitD,
unsigned  nbBits 
)

BIT_readBitsFast() : unsafe version; only works if nbBits >= 1

Definition at line 370 of file bitstream.h.

Here is the call graph for this function:

◆ BIT_reloadDStream()

BIT_reloadDStream() : Refill bitD from buffer previously set in BIT_initDStream() . This function is safe, it guarantees it will not never beyond src buffer.

Returns
: status of BIT_DStream_t internal register. when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits

Definition at line 411 of file bitstream.h.

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

◆ BIT_reloadDStream_internal()

MEM_STATIC BIT_DStream_status BIT_reloadDStream_internal ( BIT_DStream_t bitD)

BIT_reloadDStream_internal() : Simple variant of BIT_reloadDStream(), with two conditions:

  1. bitstream is valid : bitsConsumed <= sizeof(bitD->bitContainer)*8
  2. look window is valid after shifted down : bitD->ptr >= bitD->start

Definition at line 383 of file bitstream.h.

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

◆ BIT_reloadDStreamFast()

MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast ( BIT_DStream_t bitD)

BIT_reloadDStreamFast() : Similar to BIT_reloadDStream(), but with two differences:

  1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold!
  2. Returns BIT_DStream_overflow when bitD->ptr < bitD->limitPtr, at this point you must use BIT_reloadDStream() to reload.

Definition at line 399 of file bitstream.h.

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

◆ BIT_skipBits()

FORCE_INLINE_TEMPLATE void BIT_skipBits ( BIT_DStream_t bitD,
U32  nbBits 
)

Definition at line 352 of file bitstream.h.

Here is the caller graph for this function: