This makes the bitstream.h header leaner.
Unified · Split
| @@ -33,7 +33,6 @@ · 32 unmodified lines | |||
| 33 | #include "libavutil/log.h" | 33 | #include "libavutil/log.h" |
| 34 | 34 | ||
| 35 | #include "mathops.h" | 35 | #include "mathops.h" |
| 36 | #include "vlc.h" | ||
| 37 | 36 | ||
| 38 | typedef struct BitstreamContext { | 37 | typedef struct BitstreamContext { |
| 39 | uint64_t bits; // stores bits read from the buffer | 38 | uint64_t bits; // stores bits read from the buffer |
| @@ -287,78 +286,6 @@ static inline int bitstream_read_xbits(BitstreamContext *bc, unsigned length) · 247 unmodified lines | |||
| 287 | return ((((uint32_t)(sign ^ cache)) >> (32 - length)) ^ sign) - sign; | 286 | return ((((uint32_t)(sign ^ cache)) >> (32 - length)) ^ sign) - sign; |
| 288 | } | 287 | } |
| 289 | 288 | ||
| 290 | /* Return the LUT element for the given bitstream configuration. */ | ||
| 291 | static inline int set_idx(BitstreamContext *bc, int code, int *n, int *nb_bits, | ||
| 292 | VLC_TYPE (*table)[2]) | ||
| 293 | { | ||
| 294 | unsigned idx; | ||
| 295 | |||
| 296 | *nb_bits = -*n; | ||
| 297 | idx = bitstream_peek(bc, *nb_bits) + code; | ||
| 298 | *n = table[idx][1]; | ||
| 299 | |||
| 300 | return table[idx][0]; | ||
| 301 | } | ||
| 302 | |||
| 303 | /** | ||
| 304 | * Parse a VLC code. | ||
| 305 | * @param bits is the number of bits which will be read at once, must be | ||
| 306 | * identical to nb_bits in init_vlc() | ||
| 307 | * @param max_depth is the number of times bits bits must be read to completely | ||
| 308 | * read the longest VLC code | ||
| 309 | * = (max_vlc_length + bits - 1) / bits | ||
| 310 | * If the VLC code is invalid and max_depth = 1, then no bits will be removed. | ||
| 311 | * If the VLC code is invalid and max_depth > 1, then the number of bits removed | ||
| 312 | * is undefined. */ | ||
| 313 | static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2], | ||
| 314 | int bits, int max_depth) | ||
| 315 | { | ||
| 316 | int nb_bits; | ||
| 317 | unsigned idx = bitstream_peek(bc, bits); | ||
| 318 | int code = table[idx][0]; | ||
| 319 | int n = table[idx][1]; | ||
| 320 | |||
| 321 | if (max_depth > 1 && n < 0) { | ||
| 322 | skip_remaining(bc, bits); | ||
| 323 | code = set_idx(bc, code, &n, &nb_bits, table); | ||
| 324 | if (max_depth > 2 && n < 0) { | ||
| 325 | skip_remaining(bc, nb_bits); | ||
| 326 | code = set_idx(bc, code, &n, &nb_bits, table); | ||
| 327 | } | ||
| 328 | } | ||
| 329 | skip_remaining(bc, n); | ||
| 330 | |||
| 331 | return code; | ||
| 332 | } | ||
| 333 | |||
| 334 | #define BITSTREAM_RL_VLC(level, run, bc, table, bits, max_depth) \ | ||
| 335 | do { \ | ||
| 336 | int n, nb_bits; \ | ||
| 337 | unsigned index = bitstream_peek(bc, bits); \ | ||
| 338 | level = table[index].level; \ | ||
| 339 | n = table[index].len; \ | ||
| 340 | \ | ||
| 341 | if (max_depth > 1 && n < 0) { \ | ||
| 342 | bitstream_skip(bc, bits); \ | ||
| 343 | \ | ||
| 344 | nb_bits = -n; \ | ||
| 345 | \ | ||
| 346 | index = bitstream_peek(bc, nb_bits) + level; \ | ||
| 347 | level = table[index].level; \ | ||
| 348 | n = table[index].len; \ | ||
| 349 | if (max_depth > 2 && n < 0) { \ | ||
| 350 | bitstream_skip(bc, nb_bits); \ | ||
| 351 | nb_bits = -n; \ | ||
| 352 | \ | ||
| 353 | index = bitstream_peek(bc, nb_bits) + level; \ | ||
| 354 | level = table[index].level; \ | ||
| 355 | n = table[index].len; \ | ||
| 356 | } \ | ||
| 357 | } \ | ||
| 358 | run = table[index].run; \ | ||
| 359 | bitstream_skip(bc, n); \ | ||
| 360 | } while (0) | ||
| 361 | |||
| 362 | /* Return decoded truncated unary code for the values 0, 1, 2. */ | 289 | /* Return decoded truncated unary code for the values 0, 1, 2. */ |
| 363 | static inline int bitstream_decode012(BitstreamContext *bc) | 290 | static inline int bitstream_decode012(BitstreamContext *bc) |
| 364 | { | 291 | { |
| @@ -21,6 +21,8 @@ · 20 unmodified lines | |||
| 21 | 21 | ||
| 22 | #include <stdint.h> | 22 | #include <stdint.h> |
| 23 | 23 | ||
| 24 | #include "bitstream.h" | ||
| 25 | |||
| 24 | #define VLC_TYPE int16_t | 26 | #define VLC_TYPE int16_t |
| 25 | 27 | ||
| 26 | typedef struct VLC { | 28 | typedef struct VLC { |
| @@ -62,4 +64,76 @@ void ff_free_vlc(VLC *vlc); · 35 unmodified lines | |||
| 62 | init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \ | 64 | init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \ |
| 63 | } while (0) | 65 | } while (0) |
| 64 | 66 | ||
| 67 | /* Return the LUT element for the given bitstream configuration. */ | ||
| 68 | static inline int set_idx(BitstreamContext *bc, int code, int *n, int *nb_bits, | ||
| 69 | VLC_TYPE (*table)[2]) | ||
| 70 | { | ||
| 71 | unsigned idx; | ||
| 72 | |||
| 73 | *nb_bits = -*n; | ||
| 74 | idx = bitstream_peek(bc, *nb_bits) + code; | ||
| 75 | *n = table[idx][1]; | ||
| 76 | |||
| 77 | return table[idx][0]; | ||
| 78 | } | ||
| 79 | |||
| 80 | /** | ||
| 81 | * Parse a VLC code. | ||
| 82 | * @param bits is the number of bits which will be read at once, must be | ||
| 83 | * identical to nb_bits in init_vlc() | ||
| 84 | * @param max_depth is the number of times bits bits must be read to completely | ||
| 85 | * read the longest VLC code | ||
| 86 | * = (max_vlc_length + bits - 1) / bits | ||
| 87 | * If the VLC code is invalid and max_depth = 1, then no bits will be removed. | ||
| 88 | * If the VLC code is invalid and max_depth > 1, then the number of bits removed | ||
| 89 | * is undefined. */ | ||
| 90 | static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2], | ||
| 91 | int bits, int max_depth) | ||
| 92 | { | ||
| 93 | int nb_bits; | ||
| 94 | unsigned idx = bitstream_peek(bc, bits); | ||
| 95 | int code = table[idx][0]; | ||
| 96 | int n = table[idx][1]; | ||
| 97 | |||
| 98 | if (max_depth > 1 && n < 0) { | ||
| 99 | skip_remaining(bc, bits); | ||
| 100 | code = set_idx(bc, code, &n, &nb_bits, table); | ||
| 101 | if (max_depth > 2 && n < 0) { | ||
| 102 | skip_remaining(bc, nb_bits); | ||
| 103 | code = set_idx(bc, code, &n, &nb_bits, table); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | skip_remaining(bc, n); | ||
| 107 | |||
| 108 | return code; | ||
| 109 | } | ||
| 110 | |||
| 111 | #define BITSTREAM_RL_VLC(level, run, bc, table, bits, max_depth) \ | ||
| 112 | do { \ | ||
| 113 | int n, nb_bits; \ | ||
| 114 | unsigned index = bitstream_peek(bc, bits); \ | ||
| 115 | level = table[index].level; \ | ||
| 116 | n = table[index].len; \ | ||
| 117 | \ | ||
| 118 | if (max_depth > 1 && n < 0) { \ | ||
| 119 | bitstream_skip(bc, bits); \ | ||
| 120 | \ | ||
| 121 | nb_bits = -n; \ | ||
| 122 | \ | ||
| 123 | index = bitstream_peek(bc, nb_bits) + level; \ | ||
| 124 | level = table[index].level; \ | ||
| 125 | n = table[index].len; \ | ||
| 126 | if (max_depth > 2 && n < 0) { \ | ||
| 127 | bitstream_skip(bc, nb_bits); \ | ||
| 128 | nb_bits = -n; \ | ||
| 129 | \ | ||
| 130 | index = bitstream_peek(bc, nb_bits) + level; \ | ||
| 131 | level = table[index].level; \ | ||
| 132 | n = table[index].len; \ | ||
| 133 | } \ | ||
| 134 | } \ | ||
| 135 | run = table[index].run; \ | ||
| 136 | bitstream_skip(bc, n); \ | ||
| 137 | } while (0) | ||
| 138 | |||
| 65 | #endif /* AVCODEC_VLC_H */ | 139 | #endif /* AVCODEC_VLC_H */ |