Shaka Packager SDK
Public Member Functions | List of all members
shaka::media::BitReader Class Reference

A class to read bit streams. More...

#include <bit_reader.h>

Public Member Functions

 BitReader (const uint8_t *data, size_t size)
 
template<typename T >
bool ReadBits (size_t num_bits, T *out)
 
bool ReadBits (size_t num_bits, bool *out)
 
bool SkipBits (size_t num_bits)
 
bool SkipBitsConditional (bool condition, size_t num_bits)
 
void SkipToNextByte ()
 
bool SkipBytes (size_t num_bytes)
 
size_t bits_available () const
 
size_t bit_position () const
 

Detailed Description

A class to read bit streams.

Definition at line 17 of file bit_reader.h.

Constructor & Destructor Documentation

◆ BitReader()

shaka::media::BitReader::BitReader ( const uint8_t *  data,
size_t  size 
)

Initialize the BitReader object to read a data buffer.

Parameters
datapoints to the beginning of the buffer.
sizeis the buffer size in bytes.

Definition at line 12 of file bit_reader.cc.

Member Function Documentation

◆ bit_position()

size_t shaka::media::BitReader::bit_position ( ) const
inline
Returns
The current bit position.

Definition at line 94 of file bit_reader.h.

◆ bits_available()

size_t shaka::media::BitReader::bits_available ( ) const
inline
Returns
The number of bits available for reading.

Definition at line 89 of file bit_reader.h.

◆ ReadBits()

template<typename T >
bool shaka::media::BitReader::ReadBits ( size_t  num_bits,
T *  out 
)
inline

Read a number of bits from stream.

Parameters
num_bitsspecifies the number of bits to read. It cannot be larger than the number of bits the type can hold.
[out]outstores the output. The type T has to be a primitive integer type.
Returns
false if the given number of bits cannot be read (not enough bits in the stream), true otherwise. When false is returned, the stream will enter a state where further ReadBits/SkipBits operations will always return false unless num_bits is 0.

Definition at line 35 of file bit_reader.h.

◆ SkipBits()

bool shaka::media::BitReader::SkipBits ( size_t  num_bits)

Skip a number of bits from stream.

Parameters
num_bitsspecifies the number of bits to be skipped.
Returns
false if the given number of bits cannot be skipped (not enough bits in the stream), true otherwise. When false is returned, the stream will enter a state where further ReadXXX/SkipXXX operations will always return false unless |num_bits/bytes| is 0.

Definition at line 24 of file bit_reader.cc.

◆ SkipBitsConditional()

bool shaka::media::BitReader::SkipBitsConditional ( bool  condition,
size_t  num_bits 
)
inline

Read one bit then skip the number of bits specified if that bit matches condition.

Parameters
conditionindicates when the number of bits should be skipped.
num_bitsspecifies the number of bits to be skipped.
Returns
false if the one bit cannot be read (not enough bits in the stream) or if the bit is set but the given number of bits cannot be skipped (not enough bits in the stream), true otherwise. When false is returned, the stream will enter a state where further ReadXXX/SkipXXX operations will always return false.

Definition at line 69 of file bit_reader.h.

◆ SkipBytes()

bool shaka::media::BitReader::SkipBytes ( size_t  num_bytes)

Skip a number of bytes from stream. The current posision should be byte aligned, otherwise a false is returned and bytes are not skipped.

Parameters
num_bytesspecifies the number of bytes to be skipped.
Returns
false if the current position is not byte aligned or if the given number of bytes cannot be skipped (not enough bytes in the stream), true otherwise.

Definition at line 63 of file bit_reader.cc.

◆ SkipToNextByte()

void shaka::media::BitReader::SkipToNextByte ( )

Skip a number of bits so the stream is byte aligned to the initial data. There could be 0 to 7 bits skipped.

Definition at line 54 of file bit_reader.cc.


The documentation for this class was generated from the following files: