libxcoder  5.2.0
ni_bitstream.c File Reference

Utility definitions to operate on bits in a bitstream. More...

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "ni_util.h"
#include "ni_bitstream.h"

Go to the source code of this file.

Functions

void ni_bitstream_writer_init (ni_bitstream_writer_t *stream)
 init a bitstream writer More...
 
uint64_t ni_bs_writer_tell (const ni_bitstream_writer_t *const stream)
 return the number of bits written to bitstream so far More...
 
void ni_bs_writer_put (ni_bitstream_writer_t *stream, uint32_t data, uint8_t bits)
 write a specified number (<= 32) of bits to bitstream, buffer individual bits until a full byte is made More...
 
void ni_bs_writer_put_ue (ni_bitstream_writer_t *stream, uint32_t data)
 write unsigned Exp-Golomb bit string to bitstream, 2^32-2 at most. More...
 
void ni_bs_writer_put_se (ni_bitstream_writer_t *stream, int32_t data)
 write signed Exp-Golomb bit string to bitstream More...
 
void ni_bs_writer_align_zero (ni_bitstream_writer_t *stream)
 align the bitstream with zero More...
 
void ni_bs_writer_copy (uint8_t *dst, const ni_bitstream_writer_t *stream)
 copy bitstream data to dst Note: caller must ensure sufficient space in dst More...
 
void ni_bs_writer_clear (ni_bitstream_writer_t *stream)
 clear and reset bitstream More...
 
void ni_bitstream_reader_init (ni_bitstream_reader_t *br, const uint8_t *data, int bit_size)
 init a bitstream reader Note: bitstream_reader takes reading ownership of the data More...
 
int ni_bs_reader_bits_count (ni_bitstream_reader_t *br)
 return the number of bits already parsed in stream More...
 
int ni_bs_reader_get_bits_left (ni_bitstream_reader_t *br)
 return the number of bits left to parse in stream More...
 
void ni_bs_reader_skip_bits (ni_bitstream_reader_t *br, int n)
 skip a number of bits ahead in the bitstream reader More...
 
uint8_t ni_bitstream_get_1bit (ni_bitstream_reader_t *br)
 
uint8_t ni_bitstream_get_u8 (ni_bitstream_reader_t *br)
 
uint16_t ni_bitstream_get_u16 (ni_bitstream_reader_t *br)
 
uint8_t ni_bitstream_get_8bits_or_less (ni_bitstream_reader_t *br, int n)
 
uint32_t ni_bs_reader_get_bits (ni_bitstream_reader_t *br, int n)
 read bits (up to 32) from the bitstream reader, after reader init More...
 
uint32_t ni_bs_reader_get_ue (ni_bitstream_reader_t *br)
 read an unsigned Exp-Golomb code ue(v) More...
 
int32_t ni_bs_reader_get_se (ni_bitstream_reader_t *br)
 read a signed Exp-Golomb code se(v) More...
 

Variables

const uint32_t ni_bit_set_mask []
 

Detailed Description

Utility definitions to operate on bits in a bitstream.


Definition in file ni_bitstream.c.

Function Documentation

◆ ni_bitstream_get_1bit()

uint8_t ni_bitstream_get_1bit ( ni_bitstream_reader_t br)

Definition at line 378 of file ni_bitstream.c.

◆ ni_bitstream_get_8bits_or_less()

uint8_t ni_bitstream_get_8bits_or_less ( ni_bitstream_reader_t br,
int  n 
)

Definition at line 446 of file ni_bitstream.c.

◆ ni_bitstream_get_u16()

uint16_t ni_bitstream_get_u16 ( ni_bitstream_reader_t br)

Definition at line 419 of file ni_bitstream.c.

◆ ni_bitstream_get_u8()

uint8_t ni_bitstream_get_u8 ( ni_bitstream_reader_t br)

Definition at line 403 of file ni_bitstream.c.

◆ ni_bitstream_reader_init()

void ni_bitstream_reader_init ( ni_bitstream_reader_t br,
const uint8_t *  data,
int  bit_size 
)

init a bitstream reader Note: bitstream_reader takes reading ownership of the data


Parameters
brbitstream reader
datadata to be parsed
bit_sizenumber of bits in the data
Returns
none

Definition at line 317 of file ni_bitstream.c.

◆ ni_bitstream_writer_init()

void ni_bitstream_writer_init ( ni_bitstream_writer_t stream)

init a bitstream writer


Parameters
streambitstream
Returns
none

Definition at line 158 of file ni_bitstream.c.

◆ ni_bs_reader_bits_count()

int ni_bs_reader_bits_count ( ni_bitstream_reader_t br)

return the number of bits already parsed in stream


Parameters
brbitstream reader
Returns
number of bits parsed

Definition at line 338 of file ni_bitstream.c.

◆ ni_bs_reader_get_bits()

uint32_t ni_bs_reader_get_bits ( ni_bitstream_reader_t br,
int  n 
)

read bits (up to 32) from the bitstream reader, after reader init


Parameters
brbitstream reader
nnumber of bits to read
Returns
value read

Definition at line 471 of file ni_bitstream.c.

◆ ni_bs_reader_get_bits_left()

int ni_bs_reader_get_bits_left ( ni_bitstream_reader_t br)

return the number of bits left to parse in stream


Parameters
brbitstream reader
Returns
number of bits left

Definition at line 349 of file ni_bitstream.c.

◆ ni_bs_reader_get_se()

int32_t ni_bs_reader_get_se ( ni_bitstream_reader_t br)

read a signed Exp-Golomb code se(v)


Parameters
brbitstream reader
Returns
value read

Definition at line 546 of file ni_bitstream.c.

◆ ni_bs_reader_get_ue()

uint32_t ni_bs_reader_get_ue ( ni_bitstream_reader_t br)

read an unsigned Exp-Golomb code ue(v)


Parameters
brbitstream reader
Returns
value read

Definition at line 522 of file ni_bitstream.c.

◆ ni_bs_reader_skip_bits()

void ni_bs_reader_skip_bits ( ni_bitstream_reader_t br,
int  n 
)

skip a number of bits ahead in the bitstream reader


Parameters
brbitstream reader
nnumber of bits to skip
Returns
none

Definition at line 361 of file ni_bitstream.c.

◆ ni_bs_writer_align_zero()

void ni_bs_writer_align_zero ( ni_bitstream_writer_t stream)

align the bitstream with zero


Parameters
streambitstream
Returns
none

Definition at line 266 of file ni_bitstream.c.

◆ ni_bs_writer_clear()

void ni_bs_writer_clear ( ni_bitstream_writer_t stream)

clear and reset bitstream


Parameters
streambitstream
Returns
none

Definition at line 300 of file ni_bitstream.c.

◆ ni_bs_writer_copy()

void ni_bs_writer_copy ( uint8_t *  dst,
const ni_bitstream_writer_t stream 
)

copy bitstream data to dst Note: caller must ensure sufficient space in dst


Parameters
dstcopy destination
streambitstream
Returns
none

Definition at line 282 of file ni_bitstream.c.

◆ ni_bs_writer_put()

void ni_bs_writer_put ( ni_bitstream_writer_t stream,
uint32_t  data,
uint8_t  bits 
)

write a specified number (<= 32) of bits to bitstream, buffer individual bits until a full byte is made


Parameters
streambitstream
datainput data
bitsnumber of bits in data to write to stream, max 32
Returns
none

Definition at line 183 of file ni_bitstream.c.

◆ ni_bs_writer_put_se()

void ni_bs_writer_put_se ( ni_bitstream_writer_t stream,
int32_t  data 
)

write signed Exp-Golomb bit string to bitstream


Parameters
streambitstream
datainput data
Returns
none

Definition at line 253 of file ni_bitstream.c.

◆ ni_bs_writer_put_ue()

void ni_bs_writer_put_ue ( ni_bitstream_writer_t stream,
uint32_t  data 
)

write unsigned Exp-Golomb bit string to bitstream, 2^32-2 at most.


Parameters
streambitstream
datainput data
Returns
none

Definition at line 219 of file ni_bitstream.c.

◆ ni_bs_writer_tell()

uint64_t ni_bs_writer_tell ( const ni_bitstream_writer_t *const  stream)

return the number of bits written to bitstream so far


Parameters
streambitstream
Returns
position

Definition at line 169 of file ni_bitstream.c.

Variable Documentation

◆ ni_bit_set_mask

const uint32_t ni_bit_set_mask[]
Initial value:
= {
0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020,
0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800,
0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000,
0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000,
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000,
0x40000000, 0x80000000}

Definition at line 47 of file ni_bitstream.c.