Use the newly created vlc.h directly instead of including get_bits when needed. The VLC and RL_VLC_ELEM structures are independent from the bitreader.
Unified · Split
| @@ -31,8 +31,8 @@ · 30 unmodified lines | |||
| 31 | #include "avcodec.h" | 31 | #include "avcodec.h" |
| 32 | #include "internal.h" | 32 | #include "internal.h" |
| 33 | #include "mathops.h" | 33 | #include "mathops.h" |
| 34 | #include "get_bits.h" | ||
| 35 | #include "put_bits.h" | 34 | #include "put_bits.h" |
| 35 | #include "vlc.h" | ||
| 36 | 36 | ||
| 37 | const uint8_t ff_log2_run[41]={ | 37 | const uint8_t ff_log2_run[41]={ |
| 38 | 0, 0, 0, 0, 1, 1, 1, 1, | 38 | 0, 0, 0, 0, 1, 1, 1, 1, |
| @@ -32,6 +32,7 @@ · 31 unmodified lines | |||
| 32 | #include "libavutil/intreadwrite.h" | 32 | #include "libavutil/intreadwrite.h" |
| 33 | #include "libavutil/log.h" | 33 | #include "libavutil/log.h" |
| 34 | #include "mathops.h" | 34 | #include "mathops.h" |
| 35 | #include "vlc.h" | ||
| 35 | 36 | ||
| 36 | /* | 37 | /* |
| 37 | * Safe bitstream reading: | 38 | * Safe bitstream reading: |
| @@ -59,20 +60,6 @@ typedef struct GetBitContext { · 21 unmodified lines | |||
| 59 | #endif | 60 | #endif |
| 60 | } GetBitContext; | 61 | } GetBitContext; |
| 61 | 62 | ||
| 62 | #define VLC_TYPE int16_t | ||
| 63 | |||
| 64 | typedef struct VLC { | ||
| 65 | int bits; | ||
| 66 | VLC_TYPE (*table)[2]; ///< code, bits | ||
| 67 | int table_size, table_allocated; | ||
| 68 | } VLC; | ||
| 69 | |||
| 70 | typedef struct RL_VLC_ELEM { | ||
| 71 | int16_t level; | ||
| 72 | int8_t len; | ||
| 73 | uint8_t run; | ||
| 74 | } RL_VLC_ELEM; | ||
| 75 | |||
| 76 | /* Bitstream reader API docs: | 63 | /* Bitstream reader API docs: |
| 77 | * name | 64 | * name |
| 78 | * arbitrary name which is used as prefix for the internal variables | 65 | * arbitrary name which is used as prefix for the internal variables |
| @@ -421,33 +408,6 @@ static inline const uint8_t *align_get_bits(GetBitContext *s) · 342 unmodified lines | |||
| 421 | return s->buffer + (s->index >> 3); | 408 | return s->buffer + (s->index >> 3); |
| 422 | } | 409 | } |
| 423 | 410 | ||
| 424 | #define init_vlc(vlc, nb_bits, nb_codes, \ | ||
| 425 | bits, bits_wrap, bits_size, \ | ||
| 426 | codes, codes_wrap, codes_size, \ | ||
| 427 | flags) \ | ||
| 428 | ff_init_vlc_sparse(vlc, nb_bits, nb_codes, \ | ||
| 429 | bits, bits_wrap, bits_size, \ | ||
| 430 | codes, codes_wrap, codes_size, \ | ||
| 431 | NULL, 0, 0, flags) | ||
| 432 | |||
| 433 | int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | ||
| 434 | const void *bits, int bits_wrap, int bits_size, | ||
| 435 | const void *codes, int codes_wrap, int codes_size, | ||
| 436 | const void *symbols, int symbols_wrap, int symbols_size, | ||
| 437 | int flags); | ||
| 438 | void ff_free_vlc(VLC *vlc); | ||
| 439 | |||
| 440 | #define INIT_VLC_LE 2 | ||
| 441 | #define INIT_VLC_USE_NEW_STATIC 4 | ||
| 442 | |||
| 443 | #define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \ | ||
| 444 | do { \ | ||
| 445 | static VLC_TYPE table[static_size][2]; \ | ||
| 446 | (vlc)->table = table; \ | ||
| 447 | (vlc)->table_allocated = static_size; \ | ||
| 448 | init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \ | ||
| 449 | } while (0) | ||
| 450 | |||
| 451 | /** | 411 | /** |
| 452 | * If the vlc code is invalid and max_depth=1, then no bits will be removed. | 412 | * If the vlc code is invalid and max_depth=1, then no bits will be removed. |
| 453 | * If the vlc code is invalid and max_depth>1, then the number of bits removed | 413 | * If the vlc code is invalid and max_depth>1, then the number of bits removed |
| @@ -26,8 +26,11 @@ · 25 unmodified lines | |||
| 26 | 26 | ||
| 27 | #include <stdint.h> | 27 | #include <stdint.h> |
| 28 | 28 | ||
| 29 | #include"libavutil/common.h" | ||
| 30 | |||
| 29 | #include "avcodec.h" | 31 | #include "avcodec.h" |
| 30 | #include "huffman.h" | 32 | #include "huffman.h" |
| 33 | #include "vlc.h" | ||
| 31 | 34 | ||
| 32 | /* symbol for Huffman tree node */ | 35 | /* symbol for Huffman tree node */ |
| 33 | #define HNODE -1 | 36 | #define HNODE -1 |
| @@ -27,7 +27,7 @@ · 26 unmodified lines | |||
| 27 | #define AVCODEC_HUFFMAN_H | 27 | #define AVCODEC_HUFFMAN_H |
| 28 | 28 | ||
| 29 | #include "avcodec.h" | 29 | #include "avcodec.h" |
| 30 | #include "get_bits.h" | 30 | #include "vlc.h" |
| 31 | 31 | ||
| 32 | typedef struct Node { | 32 | typedef struct Node { |
| 33 | int16_t sym; | 33 | int16_t sym; |
| @@ -17,6 +17,7 @@ · 16 unmodified lines | |||
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #include <stdint.h> | 19 | #include <stdint.h> |
| 20 | #include <string.h> | ||
| 20 | 21 | ||
| 21 | #include "libavutil/attributes.h" | 22 | #include "libavutil/attributes.h" |
| 22 | #include "libavutil/mem.h" | 23 | #include "libavutil/mem.h" |
| @@ -28,7 +28,8 @@ · 27 unmodified lines | |||
| 28 | #define AVCODEC_RL_H | 28 | #define AVCODEC_RL_H |
| 29 | 29 | ||
| 30 | #include <stdint.h> | 30 | #include <stdint.h> |
| 31 | #include "get_bits.h" | 31 | |
| 32 | #include "vlc.h" | ||
| 32 | 33 | ||
| 33 | /* run length table */ | 34 | /* run length table */ |
| 34 | #define MAX_RUN 64 | 35 | #define MAX_RUN 64 |
| @@ -0,0 +1,65 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of Libav. | ||
| 3 | * | ||
| 4 | * Libav is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * Libav is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with Libav; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #ifndef AVCODEC_VLC_H | ||
| 20 | #define AVCODEC_VLC_H | ||
| 21 | |||
| 22 | #include <stdint.h> | ||
| 23 | |||
| 24 | #define VLC_TYPE int16_t | ||
| 25 | |||
| 26 | typedef struct VLC { | ||
| 27 | int bits; | ||
| 28 | VLC_TYPE (*table)[2]; ///< code, bits | ||
| 29 | int table_size, table_allocated; | ||
| 30 | } VLC; | ||
| 31 | |||
| 32 | typedef struct RL_VLC_ELEM { | ||
| 33 | int16_t level; | ||
| 34 | int8_t len; | ||
| 35 | uint8_t run; | ||
| 36 | } RL_VLC_ELEM; | ||
| 37 | |||
| 38 | #define init_vlc(vlc, nb_bits, nb_codes, \ | ||
| 39 | bits, bits_wrap, bits_size, \ | ||
| 40 | codes, codes_wrap, codes_size, \ | ||
| 41 | flags) \ | ||
| 42 | ff_init_vlc_sparse(vlc, nb_bits, nb_codes, \ | ||
| 43 | bits, bits_wrap, bits_size, \ | ||
| 44 | codes, codes_wrap, codes_size, \ | ||
| 45 | NULL, 0, 0, flags) | ||
| 46 | |||
| 47 | int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | ||
| 48 | const void *bits, int bits_wrap, int bits_size, | ||
| 49 | const void *codes, int codes_wrap, int codes_size, | ||
| 50 | const void *symbols, int symbols_wrap, int symbols_size, | ||
| 51 | int flags); | ||
| 52 | void ff_free_vlc(VLC *vlc); | ||
| 53 | |||
| 54 | #define INIT_VLC_LE 2 | ||
| 55 | #define INIT_VLC_USE_NEW_STATIC 4 | ||
| 56 | |||
| 57 | #define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \ | ||
| 58 | do { \ | ||
| 59 | static VLC_TYPE table[static_size][2]; \ | ||
| 60 | (vlc)->table = table; \ | ||
| 61 | (vlc)->table_allocated = static_size; \ | ||
| 62 | init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \ | ||
| 63 | } while (0) | ||
| 64 | |||
| 65 | #endif /* AVCODEC_VLC_H */ | ||