diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-08-27 21:18:46 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-09-07 00:23:30 +0200 |
commit | 29b9fca4b3ca24ee8d8f951a3afe6daa77089096 (patch) | |
tree | e4da7dbf8db012d0a894d82e91fdea660752cdb2 /libavcodec/bitstream_template.h | |
parent | 3a5be28857de4d523ff95ec07362771a89e00f46 (diff) | |
download | ffmpeg-29b9fca4b3ca24ee8d8f951a3afe6daa77089096.tar.gz |
avcodec: add multi vlc reader
Heavily based and inspired by Christophe's cache branches.
Co-Authored-by: Christophe Gisquet
Diffstat (limited to 'libavcodec/bitstream_template.h')
-rw-r--r-- | libavcodec/bitstream_template.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h index 30bea84add..0308e3a924 100644 --- a/libavcodec/bitstream_template.h +++ b/libavcodec/bitstream_template.h @@ -520,6 +520,35 @@ static inline int BS_FUNC(read_vlc)(BSCTX *bc, const VLCElem *table, return code; } +static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t *dst, + const VLC_MULTI_ELEM *const Jtable, + const VLCElem *const table, + const int bits, const int max_depth) +{ + unsigned idx = BS_FUNC(peek)(bc, bits); + int ret, nb_bits, code, n = Jtable[idx].len; + if (Jtable[idx].num) { + AV_COPY64U(dst, Jtable[idx].val); + ret = Jtable[idx].num; + } else { + code = table[idx].sym; + n = table[idx].len; + if (max_depth > 1 && n < 0) { + BS_FUNC(priv_skip_remaining)(bc, bits); + code = BS_FUNC(priv_set_idx)(bc, code, &n, &nb_bits, table); + if (max_depth > 2 && n < 0) { + BS_FUNC(priv_skip_remaining)(bc, nb_bits); + code = BS_FUNC(priv_set_idx)(bc, code, &n, &nb_bits, table); + } + } + AV_WN16(dst, code); + ret = n > 0; + } + BS_FUNC(priv_skip_remaining)(bc, n); + + return ret; +} + #undef BSCTX #undef BS_FUNC #undef BS_JOIN3 |