 |
libxcoder
5.2.0
|
Go to the documentation of this file.
48 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020,
49 0x00000040, 0x00000080, 0x00000100, 0x00000200, 0x00000400, 0x00000800,
50 0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000,
51 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000,
52 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000,
53 0x40000000, 0x80000000};
94 stream->
first = new_chunk;
97 stream->
last = new_chunk;
119 while (chunk != NULL)
127 static inline unsigned ni_math_floor_log2(
unsigned value)
133 for (i = 4; i >= 0; --i)
135 unsigned bits = 1ull << i;
136 unsigned shift = (value >= (1ull << bits)) ? bits : 0;
144 static inline unsigned ni_math_ceil_log2(
unsigned value)
149 return ni_math_floor_log2(value) + ((value & (value - 1)) ? 1 : 0);
171 uint64_t position = stream->
len;
172 return position * 8 + stream->
cur_bit;
207 ni_bs_writer_write_byte(stream, stream->
data);
221 unsigned data_log2 = ni_math_floor_log2(data + 1);
222 unsigned prefix = 1 << data_log2;
223 unsigned suffix = data + 1 - prefix;
224 unsigned num_bits = data_log2 * 2 + 1;
225 unsigned value = prefix | suffix;
227 if (data > 0xFFFFFFFE)
256 uint32_t data_num = data <= 0 ? (-data) << 1 : (data << 1) - 1;
268 if ((stream->
cur_bit & 7) != 0)
285 uint8_t *p_dst = dst;
286 while (chunk && chunk->
len)
288 memcpy(p_dst, chunk->
data, chunk->
len);
302 ni_bs_writer_free_chunks(stream->
first);
367 "%s: skip %d, current byte_offset "
368 "%d bit_offset %d, over total size %d, stop !\n",
424 const uint8_t *src = NULL;
429 for (i = 0; i < 2; i++)
432 ret |= ((uint16_t)src[i] << offset);
437 ret |= (src[2] >> (8 - offset));
491 }
else if (n > 8 && n < 16)
499 }
else if (n > 16 && n < 24)
536 ret += (1U << i) - 1;
Utility definitions to operate on bits in a bitstream.
const uint32_t ni_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_bs_writer_clear(ni_bitstream_writer_t *stream)
clear and reset bitstream
uint8_t data[NI_DATA_CHUNK_SIZE]
void ni_bitstream_writer_init(ni_bitstream_writer_t *stream)
init a bitstream writer
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_copy(uint8_t *dst, const ni_bitstream_writer_t *stream)
copy bitstream data to dst Note: caller must ensure sufficient space in dst
uint32_t ni_bs_reader_get_ue(ni_bitstream_reader_t *br)
read an unsigned Exp-Golomb code ue(v)
uint8_t ni_bitstream_get_u8(ni_bitstream_reader_t *br)
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...
uint16_t ni_bitstream_get_u16(ni_bitstream_reader_t *br)
#define NI_DATA_CHUNK_SIZE
int ni_bs_reader_bits_count(ni_bitstream_reader_t *br)
return the number of bits already parsed in stream
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
uint8_t ni_bitstream_get_1bit(ni_bitstream_reader_t *br)
uint64_t ni_bs_writer_tell(const ni_bitstream_writer_t *const stream)
return the number of bits written to bitstream so far
struct ni_data_chunk_t * next
void ni_bs_writer_put_se(ni_bitstream_writer_t *stream, int32_t data)
write signed Exp-Golomb bit string to bitstream
void ni_bs_writer_align_zero(ni_bitstream_writer_t *stream)
align the bitstream with zero
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
int32_t ni_bs_reader_get_se(ni_bitstream_reader_t *br)
read a signed Exp-Golomb code se(v)
uint8_t ni_bitstream_get_8bits_or_less(ni_bitstream_reader_t *br, int n)
void ni_bs_reader_skip_bits(ni_bitstream_reader_t *br, int n)
skip a number of bits ahead in the bitstream reader
int ni_bs_reader_get_bits_left(ni_bitstream_reader_t *br)
return the number of bits left to parse in stream