DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
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, off_t size)
 
template<typename T >
bool ReadBits (int num_bits, T *out)
 
bool SkipBits (int num_bits)
 
bool SkipBitsConditional (bool condition, int num_bits)
 
bool SkipBytes (int num_bytes)
 
int bits_available () const
 
int bit_position () const
 

Detailed Description

A class to read bit streams.

Definition at line 17 of file bit_reader.h.

Constructor & Destructor Documentation

shaka::media::BitReader::BitReader ( const uint8_t *  data,
off_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

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

Definition at line 81 of file bit_reader.h.

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

Definition at line 76 of file bit_reader.h.

template<typename T >
bool shaka::media::BitReader::ReadBits ( int  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.

bool shaka::media::BitReader::SkipBits ( int  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.

bool shaka::media::BitReader::SkipBitsConditional ( bool  condition,
int  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 60 of file bit_reader.h.

bool shaka::media::BitReader::SkipBytes ( int  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 56 of file bit_reader.cc.


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