aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/vlc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-09-20 16:38:18 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-31 20:46:59 +0100
commitedc50658d967f893bb1e90666e7d400b1932fa45 (patch)
tree142f121dae046ba996654010e0362553053d9973 /libavcodec/vlc.c
parent424c8ceb08b180b832e63d50cc363a197119ab7f (diff)
downloadffmpeg-edc50658d967f893bb1e90666e7d400b1932fa45.tar.gz
avcodec/vlc: Add functions to init static VLCElem[] without VLC
For lots of static VLCs, the number of bits is not read from VLC.bits, but rather a compile-constant that is hardcoded at the callsite of get_vlc2(). Only VLC.table is ever used and not using it directly is just an unnecessary indirection. This commit adds helper functions and macros to avoid the VLC structure when initializing VLC tables; there are 2x2 functions: Two choices for init_sparse or from_lengths and two choices for "overlong" initialization (as used when multiple VLCs are initialized that share the same underlying table). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/vlc.c')
-rw-r--r--libavcodec/vlc.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 7786043086..aa84ca6b3c 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -350,6 +350,74 @@ fail:
return AVERROR_INVALIDDATA;
}
+av_cold void ff_vlc_init_table_from_lengths(VLCElem table[], int table_size,
+ int nb_bits, int nb_codes,
+ const int8_t *lens, int lens_wrap,
+ const void *symbols, int symbols_wrap, int symbols_size,
+ int offset, int flags)
+{
+ VLC vlc = { .table = table, .table_allocated = table_size };
+
+ ff_vlc_init_from_lengths(&vlc, nb_bits, nb_codes, lens, lens_wrap,
+ symbols, symbols_wrap, symbols_size,
+ offset, flags | VLC_INIT_USE_STATIC, NULL);
+}
+
+av_cold const VLCElem *ff_vlc_init_tables_from_lengths(VLCInitState *state,
+ int nb_bits, int nb_codes,
+ const int8_t *lens, int lens_wrap,
+ const void *symbols, int symbols_wrap, int symbols_size,
+ int offset, int flags)
+{
+ VLC vlc = { .table = state->table, .table_allocated = state->size };
+
+ ff_vlc_init_from_lengths(&vlc, nb_bits, nb_codes, lens, lens_wrap,
+ symbols, symbols_wrap, symbols_size,
+ offset, flags | VLC_INIT_STATIC_OVERLONG, NULL);
+
+ state->table += vlc.table_size;
+ state->size -= vlc.table_size;
+
+ return vlc.table;
+}
+
+av_cold void ff_vlc_init_table_sparse(VLCElem table[], int table_size,
+ int nb_bits, int nb_codes,
+ const void *bits, int bits_wrap, int bits_size,
+ const void *codes, int codes_wrap, int codes_size,
+ const void *symbols, int symbols_wrap, int symbols_size,
+ int flags)
+{
+ VLC vlc = { .table = table, .table_allocated = table_size };
+
+ ff_vlc_init_sparse(&vlc, nb_bits, nb_codes,
+ bits, bits_wrap, bits_size,
+ codes, codes_wrap, codes_size,
+ symbols, symbols_wrap, symbols_size,
+ flags | VLC_INIT_USE_STATIC);
+}
+
+av_cold const VLCElem *ff_vlc_init_tables_sparse(VLCInitState *state,
+ int nb_bits, int nb_codes,
+ const void *bits, int bits_wrap, int bits_size,
+ const void *codes, int codes_wrap, int codes_size,
+ const void *symbols, int symbols_wrap, int symbols_size,
+ int flags)
+{
+ VLC vlc = { .table = state->table, .table_allocated = state->size };
+
+ ff_vlc_init_sparse(&vlc, nb_bits, nb_codes,
+ bits, bits_wrap, bits_size,
+ codes, codes_wrap, codes_size,
+ symbols, symbols_wrap, symbols_size,
+ flags | VLC_INIT_STATIC_OVERLONG);
+
+ state->table += vlc.table_size;
+ state->size -= vlc.table_size;
+
+ return vlc.table;
+}
+
static void add_level(VLC_MULTI_ELEM *table, const int is16bit,
const int num, const int numbits,
const VLCcode *buf,