49 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020,
50 0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800,
51 0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000,
52 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000,
53 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000,
54 0x40000000, 0x80000000};
95 stream->
first = new_chunk;
98 stream->
last = new_chunk;
120 while (chunk != NULL)
128 static inline unsigned ni_logan_math_floor_log2(
unsigned value)
134 for (i = 4; i >= 0; --i)
136 unsigned bits = 1ull << i;
137 unsigned shift = (value >= (1ull << bits)) ? bits : 0;
145 static inline unsigned ni_logan_math_ceil_log2(
unsigned value)
150 return ni_logan_math_floor_log2(value) + ((value & (value - 1)) ? 1 : 0);
172 uint64_t position = stream->
len;
173 return position * 8 + stream->
cur_bit;
208 ni_bs_writer_write_byte(stream, stream->
data);
223 unsigned data_log2 = ni_logan_math_floor_log2(data + 1);
224 unsigned prefix = 1 << data_log2;
225 unsigned suffix = data + 1 - prefix;
226 unsigned num_bits = data_log2 * 2 + 1;
227 unsigned value = prefix | suffix;
228 if (data > 0xFFFFFFFE)
257 uint32_t data_num = data <= 0 ? (-data) << 1 : (data << 1) - 1;
269 if ((stream->
cur_bit & 7) != 0)
286 uint8_t *p_dst = dst;
287 while (chunk && chunk->
len)
289 memcpy(p_dst, chunk->
data, chunk->
len);
303 ni_bs_writer_free_chunks(stream->
first);
368 "%s: skip %d, current byte_offset "
369 "%d bit_offset %d, over total size %d, stop !\n",
425 const uint8_t *src = NULL;
430 for (i = 0; i < 2; i++)
433 ret |= ((uint16_t)src[i] << offset);
438 ret |= (src[2] >> (8 - offset));
492 }
else if (n > 8 && n < 16)
500 }
else if (n > 16 && n < 24)
537 ret += (1U << i) - 1;
void ni_logan_bitstream_put_se(ni_bitstream_writer_t *stream, int32_t data)
write signed Exp-Golomb bit string to bitstream
int ni_bs_reader_bits_count(ni_bitstream_reader_t *br)
return the number of bits already parsed in stream
const uint32_t ni_logan_bit_set_mask[]
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.
void ni_bitstream_writer_init(ni_bitstream_writer_t *stream)
init a bitstream writer
uint16_t ni_logan_bitstream_get_u16(ni_bitstream_reader_t *br)
uint32_t ni_bs_reader_get_ue(ni_bitstream_reader_t *br)
read an unsigned Exp-Golomb code ue(v)
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
uint8_t ni_logan_bitstream_get_8bits_or_less(ni_bitstream_reader_t *br, int n)
int32_t ni_bs_reader_get_se(ni_bitstream_reader_t *br)
read a signed Exp-Golomb code se(v)
void ni_bs_writer_align_zero(ni_bitstream_writer_t *stream)
align the bitstream with zero
uint8_t ni_logan_bitstream_get_u8(ni_bitstream_reader_t *br)
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
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
void ni_bs_writer_clear(ni_bitstream_writer_t *stream)
clear and reset bitstream
uint64_t ni_bs_writer_tell(const ni_bitstream_writer_t *const stream)
return the number of bits written to bitstream so far
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 ma...
int ni_bs_reader_get_bits_left(ni_bitstream_reader_t *br)
return the number of bits left to parse in stream
void ni_bs_reader_skip_bits(ni_bitstream_reader_t *br, int n)
skip a number of bits ahead in the bitstream reader
uint8_t ni_logan_bitstream_get_1bit(ni_bitstream_reader_t *br)
Utility functions to operate on bits in a bitstream.
#define NI_DATA_CHUNK_SIZE
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
Exported utility routines definition.
struct ni_data_chunk_t * next
uint8_t data[NI_DATA_CHUNK_SIZE]