]> git.sesse.net Git - ffmpeg/blob - libavcodec/vlc.h
avformat/alp: fix handling of TUN files
[ffmpeg] / libavcodec / vlc.h
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 /* If INIT_VLC_INPUT_LE is set, the LSB bit of the codes used to
55  * initialize the VLC table is the first bit to be read. */
56 #define INIT_VLC_INPUT_LE       2
57 /* If set the VLC is intended for a little endian bitstream reader. */
58 #define INIT_VLC_OUTPUT_LE      8
59 #define INIT_VLC_LE             (INIT_VLC_INPUT_LE | INIT_VLC_OUTPUT_LE)
60 #define INIT_VLC_USE_NEW_STATIC 4
61
62 #define INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g,      \
63                                       h, i, j, flags, static_size)         \
64     do {                                                                   \
65         static VLC_TYPE table[static_size][2];                             \
66         (vlc)->table           = table;                                    \
67         (vlc)->table_allocated = static_size;                              \
68         ff_init_vlc_sparse(vlc, bits, a, b, c, d, e, f, g, h, i, j,        \
69                            flags | INIT_VLC_USE_NEW_STATIC);               \
70     } while (0)
71
72 #define INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \
73     INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g,          \
74                                   h, i, j, 0, static_size)
75
76 #define INIT_LE_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \
77     INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g,          \
78                                   h, i, j, INIT_VLC_LE, static_size)
79
80 #define INIT_CUSTOM_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, flags, static_size) \
81     INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g,          \
82                                   NULL, 0, 0, flags, static_size)
83
84 #define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)       \
85     INIT_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, NULL, 0, 0, static_size)
86
87 #define INIT_LE_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \
88     INIT_LE_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, NULL, 0, 0, static_size)
89
90 #endif /* AVCODEC_VLC_H */