You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

699 lines
22KB

  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. * @file
  22. * bitstream reader API header.
  23. */
  24. #ifndef AVCODEC_GET_BITS_H
  25. #define AVCODEC_GET_BITS_H
  26. #include <stdint.h>
  27. #include "libavutil/common.h"
  28. #include "libavutil/intreadwrite.h"
  29. #include "libavutil/log.h"
  30. #include "libavutil/avassert.h"
  31. #include "avcodec.h"
  32. #include "mathops.h"
  33. /*
  34. * Safe bitstream reading:
  35. * optionally, the get_bits API can check to ensure that we
  36. * don't read past input buffer boundaries. This is protected
  37. * with CONFIG_SAFE_BITSTREAM_READER at the global level, and
  38. * then below that with UNCHECKED_BITSTREAM_READER at the per-
  39. * decoder level. This means that decoders that check internally
  40. * can "#define UNCHECKED_BITSTREAM_READER 1" to disable
  41. * overread checks.
  42. * Boundary checking causes a minor performance penalty so for
  43. * applications that won't want/need this, it can be disabled
  44. * globally using "#define CONFIG_SAFE_BITSTREAM_READER 0".
  45. */
  46. #ifndef UNCHECKED_BITSTREAM_READER
  47. #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
  48. #endif
  49. typedef struct GetBitContext {
  50. const uint8_t *buffer, *buffer_end;
  51. int index;
  52. int size_in_bits;
  53. int size_in_bits_plus8;
  54. } GetBitContext;
  55. #define VLC_TYPE int16_t
  56. typedef struct VLC {
  57. int bits;
  58. VLC_TYPE (*table)[2]; ///< code, bits
  59. int table_size, table_allocated;
  60. } VLC;
  61. typedef struct RL_VLC_ELEM {
  62. int16_t level;
  63. int8_t len;
  64. uint8_t run;
  65. } RL_VLC_ELEM;
  66. /* Bitstream reader API docs:
  67. * name
  68. * arbitrary name which is used as prefix for the internal variables
  69. *
  70. * gb
  71. * getbitcontext
  72. *
  73. * OPEN_READER(name, gb)
  74. * load gb into local variables
  75. *
  76. * CLOSE_READER(name, gb)
  77. * store local vars in gb
  78. *
  79. * UPDATE_CACHE(name, gb)
  80. * Refill the internal cache from the bitstream.
  81. * After this call at least MIN_CACHE_BITS will be available.
  82. *
  83. * GET_CACHE(name, gb)
  84. * Will output the contents of the internal cache,
  85. * next bit is MSB of 32 or 64 bit (FIXME 64bit).
  86. *
  87. * SHOW_UBITS(name, gb, num)
  88. * Will return the next num bits.
  89. *
  90. * SHOW_SBITS(name, gb, num)
  91. * Will return the next num bits and do sign extension.
  92. *
  93. * SKIP_BITS(name, gb, num)
  94. * Will skip over the next num bits.
  95. * Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER.
  96. *
  97. * SKIP_CACHE(name, gb, num)
  98. * Will remove the next num bits from the cache (note SKIP_COUNTER
  99. * MUST be called before UPDATE_CACHE / CLOSE_READER).
  100. *
  101. * SKIP_COUNTER(name, gb, num)
  102. * Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS).
  103. *
  104. * LAST_SKIP_BITS(name, gb, num)
  105. * Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER.
  106. *
  107. * BITS_LEFT(name, gb)
  108. * Return the number of bits left
  109. *
  110. * For examples see get_bits, show_bits, skip_bits, get_vlc.
  111. */
  112. #ifdef LONG_BITSTREAM_READER
  113. # define MIN_CACHE_BITS 32
  114. #else
  115. # define MIN_CACHE_BITS 25
  116. #endif
  117. #define OPEN_READER_NOSIZE(name, gb) \
  118. unsigned int name ## _index = (gb)->index; \
  119. unsigned int av_unused name ## _cache
  120. #if UNCHECKED_BITSTREAM_READER
  121. #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb)
  122. #define BITS_AVAILABLE(name, gb) 1
  123. #else
  124. #define OPEN_READER(name, gb) \
  125. OPEN_READER_NOSIZE(name, gb); \
  126. unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8
  127. #define BITS_AVAILABLE(name, gb) name ## _index < name ## _size_plus8
  128. #endif
  129. #define CLOSE_READER(name, gb) (gb)->index = name ## _index
  130. # ifdef LONG_BITSTREAM_READER
  131. # define UPDATE_CACHE_LE(name, gb) name ## _cache = \
  132. AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7)
  133. # define UPDATE_CACHE_BE(name, gb) name ## _cache = \
  134. AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7))
  135. #else
  136. # define UPDATE_CACHE_LE(name, gb) name ## _cache = \
  137. AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7)
  138. # define UPDATE_CACHE_BE(name, gb) name ## _cache = \
  139. AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7)
  140. #endif
  141. #ifdef BITSTREAM_READER_LE
  142. # define UPDATE_CACHE(name, gb) UPDATE_CACHE_LE(name, gb)
  143. # define SKIP_CACHE(name, gb, num) name ## _cache >>= (num)
  144. #else
  145. # define UPDATE_CACHE(name, gb) UPDATE_CACHE_BE(name, gb)
  146. # define SKIP_CACHE(name, gb, num) name ## _cache <<= (num)
  147. #endif
  148. #if UNCHECKED_BITSTREAM_READER
  149. # define SKIP_COUNTER(name, gb, num) name ## _index += (num)
  150. #else
  151. # define SKIP_COUNTER(name, gb, num) \
  152. name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num))
  153. #endif
  154. #define BITS_LEFT(name, gb) ((int)((gb)->size_in_bits - name ## _index))
  155. #define SKIP_BITS(name, gb, num) \
  156. do { \
  157. SKIP_CACHE(name, gb, num); \
  158. SKIP_COUNTER(name, gb, num); \
  159. } while (0)
  160. #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
  161. #define SHOW_UBITS_LE(name, gb, num) zero_extend(name ## _cache, num)
  162. #define SHOW_SBITS_LE(name, gb, num) sign_extend(name ## _cache, num)
  163. #define SHOW_UBITS_BE(name, gb, num) NEG_USR32(name ## _cache, num)
  164. #define SHOW_SBITS_BE(name, gb, num) NEG_SSR32(name ## _cache, num)
  165. #ifdef BITSTREAM_READER_LE
  166. # define SHOW_UBITS(name, gb, num) SHOW_UBITS_LE(name, gb, num)
  167. # define SHOW_SBITS(name, gb, num) SHOW_SBITS_LE(name, gb, num)
  168. #else
  169. # define SHOW_UBITS(name, gb, num) SHOW_UBITS_BE(name, gb, num)
  170. # define SHOW_SBITS(name, gb, num) SHOW_SBITS_BE(name, gb, num)
  171. #endif
  172. #define GET_CACHE(name, gb) ((uint32_t) name ## _cache)
  173. static inline int get_bits_count(const GetBitContext *s)
  174. {
  175. return s->index;
  176. }
  177. static inline void skip_bits_long(GetBitContext *s, int n)
  178. {
  179. #if UNCHECKED_BITSTREAM_READER
  180. s->index += n;
  181. #else
  182. s->index += av_clip(n, -s->index, s->size_in_bits_plus8 - s->index);
  183. #endif
  184. }
  185. /**
  186. * read mpeg1 dc style vlc (sign bit + mantissa with no MSB).
  187. * if MSB not set it is negative
  188. * @param n length in bits
  189. */
  190. static inline int get_xbits(GetBitContext *s, int n)
  191. {
  192. register int sign;
  193. register int32_t cache;
  194. OPEN_READER(re, s);
  195. av_assert2(n>0 && n<=25);
  196. UPDATE_CACHE(re, s);
  197. cache = GET_CACHE(re, s);
  198. sign = ~cache >> 31;
  199. LAST_SKIP_BITS(re, s, n);
  200. CLOSE_READER(re, s);
  201. return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
  202. }
  203. static inline int get_sbits(GetBitContext *s, int n)
  204. {
  205. register int tmp;
  206. OPEN_READER(re, s);
  207. av_assert2(n>0 && n<=25);
  208. UPDATE_CACHE(re, s);
  209. tmp = SHOW_SBITS(re, s, n);
  210. LAST_SKIP_BITS(re, s, n);
  211. CLOSE_READER(re, s);
  212. return tmp;
  213. }
  214. /**
  215. * Read 1-25 bits.
  216. */
  217. static inline unsigned int get_bits(GetBitContext *s, int n)
  218. {
  219. register int tmp;
  220. OPEN_READER(re, s);
  221. av_assert2(n>0 && n<=25);
  222. UPDATE_CACHE(re, s);
  223. tmp = SHOW_UBITS(re, s, n);
  224. LAST_SKIP_BITS(re, s, n);
  225. CLOSE_READER(re, s);
  226. return tmp;
  227. }
  228. static inline unsigned int get_bits_le(GetBitContext *s, int n)
  229. {
  230. register int tmp;
  231. OPEN_READER(re, s);
  232. av_assert2(n>0 && n<=25);
  233. UPDATE_CACHE_LE(re, s);
  234. tmp = SHOW_UBITS_LE(re, s, n);
  235. LAST_SKIP_BITS(re, s, n);
  236. CLOSE_READER(re, s);
  237. return tmp;
  238. }
  239. /**
  240. * Show 1-25 bits.
  241. */
  242. static inline unsigned int show_bits(GetBitContext *s, int n)
  243. {
  244. register int tmp;
  245. OPEN_READER_NOSIZE(re, s);
  246. av_assert2(n>0 && n<=25);
  247. UPDATE_CACHE(re, s);
  248. tmp = SHOW_UBITS(re, s, n);
  249. return tmp;
  250. }
  251. static inline void skip_bits(GetBitContext *s, int n)
  252. {
  253. OPEN_READER(re, s);
  254. LAST_SKIP_BITS(re, s, n);
  255. CLOSE_READER(re, s);
  256. }
  257. static inline unsigned int get_bits1(GetBitContext *s)
  258. {
  259. unsigned int index = s->index;
  260. uint8_t result = s->buffer[index >> 3];
  261. #ifdef BITSTREAM_READER_LE
  262. result >>= index & 7;
  263. result &= 1;
  264. #else
  265. result <<= index & 7;
  266. result >>= 8 - 1;
  267. #endif
  268. #if !UNCHECKED_BITSTREAM_READER
  269. if (s->index < s->size_in_bits_plus8)
  270. #endif
  271. index++;
  272. s->index = index;
  273. return result;
  274. }
  275. static inline unsigned int show_bits1(GetBitContext *s)
  276. {
  277. return show_bits(s, 1);
  278. }
  279. static inline void skip_bits1(GetBitContext *s)
  280. {
  281. skip_bits(s, 1);
  282. }
  283. /**
  284. * Read 0-32 bits.
  285. */
  286. static inline unsigned int get_bits_long(GetBitContext *s, int n)
  287. {
  288. if (!n) {
  289. return 0;
  290. } else if (n <= MIN_CACHE_BITS) {
  291. return get_bits(s, n);
  292. } else {
  293. #ifdef BITSTREAM_READER_LE
  294. unsigned ret = get_bits(s, 16);
  295. return ret | (get_bits(s, n - 16) << 16);
  296. #else
  297. unsigned ret = get_bits(s, 16) << (n - 16);
  298. return ret | get_bits(s, n - 16);
  299. #endif
  300. }
  301. }
  302. /**
  303. * Read 0-64 bits.
  304. */
  305. static inline uint64_t get_bits64(GetBitContext *s, int n)
  306. {
  307. if (n <= 32) {
  308. return get_bits_long(s, n);
  309. } else {
  310. #ifdef BITSTREAM_READER_LE
  311. uint64_t ret = get_bits_long(s, 32);
  312. return ret | (uint64_t) get_bits_long(s, n - 32) << 32;
  313. #else
  314. uint64_t ret = (uint64_t) get_bits_long(s, n - 32) << 32;
  315. return ret | get_bits_long(s, 32);
  316. #endif
  317. }
  318. }
  319. /**
  320. * Read 0-32 bits as a signed integer.
  321. */
  322. static inline int get_sbits_long(GetBitContext *s, int n)
  323. {
  324. // sign_extend(x, 0) is undefined
  325. if (!n)
  326. return 0;
  327. return sign_extend(get_bits_long(s, n), n);
  328. }
  329. /**
  330. * Show 0-32 bits.
  331. */
  332. static inline unsigned int show_bits_long(GetBitContext *s, int n)
  333. {
  334. if (n <= MIN_CACHE_BITS) {
  335. return show_bits(s, n);
  336. } else {
  337. GetBitContext gb = *s;
  338. return get_bits_long(&gb, n);
  339. }
  340. }
  341. static inline int check_marker(GetBitContext *s, const char *msg)
  342. {
  343. int bit = get_bits1(s);
  344. if (!bit)
  345. 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);
  346. return bit;
  347. }
  348. /**
  349. * Initialize GetBitContext.
  350. * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
  351. * larger than the actual read bits because some optimized bitstream
  352. * readers read 32 or 64 bit at once and could read over the end
  353. * @param bit_size the size of the buffer in bits
  354. * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
  355. */
  356. static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
  357. int bit_size)
  358. {
  359. int buffer_size;
  360. int ret = 0;
  361. if (bit_size >= INT_MAX - FFMAX(7, AV_INPUT_BUFFER_PADDING_SIZE*8) || bit_size < 0 || !buffer) {
  362. bit_size = 0;
  363. buffer = NULL;
  364. ret = AVERROR_INVALIDDATA;
  365. }
  366. buffer_size = (bit_size + 7) >> 3;
  367. s->buffer = buffer;
  368. s->size_in_bits = bit_size;
  369. s->size_in_bits_plus8 = bit_size + 8;
  370. s->buffer_end = buffer + buffer_size;
  371. s->index = 0;
  372. return ret;
  373. }
  374. /**
  375. * Initialize GetBitContext.
  376. * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
  377. * larger than the actual read bits because some optimized bitstream
  378. * readers read 32 or 64 bit at once and could read over the end
  379. * @param byte_size the size of the buffer in bytes
  380. * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
  381. */
  382. static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
  383. int byte_size)
  384. {
  385. if (byte_size > INT_MAX / 8 || byte_size < 0)
  386. byte_size = -1;
  387. return init_get_bits(s, buffer, byte_size * 8);
  388. }
  389. static inline const uint8_t *align_get_bits(GetBitContext *s)
  390. {
  391. int n = -get_bits_count(s) & 7;
  392. if (n)
  393. skip_bits(s, n);
  394. return s->buffer + (s->index >> 3);
  395. }
  396. #define init_vlc(vlc, nb_bits, nb_codes, \
  397. bits, bits_wrap, bits_size, \
  398. codes, codes_wrap, codes_size, \
  399. flags) \
  400. ff_init_vlc_sparse(vlc, nb_bits, nb_codes, \
  401. bits, bits_wrap, bits_size, \
  402. codes, codes_wrap, codes_size, \
  403. NULL, 0, 0, flags)
  404. int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
  405. const void *bits, int bits_wrap, int bits_size,
  406. const void *codes, int codes_wrap, int codes_size,
  407. const void *symbols, int symbols_wrap, int symbols_size,
  408. int flags);
  409. void ff_free_vlc(VLC *vlc);
  410. #define INIT_VLC_LE 2
  411. #define INIT_VLC_USE_NEW_STATIC 4
  412. #define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \
  413. do { \
  414. static VLC_TYPE table[static_size][2]; \
  415. (vlc)->table = table; \
  416. (vlc)->table_allocated = static_size; \
  417. init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \
  418. } while (0)
  419. /**
  420. * If the vlc code is invalid and max_depth=1, then no bits will be removed.
  421. * If the vlc code is invalid and max_depth>1, then the number of bits removed
  422. * is undefined.
  423. */
  424. #define GET_VLC(code, name, gb, table, bits, max_depth) \
  425. do { \
  426. int n, nb_bits; \
  427. unsigned int index; \
  428. \
  429. index = SHOW_UBITS(name, gb, bits); \
  430. code = table[index][0]; \
  431. n = table[index][1]; \
  432. \
  433. if (max_depth > 1 && n < 0) { \
  434. LAST_SKIP_BITS(name, gb, bits); \
  435. UPDATE_CACHE(name, gb); \
  436. \
  437. nb_bits = -n; \
  438. \
  439. index = SHOW_UBITS(name, gb, nb_bits) + code; \
  440. code = table[index][0]; \
  441. n = table[index][1]; \
  442. if (max_depth > 2 && n < 0) { \
  443. LAST_SKIP_BITS(name, gb, nb_bits); \
  444. UPDATE_CACHE(name, gb); \
  445. \
  446. nb_bits = -n; \
  447. \
  448. index = SHOW_UBITS(name, gb, nb_bits) + code; \
  449. code = table[index][0]; \
  450. n = table[index][1]; \
  451. } \
  452. } \
  453. SKIP_BITS(name, gb, n); \
  454. } while (0)
  455. #define GET_RL_VLC_INTERNAL(level, run, name, gb, table, bits, \
  456. max_depth, need_update) \
  457. do { \
  458. int n, nb_bits; \
  459. unsigned int index; \
  460. \
  461. index = SHOW_UBITS(name, gb, bits); \
  462. level = table[index].level; \
  463. n = table[index].len; \
  464. \
  465. if (max_depth > 1 && n < 0) { \
  466. SKIP_BITS(name, gb, bits); \
  467. if (need_update) { \
  468. UPDATE_CACHE(name, gb); \
  469. } \
  470. \
  471. nb_bits = -n; \
  472. \
  473. index = SHOW_UBITS(name, gb, nb_bits) + level; \
  474. level = table[index].level; \
  475. n = table[index].len; \
  476. } \
  477. run = table[index].run; \
  478. SKIP_BITS(name, gb, n); \
  479. } while (0)
  480. /**
  481. * Parse a vlc code.
  482. * @param bits is the number of bits which will be read at once, must be
  483. * identical to nb_bits in init_vlc()
  484. * @param max_depth is the number of times bits bits must be read to completely
  485. * read the longest vlc code
  486. * = (max_vlc_length + bits - 1) / bits
  487. * @returns the code parsed or -1 if no vlc matches
  488. */
  489. static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
  490. int bits, int max_depth)
  491. {
  492. int code;
  493. OPEN_READER(re, s);
  494. UPDATE_CACHE(re, s);
  495. GET_VLC(code, re, s, table, bits, max_depth);
  496. CLOSE_READER(re, s);
  497. return code;
  498. }
  499. static inline int decode012(GetBitContext *gb)
  500. {
  501. int n;
  502. n = get_bits1(gb);
  503. if (n == 0)
  504. return 0;
  505. else
  506. return get_bits1(gb) + 1;
  507. }
  508. static inline int decode210(GetBitContext *gb)
  509. {
  510. if (get_bits1(gb))
  511. return 0;
  512. else
  513. return 2 - get_bits1(gb);
  514. }
  515. static inline int get_bits_left(GetBitContext *gb)
  516. {
  517. return gb->size_in_bits - get_bits_count(gb);
  518. }
  519. static inline int skip_1stop_8data_bits(GetBitContext *gb)
  520. {
  521. if (get_bits_left(gb) <= 0)
  522. return AVERROR_INVALIDDATA;
  523. while (get_bits1(gb)) {
  524. skip_bits(gb, 8);
  525. if (get_bits_left(gb) <= 0)
  526. return AVERROR_INVALIDDATA;
  527. }
  528. return 0;
  529. }
  530. //#define TRACE
  531. #ifdef TRACE
  532. static inline void print_bin(int bits, int n)
  533. {
  534. int i;
  535. for (i = n - 1; i >= 0; i--)
  536. av_log(NULL, AV_LOG_DEBUG, "%d", (bits >> i) & 1);
  537. for (i = n; i < 24; i++)
  538. av_log(NULL, AV_LOG_DEBUG, " ");
  539. }
  540. static inline int get_bits_trace(GetBitContext *s, int n, const char *file,
  541. const char *func, int line)
  542. {
  543. int r = get_bits(s, n);
  544. print_bin(r, n);
  545. av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n",
  546. r, n, r, get_bits_count(s) - n, file, func, line);
  547. return r;
  548. }
  549. static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2],
  550. int bits, int max_depth, const char *file,
  551. const char *func, int line)
  552. {
  553. int show = show_bits(s, 24);
  554. int pos = get_bits_count(s);
  555. int r = get_vlc2(s, table, bits, max_depth);
  556. int len = get_bits_count(s) - pos;
  557. int bits2 = show >> (24 - len);
  558. print_bin(bits2, len);
  559. av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n",
  560. bits2, len, r, pos, file, func, line);
  561. return r;
  562. }
  563. #define GET_RL_VLC(level, run, name, gb, table, bits, \
  564. max_depth, need_update) \
  565. do { \
  566. int show = SHOW_UBITS(name, gb, 24); \
  567. int len; \
  568. int pos = name ## _index; \
  569. \
  570. GET_RL_VLC_INTERNAL(level, run, name, gb, table, bits,max_depth, need_update); \
  571. \
  572. len = name ## _index - pos + 1; \
  573. show = show >> (24 - len); \
  574. \
  575. print_bin(show, len); \
  576. \
  577. av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d/%-3d rlv @%5d in %s %s:%d\n",\
  578. show, len, run-1, level, pos, __FILE__, __PRETTY_FUNCTION__, __LINE__);\
  579. } while (0) \
  580. static inline int get_xbits_trace(GetBitContext *s, int n, const char *file,
  581. const char *func, int line)
  582. {
  583. int show = show_bits(s, n);
  584. int r = get_xbits(s, n);
  585. print_bin(show, n);
  586. av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n",
  587. show, n, r, get_bits_count(s) - n, file, func, line);
  588. return r;
  589. }
  590. #define get_bits(s, n) get_bits_trace(s , n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
  591. #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
  592. #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
  593. #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
  594. #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
  595. #else //TRACE
  596. #define GET_RL_VLC GET_RL_VLC_INTERNAL
  597. #endif
  598. #endif /* AVCODEC_GET_BITS_H */