Lines Matching refs:vlc
91 vl_vlc_next_input(struct vl_vlc *vlc) in vl_vlc_next_input() argument
93 unsigned len = vlc->sizes[0]; in vl_vlc_next_input()
95 assert(vlc); in vl_vlc_next_input()
96 assert(vlc->bytes_left); in vl_vlc_next_input()
98 if (len < vlc->bytes_left) in vl_vlc_next_input()
99 vlc->bytes_left -= len; in vl_vlc_next_input()
101 len = vlc->bytes_left; in vl_vlc_next_input()
102 vlc->bytes_left = 0; in vl_vlc_next_input()
105 vlc->data = vlc->inputs[0]; in vl_vlc_next_input()
106 vlc->end = vlc->data + len; in vl_vlc_next_input()
108 ++vlc->inputs; in vl_vlc_next_input()
109 ++vlc->sizes; in vl_vlc_next_input()
116 vl_vlc_align_data_ptr(struct vl_vlc *vlc) in vl_vlc_align_data_ptr() argument
119 while (vlc->data != vlc->end && pointer_to_uintptr(vlc->data) & 3) { in vl_vlc_align_data_ptr()
120 vlc->buffer |= (uint64_t)*vlc->data << (24 + vlc->invalid_bits); in vl_vlc_align_data_ptr()
121 ++vlc->data; in vl_vlc_align_data_ptr()
122 vlc->invalid_bits -= 8; in vl_vlc_align_data_ptr()
130 vl_vlc_fillbits(struct vl_vlc *vlc) in vl_vlc_fillbits() argument
132 assert(vlc); in vl_vlc_fillbits()
135 while (vlc->invalid_bits > 0) { in vl_vlc_fillbits()
136 unsigned bytes_left = vlc->end - vlc->data; in vl_vlc_fillbits()
141 if (vlc->bytes_left) { in vl_vlc_fillbits()
143 vl_vlc_next_input(vlc); in vl_vlc_fillbits()
144 vl_vlc_align_data_ptr(vlc); in vl_vlc_fillbits()
152 uint64_t value = *(const uint32_t*)vlc->data; in vl_vlc_fillbits()
158 vlc->buffer |= value << vlc->invalid_bits; in vl_vlc_fillbits()
159 vlc->data += 4; in vl_vlc_fillbits()
160 vlc->invalid_bits -= 32; in vl_vlc_fillbits()
165 } else while (vlc->data < vlc->end) { in vl_vlc_fillbits()
168 vlc->buffer |= (uint64_t)*vlc->data << (24 + vlc->invalid_bits); in vl_vlc_fillbits()
169 ++vlc->data; in vl_vlc_fillbits()
170 vlc->invalid_bits -= 8; in vl_vlc_fillbits()
179 vl_vlc_init(struct vl_vlc *vlc, unsigned num_inputs, in vl_vlc_init() argument
184 assert(vlc); in vl_vlc_init()
187 vlc->buffer = 0; in vl_vlc_init()
188 vlc->invalid_bits = 32; in vl_vlc_init()
189 vlc->inputs = inputs; in vl_vlc_init()
190 vlc->sizes = sizes; in vl_vlc_init()
191 vlc->bytes_left = 0; in vl_vlc_init()
194 vlc->bytes_left += sizes[i]; in vl_vlc_init()
196 if (vlc->bytes_left) { in vl_vlc_init()
197 vl_vlc_next_input(vlc); in vl_vlc_init()
198 vl_vlc_align_data_ptr(vlc); in vl_vlc_init()
199 vl_vlc_fillbits(vlc); in vl_vlc_init()
207 vl_vlc_valid_bits(struct vl_vlc *vlc) in vl_vlc_valid_bits() argument
209 return 32 - vlc->invalid_bits; in vl_vlc_valid_bits()
216 vl_vlc_bits_left(struct vl_vlc *vlc) in vl_vlc_bits_left() argument
218 signed bytes_left = vlc->end - vlc->data; in vl_vlc_bits_left()
219 bytes_left += vlc->bytes_left; in vl_vlc_bits_left()
220 return bytes_left * 8 + vl_vlc_valid_bits(vlc); in vl_vlc_bits_left()
227 vl_vlc_peekbits(struct vl_vlc *vlc, unsigned num_bits) in vl_vlc_peekbits() argument
229 assert(vl_vlc_valid_bits(vlc) >= num_bits || vlc->data >= vlc->end); in vl_vlc_peekbits()
230 return vlc->buffer >> (64 - num_bits); in vl_vlc_peekbits()
237 vl_vlc_eatbits(struct vl_vlc *vlc, unsigned num_bits) in vl_vlc_eatbits() argument
239 assert(vl_vlc_valid_bits(vlc) >= num_bits); in vl_vlc_eatbits()
241 vlc->buffer <<= num_bits; in vl_vlc_eatbits()
242 vlc->invalid_bits += num_bits; in vl_vlc_eatbits()
249 vl_vlc_get_uimsbf(struct vl_vlc *vlc, unsigned num_bits) in vl_vlc_get_uimsbf() argument
253 assert(vl_vlc_valid_bits(vlc) >= num_bits); in vl_vlc_get_uimsbf()
255 value = vlc->buffer >> (64 - num_bits); in vl_vlc_get_uimsbf()
256 vl_vlc_eatbits(vlc, num_bits); in vl_vlc_get_uimsbf()
265 vl_vlc_get_simsbf(struct vl_vlc *vlc, unsigned num_bits) in vl_vlc_get_simsbf() argument
269 assert(vl_vlc_valid_bits(vlc) >= num_bits); in vl_vlc_get_simsbf()
271 value = ((int64_t)vlc->buffer) >> (64 - num_bits); in vl_vlc_get_simsbf()
272 vl_vlc_eatbits(vlc, num_bits); in vl_vlc_get_simsbf()
281 vl_vlc_get_vlclbf(struct vl_vlc *vlc, const struct vl_vlc_entry *tbl, unsigned num_bits) in vl_vlc_get_vlclbf() argument
283 tbl += vl_vlc_peekbits(vlc, num_bits); in vl_vlc_get_vlclbf()
284 vl_vlc_eatbits(vlc, tbl->length); in vl_vlc_get_vlclbf()
292 vl_vlc_search_byte(struct vl_vlc *vlc, unsigned num_bits, uint8_t value) in vl_vlc_search_byte() argument
295 assert((vl_vlc_valid_bits(vlc) % 8) == 0); in vl_vlc_search_byte()
299 while (vl_vlc_valid_bits(vlc) > 0) { in vl_vlc_search_byte()
301 if (vl_vlc_peekbits(vlc, 8) == value) { in vl_vlc_search_byte()
302 vl_vlc_fillbits(vlc); in vl_vlc_search_byte()
306 vl_vlc_eatbits(vlc, 8); in vl_vlc_search_byte()
319 if (vlc->data == vlc->end) { in vl_vlc_search_byte()
320 if (vlc->bytes_left) in vl_vlc_search_byte()
322 vl_vlc_next_input(vlc); in vl_vlc_search_byte()
328 if (*vlc->data == value) { in vl_vlc_search_byte()
329 vl_vlc_align_data_ptr(vlc); in vl_vlc_search_byte()
330 vl_vlc_fillbits(vlc); in vl_vlc_search_byte()
334 ++vlc->data; in vl_vlc_search_byte()
338 vl_vlc_align_data_ptr(vlc); in vl_vlc_search_byte()
349 vl_vlc_removebits(struct vl_vlc *vlc, unsigned pos, unsigned num_bits) in vl_vlc_removebits() argument
351 uint64_t lo = (vlc->buffer & (~0UL >> (pos + num_bits))) << num_bits; in vl_vlc_removebits()
352 uint64_t hi = (vlc->buffer & (~0UL << (64 - pos))); in vl_vlc_removebits()
353 vlc->buffer = lo | hi; in vl_vlc_removebits()
354 vlc->invalid_bits += num_bits; in vl_vlc_removebits()
361 vl_vlc_limit(struct vl_vlc *vlc, unsigned bits_left) in vl_vlc_limit() argument
363 assert(bits_left <= vl_vlc_bits_left(vlc)); in vl_vlc_limit()
365 vl_vlc_fillbits(vlc); in vl_vlc_limit()
366 if (bits_left < vl_vlc_valid_bits(vlc)) { in vl_vlc_limit()
367 vlc->invalid_bits = 32 - bits_left; in vl_vlc_limit()
368 vlc->buffer &= ~0L << (vlc->invalid_bits + 32); in vl_vlc_limit()
369 vlc->end = vlc->data; in vl_vlc_limit()
370 vlc->bytes_left = 0; in vl_vlc_limit()
372 assert((bits_left - vl_vlc_valid_bits(vlc)) % 8 == 0); in vl_vlc_limit()
373 vlc->bytes_left = (bits_left - vl_vlc_valid_bits(vlc)) / 8; in vl_vlc_limit()
374 if (vlc->bytes_left < (vlc->end - vlc->data)) { in vl_vlc_limit()
375 vlc->end = vlc->data + vlc->bytes_left; in vl_vlc_limit()
376 vlc->bytes_left = 0; in vl_vlc_limit()
378 vlc->bytes_left -= vlc->end - vlc->data; in vl_vlc_limit()