FFmpeg
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/avassert.h"
34 
35 #include "defs.h"
36 #include "mathops.h"
37 #include "vlc.h"
38 
39 /*
40  * Safe bitstream reading:
41  * optionally, the get_bits API can check to ensure that we
42  * don't read past input buffer boundaries. This is protected
43  * with CONFIG_SAFE_BITSTREAM_READER at the global level, and
44  * then below that with UNCHECKED_BITSTREAM_READER at the per-
45  * decoder level. This means that decoders that check internally
46  * can "#define UNCHECKED_BITSTREAM_READER 1" to disable
47  * overread checks.
48  * Boundary checking causes a minor performance penalty so for
49  * applications that won't want/need this, it can be disabled
50  * globally using "#define CONFIG_SAFE_BITSTREAM_READER 0".
51  */
52 #ifndef UNCHECKED_BITSTREAM_READER
53 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
54 #endif
55 
56 #ifndef CACHED_BITSTREAM_READER
57 #define CACHED_BITSTREAM_READER 0
58 #endif
59 
60 #if CACHED_BITSTREAM_READER
61 
62 // we always want the LE implementation, to provide get_bits_le()
63 #define BITSTREAM_LE
64 
65 #ifndef BITSTREAM_READER_LE
66 # define BITSTREAM_BE
67 # define BITSTREAM_DEFAULT_BE
68 #endif
69 
70 #include "bitstream.h"
71 
72 #undef BITSTREAM_LE
73 #undef BITSTREAM_BE
74 #undef BITSTREAM_DEFAULT_BE
75 
77 
78 #define get_bits_count bits_tell
79 #define get_bits_left bits_left
80 #define skip_bits_long bits_skip
81 #define skip_bits bits_skip
82 #define get_bits bits_read_nz
83 #define get_bitsz bits_read
84 #define get_bits_long bits_read
85 #define get_bits1 bits_read_bit
86 #define get_bits64 bits_read_64
87 #define get_xbits bits_read_xbits
88 #define get_sbits bits_read_signed_nz
89 #define get_sbits_long bits_read_signed
90 #define show_bits bits_peek
91 #define show_bits_long bits_peek
92 #define init_get_bits bits_init
93 #define init_get_bits8 bits_init8
94 #define align_get_bits bits_align
95 #define get_vlc2 bits_read_vlc
96 #define get_vlc_multi bits_read_vlc_multi
97 
98 #define init_get_bits8_le(s, buffer, byte_size) bits_init8_le((BitstreamContextLE*)s, buffer, byte_size)
99 #define get_bits_le(s, n) bits_read_le((BitstreamContextLE*)s, n)
100 
101 #define show_bits1(s) bits_peek(s, 1)
102 #define skip_bits1(s) bits_skip(s, 1)
103 
104 #define skip_1stop_8data_bits bits_skip_1stop_8data
105 
106 #else // CACHED_BITSTREAM_READER
107 
108 typedef struct GetBitContext {
109  const uint8_t *buffer, *buffer_end;
110  int index;
113 } GetBitContext;
114 
115 static inline unsigned int get_bits(GetBitContext *s, int n);
116 static inline void skip_bits(GetBitContext *s, int n);
117 static inline unsigned int show_bits(GetBitContext *s, int n);
118 
119 /* Bitstream reader API docs:
120  * name
121  * arbitrary name which is used as prefix for the internal variables
122  *
123  * gb
124  * getbitcontext
125  *
126  * OPEN_READER(name, gb)
127  * load gb into local variables
128  *
129  * CLOSE_READER(name, gb)
130  * store local vars in gb
131  *
132  * UPDATE_CACHE(name, gb)
133  * Refill the internal cache from the bitstream.
134  * After this call at least MIN_CACHE_BITS will be available.
135  *
136  * GET_CACHE(name, gb)
137  * Will output the contents of the internal cache,
138  * next bit is MSB of 32 or 64 bits (FIXME 64 bits).
139  *
140  * SHOW_UBITS(name, gb, num)
141  * Will return the next num bits.
142  *
143  * SHOW_SBITS(name, gb, num)
144  * Will return the next num bits and do sign extension.
145  *
146  * SKIP_BITS(name, gb, num)
147  * Will skip over the next num bits.
148  * Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER.
149  *
150  * SKIP_CACHE(name, gb, num)
151  * Will remove the next num bits from the cache (note SKIP_COUNTER
152  * MUST be called before UPDATE_CACHE / CLOSE_READER).
153  *
154  * SKIP_COUNTER(name, gb, num)
155  * Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS).
156  *
157  * LAST_SKIP_BITS(name, gb, num)
158  * Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER.
159  *
160  * BITS_LEFT(name, gb)
161  * Return the number of bits left
162  *
163  * For examples see get_bits, show_bits, skip_bits, get_vlc.
164  */
165 
166 #define MIN_CACHE_BITS 25
167 
168 #define OPEN_READER_NOSIZE(name, gb) \
169  unsigned int name ## _index = (gb)->index; \
170  unsigned int av_unused name ## _cache
171 
172 #if UNCHECKED_BITSTREAM_READER
173 #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb)
174 
175 #define BITS_AVAILABLE(name, gb) 1
176 #else
177 #define OPEN_READER(name, gb) \
178  OPEN_READER_NOSIZE(name, gb); \
179  unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8
180 
181 #define BITS_AVAILABLE(name, gb) name ## _index < name ## _size_plus8
182 #endif
183 
184 #define CLOSE_READER(name, gb) (gb)->index = name ## _index
185 
186 #define UPDATE_CACHE_BE_EXT(name, gb, bits, dst_bits) name ## _cache = \
187  AV_RB ## bits((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) >> (bits - dst_bits)
188 
189 #define UPDATE_CACHE_LE_EXT(name, gb, bits, dst_bits) name ## _cache = \
190  (uint ## dst_bits ## _t)(AV_RL ## bits((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7))
191 
192 /* Using these two macros ensures that 32 bits are available. */
193 # define UPDATE_CACHE_LE_32(name, gb) UPDATE_CACHE_LE_EXT(name, (gb), 64, 32)
194 # define UPDATE_CACHE_BE_32(name, gb) UPDATE_CACHE_BE_EXT(name, (gb), 64, 32)
195 
196 # define UPDATE_CACHE_LE(name, gb) UPDATE_CACHE_LE_EXT(name, (gb), 32, 32)
197 # define UPDATE_CACHE_BE(name, gb) UPDATE_CACHE_BE_EXT(name, (gb), 32, 32)
198 
199 #ifdef BITSTREAM_READER_LE
200 
201 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_LE(name, gb)
202 # define UPDATE_CACHE_32(name, gb) UPDATE_CACHE_LE_32(name, (gb))
203 
204 # define SKIP_CACHE(name, gb, num) name ## _cache >>= (num)
205 
206 #else
207 
208 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_BE(name, gb)
209 # define UPDATE_CACHE_32(name, gb) UPDATE_CACHE_BE_32(name, (gb))
210 
211 # define SKIP_CACHE(name, gb, num) name ## _cache <<= (num)
212 
213 #endif
214 
215 #if UNCHECKED_BITSTREAM_READER
216 # define SKIP_COUNTER(name, gb, num) name ## _index += (num)
217 #else
218 # define SKIP_COUNTER(name, gb, num) \
219  name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num))
220 #endif
221 
222 #define BITS_LEFT(name, gb) ((int)((gb)->size_in_bits - name ## _index))
223 
224 #define SKIP_BITS(name, gb, num) \
225  do { \
226  SKIP_CACHE(name, gb, num); \
227  SKIP_COUNTER(name, gb, num); \
228  } while (0)
229 
230 #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
231 
232 #define SHOW_UBITS_LE(name, gb, num) zero_extend(name ## _cache, num)
233 #define SHOW_SBITS_LE(name, gb, num) sign_extend(name ## _cache, num)
234 
235 #define SHOW_UBITS_BE(name, gb, num) NEG_USR32(name ## _cache, num)
236 #define SHOW_SBITS_BE(name, gb, num) NEG_SSR32(name ## _cache, num)
237 
238 #ifdef BITSTREAM_READER_LE
239 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_LE(name, gb, num)
240 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_LE(name, gb, num)
241 #else
242 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_BE(name, gb, num)
243 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_BE(name, gb, num)
244 #endif
245 
246 #define GET_CACHE(name, gb) ((uint32_t) name ## _cache)
247 
248 
249 static inline int get_bits_count(const GetBitContext *s)
250 {
251  return s->index;
252 }
253 
254 /**
255  * Skips the specified number of bits.
256  * @param n the number of bits to skip,
257  * For the UNCHECKED_BITSTREAM_READER this must not cause the distance
258  * from the start to overflow int32_t. Staying within the bitstream + padding
259  * is sufficient, too.
260  */
261 static inline void skip_bits_long(GetBitContext *s, int n)
262 {
263 #if UNCHECKED_BITSTREAM_READER
264  s->index += n;
265 #else
266  s->index += av_clip(n, -s->index, s->size_in_bits_plus8 - s->index);
267 #endif
268 }
269 
270 /**
271  * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
272  * if MSB not set it is negative
273  * @param n length in bits
274  */
275 static inline int get_xbits(GetBitContext *s, int n)
276 {
277  register int sign;
278  register int32_t cache;
279  OPEN_READER(re, s);
280  av_assert2(n>0 && n<=25);
281  UPDATE_CACHE(re, s);
282  cache = GET_CACHE(re, s);
283  sign = ~cache >> 31;
284  LAST_SKIP_BITS(re, s, n);
285  CLOSE_READER(re, s);
286  return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
287 }
288 
289 static inline int get_xbits_le(GetBitContext *s, int n)
290 {
291  register int sign;
292  register int32_t cache;
293  OPEN_READER(re, s);
294  av_assert2(n>0 && n<=25);
295  UPDATE_CACHE_LE(re, s);
296  cache = GET_CACHE(re, s);
297  sign = sign_extend(~cache, n) >> 31;
298  LAST_SKIP_BITS(re, s, n);
299  CLOSE_READER(re, s);
300  return (zero_extend(sign ^ cache, n) ^ sign) - sign;
301 }
302 
303 static inline int get_sbits(GetBitContext *s, int n)
304 {
305  register int tmp;
306  OPEN_READER(re, s);
307  av_assert2(n>0 && n<=25);
308  UPDATE_CACHE(re, s);
309  tmp = SHOW_SBITS(re, s, n);
310  LAST_SKIP_BITS(re, s, n);
311  CLOSE_READER(re, s);
312  return tmp;
313 }
314 
315 /**
316  * Read 1-25 bits.
317  */
318 static inline unsigned int get_bits(GetBitContext *s, int n)
319 {
320  register unsigned int tmp;
321  OPEN_READER(re, s);
322  av_assert2(n>0 && n<=25);
323  UPDATE_CACHE(re, s);
324  tmp = SHOW_UBITS(re, s, n);
325  LAST_SKIP_BITS(re, s, n);
326  CLOSE_READER(re, s);
327  av_assert2(tmp < UINT64_C(1) << n);
328  return tmp;
329 }
330 
331 /**
332  * Read 0-25 bits.
333  */
335 {
336  return n ? get_bits(s, n) : 0;
337 }
338 
339 static inline unsigned int get_bits_le(GetBitContext *s, int n)
340 {
341  register int tmp;
342  OPEN_READER(re, s);
343  av_assert2(n>0 && n<=25);
344  UPDATE_CACHE_LE(re, s);
345  tmp = SHOW_UBITS_LE(re, s, n);
346  LAST_SKIP_BITS(re, s, n);
347  CLOSE_READER(re, s);
348  return tmp;
349 }
350 
351 /**
352  * Show 1-25 bits.
353  */
354 static inline unsigned int show_bits(GetBitContext *s, int n)
355 {
356  register unsigned int tmp;
357  OPEN_READER_NOSIZE(re, s);
358  av_assert2(n>0 && n<=25);
359  UPDATE_CACHE(re, s);
360  tmp = SHOW_UBITS(re, s, n);
361  return tmp;
362 }
363 
364 static inline void skip_bits(GetBitContext *s, int n)
365 {
366  OPEN_READER(re, s);
367  LAST_SKIP_BITS(re, s, n);
368  CLOSE_READER(re, s);
369 }
370 
371 static inline unsigned int get_bits1(GetBitContext *s)
372 {
373  unsigned int index = s->index;
374  uint8_t result = s->buffer[index >> 3];
375 #ifdef BITSTREAM_READER_LE
376  result >>= index & 7;
377  result &= 1;
378 #else
379  result <<= index & 7;
380  result >>= 8 - 1;
381 #endif
382 #if !UNCHECKED_BITSTREAM_READER
383  if (s->index < s->size_in_bits_plus8)
384 #endif
385  index++;
386  s->index = index;
387 
388  return result;
389 }
390 
391 static inline unsigned int show_bits1(GetBitContext *s)
392 {
393  return show_bits(s, 1);
394 }
395 
396 static inline void skip_bits1(GetBitContext *s)
397 {
398  skip_bits(s, 1);
399 }
400 
401 /**
402  * Read 0-32 bits.
403  */
404 static inline unsigned int get_bits_long(GetBitContext *s, int n)
405 {
406  av_assert2(n>=0 && n<=32);
407  if (!n) {
408  return 0;
409  } else if ((!HAVE_FAST_64BIT || av_builtin_constant_p(n <= MIN_CACHE_BITS))
410  && n <= MIN_CACHE_BITS) {
411  return get_bits(s, n);
412  } else {
413 #if HAVE_FAST_64BIT
414  unsigned tmp;
415  OPEN_READER(re, s);
416  UPDATE_CACHE_32(re, s);
417  tmp = SHOW_UBITS(re, s, n);
418  LAST_SKIP_BITS(re, s, n);
419  CLOSE_READER(re, s);
420  return tmp;
421 #else
422 #ifdef BITSTREAM_READER_LE
423  unsigned ret = get_bits(s, 16);
424  return ret | (get_bits(s, n - 16) << 16);
425 #else
426  unsigned ret = get_bits(s, 16) << (n - 16);
427  return ret | get_bits(s, n - 16);
428 #endif
429 #endif
430  }
431 }
432 
433 /**
434  * Read 0-64 bits.
435  */
436 static inline uint64_t get_bits64(GetBitContext *s, int n)
437 {
438  if (n <= 32) {
439  return get_bits_long(s, n);
440  } else {
441 #ifdef BITSTREAM_READER_LE
442  uint64_t ret = get_bits_long(s, 32);
443  return ret | (uint64_t) get_bits_long(s, n - 32) << 32;
444 #else
445  uint64_t ret = (uint64_t) get_bits_long(s, n - 32) << 32;
446  return ret | get_bits_long(s, 32);
447 #endif
448  }
449 }
450 
451 /**
452  * Read 0-32 bits as a signed integer.
453  */
454 static inline int get_sbits_long(GetBitContext *s, int n)
455 {
456  // sign_extend(x, 0) is undefined
457  if (!n)
458  return 0;
459 
460  return sign_extend(get_bits_long(s, n), n);
461 }
462 
463 /**
464  * Read 0-64 bits as a signed integer.
465  */
466 static inline int64_t get_sbits64(GetBitContext *s, int n)
467 {
468  // sign_extend(x, 0) is undefined
469  if (!n)
470  return 0;
471 
472  return sign_extend64(get_bits64(s, n), n);
473 }
474 
475 /**
476  * Show 0-32 bits.
477  */
478 static inline unsigned int show_bits_long(GetBitContext *s, int n)
479 {
480  if (n <= MIN_CACHE_BITS) {
481  return show_bits(s, n);
482  } else {
483  GetBitContext gb = *s;
484  return get_bits_long(&gb, n);
485  }
486 }
487 
488 
489 /**
490  * Initialize GetBitContext.
491  * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
492  * larger than the actual read bits because some optimized bitstream
493  * readers read 32 or 64 bit at once and could read over the end
494  * @param bit_size the size of the buffer in bits
495  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
496  */
497 static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
498  int bit_size)
499 {
500  int buffer_size;
501  int ret = 0;
502 
503  if (bit_size >= INT_MAX - FFMAX(7, AV_INPUT_BUFFER_PADDING_SIZE*8) || bit_size < 0 || !buffer) {
504  bit_size = 0;
505  buffer = NULL;
507  }
508 
509  buffer_size = (bit_size + 7) >> 3;
510 
511  s->buffer = buffer;
512  s->size_in_bits = bit_size;
513  s->size_in_bits_plus8 = bit_size + 8;
514  s->buffer_end = buffer + buffer_size;
515  s->index = 0;
516 
517  return ret;
518 }
519 
520 /**
521  * Initialize GetBitContext.
522  * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
523  * larger than the actual read bits because some optimized bitstream
524  * readers read 32 or 64 bit at once and could read over the end
525  * @param byte_size the size of the buffer in bytes
526  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
527  */
528 static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
529  int byte_size)
530 {
531  if (byte_size > INT_MAX / 8 || byte_size < 0)
532  byte_size = -1;
533  return init_get_bits(s, buffer, byte_size * 8);
534 }
535 
536 static inline int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer,
537  int byte_size)
538 {
539  if (byte_size > INT_MAX / 8 || byte_size < 0)
540  byte_size = -1;
541  return init_get_bits(s, buffer, byte_size * 8);
542 }
543 
544 static inline const uint8_t *align_get_bits(GetBitContext *s)
545 {
546  int n = -get_bits_count(s) & 7;
547  if (n)
548  skip_bits(s, n);
549  return s->buffer + (s->index >> 3);
550 }
551 
552 /**
553  * If the vlc code is invalid and max_depth=1, then no bits will be removed.
554  * If the vlc code is invalid and max_depth>1, then the number of bits removed
555  * is undefined.
556  */
557 #define GET_VLC(code, name, gb, table, bits, max_depth) \
558  do { \
559  int n, nb_bits; \
560  unsigned int index; \
561  \
562  index = SHOW_UBITS(name, gb, bits); \
563  code = table[index].sym; \
564  n = table[index].len; \
565  \
566  if (max_depth > 1 && n < 0) { \
567  LAST_SKIP_BITS(name, gb, bits); \
568  UPDATE_CACHE(name, gb); \
569  \
570  nb_bits = -n; \
571  \
572  index = SHOW_UBITS(name, gb, nb_bits) + code; \
573  code = table[index].sym; \
574  n = table[index].len; \
575  if (max_depth > 2 && n < 0) { \
576  LAST_SKIP_BITS(name, gb, nb_bits); \
577  UPDATE_CACHE(name, gb); \
578  \
579  nb_bits = -n; \
580  \
581  index = SHOW_UBITS(name, gb, nb_bits) + code; \
582  code = table[index].sym; \
583  n = table[index].len; \
584  } \
585  } \
586  SKIP_BITS(name, gb, n); \
587  } while (0)
588 
589 #define GET_RL_VLC(level, run, name, gb, table, bits, \
590  max_depth, need_update) \
591  do { \
592  int n, nb_bits; \
593  unsigned int index; \
594  \
595  index = SHOW_UBITS(name, gb, bits); \
596  level = table[index].level; \
597  n = table[index].len8; \
598  \
599  if (max_depth > 1 && n < 0) { \
600  SKIP_BITS(name, gb, bits); \
601  if (need_update) { \
602  UPDATE_CACHE(name, gb); \
603  } \
604  \
605  nb_bits = -n; \
606  \
607  index = SHOW_UBITS(name, gb, nb_bits) + level; \
608  level = table[index].level; \
609  n = table[index].len8; \
610  if (max_depth > 2 && n < 0) { \
611  LAST_SKIP_BITS(name, gb, nb_bits); \
612  if (need_update) { \
613  UPDATE_CACHE(name, gb); \
614  } \
615  nb_bits = -n; \
616  \
617  index = SHOW_UBITS(name, gb, nb_bits) + level; \
618  level = table[index].level; \
619  n = table[index].len8; \
620  } \
621  } \
622  run = table[index].run; \
623  SKIP_BITS(name, gb, n); \
624  } while (0)
625 
626 /**
627  * Parse a vlc code.
628  * @param bits is the number of bits which will be read at once, must be
629  * identical to nb_bits in vlc_init()
630  * @param max_depth is the number of times bits bits must be read to completely
631  * read the longest vlc code
632  * = (max_vlc_length + bits - 1) / bits
633  * @returns the code parsed or -1 if no vlc matches
634  */
636  int bits, int max_depth)
637 {
638  int code;
639 
640  OPEN_READER(re, s);
641  UPDATE_CACHE(re, s);
642 
643  GET_VLC(code, re, s, table, bits, max_depth);
644 
645  CLOSE_READER(re, s);
646 
647  return code;
648 }
649 
650 static inline int get_vlc_multi(GetBitContext *s, uint8_t *dst,
651  const VLC_MULTI_ELEM *const Jtable,
652  const VLCElem *const table,
653  const int bits, const int max_depth,
654  const int symbols_size)
655 {
656  dst[0] = get_vlc2(s, table, bits, max_depth);
657  return 1;
658 }
659 
660 static inline int decode012(GetBitContext *gb)
661 {
662  int n;
663  n = get_bits1(gb);
664  if (n == 0)
665  return 0;
666  else
667  return get_bits1(gb) + 1;
668 }
669 
670 static inline int decode210(GetBitContext *gb)
671 {
672  if (get_bits1(gb))
673  return 0;
674  else
675  return 2 - get_bits1(gb);
676 }
677 
678 static inline int get_bits_left(GetBitContext *gb)
679 {
680  return gb->size_in_bits - get_bits_count(gb);
681 }
682 
683 static inline int skip_1stop_8data_bits(GetBitContext *gb)
684 {
685  if (get_bits_left(gb) <= 0)
686  return AVERROR_INVALIDDATA;
687 
688  while (get_bits1(gb)) {
689  skip_bits(gb, 8);
690  if (get_bits_left(gb) <= 0)
691  return AVERROR_INVALIDDATA;
692  }
693 
694  return 0;
695 }
696 
697 #endif // CACHED_BITSTREAM_READER
698 
699 #endif /* AVCODEC_GET_BITS_H */
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:261
av_clip
#define av_clip
Definition: common.h:100
show_bits_long
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:478
show_bits1
static unsigned int show_bits1(GetBitContext *s)
Definition: get_bits.h:391
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
GET_VLC
#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:557
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:404
int64_t
long long int64_t
Definition: coverity.c:34
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:249
VLC_MULTI_ELEM
Definition: vlc.h:56
GetBitContext::size_in_bits
int size_in_bits
Definition: get_bits.h:111
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
table
static const uint16_t table[]
Definition: prosumer.c:203
zero_extend
static av_const unsigned zero_extend(unsigned val, unsigned bits)
Definition: mathops.h:149
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:208
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:497
OPEN_READER_NOSIZE
#define OPEN_READER_NOSIZE(name, gb)
Definition: get_bits.h:168
GetBitContext::size_in_bits_plus8
int size_in_bits_plus8
Definition: get_bits.h:112
GET_CACHE
#define GET_CACHE(name, gb)
Definition: get_bits.h:246
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:364
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:318
GetBitContext
Definition: get_bits.h:108
get_vlc_multi
static int get_vlc_multi(GetBitContext *s, uint8_t *dst, const VLC_MULTI_ELEM *const Jtable, const VLCElem *const table, const int bits, const int max_depth, const int symbols_size)
Definition: get_bits.h:650
BitstreamContext
#define BitstreamContext
Definition: bitstream.h:109
avassert.h
get_sbits64
static int64_t get_sbits64(GetBitContext *s, int n)
Read 0-64 bits as a signed integer.
Definition: get_bits.h:466
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:528
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:184
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:243
bits
uint8_t bits
Definition: vp3data.h:128
sign_extend64
static av_const int64_t sign_extend64(int64_t val, unsigned bits)
Definition: mathops.h:140
get_bits_le
static unsigned int get_bits_le(GetBitContext *s, int n)
Definition: get_bits.h:339
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:303
decode012
static int decode012(GetBitContext *gb)
Definition: get_bits.h:660
SHOW_UBITS_LE
#define SHOW_UBITS_LE(name, gb, num)
Definition: get_bits.h:232
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:109
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
NULL
#define NULL
Definition: coverity.c:32
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:371
mathops.h
LAST_SKIP_BITS
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:230
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:635
index
int index
Definition: gxfenc.c:90
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
VLCElem
Definition: vlc.h:32
GetBitContext::index
int index
Definition: get_bits.h:110
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:173
get_xbits
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
Definition: get_bits.h:275
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:396
get_bits64
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
Definition: get_bits.h:436
NEG_USR32
#define NEG_USR32(a, s)
Definition: mathops.h:176
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:354
av_builtin_constant_p
#define av_builtin_constant_p
Definition: attributes.h:160
common.h
MIN_CACHE_BITS
#define MIN_CACHE_BITS
Definition: get_bits.h:166
av_always_inline
#define av_always_inline
Definition: attributes.h:49
GetBitContext::buffer_end
const uint8_t * buffer_end
Definition: get_bits.h:109
bitstream.h
get_xbits_le
static int get_xbits_le(GetBitContext *s, int n)
Definition: get_bits.h:289
ret
ret
Definition: filter_design.txt:187
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:544
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
skip_1stop_8data_bits
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:683
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:242
UPDATE_CACHE_LE
#define UPDATE_CACHE_LE(name, gb)
Definition: get_bits.h:196
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
defs.h
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:131
decode210
static int decode210(GetBitContext *gb)
Definition: get_bits.h:670
UPDATE_CACHE_32
#define UPDATE_CACHE_32(name, gb)
Definition: get_bits.h:209
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:334
init_get_bits8_le
static int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer, int byte_size)
Definition: get_bits.h:536
vlc.h
int32_t
int32_t
Definition: audioconvert.c:56
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
get_sbits_long
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:454