FFmpeg  2.8.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
get_bits.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * bitstream reader API header.
24  */
25 
26 #ifndef AVCODEC_GET_BITS_H
27 #define AVCODEC_GET_BITS_H
28 
29 #include <stdint.h>
30 
31 #include "libavutil/common.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/log.h"
34 #include "libavutil/avassert.h"
35 #include "avcodec.h"
36 #include "mathops.h"
37 
38 /*
39  * Safe bitstream reading:
40  * optionally, the get_bits API can check to ensure that we
41  * don't read past input buffer boundaries. This is protected
42  * with CONFIG_SAFE_BITSTREAM_READER at the global level, and
43  * then below that with UNCHECKED_BITSTREAM_READER at the per-
44  * decoder level. This means that decoders that check internally
45  * can "#define UNCHECKED_BITSTREAM_READER 1" to disable
46  * overread checks.
47  * Boundary checking causes a minor performance penalty so for
48  * applications that won't want/need this, it can be disabled
49  * globally using "#define CONFIG_SAFE_BITSTREAM_READER 0".
50  */
51 #ifndef UNCHECKED_BITSTREAM_READER
52 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
53 #endif
54 
55 typedef struct GetBitContext {
57  int index;
61 
62 #define VLC_TYPE int16_t
63 
64 typedef struct VLC {
65  int bits;
66  VLC_TYPE (*table)[2]; ///< code, bits
68 } VLC;
69 
70 typedef struct RL_VLC_ELEM {
71  int16_t level;
72  int8_t len;
74 } RL_VLC_ELEM;
75 
76 /* Bitstream reader API docs:
77  * name
78  * arbitrary name which is used as prefix for the internal variables
79  *
80  * gb
81  * getbitcontext
82  *
83  * OPEN_READER(name, gb)
84  * load gb into local variables
85  *
86  * CLOSE_READER(name, gb)
87  * store local vars in gb
88  *
89  * UPDATE_CACHE(name, gb)
90  * Refill the internal cache from the bitstream.
91  * After this call at least MIN_CACHE_BITS will be available.
92  *
93  * GET_CACHE(name, gb)
94  * Will output the contents of the internal cache,
95  * next bit is MSB of 32 or 64 bit (FIXME 64bit).
96  *
97  * SHOW_UBITS(name, gb, num)
98  * Will return the next num bits.
99  *
100  * SHOW_SBITS(name, gb, num)
101  * Will return the next num bits and do sign extension.
102  *
103  * SKIP_BITS(name, gb, num)
104  * Will skip over the next num bits.
105  * Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER.
106  *
107  * SKIP_CACHE(name, gb, num)
108  * Will remove the next num bits from the cache (note SKIP_COUNTER
109  * MUST be called before UPDATE_CACHE / CLOSE_READER).
110  *
111  * SKIP_COUNTER(name, gb, num)
112  * Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS).
113  *
114  * LAST_SKIP_BITS(name, gb, num)
115  * Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER.
116  *
117  * BITS_LEFT(name, gb)
118  * Return the number of bits left
119  *
120  * For examples see get_bits, show_bits, skip_bits, get_vlc.
121  */
122 
123 #ifdef LONG_BITSTREAM_READER
124 # define MIN_CACHE_BITS 32
125 #else
126 # define MIN_CACHE_BITS 25
127 #endif
128 
129 #define OPEN_READER_NOSIZE(name, gb) \
130  unsigned int name ## _index = (gb)->index; \
131  unsigned int av_unused name ## _cache
132 
133 #if UNCHECKED_BITSTREAM_READER
134 #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb)
135 
136 #define BITS_AVAILABLE(name, gb) 1
137 #else
138 #define OPEN_READER(name, gb) \
139  OPEN_READER_NOSIZE(name, gb); \
140  unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8
141 
142 #define BITS_AVAILABLE(name, gb) name ## _index < name ## _size_plus8
143 #endif
144 
145 #define CLOSE_READER(name, gb) (gb)->index = name ## _index
146 
147 # ifdef LONG_BITSTREAM_READER
148 
149 # define UPDATE_CACHE_LE(name, gb) name ## _cache = \
150  AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7)
151 
152 # define UPDATE_CACHE_BE(name, gb) name ## _cache = \
153  AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7))
154 
155 #else
156 
157 # define UPDATE_CACHE_LE(name, gb) name ## _cache = \
158  AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7)
159 
160 # define UPDATE_CACHE_BE(name, gb) name ## _cache = \
161  AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7)
162 
163 #endif
164 
165 
166 #ifdef BITSTREAM_READER_LE
167 
168 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_LE(name, gb)
169 
170 # define SKIP_CACHE(name, gb, num) name ## _cache >>= (num)
171 
172 #else
173 
174 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_BE(name, gb)
175 
176 # define SKIP_CACHE(name, gb, num) name ## _cache <<= (num)
177 
178 #endif
179 
180 #if UNCHECKED_BITSTREAM_READER
181 # define SKIP_COUNTER(name, gb, num) name ## _index += (num)
182 #else
183 # define SKIP_COUNTER(name, gb, num) \
184  name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num))
185 #endif
186 
187 #define BITS_LEFT(name, gb) ((int)((gb)->size_in_bits - name ## _index))
188 
189 #define SKIP_BITS(name, gb, num) \
190  do { \
191  SKIP_CACHE(name, gb, num); \
192  SKIP_COUNTER(name, gb, num); \
193  } while (0)
194 
195 #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
196 
197 #define SHOW_UBITS_LE(name, gb, num) zero_extend(name ## _cache, num)
198 #define SHOW_SBITS_LE(name, gb, num) sign_extend(name ## _cache, num)
199 
200 #define SHOW_UBITS_BE(name, gb, num) NEG_USR32(name ## _cache, num)
201 #define SHOW_SBITS_BE(name, gb, num) NEG_SSR32(name ## _cache, num)
202 
203 #ifdef BITSTREAM_READER_LE
204 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_LE(name, gb, num)
205 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_LE(name, gb, num)
206 #else
207 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_BE(name, gb, num)
208 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_BE(name, gb, num)
209 #endif
210 
211 #define GET_CACHE(name, gb) ((uint32_t) name ## _cache)
212 
213 static inline int get_bits_count(const GetBitContext *s)
214 {
215  return s->index;
216 }
217 
218 static inline void skip_bits_long(GetBitContext *s, int n)
219 {
220 #if UNCHECKED_BITSTREAM_READER
221  s->index += n;
222 #else
223  s->index += av_clip(n, -s->index, s->size_in_bits_plus8 - s->index);
224 #endif
225 }
226 
227 /**
228  * read mpeg1 dc style vlc (sign bit + mantissa with no MSB).
229  * if MSB not set it is negative
230  * @param n length in bits
231  */
232 static inline int get_xbits(GetBitContext *s, int n)
233 {
234  register int sign;
235  register int32_t cache;
236  OPEN_READER(re, s);
237  av_assert2(n>0 && n<=25);
238  UPDATE_CACHE(re, s);
239  cache = GET_CACHE(re, s);
240  sign = ~cache >> 31;
241  LAST_SKIP_BITS(re, s, n);
242  CLOSE_READER(re, s);
243  return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
244 }
245 
246 static inline int get_sbits(GetBitContext *s, int n)
247 {
248  register int tmp;
249  OPEN_READER(re, s);
250  av_assert2(n>0 && n<=25);
251  UPDATE_CACHE(re, s);
252  tmp = SHOW_SBITS(re, s, n);
253  LAST_SKIP_BITS(re, s, n);
254  CLOSE_READER(re, s);
255  return tmp;
256 }
257 
258 /**
259  * Read 1-25 bits.
260  */
261 static inline unsigned int get_bits(GetBitContext *s, int n)
262 {
263  register int tmp;
264  OPEN_READER(re, s);
265  av_assert2(n>0 && n<=25);
266  UPDATE_CACHE(re, s);
267  tmp = SHOW_UBITS(re, s, n);
268  LAST_SKIP_BITS(re, s, n);
269  CLOSE_READER(re, s);
270  return tmp;
271 }
272 
273 static inline unsigned int get_bits_le(GetBitContext *s, int n)
274 {
275  register int tmp;
276  OPEN_READER(re, s);
277  av_assert2(n>0 && n<=25);
278  UPDATE_CACHE_LE(re, s);
279  tmp = SHOW_UBITS_LE(re, s, n);
280  LAST_SKIP_BITS(re, s, n);
281  CLOSE_READER(re, s);
282  return tmp;
283 }
284 
285 /**
286  * Show 1-25 bits.
287  */
288 static inline unsigned int show_bits(GetBitContext *s, int n)
289 {
290  register int tmp;
292  av_assert2(n>0 && n<=25);
293  UPDATE_CACHE(re, s);
294  tmp = SHOW_UBITS(re, s, n);
295  return tmp;
296 }
297 
298 static inline void skip_bits(GetBitContext *s, int n)
299 {
300  OPEN_READER(re, s);
301  LAST_SKIP_BITS(re, s, n);
302  CLOSE_READER(re, s);
303 }
304 
305 static inline unsigned int get_bits1(GetBitContext *s)
306 {
307  unsigned int index = s->index;
308  uint8_t result = s->buffer[index >> 3];
309 #ifdef BITSTREAM_READER_LE
310  result >>= index & 7;
311  result &= 1;
312 #else
313  result <<= index & 7;
314  result >>= 8 - 1;
315 #endif
316 #if !UNCHECKED_BITSTREAM_READER
317  if (s->index < s->size_in_bits_plus8)
318 #endif
319  index++;
320  s->index = index;
321 
322  return result;
323 }
324 
325 static inline unsigned int show_bits1(GetBitContext *s)
326 {
327  return show_bits(s, 1);
328 }
329 
330 static inline void skip_bits1(GetBitContext *s)
331 {
332  skip_bits(s, 1);
333 }
334 
335 /**
336  * Read 0-32 bits.
337  */
338 static inline unsigned int get_bits_long(GetBitContext *s, int n)
339 {
340  if (!n) {
341  return 0;
342  } else if (n <= MIN_CACHE_BITS) {
343  return get_bits(s, n);
344  } else {
345 #ifdef BITSTREAM_READER_LE
346  unsigned ret = get_bits(s, 16);
347  return ret | (get_bits(s, n - 16) << 16);
348 #else
349  unsigned ret = get_bits(s, 16) << (n - 16);
350  return ret | get_bits(s, n - 16);
351 #endif
352  }
353 }
354 
355 /**
356  * Read 0-64 bits.
357  */
358 static inline uint64_t get_bits64(GetBitContext *s, int n)
359 {
360  if (n <= 32) {
361  return get_bits_long(s, n);
362  } else {
363 #ifdef BITSTREAM_READER_LE
364  uint64_t ret = get_bits_long(s, 32);
365  return ret | (uint64_t) get_bits_long(s, n - 32) << 32;
366 #else
367  uint64_t ret = (uint64_t) get_bits_long(s, n - 32) << 32;
368  return ret | get_bits_long(s, 32);
369 #endif
370  }
371 }
372 
373 /**
374  * Read 0-32 bits as a signed integer.
375  */
376 static inline int get_sbits_long(GetBitContext *s, int n)
377 {
378  // sign_extend(x, 0) is undefined
379  if (!n)
380  return 0;
381 
382  return sign_extend(get_bits_long(s, n), n);
383 }
384 
385 /**
386  * Show 0-32 bits.
387  */
388 static inline unsigned int show_bits_long(GetBitContext *s, int n)
389 {
390  if (n <= MIN_CACHE_BITS) {
391  return show_bits(s, n);
392  } else {
393  GetBitContext gb = *s;
394  return get_bits_long(&gb, n);
395  }
396 }
397 
398 static inline int check_marker(GetBitContext *s, const char *msg)
399 {
400  int bit = get_bits1(s);
401  if (!bit)
402  av_log(NULL, AV_LOG_INFO, "Marker bit missing at %d of %d %s\n", get_bits_count(s) - 1, s->size_in_bits, msg);
403 
404  return bit;
405 }
406 
407 /**
408  * Initialize GetBitContext.
409  * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
410  * larger than the actual read bits because some optimized bitstream
411  * readers read 32 or 64 bit at once and could read over the end
412  * @param bit_size the size of the buffer in bits
413  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
414  */
415 static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
416  int bit_size)
417 {
418  int buffer_size;
419  int ret = 0;
420 
421  if (bit_size >= INT_MAX - FFMAX(7, AV_INPUT_BUFFER_PADDING_SIZE*8) || bit_size < 0 || !buffer) {
422  bit_size = 0;
423  buffer = NULL;
424  ret = AVERROR_INVALIDDATA;
425  }
426 
427  buffer_size = (bit_size + 7) >> 3;
428 
429  s->buffer = buffer;
430  s->size_in_bits = bit_size;
431  s->size_in_bits_plus8 = bit_size + 8;
432  s->buffer_end = buffer + buffer_size;
433  s->index = 0;
434 
435  return ret;
436 }
437 
438 /**
439  * Initialize GetBitContext.
440  * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
441  * larger than the actual read bits because some optimized bitstream
442  * readers read 32 or 64 bit at once and could read over the end
443  * @param byte_size the size of the buffer in bytes
444  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
445  */
446 static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
447  int byte_size)
448 {
449  if (byte_size > INT_MAX / 8 || byte_size < 0)
450  byte_size = -1;
451  return init_get_bits(s, buffer, byte_size * 8);
452 }
453 
454 static inline const uint8_t *align_get_bits(GetBitContext *s)
455 {
456  int n = -get_bits_count(s) & 7;
457  if (n)
458  skip_bits(s, n);
459  return s->buffer + (s->index >> 3);
460 }
461 
462 #define init_vlc(vlc, nb_bits, nb_codes, \
463  bits, bits_wrap, bits_size, \
464  codes, codes_wrap, codes_size, \
465  flags) \
466  ff_init_vlc_sparse(vlc, nb_bits, nb_codes, \
467  bits, bits_wrap, bits_size, \
468  codes, codes_wrap, codes_size, \
469  NULL, 0, 0, flags)
470 
471 int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
472  const void *bits, int bits_wrap, int bits_size,
473  const void *codes, int codes_wrap, int codes_size,
474  const void *symbols, int symbols_wrap, int symbols_size,
475  int flags);
476 void ff_free_vlc(VLC *vlc);
477 
478 #define INIT_VLC_LE 2
479 #define INIT_VLC_USE_NEW_STATIC 4
480 
481 #define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \
482  do { \
483  static VLC_TYPE table[static_size][2]; \
484  (vlc)->table = table; \
485  (vlc)->table_allocated = static_size; \
486  init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \
487  } while (0)
488 
489 /**
490  * If the vlc code is invalid and max_depth=1, then no bits will be removed.
491  * If the vlc code is invalid and max_depth>1, then the number of bits removed
492  * is undefined.
493  */
494 #define GET_VLC(code, name, gb, table, bits, max_depth) \
495  do { \
496  int n, nb_bits; \
497  unsigned int index; \
498  \
499  index = SHOW_UBITS(name, gb, bits); \
500  code = table[index][0]; \
501  n = table[index][1]; \
502  \
503  if (max_depth > 1 && n < 0) { \
504  LAST_SKIP_BITS(name, gb, bits); \
505  UPDATE_CACHE(name, gb); \
506  \
507  nb_bits = -n; \
508  \
509  index = SHOW_UBITS(name, gb, nb_bits) + code; \
510  code = table[index][0]; \
511  n = table[index][1]; \
512  if (max_depth > 2 && n < 0) { \
513  LAST_SKIP_BITS(name, gb, nb_bits); \
514  UPDATE_CACHE(name, gb); \
515  \
516  nb_bits = -n; \
517  \
518  index = SHOW_UBITS(name, gb, nb_bits) + code; \
519  code = table[index][0]; \
520  n = table[index][1]; \
521  } \
522  } \
523  SKIP_BITS(name, gb, n); \
524  } while (0)
525 
526 #define GET_RL_VLC_INTERNAL(level, run, name, gb, table, bits, \
527  max_depth, need_update) \
528  do { \
529  int n, nb_bits; \
530  unsigned int index; \
531  \
532  index = SHOW_UBITS(name, gb, bits); \
533  level = table[index].level; \
534  n = table[index].len; \
535  \
536  if (max_depth > 1 && n < 0) { \
537  SKIP_BITS(name, gb, bits); \
538  if (need_update) { \
539  UPDATE_CACHE(name, gb); \
540  } \
541  \
542  nb_bits = -n; \
543  \
544  index = SHOW_UBITS(name, gb, nb_bits) + level; \
545  level = table[index].level; \
546  n = table[index].len; \
547  } \
548  run = table[index].run; \
549  SKIP_BITS(name, gb, n); \
550  } while (0)
551 
552 /**
553  * Parse a vlc code.
554  * @param bits is the number of bits which will be read at once, must be
555  * identical to nb_bits in init_vlc()
556  * @param max_depth is the number of times bits bits must be read to completely
557  * read the longest vlc code
558  * = (max_vlc_length + bits - 1) / bits
559  * @returns the code parsed or -1 if no vlc matches
560  */
562  int bits, int max_depth)
563 {
564  int code;
565 
566  OPEN_READER(re, s);
567  UPDATE_CACHE(re, s);
568 
569  GET_VLC(code, re, s, table, bits, max_depth);
570 
571  CLOSE_READER(re, s);
572 
573  return code;
574 }
575 
576 static inline int decode012(GetBitContext *gb)
577 {
578  int n;
579  n = get_bits1(gb);
580  if (n == 0)
581  return 0;
582  else
583  return get_bits1(gb) + 1;
584 }
585 
586 static inline int decode210(GetBitContext *gb)
587 {
588  if (get_bits1(gb))
589  return 0;
590  else
591  return 2 - get_bits1(gb);
592 }
593 
594 static inline int get_bits_left(GetBitContext *gb)
595 {
596  return gb->size_in_bits - get_bits_count(gb);
597 }
598 
599 static inline int skip_1stop_8data_bits(GetBitContext *gb)
600 {
601  if (get_bits_left(gb) <= 0)
602  return AVERROR_INVALIDDATA;
603 
604  while (get_bits1(gb)) {
605  skip_bits(gb, 8);
606  if (get_bits_left(gb) <= 0)
607  return AVERROR_INVALIDDATA;
608  }
609 
610  return 0;
611 }
612 
613 //#define TRACE
614 
615 #ifdef TRACE
616 static inline void print_bin(int bits, int n)
617 {
618  int i;
619 
620  for (i = n - 1; i >= 0; i--)
621  av_log(NULL, AV_LOG_DEBUG, "%d", (bits >> i) & 1);
622  for (i = n; i < 24; i++)
623  av_log(NULL, AV_LOG_DEBUG, " ");
624 }
625 
626 static inline int get_bits_trace(GetBitContext *s, int n, const char *file,
627  const char *func, int line)
628 {
629  int r = get_bits(s, n);
630 
631  print_bin(r, n);
632  av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n",
633  r, n, r, get_bits_count(s) - n, file, func, line);
634 
635  return r;
636 }
637 
638 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2],
639  int bits, int max_depth, const char *file,
640  const char *func, int line)
641 {
642  int show = show_bits(s, 24);
643  int pos = get_bits_count(s);
644  int r = get_vlc2(s, table, bits, max_depth);
645  int len = get_bits_count(s) - pos;
646  int bits2 = show >> (24 - len);
647 
648  print_bin(bits2, len);
649 
650  av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n",
651  bits2, len, r, pos, file, func, line);
652 
653  return r;
654 }
655 
656 #define GET_RL_VLC(level, run, name, gb, table, bits, \
657  max_depth, need_update) \
658  do { \
659  int show = SHOW_UBITS(name, gb, 24); \
660  int len; \
661  int pos = name ## _index; \
662  \
663  GET_RL_VLC_INTERNAL(level, run, name, gb, table, bits,max_depth, need_update); \
664  \
665  len = name ## _index - pos + 1; \
666  show = show >> (24 - len); \
667  \
668  print_bin(show, len); \
669  \
670  av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d/%-3d rlv @%5d in %s %s:%d\n",\
671  show, len, run-1, level, pos, __FILE__, __PRETTY_FUNCTION__, __LINE__);\
672  } while (0) \
673 
674 
675 static inline int get_xbits_trace(GetBitContext *s, int n, const char *file,
676  const char *func, int line)
677 {
678  int show = show_bits(s, n);
679  int r = get_xbits(s, n);
680 
681  print_bin(show, n);
682  av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n",
683  show, n, r, get_bits_count(s) - n, file, func, line);
684 
685  return r;
686 }
687 
688 #define get_bits(s, n) get_bits_trace(s , n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
689 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
690 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
691 
692 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
693 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
694 #else //TRACE
695 #define GET_RL_VLC GET_RL_VLC_INTERNAL
696 #endif
697 
698 #endif /* AVCODEC_GET_BITS_H */
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:388
static unsigned int show_bits1(GetBitContext *s)
Definition: get_bits.h:325
#define NULL
Definition: coverity.c:32
int table_size
Definition: get_bits.h:67
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:218
const uint8_t * buffer
Definition: get_bits.h:56
#define VLC_TYPE
Definition: get_bits.h:62
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:246
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:376
uint8_t bits
Definition: crc.c:295
uint8_t
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:213
static const uint8_t bits2[81]
Definition: aactab.c:128
#define SHOW_UBITS_LE(name, gb, num)
Definition: get_bits.h:197
#define av_log(a,...)
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:594
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
Definition: get_bits.h:358
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:174
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:359
static const struct endianess table[]
const char * r
Definition: vf_curves.c:107
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
Definition: graph2dot.c:48
simple assert() macros that are a bit more flexible than ISO C assert().
#define CLOSE_READER(name, gb)
Definition: get_bits.h:145
#define FFMAX(a, b)
Definition: common.h:90
Libavcodec external API header.
int8_t len
Definition: get_bits.h:72
static int check_marker(GetBitContext *s, const char *msg)
Definition: get_bits.h:398
Definition: get_bits.h:64
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: bitstream.c:274
#define NEG_USR32(a, s)
Definition: mathops.h:174
int size_in_bits
Definition: get_bits.h:58
int32_t
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:288
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:195
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:561
int n
Definition: avisynth_c.h:547
#define GET_VLC(code, name, gb, table, bits, max_depth)
If the vlc code is invalid and max_depth=1, then no bits will be removed.
Definition: get_bits.h:494
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:207
static int decode210(GetBitContext *gb)
Definition: get_bits.h:586
int bits
Definition: get_bits.h:65
int table_allocated
Definition: get_bits.h:67
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
int size_in_bits_plus8
Definition: get_bits.h:59
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:446
static int get_xbits(GetBitContext *s, int n)
read mpeg1 dc style vlc (sign bit + mantissa with no MSB).
Definition: get_bits.h:232
#define OPEN_READER(name, gb)
Definition: get_bits.h:134
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:305
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:330
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:298
int index
Definition: gxfenc.c:89
#define UPDATE_CACHE_LE(name, gb)
Definition: get_bits.h:157
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:415
#define GET_CACHE(name, gb)
Definition: get_bits.h:211
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:67
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:338
#define MIN_CACHE_BITS
Definition: get_bits.h:126
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:138
static unsigned int get_bits_le(GetBitContext *s, int n)
Definition: get_bits.h:273
static int flags
Definition: cpu.c:47
uint8_t run
Definition: get_bits.h:73
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:208
#define OPEN_READER_NOSIZE(name, gb)
Definition: get_bits.h:129
common internal and external API header
const uint8_t * buffer_end
Definition: get_bits.h:56
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:636
float re
Definition: fft-test.c:73
int len
static int decode012(GetBitContext *gb)
Definition: get_bits.h:576
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:454
int16_t level
Definition: get_bits.h:71
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:599
#define av_always_inline
Definition: attributes.h:37
GLuint buffer
Definition: opengl_enc.c:102