From 73fc82f3434d9b68f0948700c4fd8f5056ae5afe Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sat, 29 Apr 2017 00:34:11 +0000 Subject: [PATCH 1/2] vlc: Add header #include when the types are used Do not rely on indirectly including it from bitstream.h. Signed-off-by: Diego Biurrun --- libavcodec/4xm.c | 1 + libavcodec/atrac3.c | 1 + libavcodec/atrac3plus.c | 1 + libavcodec/bink.c | 1 + libavcodec/cfhd.h | 1 + libavcodec/clearvideo.c | 1 + libavcodec/cook.c | 1 + libavcodec/faxcompr.c | 1 + libavcodec/g2meet.c | 1 + libavcodec/hqx.h | 1 + libavcodec/imc.c | 1 + libavcodec/indeo2.c | 1 + libavcodec/indeo4.c | 1 + libavcodec/indeo5.c | 1 + libavcodec/ivi.h | 1 + libavcodec/mimic.c | 1 + libavcodec/mlpdec.c | 1 + libavcodec/motionpixels.c | 1 + libavcodec/mpc7.c | 1 + libavcodec/mpc8.c | 1 + libavcodec/qdm2.c | 1 + libavcodec/smacker.c | 1 + libavcodec/truemotion2.c | 1 + libavcodec/tscc2.c | 1 + libavcodec/utvideodec.c | 1 + libavcodec/vorbisdec.c | 1 + libavcodec/wma.h | 1 + libavcodec/wmavoice.c | 1 + libavcodec/wnv1.c | 1 + 29 files changed, 29 insertions(+) diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index b419bfa268..4a9a14a79b 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -36,6 +36,7 @@ #include "bswapdsp.h" #include "bytestream.h" #include "internal.h" +#include "vlc.h" #define BLOCK_TYPE_VLC_BITS 5 #define ACDC_VLC_BITS 9 diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 2a703ca46e..d0661c83fc 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -44,6 +44,7 @@ #include "bytestream.h" #include "fft.h" #include "internal.h" +#include "vlc.h" #include "atrac.h" #include "atrac3data.h" diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c index e3c2504178..9b7b28bb9b 100644 --- a/libavcodec/atrac3plus.c +++ b/libavcodec/atrac3plus.c @@ -29,6 +29,7 @@ #include "avcodec.h" #include "bitstream.h" +#include "vlc.h" #include "atrac3plus.h" #include "atrac3plus_data.h" diff --git a/libavcodec/bink.c b/libavcodec/bink.c index 84388b86aa..011d2d8e22 100644 --- a/libavcodec/bink.c +++ b/libavcodec/bink.c @@ -33,6 +33,7 @@ #include "hpeldsp.h" #include "internal.h" #include "mathops.h" +#include "vlc.h" #define BINK_FLAG_ALPHA 0x00100000 #define BINK_FLAG_GRAY 0x00020000 diff --git a/libavcodec/cfhd.h b/libavcodec/cfhd.h index c5da0b6ec7..27f047d3e8 100644 --- a/libavcodec/cfhd.h +++ b/libavcodec/cfhd.h @@ -25,6 +25,7 @@ #include "avcodec.h" #include "bitstream.h" +#include "vlc.h" #define VLC_BITS 9 #define SUBBAND_COUNT 10 diff --git a/libavcodec/clearvideo.c b/libavcodec/clearvideo.c index 08bf2cb6da..7c5143937f 100644 --- a/libavcodec/clearvideo.c +++ b/libavcodec/clearvideo.c @@ -29,6 +29,7 @@ #include "bytestream.h" #include "idctdsp.h" #include "internal.h" +#include "vlc.h" #define NUM_DC_CODES 127 #define NUM_AC_CODES 103 diff --git a/libavcodec/cook.c b/libavcodec/cook.c index c3304eae2e..bd8ad1d1da 100644 --- a/libavcodec/cook.c +++ b/libavcodec/cook.c @@ -52,6 +52,7 @@ #include "fft.h" #include "internal.h" #include "sinewin.h" +#include "vlc.h" #include "cookdata.h" diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c index 9eb4e37999..0a079fc992 100644 --- a/libavcodec/faxcompr.c +++ b/libavcodec/faxcompr.c @@ -27,6 +27,7 @@ #include "avcodec.h" #include "bitstream.h" #include "put_bits.h" +#include "vlc.h" #include "faxcompr.h" #define CCITT_SYMS 104 diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c index d7dc976153..93befb4809 100644 --- a/libavcodec/g2meet.c +++ b/libavcodec/g2meet.c @@ -39,6 +39,7 @@ #include "internal.h" #include "jpegtables.h" #include "mjpeg.h" +#include "vlc.h" #define EPIC_PIX_STACK_SIZE 1024 #define EPIC_PIX_STACK_MAX (EPIC_PIX_STACK_SIZE - 1) diff --git a/libavcodec/hqx.h b/libavcodec/hqx.h index e8f7c627fb..f35721a06c 100644 --- a/libavcodec/hqx.h +++ b/libavcodec/hqx.h @@ -28,6 +28,7 @@ #include "bitstream.h" #include "hqxdsp.h" +#include "vlc.h" enum HQXACMode { HQX_AC_Q0 = 0, diff --git a/libavcodec/imc.c b/libavcodec/imc.c index 145b2d56fc..100e6f8941 100644 --- a/libavcodec/imc.c +++ b/libavcodec/imc.c @@ -44,6 +44,7 @@ #include "fft.h" #include "internal.h" #include "sinewin.h" +#include "vlc.h" #include "imcdata.h" diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c index 811056dbfc..64e92d760f 100644 --- a/libavcodec/indeo2.c +++ b/libavcodec/indeo2.c @@ -32,6 +32,7 @@ #include "indeo2data.h" #include "internal.h" #include "mathops.h" +#include "vlc.h" typedef struct Ir2Context{ AVCodecContext *avctx; diff --git a/libavcodec/indeo4.c b/libavcodec/indeo4.c index 4b3f903e3b..37b5da8508 100644 --- a/libavcodec/indeo4.c +++ b/libavcodec/indeo4.c @@ -34,6 +34,7 @@ #include "internal.h" #include "ivi.h" #include "ivi_dsp.h" +#include "vlc.h" #define IVI4_PIC_SIZE_ESC 7 diff --git a/libavcodec/indeo5.c b/libavcodec/indeo5.c index 70ae1d324b..38907eb056 100644 --- a/libavcodec/indeo5.c +++ b/libavcodec/indeo5.c @@ -33,6 +33,7 @@ #include "ivi.h" #include "ivi_dsp.h" #include "indeo5data.h" +#include "vlc.h" /** * Indeo5 frame types. diff --git a/libavcodec/ivi.h b/libavcodec/ivi.h index bbc8842340..6fde8a671a 100644 --- a/libavcodec/ivi.h +++ b/libavcodec/ivi.h @@ -33,6 +33,7 @@ #include "avcodec.h" #include "bitstream.h" +#include "vlc.h" /** * Indeo 4 frame types. diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c index 31d07ecd50..da8289e411 100644 --- a/libavcodec/mimic.c +++ b/libavcodec/mimic.c @@ -32,6 +32,7 @@ #include "hpeldsp.h" #include "idctdsp.h" #include "thread.h" +#include "vlc.h" #define MIMIC_HEADER_SIZE 20 diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c index 4f6675a3ca..b377fd7e2b 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -39,6 +39,7 @@ #include "mlpdsp.h" #include "mlp.h" #include "config.h" +#include "vlc.h" /** number of bits used for VLC lookup - longest Huffman code is 9 */ #if ARCH_ARM diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c index da4c141db6..66ec5f5009 100644 --- a/libavcodec/motionpixels.c +++ b/libavcodec/motionpixels.c @@ -23,6 +23,7 @@ #include "bitstream.h" #include "bswapdsp.h" #include "internal.h" +#include "vlc.h" #define MAX_HUFF_CODES 16 diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c index 66a6162ec5..ebc3f5293b 100644 --- a/libavcodec/mpc7.c +++ b/libavcodec/mpc7.c @@ -33,6 +33,7 @@ #include "bitstream.h" #include "internal.h" #include "mpegaudiodsp.h" +#include "vlc.h" #include "mpc.h" #include "mpc7data.h" diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c index f55fd57824..649eb02e2e 100644 --- a/libavcodec/mpc8.c +++ b/libavcodec/mpc8.c @@ -32,6 +32,7 @@ #include "bitstream.h" #include "internal.h" #include "mpegaudiodsp.h" +#include "vlc.h" #include "mpc.h" #include "mpc8data.h" diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c index 00c952d51a..668e513a66 100644 --- a/libavcodec/qdm2.c +++ b/libavcodec/qdm2.c @@ -44,6 +44,7 @@ #include "mpegaudio.h" #include "mpegaudiodsp.h" #include "rdft.h" +#include "vlc.h" #include "qdm2data.h" #include "qdm2_tablegen.h" diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index 2abf7c1c5a..c4b4bc735d 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -39,6 +39,7 @@ #include "bytestream.h" #include "internal.h" #include "mathops.h" +#include "vlc.h" #define SMKTREE_BITS 9 #define SMK_NODE 0x80000000 diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c index 333451cb7c..cc3b0b76e0 100644 --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@ -31,6 +31,7 @@ #include "bswapdsp.h" #include "bytestream.h" #include "internal.h" +#include "vlc.h" #define TM2_ESCAPE 0x80000000 #define TM2_DELTAS 64 diff --git a/libavcodec/tscc2.c b/libavcodec/tscc2.c index 6081c72c30..28d6464258 100644 --- a/libavcodec/tscc2.c +++ b/libavcodec/tscc2.c @@ -33,6 +33,7 @@ #include "internal.h" #include "mathops.h" #include "tscc2data.h" +#include "vlc.h" typedef struct TSCC2Context { AVCodecContext *avctx; diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index ed6368e4cd..26b991ca7b 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -36,6 +36,7 @@ #include "internal.h" #include "thread.h" #include "utvideo.h" +#include "vlc.h" static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) { diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index 9289c82cf4..cc0f6f4a3e 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -32,6 +32,7 @@ #include "fft.h" #include "get_bits.h" #include "internal.h" +#include "vlc.h" #include "vorbis.h" #include "vorbisdsp.h" #include "xiph.h" diff --git a/libavcodec/wma.h b/libavcodec/wma.h index 6d14fc66c6..80b82867a5 100644 --- a/libavcodec/wma.h +++ b/libavcodec/wma.h @@ -28,6 +28,7 @@ #include "bitstream.h" #include "fft.h" #include "put_bits.h" +#include "vlc.h" /* size of blocks */ #define BLOCK_MIN_BITS 7 diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index cf9884108c..8c7ec7b3d6 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -43,6 +43,7 @@ #include "dct.h" #include "rdft.h" #include "sinewin.h" +#include "vlc.h" #define MAX_BLOCKS 8 ///< maximum number of blocks per frame #define MAX_LSPS 16 ///< maximum filter order diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c index e973f7ecc5..f498c20b47 100644 --- a/libavcodec/wnv1.c +++ b/libavcodec/wnv1.c @@ -28,6 +28,7 @@ #include "bitstream.h" #include "internal.h" #include "mathops.h" +#include "vlc.h" typedef struct WNV1Context { From 0ac1fec1c3dacedabbf3dd4122ef4bf8523e688c Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sat, 29 Apr 2017 00:34:12 +0000 Subject: [PATCH 2/2] bitstream: Move VLC reading functions into the vlc.h header This makes the bitstream.h header leaner. Signed-off-by: Diego Biurrun --- libavcodec/bitstream.h | 73 ----------------------------------------- libavcodec/vlc.h | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 73 deletions(-) diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h index 894a13e348..d6dd2b9411 100644 --- a/libavcodec/bitstream.h +++ b/libavcodec/bitstream.h @@ -33,7 +33,6 @@ #include "libavutil/log.h" #include "mathops.h" -#include "vlc.h" typedef struct BitstreamContext { uint64_t bits; // stores bits read from the buffer @@ -287,78 +286,6 @@ static inline int bitstream_read_xbits(BitstreamContext *bc, unsigned length) return ((((uint32_t)(sign ^ cache)) >> (32 - length)) ^ sign) - sign; } -/* Return the LUT element for the given bitstream configuration. */ -static inline int set_idx(BitstreamContext *bc, int code, int *n, int *nb_bits, - VLC_TYPE (*table)[2]) -{ - unsigned idx; - - *nb_bits = -*n; - idx = bitstream_peek(bc, *nb_bits) + code; - *n = table[idx][1]; - - return table[idx][0]; -} - -/** - * Parse a VLC code. - * @param bits is the number of bits which will be read at once, must be - * identical to nb_bits in init_vlc() - * @param max_depth is the number of times bits bits must be read to completely - * read the longest VLC code - * = (max_vlc_length + bits - 1) / bits - * If the VLC code is invalid and max_depth = 1, then no bits will be removed. - * If the VLC code is invalid and max_depth > 1, then the number of bits removed - * is undefined. */ -static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2], - int bits, int max_depth) -{ - int nb_bits; - unsigned idx = bitstream_peek(bc, bits); - int code = table[idx][0]; - int n = table[idx][1]; - - if (max_depth > 1 && n < 0) { - skip_remaining(bc, bits); - code = set_idx(bc, code, &n, &nb_bits, table); - if (max_depth > 2 && n < 0) { - skip_remaining(bc, nb_bits); - code = set_idx(bc, code, &n, &nb_bits, table); - } - } - skip_remaining(bc, n); - - return code; -} - -#define BITSTREAM_RL_VLC(level, run, bc, table, bits, max_depth) \ - do { \ - int n, nb_bits; \ - unsigned index = bitstream_peek(bc, bits); \ - level = table[index].level; \ - n = table[index].len; \ - \ - if (max_depth > 1 && n < 0) { \ - bitstream_skip(bc, bits); \ - \ - nb_bits = -n; \ - \ - index = bitstream_peek(bc, nb_bits) + level; \ - level = table[index].level; \ - n = table[index].len; \ - if (max_depth > 2 && n < 0) { \ - bitstream_skip(bc, nb_bits); \ - nb_bits = -n; \ - \ - index = bitstream_peek(bc, nb_bits) + level; \ - level = table[index].level; \ - n = table[index].len; \ - } \ - } \ - run = table[index].run; \ - bitstream_skip(bc, n); \ - } while (0) - /* Return decoded truncated unary code for the values 0, 1, 2. */ static inline int bitstream_decode012(BitstreamContext *bc) { diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h index 4ade824391..8ac52381b9 100644 --- a/libavcodec/vlc.h +++ b/libavcodec/vlc.h @@ -21,6 +21,8 @@ #include +#include "bitstream.h" + #define VLC_TYPE int16_t typedef struct VLC { @@ -62,4 +64,76 @@ void ff_free_vlc(VLC *vlc); init_vlc(vlc, bits, a, b, c, d, e, f, g, INIT_VLC_USE_NEW_STATIC); \ } while (0) +/* Return the LUT element for the given bitstream configuration. */ +static inline int set_idx(BitstreamContext *bc, int code, int *n, int *nb_bits, + VLC_TYPE (*table)[2]) +{ + unsigned idx; + + *nb_bits = -*n; + idx = bitstream_peek(bc, *nb_bits) + code; + *n = table[idx][1]; + + return table[idx][0]; +} + +/** + * Parse a VLC code. + * @param bits is the number of bits which will be read at once, must be + * identical to nb_bits in init_vlc() + * @param max_depth is the number of times bits bits must be read to completely + * read the longest VLC code + * = (max_vlc_length + bits - 1) / bits + * If the VLC code is invalid and max_depth = 1, then no bits will be removed. + * If the VLC code is invalid and max_depth > 1, then the number of bits removed + * is undefined. */ +static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2], + int bits, int max_depth) +{ + int nb_bits; + unsigned idx = bitstream_peek(bc, bits); + int code = table[idx][0]; + int n = table[idx][1]; + + if (max_depth > 1 && n < 0) { + skip_remaining(bc, bits); + code = set_idx(bc, code, &n, &nb_bits, table); + if (max_depth > 2 && n < 0) { + skip_remaining(bc, nb_bits); + code = set_idx(bc, code, &n, &nb_bits, table); + } + } + skip_remaining(bc, n); + + return code; +} + +#define BITSTREAM_RL_VLC(level, run, bc, table, bits, max_depth) \ + do { \ + int n, nb_bits; \ + unsigned index = bitstream_peek(bc, bits); \ + level = table[index].level; \ + n = table[index].len; \ + \ + if (max_depth > 1 && n < 0) { \ + bitstream_skip(bc, bits); \ + \ + nb_bits = -n; \ + \ + index = bitstream_peek(bc, nb_bits) + level; \ + level = table[index].level; \ + n = table[index].len; \ + if (max_depth > 2 && n < 0) { \ + bitstream_skip(bc, nb_bits); \ + nb_bits = -n; \ + \ + index = bitstream_peek(bc, nb_bits) + level; \ + level = table[index].level; \ + n = table[index].len; \ + } \ + } \ + run = table[index].run; \ + bitstream_skip(bc, n); \ + } while (0) + #endif /* AVCODEC_VLC_H */