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.

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