FFmpeg
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 
97 #define init_get_bits8_le(s, buffer, byte_size) bits_init8_le((BitstreamContextLE*)s, buffer, byte_size)
98 #define get_bits_le(s, n) bits_read_le((BitstreamContextLE*)s, n)
99 
100 #define show_bits1(s) bits_peek(s, 1)
101 #define skip_bits1(s) bits_skip(s, 1)
102 
103 #define skip_1stop_8data_bits bits_skip_1stop_8data
104 
105 #else // CACHED_BITSTREAM_READER
106 
107 typedef struct GetBitContext {
108  const uint8_t *buffer, *buffer_end;
109  int index;
112 } GetBitContext;
113 
114 static inline unsigned int get_bits(GetBitContext *s, int n);
115 static inline void skip_bits(GetBitContext *s, int n);
116 static inline unsigned int show_bits(GetBitContext *s, int n);
117 
118 /* Bitstream reader API docs:
119  * name
120  * arbitrary name which is used as prefix for the internal variables
121  *
122  * gb
123  * getbitcontext
124  *
125  * OPEN_READER(name, gb)
126  * load gb into local variables
127  *
128  * CLOSE_READER(name, gb)
129  * store local vars in gb
130  *
131  * UPDATE_CACHE(name, gb)
132  * Refill the internal cache from the bitstream.
133  * After this call at least MIN_CACHE_BITS will be available.
134  *
135  * GET_CACHE(name, gb)
136  * Will output the contents of the internal cache,
137  * next bit is MSB of 32 or 64 bits (FIXME 64 bits).
138  *
139  * SHOW_UBITS(name, gb, num)
140  * Will return the next num bits.
141  *
142  * SHOW_SBITS(name, gb, num)
143  * Will return the next num bits and do sign extension.
144  *
145  * SKIP_BITS(name, gb, num)
146  * Will skip over the next num bits.
147  * Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER.
148  *
149  * SKIP_CACHE(name, gb, num)
150  * Will remove the next num bits from the cache (note SKIP_COUNTER
151  * MUST be called before UPDATE_CACHE / CLOSE_READER).
152  *
153  * SKIP_COUNTER(name, gb, num)
154  * Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS).
155  *
156  * LAST_SKIP_BITS(name, gb, num)
157  * Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER.
158  *
159  * BITS_LEFT(name, gb)
160  * Return the number of bits left
161  *
162  * For examples see get_bits, show_bits, skip_bits, get_vlc.
163  */
164 
165 #if defined LONG_BITSTREAM_READER
166 # define MIN_CACHE_BITS 32
167 #else
168 # define MIN_CACHE_BITS 25
169 #endif
170 
171 #define OPEN_READER_NOSIZE(name, gb) \
172  unsigned int name ## _index = (gb)->index; \
173  unsigned int av_unused name ## _cache
174 
175 #if UNCHECKED_BITSTREAM_READER
176 #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb)
177 
178 #define BITS_AVAILABLE(name, gb) 1
179 #else
180 #define OPEN_READER(name, gb) \
181  OPEN_READER_NOSIZE(name, gb); \
182  unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8
183 
184 #define BITS_AVAILABLE(name, gb) name ## _index < name ## _size_plus8
185 #endif
186 
187 #define CLOSE_READER(name, gb) (gb)->index = name ## _index
188 
189 # ifdef LONG_BITSTREAM_READER
190 
191 # define UPDATE_CACHE_LE(name, gb) name ## _cache = \
192  AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7)
193 
194 # define UPDATE_CACHE_BE(name, gb) name ## _cache = \
195  AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7))
196 
197 #else
198 
199 # define UPDATE_CACHE_LE(name, gb) name ## _cache = \
200  AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7)
201 
202 # define UPDATE_CACHE_BE(name, gb) name ## _cache = \
203  AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7)
204 
205 #endif
206 
207 
208 #ifdef BITSTREAM_READER_LE
209 
210 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_LE(name, gb)
211 
212 # define SKIP_CACHE(name, gb, num) name ## _cache >>= (num)
213 
214 #else
215 
216 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_BE(name, gb)
217 
218 # define SKIP_CACHE(name, gb, num) name ## _cache <<= (num)
219 
220 #endif
221 
222 #if UNCHECKED_BITSTREAM_READER
223 # define SKIP_COUNTER(name, gb, num) name ## _index += (num)
224 #else
225 # define SKIP_COUNTER(name, gb, num) \
226  name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num))
227 #endif
228 
229 #define BITS_LEFT(name, gb) ((int)((gb)->size_in_bits - name ## _index))
230 
231 #define SKIP_BITS(name, gb, num) \
232  do { \
233  SKIP_CACHE(name, gb, num); \
234  SKIP_COUNTER(name, gb, num); \
235  } while (0)
236 
237 #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
238 
239 #define SHOW_UBITS_LE(name, gb, num) zero_extend(name ## _cache, num)
240 #define SHOW_SBITS_LE(name, gb, num) sign_extend(name ## _cache, num)
241 
242 #define SHOW_UBITS_BE(name, gb, num) NEG_USR32(name ## _cache, num)
243 #define SHOW_SBITS_BE(name, gb, num) NEG_SSR32(name ## _cache, num)
244 
245 #ifdef BITSTREAM_READER_LE
246 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_LE(name, gb, num)
247 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_LE(name, gb, num)
248 #else
249 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_BE(name, gb, num)
250 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_BE(name, gb, num)
251 #endif
252 
253 #define GET_CACHE(name, gb) ((uint32_t) name ## _cache)
254 
255 
256 static inline int get_bits_count(const GetBitContext *s)
257 {
258  return s->index;
259 }
260 
261 /**
262  * Skips the specified number of bits.
263  * @param n the number of bits to skip,
264  * For the UNCHECKED_BITSTREAM_READER this must not cause the distance
265  * from the start to overflow int32_t. Staying within the bitstream + padding
266  * is sufficient, too.
267  */
268 static inline void skip_bits_long(GetBitContext *s, int n)
269 {
270 #if UNCHECKED_BITSTREAM_READER
271  s->index += n;
272 #else
273  s->index += av_clip(n, -s->index, s->size_in_bits_plus8 - s->index);
274 #endif
275 }
276 
277 /**
278  * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
279  * if MSB not set it is negative
280  * @param n length in bits
281  */
282 static inline int get_xbits(GetBitContext *s, int n)
283 {
284  register int sign;
285  register int32_t cache;
286  OPEN_READER(re, s);
287  av_assert2(n>0 && n<=25);
288  UPDATE_CACHE(re, s);
289  cache = GET_CACHE(re, s);
290  sign = ~cache >> 31;
291  LAST_SKIP_BITS(re, s, n);
292  CLOSE_READER(re, s);
293  return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
294 }
295 
296 static inline int get_xbits_le(GetBitContext *s, int n)
297 {
298  register int sign;
299  register int32_t cache;
300  OPEN_READER(re, s);
301  av_assert2(n>0 && n<=25);
302  UPDATE_CACHE_LE(re, s);
303  cache = GET_CACHE(re, s);
304  sign = sign_extend(~cache, n) >> 31;
305  LAST_SKIP_BITS(re, s, n);
306  CLOSE_READER(re, s);
307  return (zero_extend(sign ^ cache, n) ^ sign) - sign;
308 }
309 
310 static inline int get_sbits(GetBitContext *s, int n)
311 {
312  register int tmp;
313  OPEN_READER(re, s);
314  av_assert2(n>0 && n<=25);
315  UPDATE_CACHE(re, s);
316  tmp = SHOW_SBITS(re, s, n);
317  LAST_SKIP_BITS(re, s, n);
318  CLOSE_READER(re, s);
319  return tmp;
320 }
321 
322 /**
323  * Read 1-25 bits.
324  */
325 static inline unsigned int get_bits(GetBitContext *s, int n)
326 {
327  register unsigned int tmp;
328  OPEN_READER(re, s);
329  av_assert2(n>0 && n<=25);
330  UPDATE_CACHE(re, s);
331  tmp = SHOW_UBITS(re, s, n);
332  LAST_SKIP_BITS(re, s, n);
333  CLOSE_READER(re, s);
334  av_assert2(tmp < UINT64_C(1) << n);
335  return tmp;
336 }
337 
338 /**
339  * Read 0-25 bits.
340  */
342 {
343  return n ? get_bits(s, n) : 0;
344 }
345 
346 static inline unsigned int get_bits_le(GetBitContext *s, int n)
347 {
348  register int tmp;
349  OPEN_READER(re, s);
350  av_assert2(n>0 && n<=25);
351  UPDATE_CACHE_LE(re, s);
352  tmp = SHOW_UBITS_LE(re, s, n);
353  LAST_SKIP_BITS(re, s, n);
354  CLOSE_READER(re, s);
355  return tmp;
356 }
357 
358 /**
359  * Show 1-25 bits.
360  */
361 static inline unsigned int show_bits(GetBitContext *s, int n)
362 {
363  register unsigned int tmp;
365  av_assert2(n>0 && n<=25);
366  UPDATE_CACHE(re, s);
367  tmp = SHOW_UBITS(re, s, n);
368  return tmp;
369 }
370 
371 static inline void skip_bits(GetBitContext *s, int n)
372 {
373  OPEN_READER(re, s);
374  LAST_SKIP_BITS(re, s, n);
375  CLOSE_READER(re, s);
376 }
377 
378 static inline unsigned int get_bits1(GetBitContext *s)
379 {
380  unsigned int index = s->index;
381  uint8_t result = s->buffer[index >> 3];
382 #ifdef BITSTREAM_READER_LE
383  result >>= index & 7;
384  result &= 1;
385 #else
386  result <<= index & 7;
387  result >>= 8 - 1;
388 #endif
389 #if !UNCHECKED_BITSTREAM_READER
390  if (s->index < s->size_in_bits_plus8)
391 #endif
392  index++;
393  s->index = index;
394 
395  return result;
396 }
397 
398 static inline unsigned int show_bits1(GetBitContext *s)
399 {
400  return show_bits(s, 1);
401 }
402 
403 static inline void skip_bits1(GetBitContext *s)
404 {
405  skip_bits(s, 1);
406 }
407 
408 /**
409  * Read 0-32 bits.
410  */
411 static inline unsigned int get_bits_long(GetBitContext *s, int n)
412 {
413  av_assert2(n>=0 && n<=32);
414  if (!n) {
415  return 0;
416  } else if (n <= MIN_CACHE_BITS) {
417  return get_bits(s, n);
418  } else {
419 #ifdef BITSTREAM_READER_LE
420  unsigned ret = get_bits(s, 16);
421  return ret | (get_bits(s, n - 16) << 16);
422 #else
423  unsigned ret = get_bits(s, 16) << (n - 16);
424  return ret | get_bits(s, n - 16);
425 #endif
426  }
427 }
428 
429 /**
430  * Read 0-64 bits.
431  */
432 static inline uint64_t get_bits64(GetBitContext *s, int n)
433 {
434  if (n <= 32) {
435  return get_bits_long(s, n);
436  } else {
437 #ifdef BITSTREAM_READER_LE
438  uint64_t ret = get_bits_long(s, 32);
439  return ret | (uint64_t) get_bits_long(s, n - 32) << 32;
440 #else
441  uint64_t ret = (uint64_t) get_bits_long(s, n - 32) << 32;
442  return ret | get_bits_long(s, 32);
443 #endif
444  }
445 }
446 
447 /**
448  * Read 0-32 bits as a signed integer.
449  */
450 static inline int get_sbits_long(GetBitContext *s, int n)
451 {
452  // sign_extend(x, 0) is undefined
453  if (!n)
454  return 0;
455 
456  return sign_extend(get_bits_long(s, n), n);
457 }
458 
459 /**
460  * Read 0-64 bits as a signed integer.
461  */
462 static inline int64_t get_sbits64(GetBitContext *s, int n)
463 {
464  // sign_extend(x, 0) is undefined
465  if (!n)
466  return 0;
467 
468  return sign_extend64(get_bits64(s, n), n);
469 }
470 
471 /**
472  * Show 0-32 bits.
473  */
474 static inline unsigned int show_bits_long(GetBitContext *s, int n)
475 {
476  if (n <= MIN_CACHE_BITS) {
477  return show_bits(s, n);
478  } else {
479  GetBitContext gb = *s;
480  return get_bits_long(&gb, n);
481  }
482 }
483 
484 
485 /**
486  * Initialize GetBitContext.
487  * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
488  * larger than the actual read bits because some optimized bitstream
489  * readers read 32 or 64 bit at once and could read over the end
490  * @param bit_size the size of the buffer in bits
491  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
492  */
493 static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
494  int bit_size)
495 {
496  int buffer_size;
497  int ret = 0;
498 
499  if (bit_size >= INT_MAX - FFMAX(7, AV_INPUT_BUFFER_PADDING_SIZE*8) || bit_size < 0 || !buffer) {
500  bit_size = 0;
501  buffer = NULL;
503  }
504 
505  buffer_size = (bit_size + 7) >> 3;
506 
507  s->buffer = buffer;
508  s->size_in_bits = bit_size;
509  s->size_in_bits_plus8 = bit_size + 8;
510  s->buffer_end = buffer + buffer_size;
511  s->index = 0;
512 
513  return ret;
514 }
515 
516 /**
517  * Initialize GetBitContext.
518  * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
519  * larger than the actual read bits because some optimized bitstream
520  * readers read 32 or 64 bit at once and could read over the end
521  * @param byte_size the size of the buffer in bytes
522  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
523  */
524 static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
525  int byte_size)
526 {
527  if (byte_size > INT_MAX / 8 || byte_size < 0)
528  byte_size = -1;
529  return init_get_bits(s, buffer, byte_size * 8);
530 }
531 
532 static inline int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer,
533  int byte_size)
534 {
535  if (byte_size > INT_MAX / 8 || byte_size < 0)
536  byte_size = -1;
537  return init_get_bits(s, buffer, byte_size * 8);
538 }
539 
540 static inline const uint8_t *align_get_bits(GetBitContext *s)
541 {
542  int n = -get_bits_count(s) & 7;
543  if (n)
544  skip_bits(s, n);
545  return s->buffer + (s->index >> 3);
546 }
547 
548 /**
549  * If the vlc code is invalid and max_depth=1, then no bits will be removed.
550  * If the vlc code is invalid and max_depth>1, then the number of bits removed
551  * is undefined.
552  */
553 #define GET_VLC(code, name, gb, table, bits, max_depth) \
554  do { \
555  int n, nb_bits; \
556  unsigned int index; \
557  \
558  index = SHOW_UBITS(name, gb, bits); \
559  code = table[index].sym; \
560  n = table[index].len; \
561  \
562  if (max_depth > 1 && n < 0) { \
563  LAST_SKIP_BITS(name, gb, bits); \
564  UPDATE_CACHE(name, gb); \
565  \
566  nb_bits = -n; \
567  \
568  index = SHOW_UBITS(name, gb, nb_bits) + code; \
569  code = table[index].sym; \
570  n = table[index].len; \
571  if (max_depth > 2 && n < 0) { \
572  LAST_SKIP_BITS(name, gb, nb_bits); \
573  UPDATE_CACHE(name, gb); \
574  \
575  nb_bits = -n; \
576  \
577  index = SHOW_UBITS(name, gb, nb_bits) + code; \
578  code = table[index].sym; \
579  n = table[index].len; \
580  } \
581  } \
582  SKIP_BITS(name, gb, n); \
583  } while (0)
584 
585 #define GET_RL_VLC(level, run, name, gb, table, bits, \
586  max_depth, need_update) \
587  do { \
588  int n, nb_bits; \
589  unsigned int index; \
590  \
591  index = SHOW_UBITS(name, gb, bits); \
592  level = table[index].level; \
593  n = table[index].len; \
594  \
595  if (max_depth > 1 && n < 0) { \
596  SKIP_BITS(name, gb, bits); \
597  if (need_update) { \
598  UPDATE_CACHE(name, gb); \
599  } \
600  \
601  nb_bits = -n; \
602  \
603  index = SHOW_UBITS(name, gb, nb_bits) + level; \
604  level = table[index].level; \
605  n = table[index].len; \
606  if (max_depth > 2 && n < 0) { \
607  LAST_SKIP_BITS(name, gb, nb_bits); \
608  if (need_update) { \
609  UPDATE_CACHE(name, gb); \
610  } \
611  nb_bits = -n; \
612  \
613  index = SHOW_UBITS(name, gb, nb_bits) + level; \
614  level = table[index].level; \
615  n = table[index].len; \
616  } \
617  } \
618  run = table[index].run; \
619  SKIP_BITS(name, gb, n); \
620  } while (0)
621 
622 /**
623  * Parse a vlc code.
624  * @param bits is the number of bits which will be read at once, must be
625  * identical to nb_bits in init_vlc()
626  * @param max_depth is the number of times bits bits must be read to completely
627  * read the longest vlc code
628  * = (max_vlc_length + bits - 1) / bits
629  * @returns the code parsed or -1 if no vlc matches
630  */
632  int bits, int max_depth)
633 {
634  int code;
635 
636  OPEN_READER(re, s);
637  UPDATE_CACHE(re, s);
638 
639  GET_VLC(code, re, s, table, bits, max_depth);
640 
641  CLOSE_READER(re, s);
642 
643  return code;
644 }
645 
646 static inline int decode012(GetBitContext *gb)
647 {
648  int n;
649  n = get_bits1(gb);
650  if (n == 0)
651  return 0;
652  else
653  return get_bits1(gb) + 1;
654 }
655 
656 static inline int decode210(GetBitContext *gb)
657 {
658  if (get_bits1(gb))
659  return 0;
660  else
661  return 2 - get_bits1(gb);
662 }
663 
664 static inline int get_bits_left(GetBitContext *gb)
665 {
666  return gb->size_in_bits - get_bits_count(gb);
667 }
668 
669 static inline int skip_1stop_8data_bits(GetBitContext *gb)
670 {
671  if (get_bits_left(gb) <= 0)
672  return AVERROR_INVALIDDATA;
673 
674  while (get_bits1(gb)) {
675  skip_bits(gb, 8);
676  if (get_bits_left(gb) <= 0)
677  return AVERROR_INVALIDDATA;
678  }
679 
680  return 0;
681 }
682 
683 #endif // CACHED_BITSTREAM_READER
684 
685 #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:268
av_clip
#define av_clip
Definition: common.h:95
show_bits_long
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:474
show_bits1
static unsigned int show_bits1(GetBitContext *s)
Definition: get_bits.h:398
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:664
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:553
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:411
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:256
GetBitContext::size_in_bits
int size_in_bits
Definition: get_bits.h:110
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
table
static const uint16_t table[]
Definition: prosumer.c:205
zero_extend
static av_const unsigned zero_extend(unsigned val, unsigned bits)
Definition: mathops.h:151
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:216
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:493
OPEN_READER_NOSIZE
#define OPEN_READER_NOSIZE(name, gb)
Definition: get_bits.h:171
GetBitContext::size_in_bits_plus8
int size_in_bits_plus8
Definition: get_bits.h:111
GET_CACHE
#define GET_CACHE(name, gb)
Definition: get_bits.h:253
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:371
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:325
GetBitContext
Definition: get_bits.h:107
BitstreamContext
#define BitstreamContext
Definition: bitstream.h:108
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:462
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:524
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:187
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:250
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:142
get_bits_le
static unsigned int get_bits_le(GetBitContext *s, int n)
Definition: get_bits.h:346
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:310
decode012
static int decode012(GetBitContext *gb)
Definition: get_bits.h:646
SHOW_UBITS_LE
#define SHOW_UBITS_LE(name, gb, num)
Definition: get_bits.h:239
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:108
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:378
mathops.h
LAST_SKIP_BITS
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:237
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:631
index
int index
Definition: gxfenc.c:89
VLCElem
Definition: vlc.h:27
GetBitContext::index
int index
Definition: get_bits.h:109
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:176
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:282
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:403
get_bits64
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
Definition: get_bits.h:432
NEG_USR32
#define NEG_USR32(a, s)
Definition: mathops.h:178
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
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:361
common.h
MIN_CACHE_BITS
#define MIN_CACHE_BITS
Definition: get_bits.h:168
av_always_inline
#define av_always_inline
Definition: attributes.h:49
GetBitContext::buffer_end
const uint8_t * buffer_end
Definition: get_bits.h:108
bitstream.h
get_xbits_le
static int get_xbits_le(GetBitContext *s, int n)
Definition: get_bits.h:296
ret
ret
Definition: filter_design.txt:187
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:540
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:669
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:249
UPDATE_CACHE_LE
#define UPDATE_CACHE_LE(name, gb)
Definition: get_bits.h:199
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:133
decode210
static int decode210(GetBitContext *gb)
Definition: get_bits.h:656
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:341
init_get_bits8_le
static int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer, int byte_size)
Definition: get_bits.h:532
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:450
re
float re
Definition: fft.c:79