* [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC
@ 2023-09-26 22:12 Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 02/61] avcodec/vp3: Make VLC tables static where possible Andreas Rheinhardt
` (60 more replies)
0 siblings, 61 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
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>
---
libavcodec/vlc.c | 68 +++++++++++++++++++++++++++++++
libavcodec/vlc.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 170 insertions(+)
diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 21b9fffe27..b5de0bd24e 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 nb_elems,
const int num, const int numbits,
const VLCcode *buf,
diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h
index 3f7c033a78..679666801a 100644
--- a/libavcodec/vlc.h
+++ b/libavcodec/vlc.h
@@ -19,8 +19,11 @@
#ifndef AVCODEC_VLC_H
#define AVCODEC_VLC_H
+#include <stddef.h>
#include <stdint.h>
+#include "libavutil/macros.h"
+
#define VLC_MULTI_MAX_SYMBOLS 6
// When changing this, be sure to also update tableprint_vlc.h accordingly.
@@ -223,4 +226,103 @@ void ff_vlc_free(VLC *vlc);
NULL); \
} while (0)
+/**
+ * For static VLCs, the number of bits can often be hardcoded
+ * at each get_vlc2() callsite. Then using a full VLC would be uneconomical,
+ * because only VLC.table would ever be accessed after initialization.
+ * The following functions provide wrappers around the relevant ff_vlc_init_*
+ * functions suitable for said task.
+ *
+ * The ff_vlc_init_tables_* functions are intended to be used for initializing
+ * a series of VLCs. The user initializes a VLCInitState with the details
+ * about the underlying array of VLCElem; it is automatically updated by
+ * the ff_vlc_init_tables_* functions (i.e. table is incremented and size
+ * decremented by the number of elements of the current table).
+ * The VLC_INIT_STATIC_OVERLONG flag is also automatically added.
+ * These functions return a pointer to the table just initialized,
+ * potentially to be used in arrays of pointer to VLC tables.
+ *
+ * The ff_vlc_init_table_* functions are intended to be used for initializing
+ * a single VLC table, given by table and table_size. The VLC_INIT_USE_STATIC
+ * flag is automatically added.
+ */
+
+typedef struct VLCInitState {
+ VLCElem *table; ///< points to where the next VLC table will be placed
+ unsigned size; ///< remaining number of elements in table
+} VLCInitState;
+
+#define VLC_INIT_STATE(_table) { .table = (_table), .size = FF_ARRAY_ELEMS(_table) }
+
+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);
+
+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);
+
+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);
+
+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);
+
+static inline
+const VLCElem *ff_vlc_init_tables(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,
+ int flags)
+{
+ return ff_vlc_init_tables_sparse(state, nb_bits, nb_codes,
+ bits, bits_wrap, bits_size,
+ codes, codes_wrap, codes_size,
+ NULL, 0, 0, flags);
+}
+
+#define VLC_INIT_STATIC_SPARSE_TABLE(vlc_table, nb_bits, nb_codes, \
+ bits, bits_wrap, bits_size, \
+ codes, codes_wrap, codes_size, \
+ symbols, symbols_wrap, symbols_size, \
+ flags) \
+ ff_vlc_init_table_sparse(vlc_table, FF_ARRAY_ELEMS(vlc_table), \
+ (nb_bits), (nb_codes), \
+ (bits), (bits_wrap), (bits_size), \
+ (codes), (codes_wrap), (codes_size), \
+ (symbols), (symbols_wrap), (symbols_size), \
+ (flags))
+
+#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, \
+ bits, bits_wrap, bits_size, \
+ codes, codes_wrap, codes_size, \
+ flags) \
+ ff_vlc_init_table_sparse(vlc_table, FF_ARRAY_ELEMS(vlc_table), \
+ (nb_bits), (nb_codes), \
+ (bits), (bits_wrap), (bits_size), \
+ (codes), (codes_wrap), (codes_size), \
+ NULL, 0, 0, (flags))
+
+#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, \
+ lens, lens_wrap, \
+ syms, syms_wrap, syms_size, \
+ offset, flags) \
+ ff_vlc_init_table_from_lengths(vlc_table, FF_ARRAY_ELEMS(vlc_table), \
+ (nb_bits), (nb_codes), \
+ (lens), (lens_wrap), \
+ (syms), (syms_wrap), (syms_size), \
+ (offset), (flags))
+
#endif /* AVCODEC_VLC_H */
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 02/61] avcodec/vp3: Make VLC tables static where possible
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 03/61] avcodec/vp3: Increase some VLC tables Andreas Rheinhardt
` (59 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is especially important for frame-threaded decoders like
this one, because up until now each thread had an identical
copy of all these VLC tables.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vp3.c | 162 +++++++++++++++++++++++------------------------
1 file changed, 81 insertions(+), 81 deletions(-)
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 98dabfc907..9199f53397 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -38,6 +38,7 @@
#include "libavutil/emms.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem_internal.h"
+#include "libavutil/thread.h"
#include "avcodec.h"
#include "codec_internal.h"
@@ -158,6 +159,18 @@ static const uint8_t vp4_pred_block_type_map[8] = {
[MODE_INTER_FOURMV] = VP4_DC_INTER,
};
+static VLCElem superblock_run_length_vlc[88]; /* version < 2 */
+static VLCElem fragment_run_length_vlc[56]; /* version < 2 */
+static VLCElem motion_vector_vlc[112]; /* version < 2 */
+
+// The VP4 tables reuse this vlc.
+static VLCElem mode_code_vlc[18 + 2084 * CONFIG_VP4_DECODER];
+
+#if CONFIG_VP4_DECODER
+static const VLCElem *vp4_mv_vlc_table[2][7]; /* version >= 2 */
+static const VLCElem *block_pattern_vlc[2]; /* version >= 2 */
+#endif
+
typedef struct {
int dc;
int type;
@@ -280,13 +293,6 @@ typedef struct Vp3DecodeContext {
the others are four groups of 16 VLCs each for ac coefficients. */
VLC coeff_vlc[5 * 16];
- VLC superblock_run_length_vlc; /* version < 2 */
- VLC fragment_run_length_vlc; /* version < 2 */
- VLC block_pattern_vlc[2]; /* version >= 2*/
- VLC mode_code_vlc;
- VLC motion_vector_vlc; /* version < 2 */
- VLC vp4_mv_vlc[2][7]; /* version >=2 */
-
/* these arrays need to be on 16-byte boundaries since SSE2 operations
* index into them */
DECLARE_ALIGNED(16, int16_t, qmat)[3][2][3][64]; ///< qmat[qpi][is_inter][plane]
@@ -362,17 +368,6 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx)
for (int i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++)
ff_vlc_free(&s->coeff_vlc[i]);
- ff_vlc_free(&s->superblock_run_length_vlc);
- ff_vlc_free(&s->fragment_run_length_vlc);
- ff_vlc_free(&s->mode_code_vlc);
- ff_vlc_free(&s->motion_vector_vlc);
-
- for (int j = 0; j < 2; j++)
- for (int i = 0; i < 7; i++)
- ff_vlc_free(&s->vp4_mv_vlc[j][i]);
-
- for (int i = 0; i < 2; i++)
- ff_vlc_free(&s->block_pattern_vlc[i]);
return 0;
}
@@ -493,7 +488,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
else
bit ^= 1;
- current_run = get_vlc2(gb, s->superblock_run_length_vlc.table,
+ current_run = get_vlc2(gb, superblock_run_length_vlc,
SUPERBLOCK_VLC_BITS, 2);
if (current_run == 34)
current_run += get_bits(gb, 12);
@@ -527,7 +522,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
else
bit ^= 1;
- current_run = get_vlc2(gb, s->superblock_run_length_vlc.table,
+ current_run = get_vlc2(gb, superblock_run_length_vlc,
SUPERBLOCK_VLC_BITS, 2);
if (current_run == 34)
current_run += get_bits(gb, 12);
@@ -607,7 +602,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
* that cares about the fragment coding runs */
if (current_run-- == 0) {
bit ^= 1;
- current_run = get_vlc2(gb, s->fragment_run_length_vlc.table, 5, 2);
+ current_run = get_vlc2(gb, fragment_run_length_vlc, 5, 2);
}
coded = bit;
}
@@ -684,9 +679,9 @@ static int vp4_get_mb_count(Vp3DecodeContext *s, GetBitContext *gb)
return v;
}
-static int vp4_get_block_pattern(Vp3DecodeContext *s, GetBitContext *gb, int *next_block_pattern_table)
+static int vp4_get_block_pattern(GetBitContext *gb, int *next_block_pattern_table)
{
- int v = get_vlc2(gb, s->block_pattern_vlc[*next_block_pattern_table].table, 3, 2);
+ int v = get_vlc2(gb, block_pattern_vlc[*next_block_pattern_table], 3, 2);
*next_block_pattern_table = vp4_block_pattern_table_selector[v];
return v + 1;
}
@@ -758,7 +753,7 @@ static int vp4_unpack_macroblocks(Vp3DecodeContext *s, GetBitContext *gb)
if (mb_coded == SB_FULLY_CODED)
pattern = 0xF;
else if (mb_coded == SB_PARTIALLY_CODED)
- pattern = vp4_get_block_pattern(s, gb, &next_block_pattern_table);
+ pattern = vp4_get_block_pattern(gb, &next_block_pattern_table);
else
pattern = 0;
@@ -845,7 +840,7 @@ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
if (scheme == 7)
coding_mode = get_bits(gb, 3);
else
- coding_mode = alphabet[get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];
+ coding_mode = alphabet[get_vlc2(gb, mode_code_vlc, 3, 3)];
s->macroblock_coding[current_macroblock] = coding_mode;
for (k = 0; k < 4; k++) {
@@ -886,11 +881,15 @@ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
return 0;
}
-static int vp4_get_mv(Vp3DecodeContext *s, GetBitContext *gb, int axis, int last_motion)
+static int vp4_get_mv(GetBitContext *gb, int axis, int last_motion)
{
- int v = get_vlc2(gb, s->vp4_mv_vlc[axis][vp4_mv_table_selector[FFABS(last_motion)]].table,
+#if CONFIG_VP4_DECODER
+ int v = get_vlc2(gb, vp4_mv_vlc_table[axis][vp4_mv_table_selector[FFABS(last_motion)]],
VP4_MV_VLC_BITS, 2);
return last_motion < 0 ? -v : v;
+#else
+ return 0;
+#endif
}
/*
@@ -938,23 +937,23 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
switch (s->macroblock_coding[current_macroblock]) {
case MODE_GOLDEN_MV:
if (coding_mode == 2) { /* VP4 */
- last_gold_motion_x = motion_x[0] = vp4_get_mv(s, gb, 0, last_gold_motion_x);
- last_gold_motion_y = motion_y[0] = vp4_get_mv(s, gb, 1, last_gold_motion_y);
+ last_gold_motion_x = motion_x[0] = vp4_get_mv(gb, 0, last_gold_motion_x);
+ last_gold_motion_y = motion_y[0] = vp4_get_mv(gb, 1, last_gold_motion_y);
break;
} /* otherwise fall through */
case MODE_INTER_PLUS_MV:
/* all 6 fragments use the same motion vector */
if (coding_mode == 0) {
- motion_x[0] = get_vlc2(gb, s->motion_vector_vlc.table,
+ motion_x[0] = get_vlc2(gb, motion_vector_vlc,
VP3_MV_VLC_BITS, 2);
- motion_y[0] = get_vlc2(gb, s->motion_vector_vlc.table,
+ motion_y[0] = get_vlc2(gb, motion_vector_vlc,
VP3_MV_VLC_BITS, 2);
} else if (coding_mode == 1) {
motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];
motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)];
} else { /* VP4 */
- motion_x[0] = vp4_get_mv(s, gb, 0, last_motion_x);
- motion_y[0] = vp4_get_mv(s, gb, 1, last_motion_y);
+ motion_x[0] = vp4_get_mv(gb, 0, last_motion_x);
+ motion_y[0] = vp4_get_mv(gb, 1, last_motion_y);
}
/* vector maintenance, only on MODE_INTER_PLUS_MV */
@@ -977,16 +976,16 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X;
if (s->all_fragments[current_fragment].coding_method != MODE_COPY) {
if (coding_mode == 0) {
- motion_x[k] = get_vlc2(gb, s->motion_vector_vlc.table,
+ motion_x[k] = get_vlc2(gb, motion_vector_vlc,
VP3_MV_VLC_BITS, 2);
- motion_y[k] = get_vlc2(gb, s->motion_vector_vlc.table,
+ motion_y[k] = get_vlc2(gb, motion_vector_vlc,
VP3_MV_VLC_BITS, 2);
} else if (coding_mode == 1) {
motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];
motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];
} else { /* VP4 */
- motion_x[k] = vp4_get_mv(s, gb, 0, prior_last_motion_x);
- motion_y[k] = vp4_get_mv(s, gb, 1, prior_last_motion_y);
+ motion_x[k] = vp4_get_mv(gb, 0, prior_last_motion_x);
+ motion_y[k] = vp4_get_mv(gb, 1, prior_last_motion_y);
}
last_motion_x = motion_x[k];
last_motion_y = motion_y[k];
@@ -1111,7 +1110,7 @@ static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb)
else
bit ^= 1;
- run_length = get_vlc2(gb, s->superblock_run_length_vlc.table,
+ run_length = get_vlc2(gb, superblock_run_length_vlc,
SUPERBLOCK_VLC_BITS, 2);
if (run_length == 34)
run_length += get_bits(gb, 12);
@@ -2258,6 +2257,48 @@ static void render_slice(Vp3DecodeContext *s, int slice)
s->height - 16));
}
+static av_cold void init_tables_once(void)
+{
+ VLCInitState state = VLC_INIT_STATE(mode_code_vlc);
+
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(superblock_run_length_vlc,
+ SUPERBLOCK_VLC_BITS, 34,
+ superblock_run_length_vlc_lens, 1,
+ NULL, 0, 0, 1, 0);
+
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(fragment_run_length_vlc, 5, 30,
+ fragment_run_length_vlc_len, 1,
+ NULL, 0, 0, 0, 0);
+
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(motion_vector_vlc, VP3_MV_VLC_BITS, 63,
+ &motion_vector_vlc_table[0][1], 2,
+ &motion_vector_vlc_table[0][0], 2, 1,
+ -31, 0);
+
+ ff_vlc_init_tables_from_lengths(&state, 3, 8,
+ mode_code_vlc_len, 1,
+ NULL, 0, 0, 0, 0);
+
+#if CONFIG_VP4_DECODER
+ for (int j = 0; j < 2; j++)
+ for (int i = 0; i < 7; i++) {
+ vp4_mv_vlc_table[j][i] =
+ ff_vlc_init_tables_from_lengths(&state, VP4_MV_VLC_BITS, 63,
+ &vp4_mv_vlc[j][i][0][1], 2,
+ &vp4_mv_vlc[j][i][0][0], 2, 1,
+ -31, 0);
+ }
+
+ /* version >= 2 */
+ for (int i = 0; i < 2; i++) {
+ block_pattern_vlc[i] =
+ ff_vlc_init_tables(&state, 3, 14,
+ &vp4_block_pattern_vlc[i][0][1], 2, 1,
+ &vp4_block_pattern_vlc[i][0][0], 2, 1, 0);
+ }
+#endif
+}
+
/// Allocate tables for per-frame data in Vp3DecodeContext
static av_cold int allocate_tables(AVCodecContext *avctx)
{
@@ -2316,6 +2357,7 @@ static av_cold int init_frames(Vp3DecodeContext *s)
static av_cold int vp3_decode_init(AVCodecContext *avctx)
{
+ static AVOnce init_static_once = AV_ONCE_INIT;
Vp3DecodeContext *s = avctx->priv_data;
int ret;
int c_width;
@@ -2445,49 +2487,7 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
}
}
- ret = ff_vlc_init_from_lengths(&s->superblock_run_length_vlc, SUPERBLOCK_VLC_BITS, 34,
- superblock_run_length_vlc_lens, 1,
- NULL, 0, 0, 1, 0, avctx);
- if (ret < 0)
- return ret;
-
- ret = ff_vlc_init_from_lengths(&s->fragment_run_length_vlc, 5, 30,
- fragment_run_length_vlc_len, 1,
- NULL, 0, 0, 0, 0, avctx);
- if (ret < 0)
- return ret;
-
- ret = ff_vlc_init_from_lengths(&s->mode_code_vlc, 3, 8,
- mode_code_vlc_len, 1,
- NULL, 0, 0, 0, 0, avctx);
- if (ret < 0)
- return ret;
-
- ret = ff_vlc_init_from_lengths(&s->motion_vector_vlc, VP3_MV_VLC_BITS, 63,
- &motion_vector_vlc_table[0][1], 2,
- &motion_vector_vlc_table[0][0], 2, 1,
- -31, 0, avctx);
- if (ret < 0)
- return ret;
-
-#if CONFIG_VP4_DECODER
- for (int j = 0; j < 2; j++)
- for (int i = 0; i < 7; i++) {
- ret = ff_vlc_init_from_lengths(&s->vp4_mv_vlc[j][i], VP4_MV_VLC_BITS, 63,
- &vp4_mv_vlc[j][i][0][1], 2,
- &vp4_mv_vlc[j][i][0][0], 2, 1, -31,
- 0, avctx);
- if (ret < 0)
- return ret;
- }
-
- /* version >= 2 */
- for (int i = 0; i < 2; i++)
- if ((ret = vlc_init(&s->block_pattern_vlc[i], 3, 14,
- &vp4_block_pattern_vlc[i][0][1], 2, 1,
- &vp4_block_pattern_vlc[i][0][0], 2, 1, 0)) < 0)
- return ret;
-#endif
+ ff_thread_once(&init_static_once, init_tables_once);
return allocate_tables(avctx);
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 03/61] avcodec/vp3: Increase some VLC tables
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 02/61] avcodec/vp3: Make VLC tables static where possible Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 04/61] avcodec/h264_cavlc: Avoid superfluous VLC structures Andreas Rheinhardt
` (58 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
These are quite small and therefore force reloads
that can be avoided by modest increases in the number of bits used.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vp3.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 9199f53397..0463909f2f 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -164,7 +164,7 @@ static VLCElem fragment_run_length_vlc[56]; /* version < 2 */
static VLCElem motion_vector_vlc[112]; /* version < 2 */
// The VP4 tables reuse this vlc.
-static VLCElem mode_code_vlc[18 + 2084 * CONFIG_VP4_DECODER];
+static VLCElem mode_code_vlc[24 + 2108 * CONFIG_VP4_DECODER];
#if CONFIG_VP4_DECODER
static const VLCElem *vp4_mv_vlc_table[2][7]; /* version >= 2 */
@@ -681,7 +681,7 @@ static int vp4_get_mb_count(Vp3DecodeContext *s, GetBitContext *gb)
static int vp4_get_block_pattern(GetBitContext *gb, int *next_block_pattern_table)
{
- int v = get_vlc2(gb, block_pattern_vlc[*next_block_pattern_table], 3, 2);
+ int v = get_vlc2(gb, block_pattern_vlc[*next_block_pattern_table], 5, 1);
*next_block_pattern_table = vp4_block_pattern_table_selector[v];
return v + 1;
}
@@ -840,7 +840,7 @@ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
if (scheme == 7)
coding_mode = get_bits(gb, 3);
else
- coding_mode = alphabet[get_vlc2(gb, mode_code_vlc, 3, 3)];
+ coding_mode = alphabet[get_vlc2(gb, mode_code_vlc, 4, 2)];
s->macroblock_coding[current_macroblock] = coding_mode;
for (k = 0; k < 4; k++) {
@@ -2275,7 +2275,7 @@ static av_cold void init_tables_once(void)
&motion_vector_vlc_table[0][0], 2, 1,
-31, 0);
- ff_vlc_init_tables_from_lengths(&state, 3, 8,
+ ff_vlc_init_tables_from_lengths(&state, 4, 8,
mode_code_vlc_len, 1,
NULL, 0, 0, 0, 0);
@@ -2292,7 +2292,7 @@ static av_cold void init_tables_once(void)
/* version >= 2 */
for (int i = 0; i < 2; i++) {
block_pattern_vlc[i] =
- ff_vlc_init_tables(&state, 3, 14,
+ ff_vlc_init_tables(&state, 5, 14,
&vp4_block_pattern_vlc[i][0][1], 2, 1,
&vp4_block_pattern_vlc[i][0][0], 2, 1, 0);
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 04/61] avcodec/h264_cavlc: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 02/61] avcodec/vp3: Make VLC tables static where possible Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 03/61] avcodec/vp3: Increase some VLC tables Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 05/61] avcodec/h264_cavlc: Avoid indirection for coefficient table VLCs Andreas Rheinhardt
` (57 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h264_cavlc.c | 190 +++++++++++++++++-----------------------
1 file changed, 80 insertions(+), 110 deletions(-)
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index a06b775422..dc22955626 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -234,38 +234,6 @@ static const uint8_t run_bits[7][16]={
{7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
};
-static VLC coeff_token_vlc[4];
-static VLCElem coeff_token_vlc_tables[520+332+280+256];
-static const int coeff_token_vlc_tables_size[4]={520,332,280,256};
-
-static VLC chroma_dc_coeff_token_vlc;
-static VLCElem chroma_dc_coeff_token_vlc_table[256];
-static const int chroma_dc_coeff_token_vlc_table_size = 256;
-
-static VLC chroma422_dc_coeff_token_vlc;
-static VLCElem chroma422_dc_coeff_token_vlc_table[8192];
-static const int chroma422_dc_coeff_token_vlc_table_size = 8192;
-
-static VLC total_zeros_vlc[15+1];
-static VLCElem total_zeros_vlc_tables[15][512];
-static const int total_zeros_vlc_tables_size = 512;
-
-static VLC chroma_dc_total_zeros_vlc[3+1];
-static VLCElem chroma_dc_total_zeros_vlc_tables[3][8];
-static const int chroma_dc_total_zeros_vlc_tables_size = 8;
-
-static VLC chroma422_dc_total_zeros_vlc[7+1];
-static VLCElem chroma422_dc_total_zeros_vlc_tables[7][32];
-static const int chroma422_dc_total_zeros_vlc_tables_size = 32;
-
-static VLC run_vlc[6+1];
-static VLCElem run_vlc_tables[6][8];
-static const int run_vlc_tables_size = 8;
-
-static VLC run7_vlc;
-static VLCElem run7_vlc_table[96];
-static const int run7_vlc_table_size = 96;
-
#define LEVEL_TAB_BITS 8
static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
@@ -278,6 +246,27 @@ static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
#define RUN_VLC_BITS 3
#define RUN7_VLC_BITS 6
+static const VLCElem *coeff_token_vlc[4];
+
+static VLCElem chroma_dc_coeff_token_vlc_table[256];
+
+static VLCElem chroma422_dc_coeff_token_vlc_table[1 << CHROMA422_DC_COEFF_TOKEN_VLC_BITS];
+
+static const VLCElem *total_zeros_vlc[15+1];
+
+static const VLCElem *chroma_dc_total_zeros_vlc[3+1];
+
+static const VLCElem *chroma422_dc_total_zeros_vlc[7+1];
+
+static const VLCElem *run_vlc[6+1];
+
+// The other pointers to VLCElem point into this array.
+static VLCElem run7_vlc_table[96 + (6 << RUN_VLC_BITS)
+ + (15 << TOTAL_ZEROS_VLC_BITS)
+ + (3 << CHROMA_DC_TOTAL_ZEROS_VLC_BITS)
+ + (7 << CHROMA422_DC_TOTAL_ZEROS_VLC_BITS)
+ + (520 + 332 + 280 + 256) /* coeff token */];
+
/**
* Get the predicted number of non-zero coefficients.
* @param n block index
@@ -324,84 +313,60 @@ static av_cold void init_cavlc_level_tab(void){
av_cold void ff_h264_decode_init_vlc(void)
{
- int offset;
-
- chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table;
- chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size;
- vlc_init(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
- &chroma_dc_coeff_token_len [0], 1, 1,
- &chroma_dc_coeff_token_bits[0], 1, 1,
- VLC_INIT_USE_STATIC);
-
- chroma422_dc_coeff_token_vlc.table = chroma422_dc_coeff_token_vlc_table;
- chroma422_dc_coeff_token_vlc.table_allocated = chroma422_dc_coeff_token_vlc_table_size;
- vlc_init(&chroma422_dc_coeff_token_vlc, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4*9,
- &chroma422_dc_coeff_token_len [0], 1, 1,
- &chroma422_dc_coeff_token_bits[0], 1, 1,
- VLC_INIT_USE_STATIC);
-
- offset = 0;
+ VLCInitState state = VLC_INIT_STATE(run7_vlc_table);
+
+ VLC_INIT_STATIC_TABLE(chroma_dc_coeff_token_vlc_table,
+ CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4 * 5,
+ &chroma_dc_coeff_token_len [0], 1, 1,
+ &chroma_dc_coeff_token_bits[0], 1, 1, 0);
+
+ VLC_INIT_STATIC_TABLE(chroma422_dc_coeff_token_vlc_table,
+ CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4 * 9,
+ &chroma422_dc_coeff_token_len [0], 1, 1,
+ &chroma422_dc_coeff_token_bits[0], 1, 1, 0);
+
+ ff_vlc_init_tables(&state, RUN7_VLC_BITS, 16,
+ &run_len [6][0], 1, 1,
+ &run_bits[6][0], 1, 1, 0);
+
+ for (int i = 0; i < 6; i++) {
+ run_vlc[i + 1] = ff_vlc_init_tables(&state, RUN_VLC_BITS, 7,
+ &run_len [i][0], 1, 1,
+ &run_bits[i][0], 1, 1, 0);
+ }
+
for (int i = 0; i < 4; i++) {
- coeff_token_vlc[i].table = coeff_token_vlc_tables + offset;
- coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i];
- vlc_init(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17,
- &coeff_token_len [i][0], 1, 1,
- &coeff_token_bits[i][0], 1, 1,
- VLC_INIT_USE_STATIC);
- offset += coeff_token_vlc_tables_size[i];
+ coeff_token_vlc[i] =
+ ff_vlc_init_tables(&state, COEFF_TOKEN_VLC_BITS, 4*17,
+ &coeff_token_len [i][0], 1, 1,
+ &coeff_token_bits[i][0], 1, 1, 0);
}
- /*
- * This is a one time safety check to make sure that
- * the packed static coeff_token_vlc table sizes
- * were initialized correctly.
- */
- av_assert0(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables));
for (int i = 0; i < 3; i++) {
- chroma_dc_total_zeros_vlc[i + 1].table = chroma_dc_total_zeros_vlc_tables[i];
- chroma_dc_total_zeros_vlc[i + 1].table_allocated = chroma_dc_total_zeros_vlc_tables_size;
- vlc_init(&chroma_dc_total_zeros_vlc[i + 1],
- CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
- &chroma_dc_total_zeros_len [i][0], 1, 1,
- &chroma_dc_total_zeros_bits[i][0], 1, 1,
- VLC_INIT_USE_STATIC);
+ chroma_dc_total_zeros_vlc[i + 1] =
+ ff_vlc_init_tables(&state, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
+ &chroma_dc_total_zeros_len [i][0], 1, 1,
+ &chroma_dc_total_zeros_bits[i][0], 1, 1, 0);
}
for (int i = 0; i < 7; i++) {
- chroma422_dc_total_zeros_vlc[i + 1].table = chroma422_dc_total_zeros_vlc_tables[i];
- chroma422_dc_total_zeros_vlc[i + 1].table_allocated = chroma422_dc_total_zeros_vlc_tables_size;
- vlc_init(&chroma422_dc_total_zeros_vlc[i + 1],
- CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8,
- &chroma422_dc_total_zeros_len [i][0], 1, 1,
- &chroma422_dc_total_zeros_bits[i][0], 1, 1,
- VLC_INIT_USE_STATIC);
+ chroma422_dc_total_zeros_vlc[i + 1] =
+ ff_vlc_init_tables(&state, CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8,
+ &chroma422_dc_total_zeros_len [i][0], 1, 1,
+ &chroma422_dc_total_zeros_bits[i][0], 1, 1, 0);
}
for (int i = 0; i < 15; i++) {
- total_zeros_vlc[i + 1].table = total_zeros_vlc_tables[i];
- total_zeros_vlc[i + 1].table_allocated = total_zeros_vlc_tables_size;
- vlc_init(&total_zeros_vlc[i + 1],
- TOTAL_ZEROS_VLC_BITS, 16,
- &total_zeros_len [i][0], 1, 1,
- &total_zeros_bits[i][0], 1, 1,
- VLC_INIT_USE_STATIC);
- }
-
- for (int i = 0; i < 6; i++) {
- run_vlc[i + 1].table = run_vlc_tables[i];
- run_vlc[i + 1].table_allocated = run_vlc_tables_size;
- vlc_init(&run_vlc[i + 1],
- RUN_VLC_BITS, 7,
- &run_len [i][0], 1, 1,
- &run_bits[i][0], 1, 1,
- VLC_INIT_USE_STATIC);
+ total_zeros_vlc[i + 1] =
+ ff_vlc_init_tables(&state, TOTAL_ZEROS_VLC_BITS, 16,
+ &total_zeros_len [i][0], 1, 1,
+ &total_zeros_bits[i][0], 1, 1, 0);
}
- run7_vlc.table = run7_vlc_table;
- run7_vlc.table_allocated = run7_vlc_table_size;
- vlc_init(&run7_vlc, RUN7_VLC_BITS, 16,
- &run_len [6][0], 1, 1,
- &run_bits[6][0], 1, 1,
- VLC_INIT_USE_STATIC);
+ /*
+ * This is a one time safety check to make sure that
+ * the vlc table sizes were initialized correctly.
+ */
+ av_assert1(state.size == 0);
init_cavlc_level_tab();
}
@@ -442,18 +407,22 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl,
if(max_coeff <= 8){
if (max_coeff == 4)
- coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
+ coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc_table,
+ CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
else
- coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);
+ coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc_table,
+ CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);
total_coeff= coeff_token>>2;
}else{
if(n >= LUMA_DC_BLOCK_INDEX){
total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);
- coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
+ coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]],
+ COEFF_TOKEN_VLC_BITS, 2);
total_coeff= coeff_token>>2;
}else{
total_coeff= pred_non_zero_count(h, sl, n);
- coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
+ coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]],
+ COEFF_TOKEN_VLC_BITS, 2);
total_coeff= coeff_token>>2;
}
}
@@ -563,13 +532,14 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl,
else{
if (max_coeff <= 8) {
if (max_coeff == 4)
- zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff].table,
+ zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff],
CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
else
- zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff].table,
+ zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff],
CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1);
} else {
- zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
+ zeros_left = get_vlc2(gb, total_zeros_vlc[total_coeff],
+ TOTAL_ZEROS_VLC_BITS, 1);
}
}
@@ -579,9 +549,9 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl,
((type*)block)[*scantable] = level[0]; \
for(i=1;i<total_coeff && zeros_left > 0;i++) { \
if(zeros_left < 7) \
- run_before= get_vlc2(gb, run_vlc[zeros_left].table, RUN_VLC_BITS, 1); \
+ run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \
else \
- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
+ run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \
zeros_left -= run_before; \
scantable -= 1 + run_before; \
((type*)block)[*scantable]= level[i]; \
@@ -594,9 +564,9 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl,
((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \
for(i=1;i<total_coeff && zeros_left > 0;i++) { \
if(zeros_left < 7) \
- run_before= get_vlc2(gb, run_vlc[zeros_left].table, RUN_VLC_BITS, 1); \
+ run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \
else \
- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \
+ run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \
zeros_left -= run_before; \
scantable -= 1 + run_before; \
((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 05/61] avcodec/h264_cavlc: Avoid indirection for coefficient table VLCs
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (2 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 04/61] avcodec/h264_cavlc: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 06/61] avcodec/h264_cavlc: Remove code duplication Andreas Rheinhardt
` (56 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h264_cavlc.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index dc22955626..f17e30e853 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -246,7 +246,8 @@ static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
#define RUN_VLC_BITS 3
#define RUN7_VLC_BITS 6
-static const VLCElem *coeff_token_vlc[4];
+/// 17 pointers to only four different VLCs
+static const VLCElem *coeff_token_vlc[17];
static VLCElem chroma_dc_coeff_token_vlc_table[256];
@@ -313,6 +314,7 @@ static av_cold void init_cavlc_level_tab(void){
av_cold void ff_h264_decode_init_vlc(void)
{
+ const VLCElem *coeff_token_vlc_original[4];
VLCInitState state = VLC_INIT_STATE(run7_vlc_table);
VLC_INIT_STATIC_TABLE(chroma_dc_coeff_token_vlc_table,
@@ -336,11 +338,17 @@ av_cold void ff_h264_decode_init_vlc(void)
}
for (int i = 0; i < 4; i++) {
- coeff_token_vlc[i] =
+ coeff_token_vlc_original[i] =
ff_vlc_init_tables(&state, COEFF_TOKEN_VLC_BITS, 4*17,
&coeff_token_len [i][0], 1, 1,
&coeff_token_bits[i][0], 1, 1, 0);
}
+ for (int i = 0; i < FF_ARRAY_ELEMS(coeff_token_vlc); i++) {
+ static const uint8_t coeff_token_table_index[17] = {
+ 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3
+ };
+ coeff_token_vlc[i] = coeff_token_vlc_original[coeff_token_table_index[i]];
+ }
for (int i = 0; i < 3; i++) {
chroma_dc_total_zeros_vlc[i + 1] =
@@ -399,7 +407,6 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl,
const uint8_t *scantable, const uint32_t *qmul,
int max_coeff)
{
- static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
int level[16];
int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
@@ -416,12 +423,12 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl,
}else{
if(n >= LUMA_DC_BLOCK_INDEX){
total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);
- coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]],
+ coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
COEFF_TOKEN_VLC_BITS, 2);
total_coeff= coeff_token>>2;
}else{
total_coeff= pred_non_zero_count(h, sl, n);
- coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]],
+ coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
COEFF_TOKEN_VLC_BITS, 2);
total_coeff= coeff_token>>2;
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 06/61] avcodec/h264_cavlc: Remove code duplication
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (3 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 05/61] avcodec/h264_cavlc: Avoid indirection for coefficient table VLCs Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 07/61] avcodec/asvdec: Avoid superfluous VLC structures Andreas Rheinhardt
` (55 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h264_cavlc.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index f17e30e853..19f067afb4 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -419,20 +419,13 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl,
else
coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc_table,
CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1);
- total_coeff= coeff_token>>2;
}else{
- if(n >= LUMA_DC_BLOCK_INDEX){
- total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);
- coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
- COEFF_TOKEN_VLC_BITS, 2);
- total_coeff= coeff_token>>2;
- }else{
- total_coeff= pred_non_zero_count(h, sl, n);
- coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
- COEFF_TOKEN_VLC_BITS, 2);
- total_coeff= coeff_token>>2;
- }
+ total_coeff = pred_non_zero_count(h, sl, n >= LUMA_DC_BLOCK_INDEX ?
+ (n - LUMA_DC_BLOCK_INDEX) * 16 : n);
+ coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
+ COEFF_TOKEN_VLC_BITS, 2);
}
+ total_coeff = coeff_token >> 2;
sl->non_zero_count_cache[scan8[n]] = total_coeff;
//FIXME set last_non_zero?
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 07/61] avcodec/asvdec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (4 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 06/61] avcodec/h264_cavlc: Remove code duplication Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 08/61] avcodec/faxcompr: " Andreas Rheinhardt
` (54 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/asvdec.c | 50 ++++++++++++++++++++++-----------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index 7ad4faebf9..568881ccd2 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -45,11 +45,11 @@
#define ASV1_LEVEL_VLC_BITS 4
#define ASV2_LEVEL_VLC_BITS 10
-static VLC ccp_vlc;
-static VLC level_vlc;
-static VLC dc_ccp_vlc;
-static VLC ac_ccp_vlc;
-static VLC asv2_level_vlc;
+static VLCElem ccp_vlc[32];
+static VLCElem level_vlc[16];
+static VLCElem dc_ccp_vlc[16];
+static VLCElem ac_ccp_vlc[64];
+static VLCElem asv2_level_vlc[1024];
typedef struct ASVDecContext {
ASVCommonContext c;
@@ -67,26 +67,26 @@ typedef struct ASVDecContext {
static av_cold void init_vlcs(void)
{
- VLC_INIT_STATIC(&ccp_vlc, CCP_VLC_BITS, 17,
- &ff_asv_ccp_tab[0][1], 2, 1,
- &ff_asv_ccp_tab[0][0], 2, 1, 32);
- VLC_INIT_LE_STATIC(&dc_ccp_vlc, DC_CCP_VLC_BITS, 8,
- &ff_asv_dc_ccp_tab[0][1], 2, 1,
- &ff_asv_dc_ccp_tab[0][0], 2, 1, 16);
- VLC_INIT_LE_STATIC(&ac_ccp_vlc, AC_CCP_VLC_BITS, 16,
- &ff_asv_ac_ccp_tab[0][1], 2, 1,
- &ff_asv_ac_ccp_tab[0][0], 2, 1, 64);
- VLC_INIT_STATIC(&level_vlc, ASV1_LEVEL_VLC_BITS, 7,
- &ff_asv_level_tab[0][1], 2, 1,
- &ff_asv_level_tab[0][0], 2, 1, 16);
- VLC_INIT_LE_STATIC(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
- &ff_asv2_level_tab[0][1], 4, 2,
- &ff_asv2_level_tab[0][0], 4, 2, 1024);
+ VLC_INIT_STATIC_TABLE(ccp_vlc, CCP_VLC_BITS, 17,
+ &ff_asv_ccp_tab[0][1], 2, 1,
+ &ff_asv_ccp_tab[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(dc_ccp_vlc, DC_CCP_VLC_BITS, 8,
+ &ff_asv_dc_ccp_tab[0][1], 2, 1,
+ &ff_asv_dc_ccp_tab[0][0], 2, 1, VLC_INIT_LE);
+ VLC_INIT_STATIC_TABLE(ac_ccp_vlc, AC_CCP_VLC_BITS, 16,
+ &ff_asv_ac_ccp_tab[0][1], 2, 1,
+ &ff_asv_ac_ccp_tab[0][0], 2, 1, VLC_INIT_LE);
+ VLC_INIT_STATIC_TABLE(level_vlc, ASV1_LEVEL_VLC_BITS, 7,
+ &ff_asv_level_tab[0][1], 2, 1,
+ &ff_asv_level_tab[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
+ &ff_asv2_level_tab[0][1], 4, 2,
+ &ff_asv2_level_tab[0][0], 4, 2, VLC_INIT_LE);
}
static inline int asv1_get_level(GetBitContext *gb)
{
- int code = get_vlc2(gb, level_vlc.table, ASV1_LEVEL_VLC_BITS, 1);
+ int code = get_vlc2(gb, level_vlc, ASV1_LEVEL_VLC_BITS, 1);
if (code == 3)
return get_sbits(gb, 8);
@@ -115,7 +115,7 @@ static inline int asv2_get_vlc2(GetBitContext *gb, const VLCElem *table, int bit
static inline int asv2_get_level(GetBitContext *gb)
{
- int code = asv2_get_vlc2(gb, asv2_level_vlc.table, ASV2_LEVEL_VLC_BITS);
+ int code = asv2_get_vlc2(gb, asv2_level_vlc, ASV2_LEVEL_VLC_BITS);
if (code == 31)
return (int8_t) get_bits_le(gb, 8);
@@ -130,7 +130,7 @@ static inline int asv1_decode_block(ASVDecContext *a, int16_t block[64])
block[0] = 8 * get_bits(&a->gb, 8);
for (i = 0; i < 11; i++) {
- const int ccp = get_vlc2(&a->gb, ccp_vlc.table, CCP_VLC_BITS, 1);
+ const int ccp = get_vlc2(&a->gb, ccp_vlc, CCP_VLC_BITS, 1);
if (ccp) {
if (ccp == 16)
@@ -162,7 +162,7 @@ static inline int asv2_decode_block(ASVDecContext *a, int16_t block[64])
block[0] = 8 * get_bits_le(&a->gb, 8);
- ccp = asv2_get_vlc2(&a->gb, dc_ccp_vlc.table, DC_CCP_VLC_BITS);
+ ccp = asv2_get_vlc2(&a->gb, dc_ccp_vlc, DC_CCP_VLC_BITS);
if (ccp) {
if (ccp & 4)
block[a->permutated_scantable[1]] = (asv2_get_level(&a->gb) * a->intra_matrix[1]) >> 4;
@@ -173,7 +173,7 @@ static inline int asv2_decode_block(ASVDecContext *a, int16_t block[64])
}
for (i = 1; i < count + 1; i++) {
- const int ccp = asv2_get_vlc2(&a->gb, ac_ccp_vlc.table, AC_CCP_VLC_BITS);
+ const int ccp = asv2_get_vlc2(&a->gb, ac_ccp_vlc, AC_CCP_VLC_BITS);
if (ccp) {
if (ccp & 8)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 08/61] avcodec/faxcompr: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (5 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 07/61] avcodec/asvdec: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 09/61] avcodec/h261dec: " Andreas Rheinhardt
` (53 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/faxcompr.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
index 62729fe90f..41a1eec081 100644
--- a/libavcodec/faxcompr.c
+++ b/libavcodec/faxcompr.c
@@ -95,28 +95,24 @@ static const uint8_t ccitt_group3_2d_lens[11] = {
4, 3, 7, 6, 3, 1, 3, 6, 7, 7, 9
};
-static VLC ccitt_vlc[2], ccitt_group3_2d_vlc;
+// Also contains the other VLC tables pointed to by ccitt_vlc
+static VLCElem ccitt_group3_2d_vlc[512 + 528 + 648];
+static const VLCElem *ccitt_vlc[2];
static av_cold void ccitt_unpack_init(void)
{
- static VLCElem code_table1[528];
- static VLCElem code_table2[648];
+ VLCInitState state = VLC_INIT_STATE(ccitt_group3_2d_vlc);
int i;
- ccitt_vlc[0].table = code_table1;
- ccitt_vlc[0].table_allocated = 528;
- ccitt_vlc[1].table = code_table2;
- ccitt_vlc[1].table_allocated = 648;
+ ff_vlc_init_tables(&state, 9, 11,
+ ccitt_group3_2d_lens, 1, 1,
+ ccitt_group3_2d_bits, 1, 1, 0);
for (i = 0; i < 2; i++) {
- ff_vlc_init_sparse(&ccitt_vlc[i], 9, CCITT_SYMS,
- ccitt_codes_lens[i], 1, 1,
- ccitt_codes_bits[i], 1, 1,
- ccitt_syms, 2, 2,
- VLC_INIT_USE_STATIC);
+ ccitt_vlc[i] = ff_vlc_init_tables_sparse(&state, 9, CCITT_SYMS,
+ ccitt_codes_lens[i], 1, 1,
+ ccitt_codes_bits[i], 1, 1,
+ ccitt_syms, 2, 2, 0);
}
- VLC_INIT_STATIC(&ccitt_group3_2d_vlc, 9, 11,
- ccitt_group3_2d_lens, 1, 1,
- ccitt_group3_2d_bits, 1, 1, 512);
}
av_cold void ff_ccitt_unpack_init(void)
@@ -213,7 +209,7 @@ static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb,
for (;;) {
if (get_bits_left(gb) <= 0)
return AVERROR_INVALIDDATA;
- t = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
+ t = get_vlc2(gb, ccitt_vlc[mode], 9, 2);
run += t;
if (t < 64) {
*runs++ = run;
@@ -261,7 +257,7 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
int cmode;
if (get_bits_left(gb) <= 0)
return AVERROR_INVALIDDATA;
- cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1);
+ cmode = get_vlc2(gb, ccitt_group3_2d_vlc, 9, 1);
if (cmode == -1) {
av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n");
return AVERROR_INVALIDDATA;
@@ -285,7 +281,7 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
for (;;) {
if (get_bits_left(gb) <= 0)
return AVERROR_INVALIDDATA;
- t = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
+ t = get_vlc2(gb, ccitt_vlc[mode], 9, 2);
if (t == -1) {
av_log(avctx, AV_LOG_ERROR, "Incorrect code\n");
return AVERROR_INVALIDDATA;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 09/61] avcodec/h261dec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (6 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 08/61] avcodec/faxcompr: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 10/61] avcodec/ituh263dec: " Andreas Rheinhardt
` (52 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index c41b96c3c7..6eb69c1120 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -44,10 +44,10 @@
#define MBA_STUFFING 33
#define MBA_STARTCODE 34
-static VLC h261_mba_vlc;
-static VLC h261_mtype_vlc;
-static VLC h261_mv_vlc;
-static VLC h261_cbp_vlc;
+static VLCElem h261_mba_vlc[540];
+static VLCElem h261_mtype_vlc[80];
+static VLCElem h261_mv_vlc[144];
+static VLCElem h261_cbp_vlc[512];
typedef struct H261DecContext {
MpegEncContext s;
@@ -64,18 +64,18 @@ typedef struct H261DecContext {
static av_cold void h261_decode_init_static(void)
{
- VLC_INIT_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
- ff_h261_mba_bits, 1, 1,
- ff_h261_mba_code, 1, 1, 540);
- VLC_INIT_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
- ff_h261_mtype_bits, 1, 1,
- ff_h261_mtype_code, 1, 1, 80);
- VLC_INIT_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
- &ff_h261_mv_tab[0][1], 2, 1,
- &ff_h261_mv_tab[0][0], 2, 1, 144);
- VLC_INIT_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
- &ff_h261_cbp_tab[0][1], 2, 1,
- &ff_h261_cbp_tab[0][0], 2, 1, 512);
+ VLC_INIT_STATIC_TABLE(h261_mba_vlc, H261_MBA_VLC_BITS, 35,
+ ff_h261_mba_bits, 1, 1,
+ ff_h261_mba_code, 1, 1, 0);
+ VLC_INIT_STATIC_TABLE(h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
+ ff_h261_mtype_bits, 1, 1,
+ ff_h261_mtype_code, 1, 1, 0);
+ VLC_INIT_STATIC_TABLE(h261_mv_vlc, H261_MV_VLC_BITS, 17,
+ &ff_h261_mv_tab[0][1], 2, 1,
+ &ff_h261_mv_tab[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
+ &ff_h261_cbp_tab[0][1], 2, 1,
+ &ff_h261_cbp_tab[0][0], 2, 1, 0);
INIT_FIRST_VLC_RL(ff_h261_rl_tcoeff, 552);
}
@@ -254,7 +254,7 @@ static const int mvmap[17] = {
static int decode_mv_component(GetBitContext *gb, int v)
{
- int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
+ int mv_diff = get_vlc2(gb, h261_mv_vlc, H261_MV_VLC_BITS, 2);
/* check if mv_diff is valid */
if (mv_diff < 0)
@@ -379,7 +379,7 @@ static int h261_decode_mb(H261DecContext *h)
cbp = 63;
// Read mba
do {
- h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table,
+ h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc,
H261_MBA_VLC_BITS, 2);
/* Check for slice end */
@@ -410,7 +410,7 @@ static int h261_decode_mb(H261DecContext *h)
h261_init_dest(s);
// Read mtype
- com->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
+ com->mtype = get_vlc2(&s->gb, h261_mtype_vlc, H261_MTYPE_VLC_BITS, 2);
if (com->mtype < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
com->mtype);
@@ -450,7 +450,7 @@ static int h261_decode_mb(H261DecContext *h)
// Read cbp
if (HAS_CBP(com->mtype))
- cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 1) + 1;
+ cbp = get_vlc2(&s->gb, h261_cbp_vlc, H261_CBP_VLC_BITS, 1) + 1;
if (s->mb_intra) {
s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 10/61] avcodec/ituh263dec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (7 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 09/61] avcodec/h261dec: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 11/61] avcodec/msmpeg4_vc1_data: " Andreas Rheinhardt
` (51 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.h | 8 ++---
libavcodec/ituh263dec.c | 68 +++++++++++++++++++-------------------
libavcodec/mpeg4videodec.c | 18 +++++-----
libavcodec/msmpeg4dec.c | 12 +++----
4 files changed, 53 insertions(+), 53 deletions(-)
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index 9f1db72903..06ff7c1c48 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -33,10 +33,10 @@
#define CBPY_VLC_BITS 6
#define TEX_VLC_BITS 9
-extern VLC ff_h263_intra_MCBPC_vlc;
-extern VLC ff_h263_inter_MCBPC_vlc;
-extern VLC ff_h263_cbpy_vlc;
-extern VLC ff_h263_mv_vlc;
+extern VLCElem ff_h263_intra_MCBPC_vlc[];
+extern VLCElem ff_h263_inter_MCBPC_vlc[];
+extern VLCElem ff_h263_cbpy_vlc[];
+extern VLCElem ff_h263_mv_vlc[];
extern const enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[];
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index f9c8476ecd..81b456405f 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -99,38 +99,38 @@ void ff_h263_show_pict_info(MpegEncContext *s){
/***********************************************/
/* decoding */
-VLC ff_h263_intra_MCBPC_vlc;
-VLC ff_h263_inter_MCBPC_vlc;
-VLC ff_h263_cbpy_vlc;
-VLC ff_h263_mv_vlc;
-static VLC h263_mbtype_b_vlc;
-static VLC cbpc_b_vlc;
+VLCElem ff_h263_intra_MCBPC_vlc[72];
+VLCElem ff_h263_inter_MCBPC_vlc[198];
+VLCElem ff_h263_cbpy_vlc[64];
+VLCElem ff_h263_mv_vlc[538];
+static VLCElem h263_mbtype_b_vlc[80];
+static VLCElem cbpc_b_vlc[8];
/* init vlcs */
static av_cold void h263_decode_init_vlc(void)
{
- VLC_INIT_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
- ff_h263_intra_MCBPC_bits, 1, 1,
- ff_h263_intra_MCBPC_code, 1, 1, 72);
- VLC_INIT_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
- ff_h263_inter_MCBPC_bits, 1, 1,
- ff_h263_inter_MCBPC_code, 1, 1, 198);
- VLC_INIT_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
- &ff_h263_cbpy_tab[0][1], 2, 1,
- &ff_h263_cbpy_tab[0][0], 2, 1, 64);
- VLC_INIT_STATIC(&ff_h263_mv_vlc, H263_MV_VLC_BITS, 33,
- &ff_mvtab[0][1], 2, 1,
- &ff_mvtab[0][0], 2, 1, 538);
+ VLC_INIT_STATIC_TABLE(ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
+ ff_h263_intra_MCBPC_bits, 1, 1,
+ ff_h263_intra_MCBPC_code, 1, 1, 0);
+ VLC_INIT_STATIC_TABLE(ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
+ ff_h263_inter_MCBPC_bits, 1, 1,
+ ff_h263_inter_MCBPC_code, 1, 1, 0);
+ VLC_INIT_STATIC_TABLE(ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
+ &ff_h263_cbpy_tab[0][1], 2, 1,
+ &ff_h263_cbpy_tab[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(ff_h263_mv_vlc, H263_MV_VLC_BITS, 33,
+ &ff_mvtab[0][1], 2, 1,
+ &ff_mvtab[0][0], 2, 1, 0);
ff_h263_init_rl_inter();
VLC_INIT_RL(ff_h263_rl_inter, 554);
INIT_FIRST_VLC_RL(ff_rl_intra_aic, 554);
- VLC_INIT_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
- &ff_h263_mbtype_b_tab[0][1], 2, 1,
- &ff_h263_mbtype_b_tab[0][0], 2, 1, 80);
- VLC_INIT_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
- &ff_cbpc_b_tab[0][1], 2, 1,
- &ff_cbpc_b_tab[0][0], 2, 1, 8);
+ VLC_INIT_STATIC_TABLE(h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
+ &ff_h263_mbtype_b_tab[0][1], 2, 1,
+ &ff_h263_mbtype_b_tab[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
+ &ff_cbpc_b_tab[0][1], 2, 1,
+ &ff_cbpc_b_tab[0][0], 2, 1, 0);
}
av_cold void ff_h263_decode_init_vlc(void)
@@ -273,7 +273,7 @@ int ff_h263_resync(MpegEncContext *s){
int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
{
int code, val, sign, shift;
- code = get_vlc2(&s->gb, ff_h263_mv_vlc.table, H263_MV_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
if (code == 0)
return pred;
@@ -366,13 +366,13 @@ static void preview_obmc(MpegEncContext *s){
s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
goto end;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
}while(cbpc == 20);
if(cbpc & 4){
s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
}else{
- get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpc & 8) {
if(s->modified_quant){
if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
@@ -809,7 +809,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->mb_skipped = !(s->obmc | s->loop_filter);
goto end;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0){
av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
return SLICE_ERROR;
@@ -824,7 +824,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
if(s->pb_frame && get_bits1(&s->gb))
pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(s->avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
@@ -905,7 +905,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
do{
- mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2);
+ mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 2);
if (mb_type < 0){
av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
return SLICE_ERROR;
@@ -917,13 +917,13 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->mb_intra = IS_INTRA(mb_type);
if(HAS_CBP(mb_type)){
s->bdsp.clear_blocks(s->block[0]);
- cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1);
+ cbpc = get_vlc2(&s->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
if(s->mb_intra){
dquant = IS_QUANT(mb_type);
goto intra;
}
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0){
av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
@@ -1009,7 +1009,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
s->current_picture.mb_type[xy] = mb_type;
} else { /* I-Frame */
do{
- cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0){
av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
return SLICE_ERROR;
@@ -1034,7 +1034,7 @@ intra:
if(s->pb_frame && get_bits1(&s->gb))
pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if(cbpy<0){
av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
return SLICE_ERROR;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index a8dd57bf6b..51a2c7fe35 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -960,7 +960,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
if (show_bits(&s->gb, 19) == DC_MARKER)
return mb_num - 1;
- cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
@@ -1032,7 +1032,7 @@ try_again:
continue;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
@@ -1147,7 +1147,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
if (s->pict_type == AV_PICTURE_TYPE_I) {
int ac_pred = get_bits1(&s->gb);
- int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
@@ -1161,7 +1161,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
int i;
int dir = 0;
int ac_pred = get_bits1(&s->gb);
- int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(s->avctx, AV_LOG_ERROR,
@@ -1193,7 +1193,7 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
s->current_picture.qscale_table[xy] = s->qscale;
s->cbp_table[xy] = 0;
} else {
- int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(s->avctx, AV_LOG_ERROR,
@@ -1689,7 +1689,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
}
goto end;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"mcbpc damaged at %d %d\n", s->mb_x, s->mb_y);
@@ -1708,7 +1708,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mcsel = get_bits1(&s->gb);
else
s->mcsel = 0;
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F;
+ cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
if (cbpy < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"P cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
@@ -1951,7 +1951,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
int use_intra_dc_vlc;
do {
- cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
@@ -1969,7 +1969,7 @@ intra:
else
s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index a81241b1bb..e61045c2f9 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -75,7 +75,7 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
{
int code, val, sign, shift;
- code = get_vlc2(&s->gb, ff_h263_mv_vlc.table, H263_MV_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
ff_dlog(s, "MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
if (code < 0)
return 0xffff;
@@ -127,7 +127,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
if(s->msmpeg4_version==2)
code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1);
else
- code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if(code<0 || code>7){
av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
return -1;
@@ -141,7 +141,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
if(s->msmpeg4_version==2)
cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1);
else
- cbp= get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+ cbp = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if(cbp<0 || cbp>3){
av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
return -1;
@@ -151,7 +151,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
if (!s->mb_intra) {
int mx, my, cbpy;
- cbpy= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if(cbpy<0){
av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
return -1;
@@ -173,7 +173,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
int v;
if(s->msmpeg4_version==2){
s->ac_pred = get_bits1(&s->gb);
- v = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (v < 0) {
av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
return -1;
@@ -181,7 +181,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
cbp|= v<<2;
} else{
s->ac_pred = 0;
- v = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
+ v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (v < 0) {
av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
return -1;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 11/61] avcodec/msmpeg4_vc1_data: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (8 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 10/61] avcodec/ituh263dec: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 12/61] avcodec/svq1dec: " Andreas Rheinhardt
` (50 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Also combine the ff_msmp4_dc_(luma|chroma)_vlcs as well
as the tables used to generate them to simplify the code.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/msmpeg4_vc1_data.c | 61 +++++++++++++++++------------------
libavcodec/msmpeg4_vc1_data.h | 10 ++----
libavcodec/msmpeg4dec.c | 13 +++-----
libavcodec/msmpeg4enc.c | 15 ++-------
libavcodec/vc1_block.c | 31 +++++-------------
libavcodec/wmv2dec.c | 2 +-
6 files changed, 48 insertions(+), 84 deletions(-)
diff --git a/libavcodec/msmpeg4_vc1_data.c b/libavcodec/msmpeg4_vc1_data.c
index e643668730..a25eb956ff 100644
--- a/libavcodec/msmpeg4_vc1_data.c
+++ b/libavcodec/msmpeg4_vc1_data.c
@@ -32,28 +32,25 @@
#include "libavutil/attributes.h"
#include "libavutil/thread.h"
-VLC ff_msmp4_mb_i_vlc;
-VLC ff_msmp4_dc_luma_vlc[2];
-VLC ff_msmp4_dc_chroma_vlc[2];
+VLCElem ff_msmp4_mb_i_vlc[536];
+const VLCElem *ff_msmp4_dc_vlc[2][2];
static av_cold void msmp4_vc1_vlcs_init(void)
{
- VLC_INIT_STATIC(&ff_msmp4_dc_luma_vlc[0], MSMP4_DC_VLC_BITS, 120,
- &ff_table0_dc_lum[0][1], 8, 4,
- &ff_table0_dc_lum[0][0], 8, 4, 1158);
- VLC_INIT_STATIC(&ff_msmp4_dc_chroma_vlc[0], MSMP4_DC_VLC_BITS, 120,
- &ff_table0_dc_chroma[0][1], 8, 4,
- &ff_table0_dc_chroma[0][0], 8, 4, 1118);
- VLC_INIT_STATIC(&ff_msmp4_dc_luma_vlc[1], MSMP4_DC_VLC_BITS, 120,
- &ff_table1_dc_lum[0][1], 8, 4,
- &ff_table1_dc_lum[0][0], 8, 4, 1476);
- VLC_INIT_STATIC(&ff_msmp4_dc_chroma_vlc[1], MSMP4_DC_VLC_BITS, 120,
- &ff_table1_dc_chroma[0][1], 8, 4,
- &ff_table1_dc_chroma[0][0], 8, 4, 1216);
+ static VLCElem vlc_buf[1158 + 1118 + 1476 + 1216];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
- VLC_INIT_STATIC(&ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 64,
- &ff_msmp4_mb_i_table[0][1], 4, 2,
- &ff_msmp4_mb_i_table[0][0], 4, 2, 536);
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 2; j++) {
+ ff_msmp4_dc_vlc[i][j] =
+ ff_vlc_init_tables(&state, MSMP4_DC_VLC_BITS, 120,
+ &ff_msmp4_dc_tables[i][j][0][1], 8, 4,
+ &ff_msmp4_dc_tables[i][j][0][0], 8, 4, 0);
+ }
+ }
+ VLC_INIT_STATIC_TABLE(ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 64,
+ &ff_msmp4_mb_i_table[0][1], 4, 2,
+ &ff_msmp4_mb_i_table[0][0], 4, 2, 0);
}
av_cold void ff_msmp4_vc1_vlcs_init_once(void)
@@ -82,9 +79,11 @@ const uint16_t ff_msmp4_mb_i_table[64][2] = {
{ 0xd, 8 }, { 0x713, 13 }, { 0x1da, 10 }, { 0x169, 10 },
};
-/* dc table 0 */
-const uint32_t ff_table0_dc_lum[120][2] = {
+const uint32_t ff_msmp4_dc_tables[2][2][120][2] = {
+{
+ /* dc table 0 */
+ {
{ 0x1, 1 }, { 0x1, 2 }, { 0x1, 4 }, { 0x1, 5 },
{ 0x5, 5 }, { 0x7, 5 }, { 0x8, 6 }, { 0xc, 6 },
{ 0x0, 7 }, { 0x2, 7 }, { 0x12, 7 }, { 0x1a, 7 },
@@ -115,9 +114,8 @@ const uint32_t ff_table0_dc_lum[120][2] = {
{ 0x60784, 24 }, { 0x60785, 24 }, { 0x60786, 24 }, { 0x60787, 24 },
{ 0x60788, 24 }, { 0x60789, 24 }, { 0x6078a, 24 }, { 0x6078b, 24 },
{ 0x6078c, 24 }, { 0x6078d, 24 }, { 0x6078e, 24 }, { 0x6078f, 24 },
-};
-
-const uint32_t ff_table0_dc_chroma[120][2] = {
+ },
+ {
{ 0x0, 2 }, { 0x1, 2 }, { 0x5, 3 }, { 0x9, 4 },
{ 0xd, 4 }, { 0x11, 5 }, { 0x1d, 5 }, { 0x1f, 5 },
{ 0x21, 6 }, { 0x31, 6 }, { 0x38, 6 }, { 0x33, 6 },
@@ -148,11 +146,11 @@ const uint32_t ff_table0_dc_chroma[120][2] = {
{ 0x608884, 23 }, { 0x608885, 23 }, { 0x608886, 23 }, { 0x608887, 23 },
{ 0x608888, 23 }, { 0x608889, 23 }, { 0x60888a, 23 }, { 0x60888b, 23 },
{ 0x60888c, 23 }, { 0x60888d, 23 }, { 0x60888e, 23 }, { 0x60888f, 23 },
-};
-
-/* dc table 1 */
-
-const uint32_t ff_table1_dc_lum[120][2] = {
+ }
+},
+{
+ /* dc table 1 */
+ {
{ 0x2, 2 }, { 0x3, 2 }, { 0x3, 3 }, { 0x2, 4 },
{ 0x5, 4 }, { 0x1, 5 }, { 0x3, 5 }, { 0x8, 5 },
{ 0x0, 6 }, { 0x5, 6 }, { 0xd, 6 }, { 0xf, 6 },
@@ -183,9 +181,8 @@ const uint32_t ff_table1_dc_lum[120][2] = {
{ 0x1e695c, 26 }, { 0x1e695d, 26 }, { 0x1e695e, 26 }, { 0x1e695f, 26 },
{ 0x1e6960, 26 }, { 0x1e6961, 26 }, { 0x1e6962, 26 }, { 0x1e6963, 26 },
{ 0x1e6964, 26 }, { 0x1e6965, 26 }, { 0x1e6966, 26 }, { 0x1e6967, 26 },
-};
-
-const uint32_t ff_table1_dc_chroma[120][2] = {
+ },
+ {
{ 0x0, 2 }, { 0x1, 2 }, { 0x4, 3 }, { 0x7, 3 },
{ 0xb, 4 }, { 0xd, 4 }, { 0x15, 5 }, { 0x28, 6 },
{ 0x30, 6 }, { 0x32, 6 }, { 0x52, 7 }, { 0x62, 7 },
@@ -216,6 +213,8 @@ const uint32_t ff_table1_dc_chroma[120][2] = {
{ 0x18f6484, 25 }, { 0x18f6485, 25 }, { 0x18f6486, 25 }, { 0x18f6487, 25 },
{ 0x18f6488, 25 }, { 0x18f6489, 25 }, { 0x18f648a, 25 }, { 0x18f648b, 25 },
{ 0x18f648c, 25 }, { 0x18f648d, 25 }, { 0x18f648e, 25 }, { 0x18f648f, 25 },
+ }
+}
};
const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64] = {
diff --git a/libavcodec/msmpeg4_vc1_data.h b/libavcodec/msmpeg4_vc1_data.h
index d12fcb032f..a92193a8f5 100644
--- a/libavcodec/msmpeg4_vc1_data.h
+++ b/libavcodec/msmpeg4_vc1_data.h
@@ -34,10 +34,9 @@ FF_VISIBILITY_PUSH_HIDDEN
void ff_msmp4_vc1_vlcs_init_once(void);
#define MSMP4_MB_INTRA_VLC_BITS 9
-extern VLC ff_msmp4_mb_i_vlc;
+extern VLCElem ff_msmp4_mb_i_vlc[];
#define MSMP4_DC_VLC_BITS 9
-extern VLC ff_msmp4_dc_luma_vlc[2];
-extern VLC ff_msmp4_dc_chroma_vlc[2];
+extern const VLCElem *ff_msmp4_dc_vlc[2 /* dc_table_index */][2 /* 0: luma, 1: chroma */];
/* intra picture macroblock coded block pattern */
extern const uint16_t ff_msmp4_mb_i_table[64][2];
@@ -46,10 +45,7 @@ extern const uint16_t ff_msmp4_mb_i_table[64][2];
extern const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64];
-extern const uint32_t ff_table0_dc_lum[120][2];
-extern const uint32_t ff_table1_dc_lum[120][2];
-extern const uint32_t ff_table0_dc_chroma[120][2];
-extern const uint32_t ff_table1_dc_chroma[120][2];
+extern const uint32_t ff_msmp4_dc_tables[2 /* dc_table_index */][2 /* 0: luma, 1: chroma */][120][2];
FF_VISIBILITY_POP_HIDDEN
#endif /* AVCODEC_MSMPEG4_VC1_DATA_H */
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index e61045c2f9..716fc13529 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -237,7 +237,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
cbp = code & 0x3f;
} else {
s->mb_intra = 1;
- code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MSMP4_MB_INTRA_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
/* predict coded block pattern */
cbp = 0;
for(i=0;i<6;i++) {
@@ -582,14 +582,9 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
return -1;
}
level-=256;
- }else{ //FIXME optimize use unified tables & index
- if (n < 4) {
- level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- } else {
- level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- }
+ } else {
+ level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
+ MSMP4_DC_VLC_BITS, 3);
if (level == DC_MAX) {
level = get_bits(&s->gb, 8);
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index a8ddb8d8e1..119ea8f15e 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -544,19 +544,8 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr
if (code > DC_MAX)
code = DC_MAX;
- if (s->dc_table_index == 0) {
- if (n < 4) {
- put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
- }
- } else {
- if (n < 4) {
- put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
- }
- }
+ put_bits(&s->pb, ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][1],
+ ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][0]);
if (code == DC_MAX)
put_bits(&s->pb, 8, level);
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 1baa6a9bf6..751ea57617 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -592,13 +592,8 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
int dcdiff, scale;
/* Get DC differential */
- if (n < 4) {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- } else {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- }
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
+ MSMP4_DC_VLC_BITS, 3);
if (dcdiff) {
const int m = (v->pq == 1 || v->pq == 2) ? 3 - v->pq : 0;
if (dcdiff == 119 /* ESC index value */) {
@@ -738,13 +733,8 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
int quant = FFABS(mquant);
/* Get DC differential */
- if (n < 4) {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- } else {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- }
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
+ MSMP4_DC_VLC_BITS, 3);
if (dcdiff) {
const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
if (dcdiff == 119 /* ESC index value */) {
@@ -940,13 +930,8 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
s->c_dc_scale = s->c_dc_scale_table[quant];
/* Get DC differential */
- if (n < 4) {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- } else {
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table,
- MSMP4_DC_VLC_BITS, 3);
- }
+ dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
+ MSMP4_DC_VLC_BITS, 3);
if (dcdiff) {
const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
if (dcdiff == 119 /* ESC index value */) {
@@ -2591,7 +2576,7 @@ static void vc1_decode_i_blocks(VC1Context *v)
}
// do actual MB decoding and displaying
- cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table,
+ cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc,
MSMP4_MB_INTRA_VLC_BITS, 2);
v->s.ac_pred = get_bits1(&v->s.gb);
@@ -2727,7 +2712,7 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
return 0;
}
- cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table,
+ cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc,
MSMP4_MB_INTRA_VLC_BITS, 2);
if (v->acpred_is_raw)
v->s.ac_pred = get_bits1(&v->s.gb);
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 469b2c4b2b..d7c193455d 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -482,7 +482,7 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->mb_intra = 1;
if (get_bits_left(&s->gb) <= 0)
return AVERROR_INVALIDDATA;
- code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table,
+ code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc,
MSMP4_MB_INTRA_VLC_BITS, 2);
/* predict coded block pattern */
cbp = 0;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 12/61] avcodec/svq1dec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (9 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 11/61] avcodec/msmpeg4_vc1_data: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 13/61] avcodec/svq1dec: Increase size of VLC Andreas Rheinhardt
` (49 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1dec.c | 82 ++++++++++++++++++++------------------------
1 file changed, 38 insertions(+), 44 deletions(-)
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index 8563b29164..372420bffe 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -45,12 +45,12 @@
#include "svq1.h"
#define SVQ1_BLOCK_TYPE_VLC_BITS 3
-static VLC svq1_block_type;
-static VLC svq1_motion_component;
-static VLC svq1_intra_multistage[6];
-static VLC svq1_inter_multistage[6];
-static VLC svq1_intra_mean;
-static VLC svq1_inter_mean;
+static VLCElem svq1_block_type[8];
+static VLCElem svq1_motion_component[176];
+static const VLCElem *svq1_intra_multistage[6];
+static const VLCElem *svq1_inter_multistage[6];
+static VLCElem svq1_intra_mean[632];
+static VLCElem svq1_inter_mean[1434];
/* motion vector (prediction) */
typedef struct svq1_pmv_s {
@@ -190,7 +190,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels,
height = 1 << ((3 + level) / 2);
/* get number of stages (-1 skips vector, 0 for mean only) */
- stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1;
+ stages = get_vlc2(bitbuf, svq1_intra_multistage[level], 3, 3) - 1;
if (stages == -1) {
for (y = 0; y < height; y++)
@@ -206,7 +206,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels,
}
av_assert0(stages >= 0);
- mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3);
+ mean = get_vlc2(bitbuf, svq1_intra_mean, 8, 3);
if (stages == 0) {
for (y = 0; y < height; y++)
@@ -257,7 +257,7 @@ static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels,
height = 1 << ((3 + level) / 2);
/* get number of stages (-1 skips vector, 0 for mean only) */
- stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1;
+ stages = get_vlc2(bitbuf, svq1_inter_multistage[level], 3, 2) - 1;
if (stages == -1)
continue; /* skip vector */
@@ -270,7 +270,7 @@ static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels,
}
av_assert0(stages >= 0);
- mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
+ mean = get_vlc2(bitbuf, svq1_inter_mean, 9, 3) - 256;
if (buggy) {
if (mean == -128)
@@ -307,7 +307,7 @@ static int svq1_decode_motion_vector(GetBitContext *bitbuf, svq1_pmv *mv,
for (i = 0; i < 2; i++) {
/* get motion code */
- diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2);
+ diff = get_vlc2(bitbuf, svq1_motion_component, 7, 2);
if (diff < 0)
return AVERROR_INVALIDDATA;
else if (diff) {
@@ -472,7 +472,7 @@ static int svq1_decode_delta_block(AVCodecContext *avctx, HpelDSPContext *hdsp,
int result = 0;
/* get block type */
- block_type = get_vlc2(bitbuf, svq1_block_type.table,
+ block_type = get_vlc2(bitbuf, svq1_block_type,
SVQ1_BLOCK_TYPE_VLC_BITS, 1);
/* reset motion vectors */
@@ -779,41 +779,35 @@ static int svq1_decode_frame(AVCodecContext *avctx, AVFrame *cur,
static av_cold void svq1_static_init(void)
{
- VLC_INIT_STATIC(&svq1_block_type, SVQ1_BLOCK_TYPE_VLC_BITS, 4,
- &ff_svq1_block_type_vlc[0][1], 2, 1,
- &ff_svq1_block_type_vlc[0][0], 2, 1, 8);
-
- VLC_INIT_STATIC(&svq1_motion_component, 7, 33,
- &ff_mvtab[0][1], 2, 1,
- &ff_mvtab[0][0], 2, 1, 176);
-
- for (int i = 0, offset = 0; i < 6; i++) {
- static const uint8_t sizes[2][6] = { { 14, 10, 14, 18, 16, 18 },
- { 10, 10, 14, 14, 14, 16 } };
- static VLCElem table[168];
- svq1_intra_multistage[i].table = &table[offset];
- svq1_intra_multistage[i].table_allocated = sizes[0][i];
- offset += sizes[0][i];
- vlc_init(&svq1_intra_multistage[i], 3, 8,
- &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
- &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1,
- VLC_INIT_USE_STATIC);
- svq1_inter_multistage[i].table = &table[offset];
- svq1_inter_multistage[i].table_allocated = sizes[1][i];
- offset += sizes[1][i];
- vlc_init(&svq1_inter_multistage[i], 3, 8,
- &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1,
- &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1,
- VLC_INIT_USE_STATIC);
+ static VLCElem table[168];
+ VLCInitState state = VLC_INIT_STATE(table);
+
+ VLC_INIT_STATIC_TABLE(svq1_block_type, SVQ1_BLOCK_TYPE_VLC_BITS, 4,
+ &ff_svq1_block_type_vlc[0][1], 2, 1,
+ &ff_svq1_block_type_vlc[0][0], 2, 1, 0);
+
+ VLC_INIT_STATIC_TABLE(svq1_motion_component, 7, 33,
+ &ff_mvtab[0][1], 2, 1,
+ &ff_mvtab[0][0], 2, 1, 0);
+
+ for (int i = 0; i < 6; i++) {
+ svq1_intra_multistage[i] =
+ ff_vlc_init_tables(&state, 3, 8,
+ &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
+ &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, 0);
+ svq1_inter_multistage[i] =
+ ff_vlc_init_tables(&state, 3, 8,
+ &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1,
+ &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, 0);
}
- VLC_INIT_STATIC(&svq1_intra_mean, 8, 256,
- &ff_svq1_intra_mean_vlc[0][1], 4, 2,
- &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632);
+ VLC_INIT_STATIC_TABLE(svq1_intra_mean, 8, 256,
+ &ff_svq1_intra_mean_vlc[0][1], 4, 2,
+ &ff_svq1_intra_mean_vlc[0][0], 4, 2, 0);
- VLC_INIT_STATIC(&svq1_inter_mean, 9, 512,
- &ff_svq1_inter_mean_vlc[0][1], 4, 2,
- &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434);
+ VLC_INIT_STATIC_TABLE(svq1_inter_mean, 9, 512,
+ &ff_svq1_inter_mean_vlc[0][1], 4, 2,
+ &ff_svq1_inter_mean_vlc[0][0], 4, 2, 0);
}
static av_cold int svq1_decode_init(AVCodecContext *avctx)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 13/61] avcodec/svq1dec: Increase size of VLC
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (10 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 12/61] avcodec/svq1dec: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 14/61] avcodec/rv40: Avoid superfluous VLC structures Andreas Rheinhardt
` (48 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It allows to reduce the number of maximum reloads by one.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1dec.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index 372420bffe..af02063a45 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -190,7 +190,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels,
height = 1 << ((3 + level) / 2);
/* get number of stages (-1 skips vector, 0 for mean only) */
- stages = get_vlc2(bitbuf, svq1_intra_multistage[level], 3, 3) - 1;
+ stages = get_vlc2(bitbuf, svq1_intra_multistage[level], 4, 2) - 1;
if (stages == -1) {
for (y = 0; y < height; y++)
@@ -779,7 +779,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, AVFrame *cur,
static av_cold void svq1_static_init(void)
{
- static VLCElem table[168];
+ static VLCElem table[196];
VLCInitState state = VLC_INIT_STATE(table);
VLC_INIT_STATIC_TABLE(svq1_block_type, SVQ1_BLOCK_TYPE_VLC_BITS, 4,
@@ -792,7 +792,7 @@ static av_cold void svq1_static_init(void)
for (int i = 0; i < 6; i++) {
svq1_intra_multistage[i] =
- ff_vlc_init_tables(&state, 3, 8,
+ ff_vlc_init_tables(&state, 4, 8,
&ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
&ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, 0);
svq1_inter_multistage[i] =
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 14/61] avcodec/rv40: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (11 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 13/61] avcodec/svq1dec: Increase size of VLC Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 15/61] avcodec/mpc7: " Andreas Rheinhardt
` (47 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv40.c | 69 ++++++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 37 deletions(-)
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index d2f8ef9f5a..3ee405f33c 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -40,22 +40,16 @@
#include "rv40vlc2.h"
#include "rv40data.h"
-static VLC aic_top_vlc;
-static VLC aic_mode1_vlc[AIC_MODE1_NUM], aic_mode2_vlc[AIC_MODE2_NUM];
-static VLC ptype_vlc[NUM_PTYPE_VLCS], btype_vlc[NUM_BTYPE_VLCS];
+static VLCElem aic_top_vlc[23590];
+static const VLCElem *aic_mode1_vlc[AIC_MODE1_NUM], *aic_mode2_vlc[AIC_MODE2_NUM];
+static const VLCElem *ptype_vlc[NUM_PTYPE_VLCS], *btype_vlc[NUM_BTYPE_VLCS];
-static av_cold void rv40_init_table(VLC *vlc, unsigned *offset, int nb_bits,
- int nb_codes, const uint8_t (*tab)[2])
+static av_cold const VLCElem *rv40_init_table(VLCInitState *state, int nb_bits,
+ int nb_codes, const uint8_t (*tab)[2])
{
- static VLCElem vlc_buf[11776];
-
- vlc->table = &vlc_buf[*offset];
- vlc->table_allocated = 1 << nb_bits;
- *offset += 1 << nb_bits;
-
- ff_vlc_init_from_lengths(vlc, nb_bits, nb_codes,
- &tab[0][1], 2, &tab[0][0], 2, 1,
- 0, VLC_INIT_USE_STATIC, NULL);
+ return ff_vlc_init_tables_from_lengths(state, nb_bits, nb_codes,
+ &tab[0][1], 2, &tab[0][0], 2, 1,
+ 0, 0);
}
/**
@@ -63,18 +57,19 @@ static av_cold void rv40_init_table(VLC *vlc, unsigned *offset, int nb_bits,
*/
static av_cold void rv40_init_tables(void)
{
- int i, offset = 0;
- static VLCElem aic_mode2_table[11814];
+ VLCInitState state = VLC_INIT_STATE(aic_top_vlc);
+ int i;
- rv40_init_table(&aic_top_vlc, &offset, AIC_TOP_BITS, AIC_TOP_SIZE,
+ rv40_init_table(&state, AIC_TOP_BITS, AIC_TOP_SIZE,
rv40_aic_top_vlc_tab);
for(i = 0; i < AIC_MODE1_NUM; i++){
// Every tenth VLC table is empty
if((i % 10) == 9) continue;
- rv40_init_table(&aic_mode1_vlc[i], &offset, AIC_MODE1_BITS,
- AIC_MODE1_SIZE, aic_mode1_vlc_tabs[i]);
+ aic_mode1_vlc[i] =
+ rv40_init_table(&state, AIC_MODE1_BITS,
+ AIC_MODE1_SIZE, aic_mode1_vlc_tabs[i]);
}
- for (unsigned i = 0, offset = 0; i < AIC_MODE2_NUM; i++){
+ for (unsigned i = 0; i < AIC_MODE2_NUM; i++){
uint16_t syms[AIC_MODE2_SIZE];
for (int j = 0; j < AIC_MODE2_SIZE; j++) {
@@ -85,20 +80,20 @@ static av_cold void rv40_init_tables(void)
else
syms[j] = first | (second << 8);
}
- aic_mode2_vlc[i].table = &aic_mode2_table[offset];
- aic_mode2_vlc[i].table_allocated = FF_ARRAY_ELEMS(aic_mode2_table) - offset;
- ff_vlc_init_from_lengths(&aic_mode2_vlc[i], AIC_MODE2_BITS, AIC_MODE2_SIZE,
- aic_mode2_vlc_bits[i], 1,
- syms, 2, 2, 0, VLC_INIT_STATIC_OVERLONG, NULL);
- offset += aic_mode2_vlc[i].table_size;
+ aic_mode2_vlc[i] =
+ ff_vlc_init_tables_from_lengths(&state, AIC_MODE2_BITS, AIC_MODE2_SIZE,
+ aic_mode2_vlc_bits[i], 1,
+ syms, 2, 2, 0, 0);
}
for(i = 0; i < NUM_PTYPE_VLCS; i++){
- rv40_init_table(&ptype_vlc[i], &offset, PTYPE_VLC_BITS, PTYPE_VLC_SIZE,
- ptype_vlc_tabs[i]);
+ ptype_vlc[i] =
+ rv40_init_table(&state, PTYPE_VLC_BITS, PTYPE_VLC_SIZE,
+ ptype_vlc_tabs[i]);
}
for(i = 0; i < NUM_BTYPE_VLCS; i++){
- rv40_init_table(&btype_vlc[i], &offset, BTYPE_VLC_BITS, BTYPE_VLC_SIZE,
- btype_vlc_tabs[i]);
+ btype_vlc[i] =
+ rv40_init_table(&state, BTYPE_VLC_BITS, BTYPE_VLC_SIZE,
+ btype_vlc_tabs[i]);
}
}
@@ -178,7 +173,7 @@ static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t
for(i = 0; i < 4; i++, dst += r->intra_types_stride){
if(!i && s->first_slice_line){
- pattern = get_vlc2(gb, aic_top_vlc.table, AIC_TOP_BITS, 1);
+ pattern = get_vlc2(gb, aic_top_vlc, AIC_TOP_BITS, 1);
dst[0] = (pattern >> 2) & 2;
dst[1] = (pattern >> 1) & 2;
dst[2] = pattern & 2;
@@ -201,12 +196,12 @@ static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t
if(pattern == rv40_aic_table_index[k])
break;
if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients
- AV_WN16(ptr, get_vlc2(gb, aic_mode2_vlc[k].table, AIC_MODE2_BITS, 2));
+ AV_WN16(ptr, get_vlc2(gb, aic_mode2_vlc[k], AIC_MODE2_BITS, 2));
ptr += 2;
j++;
}else{
if(B != -1 && C != -1)
- v = get_vlc2(gb, aic_mode1_vlc[B + C*10].table, AIC_MODE1_BITS, 1);
+ v = get_vlc2(gb, aic_mode1_vlc[B + C*10], AIC_MODE1_BITS, 1);
else{ // tricky decoding
v = 0;
switch(C){
@@ -270,17 +265,17 @@ static int rv40_decode_mb_info(RV34DecContext *r)
if(s->pict_type == AV_PICTURE_TYPE_P){
prev_type = block_num_to_ptype_vlc_num[prev_type];
- q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1);
+ q = get_vlc2(gb, ptype_vlc[prev_type], PTYPE_VLC_BITS, 1);
if(q < PBTYPE_ESCAPE)
return q;
- q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1);
+ q = get_vlc2(gb, ptype_vlc[prev_type], PTYPE_VLC_BITS, 1);
av_log(s->avctx, AV_LOG_ERROR, "Dquant for P-frame\n");
}else{
prev_type = block_num_to_btype_vlc_num[prev_type];
- q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1);
+ q = get_vlc2(gb, btype_vlc[prev_type], BTYPE_VLC_BITS, 1);
if(q < PBTYPE_ESCAPE)
return q;
- q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1);
+ q = get_vlc2(gb, btype_vlc[prev_type], BTYPE_VLC_BITS, 1);
av_log(s->avctx, AV_LOG_ERROR, "Dquant for B-frame\n");
}
return 0;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 15/61] avcodec/mpc7: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (12 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 14/61] avcodec/rv40: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 16/61] avcodec/intrax8: " Andreas Rheinhardt
` (46 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpc7.c | 52 ++++++++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index 59782c6727..b23b4094db 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -40,33 +40,34 @@
#include "mpc.h"
#include "mpc7data.h"
-static VLC scfi_vlc, dscf_vlc, hdr_vlc, quant_vlc[MPC7_QUANT_VLC_TABLES][2];
+static VLCElem scfi_vlc[1 << MPC7_SCFI_BITS];
+static VLCElem dscf_vlc[1 << MPC7_DSCF_BITS];
+static VLCElem hdr_vlc [1 << MPC7_HDR_BITS];
+static const VLCElem *quant_vlc[MPC7_QUANT_VLC_TABLES][2];
static av_cold void mpc7_init_static(void)
{
static VLCElem quant_tables[7224];
+ VLCInitState state = VLC_INIT_STATE(quant_tables);
const uint8_t *raw_quant_table = mpc7_quant_vlcs;
- VLC_INIT_STATIC_FROM_LENGTHS(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,
- &mpc7_scfi[1], 2,
- &mpc7_scfi[0], 2, 1, 0, 0, 1 << MPC7_SCFI_BITS);
- VLC_INIT_STATIC_FROM_LENGTHS(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,
- &mpc7_dscf[1], 2,
- &mpc7_dscf[0], 2, 1, -7, 0, 1 << MPC7_DSCF_BITS);
- VLC_INIT_STATIC_FROM_LENGTHS(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,
- &mpc7_hdr[1], 2,
- &mpc7_hdr[0], 2, 1, -5, 0, 1 << MPC7_HDR_BITS);
- for (unsigned i = 0, offset = 0; i < MPC7_QUANT_VLC_TABLES; i++){
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,
+ &mpc7_scfi[1], 2,
+ &mpc7_scfi[0], 2, 1, 0, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,
+ &mpc7_dscf[1], 2,
+ &mpc7_dscf[0], 2, 1, -7, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,
+ &mpc7_hdr[1], 2,
+ &mpc7_hdr[0], 2, 1, -5, 0);
+ for (int i = 0; i < MPC7_QUANT_VLC_TABLES; i++) {
for (int j = 0; j < 2; j++) {
- quant_vlc[i][j].table = &quant_tables[offset];
- quant_vlc[i][j].table_allocated = FF_ARRAY_ELEMS(quant_tables) - offset;
- ff_vlc_init_from_lengths(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i],
- &raw_quant_table[1], 2,
- &raw_quant_table[0], 2, 1,
- mpc7_quant_vlc_off[i],
- VLC_INIT_STATIC_OVERLONG, NULL);
+ quant_vlc[i][j] =
+ ff_vlc_init_tables_from_lengths(&state, 9, mpc7_quant_vlc_sizes[i],
+ &raw_quant_table[1], 2,
+ &raw_quant_table[0], 2, 1,
+ mpc7_quant_vlc_off[i], 0);
raw_quant_table += 2 * mpc7_quant_vlc_sizes[i];
- offset += quant_vlc[i][j].table_size;
}
}
ff_mpa_synth_init_fixed();
@@ -134,7 +135,7 @@ static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *
case 1:
i1 = get_bits1(gb);
for(i = 0; i < SAMPLES_PER_BAND/3; i++){
- t = get_vlc2(gb, quant_vlc[0][i1].table, 9, 2);
+ t = get_vlc2(gb, quant_vlc[0][i1], 9, 2);
*dst++ = mpc7_idx30[t];
*dst++ = mpc7_idx31[t];
*dst++ = mpc7_idx32[t];
@@ -143,7 +144,7 @@ static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *
case 2:
i1 = get_bits1(gb);
for(i = 0; i < SAMPLES_PER_BAND/2; i++){
- t = get_vlc2(gb, quant_vlc[1][i1].table, 9, 2);
+ t = get_vlc2(gb, quant_vlc[1][i1], 9, 2);
*dst++ = mpc7_idx50[t];
*dst++ = mpc7_idx51[t];
}
@@ -151,7 +152,7 @@ static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *
case 3: case 4: case 5: case 6: case 7:
i1 = get_bits1(gb);
for(i = 0; i < SAMPLES_PER_BAND; i++)
- *dst++ = get_vlc2(gb, quant_vlc[idx-1][i1].table, 9, 2);
+ *dst++ = get_vlc2(gb, quant_vlc[idx-1][i1], 9, 2);
break;
case 8: case 9: case 10: case 11: case 12:
case 13: case 14: case 15: case 16: case 17:
@@ -166,7 +167,7 @@ static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *
static int get_scale_idx(GetBitContext *gb, int ref)
{
- int t = get_vlc2(gb, dscf_vlc.table, MPC7_DSCF_BITS, 1);
+ int t = get_vlc2(gb, dscf_vlc, MPC7_DSCF_BITS, 1);
if (t == 8)
return get_bits(gb, 6);
return ref + t;
@@ -220,7 +221,7 @@ static int mpc7_decode_frame(AVCodecContext *avctx, AVFrame *frame,
/* read subband indexes */
for(i = 0; i <= c->maxbands; i++){
for(ch = 0; ch < 2; ch++){
- int t = i ? get_vlc2(&gb, hdr_vlc.table, MPC7_HDR_BITS, 1) : 4;
+ int t = i ? get_vlc2(&gb, hdr_vlc, MPC7_HDR_BITS, 1) : 4;
if(t == 4) bands[i].res[ch] = get_bits(&gb, 4);
else bands[i].res[ch] = bands[i-1].res[ch] + t;
if (bands[i].res[ch] < -1 || bands[i].res[ch] > 17) {
@@ -237,7 +238,8 @@ static int mpc7_decode_frame(AVCodecContext *avctx, AVFrame *frame,
/* get scale indexes coding method */
for(i = 0; i <= mb; i++)
for(ch = 0; ch < 2; ch++)
- if(bands[i].res[ch]) bands[i].scfi[ch] = get_vlc2(&gb, scfi_vlc.table, MPC7_SCFI_BITS, 1);
+ if (bands[i].res[ch])
+ bands[i].scfi[ch] = get_vlc2(&gb, scfi_vlc, MPC7_SCFI_BITS, 1);
/* get scale indexes */
for(i = 0; i <= mb; i++){
for(ch = 0; ch < 2; ch++){
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 16/61] avcodec/intrax8: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (13 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 15/61] avcodec/mpc7: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 17/61] avcodec/clearvideo: " Andreas Rheinhardt
` (45 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/intrax8.c | 46 +++++++++++++++++++-------------------------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index 0d90e37007..b6aacb170a 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -45,49 +45,43 @@
#define AC_VLC_MTD MAX_TABLE_DEPTH(AC_VLC_BITS, MAX_AC_VLC_BITS)
#define OR_VLC_MTD MAX_TABLE_DEPTH(OR_VLC_BITS, MAX_OR_VLC_BITS)
-static VLC j_ac_vlc[2][2][8]; // [quant < 13], [intra / inter], [select]
-static VLC j_dc_vlc[2][8]; // [quant], [select]
-static VLC j_orient_vlc[2][4]; // [quant], [select]
+static const VLCElem *j_ac_vlc[2][2][8]; // [quant < 13], [intra / inter], [select]
+static const VLCElem *j_dc_vlc[2][8]; // [quant], [select]
+static const VLCElem *j_orient_vlc[2][4]; // [quant], [select]
-static av_cold void x8_init_vlc(VLC *vlc, int nb_bits, int nb_codes,
- int *offset, const uint8_t table[][2])
+static av_cold const VLCElem *x8_init_vlc(VLCInitState *state, int nb_bits,
+ int nb_codes, const uint8_t table[][2])
{
- static VLCElem vlc_buf[VLC_BUFFER_SIZE];
-
- vlc->table = &vlc_buf[*offset];
- vlc->table_allocated = VLC_BUFFER_SIZE - *offset;
- ff_vlc_init_from_lengths(vlc, nb_bits, nb_codes, &table[0][1], 2,
- &table[0][0], 2, 1, 0, VLC_INIT_STATIC_OVERLONG, NULL);
- *offset += vlc->table_size;
+ return ff_vlc_init_tables_from_lengths(state, nb_bits, nb_codes, &table[0][1], 2,
+ &table[0][0], 2, 1, 0, 0);
}
static av_cold void x8_vlc_init(void)
{
+ static VLCElem vlc_buf[VLC_BUFFER_SIZE];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
int i;
- int offset = 0;
// set ac tables
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 8; k++)
- x8_init_vlc(&j_ac_vlc[i][j][k], AC_VLC_BITS, 77,
- &offset, x8_ac_quant_table[i][j][k]);
+ j_ac_vlc[i][j][k] = x8_init_vlc(&state, AC_VLC_BITS, 77,
+ x8_ac_quant_table[i][j][k]);
// set dc tables
for (int i = 0; i < 2; i++)
for (int j = 0; j < 8; j++)
- x8_init_vlc(&j_dc_vlc[i][j], DC_VLC_BITS, 34, &offset,
- x8_dc_quant_table[i][j]);
+ j_dc_vlc[i][j] = x8_init_vlc(&state, DC_VLC_BITS, 34,
+ x8_dc_quant_table[i][j]);
// set orient tables
for (i = 0; i < 2; i++)
- x8_init_vlc(&j_orient_vlc[0][i], OR_VLC_BITS, 12,
- &offset, x8_orient_highquant_table[i]);
+ j_orient_vlc[0][i] = x8_init_vlc(&state, OR_VLC_BITS, 12,
+ x8_orient_highquant_table[i]);
for (i = 0; i < 4; i++)
- x8_init_vlc(&j_orient_vlc[1][i], OR_VLC_BITS, 12,
- &offset, x8_orient_lowquant_table[i]);
-
- av_assert2(offset == VLC_BUFFER_SIZE);
+ j_orient_vlc[1][i] = x8_init_vlc(&state, OR_VLC_BITS, 12,
+ x8_orient_lowquant_table[i]);
}
static void x8_reset_vlc_tables(IntraX8Context *w)
@@ -108,7 +102,7 @@ static inline void x8_select_ac_table(IntraX8Context *const w, int mode)
table_index = get_bits(w->gb, 3);
// 2 modes use same tables
- w->j_ac_vlc_table[mode] = j_ac_vlc[w->quant < 13][mode >> 1][table_index].table;
+ w->j_ac_vlc_table[mode] = j_ac_vlc[w->quant < 13][mode >> 1][table_index];
av_assert2(j_ac_vlc[mode]);
}
@@ -116,7 +110,7 @@ static inline int x8_get_orient_vlc(IntraX8Context *w)
{
if (!w->j_orient_vlc_table) {
int table_index = get_bits(w->gb, 1 + (w->quant < 13));
- w->j_orient_vlc_table = j_orient_vlc[w->quant < 13][table_index].table;
+ w->j_orient_vlc_table = j_orient_vlc[w->quant < 13][table_index];
}
return get_vlc2(w->gb, w->j_orient_vlc_table, OR_VLC_BITS, OR_VLC_MTD);
@@ -258,7 +252,7 @@ static int x8_get_dc_rlf(IntraX8Context *const w, const int mode,
if (!w->j_dc_vlc_table[mode]) {
int table_index = get_bits(w->gb, 3);
// 4 modes, same table
- w->j_dc_vlc_table[mode] = j_dc_vlc[w->quant < 13][table_index].table;
+ w->j_dc_vlc_table[mode] = j_dc_vlc[w->quant < 13][table_index];
}
i = get_vlc2(w->gb, w->j_dc_vlc_table[mode], DC_VLC_BITS, DC_VLC_MTD);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 17/61] avcodec/clearvideo: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (14 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 16/61] avcodec/intrax8: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 18/61] avcodec/atrac9dec: " Andreas Rheinhardt
` (44 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/clearvideo.c | 74 ++++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 38 deletions(-)
diff --git a/libavcodec/clearvideo.c b/libavcodec/clearvideo.c
index 7f2c1c5f55..0b59d44cd6 100644
--- a/libavcodec/clearvideo.c
+++ b/libavcodec/clearvideo.c
@@ -39,9 +39,9 @@
#define CLV_VLC_BITS 9
typedef struct LevelCodes {
- VLC flags_cb;
- VLC mv_cb;
- VLC bias_cb;
+ const VLCElem *flags_cb;
+ const VLCElem *mv_cb;
+ const VLCElem *bias_cb;
} LevelCodes;
typedef struct MV {
@@ -75,9 +75,8 @@ typedef struct CLVContext {
int top_dc[3], left_dc[4];
} CLVContext;
-static VLC dc_vlc, ac_vlc;
+static VLCElem dc_vlc[1104], ac_vlc[554];
static LevelCodes lev[4 + 3 + 3]; // 0..3: Y, 4..6: U, 7..9: V
-static VLCElem vlc_buf[16716];
static inline int decode_block(CLVContext *ctx, int16_t *blk, int has_ac,
int ac_quant)
@@ -86,13 +85,13 @@ static inline int decode_block(CLVContext *ctx, int16_t *blk, int has_ac,
int idx = 1, last = 0, val, skip;
memset(blk, 0, sizeof(*blk) * 64);
- blk[0] = get_vlc2(gb, dc_vlc.table, CLV_VLC_BITS, 3);
+ blk[0] = get_vlc2(gb, dc_vlc, CLV_VLC_BITS, 3);
if (!has_ac)
return 0;
while (idx < 64 && !last) {
- val = get_vlc2(gb, ac_vlc.table, CLV_VLC_BITS, 2);
+ val = get_vlc2(gb, ac_vlc, CLV_VLC_BITS, 2);
if (val < 0)
return AVERROR_INVALIDDATA;
if (val != 0x1BFF) {
@@ -387,11 +386,11 @@ static int decode_tile(AVCodecContext *avctx, GetBitContext *gb,
MV mv = { 0 };
int err;
- if (lc->flags_cb.table)
- flags = get_vlc2(gb, lc->flags_cb.table, CLV_VLC_BITS, 2);
+ if (lc->flags_cb)
+ flags = get_vlc2(gb, lc->flags_cb, CLV_VLC_BITS, 2);
- if (lc->mv_cb.table) {
- uint16_t mv_code = get_vlc2(gb, lc->mv_cb.table, CLV_VLC_BITS, 2);
+ if (lc->mv_cb) {
+ uint16_t mv_code = get_vlc2(gb, lc->mv_cb, CLV_VLC_BITS, 2);
if (mv_code != MV_ESC) {
mv.x = (int8_t)(mv_code & 0xff);
@@ -406,8 +405,8 @@ static int decode_tile(AVCodecContext *avctx, GetBitContext *gb,
mv.x += root_mv.x;
mv.y += root_mv.y;
- if (lc->bias_cb.table) {
- uint16_t bias_val = get_vlc2(gb, lc->bias_cb.table, CLV_VLC_BITS, 2);
+ if (lc->bias_cb) {
+ uint16_t bias_val = get_vlc2(gb, lc->bias_cb, CLV_VLC_BITS, 2);
if (bias_val != BIAS_ESC) {
bias = (int16_t)(bias_val);
@@ -622,10 +621,12 @@ static int clv_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
return mb_ret < 0 ? mb_ret : buf_size;
}
-static av_cold void build_vlc(VLC *vlc, const uint8_t counts[16],
- const uint16_t **syms, unsigned *offset)
+static av_cold const VLCElem *build_vlc(VLCInitState *state,
+ const uint8_t counts[16],
+ const uint16_t **syms)
{
uint8_t lens[MAX_VLC_ENTRIES];
+ const uint16_t *symbols = *syms;
unsigned num = 0;
for (int i = 0; i < 16; i++) {
@@ -635,42 +636,39 @@ static av_cold void build_vlc(VLC *vlc, const uint8_t counts[16],
for (count += num; num < count; num++)
lens[num] = i + 1;
}
- vlc->table = &vlc_buf[*offset];
- vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *offset;
- ff_vlc_init_from_lengths(vlc, CLV_VLC_BITS, num, lens, 1,
- *syms, 2, 2, 0, VLC_INIT_STATIC_OVERLONG, NULL);
*syms += num;
- *offset += vlc->table_size;
+ return ff_vlc_init_tables_from_lengths(state, CLV_VLC_BITS, num, lens, 1,
+ symbols, 2, 2, 0, 0);
}
static av_cold void clv_init_static(void)
{
+ static VLCElem vlc_buf[16716];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
const uint16_t *mv_syms = clv_mv_syms, *bias_syms = clv_bias_syms;
- VLC_INIT_STATIC_FROM_LENGTHS(&dc_vlc, CLV_VLC_BITS, NUM_DC_CODES,
- clv_dc_lens, 1,
- clv_dc_syms, 1, 1, -63, 0, 1104);
- VLC_INIT_STATIC_FROM_LENGTHS(&ac_vlc, CLV_VLC_BITS, NUM_AC_CODES,
- clv_ac_bits, 1,
- clv_ac_syms, 2, 2, 0, 0, 554);
- for (unsigned i = 0, j = 0, k = 0, offset = 0;; i++) {
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(dc_vlc, CLV_VLC_BITS, NUM_DC_CODES,
+ clv_dc_lens, 1,
+ clv_dc_syms, 1, 1, -63, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(ac_vlc, CLV_VLC_BITS, NUM_AC_CODES,
+ clv_ac_bits, 1,
+ clv_ac_syms, 2, 2, 0, 0);
+ for (unsigned i = 0, j = 0, k = 0;; i++) {
if (0x36F & (1 << i)) {
- build_vlc(&lev[i].mv_cb, clv_mv_len_counts[k], &mv_syms, &offset);
+ lev[i].mv_cb = build_vlc(&state, clv_mv_len_counts[k], &mv_syms);
k++;
}
if (i == FF_ARRAY_ELEMS(lev) - 1)
break;
if (0x1B7 & (1 << i)) {
- lev[i].flags_cb.table = &vlc_buf[offset];
- lev[i].flags_cb.table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
- ff_vlc_init_from_lengths(&lev[i].flags_cb, CLV_VLC_BITS, 16,
- clv_flags_bits[j], 1,
- clv_flags_syms[j], 1, 1,
- 0, VLC_INIT_STATIC_OVERLONG, NULL);
- offset += lev[i].flags_cb.table_size;
-
- build_vlc(&lev[i + 1].bias_cb, clv_bias_len_counts[j],
- &bias_syms, &offset);
+ lev[i].flags_cb =
+ ff_vlc_init_tables_from_lengths(&state, CLV_VLC_BITS, 16,
+ clv_flags_bits[j], 1,
+ clv_flags_syms[j], 1, 1,
+ 0, 0);
+
+ lev[i + 1].bias_cb = build_vlc(&state, clv_bias_len_counts[j],
+ &bias_syms);
j++;
}
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 18/61] avcodec/atrac9dec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (15 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 17/61] avcodec/clearvideo: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 19/61] avcodec/imc: " Andreas Rheinhardt
` (43 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/atrac9dec.c | 52 ++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 27 deletions(-)
diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index d24a8e3f79..5b84f0c6d6 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -105,8 +105,8 @@ typedef struct ATRAC9Context {
DECLARE_ALIGNED(32, float, temp)[2048];
} ATRAC9Context;
-static VLC sf_vlc[2][8]; /* Signed/unsigned, length */
-static VLC coeff_vlc[2][8][4]; /* Cookbook, precision, cookbook index */
+static const VLCElem *sf_vlc[2][8]; /* Signed/unsigned, length */
+static const VLCElem *coeff_vlc[2][8][4]; /* Cookbook, precision, cookbook index */
static inline int parse_gradient(ATRAC9Context *s, ATRAC9BlockData *b,
GetBitContext *gb)
@@ -277,12 +277,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
const uint8_t *sf_weights = at9_tab_sf_weights[get_bits(gb, 3)];
const int base = get_bits(gb, 5);
const int len = get_bits(gb, 2) + 3;
- const VLC *tab = &sf_vlc[0][len];
+ const VLCElem *tab = sf_vlc[0][len];
c->scalefactors[0] = get_bits(gb, len);
for (int i = 1; i < b->band_ext_q_unit; i++) {
- int val = c->scalefactors[i - 1] + get_vlc2(gb, tab->table,
+ int val = c->scalefactors[i - 1] + get_vlc2(gb, tab,
ATRAC9_SF_VLC_BITS, 1);
c->scalefactors[i] = val & ((1 << len) - 1);
}
@@ -310,10 +310,10 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
const int len = get_bits(gb, 2) + 2;
const int unit_cnt = FFMIN(b->band_ext_q_unit, baseline_len);
- const VLC *tab = &sf_vlc[1][len];
+ const VLCElem *tab = sf_vlc[1][len];
for (int i = 0; i < unit_cnt; i++) {
- int dist = get_vlc2(gb, tab->table, ATRAC9_SF_VLC_BITS, 1);
+ int dist = get_vlc2(gb, tab, ATRAC9_SF_VLC_BITS, 1);
c->scalefactors[i] = baseline[i] + dist;
}
@@ -331,12 +331,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
const int base = get_bits(gb, 5) - (1 << (5 - 1));
const int len = get_bits(gb, 2) + 1;
const int unit_cnt = FFMIN(b->band_ext_q_unit, baseline_len);
- const VLC *tab = &sf_vlc[0][len];
+ const VLCElem *tab = sf_vlc[0][len];
c->scalefactors[0] = get_bits(gb, len);
for (int i = 1; i < unit_cnt; i++) {
- int val = c->scalefactors[i - 1] + get_vlc2(gb, tab->table,
+ int val = c->scalefactors[i - 1] + get_vlc2(gb, tab,
ATRAC9_SF_VLC_BITS, 1);
c->scalefactors[i] = val & ((1 << len) - 1);
}
@@ -418,12 +418,12 @@ static inline void read_coeffs_coarse(ATRAC9Context *s, ATRAC9BlockData *b,
if (prec <= max_prec) {
const int cb = c->codebookset[i];
const int cbi = at9_q_unit_to_codebookidx[i];
- const VLC *tab = &coeff_vlc[cb][prec][cbi];
+ const VLCElem *tab = coeff_vlc[cb][prec][cbi];
const HuffmanCodebook *huff = &at9_huffman_coeffs[cb][prec][cbi];
const int groups = bands >> huff->value_cnt_pow;
for (int j = 0; j < groups; j++) {
- uint16_t val = get_vlc2(gb, tab->table, ATRAC9_COEFF_VLC_BITS, 2);
+ uint16_t val = get_vlc2(gb, tab, ATRAC9_COEFF_VLC_BITS, 2);
for (int k = 0; k < huff->value_cnt; k++) {
coeffs[k] = sign_extend(val, huff->value_bits);
@@ -841,33 +841,31 @@ static av_cold int atrac9_decode_close(AVCodecContext *avctx)
return 0;
}
-static av_cold void atrac9_init_vlc(VLC *vlc, int nb_bits, int nb_codes,
- const uint8_t (**tab)[2],
- unsigned *buf_offset, int offset)
+static av_cold const VLCElem *atrac9_init_vlc(VLCInitState *state,
+ int nb_bits, int nb_codes,
+ const uint8_t (**tab)[2], int offset)
{
- static VLCElem vlc_buf[24812];
+ const uint8_t (*table)[2] = *tab;
- vlc->table = &vlc_buf[*buf_offset];
- vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *buf_offset;
- ff_vlc_init_from_lengths(vlc, nb_bits, nb_codes,
- &(*tab)[0][1], 2, &(*tab)[0][0], 2, 1,
- offset, VLC_INIT_STATIC_OVERLONG, NULL);
- *buf_offset += vlc->table_size;
*tab += nb_codes;
+ return ff_vlc_init_tables_from_lengths(state, nb_bits, nb_codes,
+ &table[0][1], 2, &table[0][0], 2, 1,
+ offset, 0);
}
static av_cold void atrac9_init_static(void)
{
+ static VLCElem vlc_buf[24812];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
const uint8_t (*tab)[2];
- unsigned offset = 0;
/* Unsigned scalefactor VLCs */
tab = at9_sfb_a_tab;
for (int i = 1; i < 7; i++) {
const HuffmanCodebook *hf = &at9_huffman_sf_unsigned[i];
- atrac9_init_vlc(&sf_vlc[0][i], ATRAC9_SF_VLC_BITS,
- hf->size, &tab, &offset, 0);
+ sf_vlc[0][i] = atrac9_init_vlc(&state, ATRAC9_SF_VLC_BITS,
+ hf->size, &tab, 0);
}
/* Signed scalefactor VLCs */
@@ -878,8 +876,8 @@ static av_cold void atrac9_init_static(void)
/* The symbols are signed integers in the range -16..15;
* the values in the source table are offset by 16 to make
* them fit into an uint8_t; the -16 reverses this shift. */
- atrac9_init_vlc(&sf_vlc[1][i], ATRAC9_SF_VLC_BITS,
- hf->size, &tab, &offset, -16);
+ sf_vlc[1][i] = atrac9_init_vlc(&state, ATRAC9_SF_VLC_BITS,
+ hf->size, &tab, -16);
}
/* Coefficient VLCs */
@@ -888,8 +886,8 @@ static av_cold void atrac9_init_static(void)
for (int j = 2; j < 8; j++) {
for (int k = i; k < 4; k++) {
const HuffmanCodebook *hf = &at9_huffman_coeffs[i][j][k];
- atrac9_init_vlc(&coeff_vlc[i][j][k], ATRAC9_COEFF_VLC_BITS,
- hf->size, &tab, &offset, 0);
+ coeff_vlc[i][j][k] = atrac9_init_vlc(&state, ATRAC9_COEFF_VLC_BITS,
+ hf->size, &tab, 0);
}
}
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 19/61] avcodec/imc: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (16 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 18/61] avcodec/atrac9dec: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 20/61] avcodec/refstruct: Add simple API for refcounted objects Andreas Rheinhardt
` (42 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/imc.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 754ceff958..99eb089236 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -106,7 +106,7 @@ typedef struct IMCContext {
AVCodecContext *avctx;
} IMCContext;
-static VLC huffman_vlc[4][4];
+static const VLCElem *huffman_vlc[4][4];
#define IMC_VLC_BITS 9
#define VLC_TABLES_SIZE 9512
@@ -171,16 +171,15 @@ static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
static av_cold void imc_init_static(void)
{
+ VLCInitState state = VLC_INIT_STATE(vlc_tables);
/* initialize the VLC tables */
- for (int i = 0, offset = 0; i < 4 ; i++) {
+ for (int i = 0; i < 4 ; i++) {
for (int j = 0; j < 4; j++) {
- huffman_vlc[i][j].table = &vlc_tables[offset];
- huffman_vlc[i][j].table_allocated = VLC_TABLES_SIZE - offset;
- ff_vlc_init_from_lengths(&huffman_vlc[i][j], IMC_VLC_BITS, imc_huffman_sizes[i],
- imc_huffman_lens[i][j], 1,
- imc_huffman_syms[i][j], 1, 1,
- 0, VLC_INIT_STATIC_OVERLONG, NULL);
- offset += huffman_vlc[i][j].table_size;
+ huffman_vlc[i][j] =
+ ff_vlc_init_tables_from_lengths(&state, IMC_VLC_BITS, imc_huffman_sizes[i],
+ imc_huffman_lens[i][j], 1,
+ imc_huffman_syms[i][j], 1, 1,
+ 0, 0);
}
}
}
@@ -311,16 +310,11 @@ static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
int *levlCoeffs)
{
int i;
- VLC *hufftab[4];
int start = 0;
const uint8_t *cb_sel;
- int s;
+ int s = stream_format_code >> 1;
+ const VLCElem * const *const hufftab = huffman_vlc[s];
- s = stream_format_code >> 1;
- hufftab[0] = &huffman_vlc[s][0];
- hufftab[1] = &huffman_vlc[s][1];
- hufftab[2] = &huffman_vlc[s][2];
- hufftab[3] = &huffman_vlc[s][3];
cb_sel = imc_cb_select[s];
if (stream_format_code & 4)
@@ -328,7 +322,7 @@ static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
if (start)
levlCoeffs[0] = get_bits(&q->gb, 7);
for (i = start; i < BANDS; i++) {
- levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]]->table,
+ levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]],
IMC_VLC_BITS, 2);
if (levlCoeffs[i] == 17)
levlCoeffs[i] += get_bits(&q->gb, 4);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 20/61] avcodec/refstruct: Add simple API for refcounted objects
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (17 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 19/61] avcodec/imc: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 21/61] avcodec/vp3: Share coefficient VLCs between threads Andreas Rheinhardt
` (41 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For now, this API is supposed to replace all the internal uses
of reference counted objects in libavcodec; "internal" here
means that the object is created in libavcodec and is never
put directly in the hands of anyone outside of it.
It is intended to be made public eventually, but for now
I enjoy the ability to modify it freely.
Several shortcomings of the AVBuffer API motivated this API:
a) The unnecessary allocations (and ensuing error checks)
when using the API. Besides the need for runtime checks it
imposes upon the developer the burden of thinking through
what happens in case an error happens. Furthermore, these
error paths are typically not covered by FATE.
b) The AVBuffer API is designed with buffers and not with
objects in mind: The type for the actual buffers used
is uint8_t*; it pretends to be able to make buffers
writable, but this is wrong in case the buffer is not a POD.
Another instance of this thinking is the lack of a reset
callback in the AVBufferPool API.
c) The AVBuffer API incurs unnecessary indirections by
going through the AVBufferRef.data pointer. In case the user
tries to avoid this indirection and stores a pointer to
AVBuffer.data separately (which also allows to use the correct
type), the user has to keep these two pointers in sync
in case they can change (and in any case has two pointers
occupying space in the containing context). See the following
commit using this API for H.264 parameter sets for an example
of the removal of such syncing code as well as the casts
involved in the parts where only the AVBufferRef* pointer
was stored.
d) Given that the AVBuffer API allows custom allocators,
creating refcounted objects with dedicated free functions
often involves a lot of boilerplate like this:
obj = av_mallocz(sizeof(*obj));
ref = av_buffer_create((uint8_t*)obj, sizeof(*obj), free_func, opaque, 0);
if (!ref) {
av_free(obj);
return AVERROR(ENOMEM);
}
(There is also a corresponding av_free() at the end of free_func().)
This is now just
obj = ff_refstruct_alloc_ext(sizeof(*obj), 0, opaque, free_func);
if (!obj)
return AVERROR(ENOMEM);
See the subsequent patch for the framepool (i.e. get_buffer.c)
for an example.
This API does things differently; it is designed to be lightweight*
as well as geared to the common case where the allocator of the
underlying object does not matter as long as it is big enough and
suitably aligned. This allows to allocate the user data together
with the API's bookkeeping data which avoids an allocation as well
as the need for separate pointers to the user data and the API's
bookkeeping data. This entails that the actual allocation of the
object is performed by refstruct, not the user. This is responsible
for avoiding the boilerplate code mentioned in d).
As a downside, custom allocators are not supported, but it will
become apparent in subsequent commits that there are enough
usecases to make it worthwhile.
Another advantage of this API is that one only needs to include
the relevant header if one uses the API and not when one includes
the header or some other component that uses it. This is because there
is no refstruct type analog of AVBufferRef. This brings with it
one further downside: It is not apparent from the pointer itself
whether the underlying object is managed by the refstruct API
or whether this pointer is a reference to it (or merely a pointer
to it).
Finally, this API supports const-qualified opaque pointees;
this will allow to avoid casting const away by the CBS code.
*: Basically the only exception to the you-only-pay-for-what-you-use
rule is that it always uses atomics for the refcount.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/Makefile | 1 +
libavcodec/refstruct.c | 139 +++++++++++++++++++++++++++++++++++++++
libavcodec/refstruct.h | 145 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 285 insertions(+)
create mode 100644 libavcodec/refstruct.c
create mode 100644 libavcodec/refstruct.h
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cae2e773a1..9e96892365 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -55,6 +55,7 @@ OBJS = ac3_parser.o \
profiles.o \
qsv_api.o \
raw.o \
+ refstruct.o \
utils.o \
version.o \
vlc.o \
diff --git a/libavcodec/refstruct.c b/libavcodec/refstruct.c
new file mode 100644
index 0000000000..917cf6b7ac
--- /dev/null
+++ b/libavcodec/refstruct.c
@@ -0,0 +1,139 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdatomic.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "internal.h"
+#include "refstruct.h"
+
+#include "libavutil/macros.h"
+#include "libavutil/mem.h"
+
+typedef struct RefCount {
+ /**
+ * An uintptr_t is big enough to hold the address of every reference,
+ * so no overflow can happen when incrementing the refcount as long as
+ * the user does not throw away references.
+ */
+ atomic_uintptr_t refcount;
+ FFRefStructOpaque opaque;
+ void (*free_cb)(FFRefStructOpaque opaque, void *obj);
+} RefCount;
+
+#if __STDC_VERSION__ >= 201112L
+#define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX3(STRIDE_ALIGN, 16, _Alignof(max_align_t)))
+#else
+#define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX(STRIDE_ALIGN, 16))
+#endif
+
+static RefCount *get_refcount(void *obj)
+{
+ return (RefCount*)((char*)obj - REFCOUNT_OFFSET);
+}
+
+static void *get_userdata(void *buf)
+{
+ return (char*)buf + REFCOUNT_OFFSET;
+}
+
+static void refcount_init(RefCount *ref, FFRefStructOpaque opaque,
+ void (*free_cb)(FFRefStructOpaque opaque, void *obj))
+{
+ atomic_init(&ref->refcount, 1);
+ ref->opaque = opaque;
+ ref->free_cb = free_cb;
+}
+
+void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque,
+ void (*free_cb)(FFRefStructOpaque opaque, void *obj))
+{
+ void *buf, *obj;
+
+ if (size > SIZE_MAX - REFCOUNT_OFFSET)
+ return NULL;
+ buf = av_malloc(size + REFCOUNT_OFFSET);
+ if (!buf)
+ return NULL;
+ refcount_init(buf, opaque, free_cb);
+ obj = get_userdata(buf);
+ if (!(flags & FF_REFSTRUCT_FLAG_NO_ZEROING))
+ memset(obj, 0, size);
+
+ return obj;
+}
+
+void *ff_refstruct_allocz(size_t size)
+{
+ return ff_refstruct_alloc_ext(size, 0, NULL, NULL);
+}
+
+void ff_refstruct_unref(void *objp)
+{
+ void *obj;
+ RefCount *ref;
+
+ memcpy(&obj, objp, sizeof(obj));
+ if (!obj)
+ return;
+ memcpy(objp, &(void *){ NULL }, sizeof(obj));
+
+ ref = get_refcount(obj);
+ if (atomic_fetch_sub_explicit(&ref->refcount, 1, memory_order_acq_rel) == 1) {
+ if (ref->free_cb)
+ ref->free_cb(ref->opaque, obj);
+ av_free(ref);
+ }
+
+ return;
+}
+
+void *ff_refstruct_ref(void *obj)
+{
+ RefCount *ref = get_refcount(obj);
+
+ atomic_fetch_add_explicit(&ref->refcount, 1, memory_order_relaxed);
+
+ return obj;
+}
+
+const void *ff_refstruct_ref_c(const void *obj)
+{
+ /* Casting const away here is fine, as it is only supposed
+ * to apply to the user's data and not our bookkeeping data. */
+ RefCount *ref = get_refcount((void*)obj);
+
+ atomic_fetch_add_explicit(&ref->refcount, 1, memory_order_relaxed);
+
+ return obj;
+}
+
+void ff_refstruct_replace(void *dstp, const void *src)
+{
+ const void *dst;
+ memcpy(&dst, dstp, sizeof(dst));
+
+ if (src == dst)
+ return;
+ ff_refstruct_unref(dstp);
+ if (src) {
+ dst = ff_refstruct_ref_c(src);
+ memcpy(dstp, &dst, sizeof(dst));
+ }
+}
diff --git a/libavcodec/refstruct.h b/libavcodec/refstruct.h
new file mode 100644
index 0000000000..0086717c17
--- /dev/null
+++ b/libavcodec/refstruct.h
@@ -0,0 +1,145 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_REFSTRUCT_H
+#define AVCODEC_REFSTRUCT_H
+
+#include <stddef.h>
+
+/**
+ * RefStruct is an API for creating reference-counted objects
+ * with minimal overhead. The API is designed for objects,
+ * not buffers like the AVBuffer API. The main differences
+ * to the AVBuffer API are as follows:
+ *
+ * - It uses void* instead of uint8_t* as its base type due to
+ * its focus on objects.
+ * - There are no equivalents of AVBuffer and AVBufferRef.
+ * E.g. there is no way to get the usable size of the object:
+ * The user is supposed to know what is at the other end of
+ * the pointer. It also avoids one level of indirection.
+ * - Custom allocators are not supported. This allows to simplify
+ * the implementation and reduce the amount of allocations.
+ * - It also has the advantage that the user's free callback need
+ * only free the resources owned by the object, but not the
+ * object itself.
+ * - Because referencing (and replacing) an object managed by the
+ * RefStruct API does not involve allocations, they can not fail
+ * and therefore need not be checked.
+ *
+ * @note Referencing and unreferencing the buffers is thread-safe and thus
+ * may be done from multiple threads simultaneously without any need for
+ * additional locking.
+ */
+
+/**
+ * This union is used for all opaque parameters in this API to spare the user
+ * to cast const away in case the opaque to use is const-qualified.
+ *
+ * The functions provided by this API with an FFRefStructOpaque come in pairs
+ * named foo_c and foo. The foo function accepts void* as opaque and is just
+ * a wrapper around the foo_c function; "_c" means "(potentially) const".
+ */
+typedef union {
+ void *nc;
+ const void *c;
+} FFRefStructOpaque;
+
+/**
+ * If this flag is set in ff_refstruct_alloc_ext_c(), the object will not
+ * be initially zeroed.
+ */
+#define FF_REFSTRUCT_FLAG_NO_ZEROING (1 << 0)
+
+/**
+ * Allocate a refcounted object of usable size `size` managed via
+ * the RefStruct API.
+ *
+ * By default (in the absence of flags to the contrary),
+ * the returned object is initially zeroed.
+ *
+ * @param size Desired usable size of the returned object.
+ * @param flags A bitwise combination of FF_REFSTRUCT_FLAG_* flags.
+ * @param opaque A pointer that will be passed to the free_cb callback.
+ * @param free_cb A callback for freeing this object's content
+ * when its reference count reaches zero;
+ * it must not free the object itself.
+ * @return A pointer to an object of the desired size or NULL on failure.
+ */
+void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque,
+ void (*free_cb)(FFRefStructOpaque opaque, void *obj));
+
+/**
+ * A wrapper around ff_refstruct_alloc_ext_c() for the common case
+ * of a non-const qualified opaque.
+ *
+ * @see ff_refstruct_alloc_ext_c()
+ */
+static inline
+void *ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque,
+ void (*free_cb)(FFRefStructOpaque opaque, void *obj))
+{
+ return ff_refstruct_alloc_ext_c(size, flags, (FFRefStructOpaque){.nc = opaque},
+ free_cb);
+}
+
+/**
+ * Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL)
+ */
+void *ff_refstruct_allocz(size_t size);
+
+/**
+ * Decrement the reference count of the underlying object and automatically
+ * free the object if there are no more references to it.
+ *
+ * `*objp == NULL` is legal and a no-op.
+ *
+ * @param objp Pointer to a pointer that is either NULL or points to an object
+ * managed via this API. `*objp` is set to NULL on return.
+ */
+void ff_refstruct_unref(void *objp);
+
+/**
+ * Create a new reference to an object managed via this API,
+ * i.e. increment the reference count of the underlying object
+ * and return obj.
+ * @return a pointer equal to obj.
+ */
+void *ff_refstruct_ref(void *obj);
+
+/**
+ * Analog of ff_refstruct_ref(), but for constant objects.
+ * @see ff_refstruct_ref()
+ */
+const void *ff_refstruct_ref_c(const void *obj);
+
+/**
+ * Ensure `*dstp` refers to the same object as src.
+ *
+ * If `*dstp` is already equal to src, do nothing. Otherwise unreference `*dstp`
+ * and replace it with a new reference to src in case `src != NULL` (this
+ * involves incrementing the reference count of src's underlying object) or
+ * with NULL otherwise.
+ *
+ * @param dstp Pointer to a pointer that is either NULL or points to an object
+ * managed via this API.
+ * @param src A pointer to an object managed via this API or NULL.
+ */
+void ff_refstruct_replace(void *dstp, const void *src);
+
+#endif /* AVCODEC_REFSTRUCT_H */
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 21/61] avcodec/vp3: Share coefficient VLCs between threads
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (18 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 20/61] avcodec/refstruct: Add simple API for refcounted objects Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 22/61] avcodec/vp3: Avoid complete VLC struct, only use VLCElem* Andreas Rheinhardt
` (40 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
These VLCs are very big: The VP3 one have 164382 elements
but due to the overallocation enough memory for 313344 elements
are allocated (1.195 MiB with sizeof(VLCElem) == 4);
for VP4 the numbers are very similar, namely 311296 and 164392
elements. Since 1f4cf92cfbd3accbae582ac63126ed5570ddfd37, each
frame thread has its own copy of these VLCs.
This commit fixes this by sharing these VLCs across threads.
The approach used here will also make it easier to support
stream reconfigurations in case of frame-multithreading
in the future.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vp3.c | 99 +++++++++++++++++++++++++++++++-----------------
1 file changed, 65 insertions(+), 34 deletions(-)
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 0463909f2f..1abf7e8078 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -45,8 +45,10 @@
#include "decode.h"
#include "get_bits.h"
#include "hpeldsp.h"
+#include "internal.h"
#include "jpegquanttables.h"
#include "mathops.h"
+#include "refstruct.h"
#include "thread.h"
#include "threadframe.h"
#include "videodsp.h"
@@ -187,6 +189,10 @@ typedef struct HuffTable {
uint8_t nb_entries;
} HuffTable;
+typedef struct CoeffVLCs {
+ VLC vlcs[80];
+} CoeffVLCs;
+
typedef struct Vp3DecodeContext {
AVCodecContext *avctx;
int theora, theora_tables, theora_header;
@@ -289,9 +295,12 @@ typedef struct Vp3DecodeContext {
int *nkf_coded_fragment_list;
int num_kf_coded_fragment[3];
- /* The first 16 of the following VLCs are for the dc coefficients;
- the others are four groups of 16 VLCs each for ac coefficients. */
- VLC coeff_vlc[5 * 16];
+ /**
+ * The first 16 of the following VLCs are for the dc coefficients;
+ * the others are four groups of 16 VLCs each for ac coefficients.
+ * This is a RefStruct reference to share these VLCs between threads.
+ */
+ CoeffVLCs *coeff_vlc;
/* these arrays need to be on 16-byte boundaries since SSE2 operations
* index into them */
@@ -365,8 +374,7 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx)
av_frame_free(&s->last_frame.f);
av_frame_free(&s->golden_frame.f);
- for (int i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++)
- ff_vlc_free(&s->coeff_vlc[i]);
+ ff_refstruct_unref(&s->coeff_vlc);
return 0;
}
@@ -1295,13 +1303,14 @@ static void reverse_dc_prediction(Vp3DecodeContext *s,
*/
static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
{
+ const VLC *coeff_vlc = s->coeff_vlc->vlcs;
int dc_y_table;
int dc_c_table;
int ac_y_table;
int ac_c_table;
int residual_eob_run = 0;
- VLC *y_tables[64];
- VLC *c_tables[64];
+ const VLC *y_tables[64];
+ const VLC *c_tables[64];
s->dct_tokens[0][0] = s->dct_tokens_base;
@@ -1313,7 +1322,7 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
dc_c_table = get_bits(gb, 4);
/* unpack the Y plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &s->coeff_vlc[dc_y_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, &coeff_vlc[dc_y_table], 0,
0, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
@@ -1324,11 +1333,11 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]);
/* unpack the C plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &s->coeff_vlc[dc_c_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, &coeff_vlc[dc_c_table], 0,
1, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
- residual_eob_run = unpack_vlcs(s, gb, &s->coeff_vlc[dc_c_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, &coeff_vlc[dc_c_table], 0,
2, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
@@ -1350,23 +1359,23 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
/* build tables of AC VLC tables */
for (int i = 1; i <= 5; i++) {
/* AC VLC table group 1 */
- y_tables[i] = &s->coeff_vlc[ac_y_table + 16];
- c_tables[i] = &s->coeff_vlc[ac_c_table + 16];
+ y_tables[i] = &coeff_vlc[ac_y_table + 16];
+ c_tables[i] = &coeff_vlc[ac_c_table + 16];
}
for (int i = 6; i <= 14; i++) {
/* AC VLC table group 2 */
- y_tables[i] = &s->coeff_vlc[ac_y_table + 32];
- c_tables[i] = &s->coeff_vlc[ac_c_table + 32];
+ y_tables[i] = &coeff_vlc[ac_y_table + 32];
+ c_tables[i] = &coeff_vlc[ac_c_table + 32];
}
for (int i = 15; i <= 27; i++) {
/* AC VLC table group 3 */
- y_tables[i] = &s->coeff_vlc[ac_y_table + 48];
- c_tables[i] = &s->coeff_vlc[ac_c_table + 48];
+ y_tables[i] = &coeff_vlc[ac_y_table + 48];
+ c_tables[i] = &coeff_vlc[ac_c_table + 48];
}
for (int i = 28; i <= 63; i++) {
/* AC VLC table group 4 */
- y_tables[i] = &s->coeff_vlc[ac_y_table + 64];
- c_tables[i] = &s->coeff_vlc[ac_c_table + 64];
+ y_tables[i] = &coeff_vlc[ac_y_table + 64];
+ c_tables[i] = &coeff_vlc[ac_c_table + 64];
}
/* decode all AC coefficients */
@@ -1517,6 +1526,7 @@ static void vp4_set_tokens_base(Vp3DecodeContext *s)
static int vp4_unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
{
+ const VLC *coeff_vlc = s->coeff_vlc->vlcs;
int dc_y_table;
int dc_c_table;
int ac_y_table;
@@ -1539,27 +1549,27 @@ static int vp4_unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
/* build tables of DC/AC VLC tables */
/* DC table group */
- tables[0][0] = &s->coeff_vlc[dc_y_table];
- tables[1][0] = &s->coeff_vlc[dc_c_table];
+ tables[0][0] = &coeff_vlc[dc_y_table];
+ tables[1][0] = &coeff_vlc[dc_c_table];
for (int i = 1; i <= 5; i++) {
/* AC VLC table group 1 */
- tables[0][i] = &s->coeff_vlc[ac_y_table + 16];
- tables[1][i] = &s->coeff_vlc[ac_c_table + 16];
+ tables[0][i] = &coeff_vlc[ac_y_table + 16];
+ tables[1][i] = &coeff_vlc[ac_c_table + 16];
}
for (int i = 6; i <= 14; i++) {
/* AC VLC table group 2 */
- tables[0][i] = &s->coeff_vlc[ac_y_table + 32];
- tables[1][i] = &s->coeff_vlc[ac_c_table + 32];
+ tables[0][i] = &coeff_vlc[ac_y_table + 32];
+ tables[1][i] = &coeff_vlc[ac_c_table + 32];
}
for (int i = 15; i <= 27; i++) {
/* AC VLC table group 3 */
- tables[0][i] = &s->coeff_vlc[ac_y_table + 48];
- tables[1][i] = &s->coeff_vlc[ac_c_table + 48];
+ tables[0][i] = &coeff_vlc[ac_y_table + 48];
+ tables[1][i] = &coeff_vlc[ac_c_table + 48];
}
for (int i = 28; i <= 63; i++) {
/* AC VLC table group 4 */
- tables[0][i] = &s->coeff_vlc[ac_y_table + 64];
- tables[1][i] = &s->coeff_vlc[ac_c_table + 64];
+ tables[0][i] = &coeff_vlc[ac_y_table + 64];
+ tables[1][i] = &coeff_vlc[ac_c_table + 64];
}
vp4_set_tokens_base(s);
@@ -2355,6 +2365,14 @@ static av_cold int init_frames(Vp3DecodeContext *s)
return 0;
}
+static av_cold void free_vlc_tables(FFRefStructOpaque unused, void *obj)
+{
+ CoeffVLCs *vlcs = obj;
+
+ for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++)
+ ff_vlc_free(&vlcs->vlcs[i]);
+}
+
static av_cold int vp3_decode_init(AVCodecContext *avctx)
{
static AVOnce init_static_once = AV_ONCE_INIT;
@@ -2443,8 +2461,6 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
s->fragment_start[2] = y_fragment_count + c_fragment_count;
if (!s->theora_tables) {
- const uint8_t (*bias_tabs)[32][2];
-
for (int i = 0; i < 64; i++) {
s->coded_dc_scale_factor[0][i] = s->version < 2 ? vp31_dc_scale_factor[i] : vp4_y_dc_scale_factor[i];
s->coded_dc_scale_factor[1][i] = s->version < 2 ? vp31_dc_scale_factor[i] : vp4_uv_dc_scale_factor[i];
@@ -2463,11 +2479,23 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
s->qr_base[inter][plane][1] = 2 * inter + (!!plane) * !inter;
}
}
+ }
+
+ if (!avctx->internal->is_copy) {
+ CoeffVLCs *vlcs = ff_refstruct_alloc_ext(sizeof(*s->coeff_vlc), 0,
+ NULL, free_vlc_tables);
+ if (!vlcs)
+ return AVERROR(ENOMEM);
+
+ s->coeff_vlc = vlcs;
+
+ if (!s->theora_tables) {
+ const uint8_t (*bias_tabs)[32][2];
/* init VLC tables */
bias_tabs = CONFIG_VP4_DECODER && s->version >= 2 ? vp4_bias : vp3_bias;
- for (int i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++) {
- ret = ff_vlc_init_from_lengths(&s->coeff_vlc[i], 11, 32,
+ for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
+ ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, 32,
&bias_tabs[i][0][1], 2,
&bias_tabs[i][0][0], 2, 1,
0, 0, avctx);
@@ -2475,10 +2503,10 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
return ret;
}
} else {
- for (int i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++) {
+ for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
const HuffTable *tab = &s->huffman_table[i];
- ret = ff_vlc_init_from_lengths(&s->coeff_vlc[i], 11, tab->nb_entries,
+ ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, tab->nb_entries,
&tab->entries[0].len, sizeof(*tab->entries),
&tab->entries[0].sym, sizeof(*tab->entries), 1,
0, 0, avctx);
@@ -2486,6 +2514,7 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
return ret;
}
}
+ }
ff_thread_once(&init_static_once, init_tables_once);
@@ -2534,6 +2563,8 @@ static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *
const Vp3DecodeContext *s1 = src->priv_data;
int qps_changed = 0, err;
+ ff_refstruct_replace(&s->coeff_vlc, s1->coeff_vlc);
+
if (!s1->current_frame.f->data[0] ||
s->width != s1->width || s->height != s1->height) {
if (s != s1)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 22/61] avcodec/vp3: Avoid complete VLC struct, only use VLCElem*
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (19 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 21/61] avcodec/vp3: Share coefficient VLCs between threads Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 23/61] avcodec/vp3: Reindent after the previous commits Andreas Rheinhardt
` (39 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vp3.c | 61 ++++++++++++++++++++++++------------------------
1 file changed, 31 insertions(+), 30 deletions(-)
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 1abf7e8078..b7c323b153 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -190,6 +190,7 @@ typedef struct HuffTable {
} HuffTable;
typedef struct CoeffVLCs {
+ const VLCElem *vlc_tabs[80];
VLC vlcs[80];
} CoeffVLCs;
@@ -1181,7 +1182,7 @@ static inline int get_coeff(GetBitContext *gb, int token, int16_t *coeff)
* be passed into the next call to this same function.
*/
static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
- const VLC *table, int coeff_index,
+ const VLCElem *vlc_table, int coeff_index,
int plane,
int eob_run)
{
@@ -1197,7 +1198,6 @@ static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
/* local references to structure members to avoid repeated dereferences */
const int *coded_fragment_list = s->coded_fragment_list[plane];
Vp3Fragment *all_fragments = s->all_fragments;
- const VLCElem *vlc_table = table->table;
if (num_coeffs < 0) {
av_log(s->avctx, AV_LOG_ERROR,
@@ -1303,14 +1303,13 @@ static void reverse_dc_prediction(Vp3DecodeContext *s,
*/
static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
{
- const VLC *coeff_vlc = s->coeff_vlc->vlcs;
+ const VLCElem *const *coeff_vlc = s->coeff_vlc->vlc_tabs;
int dc_y_table;
int dc_c_table;
int ac_y_table;
int ac_c_table;
int residual_eob_run = 0;
- const VLC *y_tables[64];
- const VLC *c_tables[64];
+ const VLCElem *y_tables[64], *c_tables[64];
s->dct_tokens[0][0] = s->dct_tokens_base;
@@ -1322,7 +1321,7 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
dc_c_table = get_bits(gb, 4);
/* unpack the Y plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &coeff_vlc[dc_y_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, coeff_vlc[dc_y_table], 0,
0, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
@@ -1333,11 +1332,11 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]);
/* unpack the C plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &coeff_vlc[dc_c_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, coeff_vlc[dc_c_table], 0,
1, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
- residual_eob_run = unpack_vlcs(s, gb, &coeff_vlc[dc_c_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, coeff_vlc[dc_c_table], 0,
2, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
@@ -1359,23 +1358,23 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
/* build tables of AC VLC tables */
for (int i = 1; i <= 5; i++) {
/* AC VLC table group 1 */
- y_tables[i] = &coeff_vlc[ac_y_table + 16];
- c_tables[i] = &coeff_vlc[ac_c_table + 16];
+ y_tables[i] = coeff_vlc[ac_y_table + 16];
+ c_tables[i] = coeff_vlc[ac_c_table + 16];
}
for (int i = 6; i <= 14; i++) {
/* AC VLC table group 2 */
- y_tables[i] = &coeff_vlc[ac_y_table + 32];
- c_tables[i] = &coeff_vlc[ac_c_table + 32];
+ y_tables[i] = coeff_vlc[ac_y_table + 32];
+ c_tables[i] = coeff_vlc[ac_c_table + 32];
}
for (int i = 15; i <= 27; i++) {
/* AC VLC table group 3 */
- y_tables[i] = &coeff_vlc[ac_y_table + 48];
- c_tables[i] = &coeff_vlc[ac_c_table + 48];
+ y_tables[i] = coeff_vlc[ac_y_table + 48];
+ c_tables[i] = coeff_vlc[ac_c_table + 48];
}
for (int i = 28; i <= 63; i++) {
/* AC VLC table group 4 */
- y_tables[i] = &coeff_vlc[ac_y_table + 64];
- c_tables[i] = &coeff_vlc[ac_c_table + 64];
+ y_tables[i] = coeff_vlc[ac_y_table + 64];
+ c_tables[i] = coeff_vlc[ac_c_table + 64];
}
/* decode all AC coefficients */
@@ -1406,7 +1405,7 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
* @return < 0 on error
*/
static int vp4_unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
- const VLC *vlc_tables[64],
+ const VLCElem *const vlc_tables[64],
int plane, int eob_tracker[64], int fragment)
{
int token;
@@ -1419,7 +1418,7 @@ static int vp4_unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
if (get_bits_left(gb) < 1)
return AVERROR_INVALIDDATA;
- token = get_vlc2(gb, vlc_tables[coeff_i]->table, 11, 3);
+ token = get_vlc2(gb, vlc_tables[coeff_i], 11, 3);
/* use the token to get a zero run, a coefficient, and an eob run */
if ((unsigned) token <= 6U) {
@@ -1526,12 +1525,12 @@ static void vp4_set_tokens_base(Vp3DecodeContext *s)
static int vp4_unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
{
- const VLC *coeff_vlc = s->coeff_vlc->vlcs;
+ const VLCElem *const *coeff_vlc = s->coeff_vlc->vlc_tabs;
int dc_y_table;
int dc_c_table;
int ac_y_table;
int ac_c_table;
- const VLC *tables[2][64];
+ const VLCElem *tables[2][64];
int eob_tracker[64];
VP4Predictor dc_pred[6][6];
int last_dc[NB_VP4_DC_TYPES];
@@ -1549,27 +1548,27 @@ static int vp4_unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
/* build tables of DC/AC VLC tables */
/* DC table group */
- tables[0][0] = &coeff_vlc[dc_y_table];
- tables[1][0] = &coeff_vlc[dc_c_table];
+ tables[0][0] = coeff_vlc[dc_y_table];
+ tables[1][0] = coeff_vlc[dc_c_table];
for (int i = 1; i <= 5; i++) {
/* AC VLC table group 1 */
- tables[0][i] = &coeff_vlc[ac_y_table + 16];
- tables[1][i] = &coeff_vlc[ac_c_table + 16];
+ tables[0][i] = coeff_vlc[ac_y_table + 16];
+ tables[1][i] = coeff_vlc[ac_c_table + 16];
}
for (int i = 6; i <= 14; i++) {
/* AC VLC table group 2 */
- tables[0][i] = &coeff_vlc[ac_y_table + 32];
- tables[1][i] = &coeff_vlc[ac_c_table + 32];
+ tables[0][i] = coeff_vlc[ac_y_table + 32];
+ tables[1][i] = coeff_vlc[ac_c_table + 32];
}
for (int i = 15; i <= 27; i++) {
/* AC VLC table group 3 */
- tables[0][i] = &coeff_vlc[ac_y_table + 48];
- tables[1][i] = &coeff_vlc[ac_c_table + 48];
+ tables[0][i] = coeff_vlc[ac_y_table + 48];
+ tables[1][i] = coeff_vlc[ac_c_table + 48];
}
for (int i = 28; i <= 63; i++) {
/* AC VLC table group 4 */
- tables[0][i] = &coeff_vlc[ac_y_table + 64];
- tables[1][i] = &coeff_vlc[ac_c_table + 64];
+ tables[0][i] = coeff_vlc[ac_y_table + 64];
+ tables[1][i] = coeff_vlc[ac_c_table + 64];
}
vp4_set_tokens_base(s);
@@ -2501,6 +2500,7 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
0, 0, avctx);
if (ret < 0)
return ret;
+ vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
}
} else {
for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
@@ -2512,6 +2512,7 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
0, 0, avctx);
if (ret < 0)
return ret;
+ vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
}
}
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 23/61] avcodec/vp3: Reindent after the previous commits
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (20 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 22/61] avcodec/vp3: Avoid complete VLC struct, only use VLCElem* Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 24/61] avcodec/rv34: Avoid superfluous VLC structures Andreas Rheinhardt
` (38 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vp3.c | 52 ++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index b7c323b153..b11be97fbf 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -2488,34 +2488,34 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
s->coeff_vlc = vlcs;
- if (!s->theora_tables) {
- const uint8_t (*bias_tabs)[32][2];
-
- /* init VLC tables */
- bias_tabs = CONFIG_VP4_DECODER && s->version >= 2 ? vp4_bias : vp3_bias;
- for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
- ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, 32,
- &bias_tabs[i][0][1], 2,
- &bias_tabs[i][0][0], 2, 1,
- 0, 0, avctx);
- if (ret < 0)
- return ret;
- vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
- }
- } else {
- for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
- const HuffTable *tab = &s->huffman_table[i];
-
- ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, tab->nb_entries,
- &tab->entries[0].len, sizeof(*tab->entries),
- &tab->entries[0].sym, sizeof(*tab->entries), 1,
- 0, 0, avctx);
- if (ret < 0)
- return ret;
- vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
+ if (!s->theora_tables) {
+ const uint8_t (*bias_tabs)[32][2];
+
+ /* init VLC tables */
+ bias_tabs = CONFIG_VP4_DECODER && s->version >= 2 ? vp4_bias : vp3_bias;
+ for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
+ ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, 32,
+ &bias_tabs[i][0][1], 2,
+ &bias_tabs[i][0][0], 2, 1,
+ 0, 0, avctx);
+ if (ret < 0)
+ return ret;
+ vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
+ }
+ } else {
+ for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
+ const HuffTable *tab = &s->huffman_table[i];
+
+ ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, tab->nb_entries,
+ &tab->entries[0].len, sizeof(*tab->entries),
+ &tab->entries[0].sym, sizeof(*tab->entries), 1,
+ 0, 0, avctx);
+ if (ret < 0)
+ return ret;
+ vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
+ }
}
}
- }
ff_thread_once(&init_static_once, init_tables_once);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 24/61] avcodec/rv34: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (21 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 23/61] avcodec/vp3: Reindent after the previous commits Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 25/61] avcodec/rv34: Constify pointer to static object Andreas Rheinhardt
` (37 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For most VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv34.c | 74 +++++++++++++++++++++++++++--------------------
libavcodec/rv34.h | 12 ++++----
2 files changed, 49 insertions(+), 37 deletions(-)
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index e9660bb457..a7bc8efd8e 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -90,8 +90,8 @@ static VLCElem table_data[117592];
* @param insyms symbols for input codes (NULL for default ones)
* @param num VLC table number (for static initialization)
*/
-static void rv34_gen_vlc(const uint8_t *bits, int size, VLC *vlc, const uint8_t *syms,
- int *offset)
+static av_cold void rv34_gen_vlc_ext(const uint8_t *bits, int size, VLC *vlc,
+ const uint8_t *syms, int *offset)
{
int counts[17] = {0}, codes[17];
uint16_t cw[MAX_VLC_SIZE];
@@ -120,6 +120,14 @@ static void rv34_gen_vlc(const uint8_t *bits, int size, VLC *vlc, const uint8_t
*offset += vlc->table_size;
}
+static av_cold void rv34_gen_vlc(const uint8_t *bits, int size, const VLCElem **vlcp,
+ int *offset)
+{
+ VLC vlc = { 0 };
+ rv34_gen_vlc_ext(bits, size, &vlc, NULL, offset);
+ *vlcp = vlc.table;
+}
+
/**
* Initialize all tables.
*/
@@ -130,41 +138,41 @@ static av_cold void rv34_init_tables(void)
for(i = 0; i < NUM_INTRA_TABLES; i++){
for(j = 0; j < 2; j++){
rv34_gen_vlc(rv34_table_intra_cbppat [i][j], CBPPAT_VLC_SIZE,
- &intra_vlcs[i].cbppattern[j], NULL, &offset);
+ &intra_vlcs[i].cbppattern[j], &offset);
rv34_gen_vlc(rv34_table_intra_secondpat[i][j], OTHERBLK_VLC_SIZE,
- &intra_vlcs[i].second_pattern[j], NULL, &offset);
+ &intra_vlcs[i].second_pattern[j], &offset);
rv34_gen_vlc(rv34_table_intra_thirdpat [i][j], OTHERBLK_VLC_SIZE,
- &intra_vlcs[i].third_pattern[j], NULL, &offset);
+ &intra_vlcs[i].third_pattern[j], &offset);
for(k = 0; k < 4; k++){
- rv34_gen_vlc(rv34_table_intra_cbp[i][j+k*2], CBP_VLC_SIZE,
- &intra_vlcs[i].cbp[j][k], rv34_cbp_code, &offset);
+ rv34_gen_vlc_ext(rv34_table_intra_cbp[i][j+k*2], CBP_VLC_SIZE,
+ &intra_vlcs[i].cbp[j][k], rv34_cbp_code, &offset);
}
}
for(j = 0; j < 4; j++){
rv34_gen_vlc(rv34_table_intra_firstpat[i][j], FIRSTBLK_VLC_SIZE,
- &intra_vlcs[i].first_pattern[j], NULL, &offset);
+ &intra_vlcs[i].first_pattern[j], &offset);
}
rv34_gen_vlc(rv34_intra_coeff[i], COEFF_VLC_SIZE,
- &intra_vlcs[i].coefficient, NULL, &offset);
+ &intra_vlcs[i].coefficient, &offset);
}
for(i = 0; i < NUM_INTER_TABLES; i++){
rv34_gen_vlc(rv34_inter_cbppat[i], CBPPAT_VLC_SIZE,
- &inter_vlcs[i].cbppattern[0], NULL, &offset);
+ &inter_vlcs[i].cbppattern[0], &offset);
for(j = 0; j < 4; j++){
- rv34_gen_vlc(rv34_inter_cbp[i][j], CBP_VLC_SIZE,
- &inter_vlcs[i].cbp[0][j], rv34_cbp_code, &offset);
+ rv34_gen_vlc_ext(rv34_inter_cbp[i][j], CBP_VLC_SIZE,
+ &inter_vlcs[i].cbp[0][j], rv34_cbp_code, &offset);
}
for(j = 0; j < 2; j++){
rv34_gen_vlc(rv34_table_inter_firstpat [i][j], FIRSTBLK_VLC_SIZE,
- &inter_vlcs[i].first_pattern[j], NULL, &offset);
+ &inter_vlcs[i].first_pattern[j], &offset);
rv34_gen_vlc(rv34_table_inter_secondpat[i][j], OTHERBLK_VLC_SIZE,
- &inter_vlcs[i].second_pattern[j], NULL, &offset);
+ &inter_vlcs[i].second_pattern[j], &offset);
rv34_gen_vlc(rv34_table_inter_thirdpat [i][j], OTHERBLK_VLC_SIZE,
- &inter_vlcs[i].third_pattern[j], NULL, &offset);
+ &inter_vlcs[i].third_pattern[j], &offset);
}
rv34_gen_vlc(rv34_inter_coeff[i], COEFF_VLC_SIZE,
- &inter_vlcs[i].coefficient, NULL, &offset);
+ &inter_vlcs[i].coefficient, &offset);
}
}
@@ -187,7 +195,7 @@ static int rv34_decode_cbp(GetBitContext *gb, RV34VLC *vlc, int table)
const int *curshift = shifts;
int i, t, mask;
- code = get_vlc2(gb, vlc->cbppattern[table].table, 9, 2);
+ code = get_vlc2(gb, vlc->cbppattern[table], 9, 2);
pattern = code & 0xF;
code >>= 4;
@@ -211,11 +219,12 @@ static int rv34_decode_cbp(GetBitContext *gb, RV34VLC *vlc, int table)
/**
* Get one coefficient value from the bitstream and store it.
*/
-static inline void decode_coeff(int16_t *dst, int coef, int esc, GetBitContext *gb, VLC* vlc, int q)
+static inline void decode_coeff(int16_t *dst, int coef, int esc, GetBitContext *gb,
+ const VLCElem *vlc, int q)
{
if(coef){
if(coef == esc){
- coef = get_vlc2(gb, vlc->table, 9, 2);
+ coef = get_vlc2(gb, vlc, 9, 2);
if(coef > 23){
coef -= 23;
coef = 22 + ((1 << coef) | get_bits(gb, coef));
@@ -231,7 +240,8 @@ static inline void decode_coeff(int16_t *dst, int coef, int esc, GetBitContext *
/**
* Decode 2x2 subblock of coefficients.
*/
-static inline void decode_subblock(int16_t *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc, int q)
+static inline void decode_subblock(int16_t *dst, int code, const int is_block2,
+ GetBitContext *gb, const VLCElem *vlc, int q)
{
int flags = modulo_three_table[code];
@@ -249,13 +259,15 @@ static inline void decode_subblock(int16_t *dst, int code, const int is_block2,
/**
* Decode a single coefficient.
*/
-static inline void decode_subblock1(int16_t *dst, int code, GetBitContext *gb, VLC *vlc, int q)
+static inline void decode_subblock1(int16_t *dst, int code, GetBitContext *gb,
+ const VLCElem *vlc, int q)
{
int coeff = modulo_three_table[code] >> 6;
decode_coeff(dst, coeff, 3, gb, vlc, q);
}
-static inline void decode_subblock3(int16_t *dst, int code, GetBitContext *gb, VLC *vlc,
+static inline void decode_subblock3(int16_t *dst, int code, GetBitContext *gb,
+ const VLCElem *vlc,
int q_dc, int q_ac1, int q_ac2)
{
int flags = modulo_three_table[code];
@@ -281,32 +293,32 @@ static int rv34_decode_block(int16_t *dst, GetBitContext *gb, RV34VLC *rvlc, int
{
int code, pattern, has_ac = 1;
- code = get_vlc2(gb, rvlc->first_pattern[fc].table, 9, 2);
+ code = get_vlc2(gb, rvlc->first_pattern[fc], 9, 2);
pattern = code & 0x7;
code >>= 3;
if (modulo_three_table[code] & 0x3F) {
- decode_subblock3(dst, code, gb, &rvlc->coefficient, q_dc, q_ac1, q_ac2);
+ decode_subblock3(dst, code, gb, rvlc->coefficient, q_dc, q_ac1, q_ac2);
} else {
- decode_subblock1(dst, code, gb, &rvlc->coefficient, q_dc);
+ decode_subblock1(dst, code, gb, rvlc->coefficient, q_dc);
if (!pattern)
return 0;
has_ac = 0;
}
if(pattern & 4){
- code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2);
- decode_subblock(dst + 4*0+2, code, 0, gb, &rvlc->coefficient, q_ac2);
+ code = get_vlc2(gb, rvlc->second_pattern[sc], 9, 2);
+ decode_subblock(dst + 4*0+2, code, 0, gb, rvlc->coefficient, q_ac2);
}
if(pattern & 2){ // Looks like coefficients 1 and 2 are swapped for this block
- code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2);
- decode_subblock(dst + 4*2+0, code, 1, gb, &rvlc->coefficient, q_ac2);
+ code = get_vlc2(gb, rvlc->second_pattern[sc], 9, 2);
+ decode_subblock(dst + 4*2+0, code, 1, gb, rvlc->coefficient, q_ac2);
}
if(pattern & 1){
- code = get_vlc2(gb, rvlc->third_pattern[sc].table, 9, 2);
- decode_subblock(dst + 4*2+2, code, 0, gb, &rvlc->coefficient, q_ac2);
+ code = get_vlc2(gb, rvlc->third_pattern[sc], 9, 2);
+ decode_subblock(dst + 4*2+2, code, 0, gb, rvlc->coefficient, q_ac2);
}
return has_ac | pattern;
}
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index 84789625ce..4bb81b4965 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -63,12 +63,12 @@ enum RV40BlockTypes{
* Intra frame VLC sets do not contain some of those tables.
*/
typedef struct RV34VLC{
- VLC cbppattern[2]; ///< VLCs used for pattern of coded block patterns decoding
- VLC cbp[2][4]; ///< VLCs used for coded block patterns decoding
- VLC first_pattern[4]; ///< VLCs used for decoding coefficients in the first subblock
- VLC second_pattern[2]; ///< VLCs used for decoding coefficients in the subblocks 2 and 3
- VLC third_pattern[2]; ///< VLCs used for decoding coefficients in the last subblock
- VLC coefficient; ///< VLCs used for decoding big coefficients
+ const VLCElem *cbppattern[2]; ///< VLCs used for pattern of coded block patterns decoding
+ VLC cbp[2][4]; ///< VLCs used for coded block patterns decoding
+ const VLCElem *first_pattern[4]; ///< VLCs used for decoding coefficients in the first subblock
+ const VLCElem *second_pattern[2]; ///< VLCs used for decoding coefficients in the subblocks 2 and 3
+ const VLCElem *third_pattern[2]; ///< VLCs used for decoding coefficients in the last subblock
+ const VLCElem *coefficient; ///< VLCs used for decoding big coefficients
}RV34VLC;
/** essential slice information */
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 25/61] avcodec/rv34: Constify pointer to static object
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (22 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 24/61] avcodec/rv34: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 26/61] avcodec/wnv1: Avoid unnecessary VLC structure Andreas Rheinhardt
` (36 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Said object is only allowed to be modified during its
initialization and is immutable afterwards.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv34.c | 5 +++--
libavcodec/rv34.h | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index a7bc8efd8e..3e065d14b1 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -186,7 +186,7 @@ static av_cold void rv34_init_tables(void)
/**
* Decode coded block pattern.
*/
-static int rv34_decode_cbp(GetBitContext *gb, RV34VLC *vlc, int table)
+static int rv34_decode_cbp(GetBitContext *gb, const RV34VLC *vlc, int table)
{
int pattern, code, cbp=0;
int ones;
@@ -289,7 +289,8 @@ static inline void decode_subblock3(int16_t *dst, int code, GetBitContext *gb,
* o--o
*/
-static int rv34_decode_block(int16_t *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc, int q_dc, int q_ac1, int q_ac2)
+static int rv34_decode_block(int16_t *dst, GetBitContext *gb, const RV34VLC *rvlc,
+ int fc, int sc, int q_dc, int q_ac1, int q_ac2)
{
int code, pattern, has_ac = 1;
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index 4bb81b4965..6fe1f8087d 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -92,7 +92,7 @@ typedef struct RV34DecContext{
const uint8_t *luma_dc_quant_i;///< luma subblock DC quantizer for intraframes
const uint8_t *luma_dc_quant_p;///< luma subblock DC quantizer for interframes
- RV34VLC *cur_vlcs; ///< VLC set used for current frame decoding
+ const RV34VLC *cur_vlcs; ///< VLC set used for current frame decoding
H264PredContext h; ///< functions for 4x4 and 16x16 intra block prediction
SliceInfo si; ///< current slice information
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 26/61] avcodec/wnv1: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (23 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 25/61] avcodec/rv34: Constify pointer to static object Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 27/61] avcodec/mv30: " Andreas Rheinhardt
` (35 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/wnv1.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c
index ffc9174ab2..0e8dae598f 100644
--- a/libavcodec/wnv1.c
+++ b/libavcodec/wnv1.c
@@ -39,12 +39,12 @@ static const uint8_t code_tab[16][2] = {
};
#define CODE_VLC_BITS 9
-static VLC code_vlc;
+static VLCElem code_vlc[1 << CODE_VLC_BITS];
/* returns modified base_value */
static inline int wnv1_get_code(GetBitContext *gb, int shift, int base_value)
{
- int v = get_vlc2(gb, code_vlc.table, CODE_VLC_BITS, 1);
+ int v = get_vlc2(gb, code_vlc, CODE_VLC_BITS, 1);
if (v == 8)
return get_bits(gb, 8 - shift) << shift;
@@ -115,10 +115,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
static av_cold void wnv1_init_static(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&code_vlc, CODE_VLC_BITS, 16,
- &code_tab[0][1], 2,
- &code_tab[0][0], 2, 1,
- -7, VLC_INIT_OUTPUT_LE, 1 << CODE_VLC_BITS);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(code_vlc, CODE_VLC_BITS, 16,
+ &code_tab[0][1], 2,
+ &code_tab[0][0], 2, 1,
+ -7, VLC_INIT_OUTPUT_LE);
}
static av_cold int decode_init(AVCodecContext *avctx)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 27/61] avcodec/mv30: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (24 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 26/61] avcodec/wnv1: Avoid unnecessary VLC structure Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 28/61] avcodec/vqcdec: " Andreas Rheinhardt
` (34 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mv30.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mv30.c b/libavcodec/mv30.c
index 9c72c0080d..8c45c8304b 100644
--- a/libavcodec/mv30.c
+++ b/libavcodec/mv30.c
@@ -59,7 +59,7 @@ typedef struct MV30Context {
AVFrame *prev_frame;
} MV30Context;
-static VLC cbp_tab;
+static VLCElem cbp_tab[1 << CBP_VLC_BITS];
static const uint8_t luma_tab[] = {
12, 12, 15, 19, 25, 34, 40, 48,
@@ -379,7 +379,7 @@ static int decode_coeffs(GetBitContext *gb, int16_t *coeffs, int nb_codes)
memset(coeffs, 0, nb_codes * sizeof(*coeffs));
for (int i = 0; i < nb_codes;) {
- int value = get_vlc2(gb, cbp_tab.table, CBP_VLC_BITS, 1);
+ int value = get_vlc2(gb, cbp_tab, CBP_VLC_BITS, 1);
if (value > 0) {
int x = get_bits(gb, value);
@@ -657,8 +657,9 @@ static const uint8_t cbp_bits[] = {
static av_cold void init_static_data(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&cbp_tab, CBP_VLC_BITS, FF_ARRAY_ELEMS(cbp_bits),
- cbp_bits, 1, NULL, 0, 0, 0, 0, 1 << CBP_VLC_BITS);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(cbp_tab, CBP_VLC_BITS,
+ FF_ARRAY_ELEMS(cbp_bits),
+ cbp_bits, 1, NULL, 0, 0, 0, 0);
}
static av_cold int decode_init(AVCodecContext *avctx)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 28/61] avcodec/vqcdec: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (25 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 27/61] avcodec/mv30: " Andreas Rheinhardt
@ 2023-09-26 22:16 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: " Andreas Rheinhardt
` (33 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:16 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vqcdec.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/libavcodec/vqcdec.c b/libavcodec/vqcdec.c
index 462d810a2f..dc9248d99f 100644
--- a/libavcodec/vqcdec.c
+++ b/libavcodec/vqcdec.c
@@ -49,14 +49,15 @@ static const int8_t vector_symbols[] = {
2, 3, 4, SIGNED_8BIT, -2, -3, -4, SIGNED_6BIT
};
-static VLC vector_vlc;
+static VLCElem vector_vlc[1 << VECTOR_VLC_BITS];
static av_cold void vqc_init_static_data(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&vector_vlc, VECTOR_VLC_BITS, FF_ARRAY_ELEMS(vector_nbits),
- vector_nbits, 1,
- vector_symbols, 1, 1,
- 0, 0, 1 << VECTOR_VLC_BITS);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vector_vlc, VECTOR_VLC_BITS,
+ FF_ARRAY_ELEMS(vector_nbits),
+ vector_nbits, 1,
+ vector_symbols, 1, 1,
+ 0, 0);
}
typedef struct VqcContext {
@@ -171,7 +172,7 @@ static int decode_vectors(VqcContext * s, const uint8_t * buf, int size, int wid
continue;
}
- symbol = get_vlc2(&gb, vector_vlc.table, VECTOR_VLC_BITS, 1);
+ symbol = get_vlc2(&gb, vector_vlc, VECTOR_VLC_BITS, 1);
switch(symbol) {
case SKIP_3: dst += 3; break;
case SKIP_4: dst += 4; break;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (26 preceding siblings ...)
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 28/61] avcodec/vqcdec: " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-27 23:20 ` Michael Niedermayer
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 30/61] avcodec/mimic: " Andreas Rheinhardt
` (32 subsequent siblings)
60 siblings, 1 reply; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and only VLC.table needs to be retained.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mobiclip.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c
index 98c0f55a5c..144fec6363 100644
--- a/libavcodec/mobiclip.c
+++ b/libavcodec/mobiclip.c
@@ -274,28 +274,26 @@ typedef struct MobiClipContext {
BswapDSPContext bdsp;
} MobiClipContext;
-static VLC rl_vlc[2];
-static VLC mv_vlc[2][16];
+static const VLCElem *rl_vlc[2];
+static const VLCElem *mv_vlc[2][16];
static av_cold void mobiclip_init_static(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&rl_vlc[0], MOBI_RL_VLC_BITS, 104,
- bits0, sizeof(*bits0),
- syms0, sizeof(*syms0), sizeof(*syms0),
- 0, 0, 1 << MOBI_RL_VLC_BITS);
- VLC_INIT_STATIC_FROM_LENGTHS(&rl_vlc[1], MOBI_RL_VLC_BITS, 104,
- bits0, sizeof(*bits0),
- syms1, sizeof(*syms1), sizeof(*syms1),
- 0, 0, 1 << MOBI_RL_VLC_BITS);
+ static VLCElem vlc_buf[(2 << MOBI_RL_VLC_BITS) + (2 * 16 << MOBI_MV_VLC_BITS)];
+ VLCInitState state =VLC_INIT_STATE(vlc_buf);
+
for (int i = 0; i < 2; i++) {
- static VLCElem vlc_buf[2 * 16 << MOBI_MV_VLC_BITS];
+ rl_vlc[i] =
+ ff_vlc_init_tables_from_lengths(&state, MOBI_RL_VLC_BITS, 104,
+ bits0, sizeof(*bits0),
+ syms0, sizeof(*syms0), sizeof(*syms0),
+ 0, 0);
for (int j = 0; j < 16; j++) {
- mv_vlc[i][j].table = &vlc_buf[(16 * i + j) << MOBI_MV_VLC_BITS];
- mv_vlc[i][j].table_allocated = 1 << MOBI_MV_VLC_BITS;
- ff_vlc_init_from_lengths(&mv_vlc[i][j], MOBI_MV_VLC_BITS, mv_len[j],
- mv_bits[i][j], sizeof(*mv_bits[i][j]),
- mv_syms[i][j], sizeof(*mv_syms[i][j]), sizeof(*mv_syms[i][j]),
- 0, VLC_INIT_USE_STATIC, NULL);
+ mv_vlc[i][j] =
+ ff_vlc_init_tables_from_lengths(&state, MOBI_MV_VLC_BITS, mv_len[j],
+ mv_bits[i][j], sizeof(*mv_bits[i][j]),
+ mv_syms[i][j], sizeof(*mv_syms[i][j]), sizeof(*mv_syms[i][j]),
+ 0, 0);
}
}
}
@@ -410,8 +408,7 @@ static void read_run_encoding(AVCodecContext *avctx,
{
MobiClipContext *s = avctx->priv_data;
GetBitContext *gb = &s->gb;
- int n = get_vlc2(gb, rl_vlc[s->dct_tab_idx].table,
- MOBI_RL_VLC_BITS, 1);
+ int n = get_vlc2(gb, rl_vlc[s->dct_tab_idx], MOBI_RL_VLC_BITS, 1);
*last = (n >> 11) == 1;
*run = (n >> 5) & 0x3F;
@@ -1195,8 +1192,7 @@ static int predict_motion(AVCodecContext *avctx,
for (int i = 0; i < 2; i++) {
int ret, idx2;
- idx2 = get_vlc2(gb, mv_vlc[s->moflex][tidx].table,
- MOBI_MV_VLC_BITS, 1);
+ idx2 = get_vlc2(gb, mv_vlc[s->moflex][tidx], MOBI_MV_VLC_BITS, 1);
ret = predict_motion(avctx, width, height, idx2,
offsetm, offsetx + i * adjx, offsety + i * adjy);
@@ -1272,8 +1268,7 @@ static int mobiclip_decode(AVCodecContext *avctx, AVFrame *rframe,
motion[x / 16 + 2].x = 0;
motion[x / 16 + 2].y = 0;
- idx = get_vlc2(gb, mv_vlc[s->moflex][0].table,
- MOBI_MV_VLC_BITS, 1);
+ idx = get_vlc2(gb, mv_vlc[s->moflex][0], MOBI_MV_VLC_BITS, 1);
if (idx == 6 || idx == 7) {
ret = decode_macroblock(avctx, frame, x, y, idx == 7);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 30/61] avcodec/mimic: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (27 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 31/61] avcodec/imm4: " Andreas Rheinhardt
` (31 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mimic.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index a846a07a40..62029e9dd5 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -67,7 +67,7 @@ typedef struct MimicContext {
int next_prev_index;
} MimicContext;
-static VLC block_vlc;
+static VLCElem block_vlc[4368];
static const uint8_t huffsyms[] = {
0x10, 0x20, 0x30, 0x00, 0x11, 0x40, 0x50, 0x12, 0x13, 0x21, 0x31, 0x60,
@@ -120,8 +120,9 @@ static av_cold int mimic_decode_end(AVCodecContext *avctx)
static av_cold void mimic_init_static(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&block_vlc, MIMIC_VLC_BITS, FF_ARRAY_ELEMS(huffbits),
- huffbits, 1, huffsyms, 1, 1, 0, 0, 4368);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(block_vlc, MIMIC_VLC_BITS,
+ FF_ARRAY_ELEMS(huffbits),
+ huffbits, 1, huffsyms, 1, 1, 0, 0);
}
static av_cold int mimic_decode_init(AVCodecContext *avctx)
@@ -226,7 +227,7 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale)
int value;
int coeff;
- vlc = get_vlc2(&ctx->gb, block_vlc.table, MIMIC_VLC_BITS, 3);
+ vlc = get_vlc2(&ctx->gb, block_vlc, MIMIC_VLC_BITS, 3);
if (!vlc) /* end-of-block code */
return 0;
if (vlc == -1)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 31/61] avcodec/imm4: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (28 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 30/61] avcodec/mimic: " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 32/61] avcodec/lagarith: " Andreas Rheinhardt
` (30 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/imm4.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/libavcodec/imm4.c b/libavcodec/imm4.c
index d4011b33c1..656fc9c05f 100644
--- a/libavcodec/imm4.c
+++ b/libavcodec/imm4.c
@@ -108,16 +108,16 @@ static const uint8_t block_bits[] = {
6, 5, 5, 5, 4, 2, 3, 4, 4,
};
-static VLC cbplo_tab;
-static VLC cbphi_tab;
-static VLC blktype_tab;
-static VLC block_tab;
+static VLCElem cbplo_tab[1 << CBPLO_VLC_BITS];
+static VLCElem cbphi_tab[1 << CBPHI_VLC_BITS];
+static VLCElem blktype_tab[1 << BLKTYPE_VLC_BITS];
+static VLCElem block_tab[1 << BLOCK_VLC_BITS];
static int get_cbphi(GetBitContext *gb, int x)
{
int value;
- value = get_vlc2(gb, cbphi_tab.table, CBPHI_VLC_BITS, 1);
+ value = get_vlc2(gb, cbphi_tab, CBPHI_VLC_BITS, 1);
if (value < 0)
return AVERROR_INVALIDDATA;
@@ -134,7 +134,7 @@ static int decode_block(AVCodecContext *avctx, GetBitContext *gb,
for (i = !flag; i < 64; i++) {
int value;
- value = get_vlc2(gb, block_tab.table, BLOCK_VLC_BITS, 1);
+ value = get_vlc2(gb, block_tab, BLOCK_VLC_BITS, 1);
if (value < 0)
return AVERROR_INVALIDDATA;
if (value == 0) {
@@ -221,7 +221,7 @@ static int decode_intra(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame
for (x = 0; x < avctx->width; x += 16) {
unsigned flag, cbphi, cbplo;
- cbplo = get_vlc2(gb, cbplo_tab.table, CBPLO_VLC_BITS, 1);
+ cbplo = get_vlc2(gb, cbplo_tab, CBPLO_VLC_BITS, 1);
flag = get_bits1(gb);
cbphi = get_cbphi(gb, 1);
@@ -287,7 +287,7 @@ static int decode_inter(AVCodecContext *avctx, GetBitContext *gb,
continue;
}
- value = get_vlc2(gb, blktype_tab.table, BLKTYPE_VLC_BITS, 1);
+ value = get_vlc2(gb, blktype_tab, BLKTYPE_VLC_BITS, 1);
if (value < 0)
return AVERROR_INVALIDDATA;
@@ -473,20 +473,20 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
static av_cold void imm4_init_static_data(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&cbplo_tab, CBPLO_VLC_BITS, FF_ARRAY_ELEMS(cbplo),
- &cbplo[0][1], 2, &cbplo[0][0], 2, 1,
- 0, 0, 1 << CBPLO_VLC_BITS);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(cbplo_tab, CBPLO_VLC_BITS, FF_ARRAY_ELEMS(cbplo),
+ &cbplo[0][1], 2, &cbplo[0][0], 2, 1,
+ 0, 0);
- VLC_INIT_SPARSE_STATIC(&cbphi_tab, CBPHI_VLC_BITS, FF_ARRAY_ELEMS(cbphi_bits),
- cbphi_bits, 1, 1, cbphi_codes, 1, 1, NULL, 0, 0, 64);
+ VLC_INIT_STATIC_TABLE(cbphi_tab, CBPHI_VLC_BITS, FF_ARRAY_ELEMS(cbphi_bits),
+ cbphi_bits, 1, 1, cbphi_codes, 1, 1, 0);
- VLC_INIT_STATIC_FROM_LENGTHS(&blktype_tab, BLKTYPE_VLC_BITS, FF_ARRAY_ELEMS(blktype),
- &blktype[0][1], 2, &blktype[0][0], 2, 1,
- 0, 0, 1 << BLKTYPE_VLC_BITS);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(blktype_tab, BLKTYPE_VLC_BITS, FF_ARRAY_ELEMS(blktype),
+ &blktype[0][1], 2, &blktype[0][0], 2, 1,
+ 0, 0);
- VLC_INIT_STATIC_FROM_LENGTHS(&block_tab, BLOCK_VLC_BITS, FF_ARRAY_ELEMS(block_bits),
- block_bits, 1, block_symbols, 2, 2,
- 0, 0, 1 << BLOCK_VLC_BITS);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(block_tab, BLOCK_VLC_BITS, FF_ARRAY_ELEMS(block_bits),
+ block_bits, 1, block_symbols, 2, 2,
+ 0, 0);
}
static av_cold int decode_init(AVCodecContext *avctx)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 32/61] avcodec/lagarith: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (29 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 31/61] avcodec/imm4: " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 33/61] avcodec/speedhqdec: " Andreas Rheinhardt
` (29 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/lagarith.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/lagarith.c b/libavcodec/lagarith.c
index 3288c0517c..3c6635f763 100644
--- a/libavcodec/lagarith.c
+++ b/libavcodec/lagarith.c
@@ -60,7 +60,7 @@ typedef struct LagarithContext {
int zeros_rem; /**< number of zero bytes remaining to output */
} LagarithContext;
-static VLC lag_tab;
+static VLCElem lag_tab[1 << VLC_BITS];
static const uint8_t lag_bits[] = {
7, 7, 2, 7, 3, 4, 5, 6, 7, 7, 7, 7, 7, 6, 7, 4, 5, 7, 7, 7, 7,
@@ -85,8 +85,8 @@ static const uint8_t lag_symbols[] = {
static av_cold void lag_init_static_data(void)
{
- VLC_INIT_SPARSE_STATIC(&lag_tab, VLC_BITS, FF_ARRAY_ELEMS(lag_bits),
- lag_bits, 1, 1, lag_codes, 1, 1, lag_symbols, 1, 1, 128);
+ VLC_INIT_STATIC_SPARSE_TABLE(lag_tab, VLC_BITS, FF_ARRAY_ELEMS(lag_bits),
+ lag_bits, 1, 1, lag_codes, 1, 1, lag_symbols, 1, 1, 0);
}
/**
@@ -136,7 +136,7 @@ static int lag_decode_prob(GetBitContext *gb, uint32_t *value)
{
unsigned val, bits;
- bits = get_vlc2(gb, lag_tab.table, VLC_BITS, 1);
+ bits = get_vlc2(gb, lag_tab, VLC_BITS, 1);
if (bits > 31) {
*value = 0;
return AVERROR_INVALIDDATA;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 33/61] avcodec/speedhqdec: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (30 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 32/61] avcodec/lagarith: " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 34/61] avcodec/vc1: Avoid superfluous VLC structures Andreas Rheinhardt
` (28 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/speedhqdec.c | 52 ++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/libavcodec/speedhqdec.c b/libavcodec/speedhqdec.c
index f3e84ab348..d3605b0649 100644
--- a/libavcodec/speedhqdec.c
+++ b/libavcodec/speedhqdec.c
@@ -71,10 +71,10 @@ static const uint8_t unscaled_quant_matrix[64] = {
27, 29, 35, 38, 46, 56, 69, 83
};
-static VLC dc_lum_vlc_le;
-static VLC dc_chroma_vlc_le;
-static VLC dc_alpha_run_vlc_le;
-static VLC dc_alpha_level_vlc_le;
+static VLCElem dc_lum_vlc_le[512];
+static VLCElem dc_chroma_vlc_le[514];
+static VLCElem dc_alpha_run_vlc_le[160];
+static VLCElem dc_alpha_level_vlc_le[288];
static RL_VLC_ELEM speedhq_rl_vlc[674];
@@ -83,9 +83,9 @@ static inline int decode_dc_le(GetBitContext *gb, int component)
int code, diff;
if (component == 0 || component == 3) {
- code = get_vlc2(gb, dc_lum_vlc_le.table, DC_VLC_BITS, 2);
+ code = get_vlc2(gb, dc_lum_vlc_le, DC_VLC_BITS, 2);
} else {
- code = get_vlc2(gb, dc_chroma_vlc_le.table, DC_VLC_BITS, 2);
+ code = get_vlc2(gb, dc_chroma_vlc_le, DC_VLC_BITS, 2);
}
if (!code) {
diff = 0;
@@ -109,7 +109,7 @@ static inline int decode_alpha_block(const SHQContext *s, GetBitContext *gb, uin
int run, level;
UPDATE_CACHE_LE(re, gb);
- GET_VLC(run, re, gb, dc_alpha_run_vlc_le.table, ALPHA_VLC_BITS, 2);
+ GET_VLC(run, re, gb, dc_alpha_run_vlc_le, ALPHA_VLC_BITS, 2);
if (run < 0) break;
i += run;
@@ -117,7 +117,7 @@ static inline int decode_alpha_block(const SHQContext *s, GetBitContext *gb, uin
return AVERROR_INVALIDDATA;
UPDATE_CACHE_LE(re, gb);
- GET_VLC(level, re, gb, dc_alpha_level_vlc_le.table, ALPHA_VLC_BITS, 2);
+ GET_VLC(level, re, gb, dc_alpha_level_vlc_le, ALPHA_VLC_BITS, 2);
block[i++] = level;
}
@@ -506,11 +506,11 @@ static av_cold void compute_alpha_vlcs(void)
av_assert0(entry == FF_ARRAY_ELEMS(run_code));
- VLC_INIT_LE_SPARSE_STATIC(&dc_alpha_run_vlc_le, ALPHA_VLC_BITS,
- FF_ARRAY_ELEMS(run_code),
- run_bits, 1, 1,
- run_code, 2, 2,
- run_symbols, 2, 2, 160);
+ VLC_INIT_STATIC_SPARSE_TABLE(dc_alpha_run_vlc_le, ALPHA_VLC_BITS,
+ FF_ARRAY_ELEMS(run_code),
+ run_bits, 1, 1,
+ run_code, 2, 2,
+ run_symbols, 2, 2, VLC_INIT_LE);
/* Initialize VLC for alpha level. */
entry = 0;
@@ -546,24 +546,24 @@ static av_cold void compute_alpha_vlcs(void)
av_assert0(entry == FF_ARRAY_ELEMS(level_code));
- VLC_INIT_LE_SPARSE_STATIC(&dc_alpha_level_vlc_le, ALPHA_VLC_BITS,
- FF_ARRAY_ELEMS(level_code),
- level_bits, 1, 1,
- level_code, 2, 2,
- level_symbols, 2, 2, 288);
+ VLC_INIT_STATIC_SPARSE_TABLE(dc_alpha_level_vlc_le, ALPHA_VLC_BITS,
+ FF_ARRAY_ELEMS(level_code),
+ level_bits, 1, 1,
+ level_code, 2, 2,
+ level_symbols, 2, 2, VLC_INIT_LE);
}
static av_cold void speedhq_static_init(void)
{
/* Exactly the same as MPEG-2, except for a little-endian reader. */
- VLC_INIT_CUSTOM_STATIC(&dc_lum_vlc_le, DC_VLC_BITS, 12,
- ff_mpeg12_vlc_dc_lum_bits, 1, 1,
- ff_mpeg12_vlc_dc_lum_code, 2, 2,
- VLC_INIT_OUTPUT_LE, 512);
- VLC_INIT_CUSTOM_STATIC(&dc_chroma_vlc_le, DC_VLC_BITS, 12,
- ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
- ff_mpeg12_vlc_dc_chroma_code, 2, 2,
- VLC_INIT_OUTPUT_LE, 514);
+ VLC_INIT_STATIC_TABLE(dc_lum_vlc_le, DC_VLC_BITS, 12,
+ ff_mpeg12_vlc_dc_lum_bits, 1, 1,
+ ff_mpeg12_vlc_dc_lum_code, 2, 2,
+ VLC_INIT_OUTPUT_LE);
+ VLC_INIT_STATIC_TABLE(dc_chroma_vlc_le, DC_VLC_BITS, 12,
+ ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
+ ff_mpeg12_vlc_dc_chroma_code, 2, 2,
+ VLC_INIT_OUTPUT_LE);
ff_init_2d_vlc_rl(ff_speedhq_vlc_table, speedhq_rl_vlc, ff_speedhq_run,
ff_speedhq_level, SPEEDHQ_RL_NB_ELEMS,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 34/61] avcodec/vc1: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (31 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 33/61] avcodec/speedhqdec: " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 35/61] avcodec/4xm: Avoid unnecessary " Andreas Rheinhardt
` (27 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For all VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table. And in some cases one can even
avoid this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vc1.c | 60 +++++++-------
libavcodec/vc1.h | 10 +--
libavcodec/vc1_block.c | 74 +++++++++---------
libavcodec/vc1data.c | 36 ++++-----
libavcodec/vc1data.h | 36 ++++-----
libavcodec/vc1dec.c | 174 +++++++++++++++++------------------------
6 files changed, 180 insertions(+), 210 deletions(-)
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index 795c6db541..e234192fdd 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -104,7 +104,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
height = v->s.mb_height >> v->field_mode;
stride = v->s.mb_stride;
invert = get_bits1(gb);
- imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
+ imode = get_vlc2(gb, ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 1);
*raw_flag = 0;
switch (imode) {
@@ -126,7 +126,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
y = offset = 0;
// decode bitplane as one long line
for (; y < height * width; y += 2) {
- code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
+ code = get_vlc2(gb, ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 1);
*planep++ = code & 1;
offset++;
if (offset == width) {
@@ -146,7 +146,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
if (!(height % 3) && (width % 3)) { // use 2x3 decoding
for (y = 0; y < height; y += 3) {
for (x = width & 1; x < width; x += 2) {
- code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
+ code = get_vlc2(gb, ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 2);
if (code < 0) {
av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
return -1;
@@ -166,7 +166,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
planep += (height & 1) * stride;
for (y = height & 1; y < height; y += 2) {
for (x = width % 3; x < width; x += 3) {
- code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
+ code = get_vlc2(gb, ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 2);
if (code < 0) {
av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
return -1;
@@ -765,7 +765,7 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
/* Hopefully this is correct for P-frames */
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
v->cbptab = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
+ v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
@@ -804,7 +804,7 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
v->s.mv_table_index = get_bits(gb, 2);
v->cbptab = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
+ v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
@@ -1061,19 +1061,19 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->mbmodetab = get_bits(gb, 2);
if (v->fourmvswitch)
- v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[v->mbmodetab];
+ v->mbmode_vlc = ff_vc1_intfr_4mv_mbmode_vlc[v->mbmodetab];
else
- v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
+ v->mbmode_vlc = ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
v->imvtab = get_bits(gb, 2);
- v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
+ v->imv_vlc = ff_vc1_1ref_mvdata_vlc[v->imvtab];
// interlaced p-picture cbpcy range is [1, 63]
v->icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
+ v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
v->twomvbptab = get_bits(gb, 2);
- v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
+ v->twomvbp_vlc = ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
if (v->fourmvswitch) {
v->fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
+ v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
}
}
}
@@ -1158,7 +1158,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
/* Hopefully this is correct for P-frames */
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
v->cbptab = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
+ v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
} else if (v->fcm == ILACE_FRAME) { // frame interlaced
v->qs_last = v->s.quarter_sample;
v->s.quarter_sample = 1;
@@ -1167,18 +1167,18 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
v->mbmodetab = get_bits(gb, 3);
v->imvtab = get_bits(gb, 2 + v->numref);
if (!v->numref)
- v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
+ v->imv_vlc = ff_vc1_1ref_mvdata_vlc[v->imvtab];
else
- v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[v->imvtab];
+ v->imv_vlc = ff_vc1_2ref_mvdata_vlc[v->imvtab];
v->icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
+ v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) {
v->fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
- v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
+ v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
+ v->mbmode_vlc = ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
} else {
- v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
+ v->mbmode_vlc = ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
}
}
if (v->dquant) {
@@ -1234,16 +1234,16 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->mbmodetab = get_bits(gb, 3);
if (v->mv_mode == MV_PMODE_MIXED_MV)
- v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
+ v->mbmode_vlc = ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
else
- v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
+ v->mbmode_vlc = ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
v->imvtab = get_bits(gb, 3);
- v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[v->imvtab];
+ v->imv_vlc = ff_vc1_2ref_mvdata_vlc[v->imvtab];
v->icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
+ v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
if (v->mv_mode == MV_PMODE_MIXED_MV) {
v->fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
+ v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
}
v->numref = 1; // interlaced field B pictures are always 2-ref
} else if (v->fcm == ILACE_FRAME) {
@@ -1268,16 +1268,16 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->mbmodetab = get_bits(gb, 2);
- v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
+ v->mbmode_vlc = ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
v->imvtab = get_bits(gb, 2);
- v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
+ v->imv_vlc = ff_vc1_1ref_mvdata_vlc[v->imvtab];
// interlaced p/b-picture cbpcy range is [1, 63]
v->icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
+ v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
v->twomvbptab = get_bits(gb, 2);
- v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
+ v->twomvbp_vlc = ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
v->fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
+ v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
} else {
v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
v->qs_last = v->s.quarter_sample;
@@ -1295,7 +1295,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->s.mv_table_index = get_bits(gb, 2);
v->cbptab = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
+ v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
}
if (v->dquant) {
diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h
index 3b6be78141..0e01458c89 100644
--- a/libavcodec/vc1.h
+++ b/libavcodec/vc1.h
@@ -279,7 +279,7 @@ typedef struct VC1Context{
*/
uint8_t mvrange; ///< Extended MV range flag
uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
- VLC *cbpcy_vlc; ///< CBPCY VLC table
+ const VLCElem *cbpcy_vlc; ///< CBPCY VLC table
int tt_index; ///< Index for Transform Type tables (to decode TTMB)
uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
@@ -334,10 +334,10 @@ typedef struct VC1Context{
int intcomp;
uint8_t lumscale2; ///< for interlaced field P picture
uint8_t lumshift2;
- VLC* mbmode_vlc;
- VLC* imv_vlc;
- VLC* twomvbp_vlc;
- VLC* fourmvbp_vlc;
+ const VLCElem *mbmode_vlc;
+ const VLCElem *imv_vlc;
+ const VLCElem *twomvbp_vlc;
+ const VLCElem *fourmvbp_vlc;
uint8_t twomvbp;
uint8_t fourmvbp;
uint8_t* fieldtx_plane;
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 751ea57617..a6ee4922f9 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -227,7 +227,7 @@ static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
* @param _dmv_y Vertical differential for decoded MV
*/
#define GET_MVDATA(_dmv_x, _dmv_y) \
- index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \
+ index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index], \
VC1_MV_DIFF_VLC_BITS, 2); \
if (index > 36) { \
mb_has_coeffs = 1; \
@@ -282,7 +282,7 @@ static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x,
}
extend_x = v->dmvrange & 1;
extend_y = (v->dmvrange >> 1) & 1;
- index = get_vlc2(gb, v->imv_vlc->table, bits, 3);
+ index = get_vlc2(gb, v->imv_vlc, bits, 3);
if (index == esc) {
*dmv_x = get_bits(gb, v->k_x);
*dmv_y = get_bits(gb, v->k_y);
@@ -519,7 +519,7 @@ static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
GetBitContext *gb = &v->s.gb;
int index, run, level, lst, sign;
- index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
+ index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset], AC_VLC_BITS, 3);
if (index < 0)
return index;
if (index != ff_vc1_ac_sizes[codingset] - 1) {
@@ -530,7 +530,7 @@ static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
} else {
int escape = decode210(gb);
if (escape != 2) {
- index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
+ index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset], AC_VLC_BITS, 3);
if (index >= ff_vc1_ac_sizes[codingset] - 1U)
return AVERROR_INVALIDDATA;
run = vc1_index_decode_table[codingset][index][0];
@@ -1124,10 +1124,10 @@ static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n,
s->bdsp.clear_block(block);
if (ttmb == -1) {
- ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)];
+ ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index], VC1_TTBLK_VLC_BITS, 1)];
}
if (ttblk == TT_4X4) {
- subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
+ subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index], VC1_SUBBLKPAT_VLC_BITS, 1) + 1);
}
if ((ttblk != TT_8X8 && ttblk != TT_4X4)
&& ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))
@@ -1328,7 +1328,7 @@ static int vc1_decode_p_mb(VC1Context *v)
} else if (mb_has_coeffs) {
if (s->mb_intra)
s->ac_pred = get_bits1(gb);
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
} else {
mquant = v->pq;
@@ -1337,7 +1337,7 @@ static int vc1_decode_p_mb(VC1Context *v)
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index],
VC1_TTMB_VLC_BITS, 2);
if (!s->mb_intra) ff_vc1_mc_1mv(v, 0);
dst_idx = 0;
@@ -1393,7 +1393,7 @@ static int vc1_decode_p_mb(VC1Context *v)
int intra_count = 0, coded_inter = 0;
int is_intra[6], is_coded[6];
/* Get CBPCY */
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
val = ((cbp >> (5 - i)) & 1);
s->dc_val[0][s->block_index[i]] = 0;
@@ -1445,7 +1445,7 @@ static int vc1_decode_p_mb(VC1Context *v)
s->ac_pred = 0;
}
if (!v->ttmbf && coded_inter)
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
dst_idx += i >> 2;
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
@@ -1539,9 +1539,9 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
skipped = v->s.mbskip_table[mb_pos];
if (!skipped) {
if (v->fourmvswitch)
- idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_4MV_MBMODE_VLC_BITS, 2); // try getting this done
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc, VC1_INTFR_4MV_MBMODE_VLC_BITS, 2); // try getting this done
else
- idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2); // in a single line
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2); // in a single line
switch (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0]) {
/* store the motion vector type in a flag (useful later) */
case MV_PMODE_INTFR_4MV:
@@ -1583,7 +1583,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = get_bits1(gb);
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
GET_MQUANT();
s->current_picture.qscale_table[mb_pos] = mquant;
@@ -1617,13 +1617,13 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
} else { // inter MB
mb_has_coeffs = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][3];
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
- v->twomvbp = get_vlc2(gb, v->twomvbp_vlc->table, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
+ v->twomvbp = get_vlc2(gb, v->twomvbp_vlc, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
} else {
if ((ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV)
|| (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV_FIELD)) {
- v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
}
}
s->mb_intra = v->is_intra[s->mb_x] = 0;
@@ -1672,7 +1672,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
GET_MQUANT(); // p. 227
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && cbp)
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
@@ -1742,7 +1742,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
mquant = v->pq; /* Lossy initialization */
- idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc, VC1_IF_MBMODE_VLC_BITS, 2);
if (idx_mbmode <= 1) { // intra MB
v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
s->mb_intra = 1;
@@ -1757,7 +1757,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = idx_mbmode & 1;
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_ICBPCY_VLC_BITS, 2);
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
@@ -1792,7 +1792,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
ff_vc1_mc_1mv(v, 0);
mb_has_coeffs = !(idx_mbmode & 2);
} else { // 4-MV
- v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
for (i = 0; i < 4; i++) {
dmv_x = dmv_y = pred_flag = 0;
if (v->fourmvbp & (8 >> i))
@@ -1804,13 +1804,13 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
mb_has_coeffs = idx_mbmode & 1;
}
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (cbp) {
GET_MQUANT();
}
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && cbp) {
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
}
dst_idx = 0;
for (i = 0; i < 6; i++) {
@@ -1914,12 +1914,12 @@ static int vc1_decode_b_mb(VC1Context *v)
return 0;
}
if (direct) {
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
s->mb_intra = 0;
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf)
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0;
ff_vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype);
vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype);
@@ -1952,11 +1952,11 @@ static int vc1_decode_b_mb(VC1Context *v)
}
if (s->mb_intra)
s->ac_pred = get_bits1(gb);
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
}
}
dst_idx = 0;
@@ -2025,7 +2025,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
mquant = v->pq; /* Lossy initialization */
s->mb_intra = 0;
- idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2);
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc, VC1_IF_MBMODE_VLC_BITS, 2);
if (idx_mbmode <= 1) { // intra MB
v->is_intra[s->mb_x] = 0x3f; // Set the bitfield to all 1.
s->mb_intra = 1;
@@ -2040,7 +2040,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = idx_mbmode & 1;
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_ICBPCY_VLC_BITS, 2);
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
@@ -2118,7 +2118,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
if (fwd)
bmvtype = BMV_TYPE_FORWARD;
v->bmvtype = bmvtype;
- v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
for (i = 0; i < 4; i++) {
dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
dmv_x[1] = dmv_y[1] = pred_flag[1] = 0;
@@ -2134,13 +2134,13 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
mb_has_coeffs = idx_mbmode & 1;
}
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (cbp) {
GET_MQUANT();
}
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && cbp) {
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
}
dst_idx = 0;
for (i = 0; i < 6; i++) {
@@ -2200,7 +2200,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
skipped = v->s.mbskip_table[mb_pos];
if (!skipped) {
- idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2);
+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2);
if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
twomv = 1;
v->blk_mv_type[s->block_index[0]] = 1;
@@ -2228,7 +2228,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = get_bits1(gb);
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
GET_MQUANT();
s->current_picture.qscale_table[mb_pos] = mquant;
@@ -2323,12 +2323,12 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
if (!skipped) { // inter MB
mb_has_coeffs = ff_vc1_mbmode_intfrp[0][idx_mbmode][3];
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (!direct) {
if (bmvtype == BMV_TYPE_INTERPOLATED && twomv) {
- v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
} else if (bmvtype == BMV_TYPE_INTERPOLATED || twomv) {
- v->twomvbp = get_vlc2(gb, v->twomvbp_vlc->table, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
+ v->twomvbp = get_vlc2(gb, v->twomvbp_vlc, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
}
}
@@ -2438,7 +2438,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
GET_MQUANT(); // p. 227
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && cbp)
- ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index], VC1_TTMB_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
diff --git a/libavcodec/vc1data.c b/libavcodec/vc1data.c
index 5ebf20a0f0..4046ea042f 100644
--- a/libavcodec/vc1data.c
+++ b/libavcodec/vc1data.c
@@ -102,26 +102,26 @@ const uint8_t ff_vc1_pquant_table[3][32] = {
* @todo TODO move this into the context
*/
//@{
-VLC ff_vc1_imode_vlc;
-VLC ff_vc1_norm2_vlc;
-VLC ff_vc1_norm6_vlc;
+VLCElem ff_vc1_imode_vlc[1 << VC1_IMODE_VLC_BITS];
+VLCElem ff_vc1_norm2_vlc[1 << VC1_NORM2_VLC_BITS];
+VLCElem ff_vc1_norm6_vlc[556];
/* Could be optimized, one table only needs 8 bits */
-VLC ff_vc1_ttmb_vlc[3];
-VLC ff_vc1_mv_diff_vlc[4];
-VLC ff_vc1_cbpcy_p_vlc[4];
-VLC ff_vc1_icbpcy_vlc[8];
-VLC ff_vc1_4mv_block_pattern_vlc[4];
-VLC ff_vc1_2mv_block_pattern_vlc[4];
-VLC ff_vc1_ttblk_vlc[3];
-VLC ff_vc1_subblkpat_vlc[3];
-VLC ff_vc1_intfr_4mv_mbmode_vlc[4];
-VLC ff_vc1_intfr_non4mv_mbmode_vlc[4];
-VLC ff_vc1_if_mmv_mbmode_vlc[8];
-VLC ff_vc1_if_1mv_mbmode_vlc[8];
-VLC ff_vc1_1ref_mvdata_vlc[4];
-VLC ff_vc1_2ref_mvdata_vlc[8];
+const VLCElem *ff_vc1_ttmb_vlc[3];
+const VLCElem *ff_vc1_mv_diff_vlc[4];
+const VLCElem *ff_vc1_cbpcy_p_vlc[4];
+const VLCElem *ff_vc1_icbpcy_vlc[8];
+const VLCElem *ff_vc1_4mv_block_pattern_vlc[4];
+const VLCElem *ff_vc1_2mv_block_pattern_vlc[4];
+const VLCElem *ff_vc1_ttblk_vlc[3];
+const VLCElem *ff_vc1_subblkpat_vlc[3];
+const VLCElem *ff_vc1_intfr_4mv_mbmode_vlc[4];
+const VLCElem *ff_vc1_intfr_non4mv_mbmode_vlc[4];
+const VLCElem *ff_vc1_if_mmv_mbmode_vlc[8];
+const VLCElem *ff_vc1_if_1mv_mbmode_vlc[8];
+const VLCElem *ff_vc1_1ref_mvdata_vlc[4];
+const VLCElem *ff_vc1_2ref_mvdata_vlc[8];
-VLC ff_vc1_ac_coeff_table[8];
+const VLCElem *ff_vc1_ac_coeff_table[8];
//@}
diff --git a/libavcodec/vc1data.h b/libavcodec/vc1data.h
index 0900469ab2..e71593d023 100644
--- a/libavcodec/vc1data.h
+++ b/libavcodec/vc1data.h
@@ -56,42 +56,42 @@ extern const uint8_t ff_vc1_mbmode_intfrp[2][15][4];
*/
//@{
#define VC1_IMODE_VLC_BITS 4
-extern VLC ff_vc1_imode_vlc;
+extern VLCElem ff_vc1_imode_vlc[1 << VC1_IMODE_VLC_BITS];
#define VC1_NORM2_VLC_BITS 3
-extern VLC ff_vc1_norm2_vlc;
+extern VLCElem ff_vc1_norm2_vlc[1 << VC1_NORM2_VLC_BITS];
#define VC1_NORM6_VLC_BITS 9
-extern VLC ff_vc1_norm6_vlc;
+extern VLCElem ff_vc1_norm6_vlc[556];
/* Could be optimized, one table only needs 8 bits */
#define VC1_TTMB_VLC_BITS 9 //12
-extern VLC ff_vc1_ttmb_vlc[3];
+extern const VLCElem *ff_vc1_ttmb_vlc[3];
#define VC1_MV_DIFF_VLC_BITS 9 //15
-extern VLC ff_vc1_mv_diff_vlc[4];
+extern const VLCElem *ff_vc1_mv_diff_vlc[4];
#define VC1_CBPCY_P_VLC_BITS 9 //14
-extern VLC ff_vc1_cbpcy_p_vlc[4];
+extern const VLCElem *ff_vc1_cbpcy_p_vlc[4];
#define VC1_ICBPCY_VLC_BITS 9
-extern VLC ff_vc1_icbpcy_vlc[8];
+extern const VLCElem *ff_vc1_icbpcy_vlc[8];
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
-extern VLC ff_vc1_4mv_block_pattern_vlc[4];
+extern const VLCElem *ff_vc1_4mv_block_pattern_vlc[4];
#define VC1_2MV_BLOCK_PATTERN_VLC_BITS 3
-extern VLC ff_vc1_2mv_block_pattern_vlc[4];
+extern const VLCElem *ff_vc1_2mv_block_pattern_vlc[4];
#define VC1_TTBLK_VLC_BITS 5
-extern VLC ff_vc1_ttblk_vlc[3];
+extern const VLCElem *ff_vc1_ttblk_vlc[3];
#define VC1_SUBBLKPAT_VLC_BITS 6
-extern VLC ff_vc1_subblkpat_vlc[3];
+extern const VLCElem *ff_vc1_subblkpat_vlc[3];
#define VC1_INTFR_4MV_MBMODE_VLC_BITS 9
-extern VLC ff_vc1_intfr_4mv_mbmode_vlc[4];
+extern const VLCElem *ff_vc1_intfr_4mv_mbmode_vlc[4];
#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS 6
-extern VLC ff_vc1_intfr_non4mv_mbmode_vlc[4];
+extern const VLCElem *ff_vc1_intfr_non4mv_mbmode_vlc[4];
#define VC1_IF_MMV_MBMODE_VLC_BITS 5
-extern VLC ff_vc1_if_mmv_mbmode_vlc[8];
+extern const VLCElem *ff_vc1_if_mmv_mbmode_vlc[8];
#define VC1_IF_1MV_MBMODE_VLC_BITS 5
-extern VLC ff_vc1_if_1mv_mbmode_vlc[8];
+extern const VLCElem *ff_vc1_if_1mv_mbmode_vlc[8];
#define VC1_1REF_MVDATA_VLC_BITS 9
-extern VLC ff_vc1_1ref_mvdata_vlc[4];
+extern const VLCElem *ff_vc1_1ref_mvdata_vlc[4];
#define VC1_2REF_MVDATA_VLC_BITS 9
-extern VLC ff_vc1_2ref_mvdata_vlc[8];
+extern const VLCElem *ff_vc1_2ref_mvdata_vlc[8];
-extern VLC ff_vc1_ac_coeff_table[8];
+extern const VLCElem *ff_vc1_ac_coeff_table[8];
#define VC1_IF_MBMODE_VLC_BITS 5 // as a placeholder for VC1_IF_MMV_MBMODE_VLC_BITS
// or VC1_IF_1MV_MBMODE_VLC_BITS since they are the same
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 449d2fea5e..fe0158d1fa 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -470,122 +470,92 @@ av_cold void ff_vc1_init_transposed_scantables(VC1Context *v)
v->top_blk_sh = 3;
}
-static const uint16_t vlc_offs[] = {
- 0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436,
- 2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8342,
- 9304, 9988, 10630, 11234, 12174, 13006, 13560, 14232, 14786, 15432, 16350, 17522,
- 20372, 21818, 22330, 22394, 23166, 23678, 23742, 24820, 25332, 25396, 26460, 26980,
- 27048, 27592, 27600, 27608, 27616, 27624, 28224, 28258, 28290, 28802, 28834, 28866,
- 29378, 29412, 29444, 29960, 29994, 30026, 30538, 30572, 30604, 31120, 31154, 31186,
- 31714, 31746, 31778, 32306, 32340, 32372
-};
-
static av_cold void vc1_init_static(void)
{
static VLCElem vlc_table[32372];
-
- VLC_INIT_STATIC(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,
- vc1_norm2_bits, 1, 1,
- vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS);
- VLC_INIT_STATIC(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,
- vc1_norm6_bits, 1, 1,
- vc1_norm6_codes, 2, 2, 556);
- VLC_INIT_STATIC(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,
- vc1_imode_bits, 1, 1,
- vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS);
+ VLCInitState state = VLC_INIT_STATE(vlc_table);
+
+ VLC_INIT_STATIC_TABLE(ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,
+ vc1_norm2_bits, 1, 1,
+ vc1_norm2_codes, 1, 1, 0);
+ VLC_INIT_STATIC_TABLE(ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,
+ vc1_norm6_bits, 1, 1,
+ vc1_norm6_codes, 2, 2, 0);
+ VLC_INIT_STATIC_TABLE(ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,
+ vc1_imode_bits, 1, 1,
+ vc1_imode_codes, 1, 1, 0);
for (int i = 0; i < 3; i++) {
- ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 0]];
- ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i * 3 + 1] - vlc_offs[i * 3 + 0];
- vlc_init(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16,
- vc1_ttmb_bits[i], 1, 1,
- vc1_ttmb_codes[i], 2, 2, VLC_INIT_USE_STATIC);
- ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 1]];
- ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i * 3 + 2] - vlc_offs[i * 3 + 1];
- vlc_init(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,
- vc1_ttblk_bits[i], 1, 1,
- vc1_ttblk_codes[i], 1, 1, VLC_INIT_USE_STATIC);
- ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 2]];
- ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i * 3 + 3] - vlc_offs[i * 3 + 2];
- vlc_init(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,
- vc1_subblkpat_bits[i], 1, 1,
- vc1_subblkpat_codes[i], 1, 1, VLC_INIT_USE_STATIC);
- }
- for (int i = 0; i < 4; i++) {
- ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 9]];
- ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i * 3 + 10] - vlc_offs[i * 3 + 9];
- vlc_init(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,
- vc1_4mv_block_pattern_bits[i], 1, 1,
- vc1_4mv_block_pattern_codes[i], 1, 1, VLC_INIT_USE_STATIC);
- ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 10]];
- ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i * 3 + 11] - vlc_offs[i * 3 + 10];
- vlc_init(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64,
- vc1_cbpcy_p_bits[i], 1, 1,
- vc1_cbpcy_p_codes[i], 2, 2, VLC_INIT_USE_STATIC);
- ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 11]];
- ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i * 3 + 12] - vlc_offs[i * 3 + 11];
- vlc_init(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73,
- vc1_mv_diff_bits[i], 1, 1,
- vc1_mv_diff_codes[i], 2, 2, VLC_INIT_USE_STATIC);
- }
- for (int i = 0; i < 8; i++) {
- ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i * 2 + 21]];
- ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i * 2 + 22] - vlc_offs[i * 2 + 21];
- vlc_init(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, ff_vc1_ac_sizes[i],
- &vc1_ac_tables[i][0][1], 8, 4,
- &vc1_ac_tables[i][0][0], 8, 4, VLC_INIT_USE_STATIC);
- /* initialize interlaced MVDATA tables (2-Ref) */
- ff_vc1_2ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 2 + 22]];
- ff_vc1_2ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 2 + 23] - vlc_offs[i * 2 + 22];
- vlc_init(&ff_vc1_2ref_mvdata_vlc[i], VC1_2REF_MVDATA_VLC_BITS, 126,
- vc1_2ref_mvdata_bits[i], 1, 1,
- vc1_2ref_mvdata_codes[i], 4, 4, VLC_INIT_USE_STATIC);
+ ff_vc1_ttmb_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_TTMB_VLC_BITS, 16,
+ vc1_ttmb_bits[i], 1, 1,
+ vc1_ttmb_codes[i], 2, 2, 0);
+ ff_vc1_ttblk_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_TTBLK_VLC_BITS, 8,
+ vc1_ttblk_bits[i], 1, 1,
+ vc1_ttblk_codes[i], 1, 1, 0);
+ ff_vc1_subblkpat_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_SUBBLKPAT_VLC_BITS, 15,
+ vc1_subblkpat_bits[i], 1, 1,
+ vc1_subblkpat_codes[i], 1, 1, 0);
}
for (int i = 0; i < 4; i++) {
+ ff_vc1_4mv_block_pattern_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,
+ vc1_4mv_block_pattern_bits[i], 1, 1,
+ vc1_4mv_block_pattern_codes[i], 1, 1, 0);
+ ff_vc1_cbpcy_p_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_CBPCY_P_VLC_BITS, 64,
+ vc1_cbpcy_p_bits[i], 1, 1,
+ vc1_cbpcy_p_codes[i], 2, 2, 0);
+ ff_vc1_mv_diff_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_MV_DIFF_VLC_BITS, 73,
+ vc1_mv_diff_bits[i], 1, 1,
+ vc1_mv_diff_codes[i], 2, 2, 0);
/* initialize 4MV MBMODE VLC tables for interlaced frame P picture */
- ff_vc1_intfr_4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 37]];
- ff_vc1_intfr_4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 38] - vlc_offs[i * 3 + 37];
- vlc_init(&ff_vc1_intfr_4mv_mbmode_vlc[i], VC1_INTFR_4MV_MBMODE_VLC_BITS, 15,
- vc1_intfr_4mv_mbmode_bits[i], 1, 1,
- vc1_intfr_4mv_mbmode_codes[i], 2, 2, VLC_INIT_USE_STATIC);
+ ff_vc1_intfr_4mv_mbmode_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_INTFR_4MV_MBMODE_VLC_BITS, 15,
+ vc1_intfr_4mv_mbmode_bits[i], 1, 1,
+ vc1_intfr_4mv_mbmode_codes[i], 2, 2, 0);
/* initialize NON-4MV MBMODE VLC tables for the same */
- ff_vc1_intfr_non4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 38]];
- ff_vc1_intfr_non4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 39] - vlc_offs[i * 3 + 38];
- vlc_init(&ff_vc1_intfr_non4mv_mbmode_vlc[i], VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 9,
- vc1_intfr_non4mv_mbmode_bits[i], 1, 1,
- vc1_intfr_non4mv_mbmode_codes[i], 1, 1, VLC_INIT_USE_STATIC);
+ ff_vc1_intfr_non4mv_mbmode_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 9,
+ vc1_intfr_non4mv_mbmode_bits[i], 1, 1,
+ vc1_intfr_non4mv_mbmode_codes[i], 1, 1, 0);
/* initialize interlaced MVDATA tables (1-Ref) */
- ff_vc1_1ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 39]];
- ff_vc1_1ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 3 + 40] - vlc_offs[i * 3 + 39];
- vlc_init(&ff_vc1_1ref_mvdata_vlc[i], VC1_1REF_MVDATA_VLC_BITS, 72,
- vc1_1ref_mvdata_bits[i], 1, 1,
- vc1_1ref_mvdata_codes[i], 4, 4, VLC_INIT_USE_STATIC);
- }
- for (int i = 0; i < 4; i++) {
+ ff_vc1_1ref_mvdata_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_1REF_MVDATA_VLC_BITS, 72,
+ vc1_1ref_mvdata_bits[i], 1, 1,
+ vc1_1ref_mvdata_codes[i], 4, 4, 0);
/* Initialize 2MV Block pattern VLC tables */
- ff_vc1_2mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i + 49]];
- ff_vc1_2mv_block_pattern_vlc[i].table_allocated = vlc_offs[i + 50] - vlc_offs[i + 49];
- vlc_init(&ff_vc1_2mv_block_pattern_vlc[i], VC1_2MV_BLOCK_PATTERN_VLC_BITS, 4,
- vc1_2mv_block_pattern_bits[i], 1, 1,
- vc1_2mv_block_pattern_codes[i], 1, 1, VLC_INIT_USE_STATIC);
+ ff_vc1_2mv_block_pattern_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 4,
+ vc1_2mv_block_pattern_bits[i], 1, 1,
+ vc1_2mv_block_pattern_codes[i], 1, 1, 0);
}
for (int i = 0; i < 8; i++) {
+ ff_vc1_ac_coeff_table[i] =
+ ff_vlc_init_tables(&state, AC_VLC_BITS, ff_vc1_ac_sizes[i],
+ &vc1_ac_tables[i][0][1], 8, 4,
+ &vc1_ac_tables[i][0][0], 8, 4, 0);
+ /* initialize interlaced MVDATA tables (2-Ref) */
+ ff_vc1_2ref_mvdata_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_2REF_MVDATA_VLC_BITS, 126,
+ vc1_2ref_mvdata_bits[i], 1, 1,
+ vc1_2ref_mvdata_codes[i], 4, 4, 0);
/* Initialize interlaced CBPCY VLC tables (Table 124 - Table 131) */
- ff_vc1_icbpcy_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 53]];
- ff_vc1_icbpcy_vlc[i].table_allocated = vlc_offs[i * 3 + 54] - vlc_offs[i * 3 + 53];
- vlc_init(&ff_vc1_icbpcy_vlc[i], VC1_ICBPCY_VLC_BITS, 63,
- vc1_icbpcy_p_bits[i], 1, 1,
- vc1_icbpcy_p_codes[i], 2, 2, VLC_INIT_USE_STATIC);
+ ff_vc1_icbpcy_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_ICBPCY_VLC_BITS, 63,
+ vc1_icbpcy_p_bits[i], 1, 1,
+ vc1_icbpcy_p_codes[i], 2, 2, 0);
/* Initialize interlaced field picture MBMODE VLC tables */
- ff_vc1_if_mmv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 54]];
- ff_vc1_if_mmv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 55] - vlc_offs[i * 3 + 54];
- vlc_init(&ff_vc1_if_mmv_mbmode_vlc[i], VC1_IF_MMV_MBMODE_VLC_BITS, 8,
- vc1_if_mmv_mbmode_bits[i], 1, 1,
- vc1_if_mmv_mbmode_codes[i], 1, 1, VLC_INIT_USE_STATIC);
- ff_vc1_if_1mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 55]];
- ff_vc1_if_1mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 56] - vlc_offs[i * 3 + 55];
- vlc_init(&ff_vc1_if_1mv_mbmode_vlc[i], VC1_IF_1MV_MBMODE_VLC_BITS, 6,
- vc1_if_1mv_mbmode_bits[i], 1, 1,
- vc1_if_1mv_mbmode_codes[i], 1, 1, VLC_INIT_USE_STATIC);
+ ff_vc1_if_mmv_mbmode_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_IF_MMV_MBMODE_VLC_BITS, 8,
+ vc1_if_mmv_mbmode_bits[i], 1, 1,
+ vc1_if_mmv_mbmode_codes[i], 1, 1, 0);
+ ff_vc1_if_1mv_mbmode_vlc[i] =
+ ff_vlc_init_tables(&state, VC1_IF_1MV_MBMODE_VLC_BITS, 6,
+ vc1_if_1mv_mbmode_bits[i], 1, 1,
+ vc1_if_1mv_mbmode_codes[i], 1, 1, 0);
}
ff_msmp4_vc1_vlcs_init_once();
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 35/61] avcodec/4xm: Avoid unnecessary VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (32 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 34/61] avcodec/vc1: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 36/61] avcodec/indeo2: Avoid unnecessary VLC structure Andreas Rheinhardt
` (26 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/4xm.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index c3e3a45df5..158b37a38b 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -125,7 +125,7 @@ static const uint8_t dequant_table[64] = {
20, 35, 34, 32, 31, 22, 15, 8,
};
-static VLC block_type_vlc[2][4];
+static VLCElem block_type_vlc[2][4][32];
typedef struct CFrameBuffer {
@@ -250,17 +250,15 @@ static void idct(int16_t block[64])
static av_cold void init_vlcs(void)
{
- static VLCElem table[2][4][32];
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 4; j++) {
- block_type_vlc[i][j].table = table[i][j];
- block_type_vlc[i][j].table_allocated = 32;
- vlc_init(&block_type_vlc[i][j], BLOCK_TYPE_VLC_BITS, 7,
- &block_type_tab[i][j][0][1], 2, 1,
- &block_type_tab[i][j][0][0], 2, 1,
- VLC_INIT_USE_STATIC);
+ ff_vlc_init_table_sparse(block_type_vlc[i][j], FF_ARRAY_ELEMS(block_type_vlc[i][j]),
+ BLOCK_TYPE_VLC_BITS, 7,
+ &block_type_tab[i][j][0][1], 2, 1,
+ &block_type_tab[i][j][0][0], 2, 1,
+ NULL, 0, 0, 0);
}
}
}
@@ -357,7 +355,7 @@ static int decode_p_block(FourXContext *f, uint16_t *dst, const uint16_t *src,
if (get_bits_left(&f->gb) < 1)
return AVERROR_INVALIDDATA;
h = 1 << log2h;
- code = get_vlc2(&f->gb, block_type_vlc[1 - (f->version > 1)][index].table,
+ code = get_vlc2(&f->gb, block_type_vlc[1 - (f->version > 1)][index],
BLOCK_TYPE_VLC_BITS, 1);
av_assert0(code >= 0 && code <= 6);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 36/61] avcodec/indeo2: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (33 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 35/61] avcodec/4xm: Avoid unnecessary " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 37/61] avcodec/mss4: Partially inline max_depth and nb_bits of VLC Andreas Rheinhardt
` (25 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/indeo2.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c
index 2f64320682..6878ab7cb6 100644
--- a/libavcodec/indeo2.c
+++ b/libavcodec/indeo2.c
@@ -42,12 +42,12 @@ typedef struct Ir2Context{
} Ir2Context;
#define CODE_VLC_BITS 14
-static VLC ir2_vlc;
+static VLCElem ir2_vlc[1 << CODE_VLC_BITS];
/* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
static inline int ir2_get_code(GetBitContext *gb)
{
- return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1);
+ return get_vlc2(gb, ir2_vlc, CODE_VLC_BITS, 1);
}
static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst,
@@ -226,9 +226,9 @@ static int ir2_decode_frame(AVCodecContext *avctx, AVFrame *picture,
static av_cold void ir2_init_static(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
- &ir2_tab[0][1], 2, &ir2_tab[0][0], 2, 1,
- 0, VLC_INIT_OUTPUT_LE, 1 << CODE_VLC_BITS);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(ir2_vlc, CODE_VLC_BITS, IR2_CODES,
+ &ir2_tab[0][1], 2, &ir2_tab[0][0], 2, 1,
+ 0, VLC_INIT_OUTPUT_LE);
}
static av_cold int ir2_decode_init(AVCodecContext *avctx)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 37/61] avcodec/mss4: Partially inline max_depth and nb_bits of VLC
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (34 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 36/61] avcodec/indeo2: Avoid unnecessary VLC structure Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 38/61] avcodec/mpeg4videodec: Avoid superfluous VLC structures Andreas Rheinhardt
` (24 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is known at compile-time for the vec_entry_vlcs.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mss4.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c
index 0e7cc3e124..8ae4f152c6 100644
--- a/libavcodec/mss4.c
+++ b/libavcodec/mss4.c
@@ -156,9 +156,10 @@ static av_always_inline int get_coeff_bits(GetBitContext *gb, int nbits)
return val;
}
-static inline int get_coeff(GetBitContext *gb, VLC *vlc)
+static inline int get_coeff(GetBitContext *gb, const VLC *vlc,
+ int nb_bits, int max_depth)
{
- int val = get_vlc2(gb, vlc->table, vlc->bits, 2);
+ int val = get_vlc2(gb, vlc->table, nb_bits, max_depth);
return get_coeff_bits(gb, val);
}
@@ -171,7 +172,7 @@ static int mss4_decode_dct(GetBitContext *gb, VLC *dc_vlc, VLC *ac_vlc,
memset(block, 0, sizeof(*block) * 64);
- dc = get_coeff(gb, dc_vlc);
+ dc = get_coeff(gb, dc_vlc, dc_vlc->bits, 2);
// DC prediction is the same as in MSS3
if (by) {
if (bx) {
@@ -337,7 +338,7 @@ static int mss4_decode_image_block(MSS4Context *ctx, GetBitContext *gb,
for (i = 0; i < 3; i++) {
vec_len[i] = vec_len_syms[!!i][get_unary(gb, 0, 3)];
for (j = 0; j < vec_len[i]; j++) {
- vec[i][j] = get_coeff(gb, &vec_entry_vlc[!!i]);
+ vec[i][j] = get_coeff(gb, &vec_entry_vlc[!!i], 5, 1);
vec[i][j] += ctx->prev_vec[i][j];
ctx->prev_vec[i][j] = vec[i][j];
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 38/61] avcodec/mpeg4videodec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (35 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 37/61] avcodec/mss4: Partially inline max_depth and nb_bits of VLC Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 39/61] avcodec/msmpeg4dec: " Andreas Rheinhardt
` (23 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For all VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table. And in some cases one can even
avoid this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 93 ++++++++++++++++++--------------------
1 file changed, 45 insertions(+), 48 deletions(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 51a2c7fe35..347e5f7809 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -57,12 +57,12 @@
#define MB_TYPE_B_VLC_BITS 4
#define STUDIO_INTRA_BITS 9
-static VLC dc_lum, dc_chrom;
-static VLC sprite_trajectory;
-static VLC mb_type_b_vlc;
-static VLC studio_intra_tab[12];
-static VLC studio_luma_dc;
-static VLC studio_chroma_dc;
+static VLCElem dc_lum[512], dc_chrom[512];
+static VLCElem sprite_trajectory[128];
+static VLCElem mb_type_b_vlc[16];
+static const VLCElem *studio_intra_tab[12];
+static VLCElem studio_luma_dc[528];
+static VLCElem studio_chroma_dc[528];
static const uint8_t mpeg4_block_count[4] = { 0, 6, 8, 12 };
@@ -448,14 +448,14 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
int length;
int x = 0, y = 0;
- length = get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 2);
+ length = get_vlc2(gb, sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 2);
if (length > 0)
x = get_xbits(gb, length);
if (!(ctx->divx_version == 500 && ctx->divx_build == 413))
check_marker(s->avctx, gb, "before sprite_trajectory");
- length = get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 2);
+ length = get_vlc2(gb, sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 2);
if (length > 0)
y = get_xbits(gb, length);
@@ -890,9 +890,9 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
int level, code;
if (n < 4)
- code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1);
+ code = get_vlc2(&s->gb, dc_lum, DC_VLC_BITS, 1);
else
- code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1);
+ code = get_vlc2(&s->gb, dc_chrom, DC_VLC_BITS, 1);
if (code < 0 || code > 9 /* && s->nbit < 9 */) {
av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
@@ -1839,7 +1839,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
cbp = 0;
} else {
modb2 = get_bits1(&s->gb);
- mb_type = get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);
+ mb_type = get_vlc2(&s->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
if (mb_type < 0) {
av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");
return AVERROR_INVALIDDATA;
@@ -2071,7 +2071,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0,
additional_code_len, sign, mismatch;
- const VLC *cur_vlc = &studio_intra_tab[0];
+ const VLCElem *cur_vlc = studio_intra_tab[0];
uint8_t *const scantable = s->intra_scantable.permutated;
const uint16_t *quant_matrix;
uint32_t flc;
@@ -2085,14 +2085,14 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
if (n < 4) {
cc = 0;
- dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
quant_matrix = s->intra_matrix;
} else {
cc = (n & 1) + 1;
if (ctx->rgb)
- dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
else
- dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc.table, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
quant_matrix = s->chroma_intra_matrix;
}
@@ -2121,7 +2121,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
/* AC Coefficients */
while (1) {
- group = get_vlc2(&s->gb, cur_vlc->table, STUDIO_INTRA_BITS, 2);
+ group = get_vlc2(&s->gb, cur_vlc, STUDIO_INTRA_BITS, 2);
if (group < 0) {
av_log(s->avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n");
@@ -2129,7 +2129,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
}
additional_code_len = ac_state_tab[group][0];
- cur_vlc = &studio_intra_tab[ac_state_tab[group][1]];
+ cur_vlc = studio_intra_tab[ac_state_tab[group][1]];
if (group == 0) {
/* End of Block */
@@ -3760,28 +3760,25 @@ static int mpeg4_update_thread_context_for_user(AVCodecContext *dst,
static av_cold void mpeg4_init_static(void)
{
static uint8_t mpeg4_rvlc_rl_tables[2][2][2 * MAX_RUN + MAX_LEVEL + 3];
+ static VLCElem vlc_buf[6498];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
- VLC_INIT_STATIC_FROM_LENGTHS(&studio_luma_dc, STUDIO_INTRA_BITS, 19,
- &ff_mpeg4_studio_dc_luma[0][1], 2,
- &ff_mpeg4_studio_dc_luma[0][0], 2, 1,
- 0, 0, 528);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(studio_luma_dc, STUDIO_INTRA_BITS, 19,
+ &ff_mpeg4_studio_dc_luma[0][1], 2,
+ &ff_mpeg4_studio_dc_luma[0][0], 2, 1,
+ 0, 0);
- VLC_INIT_STATIC_FROM_LENGTHS(&studio_chroma_dc, STUDIO_INTRA_BITS, 19,
- &ff_mpeg4_studio_dc_chroma[0][1], 2,
- &ff_mpeg4_studio_dc_chroma[0][0], 2, 1,
- 0, 0, 528);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(studio_chroma_dc, STUDIO_INTRA_BITS, 19,
+ &ff_mpeg4_studio_dc_chroma[0][1], 2,
+ &ff_mpeg4_studio_dc_chroma[0][0], 2, 1,
+ 0, 0);
- for (unsigned i = 0, offset = 0; i < 12; i++) {
- static VLCElem vlc_buf[6498];
-
- studio_intra_tab[i].table = &vlc_buf[offset];
- studio_intra_tab[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
- ff_vlc_init_from_lengths(&studio_intra_tab[i],
- STUDIO_INTRA_BITS, 24,
- &ff_mpeg4_studio_intra[i][0][1], 2,
- &ff_mpeg4_studio_intra[i][0][0], 2, 1,
- 0, VLC_INIT_STATIC_OVERLONG, NULL);
- offset += studio_intra_tab[i].table_size;
+ for (unsigned i = 0; i < 12; i++) {
+ studio_intra_tab[i] =
+ ff_vlc_init_tables_from_lengths(&state, STUDIO_INTRA_BITS, 24,
+ &ff_mpeg4_studio_intra[i][0][1], 2,
+ &ff_mpeg4_studio_intra[i][0][0], 2, 1,
+ 0, 0);
}
ff_mpeg4_init_rl_intra();
@@ -3790,18 +3787,18 @@ static av_cold void mpeg4_init_static(void)
INIT_FIRST_VLC_RL(ff_mpeg4_rl_intra, 554);
VLC_INIT_RL(ff_rvlc_rl_inter, 1072);
INIT_FIRST_VLC_RL(ff_rvlc_rl_intra, 1072);
- VLC_INIT_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
- &ff_mpeg4_DCtab_lum[0][1], 2, 1,
- &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512);
- VLC_INIT_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
- &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
- &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512);
- VLC_INIT_STATIC_FROM_LENGTHS(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
- ff_sprite_trajectory_lens, 1,
- NULL, 0, 0, 0, 0, 128);
- VLC_INIT_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
- &ff_mb_type_b_tab[0][1], 2, 1,
- &ff_mb_type_b_tab[0][0], 2, 1, 16);
+ VLC_INIT_STATIC_TABLE(dc_lum, DC_VLC_BITS, 10 /* 13 */,
+ &ff_mpeg4_DCtab_lum[0][1], 2, 1,
+ &ff_mpeg4_DCtab_lum[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(dc_chrom, DC_VLC_BITS, 10 /* 13 */,
+ &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
+ &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
+ ff_sprite_trajectory_lens, 1,
+ NULL, 0, 0, 0, 0);
+ VLC_INIT_STATIC_TABLE(mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
+ &ff_mb_type_b_tab[0][1], 2, 1,
+ &ff_mb_type_b_tab[0][0], 2, 1, 0);
}
static av_cold int decode_init(AVCodecContext *avctx)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 39/61] avcodec/msmpeg4dec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (36 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 38/61] avcodec/mpeg4videodec: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 40/61] avcodec/aacps: Remove unused AVCodecContext* parameter from ff_ps_apply Andreas Rheinhardt
` (22 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For all VLCs here, the number of bits of the VLC is write-only,
because it is hardcoded at the call site. Therefore one can replace
these VLC structures with the only thing that is actually used:
The pointer to the VLCElem table. And in some cases one can even
avoid this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/msmpeg4data.h | 2 +-
libavcodec/msmpeg4dec.c | 95 +++++++++++++++++++++-------------------
libavcodec/msmpeg4dec.h | 4 +-
libavcodec/wmv2dec.c | 4 +-
4 files changed, 54 insertions(+), 51 deletions(-)
diff --git a/libavcodec/msmpeg4data.h b/libavcodec/msmpeg4data.h
index 26ee960f82..aa4ca86a05 100644
--- a/libavcodec/msmpeg4data.h
+++ b/libavcodec/msmpeg4data.h
@@ -44,7 +44,7 @@ typedef struct MVTable {
const uint8_t *table_mvx;
const uint8_t *table_mvy;
uint16_t *table_mv_index; /* encoding: convert mv to index in table_mv */
- VLC vlc; /* decoding: vlc */
+ const VLCElem *vlc; /* decoding: vlc */
} MVTable;
FF_VISIBILITY_PUSH_HIDDEN
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 716fc13529..5b10d8f225 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -63,12 +63,12 @@ static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
/****************************************/
/* decoding stuff */
-VLC ff_mb_non_intra_vlc[4];
-static VLC v2_dc_lum_vlc;
-static VLC v2_dc_chroma_vlc;
-static VLC v2_intra_cbpc_vlc;
-static VLC v2_mb_type_vlc;
-VLC ff_inter_intra_vlc;
+const VLCElem *ff_mb_non_intra_vlc[4];
+static VLCElem v2_dc_lum_vlc[1472];
+static VLCElem v2_dc_chroma_vlc[1506];
+static VLCElem v2_intra_cbpc_vlc[8];
+static VLCElem v2_mb_type_vlc[128];
+VLCElem ff_inter_intra_vlc[8];
/* This is identical to H.263 except that its range is multiplied by 2. */
static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
@@ -125,7 +125,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
}
if(s->msmpeg4_version==2)
- code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1);
+ code = get_vlc2(&s->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
else
code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if(code<0 || code>7){
@@ -139,7 +139,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
} else {
s->mb_intra = 1;
if(s->msmpeg4_version==2)
- cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1);
+ cbp = get_vlc2(&s->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
else
cbp = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if(cbp<0 || cbp>3){
@@ -230,7 +230,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
}
}
- code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3);
+ code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
//s->mb_intra = (code & 0x40) ? 0 : 1;
s->mb_intra = (~code & 0x40) >> 6;
@@ -271,7 +271,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
s->ac_pred = get_bits1(&s->gb);
*mb_type_ptr = MB_TYPE_INTRA;
if(s->inter_intra_pred){
- s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
+ s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
ff_dlog(s, "%d%d %d %d/",
s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
}
@@ -296,6 +296,8 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
/* init all vlc decoding tables */
static av_cold void msmpeg4_decode_init_static(void)
{
+ static VLCElem vlc_buf[3714 + 2694 + 1636 + 2648 + 1532 + 2488];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
MVTable *mv;
INIT_FIRST_VLC_RL(ff_rl_table[0], 642);
@@ -308,43 +310,44 @@ static av_cold void msmpeg4_decode_init_static(void)
av_assert1(ff_h263_rl_inter.rl_vlc[0]);
memcpy(ff_rl_table[5].rl_vlc, ff_h263_rl_inter.rl_vlc, sizeof(ff_rl_table[5].rl_vlc));
+ VLC_INIT_STATIC_TABLE(v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 512,
+ &ff_v2_dc_lum_table[0][1], 8, 4,
+ &ff_v2_dc_lum_table[0][0], 8, 4, 0);
+ VLC_INIT_STATIC_TABLE(v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 512,
+ &ff_v2_dc_chroma_table[0][1], 8, 4,
+ &ff_v2_dc_chroma_table[0][0], 8, 4, 0);
+
+ VLC_INIT_STATIC_TABLE(v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
+ &ff_v2_intra_cbpc[0][1], 2, 1,
+ &ff_v2_intra_cbpc[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
+ &ff_v2_mb_type[0][1], 2, 1,
+ &ff_v2_mb_type[0][0], 2, 1, 0);
+
mv = &ff_mv_tables[0];
- VLC_INIT_STATIC(&mv->vlc, MV_VLC_BITS, MSMPEG4_MV_TABLES_NB_ELEMS + 1,
- mv->table_mv_bits, 1, 1,
- mv->table_mv_code, 2, 2, 3714);
+ mv->vlc = ff_vlc_init_tables_sparse(&state, MV_VLC_BITS,
+ MSMPEG4_MV_TABLES_NB_ELEMS + 1,
+ mv->table_mv_bits, 1, 1,
+ mv->table_mv_code, 2, 2,
+ NULL, 0, 0, 0);
mv = &ff_mv_tables[1];
- VLC_INIT_STATIC(&mv->vlc, MV_VLC_BITS, MSMPEG4_MV_TABLES_NB_ELEMS + 1,
- mv->table_mv_bits, 1, 1,
- mv->table_mv_code, 2, 2, 2694);
-
- VLC_INIT_STATIC(&v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 512,
- &ff_v2_dc_lum_table[0][1], 8, 4,
- &ff_v2_dc_lum_table[0][0], 8, 4, 1472);
- VLC_INIT_STATIC(&v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 512,
- &ff_v2_dc_chroma_table[0][1], 8, 4,
- &ff_v2_dc_chroma_table[0][0], 8, 4, 1506);
-
- VLC_INIT_STATIC(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
- &ff_v2_intra_cbpc[0][1], 2, 1,
- &ff_v2_intra_cbpc[0][0], 2, 1, 8);
- VLC_INIT_STATIC(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
- &ff_v2_mb_type[0][1], 2, 1,
- &ff_v2_mb_type[0][0], 2, 1, 128);
-
- for (unsigned i = 0, offset = 0; i < 4; i++) {
- static VLCElem vlc_buf[1636 + 2648 + 1532 + 2488];
- ff_mb_non_intra_vlc[i].table = &vlc_buf[offset];
- ff_mb_non_intra_vlc[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
- vlc_init(&ff_mb_non_intra_vlc[i], MB_NON_INTRA_VLC_BITS, 128,
- &ff_wmv2_inter_table[i][0][1], 8, 4,
- &ff_wmv2_inter_table[i][0][0], 8, 4,
- VLC_INIT_STATIC_OVERLONG);
- offset += ff_mb_non_intra_vlc[i].table_size;
+ mv->vlc = ff_vlc_init_tables_sparse(&state, MV_VLC_BITS,
+ MSMPEG4_MV_TABLES_NB_ELEMS + 1,
+ mv->table_mv_bits, 1, 1,
+ mv->table_mv_code, 2, 2,
+ NULL, 0, 0, 0);
+
+ for (unsigned i = 0; i < 4; i++) {
+ ff_mb_non_intra_vlc[i] =
+ ff_vlc_init_tables_sparse(&state, MB_NON_INTRA_VLC_BITS, 128,
+ &ff_wmv2_inter_table[i][0][1], 8, 4,
+ &ff_wmv2_inter_table[i][0][0], 8, 4,
+ NULL, 0, 0, 0);
}
- VLC_INIT_STATIC(&ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
- &ff_table_inter_intra[0][1], 2, 1,
- &ff_table_inter_intra[0][0], 2, 1, 8);
+ VLC_INIT_STATIC_TABLE(ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
+ &ff_table_inter_intra[0][1], 2, 1,
+ &ff_table_inter_intra[0][0], 2, 1, 0);
ff_msmp4_vc1_vlcs_init_once();
}
@@ -572,9 +575,9 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
if(s->msmpeg4_version<=2){
if (n < 4) {
- level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, MSMP4_DC_VLC_BITS, 3);
+ level = get_vlc2(&s->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
} else {
- level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, MSMP4_DC_VLC_BITS, 3);
+ level = get_vlc2(&s->gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
}
if (level < 0) {
av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
@@ -813,7 +816,7 @@ void ff_msmpeg4_decode_motion(MpegEncContext *s, int *mx_ptr, int *my_ptr)
mv = &ff_mv_tables[s->mv_table_index];
- code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, mv->vlc, MV_VLC_BITS, 2);
if (code == MSMPEG4_MV_TABLES_NB_ELEMS) {
mx = get_bits(&s->gb, 6);
my = get_bits(&s->gb, 6);
diff --git a/libavcodec/msmpeg4dec.h b/libavcodec/msmpeg4dec.h
index ad41eea9d4..5daa7c6bc3 100644
--- a/libavcodec/msmpeg4dec.h
+++ b/libavcodec/msmpeg4dec.h
@@ -28,8 +28,8 @@
#define INTER_INTRA_VLC_BITS 3
#define MB_NON_INTRA_VLC_BITS 9
-extern VLC ff_mb_non_intra_vlc[4];
-extern VLC ff_inter_intra_vlc;
+extern const VLCElem *ff_mb_non_intra_vlc[4];
+extern VLCElem ff_inter_intra_vlc[8];
int ff_msmpeg4_decode_init(AVCodecContext *avctx);
int ff_msmpeg4_decode_picture_header(MpegEncContext *s);
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index d7c193455d..ed6140d29c 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -473,7 +473,7 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
if (get_bits_left(&s->gb) <= 0)
return AVERROR_INVALIDDATA;
- code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[w->cbp_table_index].table,
+ code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[w->cbp_table_index],
MB_NON_INTRA_VLC_BITS, 3);
s->mb_intra = (~code & 0x40) >> 6;
@@ -539,7 +539,7 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
show_bits(&s->gb, 24));
s->ac_pred = get_bits1(&s->gb);
if (s->inter_intra_pred) {
- s->h263_aic_dir = get_vlc2(&s->gb, ff_inter_intra_vlc.table,
+ s->h263_aic_dir = get_vlc2(&s->gb, ff_inter_intra_vlc,
INTER_INTRA_VLC_BITS, 1);
ff_dlog(s->avctx, "%d%d %d %d/",
s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 40/61] avcodec/aacps: Remove unused AVCodecContext* parameter from ff_ps_apply
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (37 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 39/61] avcodec/msmpeg4dec: " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 41/61] avcodec/aacps: Pass logctx as void* instead of AVCodecContext* Andreas Rheinhardt
` (21 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacps.c | 3 +--
libavcodec/aacps.h | 2 +-
libavcodec/aacsbr_template.c | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/libavcodec/aacps.c b/libavcodec/aacps.c
index 655e8fe5b4..ed00006a3a 100644
--- a/libavcodec/aacps.c
+++ b/libavcodec/aacps.c
@@ -26,7 +26,6 @@
#include "libavutil/common.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem_internal.h"
-#include "avcodec.h"
#include "aacps.h"
#if USE_FIXED
#include "aacps_fixed_tablegen.h"
@@ -717,7 +716,7 @@ static void stereo_processing(PSContext *ps, INTFLOAT (*l)[32][2], INTFLOAT (*r)
}
}
-int AAC_RENAME(ff_ps_apply)(AVCodecContext *avctx, PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][38][64], int top)
+int AAC_RENAME(ff_ps_apply)(PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][38][64], int top)
{
INTFLOAT (*Lbuf)[32][2] = ps->Lbuf;
INTFLOAT (*Rbuf)[32][2] = ps->Rbuf;
diff --git a/libavcodec/aacps.h b/libavcodec/aacps.h
index 3efa38ad88..9d7e79c2b2 100644
--- a/libavcodec/aacps.h
+++ b/libavcodec/aacps.h
@@ -97,6 +97,6 @@ void AAC_RENAME(ff_ps_init)(void);
void AAC_RENAME(ff_ps_ctx_init)(PSContext *ps);
int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb,
PSCommonContext *ps, int bits_left);
-int AAC_RENAME(ff_ps_apply)(AVCodecContext *avctx, PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][38][64], int top);
+int AAC_RENAME(ff_ps_apply)(PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][38][64], int top);
#endif /* AVCODEC_AACPS_H */
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index b33ffd4295..f3d3258d2e 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -1569,7 +1569,7 @@ void AAC_RENAME(ff_sbr_apply)(AACContext *ac, SpectralBandReplication *sbr, int
if (ac->oc[1].m4ac.ps == 1) {
if (sbr->ps.common.start) {
- AAC_RENAME(ff_ps_apply)(ac->avctx, &sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]);
+ AAC_RENAME(ff_ps_apply)(&sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]);
} else {
memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0]));
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 41/61] avcodec/aacps: Pass logctx as void* instead of AVCodecContext*
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (38 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 40/61] avcodec/aacps: Remove unused AVCodecContext* parameter from ff_ps_apply Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 42/61] avcodec/aacdectab: Deduplicate common decoder tables Andreas Rheinhardt
` (20 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacps.h | 3 +--
libavcodec/aacps_common.c | 26 +++++++++++++-------------
2 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/libavcodec/aacps.h b/libavcodec/aacps.h
index 9d7e79c2b2..c8814b4c3d 100644
--- a/libavcodec/aacps.h
+++ b/libavcodec/aacps.h
@@ -27,7 +27,6 @@
#include "libavutil/mem_internal.h"
#include "aacpsdsp.h"
-#include "avcodec.h"
#include "get_bits.h"
#define PS_MAX_NUM_ENV 5
@@ -95,7 +94,7 @@ extern const int8_t ff_k_to_i_34[];
void ff_ps_init_common(void);
void AAC_RENAME(ff_ps_init)(void);
void AAC_RENAME(ff_ps_ctx_init)(PSContext *ps);
-int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb,
+int ff_ps_read_data(void *logctx, GetBitContext *gb,
PSCommonContext *ps, int bits_left);
int AAC_RENAME(ff_ps_apply)(PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][38][64], int top);
diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index bee07b5fb3..11bdb960cf 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -67,14 +67,14 @@ static VLC vlc_ps[10];
* Inter-channel Phase Difference/Overall Phase Difference parameters from the \
* bitstream. \
* \
- * @param avctx contains the current codec context \
+ * @param logctx a context for logging \
* @param gb pointer to the input bitstream \
* @param ps pointer to the Parametric Stereo context \
* @param PAR pointer to the parameter to be read \
* @param e envelope to decode \
* @param dt 1: time delta-coded, 0: frequency delta-coded \
*/ \
-static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSCommonContext *ps, \
+static int read_ ## PAR ## _data(void *logctx, GetBitContext *gb, PSCommonContext *ps, \
int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
{ \
int b, num = ps->nr_ ## PAR ## _par; \
@@ -101,7 +101,7 @@ static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSCom
} \
return 0; \
err: \
- av_log(avctx, AV_LOG_ERROR, "illegal "#PAR"\n"); \
+ av_log(logctx, AV_LOG_ERROR, "illegal "#PAR"\n"); \
return AVERROR_INVALIDDATA; \
}
@@ -131,7 +131,7 @@ static int ps_read_extension_data(GetBitContext *gb, PSCommonContext *ps,
return get_bits_count(gb) - count;
}
-int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
+int ff_ps_read_data(void *logctx, GetBitContext *gb_host,
PSCommonContext *ps, int bits_left)
{
int e;
@@ -146,7 +146,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
if (ps->enable_iid) {
int iid_mode = get_bits(gb, 3);
if (iid_mode > 5) {
- av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n",
+ av_log(logctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n",
iid_mode);
goto err;
}
@@ -158,7 +158,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
if (ps->enable_icc) {
ps->icc_mode = get_bits(gb, 3);
if (ps->icc_mode > 5) {
- av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",
+ av_log(logctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",
ps->icc_mode);
goto err;
}
@@ -176,7 +176,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
for (e = 1; e <= ps->num_env; e++) {
ps->border_position[e] = get_bits(gb, 5);
if (ps->border_position[e] < ps->border_position[e-1]) {
- av_log(avctx, AV_LOG_ERROR, "border_position non monotone.\n");
+ av_log(logctx, AV_LOG_ERROR, "border_position non monotone.\n");
goto err;
}
}
@@ -187,7 +187,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
if (ps->enable_iid) {
for (e = 0; e < ps->num_env; e++) {
int dt = get_bits1(gb);
- if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt))
+ if (read_iid_data(logctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt))
goto err;
}
} else
@@ -196,7 +196,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
if (ps->enable_icc)
for (e = 0; e < ps->num_env; e++) {
int dt = get_bits1(gb);
- if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt))
+ if (read_icc_data(logctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt))
goto err;
}
else
@@ -213,7 +213,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
cnt -= 2 + ps_read_extension_data(gb, ps, ps_extension_id);
}
if (cnt < 0) {
- av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt);
+ av_log(logctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt);
goto err;
}
skip_bits(gb, cnt);
@@ -241,7 +241,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
if (ps->enable_iid){
for (b = 0; b < ps->nr_iid_par; b++) {
if (FFABS(ps->iid_par[ps->num_env][b]) > 7 + 8 * ps->iid_quant) {
- av_log(avctx, AV_LOG_ERROR, "iid_par invalid\n");
+ av_log(logctx, AV_LOG_ERROR, "iid_par invalid\n");
goto err;
}
}
@@ -249,7 +249,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
if (ps->enable_icc){
for (b = 0; b < ps->nr_iid_par; b++) {
if (ps->icc_par[ps->num_env][b] > 7U) {
- av_log(avctx, AV_LOG_ERROR, "icc_par invalid\n");
+ av_log(logctx, AV_LOG_ERROR, "icc_par invalid\n");
goto err;
}
}
@@ -278,7 +278,7 @@ int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host,
skip_bits_long(gb_host, bits_consumed);
return bits_consumed;
}
- av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);
+ av_log(logctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);
err:
ps->start = 0;
skip_bits_long(gb_host, bits_left);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 42/61] avcodec/aacdectab: Deduplicate common decoder tables
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (39 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 41/61] avcodec/aacps: Pass logctx as void* instead of AVCodecContext* Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 43/61] avcodec/aacdec_template: Deduplicate VLCs Andreas Rheinhardt
` (19 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/Makefile | 6 +-
libavcodec/aacdec.c | 8 +--
libavcodec/aacdec_common.c | 119 +++++++++++++++++++++++++++++++++++
libavcodec/aacdec_fixed.c | 4 +-
libavcodec/aacdec_template.c | 36 +++++------
libavcodec/aacdectab.h | 95 +++-------------------------
6 files changed, 154 insertions(+), 114 deletions(-)
create mode 100644 libavcodec/aacdec_common.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9e96892365..d4c21474ec 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -180,10 +180,12 @@ OBJS-$(CONFIG_WMV2DSP) += wmv2dsp.o
OBJS-$(CONFIG_ZERO12V_DECODER) += 012v.o
OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o
OBJS-$(CONFIG_A64MULTI5_ENCODER) += a64multienc.o elbg.o
-OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o aacps_common.o aacps_float.o \
+OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aacdec_common.o aactab.o \
+ aacsbr.o aacps_common.o aacps_float.o \
kbdwin.o \
sbrdsp.o aacpsdsp_float.o cbrt_data.o
-OBJS-$(CONFIG_AAC_FIXED_DECODER) += aacdec_fixed.o aactab.o aacsbr_fixed.o aacps_common.o aacps_fixed.o \
+OBJS-$(CONFIG_AAC_FIXED_DECODER) += aacdec_fixed.o aacdec_common.o aactab.o \
+ aacsbr_fixed.o aacps_common.o aacps_fixed.o \
kbdwin.o \
sbrdsp_fixed.o aacpsdsp_fixed.o cbrt_data_fixed.o
OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o aacenctab.o \
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index ca31540d3c..d66ebf4a7c 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -564,8 +564,8 @@ const FFCodec ff_aac_decoder = {
},
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
- CODEC_OLD_CHANNEL_LAYOUTS_ARRAY(aac_channel_layout)
- .p.ch_layouts = aac_ch_layout,
+ CODEC_OLD_CHANNEL_LAYOUTS_ARRAY(ff_aac_channel_layout)
+ .p.ch_layouts = ff_aac_ch_layout,
.flush = flush,
.p.priv_class = &aac_decoder_class,
.p.profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
@@ -590,8 +590,8 @@ const FFCodec ff_aac_latm_decoder = {
},
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
- CODEC_OLD_CHANNEL_LAYOUTS_ARRAY(aac_channel_layout)
- .p.ch_layouts = aac_ch_layout,
+ CODEC_OLD_CHANNEL_LAYOUTS_ARRAY(ff_aac_channel_layout)
+ .p.ch_layouts = ff_aac_ch_layout,
.flush = flush,
.p.profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
};
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
new file mode 100644
index 0000000000..c75c6fadc6
--- /dev/null
+++ b/libavcodec/aacdec_common.c
@@ -0,0 +1,119 @@
+/*
+ * Common code and tables of the AAC fixed- and floating-point decoders
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Common code and tables of the AAC fixed- and floating-point decoders
+ */
+
+#include "aac.h"
+#include "aacdectab.h"
+
+const int8_t ff_tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 5, 5, 16, 5, 0 };
+
+const uint8_t ff_aac_channel_layout_map[16][16][3] = {
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, },
+ { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
+ { { 0, } },
+ { { 0, } },
+ { { 0, } },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
+ {
+ { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, // SCE1 = FC,
+ { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, // CPE1 = FLc and FRc,
+ { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, // CPE2 = FL and FR,
+ { TYPE_CPE, 2, AAC_CHANNEL_BACK }, // CPE3 = SiL and SiR,
+ { TYPE_CPE, 3, AAC_CHANNEL_BACK }, // CPE4 = BL and BR,
+ { TYPE_SCE, 1, AAC_CHANNEL_BACK }, // SCE2 = BC,
+ { TYPE_LFE, 0, AAC_CHANNEL_LFE }, // LFE1 = LFE1,
+ { TYPE_LFE, 1, AAC_CHANNEL_LFE }, // LFE2 = LFE2,
+ { TYPE_SCE, 2, AAC_CHANNEL_FRONT }, // SCE3 = TpFC,
+ { TYPE_CPE, 4, AAC_CHANNEL_FRONT }, // CPE5 = TpFL and TpFR,
+ { TYPE_CPE, 5, AAC_CHANNEL_SIDE }, // CPE6 = TpSiL and TpSiR,
+ { TYPE_SCE, 3, AAC_CHANNEL_SIDE }, // SCE4 = TpC,
+ { TYPE_CPE, 6, AAC_CHANNEL_BACK }, // CPE7 = TpBL and TpBR,
+ { TYPE_SCE, 4, AAC_CHANNEL_BACK }, // SCE5 = TpBC,
+ { TYPE_SCE, 5, AAC_CHANNEL_FRONT }, // SCE6 = BtFC,
+ { TYPE_CPE, 7, AAC_CHANNEL_FRONT }, // CPE8 = BtFL and BtFR
+ },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, { TYPE_CPE, 2, AAC_CHANNEL_FRONT }, },
+ { { 0, } },
+};
+
+const int16_t ff_aac_channel_map[3][4][6] = {
+ {
+ { AV_CHAN_FRONT_CENTER, AV_CHAN_FRONT_LEFT_OF_CENTER, AV_CHAN_FRONT_RIGHT_OF_CENTER, AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_NONE },
+ { AV_CHAN_UNUSED, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
+ { AV_CHAN_UNUSED, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT, AV_CHAN_BACK_LEFT, AV_CHAN_BACK_RIGHT, AV_CHAN_BACK_CENTER },
+ { AV_CHAN_LOW_FREQUENCY, AV_CHAN_LOW_FREQUENCY_2, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
+ },
+ {
+ { AV_CHAN_TOP_FRONT_CENTER, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_TOP_FRONT_LEFT, AV_CHAN_TOP_FRONT_RIGHT, AV_CHAN_NONE },
+ { AV_CHAN_UNUSED, AV_CHAN_TOP_SIDE_LEFT, AV_CHAN_TOP_SIDE_RIGHT, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_TOP_CENTER},
+ { AV_CHAN_UNUSED, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_TOP_BACK_LEFT, AV_CHAN_TOP_BACK_RIGHT, AV_CHAN_TOP_BACK_CENTER},
+ { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE},
+ },
+ {
+ { AV_CHAN_BOTTOM_FRONT_CENTER, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_BOTTOM_FRONT_LEFT, AV_CHAN_BOTTOM_FRONT_RIGHT, AV_CHAN_NONE },
+ { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
+ { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
+ { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
+ },
+};
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+const uint64_t ff_aac_channel_layout[] = {
+ AV_CH_LAYOUT_MONO,
+ AV_CH_LAYOUT_STEREO,
+ AV_CH_LAYOUT_SURROUND,
+ AV_CH_LAYOUT_4POINT0,
+ AV_CH_LAYOUT_5POINT0_BACK,
+ AV_CH_LAYOUT_5POINT1_BACK,
+ AV_CH_LAYOUT_7POINT1_WIDE_BACK,
+ AV_CH_LAYOUT_6POINT1_BACK,
+ AV_CH_LAYOUT_7POINT1,
+ AV_CH_LAYOUT_22POINT2,
+ AV_CH_LAYOUT_7POINT1_TOP_BACK,
+ 0,
+};
+#endif
+
+const AVChannelLayout ff_aac_ch_layout[] = {
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ AV_CHANNEL_LAYOUT_SURROUND,
+ AV_CHANNEL_LAYOUT_4POINT0,
+ AV_CHANNEL_LAYOUT_5POINT0_BACK,
+ AV_CHANNEL_LAYOUT_5POINT1_BACK,
+ AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
+ AV_CHANNEL_LAYOUT_6POINT1_BACK,
+ AV_CHANNEL_LAYOUT_7POINT1,
+ AV_CHANNEL_LAYOUT_22POINT2,
+ AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK,
+ { 0 },
+};
diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
index 46f0ebf91b..2b8ac67659 100644
--- a/libavcodec/aacdec_fixed.c
+++ b/libavcodec/aacdec_fixed.c
@@ -465,8 +465,8 @@ const FFCodec ff_aac_fixed_decoder = {
},
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
- CODEC_OLD_CHANNEL_LAYOUTS_ARRAY(aac_channel_layout)
- .p.ch_layouts = aac_ch_layout,
+ CODEC_OLD_CHANNEL_LAYOUTS_ARRAY(ff_aac_channel_layout)
+ .p.ch_layouts = ff_aac_ch_layout,
.p.priv_class = &aac_decoder_class,
.p.profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
.flush = flush,
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 51a4cb2b66..3fb9a01da5 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -283,10 +283,10 @@ static int assign_channels(struct elem_to_channel e2c_vec[MAX_ELEM_ID], uint8_t
if (pos == AAC_CHANNEL_LFE) {
while (nb_channels) {
- if (aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE)
+ if (ff_aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE)
return -1;
e2c_vec[i] = (struct elem_to_channel) {
- .av_position = 1ULL << aac_channel_map[layer][pos - 1][j],
+ .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][j],
.syn_ele = layout_map[i][0],
.elem_id = layout_map[i][1],
.aac_position = pos
@@ -302,12 +302,12 @@ static int assign_channels(struct elem_to_channel e2c_vec[MAX_ELEM_ID], uint8_t
}
while (nb_channels & 1) {
- if (aac_channel_map[layer][pos - 1][0] == AV_CHAN_NONE)
+ if (ff_aac_channel_map[layer][pos - 1][0] == AV_CHAN_NONE)
return -1;
- if (aac_channel_map[layer][pos - 1][0] == AV_CHAN_UNUSED)
+ if (ff_aac_channel_map[layer][pos - 1][0] == AV_CHAN_UNUSED)
break;
e2c_vec[i] = (struct elem_to_channel) {
- .av_position = 1ULL << aac_channel_map[layer][pos - 1][0],
+ .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][0],
.syn_ele = layout_map[i][0],
.elem_id = layout_map[i][1],
.aac_position = pos
@@ -319,21 +319,21 @@ static int assign_channels(struct elem_to_channel e2c_vec[MAX_ELEM_ID], uint8_t
j = (pos != AAC_CHANNEL_SIDE) && nb_channels <= 3 ? 3 : 1;
while (nb_channels >= 2) {
- if (aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE ||
- aac_channel_map[layer][pos - 1][j+1] == AV_CHAN_NONE)
+ if (ff_aac_channel_map[layer][pos - 1][j] == AV_CHAN_NONE ||
+ ff_aac_channel_map[layer][pos - 1][j+1] == AV_CHAN_NONE)
return -1;
i += assign_pair(e2c_vec, layout_map, i,
- 1ULL << aac_channel_map[layer][pos - 1][j],
- 1ULL << aac_channel_map[layer][pos - 1][j+1],
+ 1ULL << ff_aac_channel_map[layer][pos - 1][j],
+ 1ULL << ff_aac_channel_map[layer][pos - 1][j+1],
pos, layout);
j += 2;
nb_channels -= 2;
}
while (nb_channels & 1) {
- if (aac_channel_map[layer][pos - 1][5] == AV_CHAN_NONE)
+ if (ff_aac_channel_map[layer][pos - 1][5] == AV_CHAN_NONE)
return -1;
e2c_vec[i] = (struct elem_to_channel) {
- .av_position = 1ULL << aac_channel_map[layer][pos - 1][5],
+ .av_position = 1ULL << ff_aac_channel_map[layer][pos - 1][5],
.syn_ele = layout_map[i][0],
.elem_id = layout_map[i][1],
.aac_position = pos
@@ -552,8 +552,8 @@ static int set_default_channel_config(AACContext *ac, AVCodecContext *avctx,
channel_config);
return AVERROR_INVALIDDATA;
}
- *tags = tags_per_config[channel_config];
- memcpy(layout_map, aac_channel_layout_map[channel_config - 1],
+ *tags = ff_tags_per_config[channel_config];
+ memcpy(layout_map, ff_aac_channel_layout_map[channel_config - 1],
*tags * sizeof(*layout_map));
/*
@@ -661,7 +661,7 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
* SCE[0] CPE[0] CPE[1] LFE[0].
* If we seem to have encountered such a stream, transfer
* the LFE[0] element to the SCE[1]'s mapping */
- if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
+ if (ac->tags_mapped == ff_tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
if (!ac->warned_remapping_once && (type != TYPE_LFE || elem_id != 0)) {
av_log(ac->avctx, AV_LOG_WARNING,
"This stream seems to incorrectly report its last channel as %s[%d], mapping to LFE[0]\n",
@@ -683,7 +683,7 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
* SCE[0] CPE[0] SCE[1].
* If we seem to have encountered such a stream, transfer
* the SCE[1] element to the LFE[0]'s mapping */
- if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
+ if (ac->tags_mapped == ff_tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
if (!ac->warned_remapping_once && (type != TYPE_SCE || elem_id != 1)) {
av_log(ac->avctx, AV_LOG_WARNING,
"This stream seems to incorrectly report its last channel as %s[%d], mapping to SCE[1]\n",
@@ -3091,9 +3091,9 @@ static int aac_decode_er_frame(AVCodecContext *avctx, void *data,
chan_config);
return AVERROR_INVALIDDATA;
}
- for (i = 0; i < tags_per_config[chan_config]; i++) {
- const int elem_type = aac_channel_layout_map[chan_config-1][i][0];
- const int elem_id = aac_channel_layout_map[chan_config-1][i][1];
+ for (i = 0; i < ff_tags_per_config[chan_config]; i++) {
+ const int elem_type = ff_aac_channel_layout_map[chan_config-1][i][0];
+ const int elem_id = ff_aac_channel_layout_map[chan_config-1][i][1];
if (!(che=get_che(ac, elem_type, elem_id))) {
av_log(ac->avctx, AV_LOG_ERROR,
"channel element %d.%d is not allocated\n",
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index 41f1db781d..db6fd0a04f 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -1,7 +1,5 @@
/*
* AAC decoder data
- * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
- * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
*
* This file is part of FFmpeg.
*
@@ -30,99 +28,20 @@
#ifndef AVCODEC_AACDECTAB_H
#define AVCODEC_AACDECTAB_H
-#include "libavutil/channel_layout.h"
-#include "aac.h"
-
#include <stdint.h>
-static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 5, 5, 16, 5, 0 };
+#include "libavutil/channel_layout.h"
+
+extern const int8_t ff_tags_per_config[16];
-static const uint8_t aac_channel_layout_map[16][16][3] = {
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, },
- { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
- { { 0, } },
- { { 0, } },
- { { 0, } },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
- {
- { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, // SCE1 = FC,
- { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, // CPE1 = FLc and FRc,
- { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, // CPE2 = FL and FR,
- { TYPE_CPE, 2, AAC_CHANNEL_BACK }, // CPE3 = SiL and SiR,
- { TYPE_CPE, 3, AAC_CHANNEL_BACK }, // CPE4 = BL and BR,
- { TYPE_SCE, 1, AAC_CHANNEL_BACK }, // SCE2 = BC,
- { TYPE_LFE, 0, AAC_CHANNEL_LFE }, // LFE1 = LFE1,
- { TYPE_LFE, 1, AAC_CHANNEL_LFE }, // LFE2 = LFE2,
- { TYPE_SCE, 2, AAC_CHANNEL_FRONT }, // SCE3 = TpFC,
- { TYPE_CPE, 4, AAC_CHANNEL_FRONT }, // CPE5 = TpFL and TpFR,
- { TYPE_CPE, 5, AAC_CHANNEL_SIDE }, // CPE6 = TpSiL and TpSiR,
- { TYPE_SCE, 3, AAC_CHANNEL_SIDE }, // SCE4 = TpC,
- { TYPE_CPE, 6, AAC_CHANNEL_BACK }, // CPE7 = TpBL and TpBR,
- { TYPE_SCE, 4, AAC_CHANNEL_BACK }, // SCE5 = TpBC,
- { TYPE_SCE, 5, AAC_CHANNEL_FRONT }, // SCE6 = BtFC,
- { TYPE_CPE, 7, AAC_CHANNEL_FRONT }, // CPE8 = BtFL and BtFR
- },
- { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, { TYPE_CPE, 2, AAC_CHANNEL_FRONT }, },
- { { 0, } },
-};
+extern const uint8_t ff_aac_channel_layout_map[16][16][3];
-static const int16_t aac_channel_map[3][4][6] = {
- {
- { AV_CHAN_FRONT_CENTER, AV_CHAN_FRONT_LEFT_OF_CENTER, AV_CHAN_FRONT_RIGHT_OF_CENTER, AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT, AV_CHAN_NONE },
- { AV_CHAN_UNUSED, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
- { AV_CHAN_UNUSED, AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT, AV_CHAN_BACK_LEFT, AV_CHAN_BACK_RIGHT, AV_CHAN_BACK_CENTER },
- { AV_CHAN_LOW_FREQUENCY, AV_CHAN_LOW_FREQUENCY_2, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
- },
- {
- { AV_CHAN_TOP_FRONT_CENTER, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_TOP_FRONT_LEFT, AV_CHAN_TOP_FRONT_RIGHT, AV_CHAN_NONE },
- { AV_CHAN_UNUSED, AV_CHAN_TOP_SIDE_LEFT, AV_CHAN_TOP_SIDE_RIGHT, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_TOP_CENTER},
- { AV_CHAN_UNUSED, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_TOP_BACK_LEFT, AV_CHAN_TOP_BACK_RIGHT, AV_CHAN_TOP_BACK_CENTER},
- { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE},
- },
- {
- { AV_CHAN_BOTTOM_FRONT_CENTER, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_BOTTOM_FRONT_LEFT, AV_CHAN_BOTTOM_FRONT_RIGHT, AV_CHAN_NONE },
- { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
- { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
- { AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE, AV_CHAN_NONE },
- },
-};
+extern const int16_t ff_aac_channel_map[3][4][6];
#if FF_API_OLD_CHANNEL_LAYOUT
-static const uint64_t aac_channel_layout[] = {
- AV_CH_LAYOUT_MONO,
- AV_CH_LAYOUT_STEREO,
- AV_CH_LAYOUT_SURROUND,
- AV_CH_LAYOUT_4POINT0,
- AV_CH_LAYOUT_5POINT0_BACK,
- AV_CH_LAYOUT_5POINT1_BACK,
- AV_CH_LAYOUT_7POINT1_WIDE_BACK,
- AV_CH_LAYOUT_6POINT1_BACK,
- AV_CH_LAYOUT_7POINT1,
- AV_CH_LAYOUT_22POINT2,
- AV_CH_LAYOUT_7POINT1_TOP_BACK,
- 0,
-};
+extern const uint64_t ff_aac_channel_layout[];
#endif
-static const AVChannelLayout aac_ch_layout[] = {
- AV_CHANNEL_LAYOUT_MONO,
- AV_CHANNEL_LAYOUT_STEREO,
- AV_CHANNEL_LAYOUT_SURROUND,
- AV_CHANNEL_LAYOUT_4POINT0,
- AV_CHANNEL_LAYOUT_5POINT0_BACK,
- AV_CHANNEL_LAYOUT_5POINT1_BACK,
- AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
- AV_CHANNEL_LAYOUT_6POINT1_BACK,
- AV_CHANNEL_LAYOUT_7POINT1,
- AV_CHANNEL_LAYOUT_22POINT2,
- AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK,
- { 0 },
-};
+extern const AVChannelLayout ff_aac_ch_layout[];
#endif /* AVCODEC_AACDECTAB_H */
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 43/61] avcodec/aacdec_template: Deduplicate VLCs
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (40 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 42/61] avcodec/aacdectab: Deduplicate common decoder tables Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 44/61] avcodec/aacdec_template: Don't init unused table for fixed-point decoder Andreas Rheinhardt
` (18 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
They (as well as their init code) are currently duplicated
for the floating- and fixed-point decoders.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 43 ++++++++++++++++++++++++++++++++++++
libavcodec/aacdec_template.c | 42 ++++++-----------------------------
libavcodec/aacdectab.h | 10 +++++++++
3 files changed, 60 insertions(+), 35 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index c75c6fadc6..45f1986258 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -27,6 +27,11 @@
#include "aac.h"
#include "aacdectab.h"
+#include "aactab.h"
+#include "vlc.h"
+
+#include "libavutil/attributes.h"
+#include "libavutil/thread.h"
const int8_t ff_tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 5, 5, 16, 5, 0 };
@@ -117,3 +122,41 @@ const AVChannelLayout ff_aac_ch_layout[] = {
AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK,
{ 0 },
};
+
+VLC ff_vlc_scalefactors;
+VLC ff_vlc_spectral[11];
+
+static av_cold void aacdec_common_init(void)
+{
+ static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
+ 294 + 306 + 268 + 510 + 366 + 462];
+ for (unsigned i = 0, offset = 0; i < 11; i++) {
+ ff_vlc_spectral[i].table = &vlc_buf[offset];
+ ff_vlc_spectral[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
+ ff_vlc_init_sparse(&ff_vlc_spectral[i], 8, ff_aac_spectral_sizes[i],
+ ff_aac_spectral_bits[i], sizeof(ff_aac_spectral_bits[i][0]),
+ sizeof(ff_aac_spectral_bits[i][0]),
+ ff_aac_spectral_codes[i], sizeof(ff_aac_spectral_codes[i][0]),
+ sizeof(ff_aac_spectral_codes[i][0]),
+ ff_aac_codebook_vector_idx[i], sizeof(ff_aac_codebook_vector_idx[i][0]),
+ sizeof(ff_aac_codebook_vector_idx[i][0]),
+ VLC_INIT_STATIC_OVERLONG);
+ offset += ff_vlc_spectral[i].table_size;
+ }
+
+ VLC_INIT_STATIC(&ff_vlc_scalefactors, 7,
+ FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
+ ff_aac_scalefactor_bits,
+ sizeof(ff_aac_scalefactor_bits[0]),
+ sizeof(ff_aac_scalefactor_bits[0]),
+ ff_aac_scalefactor_code,
+ sizeof(ff_aac_scalefactor_code[0]),
+ sizeof(ff_aac_scalefactor_code[0]),
+ 352);
+}
+
+av_cold void ff_aacdec_common_init_once(void)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
+ ff_thread_once(&init_static_once, aacdec_common_init);
+}
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 3fb9a01da5..27be1f896d 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -94,9 +94,6 @@
#include "decode.h"
#include "internal.h"
-static VLC vlc_scalefactors;
-static VLC vlc_spectral[11];
-
static int output_configure(AACContext *ac,
uint8_t layout_map[MAX_ELEM_ID*4][3], int tags,
enum OCStatus oc_type, int get_new_frame);
@@ -1128,36 +1125,11 @@ static void aacdec_init(AACContext *ac);
static av_cold void aac_static_table_init(void)
{
- static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
- 294 + 306 + 268 + 510 + 366 + 462];
- for (unsigned i = 0, offset = 0; i < 11; i++) {
- vlc_spectral[i].table = &vlc_buf[offset];
- vlc_spectral[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
- ff_vlc_init_sparse(&vlc_spectral[i], 8, ff_aac_spectral_sizes[i],
- ff_aac_spectral_bits[i], sizeof(ff_aac_spectral_bits[i][0]),
- sizeof(ff_aac_spectral_bits[i][0]),
- ff_aac_spectral_codes[i], sizeof(ff_aac_spectral_codes[i][0]),
- sizeof(ff_aac_spectral_codes[i][0]),
- ff_aac_codebook_vector_idx[i], sizeof(ff_aac_codebook_vector_idx[i][0]),
- sizeof(ff_aac_codebook_vector_idx[i][0]),
- VLC_INIT_STATIC_OVERLONG);
- offset += vlc_spectral[i].table_size;
- }
-
AAC_RENAME(ff_aac_sbr_init)();
+ ff_aacdec_common_init_once();
ff_aac_tableinit();
- VLC_INIT_STATIC(&vlc_scalefactors, 7,
- FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
- ff_aac_scalefactor_bits,
- sizeof(ff_aac_scalefactor_bits[0]),
- sizeof(ff_aac_scalefactor_bits[0]),
- ff_aac_scalefactor_code,
- sizeof(ff_aac_scalefactor_code[0]),
- sizeof(ff_aac_scalefactor_code[0]),
- 352);
-
// window initialization
AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960);
AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME(aac_kbd_short_120), 6.0, 120);
@@ -1526,7 +1498,7 @@ static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *
} else if ((band_type[idx] == INTENSITY_BT) ||
(band_type[idx] == INTENSITY_BT2)) {
for (; i < run_end; i++, idx++) {
- offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
+ offset[2] += get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
clipped_offset = av_clip(offset[2], -155, 100);
if (offset[2] != clipped_offset) {
avpriv_request_sample(ac->avctx,
@@ -1545,7 +1517,7 @@ static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *
if (noise_flag-- > 0)
offset[1] += get_bits(gb, NOISE_PRE_BITS) - NOISE_PRE;
else
- offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
+ offset[1] += get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
clipped_offset = av_clip(offset[1], -100, 155);
if (offset[1] != clipped_offset) {
avpriv_request_sample(ac->avctx,
@@ -1561,7 +1533,7 @@ static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *
}
} else {
for (; i < run_end; i++, idx++) {
- offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
+ offset[0] += get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
if (offset[0] > 255U) {
av_log(ac->avctx, AV_LOG_ERROR,
"Scalefactor (%d) out of range.\n", offset[0]);
@@ -1734,7 +1706,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, INTFLOAT coef[1024],
#if !USE_FIXED
const float *vq = ff_aac_codebook_vector_vals[cbt_m1];
#endif /* !USE_FIXED */
- const VLCElem *vlc_tab = vlc_spectral[cbt_m1].table;
+ const VLCElem *vlc_tab = ff_vlc_spectral[cbt_m1].table;
OPEN_READER(re, gb);
switch (cbt_m1 >> 1) {
@@ -2308,7 +2280,7 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
INTFLOAT gain_cache = FIXR10(1.);
if (c) {
cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb);
- gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0;
+ gain = cge ? get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - 60: 0;
gain_cache = GET_GAIN(scale, gain);
#if USE_FIXED
if ((abs(gain_cache)-1024) >> 3 > 30)
@@ -2322,7 +2294,7 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) {
if (sce->band_type[idx] != ZERO_BT) {
if (!cge) {
- int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
+ int t = get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - 60;
if (t) {
int s = 1;
t = gain += t;
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index db6fd0a04f..a009e9f46e 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -30,8 +30,17 @@
#include <stdint.h>
+#include "vlc.h"
+
+#include "libavutil/attributes_internal.h"
#include "libavutil/channel_layout.h"
+FF_VISIBILITY_PUSH_HIDDEN
+void ff_aacdec_common_init_once(void);
+
+extern VLC ff_vlc_scalefactors;
+extern VLC ff_vlc_spectral[11];
+
extern const int8_t ff_tags_per_config[16];
extern const uint8_t ff_aac_channel_layout_map[16][16][3];
@@ -43,5 +52,6 @@ extern const uint64_t ff_aac_channel_layout[];
#endif
extern const AVChannelLayout ff_aac_ch_layout[];
+FF_VISIBILITY_POP_HIDDEN
#endif /* AVCODEC_AACDECTAB_H */
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 44/61] avcodec/aacdec_template: Don't init unused table for fixed-point decoder
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (41 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 43/61] avcodec/aacdec_template: Deduplicate VLCs Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 45/61] avcodec/aactab: Improve included headers Andreas Rheinhardt
` (17 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The fixed-point decoder actually does not use the floating-point
tables initialized by ff_aac_tableinit() at all. So don't
initialize them for it; instead merge initializing these tables
into ff_aac_float_common_init() which is already the function
for the common static initializations of the floating-point
AAC decoder and the (also floating-point) AAC encoder.
Doing so saves also one AVOnce.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_template.c | 1 -
libavcodec/aacenc.c | 7 ++-
libavcodec/aactab.c | 102 +++++++++++++++++------------------
libavcodec/aactab.h | 2 -
4 files changed, 52 insertions(+), 60 deletions(-)
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 27be1f896d..4591eac6b9 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1128,7 +1128,6 @@ static av_cold void aac_static_table_init(void)
AAC_RENAME(ff_aac_sbr_init)();
ff_aacdec_common_init_once();
- ff_aac_tableinit();
// window initialization
AAC_RENAME(avpriv_kbd_window_init)(AAC_RENAME(aac_kbd_long_960), 4.0, 960);
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 2a34685aec..5e6a255a8f 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -1210,9 +1210,6 @@ static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s)
if (!s->fdsp)
return AVERROR(ENOMEM);
- // window init
- ff_aac_float_common_init();
-
if ((ret = av_tx_init(&s->mdct1024, &s->mdct1024_fn, AV_TX_FLOAT_MDCT, 0,
1024, &scale, 0)) < 0)
return ret;
@@ -1359,6 +1356,9 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
if (s->channels > 3)
s->options.mid_side = 0;
+ // Initialize static tables
+ ff_aac_float_common_init();
+
if ((ret = dsp_init(avctx, s)) < 0)
return ret;
@@ -1393,7 +1393,6 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
#endif
ff_af_queue_init(avctx, &s->afq);
- ff_aac_tableinit();
return 0;
}
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index d0006eac35..edb51d8810 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -36,18 +36,64 @@
#include <stdint.h>
-float ff_aac_pow2sf_tab[428];
-float ff_aac_pow34sf_tab[428];
-
#if CONFIG_AAC_ENCODER || CONFIG_AAC_DECODER
#include "kbdwin.h"
#include "sinewin.h"
+float ff_aac_pow2sf_tab[428];
+float ff_aac_pow34sf_tab[428];
+
DECLARE_ALIGNED(32, float, ff_aac_kbd_long_1024)[1024];
DECLARE_ALIGNED(32, float, ff_aac_kbd_short_128)[128];
+static av_cold void aac_tableinit(void)
+{
+ /* 2^(i/16) for 0 <= i <= 15 */
+ static const float exp2_lut[] = {
+ 1.00000000000000000000,
+ 1.04427378242741384032,
+ 1.09050773266525765921,
+ 1.13878863475669165370,
+ 1.18920711500272106672,
+ 1.24185781207348404859,
+ 1.29683955465100966593,
+ 1.35425554693689272830,
+ 1.41421356237309504880,
+ 1.47682614593949931139,
+ 1.54221082540794082361,
+ 1.61049033194925430818,
+ 1.68179283050742908606,
+ 1.75625216037329948311,
+ 1.83400808640934246349,
+ 1.91520656139714729387,
+ };
+ float t1 = 8.8817841970012523233890533447265625e-16; // 2^(-50)
+ float t2 = 3.63797880709171295166015625e-12; // 2^(-38)
+ int t1_inc_cur, t2_inc_cur;
+ int t1_inc_prev = 0;
+ int t2_inc_prev = 8;
+
+ for (int i = 0; i < 428; i++) {
+ t1_inc_cur = 4 * (i % 4);
+ t2_inc_cur = (8 + 3*i) % 16;
+ if (t1_inc_cur < t1_inc_prev)
+ t1 *= 2;
+ if (t2_inc_cur < t2_inc_prev)
+ t2 *= 2;
+ // A much more efficient and accurate way of doing:
+ // ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.0);
+ // ff_aac_pow34sf_tab[i] = pow(ff_aac_pow2sf_tab[i], 3.0/4.0);
+ ff_aac_pow2sf_tab[i] = t1 * exp2_lut[t1_inc_cur];
+ ff_aac_pow34sf_tab[i] = t2 * exp2_lut[t2_inc_cur];
+ t1_inc_prev = t1_inc_cur;
+ t2_inc_prev = t2_inc_cur;
+ }
+}
+
static av_cold void aac_float_common_init(void)
{
+ aac_tableinit();
+
avpriv_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
avpriv_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
ff_init_ff_sine_windows(10);
@@ -3299,53 +3345,3 @@ const DECLARE_ALIGNED(32, int, ff_aac_eld_window_480_fixed)[1800] = {
0xffecff1c, 0xffed391e, 0xffed740c, 0xffedafb1,
0xffedebe1, 0xffee287d, 0xffee654e, 0xffeea23f,
};
-
-static void aac_tableinit(void)
-{
- /* 2^(i/16) for 0 <= i <= 15 */
- static const float exp2_lut[] = {
- 1.00000000000000000000,
- 1.04427378242741384032,
- 1.09050773266525765921,
- 1.13878863475669165370,
- 1.18920711500272106672,
- 1.24185781207348404859,
- 1.29683955465100966593,
- 1.35425554693689272830,
- 1.41421356237309504880,
- 1.47682614593949931139,
- 1.54221082540794082361,
- 1.61049033194925430818,
- 1.68179283050742908606,
- 1.75625216037329948311,
- 1.83400808640934246349,
- 1.91520656139714729387,
- };
- float t1 = 8.8817841970012523233890533447265625e-16; // 2^(-50)
- float t2 = 3.63797880709171295166015625e-12; // 2^(-38)
- int t1_inc_cur, t2_inc_cur;
- int t1_inc_prev = 0;
- int t2_inc_prev = 8;
-
- for (int i = 0; i < 428; i++) {
- t1_inc_cur = 4 * (i % 4);
- t2_inc_cur = (8 + 3*i) % 16;
- if (t1_inc_cur < t1_inc_prev)
- t1 *= 2;
- if (t2_inc_cur < t2_inc_prev)
- t2 *= 2;
- // A much more efficient and accurate way of doing:
- // ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.0);
- // ff_aac_pow34sf_tab[i] = pow(ff_aac_pow2sf_tab[i], 3.0/4.0);
- ff_aac_pow2sf_tab[i] = t1 * exp2_lut[t1_inc_cur];
- ff_aac_pow34sf_tab[i] = t2 * exp2_lut[t2_inc_cur];
- t1_inc_prev = t1_inc_cur;
- t2_inc_prev = t2_inc_cur;
- }
-}
-
-void ff_aac_tableinit(void)
-{
- static AVOnce init_static_once = AV_ONCE_INIT;
- ff_thread_once(&init_static_once, aac_tableinit);
-}
diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h
index 9b1450c2eb..7693876c34 100644
--- a/libavcodec/aactab.h
+++ b/libavcodec/aactab.h
@@ -42,8 +42,6 @@
extern float ff_aac_pow2sf_tab[428];
extern float ff_aac_pow34sf_tab[428];
-void ff_aac_tableinit(void);
-
/* @name ltp_coef
* Table of the LTP coefficients
*/
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 45/61] avcodec/aactab: Improve included headers
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (42 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 44/61] avcodec/aacdec_template: Don't init unused table for fixed-point decoder Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 46/61] avcodec/aacdec_common: Avoid superfluous VLC structures Andreas Rheinhardt
` (16 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacpsy.c | 2 +-
libavcodec/aactab.c | 8 ++++----
libavcodec/aactab.h | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 933369e445..1fbd259e51 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -28,7 +28,7 @@
#include "libavutil/ffmath.h"
#include "avcodec.h"
-#include "aactab.h"
+#include "aac.h"
#include "psymodel.h"
/***********************************
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index edb51d8810..d20ac56a3f 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -27,15 +27,15 @@
* @author Maxim Gavrilov ( maxim.gavrilov gmail com )
*/
-#include "config.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include "config_components.h"
+#include "libavutil/attributes.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
-#include "aac.h"
#include "aactab.h"
-#include <stdint.h>
-
#if CONFIG_AAC_ENCODER || CONFIG_AAC_DECODER
#include "kbdwin.h"
#include "sinewin.h"
diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h
index 7693876c34..81db29a4e4 100644
--- a/libavcodec/aactab.h
+++ b/libavcodec/aactab.h
@@ -31,7 +31,7 @@
#define AVCODEC_AACTAB_H
#include "libavutil/mem_internal.h"
-#include "aac.h"
+#include "aac_defines.h"
#include <stdint.h>
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 46/61] avcodec/aacdec_common: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (43 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 45/61] avcodec/aactab: Improve included headers Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 47/61] avcodec/aacsbr_template: Deduplicate VLCs Andreas Rheinhardt
` (15 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For all VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table. And in some cases one can even
avoid this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 43 +++++++++++++++++-------------------
libavcodec/aacdec_template.c | 12 +++++-----
libavcodec/aacdectab.h | 4 ++--
3 files changed, 28 insertions(+), 31 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index 45f1986258..61d81343fe 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -123,36 +123,33 @@ const AVChannelLayout ff_aac_ch_layout[] = {
{ 0 },
};
-VLC ff_vlc_scalefactors;
-VLC ff_vlc_spectral[11];
+VLCElem ff_vlc_scalefactors[352];
+const VLCElem *ff_vlc_spectral[11];
static av_cold void aacdec_common_init(void)
{
static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
294 + 306 + 268 + 510 + 366 + 462];
- for (unsigned i = 0, offset = 0; i < 11; i++) {
- ff_vlc_spectral[i].table = &vlc_buf[offset];
- ff_vlc_spectral[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
- ff_vlc_init_sparse(&ff_vlc_spectral[i], 8, ff_aac_spectral_sizes[i],
- ff_aac_spectral_bits[i], sizeof(ff_aac_spectral_bits[i][0]),
- sizeof(ff_aac_spectral_bits[i][0]),
- ff_aac_spectral_codes[i], sizeof(ff_aac_spectral_codes[i][0]),
- sizeof(ff_aac_spectral_codes[i][0]),
- ff_aac_codebook_vector_idx[i], sizeof(ff_aac_codebook_vector_idx[i][0]),
- sizeof(ff_aac_codebook_vector_idx[i][0]),
- VLC_INIT_STATIC_OVERLONG);
- offset += ff_vlc_spectral[i].table_size;
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
+
+ for (unsigned i = 0; i < 11; i++) {
+#define TAB_WRAP_SIZE(name) name[i], sizeof(name[i][0]), sizeof(name[i][0])
+ ff_vlc_spectral[i] =
+ ff_vlc_init_tables_sparse(&state, 8, ff_aac_spectral_sizes[i],
+ TAB_WRAP_SIZE(ff_aac_spectral_bits),
+ TAB_WRAP_SIZE(ff_aac_spectral_codes),
+ TAB_WRAP_SIZE(ff_aac_codebook_vector_idx),
+ 0);
}
- VLC_INIT_STATIC(&ff_vlc_scalefactors, 7,
- FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
- ff_aac_scalefactor_bits,
- sizeof(ff_aac_scalefactor_bits[0]),
- sizeof(ff_aac_scalefactor_bits[0]),
- ff_aac_scalefactor_code,
- sizeof(ff_aac_scalefactor_code[0]),
- sizeof(ff_aac_scalefactor_code[0]),
- 352);
+ VLC_INIT_STATIC_TABLE(ff_vlc_scalefactors, 7,
+ FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
+ ff_aac_scalefactor_bits,
+ sizeof(ff_aac_scalefactor_bits[0]),
+ sizeof(ff_aac_scalefactor_bits[0]),
+ ff_aac_scalefactor_code,
+ sizeof(ff_aac_scalefactor_code[0]),
+ sizeof(ff_aac_scalefactor_code[0]), 0);
}
av_cold void ff_aacdec_common_init_once(void)
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 4591eac6b9..1ea551b533 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1497,7 +1497,7 @@ static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *
} else if ((band_type[idx] == INTENSITY_BT) ||
(band_type[idx] == INTENSITY_BT2)) {
for (; i < run_end; i++, idx++) {
- offset[2] += get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
+ offset[2] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
clipped_offset = av_clip(offset[2], -155, 100);
if (offset[2] != clipped_offset) {
avpriv_request_sample(ac->avctx,
@@ -1516,7 +1516,7 @@ static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *
if (noise_flag-- > 0)
offset[1] += get_bits(gb, NOISE_PRE_BITS) - NOISE_PRE;
else
- offset[1] += get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
+ offset[1] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
clipped_offset = av_clip(offset[1], -100, 155);
if (offset[1] != clipped_offset) {
avpriv_request_sample(ac->avctx,
@@ -1532,7 +1532,7 @@ static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *
}
} else {
for (; i < run_end; i++, idx++) {
- offset[0] += get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - SCALE_DIFF_ZERO;
+ offset[0] += get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - SCALE_DIFF_ZERO;
if (offset[0] > 255U) {
av_log(ac->avctx, AV_LOG_ERROR,
"Scalefactor (%d) out of range.\n", offset[0]);
@@ -1705,7 +1705,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, INTFLOAT coef[1024],
#if !USE_FIXED
const float *vq = ff_aac_codebook_vector_vals[cbt_m1];
#endif /* !USE_FIXED */
- const VLCElem *vlc_tab = ff_vlc_spectral[cbt_m1].table;
+ const VLCElem *vlc_tab = ff_vlc_spectral[cbt_m1];
OPEN_READER(re, gb);
switch (cbt_m1 >> 1) {
@@ -2279,7 +2279,7 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
INTFLOAT gain_cache = FIXR10(1.);
if (c) {
cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb);
- gain = cge ? get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - 60: 0;
+ gain = cge ? get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - 60: 0;
gain_cache = GET_GAIN(scale, gain);
#if USE_FIXED
if ((abs(gain_cache)-1024) >> 3 > 30)
@@ -2293,7 +2293,7 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) {
if (sce->band_type[idx] != ZERO_BT) {
if (!cge) {
- int t = get_vlc2(gb, ff_vlc_scalefactors.table, 7, 3) - 60;
+ int t = get_vlc2(gb, ff_vlc_scalefactors, 7, 3) - 60;
if (t) {
int s = 1;
t = gain += t;
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index a009e9f46e..d62f170136 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -38,8 +38,8 @@
FF_VISIBILITY_PUSH_HIDDEN
void ff_aacdec_common_init_once(void);
-extern VLC ff_vlc_scalefactors;
-extern VLC ff_vlc_spectral[11];
+extern VLCElem ff_vlc_scalefactors[];
+extern const VLCElem *ff_vlc_spectral[11];
extern const int8_t ff_tags_per_config[16];
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 47/61] avcodec/aacsbr_template: Deduplicate VLCs
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (44 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 46/61] avcodec/aacdec_common: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 48/61] avcodec/aacdec_common: Avoid superfluous VLC structures for SBR VLCs Andreas Rheinhardt
` (14 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The VLCs, their init code and the tables used for initialization
are currently duplicated for the floating- and fixed-point decoders.
This commit stops doing so and moves this stuff to aacdec_common.c.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 263 +++++++++++++++++++++++++++++++++++
libavcodec/aacdectab.h | 2 +
libavcodec/aacsbr.c | 1 -
libavcodec/aacsbr.h | 11 +-
libavcodec/aacsbr_fixed.c | 1 -
libavcodec/aacsbr_template.c | 53 ++-----
libavcodec/aacsbrdata.h | 226 ------------------------------
7 files changed, 279 insertions(+), 278 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index 61d81343fe..cbd2a9ccd2 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -126,8 +126,259 @@ const AVChannelLayout ff_aac_ch_layout[] = {
VLCElem ff_vlc_scalefactors[352];
const VLCElem *ff_vlc_spectral[11];
+/// Huffman tables for SBR
+
+static const uint8_t t_huffman_env_1_5dB_bits[121] = {
+ 18, 18, 18, 18, 18, 18, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 17, 18, 16, 17, 18, 17,
+ 16, 16, 16, 16, 15, 14, 14, 13,
+ 13, 12, 11, 10, 9, 8, 7, 6,
+ 5, 4, 3, 2, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 12, 13, 14,
+ 14, 15, 16, 17, 16, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19,
+};
+
+static const uint32_t t_huffman_env_1_5dB_codes[121] = {
+ 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9,
+ 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1,
+ 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9,
+ 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1,
+ 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7,
+ 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa,
+ 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d,
+ 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c,
+ 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6,
+ 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6,
+ 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde,
+ 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6,
+ 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee,
+ 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6,
+ 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe,
+ 0x7ffff,
+};
+
+static const uint8_t f_huffman_env_1_5dB_bits[121] = {
+ 19, 19, 20, 20, 20, 20, 20, 20,
+ 20, 19, 20, 20, 20, 20, 19, 20,
+ 19, 19, 20, 18, 20, 20, 20, 19,
+ 20, 20, 20, 19, 20, 19, 18, 19,
+ 18, 18, 17, 18, 17, 17, 17, 16,
+ 16, 16, 15, 15, 14, 13, 13, 12,
+ 12, 11, 10, 9, 9, 8, 7, 6,
+ 5, 4, 3, 2, 2, 3, 4, 5,
+ 6, 8, 8, 9, 10, 11, 11, 11,
+ 12, 12, 13, 13, 14, 14, 16, 16,
+ 17, 17, 18, 18, 18, 18, 18, 18,
+ 18, 20, 19, 20, 20, 20, 20, 20,
+ 20, 19, 20, 20, 20, 20, 19, 20,
+ 18, 20, 20, 19, 19, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20,
+ 20,
+};
+
+static const uint32_t f_huffman_env_1_5dB_codes[121] = {
+ 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7,
+ 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd,
+ 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde,
+ 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1,
+ 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4,
+ 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa,
+ 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c,
+ 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d,
+ 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb,
+ 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2,
+ 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7,
+ 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb,
+ 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1,
+ 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6,
+ 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe,
+ 0xfffff,
+};
+
+static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = {
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 12, 11, 9, 7, 5, 3,
+ 1, 2, 4, 6, 8, 11, 12, 15,
+ 16, 16, 16, 16, 16, 16, 16, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 17,
+};
+
+static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = {
+ 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb,
+ 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3,
+ 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006,
+ 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0,
+ 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6,
+ 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe,
+ 0x1ffff,
+};
+
+static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = {
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 16,
+ 17, 14, 11, 11, 8, 7, 4, 2,
+ 1, 3, 5, 6, 9, 11, 12, 15,
+ 16, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 19,
+ 19,
+};
+
+static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = {
+ 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9,
+ 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7,
+ 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002,
+ 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa,
+ 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7,
+ 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe,
+ 0x7ffff,
+};
+
+static const uint8_t t_huffman_env_3_0dB_bits[63] = {
+ 18, 18, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 17, 16, 16, 16, 14, 14, 14,
+ 13, 12, 11, 8, 6, 4, 2, 1,
+ 3, 5, 7, 9, 11, 13, 14, 14,
+ 15, 16, 17, 18, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19,
+};
+
+static const uint32_t t_huffman_env_3_0dB_codes[63] = {
+ 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3,
+ 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb,
+ 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8,
+ 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000,
+ 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc,
+ 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0,
+ 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8,
+ 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff,
+};
+
+static const uint8_t f_huffman_env_3_0dB_bits[63] = {
+ 20, 20, 20, 20, 20, 20, 20, 18,
+ 19, 19, 19, 19, 18, 18, 20, 19,
+ 17, 18, 17, 16, 16, 15, 14, 12,
+ 11, 10, 9, 8, 6, 4, 2, 1,
+ 3, 5, 8, 9, 10, 11, 12, 13,
+ 14, 15, 15, 16, 16, 17, 17, 18,
+ 18, 18, 20, 19, 19, 19, 20, 19,
+ 19, 20, 20, 20, 20, 20, 20,
+};
+
+static const uint32_t f_huffman_env_3_0dB_codes[63] = {
+ 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3,
+ 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0,
+ 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd,
+ 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000,
+ 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc,
+ 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5,
+ 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7,
+ 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff,
+};
+
+static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = {
+ 13, 13, 13, 13, 13, 13, 13, 12,
+ 8, 7, 4, 3, 1, 2, 5, 6,
+ 9, 13, 13, 13, 13, 13, 13, 14,
+ 14,
+};
+
+static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = {
+ 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8,
+ 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e,
+ 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe,
+ 0x3fff,
+};
+
+static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = {
+ 13, 13, 13, 13, 13, 14, 14, 11,
+ 8, 7, 4, 2, 1, 3, 5, 6,
+ 9, 12, 13, 14, 14, 14, 14, 14,
+ 14,
+};
+
+static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = {
+ 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc,
+ 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e,
+ 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe,
+ 0x3fff,
+};
+
+static const uint8_t t_huffman_noise_3_0dB_bits[63] = {
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 11, 8, 6, 4, 3, 1,
+ 2, 5, 8, 10, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 14, 14,
+};
+
+static const uint16_t t_huffman_noise_3_0dB_codes[63] = {
+ 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5,
+ 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd,
+ 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5,
+ 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000,
+ 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea,
+ 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1,
+ 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9,
+ 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff,
+};
+
+static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = {
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 5, 2, 1, 3, 6, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8,
+};
+
+static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
+ 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
+ 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6,
+ 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
+ 0xff,
+};
+
+VLC ff_aac_sbr_vlc[10];
+
static av_cold void aacdec_common_init(void)
{
+#define SBR_INIT_VLC_STATIC(num, size) \
+ VLC_INIT_STATIC(&ff_aac_sbr_vlc[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \
+ sbr_tmp[num].sbr_bits , 1, 1, \
+ sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \
+ size)
+#define SBR_VLC_ROW(name) \
+ { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
+ static const struct {
+ const void *sbr_codes, *sbr_bits;
+ const unsigned int table_size, elem_size;
+ } sbr_tmp[] = {
+ SBR_VLC_ROW(t_huffman_env_1_5dB),
+ SBR_VLC_ROW(f_huffman_env_1_5dB),
+ SBR_VLC_ROW(t_huffman_env_bal_1_5dB),
+ SBR_VLC_ROW(f_huffman_env_bal_1_5dB),
+ SBR_VLC_ROW(t_huffman_env_3_0dB),
+ SBR_VLC_ROW(f_huffman_env_3_0dB),
+ SBR_VLC_ROW(t_huffman_env_bal_3_0dB),
+ SBR_VLC_ROW(f_huffman_env_bal_3_0dB),
+ SBR_VLC_ROW(t_huffman_noise_3_0dB),
+ SBR_VLC_ROW(t_huffman_noise_bal_3_0dB),
+ };
+
static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
294 + 306 + 268 + 510 + 366 + 462];
VLCInitState state = VLC_INIT_STATE(vlc_buf);
@@ -150,6 +401,18 @@ static av_cold void aacdec_common_init(void)
ff_aac_scalefactor_code,
sizeof(ff_aac_scalefactor_code[0]),
sizeof(ff_aac_scalefactor_code[0]), 0);
+
+ // SBR VLC table initialization
+ SBR_INIT_VLC_STATIC(0, 1098);
+ SBR_INIT_VLC_STATIC(1, 1092);
+ SBR_INIT_VLC_STATIC(2, 768);
+ SBR_INIT_VLC_STATIC(3, 1026);
+ SBR_INIT_VLC_STATIC(4, 1058);
+ SBR_INIT_VLC_STATIC(5, 1052);
+ SBR_INIT_VLC_STATIC(6, 544);
+ SBR_INIT_VLC_STATIC(7, 544);
+ SBR_INIT_VLC_STATIC(8, 592);
+ SBR_INIT_VLC_STATIC(9, 512);
}
av_cold void ff_aacdec_common_init_once(void)
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index d62f170136..02e0d8a48e 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -38,6 +38,8 @@
FF_VISIBILITY_PUSH_HIDDEN
void ff_aacdec_common_init_once(void);
+extern VLC ff_aac_sbr_vlc[10];
+
extern VLCElem ff_vlc_scalefactors[];
extern const VLCElem *ff_vlc_spectral[11];
diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c
index 47aa6cb3c1..683c079b91 100644
--- a/libavcodec/aacsbr.c
+++ b/libavcodec/aacsbr.c
@@ -47,7 +47,6 @@
#include "mips/aacsbr_mips.h"
#endif /* ARCH_MIPS */
-static VLC vlc_sbr[10];
static void aacsbr_func_ptr_init(AACSBRContext *c);
static void make_bands(int16_t* bands, int start, int stop, int num_bands)
diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h
index 09f9eb1d2c..0d182f822c 100644
--- a/libavcodec/aacsbr.h
+++ b/libavcodec/aacsbr.h
@@ -30,7 +30,7 @@
#define AVCODEC_AACSBR_H
#include "get_bits.h"
-#include "aac.h"
+#include "aac_defines.h"
#include "sbr.h"
#define ENVELOPE_ADJUSTMENT_OFFSET 2
@@ -69,15 +69,6 @@ enum {
static const int8_t vlc_sbr_lav[10] =
{ 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 };
-#define SBR_INIT_VLC_STATIC(num, size) \
- VLC_INIT_STATIC(&vlc_sbr[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \
- sbr_tmp[num].sbr_bits , 1, 1, \
- sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \
- size)
-
-#define SBR_VLC_ROW(name) \
- { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
-
/** Initialize SBR. */
void AAC_RENAME(ff_aac_sbr_init)(void);
/** Initialize one SBR context. */
diff --git a/libavcodec/aacsbr_fixed.c b/libavcodec/aacsbr_fixed.c
index cac472552e..3dbda32447 100644
--- a/libavcodec/aacsbr_fixed.c
+++ b/libavcodec/aacsbr_fixed.c
@@ -70,7 +70,6 @@
#include <float.h>
#include <math.h>
-static VLC vlc_sbr[10];
static void aacsbr_func_ptr_init(AACSBRContext *c);
static const int CONST_LN2 = Q31(0.6931471806/256); // ln(2)/256
static const int CONST_RECIP_LN2 = Q31(0.7213475204); // 0.5/ln(2)
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index f3d3258d2e..26be2739d3 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -32,6 +32,7 @@
* @author Zoran Basaric ( zoran.basaric@imgtec.com )
*/
+#include "aacdectab.h"
#include "libavutil/qsort.h"
static av_cold void aacsbr_tableinit(void)
@@ -44,34 +45,6 @@ static av_cold void aacsbr_tableinit(void)
av_cold void AAC_RENAME(ff_aac_sbr_init)(void)
{
- static const struct {
- const void *sbr_codes, *sbr_bits;
- const unsigned int table_size, elem_size;
- } sbr_tmp[] = {
- SBR_VLC_ROW(t_huffman_env_1_5dB),
- SBR_VLC_ROW(f_huffman_env_1_5dB),
- SBR_VLC_ROW(t_huffman_env_bal_1_5dB),
- SBR_VLC_ROW(f_huffman_env_bal_1_5dB),
- SBR_VLC_ROW(t_huffman_env_3_0dB),
- SBR_VLC_ROW(f_huffman_env_3_0dB),
- SBR_VLC_ROW(t_huffman_env_bal_3_0dB),
- SBR_VLC_ROW(f_huffman_env_bal_3_0dB),
- SBR_VLC_ROW(t_huffman_noise_3_0dB),
- SBR_VLC_ROW(t_huffman_noise_bal_3_0dB),
- };
-
- // SBR VLC table initialization
- SBR_INIT_VLC_STATIC(0, 1098);
- SBR_INIT_VLC_STATIC(1, 1092);
- SBR_INIT_VLC_STATIC(2, 768);
- SBR_INIT_VLC_STATIC(3, 1026);
- SBR_INIT_VLC_STATIC(4, 1058);
- SBR_INIT_VLC_STATIC(5, 1052);
- SBR_INIT_VLC_STATIC(6, 544);
- SBR_INIT_VLC_STATIC(7, 544);
- SBR_INIT_VLC_STATIC(8, 592);
- SBR_INIT_VLC_STATIC(9, 512);
-
aacsbr_tableinit();
AAC_RENAME(ff_ps_init)();
@@ -838,29 +811,29 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
if (sbr->bs_coupling && ch) {
if (ch_data->bs_amp_res) {
bits = 5;
- t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_3_0DB].table;
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB];
- f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB].table;
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
} else {
bits = 6;
- t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_1_5DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_1_5DB].table;
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB];
- f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_1_5DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_1_5DB].table;
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB];
}
} else {
if (ch_data->bs_amp_res) {
bits = 6;
- t_huff = vlc_sbr[T_HUFFMAN_ENV_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_3_0DB].table;
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB];
- f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB].table;
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
} else {
bits = 7;
- t_huff = vlc_sbr[T_HUFFMAN_ENV_1_5DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_1_5DB].table;
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB];
- f_huff = vlc_sbr[F_HUFFMAN_ENV_1_5DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_1_5DB].table;
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB];
}
}
@@ -923,14 +896,14 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
if (sbr->bs_coupling && ch) {
- t_huff = vlc_sbr[T_HUFFMAN_NOISE_BAL_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_BAL_3_0DB].table;
t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB];
- f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB].table;
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
} else {
- t_huff = vlc_sbr[T_HUFFMAN_NOISE_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_3_0DB].table;
t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB];
- f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB].table;
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
}
diff --git a/libavcodec/aacsbrdata.h b/libavcodec/aacsbrdata.h
index 7bb45b229e..cb8b83d3d6 100644
--- a/libavcodec/aacsbrdata.h
+++ b/libavcodec/aacsbrdata.h
@@ -33,232 +33,6 @@
#include "libavutil/mem_internal.h"
#include "aac_defines.h"
-///< Huffman tables for SBR
-
-static const uint8_t t_huffman_env_1_5dB_bits[121] = {
- 18, 18, 18, 18, 18, 18, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 17, 18, 16, 17, 18, 17,
- 16, 16, 16, 16, 15, 14, 14, 13,
- 13, 12, 11, 10, 9, 8, 7, 6,
- 5, 4, 3, 2, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 12, 13, 14,
- 14, 15, 16, 17, 16, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19,
-};
-
-static const uint32_t t_huffman_env_1_5dB_codes[121] = {
- 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9,
- 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1,
- 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9,
- 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1,
- 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7,
- 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa,
- 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d,
- 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c,
- 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6,
- 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6,
- 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde,
- 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6,
- 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee,
- 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6,
- 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe,
- 0x7ffff,
-};
-
-static const uint8_t f_huffman_env_1_5dB_bits[121] = {
- 19, 19, 20, 20, 20, 20, 20, 20,
- 20, 19, 20, 20, 20, 20, 19, 20,
- 19, 19, 20, 18, 20, 20, 20, 19,
- 20, 20, 20, 19, 20, 19, 18, 19,
- 18, 18, 17, 18, 17, 17, 17, 16,
- 16, 16, 15, 15, 14, 13, 13, 12,
- 12, 11, 10, 9, 9, 8, 7, 6,
- 5, 4, 3, 2, 2, 3, 4, 5,
- 6, 8, 8, 9, 10, 11, 11, 11,
- 12, 12, 13, 13, 14, 14, 16, 16,
- 17, 17, 18, 18, 18, 18, 18, 18,
- 18, 20, 19, 20, 20, 20, 20, 20,
- 20, 19, 20, 20, 20, 20, 19, 20,
- 18, 20, 20, 19, 19, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20,
- 20,
-};
-
-static const uint32_t f_huffman_env_1_5dB_codes[121] = {
- 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7,
- 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd,
- 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde,
- 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1,
- 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4,
- 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa,
- 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c,
- 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d,
- 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb,
- 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2,
- 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7,
- 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb,
- 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1,
- 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6,
- 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe,
- 0xfffff,
-};
-
-static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = {
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 12, 11, 9, 7, 5, 3,
- 1, 2, 4, 6, 8, 11, 12, 15,
- 16, 16, 16, 16, 16, 16, 16, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17,
-};
-
-static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = {
- 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb,
- 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3,
- 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006,
- 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0,
- 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6,
- 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe,
- 0x1ffff,
-};
-
-static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = {
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 16,
- 17, 14, 11, 11, 8, 7, 4, 2,
- 1, 3, 5, 6, 9, 11, 12, 15,
- 16, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 19,
- 19,
-};
-
-static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = {
- 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9,
- 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7,
- 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002,
- 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa,
- 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7,
- 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe,
- 0x7ffff,
-};
-
-static const uint8_t t_huffman_env_3_0dB_bits[63] = {
- 18, 18, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 17, 16, 16, 16, 14, 14, 14,
- 13, 12, 11, 8, 6, 4, 2, 1,
- 3, 5, 7, 9, 11, 13, 14, 14,
- 15, 16, 17, 18, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19,
-};
-
-static const uint32_t t_huffman_env_3_0dB_codes[63] = {
- 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3,
- 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb,
- 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8,
- 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000,
- 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc,
- 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0,
- 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8,
- 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff,
-};
-
-static const uint8_t f_huffman_env_3_0dB_bits[63] = {
- 20, 20, 20, 20, 20, 20, 20, 18,
- 19, 19, 19, 19, 18, 18, 20, 19,
- 17, 18, 17, 16, 16, 15, 14, 12,
- 11, 10, 9, 8, 6, 4, 2, 1,
- 3, 5, 8, 9, 10, 11, 12, 13,
- 14, 15, 15, 16, 16, 17, 17, 18,
- 18, 18, 20, 19, 19, 19, 20, 19,
- 19, 20, 20, 20, 20, 20, 20,
-};
-
-static const uint32_t f_huffman_env_3_0dB_codes[63] = {
- 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3,
- 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0,
- 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd,
- 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000,
- 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc,
- 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5,
- 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7,
- 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff,
-};
-
-static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = {
- 13, 13, 13, 13, 13, 13, 13, 12,
- 8, 7, 4, 3, 1, 2, 5, 6,
- 9, 13, 13, 13, 13, 13, 13, 14,
- 14,
-};
-
-static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = {
- 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8,
- 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e,
- 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe,
- 0x3fff,
-};
-
-static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = {
- 13, 13, 13, 13, 13, 14, 14, 11,
- 8, 7, 4, 2, 1, 3, 5, 6,
- 9, 12, 13, 14, 14, 14, 14, 14,
- 14,
-};
-
-static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = {
- 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc,
- 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e,
- 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe,
- 0x3fff,
-};
-
-static const uint8_t t_huffman_noise_3_0dB_bits[63] = {
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 11, 8, 6, 4, 3, 1,
- 2, 5, 8, 10, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 14, 14,
-};
-
-static const uint16_t t_huffman_noise_3_0dB_codes[63] = {
- 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5,
- 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd,
- 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5,
- 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000,
- 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea,
- 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1,
- 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9,
- 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff,
-};
-
-static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = {
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 5, 2, 1, 3, 6, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8,
-};
-
-static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
- 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
- 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6,
- 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
- 0xff,
-};
-
static const int8_t sbr_offset[6][16] = {
{-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, // fs_sbr = 16000 Hz
{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13}, // fs_sbr = 22050 Hz
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 48/61] avcodec/aacdec_common: Avoid superfluous VLC structures for SBR VLCs
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (45 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 47/61] avcodec/aacsbr_template: Deduplicate VLCs Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 49/61] avcodec/aacdec_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
` (13 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For all VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 35 +++++++++++++++++++----------------
libavcodec/aacdectab.h | 2 +-
libavcodec/aacsbr_template.c | 24 ++++++++++++------------
3 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index cbd2a9ccd2..295ea87dce 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -352,15 +352,16 @@ static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
0xff,
};
-VLC ff_aac_sbr_vlc[10];
+const VLCElem *ff_aac_sbr_vlc[10];
static av_cold void aacdec_common_init(void)
{
-#define SBR_INIT_VLC_STATIC(num, size) \
- VLC_INIT_STATIC(&ff_aac_sbr_vlc[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \
+#define SBR_INIT_VLC_STATIC(num) \
+ ff_aac_sbr_vlc[num] = \
+ ff_vlc_init_tables_sparse(&state, 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \
sbr_tmp[num].sbr_bits , 1, 1, \
sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \
- size)
+ NULL, 0, 0, 0)
#define SBR_VLC_ROW(name) \
{ name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
static const struct {
@@ -379,8 +380,10 @@ static av_cold void aacdec_common_init(void)
SBR_VLC_ROW(t_huffman_noise_bal_3_0dB),
};
- static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
- 294 + 306 + 268 + 510 + 366 + 462];
+ static VLCElem vlc_buf[(304 + 270 + 550 + 300 + 328 +
+ 294 + 306 + 268 + 510 + 366 + 462) +
+ (1098 + 1092 + 768 + 1026 + 1058 +
+ 1052 + 544 + 544 + 592 + 512)];
VLCInitState state = VLC_INIT_STATE(vlc_buf);
for (unsigned i = 0; i < 11; i++) {
@@ -403,16 +406,16 @@ static av_cold void aacdec_common_init(void)
sizeof(ff_aac_scalefactor_code[0]), 0);
// SBR VLC table initialization
- SBR_INIT_VLC_STATIC(0, 1098);
- SBR_INIT_VLC_STATIC(1, 1092);
- SBR_INIT_VLC_STATIC(2, 768);
- SBR_INIT_VLC_STATIC(3, 1026);
- SBR_INIT_VLC_STATIC(4, 1058);
- SBR_INIT_VLC_STATIC(5, 1052);
- SBR_INIT_VLC_STATIC(6, 544);
- SBR_INIT_VLC_STATIC(7, 544);
- SBR_INIT_VLC_STATIC(8, 592);
- SBR_INIT_VLC_STATIC(9, 512);
+ SBR_INIT_VLC_STATIC(0);
+ SBR_INIT_VLC_STATIC(1);
+ SBR_INIT_VLC_STATIC(2);
+ SBR_INIT_VLC_STATIC(3);
+ SBR_INIT_VLC_STATIC(4);
+ SBR_INIT_VLC_STATIC(5);
+ SBR_INIT_VLC_STATIC(6);
+ SBR_INIT_VLC_STATIC(7);
+ SBR_INIT_VLC_STATIC(8);
+ SBR_INIT_VLC_STATIC(9);
}
av_cold void ff_aacdec_common_init_once(void)
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index 02e0d8a48e..7079b061fc 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -38,7 +38,7 @@
FF_VISIBILITY_PUSH_HIDDEN
void ff_aacdec_common_init_once(void);
-extern VLC ff_aac_sbr_vlc[10];
+extern const VLCElem *ff_aac_sbr_vlc[10];
extern VLCElem ff_vlc_scalefactors[];
extern const VLCElem *ff_vlc_spectral[11];
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index 26be2739d3..a82be8a8d5 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -811,29 +811,29 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
if (sbr->bs_coupling && ch) {
if (ch_data->bs_amp_res) {
bits = 5;
- t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_3_0DB];
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB];
- f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
} else {
bits = 6;
- t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_1_5DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_1_5DB];
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB];
- f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_1_5DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_1_5DB];
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB];
}
} else {
if (ch_data->bs_amp_res) {
bits = 6;
- t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_3_0DB];
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB];
- f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
} else {
bits = 7;
- t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_1_5DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_1_5DB];
t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB];
- f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_1_5DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_1_5DB];
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB];
}
}
@@ -896,14 +896,14 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
if (sbr->bs_coupling && ch) {
- t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_BAL_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_BAL_3_0DB];
t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB];
- f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
} else {
- t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_3_0DB].table;
+ t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_3_0DB];
t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB];
- f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB].table;
+ f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 49/61] avcodec/aacdec_common: Switch to ff_vlc_init_tables_from_lengths()
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (46 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 48/61] avcodec/aacdec_common: Avoid superfluous VLC structures for SBR VLCs Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 50/61] avcodec/aacdec_common: Combine huffman tabs Andreas Rheinhardt
` (12 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It allows to replace code tables of type uint32_t or uint16_t
by symbols of type uint8_t. It is also faster.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 377 +++++++++++++++----------------------
1 file changed, 154 insertions(+), 223 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index 295ea87dce..d03fbdbaec 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -128,245 +128,179 @@ const VLCElem *ff_vlc_spectral[11];
/// Huffman tables for SBR
-static const uint8_t t_huffman_env_1_5dB_bits[121] = {
- 18, 18, 18, 18, 18, 18, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 17, 18, 16, 17, 18, 17,
- 16, 16, 16, 16, 15, 14, 14, 13,
- 13, 12, 11, 10, 9, 8, 7, 6,
- 5, 4, 3, 2, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 12, 13, 14,
- 14, 15, 16, 17, 16, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19,
+ /* t_huffman_env_1_5dB - 121 entries */
+static const uint8_t t_huffman_env_1_5dB_tab[][2] = {
+ { 60, 2 }, { 59, 2 }, { 61, 3 }, { 58, 3 }, { 62, 4 },
+ { 57, 4 }, { 63, 5 }, { 56, 5 }, { 64, 6 }, { 55, 6 },
+ { 65, 7 }, { 54, 7 }, { 66, 8 }, { 53, 8 }, { 67, 9 },
+ { 52, 9 }, { 51, 10 }, { 68, 10 }, { 50, 11 }, { 69, 12 },
+ { 49, 12 }, { 70, 13 }, { 48, 13 }, { 47, 13 }, { 71, 14 },
+ { 46, 14 }, { 72, 14 }, { 45, 14 }, { 44, 15 }, { 73, 15 },
+ { 41, 16 }, { 42, 16 }, { 43, 16 }, { 74, 16 }, { 36, 16 },
+ { 40, 16 }, { 76, 16 }, { 34, 17 }, { 39, 17 }, { 75, 17 },
+ { 37, 17 }, { 35, 18 }, { 38, 18 }, { 0, 18 }, { 1, 18 },
+ { 2, 18 }, { 3, 18 }, { 4, 18 }, { 5, 18 }, { 6, 19 },
+ { 7, 19 }, { 8, 19 }, { 9, 19 }, { 10, 19 }, { 11, 19 },
+ { 12, 19 }, { 13, 19 }, { 14, 19 }, { 15, 19 }, { 16, 19 },
+ { 17, 19 }, { 18, 19 }, { 19, 19 }, { 20, 19 }, { 21, 19 },
+ { 22, 19 }, { 23, 19 }, { 24, 19 }, { 25, 19 }, { 26, 19 },
+ { 27, 19 }, { 28, 19 }, { 29, 19 }, { 30, 19 }, { 31, 19 },
+ { 32, 19 }, { 33, 19 }, { 77, 19 }, { 78, 19 }, { 79, 19 },
+ { 80, 19 }, { 81, 19 }, { 82, 19 }, { 83, 19 }, { 84, 19 },
+ { 85, 19 }, { 86, 19 }, { 87, 19 }, { 88, 19 }, { 89, 19 },
+ { 90, 19 }, { 91, 19 }, { 92, 19 }, { 93, 19 }, { 94, 19 },
+ { 95, 19 }, { 96, 19 }, { 97, 19 }, { 98, 19 }, { 99, 19 },
+ { 100, 19 }, { 101, 19 }, { 102, 19 }, { 103, 19 }, { 104, 19 },
+ { 105, 19 }, { 106, 19 }, { 107, 19 }, { 108, 19 }, { 109, 19 },
+ { 110, 19 }, { 111, 19 }, { 112, 19 }, { 113, 19 }, { 114, 19 },
+ { 115, 19 }, { 116, 19 }, { 117, 19 }, { 118, 19 }, { 119, 19 },
+ { 120, 19 },
};
-static const uint32_t t_huffman_env_1_5dB_codes[121] = {
- 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9,
- 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1,
- 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9,
- 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1,
- 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7,
- 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa,
- 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d,
- 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c,
- 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6,
- 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6,
- 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde,
- 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6,
- 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee,
- 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6,
- 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe,
- 0x7ffff,
+ /* f_huffman_env_1_5dB - 121 entries */
+static const uint8_t f_huffman_env_1_5dB_tab[][2] = {
+ { 60, 2 }, { 59, 2 }, { 61, 3 }, { 58, 3 }, { 57, 4 },
+ { 62, 4 }, { 56, 5 }, { 63, 5 }, { 55, 6 }, { 64, 6 },
+ { 54, 7 }, { 65, 8 }, { 53, 8 }, { 66, 8 }, { 52, 9 },
+ { 67, 9 }, { 51, 9 }, { 68, 10 }, { 50, 10 }, { 69, 11 },
+ { 49, 11 }, { 70, 11 }, { 71, 11 }, { 48, 12 }, { 72, 12 },
+ { 47, 12 }, { 73, 12 }, { 74, 13 }, { 46, 13 }, { 45, 13 },
+ { 75, 13 }, { 76, 14 }, { 77, 14 }, { 44, 14 }, { 43, 15 },
+ { 42, 15 }, { 41, 16 }, { 78, 16 }, { 79, 16 }, { 40, 16 },
+ { 39, 16 }, { 80, 17 }, { 81, 17 }, { 36, 17 }, { 37, 17 },
+ { 38, 17 }, { 34, 17 }, { 32, 18 }, { 82, 18 }, { 83, 18 },
+ { 85, 18 }, { 19, 18 }, { 35, 18 }, { 86, 18 }, { 87, 18 },
+ { 30, 18 }, { 33, 18 }, { 84, 18 }, { 88, 18 }, { 104, 18 },
+ { 9, 19 }, { 14, 19 }, { 16, 19 }, { 17, 19 }, { 23, 19 },
+ { 27, 19 }, { 29, 19 }, { 31, 19 }, { 90, 19 }, { 97, 19 },
+ { 102, 19 }, { 107, 19 }, { 108, 19 }, { 0, 19 }, { 1, 19 },
+ { 2, 20 }, { 3, 20 }, { 4, 20 }, { 5, 20 }, { 6, 20 },
+ { 7, 20 }, { 8, 20 }, { 10, 20 }, { 11, 20 }, { 12, 20 },
+ { 13, 20 }, { 15, 20 }, { 18, 20 }, { 20, 20 }, { 21, 20 },
+ { 22, 20 }, { 24, 20 }, { 25, 20 }, { 26, 20 }, { 28, 20 },
+ { 89, 20 }, { 91, 20 }, { 92, 20 }, { 93, 20 }, { 94, 20 },
+ { 95, 20 }, { 96, 20 }, { 98, 20 }, { 99, 20 }, { 100, 20 },
+ { 101, 20 }, { 103, 20 }, { 105, 20 }, { 106, 20 }, { 109, 20 },
+ { 110, 20 }, { 111, 20 }, { 112, 20 }, { 113, 20 }, { 114, 20 },
+ { 115, 20 }, { 116, 20 }, { 117, 20 }, { 118, 20 }, { 119, 20 },
+ { 120, 20 },
};
-static const uint8_t f_huffman_env_1_5dB_bits[121] = {
- 19, 19, 20, 20, 20, 20, 20, 20,
- 20, 19, 20, 20, 20, 20, 19, 20,
- 19, 19, 20, 18, 20, 20, 20, 19,
- 20, 20, 20, 19, 20, 19, 18, 19,
- 18, 18, 17, 18, 17, 17, 17, 16,
- 16, 16, 15, 15, 14, 13, 13, 12,
- 12, 11, 10, 9, 9, 8, 7, 6,
- 5, 4, 3, 2, 2, 3, 4, 5,
- 6, 8, 8, 9, 10, 11, 11, 11,
- 12, 12, 13, 13, 14, 14, 16, 16,
- 17, 17, 18, 18, 18, 18, 18, 18,
- 18, 20, 19, 20, 20, 20, 20, 20,
- 20, 19, 20, 20, 20, 20, 19, 20,
- 18, 20, 20, 19, 19, 20, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20,
- 20,
+ /* t_huffman_env_bal_1_5dB - 49 entries */
+static const uint8_t t_huffman_env_bal_1_5dB_tab[][2] = {
+ { 24, 1 }, { 25, 2 }, { 23, 3 }, { 26, 4 }, { 22, 5 },
+ { 27, 6 }, { 21, 7 }, { 28, 8 }, { 20, 9 }, { 19, 11 },
+ { 29, 11 }, { 18, 12 }, { 30, 12 }, { 31, 15 }, { 17, 16 },
+ { 32, 16 }, { 0, 16 }, { 1, 16 }, { 2, 16 }, { 3, 16 },
+ { 4, 16 }, { 5, 16 }, { 6, 16 }, { 7, 16 }, { 8, 16 },
+ { 9, 16 }, { 10, 16 }, { 11, 16 }, { 12, 16 }, { 13, 16 },
+ { 14, 16 }, { 15, 16 }, { 16, 16 }, { 33, 16 }, { 34, 16 },
+ { 35, 16 }, { 36, 16 }, { 37, 16 }, { 38, 16 }, { 39, 17 },
+ { 40, 17 }, { 41, 17 }, { 42, 17 }, { 43, 17 }, { 44, 17 },
+ { 45, 17 }, { 46, 17 }, { 47, 17 }, { 48, 17 },
};
-static const uint32_t f_huffman_env_1_5dB_codes[121] = {
- 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7,
- 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd,
- 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde,
- 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1,
- 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4,
- 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa,
- 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c,
- 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d,
- 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb,
- 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2,
- 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7,
- 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb,
- 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1,
- 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6,
- 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe,
- 0xfffff,
+ /* f_huffman_env_bal_1_5dB - 49 entries */
+static const uint8_t f_huffman_env_bal_1_5dB_tab[][2] = {
+ { 24, 1 }, { 23, 2 }, { 25, 3 }, { 22, 4 }, { 26, 5 },
+ { 27, 6 }, { 21, 7 }, { 20, 8 }, { 28, 9 }, { 19, 11 },
+ { 29, 11 }, { 18, 11 }, { 30, 12 }, { 17, 14 }, { 31, 15 },
+ { 32, 16 }, { 15, 16 }, { 16, 17 }, { 0, 18 }, { 1, 18 },
+ { 2, 18 }, { 3, 18 }, { 4, 18 }, { 5, 18 }, { 6, 18 },
+ { 7, 18 }, { 8, 18 }, { 9, 18 }, { 10, 18 }, { 11, 18 },
+ { 12, 18 }, { 13, 18 }, { 14, 18 }, { 33, 18 }, { 34, 18 },
+ { 35, 18 }, { 36, 18 }, { 37, 18 }, { 38, 18 }, { 39, 18 },
+ { 40, 18 }, { 41, 18 }, { 42, 18 }, { 43, 18 }, { 44, 18 },
+ { 45, 18 }, { 46, 18 }, { 47, 19 }, { 48, 19 },
};
-static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = {
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 12, 11, 9, 7, 5, 3,
- 1, 2, 4, 6, 8, 11, 12, 15,
- 16, 16, 16, 16, 16, 16, 16, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17,
+ /* t_huffman_env_3_0dB - 63 entries */
+static const uint8_t t_huffman_env_3_0dB_tab[][2] = {
+ { 31, 1 }, { 30, 2 }, { 32, 3 }, { 29, 4 }, { 33, 5 },
+ { 28, 6 }, { 34, 7 }, { 27, 8 }, { 35, 9 }, { 26, 11 },
+ { 36, 11 }, { 25, 12 }, { 24, 13 }, { 37, 13 }, { 23, 14 },
+ { 38, 14 }, { 22, 14 }, { 21, 14 }, { 39, 14 }, { 40, 15 },
+ { 41, 16 }, { 18, 16 }, { 20, 16 }, { 19, 16 }, { 17, 17 },
+ { 42, 17 }, { 43, 18 }, { 0, 18 }, { 1, 18 }, { 2, 19 },
+ { 3, 19 }, { 4, 19 }, { 5, 19 }, { 6, 19 }, { 7, 19 },
+ { 8, 19 }, { 9, 19 }, { 10, 19 }, { 11, 19 }, { 12, 19 },
+ { 13, 19 }, { 14, 19 }, { 15, 19 }, { 16, 19 }, { 44, 19 },
+ { 45, 19 }, { 46, 19 }, { 47, 19 }, { 48, 19 }, { 49, 19 },
+ { 50, 19 }, { 51, 19 }, { 52, 19 }, { 53, 19 }, { 54, 19 },
+ { 55, 19 }, { 56, 19 }, { 57, 19 }, { 58, 19 }, { 59, 19 },
+ { 60, 19 }, { 61, 19 }, { 62, 19 },
};
-static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = {
- 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb,
- 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3,
- 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006,
- 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0,
- 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6,
- 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe,
- 0x1ffff,
+ /* f_huffman_env_3_0dB - 63 entries */
+static const uint8_t f_huffman_env_3_0dB_tab[][2] = {
+ { 31, 1 }, { 30, 2 }, { 32, 3 }, { 29, 4 }, { 33, 5 },
+ { 28, 6 }, { 34, 8 }, { 27, 8 }, { 35, 9 }, { 26, 9 },
+ { 36, 10 }, { 25, 10 }, { 37, 11 }, { 24, 11 }, { 38, 12 },
+ { 23, 12 }, { 39, 13 }, { 40, 14 }, { 22, 14 }, { 21, 15 },
+ { 41, 15 }, { 42, 15 }, { 20, 16 }, { 19, 16 }, { 43, 16 },
+ { 44, 16 }, { 18, 17 }, { 16, 17 }, { 45, 17 }, { 46, 17 },
+ { 17, 18 }, { 49, 18 }, { 13, 18 }, { 7, 18 }, { 12, 18 },
+ { 47, 18 }, { 48, 18 }, { 9, 19 }, { 10, 19 }, { 15, 19 },
+ { 51, 19 }, { 52, 19 }, { 53, 19 }, { 56, 19 }, { 8, 19 },
+ { 11, 19 }, { 55, 19 }, { 0, 20 }, { 1, 20 }, { 2, 20 },
+ { 3, 20 }, { 4, 20 }, { 5, 20 }, { 6, 20 }, { 14, 20 },
+ { 50, 20 }, { 54, 20 }, { 57, 20 }, { 58, 20 }, { 59, 20 },
+ { 60, 20 }, { 61, 20 }, { 62, 20 },
};
-static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = {
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 16,
- 17, 14, 11, 11, 8, 7, 4, 2,
- 1, 3, 5, 6, 9, 11, 12, 15,
- 16, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 19,
- 19,
+ /* t_huffman_env_bal_3_0dB - 25 entries */
+static const uint8_t t_huffman_env_bal_3_0dB_tab[][2] = {
+ { 12, 1 }, { 13, 2 }, { 11, 3 }, { 10, 4 }, { 14, 5 },
+ { 15, 6 }, { 9, 7 }, { 8, 8 }, { 16, 9 }, { 7, 12 },
+ { 0, 13 }, { 1, 13 }, { 2, 13 }, { 3, 13 }, { 4, 13 },
+ { 5, 13 }, { 6, 13 }, { 17, 13 }, { 18, 13 }, { 19, 13 },
+ { 20, 13 }, { 21, 13 }, { 22, 13 }, { 23, 14 }, { 24, 14 },
};
-static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = {
- 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9,
- 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7,
- 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002,
- 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa,
- 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7,
- 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe,
- 0x7ffff,
+ /* f_huffman_env_bal_3_0dB - 25 entries */
+static const uint8_t f_huffman_env_bal_3_0dB_tab[][2] = {
+ { 12, 1 }, { 11, 2 }, { 13, 3 }, { 10, 4 }, { 14, 5 },
+ { 15, 6 }, { 9, 7 }, { 8, 8 }, { 16, 9 }, { 7, 11 },
+ { 17, 12 }, { 18, 13 }, { 0, 13 }, { 1, 13 }, { 2, 13 },
+ { 3, 13 }, { 4, 13 }, { 5, 14 }, { 6, 14 }, { 19, 14 },
+ { 20, 14 }, { 21, 14 }, { 22, 14 }, { 23, 14 }, { 24, 14 },
};
-static const uint8_t t_huffman_env_3_0dB_bits[63] = {
- 18, 18, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 17, 16, 16, 16, 14, 14, 14,
- 13, 12, 11, 8, 6, 4, 2, 1,
- 3, 5, 7, 9, 11, 13, 14, 14,
- 15, 16, 17, 18, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19,
+ /* t_huffman_noise_3_0dB - 63 entries */
+static const uint8_t t_huffman_noise_3_0dB_tab[][2] = {
+ { 31, 1 }, { 32, 2 }, { 30, 3 }, { 29, 4 }, { 33, 5 },
+ { 28, 6 }, { 34, 8 }, { 27, 8 }, { 35, 10 }, { 26, 11 },
+ { 36, 13 }, { 42, 13 }, { 0, 13 }, { 1, 13 }, { 2, 13 },
+ { 3, 13 }, { 4, 13 }, { 5, 13 }, { 6, 13 }, { 7, 13 },
+ { 8, 13 }, { 9, 13 }, { 10, 13 }, { 11, 13 }, { 12, 13 },
+ { 13, 13 }, { 14, 13 }, { 15, 13 }, { 16, 13 }, { 17, 13 },
+ { 18, 13 }, { 19, 13 }, { 20, 13 }, { 21, 13 }, { 22, 13 },
+ { 23, 13 }, { 24, 13 }, { 25, 13 }, { 37, 13 }, { 38, 13 },
+ { 39, 13 }, { 40, 13 }, { 41, 13 }, { 43, 13 }, { 44, 13 },
+ { 45, 13 }, { 46, 13 }, { 47, 13 }, { 48, 13 }, { 49, 13 },
+ { 50, 13 }, { 51, 13 }, { 52, 13 }, { 53, 13 }, { 54, 13 },
+ { 55, 13 }, { 56, 13 }, { 57, 13 }, { 58, 13 }, { 59, 13 },
+ { 60, 13 }, { 61, 14 }, { 62, 14 },
};
-static const uint32_t t_huffman_env_3_0dB_codes[63] = {
- 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3,
- 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb,
- 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8,
- 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000,
- 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc,
- 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0,
- 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8,
- 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff,
-};
-
-static const uint8_t f_huffman_env_3_0dB_bits[63] = {
- 20, 20, 20, 20, 20, 20, 20, 18,
- 19, 19, 19, 19, 18, 18, 20, 19,
- 17, 18, 17, 16, 16, 15, 14, 12,
- 11, 10, 9, 8, 6, 4, 2, 1,
- 3, 5, 8, 9, 10, 11, 12, 13,
- 14, 15, 15, 16, 16, 17, 17, 18,
- 18, 18, 20, 19, 19, 19, 20, 19,
- 19, 20, 20, 20, 20, 20, 20,
-};
-
-static const uint32_t f_huffman_env_3_0dB_codes[63] = {
- 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3,
- 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0,
- 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd,
- 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000,
- 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc,
- 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5,
- 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7,
- 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff,
-};
-
-static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = {
- 13, 13, 13, 13, 13, 13, 13, 12,
- 8, 7, 4, 3, 1, 2, 5, 6,
- 9, 13, 13, 13, 13, 13, 13, 14,
- 14,
-};
-
-static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = {
- 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8,
- 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e,
- 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe,
- 0x3fff,
-};
-
-static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = {
- 13, 13, 13, 13, 13, 14, 14, 11,
- 8, 7, 4, 2, 1, 3, 5, 6,
- 9, 12, 13, 14, 14, 14, 14, 14,
- 14,
-};
-
-static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = {
- 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc,
- 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e,
- 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe,
- 0x3fff,
-};
-
-static const uint8_t t_huffman_noise_3_0dB_bits[63] = {
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 11, 8, 6, 4, 3, 1,
- 2, 5, 8, 10, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 14, 14,
-};
-
-static const uint16_t t_huffman_noise_3_0dB_codes[63] = {
- 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5,
- 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd,
- 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5,
- 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000,
- 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea,
- 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1,
- 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9,
- 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff,
-};
-
-static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = {
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 5, 2, 1, 3, 6, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8,
-};
-
-static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
- 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
- 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6,
- 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
- 0xff,
+ /* t_huffman_noise_bal_3_0dB - 25 entries */
+static const uint8_t t_huffman_noise_bal_3_0dB_tab[][2] = {
+ { 12, 1 }, { 11, 2 }, { 13, 3 }, { 10, 5 }, { 14, 6 },
+ { 0, 8 }, { 1, 8 }, { 2, 8 }, { 3, 8 }, { 4, 8 },
+ { 5, 8 }, { 6, 8 }, { 7, 8 }, { 8, 8 }, { 9, 8 },
+ { 15, 8 }, { 16, 8 }, { 17, 8 }, { 18, 8 }, { 19, 8 },
+ { 20, 8 }, { 21, 8 }, { 22, 8 }, { 23, 8 }, { 24, 8 },
};
const VLCElem *ff_aac_sbr_vlc[10];
static av_cold void aacdec_common_init(void)
{
-#define SBR_INIT_VLC_STATIC(num) \
- ff_aac_sbr_vlc[num] = \
- ff_vlc_init_tables_sparse(&state, 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \
- sbr_tmp[num].sbr_bits , 1, 1, \
- sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \
- NULL, 0, 0, 0)
#define SBR_VLC_ROW(name) \
- { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
+ { name ## _tab, FF_ARRAY_ELEMS(name ## _tab) }
static const struct {
- const void *sbr_codes, *sbr_bits;
- const unsigned int table_size, elem_size;
+ const uint8_t (*sbr_tab)[2];
+ const unsigned int table_size;
} sbr_tmp[] = {
SBR_VLC_ROW(t_huffman_env_1_5dB),
SBR_VLC_ROW(f_huffman_env_1_5dB),
@@ -406,16 +340,13 @@ static av_cold void aacdec_common_init(void)
sizeof(ff_aac_scalefactor_code[0]), 0);
// SBR VLC table initialization
- SBR_INIT_VLC_STATIC(0);
- SBR_INIT_VLC_STATIC(1);
- SBR_INIT_VLC_STATIC(2);
- SBR_INIT_VLC_STATIC(3);
- SBR_INIT_VLC_STATIC(4);
- SBR_INIT_VLC_STATIC(5);
- SBR_INIT_VLC_STATIC(6);
- SBR_INIT_VLC_STATIC(7);
- SBR_INIT_VLC_STATIC(8);
- SBR_INIT_VLC_STATIC(9);
+ for (int i = 0; i < FF_ARRAY_ELEMS(ff_aac_sbr_vlc); i++) {
+ ff_aac_sbr_vlc[i] =
+ ff_vlc_init_tables_from_lengths(&state, 9, sbr_tmp[i].table_size,
+ &sbr_tmp[i].sbr_tab[0][1], 2,
+ &sbr_tmp[i].sbr_tab[0][0], 2, 1,
+ 0, 0);
+ }
}
av_cold void ff_aacdec_common_init_once(void)
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 50/61] avcodec/aacdec_common: Combine huffman tabs
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (47 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 49/61] avcodec/aacdec_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 51/61] avcodec/aacdec_common: Apply offset for SBR VLCs during init Andreas Rheinhardt
` (11 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This allows to avoid the relocations inherent in a table
to individual tables; it also reduces padding.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 59 +++++++-------------------------------
1 file changed, 10 insertions(+), 49 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index d03fbdbaec..6a592600dc 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -128,8 +128,8 @@ const VLCElem *ff_vlc_spectral[11];
/// Huffman tables for SBR
+static const uint8_t sbr_huffman_tab[][2] = {
/* t_huffman_env_1_5dB - 121 entries */
-static const uint8_t t_huffman_env_1_5dB_tab[][2] = {
{ 60, 2 }, { 59, 2 }, { 61, 3 }, { 58, 3 }, { 62, 4 },
{ 57, 4 }, { 63, 5 }, { 56, 5 }, { 64, 6 }, { 55, 6 },
{ 65, 7 }, { 54, 7 }, { 66, 8 }, { 53, 8 }, { 67, 9 },
@@ -155,10 +155,7 @@ static const uint8_t t_huffman_env_1_5dB_tab[][2] = {
{ 110, 19 }, { 111, 19 }, { 112, 19 }, { 113, 19 }, { 114, 19 },
{ 115, 19 }, { 116, 19 }, { 117, 19 }, { 118, 19 }, { 119, 19 },
{ 120, 19 },
-};
-
/* f_huffman_env_1_5dB - 121 entries */
-static const uint8_t f_huffman_env_1_5dB_tab[][2] = {
{ 60, 2 }, { 59, 2 }, { 61, 3 }, { 58, 3 }, { 57, 4 },
{ 62, 4 }, { 56, 5 }, { 63, 5 }, { 55, 6 }, { 64, 6 },
{ 54, 7 }, { 65, 8 }, { 53, 8 }, { 66, 8 }, { 52, 9 },
@@ -184,10 +181,7 @@ static const uint8_t f_huffman_env_1_5dB_tab[][2] = {
{ 110, 20 }, { 111, 20 }, { 112, 20 }, { 113, 20 }, { 114, 20 },
{ 115, 20 }, { 116, 20 }, { 117, 20 }, { 118, 20 }, { 119, 20 },
{ 120, 20 },
-};
-
/* t_huffman_env_bal_1_5dB - 49 entries */
-static const uint8_t t_huffman_env_bal_1_5dB_tab[][2] = {
{ 24, 1 }, { 25, 2 }, { 23, 3 }, { 26, 4 }, { 22, 5 },
{ 27, 6 }, { 21, 7 }, { 28, 8 }, { 20, 9 }, { 19, 11 },
{ 29, 11 }, { 18, 12 }, { 30, 12 }, { 31, 15 }, { 17, 16 },
@@ -198,10 +192,7 @@ static const uint8_t t_huffman_env_bal_1_5dB_tab[][2] = {
{ 35, 16 }, { 36, 16 }, { 37, 16 }, { 38, 16 }, { 39, 17 },
{ 40, 17 }, { 41, 17 }, { 42, 17 }, { 43, 17 }, { 44, 17 },
{ 45, 17 }, { 46, 17 }, { 47, 17 }, { 48, 17 },
-};
-
/* f_huffman_env_bal_1_5dB - 49 entries */
-static const uint8_t f_huffman_env_bal_1_5dB_tab[][2] = {
{ 24, 1 }, { 23, 2 }, { 25, 3 }, { 22, 4 }, { 26, 5 },
{ 27, 6 }, { 21, 7 }, { 20, 8 }, { 28, 9 }, { 19, 11 },
{ 29, 11 }, { 18, 11 }, { 30, 12 }, { 17, 14 }, { 31, 15 },
@@ -212,10 +203,7 @@ static const uint8_t f_huffman_env_bal_1_5dB_tab[][2] = {
{ 35, 18 }, { 36, 18 }, { 37, 18 }, { 38, 18 }, { 39, 18 },
{ 40, 18 }, { 41, 18 }, { 42, 18 }, { 43, 18 }, { 44, 18 },
{ 45, 18 }, { 46, 18 }, { 47, 19 }, { 48, 19 },
-};
-
/* t_huffman_env_3_0dB - 63 entries */
-static const uint8_t t_huffman_env_3_0dB_tab[][2] = {
{ 31, 1 }, { 30, 2 }, { 32, 3 }, { 29, 4 }, { 33, 5 },
{ 28, 6 }, { 34, 7 }, { 27, 8 }, { 35, 9 }, { 26, 11 },
{ 36, 11 }, { 25, 12 }, { 24, 13 }, { 37, 13 }, { 23, 14 },
@@ -229,10 +217,7 @@ static const uint8_t t_huffman_env_3_0dB_tab[][2] = {
{ 50, 19 }, { 51, 19 }, { 52, 19 }, { 53, 19 }, { 54, 19 },
{ 55, 19 }, { 56, 19 }, { 57, 19 }, { 58, 19 }, { 59, 19 },
{ 60, 19 }, { 61, 19 }, { 62, 19 },
-};
-
/* f_huffman_env_3_0dB - 63 entries */
-static const uint8_t f_huffman_env_3_0dB_tab[][2] = {
{ 31, 1 }, { 30, 2 }, { 32, 3 }, { 29, 4 }, { 33, 5 },
{ 28, 6 }, { 34, 8 }, { 27, 8 }, { 35, 9 }, { 26, 9 },
{ 36, 10 }, { 25, 10 }, { 37, 11 }, { 24, 11 }, { 38, 12 },
@@ -246,28 +231,19 @@ static const uint8_t f_huffman_env_3_0dB_tab[][2] = {
{ 3, 20 }, { 4, 20 }, { 5, 20 }, { 6, 20 }, { 14, 20 },
{ 50, 20 }, { 54, 20 }, { 57, 20 }, { 58, 20 }, { 59, 20 },
{ 60, 20 }, { 61, 20 }, { 62, 20 },
-};
-
/* t_huffman_env_bal_3_0dB - 25 entries */
-static const uint8_t t_huffman_env_bal_3_0dB_tab[][2] = {
{ 12, 1 }, { 13, 2 }, { 11, 3 }, { 10, 4 }, { 14, 5 },
{ 15, 6 }, { 9, 7 }, { 8, 8 }, { 16, 9 }, { 7, 12 },
{ 0, 13 }, { 1, 13 }, { 2, 13 }, { 3, 13 }, { 4, 13 },
{ 5, 13 }, { 6, 13 }, { 17, 13 }, { 18, 13 }, { 19, 13 },
{ 20, 13 }, { 21, 13 }, { 22, 13 }, { 23, 14 }, { 24, 14 },
-};
-
/* f_huffman_env_bal_3_0dB - 25 entries */
-static const uint8_t f_huffman_env_bal_3_0dB_tab[][2] = {
{ 12, 1 }, { 11, 2 }, { 13, 3 }, { 10, 4 }, { 14, 5 },
{ 15, 6 }, { 9, 7 }, { 8, 8 }, { 16, 9 }, { 7, 11 },
{ 17, 12 }, { 18, 13 }, { 0, 13 }, { 1, 13 }, { 2, 13 },
{ 3, 13 }, { 4, 13 }, { 5, 14 }, { 6, 14 }, { 19, 14 },
{ 20, 14 }, { 21, 14 }, { 22, 14 }, { 23, 14 }, { 24, 14 },
-};
-
/* t_huffman_noise_3_0dB - 63 entries */
-static const uint8_t t_huffman_noise_3_0dB_tab[][2] = {
{ 31, 1 }, { 32, 2 }, { 30, 3 }, { 29, 4 }, { 33, 5 },
{ 28, 6 }, { 34, 8 }, { 27, 8 }, { 35, 10 }, { 26, 11 },
{ 36, 13 }, { 42, 13 }, { 0, 13 }, { 1, 13 }, { 2, 13 },
@@ -281,10 +257,7 @@ static const uint8_t t_huffman_noise_3_0dB_tab[][2] = {
{ 50, 13 }, { 51, 13 }, { 52, 13 }, { 53, 13 }, { 54, 13 },
{ 55, 13 }, { 56, 13 }, { 57, 13 }, { 58, 13 }, { 59, 13 },
{ 60, 13 }, { 61, 14 }, { 62, 14 },
-};
-
/* t_huffman_noise_bal_3_0dB - 25 entries */
-static const uint8_t t_huffman_noise_bal_3_0dB_tab[][2] = {
{ 12, 1 }, { 11, 2 }, { 13, 3 }, { 10, 5 }, { 14, 6 },
{ 0, 8 }, { 1, 8 }, { 2, 8 }, { 3, 8 }, { 4, 8 },
{ 5, 8 }, { 6, 8 }, { 7, 8 }, { 8, 8 }, { 9, 8 },
@@ -292,33 +265,20 @@ static const uint8_t t_huffman_noise_bal_3_0dB_tab[][2] = {
{ 20, 8 }, { 21, 8 }, { 22, 8 }, { 23, 8 }, { 24, 8 },
};
+static const uint8_t sbr_huffman_nb_codes[] = {
+ 121, 121, 49, 49, 63, 63, 25, 25, 63, 25
+};
+
const VLCElem *ff_aac_sbr_vlc[10];
static av_cold void aacdec_common_init(void)
{
-#define SBR_VLC_ROW(name) \
- { name ## _tab, FF_ARRAY_ELEMS(name ## _tab) }
- static const struct {
- const uint8_t (*sbr_tab)[2];
- const unsigned int table_size;
- } sbr_tmp[] = {
- SBR_VLC_ROW(t_huffman_env_1_5dB),
- SBR_VLC_ROW(f_huffman_env_1_5dB),
- SBR_VLC_ROW(t_huffman_env_bal_1_5dB),
- SBR_VLC_ROW(f_huffman_env_bal_1_5dB),
- SBR_VLC_ROW(t_huffman_env_3_0dB),
- SBR_VLC_ROW(f_huffman_env_3_0dB),
- SBR_VLC_ROW(t_huffman_env_bal_3_0dB),
- SBR_VLC_ROW(f_huffman_env_bal_3_0dB),
- SBR_VLC_ROW(t_huffman_noise_3_0dB),
- SBR_VLC_ROW(t_huffman_noise_bal_3_0dB),
- };
-
static VLCElem vlc_buf[(304 + 270 + 550 + 300 + 328 +
294 + 306 + 268 + 510 + 366 + 462) +
(1098 + 1092 + 768 + 1026 + 1058 +
1052 + 544 + 544 + 592 + 512)];
VLCInitState state = VLC_INIT_STATE(vlc_buf);
+ const uint8_t (*tab)[2] = sbr_huffman_tab;
for (unsigned i = 0; i < 11; i++) {
#define TAB_WRAP_SIZE(name) name[i], sizeof(name[i][0]), sizeof(name[i][0])
@@ -342,10 +302,11 @@ static av_cold void aacdec_common_init(void)
// SBR VLC table initialization
for (int i = 0; i < FF_ARRAY_ELEMS(ff_aac_sbr_vlc); i++) {
ff_aac_sbr_vlc[i] =
- ff_vlc_init_tables_from_lengths(&state, 9, sbr_tmp[i].table_size,
- &sbr_tmp[i].sbr_tab[0][1], 2,
- &sbr_tmp[i].sbr_tab[0][0], 2, 1,
+ ff_vlc_init_tables_from_lengths(&state, 9, sbr_huffman_nb_codes[i],
+ &tab[0][1], 2,
+ &tab[0][0], 2, 1,
0, 0);
+ tab += sbr_huffman_nb_codes[i];
}
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 51/61] avcodec/aacdec_common: Apply offset for SBR VLCs during init
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (48 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 50/61] avcodec/aacdec_common: Combine huffman tabs Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 52/61] avcodec/aacps: Move initializing common stuff to aacdec_common.c Andreas Rheinhardt
` (10 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This avoids having to apply it later after every get_vlc2().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 6 +++++-
libavcodec/aacsbr.h | 3 ---
libavcodec/aacsbr_template.c | 26 ++++++--------------------
3 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index 6a592600dc..4af60e8c7c 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -269,6 +269,10 @@ static const uint8_t sbr_huffman_nb_codes[] = {
121, 121, 49, 49, 63, 63, 25, 25, 63, 25
};
+static const int8_t sbr_vlc_offsets[10] = {
+ -60, -60, -24, -24, -31, -31, -12, -12, -31, -12
+};
+
const VLCElem *ff_aac_sbr_vlc[10];
static av_cold void aacdec_common_init(void)
@@ -305,7 +309,7 @@ static av_cold void aacdec_common_init(void)
ff_vlc_init_tables_from_lengths(&state, 9, sbr_huffman_nb_codes[i],
&tab[0][1], 2,
&tab[0][0], 2, 1,
- 0, 0);
+ sbr_vlc_offsets[i], 0);
tab += sbr_huffman_nb_codes[i];
}
}
diff --git a/libavcodec/aacsbr.h b/libavcodec/aacsbr.h
index 0d182f822c..3a19fe1c7e 100644
--- a/libavcodec/aacsbr.h
+++ b/libavcodec/aacsbr.h
@@ -66,9 +66,6 @@ enum {
EXTENSION_ID_PS = 2,
};
-static const int8_t vlc_sbr_lav[10] =
- { 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 };
-
/** Initialize SBR. */
void AAC_RENAME(ff_aac_sbr_init)(void);
/** Initialize one SBR context. */
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index a82be8a8d5..98e9fd8fed 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -804,7 +804,6 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
int bits;
int i, j, k;
const VLCElem *t_huff, *f_huff;
- int t_lav, f_lav;
const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
const int odd = sbr->n[1] & 1;
@@ -812,29 +811,21 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
if (ch_data->bs_amp_res) {
bits = 5;
t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_3_0DB];
- t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB];
f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
- f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
} else {
bits = 6;
t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_BAL_1_5DB];
- t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB];
f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_1_5DB];
- f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB];
}
} else {
if (ch_data->bs_amp_res) {
bits = 6;
t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_3_0DB];
- t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB];
f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
- f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
} else {
bits = 7;
t_huff = ff_aac_sbr_vlc[T_HUFFMAN_ENV_1_5DB];
- t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB];
f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_1_5DB];
- f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB];
}
}
@@ -843,7 +834,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
// bs_freq_res[0] == bs_freq_res[bs_num_env] from prev frame
if (ch_data->bs_freq_res[i + 1] == ch_data->bs_freq_res[i]) {
for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
- ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][j] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+ ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][j] + delta * get_vlc2(gb, t_huff, 9, 3);
if (ch_data->env_facs_q[i + 1][j] > 127U) {
av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
return AVERROR_INVALIDDATA;
@@ -852,7 +843,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
} else if (ch_data->bs_freq_res[i + 1]) {
for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
k = (j + odd) >> 1; // find k such that f_tablelow[k] <= f_tablehigh[j] < f_tablelow[k + 1]
- ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+ ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * get_vlc2(gb, t_huff, 9, 3);
if (ch_data->env_facs_q[i + 1][j] > 127U) {
av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
return AVERROR_INVALIDDATA;
@@ -861,7 +852,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
} else {
for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
k = j ? 2*j - odd : 0; // find k such that f_tablehigh[k] == f_tablelow[j]
- ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+ ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i][k] + delta * get_vlc2(gb, t_huff, 9, 3);
if (ch_data->env_facs_q[i + 1][j] > 127U) {
av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
return AVERROR_INVALIDDATA;
@@ -871,7 +862,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
} else {
ch_data->env_facs_q[i + 1][0] = delta * get_bits(gb, bits); // bs_env_start_value_balance
for (j = 1; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
- ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav);
+ ch_data->env_facs_q[i + 1][j] = ch_data->env_facs_q[i + 1][j - 1] + delta * get_vlc2(gb, f_huff, 9, 3);
if (ch_data->env_facs_q[i + 1][j] > 127U) {
av_log(ac->avctx, AV_LOG_ERROR, "env_facs_q %d is invalid\n", ch_data->env_facs_q[i + 1][j]);
return AVERROR_INVALIDDATA;
@@ -892,25 +883,20 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
{
int i, j;
const VLCElem *t_huff, *f_huff;
- int t_lav, f_lav;
int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
if (sbr->bs_coupling && ch) {
t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_BAL_3_0DB];
- t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB];
f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_BAL_3_0DB];
- f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
} else {
t_huff = ff_aac_sbr_vlc[T_HUFFMAN_NOISE_3_0DB];
- t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB];
f_huff = ff_aac_sbr_vlc[F_HUFFMAN_ENV_3_0DB];
- f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
}
for (i = 0; i < ch_data->bs_num_noise; i++) {
if (ch_data->bs_df_noise[i]) {
for (j = 0; j < sbr->n_q; j++) {
- ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav);
+ ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i][j] + delta * get_vlc2(gb, t_huff, 9, 2);
if (ch_data->noise_facs_q[i + 1][j] > 30U) {
av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
return AVERROR_INVALIDDATA;
@@ -919,7 +905,7 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
} else {
ch_data->noise_facs_q[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level
for (j = 1; j < sbr->n_q; j++) {
- ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav);
+ ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i + 1][j - 1] + delta * get_vlc2(gb, f_huff, 9, 3);
if (ch_data->noise_facs_q[i + 1][j] > 30U) {
av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
return AVERROR_INVALIDDATA;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 52/61] avcodec/aacps: Move initializing common stuff to aacdec_common.c
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (49 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 51/61] avcodec/aacdec_common: Apply offset for SBR VLCs during init Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 53/61] avcodec/aacps_common: Avoid superfluous VLC structures Andreas Rheinhardt
` (9 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
ff_ps_init() initializes some tables for AAC parametric stereo
and some of them are only valid for the fixed- or floating-point
decoder, whereas others (namely VLCs) are valid for both.
The latter are therefore initialized by ff_ps_init_common()
and because the two versions of ff_ps_init() can be run
concurrently, it is guarded by an AVOnce.
Yet now that there is ff_aacdec_common_init_once() there is
a better way to do this: Call ff_ps_init_common()
from ff_aacdec_common_init_once(). That way there is no need
to guard ff_ps_init_common() by an AVOnce any more.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacdec_common.c | 3 +++
libavcodec/aacps.c | 1 -
libavcodec/aacps_common.c | 9 +--------
3 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/libavcodec/aacdec_common.c b/libavcodec/aacdec_common.c
index 4af60e8c7c..75368b7075 100644
--- a/libavcodec/aacdec_common.c
+++ b/libavcodec/aacdec_common.c
@@ -27,6 +27,7 @@
#include "aac.h"
#include "aacdectab.h"
+#include "aacps.h"
#include "aactab.h"
#include "vlc.h"
@@ -312,6 +313,8 @@ static av_cold void aacdec_common_init(void)
sbr_vlc_offsets[i], 0);
tab += sbr_huffman_nb_codes[i];
}
+
+ ff_ps_init_common();
}
av_cold void ff_aacdec_common_init_once(void)
diff --git a/libavcodec/aacps.c b/libavcodec/aacps.c
index ed00006a3a..5a3e6b3dfd 100644
--- a/libavcodec/aacps.c
+++ b/libavcodec/aacps.c
@@ -739,7 +739,6 @@ int AAC_RENAME(ff_ps_apply)(PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][
av_cold void AAC_RENAME(ff_ps_init)(void) {
ps_tableinit();
- ff_ps_init_common();
}
av_cold void AAC_RENAME(ff_ps_ctx_init)(PSContext *ps)
diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index 11bdb960cf..6b5493d4c2 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -21,7 +21,6 @@
#include <stdint.h>
#include "libavutil/common.h"
-#include "libavutil/thread.h"
#include "aacps.h"
#include "get_bits.h"
#include "aacpsdata.c"
@@ -298,7 +297,7 @@ err:
#define PS_VLC_ROW(name) \
{ name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
-static av_cold void ps_init_common(void)
+av_cold void ff_ps_init_common(void)
{
// Syntax initialization
static const struct {
@@ -328,9 +327,3 @@ static av_cold void ps_init_common(void)
PS_INIT_VLC_STATIC(8, 5, 32);
PS_INIT_VLC_STATIC(9, 5, 32);
}
-
-av_cold void ff_ps_init_common(void)
-{
- static AVOnce init_static_once = AV_ONCE_INIT;
- ff_thread_once(&init_static_once, ps_init_common);
-}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 53/61] avcodec/aacps_common: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (50 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 52/61] avcodec/aacps: Move initializing common stuff to aacdec_common.c Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 54/61] avcodec/aacps_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
` (8 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For all VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacps_common.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index 6b5493d4c2..281eaa12e7 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -58,7 +58,7 @@ static const int huff_iid[] = {
huff_iid_dt1,
};
-static VLC vlc_ps[10];
+static const VLCElem *vlc_ps[10];
#define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION, NB_BITS, MAX_DEPTH) \
/** \
@@ -77,7 +77,7 @@ static int read_ ## PAR ## _data(void *logctx, GetBitContext *gb, PSCommonContex
int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
{ \
int b, num = ps->nr_ ## PAR ## _par; \
- const VLCElem *vlc_table = vlc_ps[table_idx].table; \
+ const VLCElem *vlc_table = vlc_ps[table_idx]; \
if (dt) { \
int e_prev = e ? e - 1 : ps->num_env_old - 1; \
e_prev = FFMAX(e_prev, 0); \
@@ -289,16 +289,18 @@ err:
}
#define PS_INIT_VLC_STATIC(num, nb_bits, size) \
- VLC_INIT_STATIC(&vlc_ps[num], nb_bits, ps_tmp[num].table_size / ps_tmp[num].elem_size, \
- ps_tmp[num].ps_bits, 1, 1, \
- ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, \
- size);
+ vlc_ps[num] = ff_vlc_init_tables(&state, nb_bits, ps_tmp[num].table_size / ps_tmp[num].elem_size, \
+ ps_tmp[num].ps_bits, 1, 1, \
+ ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, 0);
#define PS_VLC_ROW(name) \
{ name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
av_cold void ff_ps_init_common(void)
{
+ static VLCElem vlc_buf[(1544 + 832 + 1024 + 1036) +
+ (544 + 544) + (32 + 32 + 32 + 32)];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
// Syntax initialization
static const struct {
const void *ps_codes, *ps_bits;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 54/61] avcodec/aacps_common: Switch to ff_vlc_init_tables_from_lengths()
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (51 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 53/61] avcodec/aacps_common: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 55/61] avcodec/aacps_common: Combine huffman tabels Andreas Rheinhardt
` (7 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It allows to replace codes of type uint16_t or uint32_t
by symbols of type uint8_t.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacps_common.c | 28 ++----
libavcodec/aacpsdata.c | 204 +++++++++++++++++---------------------
2 files changed, 102 insertions(+), 130 deletions(-)
diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index 281eaa12e7..653fc38da3 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -288,13 +288,8 @@ err:
return bits_left;
}
-#define PS_INIT_VLC_STATIC(num, nb_bits, size) \
- vlc_ps[num] = ff_vlc_init_tables(&state, nb_bits, ps_tmp[num].table_size / ps_tmp[num].elem_size, \
- ps_tmp[num].ps_bits, 1, 1, \
- ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, 0);
-
#define PS_VLC_ROW(name) \
- { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
+ { name ## _tab, FF_ARRAY_ELEMS(name ## _tab) }
av_cold void ff_ps_init_common(void)
{
@@ -303,8 +298,8 @@ av_cold void ff_ps_init_common(void)
VLCInitState state = VLC_INIT_STATE(vlc_buf);
// Syntax initialization
static const struct {
- const void *ps_codes, *ps_bits;
- const unsigned int table_size, elem_size;
+ const uint8_t (*vlc_tab)[2];
+ const unsigned int table_elems;
} ps_tmp[] = {
PS_VLC_ROW(huff_iid_df1),
PS_VLC_ROW(huff_iid_dt1),
@@ -318,14 +313,11 @@ av_cold void ff_ps_init_common(void)
PS_VLC_ROW(huff_opd_dt),
};
- PS_INIT_VLC_STATIC(0, 9, 1544);
- PS_INIT_VLC_STATIC(1, 9, 832);
- PS_INIT_VLC_STATIC(2, 9, 1024);
- PS_INIT_VLC_STATIC(3, 9, 1036);
- PS_INIT_VLC_STATIC(4, 9, 544);
- PS_INIT_VLC_STATIC(5, 9, 544);
- PS_INIT_VLC_STATIC(6, 5, 32);
- PS_INIT_VLC_STATIC(7, 5, 32);
- PS_INIT_VLC_STATIC(8, 5, 32);
- PS_INIT_VLC_STATIC(9, 5, 32);
+ for (int i = 0; i < FF_ARRAY_ELEMS(vlc_ps); i++) {
+ vlc_ps[i] =
+ ff_vlc_init_tables_from_lengths(&state, i <= 5 ? 9 : 5, ps_tmp[i].table_elems,
+ &ps_tmp[i].vlc_tab[0][1], 2,
+ &ps_tmp[i].vlc_tab[0][0], 2, 1,
+ 0, 0);
+ }
}
diff --git a/libavcodec/aacpsdata.c b/libavcodec/aacpsdata.c
index 7a1f490060..8241346b0d 100644
--- a/libavcodec/aacpsdata.c
+++ b/libavcodec/aacpsdata.c
@@ -19,118 +19,98 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-static const uint8_t huff_iid_df1_bits[] = {
- 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15, 14, 14,
- 13, 12, 12, 11, 10, 10, 8, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 17, 18, 17, 18, 18,
- 18, 18, 18, 18, 18, 18, 18,
-};
-
-static const uint32_t huff_iid_df1_codes[] = {
- 0x01FEB4, 0x01FEB5, 0x01FD76, 0x01FD77, 0x01FD74, 0x01FD75, 0x01FE8A,
- 0x01FE8B, 0x01FE88, 0x00FE80, 0x01FEB6, 0x00FE82, 0x00FEB8, 0x007F42,
- 0x007FAE, 0x003FAF, 0x001FD1, 0x001FE9, 0x000FE9, 0x0007EA, 0x0007FB,
- 0x0003FB, 0x0001FB, 0x0001FF, 0x00007C, 0x00003C, 0x00001C, 0x00000C,
- 0x000000, 0x000001, 0x000001, 0x000002, 0x000001, 0x00000D, 0x00001D,
- 0x00003D, 0x00007D, 0x0000FC, 0x0001FC, 0x0003FC, 0x0003F4, 0x0007EB,
- 0x000FEA, 0x001FEA, 0x001FD6, 0x003FD0, 0x007FAF, 0x007F43, 0x00FEB9,
- 0x00FE83, 0x01FEB7, 0x00FE81, 0x01FE89, 0x01FE8E, 0x01FE8F, 0x01FE8C,
- 0x01FE8D, 0x01FEB2, 0x01FEB3, 0x01FEB0, 0x01FEB1,
-};
-
-static const uint8_t huff_iid_dt1_bits[] = {
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 13,
- 13, 13, 12, 12, 11, 10, 9, 9, 7, 6, 5, 3, 1, 2, 5, 6, 7, 8,
- 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16,
-};
-
-static const uint16_t huff_iid_dt1_codes[] = {
- 0x004ED4, 0x004ED5, 0x004ECE, 0x004ECF, 0x004ECC, 0x004ED6, 0x004ED8,
- 0x004F46, 0x004F60, 0x002718, 0x002719, 0x002764, 0x002765, 0x00276D,
- 0x0027B1, 0x0013B7, 0x0013D6, 0x0009C7, 0x0009E9, 0x0009ED, 0x0004EE,
- 0x0004F7, 0x000278, 0x000139, 0x00009A, 0x00009F, 0x000020, 0x000011,
- 0x00000A, 0x000003, 0x000001, 0x000000, 0x00000B, 0x000012, 0x000021,
- 0x00004C, 0x00009B, 0x00013A, 0x000279, 0x000270, 0x0004EF, 0x0004E2,
- 0x0009EA, 0x0009D8, 0x0013D7, 0x0013D0, 0x0027B2, 0x0027A2, 0x00271A,
- 0x00271B, 0x004F66, 0x004F67, 0x004F61, 0x004F47, 0x004ED9, 0x004ED7,
- 0x004ECD, 0x004ED2, 0x004ED3, 0x004ED0, 0x004ED1,
-};
-
-static const uint8_t huff_iid_df0_bits[] = {
- 17, 17, 17, 17, 16, 15, 13, 10, 9, 7, 6, 5, 4, 3, 1, 3, 4, 5,
- 6, 6, 8, 11, 13, 14, 14, 15, 17, 18, 18,
-};
-
-static const uint32_t huff_iid_df0_codes[] = {
- 0x01FFFB, 0x01FFFC, 0x01FFFD, 0x01FFFA, 0x00FFFC, 0x007FFC, 0x001FFD,
- 0x0003FE, 0x0001FE, 0x00007E, 0x00003C, 0x00001D, 0x00000D, 0x000005,
- 0x000000, 0x000004, 0x00000C, 0x00001C, 0x00003D, 0x00003E, 0x0000FE,
- 0x0007FE, 0x001FFC, 0x003FFC, 0x003FFD, 0x007FFD, 0x01FFFE, 0x03FFFE,
- 0x03FFFF,
-};
-
-static const uint8_t huff_iid_dt0_bits[] = {
- 19, 19, 19, 20, 20, 20, 17, 15, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7,
- 9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20,
-};
-
-static const uint32_t huff_iid_dt0_codes[] = {
- 0x07FFF9, 0x07FFFA, 0x07FFFB, 0x0FFFF8, 0x0FFFF9, 0x0FFFFA, 0x01FFFD,
- 0x007FFE, 0x000FFE, 0x0003FE, 0x0000FE, 0x00003E, 0x00000E, 0x000002,
- 0x000000, 0x000006, 0x00001E, 0x00007E, 0x0001FE, 0x0007FE, 0x001FFE,
- 0x003FFE, 0x01FFFC, 0x07FFF8, 0x0FFFFB, 0x0FFFFC, 0x0FFFFD, 0x0FFFFE,
- 0x0FFFFF,
-};
-
-static const uint8_t huff_icc_df_bits[] = {
- 14, 14, 12, 10, 7, 5, 3, 1, 2, 4, 6, 8, 9, 11, 13,
-};
-
-static const uint16_t huff_icc_df_codes[] = {
- 0x3FFF, 0x3FFE, 0x0FFE, 0x03FE, 0x007E, 0x001E, 0x0006, 0x0000,
- 0x0002, 0x000E, 0x003E, 0x00FE, 0x01FE, 0x07FE, 0x1FFE,
-};
-
-static const uint8_t huff_icc_dt_bits[] = {
- 14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14,
-};
-
-static const uint16_t huff_icc_dt_codes[] = {
- 0x3FFE, 0x1FFE, 0x07FE, 0x01FE, 0x007E, 0x001E, 0x0006, 0x0000,
- 0x0002, 0x000E, 0x003E, 0x00FE, 0x03FE, 0x0FFE, 0x3FFF,
-};
-
-static const uint8_t huff_ipd_df_bits[] = {
- 1, 3, 4, 4, 4, 4, 4, 4,
-};
-
-static const uint8_t huff_ipd_df_codes[] = {
- 0x01, 0x00, 0x06, 0x04, 0x02, 0x03, 0x05, 0x07,
-};
-
-static const uint8_t huff_ipd_dt_bits[] = {
- 1, 3, 4, 5, 5, 4, 4, 3,
-};
-
-static const uint8_t huff_ipd_dt_codes[] = {
- 0x01, 0x02, 0x02, 0x03, 0x02, 0x00, 0x03, 0x03,
-};
-
-static const uint8_t huff_opd_df_bits[] = {
- 1, 3, 4, 4, 5, 5, 4, 3,
-};
-
-static const uint8_t huff_opd_df_codes[] = {
- 0x01, 0x01, 0x06, 0x04, 0x0F, 0x0E, 0x05, 0x00,
-};
-
-static const uint8_t huff_opd_dt_bits[] = {
- 1, 3, 4, 5, 5, 4, 4, 3,
-};
-
-static const uint8_t huff_opd_dt_codes[] = {
- 0x01, 0x02, 0x01, 0x07, 0x06, 0x00, 0x02, 0x03,
+#include <stdint.h>
+
+static const uint8_t huff_iid_df1_tab[][2] = {
+ /* huff_iid_df1 - 61 entries */
+ { 28, 4 }, { 32, 4 }, { 29, 3 }, { 31, 3 }, { 27, 5 },
+ { 33, 5 }, { 26, 6 }, { 34, 6 }, { 25, 7 }, { 35, 7 },
+ { 24, 8 }, { 36, 8 }, { 37, 9 }, { 40, 11 }, { 19, 12 },
+ { 41, 12 }, { 22, 10 }, { 38, 10 }, { 9, 17 }, { 51, 17 },
+ { 11, 17 }, { 49, 17 }, { 13, 16 }, { 47, 16 }, { 16, 14 },
+ { 18, 13 }, { 42, 13 }, { 44, 14 }, { 12, 17 }, { 48, 17 },
+ { 4, 18 }, { 5, 18 }, { 2, 18 }, { 3, 18 }, { 15, 15 },
+ { 21, 11 }, { 39, 11 }, { 45, 15 }, { 8, 18 }, { 52, 18 },
+ { 6, 18 }, { 7, 18 }, { 55, 18 }, { 56, 18 }, { 53, 18 },
+ { 54, 18 }, { 17, 14 }, { 43, 14 }, { 59, 18 }, { 60, 18 },
+ { 57, 18 }, { 58, 18 }, { 0, 18 }, { 1, 18 }, { 10, 18 },
+ { 50, 18 }, { 14, 16 }, { 46, 16 }, { 20, 12 }, { 23, 10 },
+ { 30, 1 },
+};
+
+static const uint8_t huff_iid_dt1_tab[][2] = {
+ /* huff_iid_dt1 - 61 entries */
+ { 31, 2 }, { 26, 7 }, { 34, 7 }, { 27, 6 }, { 33, 6 },
+ { 35, 8 }, { 24, 9 }, { 36, 9 }, { 39, 11 }, { 41, 12 },
+ { 9, 15 }, { 10, 15 }, { 48, 15 }, { 49, 15 }, { 17, 13 },
+ { 23, 10 }, { 37, 10 }, { 43, 13 }, { 11, 15 }, { 12, 15 },
+ { 4, 16 }, { 56, 16 }, { 2, 16 }, { 3, 16 }, { 59, 16 },
+ { 60, 16 }, { 57, 16 }, { 58, 16 }, { 0, 16 }, { 1, 16 },
+ { 5, 16 }, { 55, 16 }, { 6, 16 }, { 54, 16 }, { 13, 15 },
+ { 15, 14 }, { 20, 12 }, { 40, 12 }, { 22, 11 }, { 38, 11 },
+ { 45, 14 }, { 47, 15 }, { 7, 16 }, { 53, 16 }, { 18, 13 },
+ { 42, 13 }, { 16, 14 }, { 44, 14 }, { 8, 16 }, { 52, 16 },
+ { 14, 15 }, { 46, 15 }, { 50, 16 }, { 51, 16 }, { 19, 13 },
+ { 21, 12 }, { 25, 9 }, { 28, 5 }, { 32, 5 }, { 29, 3 },
+ { 30, 1 },
+};
+
+static const uint8_t huff_iid_df0_tab[][2] = {
+ /* huff_iid_df0 - 29 entries */
+ { 14, 1 }, { 15, 3 }, { 13, 3 }, { 16, 4 }, { 12, 4 },
+ { 17, 5 }, { 11, 5 }, { 10, 6 }, { 18, 6 }, { 19, 6 },
+ { 9, 7 }, { 20, 8 }, { 8, 9 }, { 7, 10 }, { 21, 11 },
+ { 22, 13 }, { 6, 13 }, { 23, 14 }, { 24, 14 }, { 5, 15 },
+ { 25, 15 }, { 4, 16 }, { 3, 17 }, { 0, 17 }, { 1, 17 },
+ { 2, 17 }, { 26, 17 }, { 27, 18 }, { 28, 18 },
+};
+
+static const uint8_t huff_iid_dt0_tab[][2] = {
+ /* huff_iid_dt0 - 29 entries */
+ { 14, 1 }, { 13, 2 }, { 15, 3 }, { 12, 4 }, { 16, 5 },
+ { 11, 6 }, { 17, 7 }, { 10, 8 }, { 18, 9 }, { 9, 10 },
+ { 19, 11 }, { 8, 12 }, { 20, 13 }, { 21, 14 }, { 7, 15 },
+ { 22, 17 }, { 6, 17 }, { 23, 19 }, { 0, 19 }, { 1, 19 },
+ { 2, 19 }, { 3, 20 }, { 4, 20 }, { 5, 20 }, { 24, 20 },
+ { 25, 20 }, { 26, 20 }, { 27, 20 }, { 28, 20 },
+};
+
+static const uint8_t huff_icc_df_tab[][2] = {
+ /* huff_icc_df - 15 entries */
+ { 7, 1 }, { 8, 2 }, { 6, 3 }, { 9, 4 }, { 5, 5 },
+ { 10, 6 }, { 4, 7 }, { 11, 8 }, { 12, 9 }, { 3, 10 },
+ { 13, 11 }, { 2, 12 }, { 14, 13 }, { 1, 14 }, { 0, 14 },
+};
+
+static const uint8_t huff_icc_dt_tab[][2] = {
+ /* huff_icc_dt - 15 entries */
+ { 7, 1 }, { 8, 2 }, { 6, 3 }, { 9, 4 }, { 5, 5 },
+ { 10, 6 }, { 4, 7 }, { 11, 8 }, { 3, 9 }, { 12, 10 },
+ { 2, 11 }, { 13, 12 }, { 1, 13 }, { 0, 14 }, { 14, 14 },
+};
+
+static const uint8_t huff_ipd_df_tab[][2] = {
+ /* huff_ipd_df - 8 entries */
+ { 1, 3 }, { 4, 4 }, { 5, 4 }, { 3, 4 }, { 6, 4 },
+ { 2, 4 }, { 7, 4 }, { 0, 1 },
+};
+
+static const uint8_t huff_ipd_dt_tab[][2] = {
+ /* huff_ipd_dt - 8 entries */
+ { 5, 4 }, { 4, 5 }, { 3, 5 }, { 2, 4 }, { 6, 4 },
+ { 1, 3 }, { 7, 3 }, { 0, 1 },
+};
+
+static const uint8_t huff_opd_df_tab[][2] = {
+ /* huff_opd_df - 8 entries */
+ { 7, 3 }, { 1, 3 }, { 3, 4 }, { 6, 4 }, { 2, 4 },
+ { 5, 5 }, { 4, 5 }, { 0, 1 },
+};
+
+static const uint8_t huff_opd_dt_tab[][2] = {
+ /* huff_opd_dt - 8 entries */
+ { 5, 4 }, { 2, 4 }, { 6, 4 }, { 4, 5 }, { 3, 5 },
+ { 1, 3 }, { 7, 3 }, { 0, 1 },
};
static const int8_t huff_offset[] = {
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 55/61] avcodec/aacps_common: Combine huffman tabels
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (52 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 54/61] avcodec/aacps_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 56/61] avcodec/aacps_common: Apply offset for VLCs during init Andreas Rheinhardt
` (6 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This allows to avoid the relocations inherent in an array
to individual tables; it also reduces padding.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacps_common.c | 27 +++++----------------------
libavcodec/aacpsdata.c | 31 +++----------------------------
2 files changed, 8 insertions(+), 50 deletions(-)
diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index 653fc38da3..7a83cbd7d6 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -288,36 +288,19 @@ err:
return bits_left;
}
-#define PS_VLC_ROW(name) \
- { name ## _tab, FF_ARRAY_ELEMS(name ## _tab) }
-
av_cold void ff_ps_init_common(void)
{
static VLCElem vlc_buf[(1544 + 832 + 1024 + 1036) +
(544 + 544) + (32 + 32 + 32 + 32)];
VLCInitState state = VLC_INIT_STATE(vlc_buf);
- // Syntax initialization
- static const struct {
- const uint8_t (*vlc_tab)[2];
- const unsigned int table_elems;
- } ps_tmp[] = {
- PS_VLC_ROW(huff_iid_df1),
- PS_VLC_ROW(huff_iid_dt1),
- PS_VLC_ROW(huff_iid_df0),
- PS_VLC_ROW(huff_iid_dt0),
- PS_VLC_ROW(huff_icc_df),
- PS_VLC_ROW(huff_icc_dt),
- PS_VLC_ROW(huff_ipd_df),
- PS_VLC_ROW(huff_ipd_dt),
- PS_VLC_ROW(huff_opd_df),
- PS_VLC_ROW(huff_opd_dt),
- };
+ const uint8_t (*tab)[2] = aacps_huff_tabs;
for (int i = 0; i < FF_ARRAY_ELEMS(vlc_ps); i++) {
vlc_ps[i] =
- ff_vlc_init_tables_from_lengths(&state, i <= 5 ? 9 : 5, ps_tmp[i].table_elems,
- &ps_tmp[i].vlc_tab[0][1], 2,
- &ps_tmp[i].vlc_tab[0][0], 2, 1,
+ ff_vlc_init_tables_from_lengths(&state, i <= 5 ? 9 : 5, huff_sizes[i],
+ &tab[0][1], 2,
+ &tab[0][0], 2, 1,
0, 0);
+ tab += huff_sizes[i];
}
}
diff --git a/libavcodec/aacpsdata.c b/libavcodec/aacpsdata.c
index 8241346b0d..6885b386c0 100644
--- a/libavcodec/aacpsdata.c
+++ b/libavcodec/aacpsdata.c
@@ -21,7 +21,9 @@
#include <stdint.h>
-static const uint8_t huff_iid_df1_tab[][2] = {
+static const uint8_t huff_sizes[] = { 61, 61, 29, 29, 15, 15, 8, 8, 8, 8 };
+
+static const uint8_t aacps_huff_tabs[][2] = {
/* huff_iid_df1 - 61 entries */
{ 28, 4 }, { 32, 4 }, { 29, 3 }, { 31, 3 }, { 27, 5 },
{ 33, 5 }, { 26, 6 }, { 34, 6 }, { 25, 7 }, { 35, 7 },
@@ -36,9 +38,6 @@ static const uint8_t huff_iid_df1_tab[][2] = {
{ 57, 18 }, { 58, 18 }, { 0, 18 }, { 1, 18 }, { 10, 18 },
{ 50, 18 }, { 14, 16 }, { 46, 16 }, { 20, 12 }, { 23, 10 },
{ 30, 1 },
-};
-
-static const uint8_t huff_iid_dt1_tab[][2] = {
/* huff_iid_dt1 - 61 entries */
{ 31, 2 }, { 26, 7 }, { 34, 7 }, { 27, 6 }, { 33, 6 },
{ 35, 8 }, { 24, 9 }, { 36, 9 }, { 39, 11 }, { 41, 12 },
@@ -53,9 +52,6 @@ static const uint8_t huff_iid_dt1_tab[][2] = {
{ 14, 15 }, { 46, 15 }, { 50, 16 }, { 51, 16 }, { 19, 13 },
{ 21, 12 }, { 25, 9 }, { 28, 5 }, { 32, 5 }, { 29, 3 },
{ 30, 1 },
-};
-
-static const uint8_t huff_iid_df0_tab[][2] = {
/* huff_iid_df0 - 29 entries */
{ 14, 1 }, { 15, 3 }, { 13, 3 }, { 16, 4 }, { 12, 4 },
{ 17, 5 }, { 11, 5 }, { 10, 6 }, { 18, 6 }, { 19, 6 },
@@ -63,9 +59,6 @@ static const uint8_t huff_iid_df0_tab[][2] = {
{ 22, 13 }, { 6, 13 }, { 23, 14 }, { 24, 14 }, { 5, 15 },
{ 25, 15 }, { 4, 16 }, { 3, 17 }, { 0, 17 }, { 1, 17 },
{ 2, 17 }, { 26, 17 }, { 27, 18 }, { 28, 18 },
-};
-
-static const uint8_t huff_iid_dt0_tab[][2] = {
/* huff_iid_dt0 - 29 entries */
{ 14, 1 }, { 13, 2 }, { 15, 3 }, { 12, 4 }, { 16, 5 },
{ 11, 6 }, { 17, 7 }, { 10, 8 }, { 18, 9 }, { 9, 10 },
@@ -73,41 +66,23 @@ static const uint8_t huff_iid_dt0_tab[][2] = {
{ 22, 17 }, { 6, 17 }, { 23, 19 }, { 0, 19 }, { 1, 19 },
{ 2, 19 }, { 3, 20 }, { 4, 20 }, { 5, 20 }, { 24, 20 },
{ 25, 20 }, { 26, 20 }, { 27, 20 }, { 28, 20 },
-};
-
-static const uint8_t huff_icc_df_tab[][2] = {
/* huff_icc_df - 15 entries */
{ 7, 1 }, { 8, 2 }, { 6, 3 }, { 9, 4 }, { 5, 5 },
{ 10, 6 }, { 4, 7 }, { 11, 8 }, { 12, 9 }, { 3, 10 },
{ 13, 11 }, { 2, 12 }, { 14, 13 }, { 1, 14 }, { 0, 14 },
-};
-
-static const uint8_t huff_icc_dt_tab[][2] = {
/* huff_icc_dt - 15 entries */
{ 7, 1 }, { 8, 2 }, { 6, 3 }, { 9, 4 }, { 5, 5 },
{ 10, 6 }, { 4, 7 }, { 11, 8 }, { 3, 9 }, { 12, 10 },
{ 2, 11 }, { 13, 12 }, { 1, 13 }, { 0, 14 }, { 14, 14 },
-};
-
-static const uint8_t huff_ipd_df_tab[][2] = {
/* huff_ipd_df - 8 entries */
{ 1, 3 }, { 4, 4 }, { 5, 4 }, { 3, 4 }, { 6, 4 },
{ 2, 4 }, { 7, 4 }, { 0, 1 },
-};
-
-static const uint8_t huff_ipd_dt_tab[][2] = {
/* huff_ipd_dt - 8 entries */
{ 5, 4 }, { 4, 5 }, { 3, 5 }, { 2, 4 }, { 6, 4 },
{ 1, 3 }, { 7, 3 }, { 0, 1 },
-};
-
-static const uint8_t huff_opd_df_tab[][2] = {
/* huff_opd_df - 8 entries */
{ 7, 3 }, { 1, 3 }, { 3, 4 }, { 6, 4 }, { 2, 4 },
{ 5, 5 }, { 4, 5 }, { 0, 1 },
-};
-
-static const uint8_t huff_opd_dt_tab[][2] = {
/* huff_opd_dt - 8 entries */
{ 5, 4 }, { 2, 4 }, { 6, 4 }, { 4, 5 }, { 3, 5 },
{ 1, 3 }, { 7, 3 }, { 0, 1 },
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 56/61] avcodec/aacps_common: Apply offset for VLCs during init
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (53 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 55/61] avcodec/aacps_common: Combine huffman tabels Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 57/61] avcodec/mpegaudiodec_common: Avoid superfluous VLC structures Andreas Rheinhardt
` (5 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This avoids having to apply it later after every get_vlc2().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/aacps_common.c | 14 +++++++-------
libavcodec/aacpsdata.c | 6 +++---
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index 7a83cbd7d6..74fa005aaf 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -60,7 +60,7 @@ static const int huff_iid[] = {
static const VLCElem *vlc_ps[10];
-#define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION, NB_BITS, MAX_DEPTH) \
+#define READ_PAR_DATA(PAR, MASK, ERR_CONDITION, NB_BITS, MAX_DEPTH) \
/** \
* Read Inter-channel Intensity Difference/Inter-Channel Coherence/ \
* Inter-channel Phase Difference/Overall Phase Difference parameters from the \
@@ -82,7 +82,7 @@ static int read_ ## PAR ## _data(void *logctx, GetBitContext *gb, PSCommonContex
int e_prev = e ? e - 1 : ps->num_env_old - 1; \
e_prev = FFMAX(e_prev, 0); \
for (b = 0; b < num; b++) { \
- int val = PAR[e_prev][b] + get_vlc2(gb, vlc_table, NB_BITS, MAX_DEPTH) - OFFSET; \
+ int val = PAR[e_prev][b] + get_vlc2(gb, vlc_table, NB_BITS, MAX_DEPTH); \
if (MASK) val &= MASK; \
PAR[e][b] = val; \
if (ERR_CONDITION) \
@@ -91,7 +91,7 @@ static int read_ ## PAR ## _data(void *logctx, GetBitContext *gb, PSCommonContex
} else { \
int val = 0; \
for (b = 0; b < num; b++) { \
- val += get_vlc2(gb, vlc_table, NB_BITS, MAX_DEPTH) - OFFSET; \
+ val += get_vlc2(gb, vlc_table, NB_BITS, MAX_DEPTH); \
if (MASK) val &= MASK; \
PAR[e][b] = val; \
if (ERR_CONDITION) \
@@ -104,9 +104,9 @@ err: \
return AVERROR_INVALIDDATA; \
}
-READ_PAR_DATA(iid, huff_offset[table_idx], 0, FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant, 9, 3)
-READ_PAR_DATA(icc, huff_offset[table_idx], 0, ps->icc_par[e][b] > 7U, 9, 2)
-READ_PAR_DATA(ipdopd, 0, 0x07, 0, 5, 1)
+READ_PAR_DATA(iid, 0, FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant, 9, 3)
+READ_PAR_DATA(icc, 0, ps->icc_par[e][b] > 7U, 9, 2)
+READ_PAR_DATA(ipdopd, 0x07, 0, 5, 1)
static int ps_read_extension_data(GetBitContext *gb, PSCommonContext *ps,
int ps_extension_id)
@@ -300,7 +300,7 @@ av_cold void ff_ps_init_common(void)
ff_vlc_init_tables_from_lengths(&state, i <= 5 ? 9 : 5, huff_sizes[i],
&tab[0][1], 2,
&tab[0][0], 2, 1,
- 0, 0);
+ huff_offset[i], 0);
tab += huff_sizes[i];
}
}
diff --git a/libavcodec/aacpsdata.c b/libavcodec/aacpsdata.c
index 6885b386c0..8c79a154e2 100644
--- a/libavcodec/aacpsdata.c
+++ b/libavcodec/aacpsdata.c
@@ -89,9 +89,9 @@ static const uint8_t aacps_huff_tabs[][2] = {
};
static const int8_t huff_offset[] = {
- 30, 30,
- 14, 14,
- 7, 7,
+ -30, -30,
+ -14, -14,
+ -7, -7,
0, 0,
0, 0,
};
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 57/61] avcodec/mpegaudiodec_common: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (54 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 56/61] avcodec/aacps_common: Apply offset for VLCs during init Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 58/61] avcodec/mpeg12: Avoid unnecessary " Andreas Rheinhardt
` (4 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For some VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegaudiodata.h | 2 +-
libavcodec/mpegaudiodec_common.c | 16 +++++++---------
libavcodec/mpegaudiodec_template.c | 5 +++--
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h
index a4148a1ffe..fbad67a0b3 100644
--- a/libavcodec/mpegaudiodata.h
+++ b/libavcodec/mpegaudiodata.h
@@ -53,7 +53,7 @@ extern uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
#endif
/* VLCs for decoding layer 3 huffman tables */
-extern VLC ff_huff_vlc[16];
+extern const VLCElem *ff_huff_vlc[16];
extern VLC ff_huff_quad_vlc[2];
/* layer3 scale factor size */
diff --git a/libavcodec/mpegaudiodec_common.c b/libavcodec/mpegaudiodec_common.c
index 3a60b03e9e..6446d08967 100644
--- a/libavcodec/mpegaudiodec_common.c
+++ b/libavcodec/mpegaudiodec_common.c
@@ -64,7 +64,7 @@ const uint8_t ff_lsf_nsf_table[6][3][4] = {
};
/* mpegaudio layer 3 huffman tables */
-VLC ff_huff_vlc[16];
+const VLCElem *ff_huff_vlc[16];
static VLCElem huff_vlc_tables[128 + 128 + 128 + 130 + 128 + 154 + 166 + 142 +
204 + 190 + 170 + 542 + 460 + 662 + 414];
VLC ff_huff_quad_vlc[2];
@@ -401,6 +401,7 @@ const uint8_t ff_mpa_pretab[2][22] = {
static av_cold void mpegaudiodec_common_init_static(void)
{
+ VLCInitState state = VLC_INIT_STATE(huff_vlc_tables);
const uint8_t *huff_sym = mpa_huffsymbols, *huff_lens = mpa_hufflens;
int offset;
@@ -414,7 +415,6 @@ static av_cold void mpegaudiodec_common_init_static(void)
}
/* huffman decode tables */
- offset = 0;
for (int i = 0; i < 15;) {
uint16_t tmp_symbols[256];
int nb_codes_minus_one = mpa_huff_sizes_minus_one[i];
@@ -426,16 +426,14 @@ static av_cold void mpegaudiodec_common_init_static(void)
tmp_symbols[j] = high << 1 | ((high && low) << 4) | low;
}
- ff_huff_vlc[++i].table = huff_vlc_tables + offset;
- ff_huff_vlc[i].table_allocated = FF_ARRAY_ELEMS(huff_vlc_tables) - offset;
- ff_vlc_init_from_lengths(&ff_huff_vlc[i], 7, j,
- huff_lens, 1, tmp_symbols, 2, 2,
- 0, VLC_INIT_STATIC_OVERLONG, NULL);
- offset += ff_huff_vlc[i].table_size;
+ ff_huff_vlc[++i] = ff_vlc_init_tables_from_lengths(&state, 7, j,
+ huff_lens, 1,
+ tmp_symbols, 2, 2,
+ 0, 0);
huff_lens += j;
huff_sym += j;
}
- av_assert0(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
+ av_assert1(state.size == 0);
offset = 0;
for (int i = 0; i < 2; i++) {
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 3e4ee79be6..c227604107 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -760,6 +760,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
/* low frequencies (called big values) */
s_index = 0;
for (i = 0; i < 3; i++) {
+ const VLCElem *vlctab;
int j, k, l, linbits;
j = g->region_size[i];
if (j == 0)
@@ -768,13 +769,13 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
k = g->table_select[i];
l = ff_mpa_huff_data[k][0];
linbits = ff_mpa_huff_data[k][1];
- vlc = &ff_huff_vlc[l];
if (!l) {
memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * 2 * j);
s_index += 2 * j;
continue;
}
+ vlctab = ff_huff_vlc[l];
/* read huffcode and compute each couple */
for (; j > 0; j--) {
@@ -787,7 +788,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
if (pos >= end_pos)
break;
}
- y = get_vlc2(&s->gb, vlc->table, 7, 3);
+ y = get_vlc2(&s->gb, vlctab, 7, 3);
if (!y) {
g->sb_hybrid[s_index ] =
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 58/61] avcodec/mpeg12: Avoid unnecessary VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (55 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 57/61] avcodec/mpegaudiodec_common: Avoid superfluous VLC structures Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 59/61] avcodec/wmaprodec: Avoid superfluous " Andreas Rheinhardt
` (3 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying tables directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12.c | 58 +++++++++++++++++++++---------------------
libavcodec/mpeg12dec.c | 12 ++++-----
libavcodec/mpeg12dec.h | 4 +--
libavcodec/mpeg12vlc.h | 14 +++++-----
4 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 70033ec725..8d88820c46 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -115,43 +115,43 @@ void ff_mpeg1_clean_buffers(MpegEncContext *s)
/******************************************/
/* decoding */
-VLC ff_mv_vlc;
+VLCElem ff_mv_vlc[266];
-VLC ff_dc_lum_vlc;
-VLC ff_dc_chroma_vlc;
+VLCElem ff_dc_lum_vlc[512];
+VLCElem ff_dc_chroma_vlc[514];
-VLC ff_mbincr_vlc;
-VLC ff_mb_ptype_vlc;
-VLC ff_mb_btype_vlc;
-VLC ff_mb_pat_vlc;
+VLCElem ff_mbincr_vlc[538];
+VLCElem ff_mb_ptype_vlc[64];
+VLCElem ff_mb_btype_vlc[64];
+VLCElem ff_mb_pat_vlc[512];
RL_VLC_ELEM ff_mpeg1_rl_vlc[680];
RL_VLC_ELEM ff_mpeg2_rl_vlc[674];
static av_cold void mpeg12_init_vlcs(void)
{
- VLC_INIT_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
- ff_mpeg12_vlc_dc_lum_bits, 1, 1,
- ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
- VLC_INIT_STATIC(&ff_dc_chroma_vlc, DC_VLC_BITS, 12,
- ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
- ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514);
- VLC_INIT_STATIC(&ff_mv_vlc, MV_VLC_BITS, 17,
- &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
- &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 266);
- VLC_INIT_STATIC(&ff_mbincr_vlc, MBINCR_VLC_BITS, 36,
- &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
- &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538);
- VLC_INIT_STATIC(&ff_mb_pat_vlc, MB_PAT_VLC_BITS, 64,
- &ff_mpeg12_mbPatTable[0][1], 2, 1,
- &ff_mpeg12_mbPatTable[0][0], 2, 1, 512);
-
- VLC_INIT_STATIC(&ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
- &table_mb_ptype[0][1], 2, 1,
- &table_mb_ptype[0][0], 2, 1, 64);
- VLC_INIT_STATIC(&ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
- &table_mb_btype[0][1], 2, 1,
- &table_mb_btype[0][0], 2, 1, 64);
+ VLC_INIT_STATIC_TABLE(ff_dc_lum_vlc, DC_VLC_BITS, 12,
+ ff_mpeg12_vlc_dc_lum_bits, 1, 1,
+ ff_mpeg12_vlc_dc_lum_code, 2, 2, 0);
+ VLC_INIT_STATIC_TABLE(ff_dc_chroma_vlc, DC_VLC_BITS, 12,
+ ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
+ ff_mpeg12_vlc_dc_chroma_code, 2, 2, 0);
+ VLC_INIT_STATIC_TABLE(ff_mv_vlc, MV_VLC_BITS, 17,
+ &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
+ &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(ff_mbincr_vlc, MBINCR_VLC_BITS, 36,
+ &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
+ &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(ff_mb_pat_vlc, MB_PAT_VLC_BITS, 64,
+ &ff_mpeg12_mbPatTable[0][1], 2, 1,
+ &ff_mpeg12_mbPatTable[0][0], 2, 1, 0);
+
+ VLC_INIT_STATIC_TABLE(ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
+ &table_mb_ptype[0][1], 2, 1,
+ &table_mb_ptype[0][0], 2, 1, 0);
+ VLC_INIT_STATIC_TABLE(ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
+ &table_mb_btype[0][1], 2, 1,
+ &table_mb_btype[0][0], 2, 1, 0);
ff_init_2d_vlc_rl(ff_mpeg1_vlc_table, ff_mpeg1_rl_vlc, ff_mpeg12_run,
ff_mpeg12_level, MPEG12_RL_NB_ELEMS,
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 92ef6944fa..5f7ff4bb7a 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -117,7 +117,7 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
{
int code, sign, val, shift;
- code = get_vlc2(&s->gb, ff_mv_vlc.table, MV_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, ff_mv_vlc, MV_VLC_BITS, 2);
if (code == 0)
return pred;
if (code < 0)
@@ -710,7 +710,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
}
break;
case AV_PICTURE_TYPE_P:
- mb_type = get_vlc2(&s->gb, ff_mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
+ mb_type = get_vlc2(&s->gb, ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 1);
if (mb_type < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"Invalid mb type in P-frame at %d %d\n", s->mb_x, s->mb_y);
@@ -719,7 +719,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
mb_type = ptype2mb_type[mb_type];
break;
case AV_PICTURE_TYPE_B:
- mb_type = get_vlc2(&s->gb, ff_mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
+ mb_type = get_vlc2(&s->gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
if (mb_type < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"Invalid mb type in B-frame at %d %d\n", s->mb_x, s->mb_y);
@@ -981,7 +981,7 @@ static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
if (HAS_CBP(mb_type)) {
s->bdsp.clear_blocks(s->block[0]);
- cbp = get_vlc2(&s->gb, ff_mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
+ cbp = get_vlc2(&s->gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
if (mb_block_count > 6) {
cbp *= 1 << mb_block_count - 6;
cbp |= get_bits(&s->gb, mb_block_count - 6);
@@ -1723,7 +1723,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
skip_bits1(&s->gb);
} else {
while (get_bits_left(&s->gb) > 0) {
- int code = get_vlc2(&s->gb, ff_mbincr_vlc.table,
+ int code = get_vlc2(&s->gb, ff_mbincr_vlc,
MBINCR_VLC_BITS, 2);
if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
@@ -1892,7 +1892,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
/* read increment again */
s->mb_skip_run = 0;
for (;;) {
- int code = get_vlc2(&s->gb, ff_mbincr_vlc.table,
+ int code = get_vlc2(&s->gb, ff_mbincr_vlc,
MBINCR_VLC_BITS, 2);
if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
diff --git a/libavcodec/mpeg12dec.h b/libavcodec/mpeg12dec.h
index 4c015d3096..4641179149 100644
--- a/libavcodec/mpeg12dec.h
+++ b/libavcodec/mpeg12dec.h
@@ -30,9 +30,9 @@ static inline int decode_dc(GetBitContext *gb, int component)
int code, diff;
if (component == 0) {
- code = get_vlc2(gb, ff_dc_lum_vlc.table, DC_VLC_BITS, 2);
+ code = get_vlc2(gb, ff_dc_lum_vlc, DC_VLC_BITS, 2);
} else {
- code = get_vlc2(gb, ff_dc_chroma_vlc.table, DC_VLC_BITS, 2);
+ code = get_vlc2(gb, ff_dc_chroma_vlc, DC_VLC_BITS, 2);
}
if (code == 0) {
diff = 0;
diff --git a/libavcodec/mpeg12vlc.h b/libavcodec/mpeg12vlc.h
index 3ed35968f6..53f53947c3 100644
--- a/libavcodec/mpeg12vlc.h
+++ b/libavcodec/mpeg12vlc.h
@@ -39,13 +39,13 @@
#define MB_PTYPE_VLC_BITS 6
#define MB_BTYPE_VLC_BITS 6
-extern VLC ff_dc_lum_vlc;
-extern VLC ff_dc_chroma_vlc;
-extern VLC ff_mbincr_vlc;
-extern VLC ff_mb_ptype_vlc;
-extern VLC ff_mb_btype_vlc;
-extern VLC ff_mb_pat_vlc;
-extern VLC ff_mv_vlc;
+extern VLCElem ff_dc_lum_vlc[];
+extern VLCElem ff_dc_chroma_vlc[];
+extern VLCElem ff_mbincr_vlc[];
+extern VLCElem ff_mb_ptype_vlc[];
+extern VLCElem ff_mb_btype_vlc[];
+extern VLCElem ff_mb_pat_vlc[];
+extern VLCElem ff_mv_vlc[];
void ff_mpeg12_init_vlcs(void);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 59/61] avcodec/wmaprodec: Avoid superfluous VLC structures
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (56 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 58/61] avcodec/mpeg12: Avoid unnecessary " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 60/61] avcodec/wmavoice: Avoid unnecessary VLC structure Andreas Rheinhardt
` (2 subsequent siblings)
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
For all VLCs here, the number of bits of the VLC is write-only,
because it is hardcoded at the call site. Therefore one can replace
these VLC structures with the only thing that is actually used:
The pointer to the VLCElem table. And in most cases one can even
avoid this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/wma.c | 4 +--
libavcodec/wma.h | 2 +-
libavcodec/wmadec.c | 2 +-
libavcodec/wmaprodec.c | 73 ++++++++++++++++++++++--------------------
4 files changed, 43 insertions(+), 38 deletions(-)
diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index 3b4d049a83..5eacf230fa 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -424,7 +424,7 @@ unsigned int ff_wma_get_large_val(GetBitContext *gb)
* @return 0 on success, -1 otherwise
*/
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
- VLC *vlc, const float *level_table,
+ const VLCElem *vlc, const float *level_table,
const uint16_t *run_table, int version,
WMACoef *ptr, int offset, int num_coefs,
int block_len, int frame_len_bits,
@@ -435,7 +435,7 @@ int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
uint32_t *iptr = (uint32_t *) ptr;
const unsigned int coef_mask = block_len - 1;
for (; offset < num_coefs; offset++) {
- code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
+ code = get_vlc2(gb, vlc, VLCBITS, VLCMAX);
if (code > 1) {
/** normal code */
offset += run_table[code];
diff --git a/libavcodec/wma.h b/libavcodec/wma.h
index 5dc604154d..3d0d872ea3 100644
--- a/libavcodec/wma.h
+++ b/libavcodec/wma.h
@@ -155,7 +155,7 @@ int ff_wma_total_gain_to_bits(int total_gain);
int ff_wma_end(AVCodecContext *avctx);
unsigned int ff_wma_get_large_val(GetBitContext *gb);
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
- VLC *vlc, const float *level_table,
+ const VLCElem *vlc, const float *level_table,
const uint16_t *run_table, int version,
WMACoef *ptr, int offset, int num_coefs,
int block_len, int frame_len_bits,
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index ab48e28ebc..3427e482dc 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -616,7 +616,7 @@ static int wma_decode_block(WMACodecContext *s)
* there is potentially less energy there */
tindex = (ch == 1 && s->ms_stereo);
memset(ptr, 0, s->block_len * sizeof(WMACoef));
- ret = ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex],
+ ret = ff_wma_run_level_decode(s->avctx, &s->gb, s->coef_vlc[tindex].table,
s->level_table[tindex], s->run_table[tindex],
0, ptr, 0, nb_coefs[ch],
s->block_len, s->frame_len_bits, coef_nb_bits);
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 61b86ad6d1..65b269adda 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -132,12 +132,12 @@
#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
-static VLC sf_vlc; ///< scale factor DPCM vlc
-static VLC sf_rl_vlc; ///< scale factor run length vlc
-static VLC vec4_vlc; ///< 4 coefficients per symbol
-static VLC vec2_vlc; ///< 2 coefficients per symbol
-static VLC vec1_vlc; ///< 1 coefficient per symbol
-static VLC coef_vlc[2]; ///< coefficient run length vlc codes
+static VLCElem sf_vlc[616]; ///< scale factor DPCM vlc
+static VLCElem sf_rl_vlc[1406]; ///< scale factor run length vlc
+static VLCElem vec4_vlc[604]; ///< 4 coefficients per symbol
+static VLCElem vec2_vlc[562]; ///< 2 coefficients per symbol
+static VLCElem vec1_vlc[562]; ///< 1 coefficient per symbol
+static const VLCElem *coef_vlc[2]; ///< coefficient run length vlc codes
static float sin64[33]; ///< sine table for decorrelation
/**
@@ -320,27 +320,32 @@ static av_cold int get_rate(AVCodecContext *avctx)
static av_cold void decode_init_static(void)
{
- VLC_INIT_STATIC_FROM_LENGTHS(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE,
- &scale_table[0][1], 2,
- &scale_table[0][0], 2, 1, -60, 0, 616);
- VLC_INIT_STATIC_FROM_LENGTHS(&sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE,
- &scale_rl_table[0][1], 2,
- &scale_rl_table[0][0], 2, 1, 0, 0, 1406);
- VLC_INIT_STATIC_FROM_LENGTHS(&coef_vlc[0], VLCBITS, HUFF_COEF0_SIZE,
- coef0_lens, 1,
- coef0_syms, 2, 2, 0, 0, 2108);
- VLC_INIT_STATIC_FROM_LENGTHS(&coef_vlc[1], VLCBITS, HUFF_COEF1_SIZE,
+ static VLCElem vlc_buf[2108 + 3912];
+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
+
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE,
+ &scale_table[0][1], 2,
+ &scale_table[0][0], 2, 1, -60, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE,
+ &scale_rl_table[0][1], 2,
+ &scale_rl_table[0][0], 2, 1, 0, 0);
+ coef_vlc[0] =
+ ff_vlc_init_tables_from_lengths(&state, VLCBITS, HUFF_COEF0_SIZE,
+ coef0_lens, 1,
+ coef0_syms, 2, 2, 0, 0);
+ coef_vlc[1] =
+ ff_vlc_init_tables_from_lengths(&state, VLCBITS, HUFF_COEF1_SIZE,
&coef1_table[0][1], 2,
- &coef1_table[0][0], 2, 1, 0, 0, 3912);
- VLC_INIT_STATIC_FROM_LENGTHS(&vec4_vlc, VLCBITS, HUFF_VEC4_SIZE,
- vec4_lens, 1,
- vec4_syms, 2, 2, -1, 0, 604);
- VLC_INIT_STATIC_FROM_LENGTHS(&vec2_vlc, VLCBITS, HUFF_VEC2_SIZE,
- &vec2_table[0][1], 2,
- &vec2_table[0][0], 2, 1, -1, 0, 562);
- VLC_INIT_STATIC_FROM_LENGTHS(&vec1_vlc, VLCBITS, HUFF_VEC1_SIZE,
- &vec1_table[0][1], 2,
- &vec1_table[0][0], 2, 1, 0, 0, 562);
+ &coef1_table[0][0], 2, 1, 0, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vec4_vlc, VLCBITS, HUFF_VEC4_SIZE,
+ vec4_lens, 1,
+ vec4_syms, 2, 2, -1, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vec2_vlc, VLCBITS, HUFF_VEC2_SIZE,
+ &vec2_table[0][1], 2,
+ &vec2_table[0][0], 2, 1, -1, 0);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vec1_vlc, VLCBITS, HUFF_VEC1_SIZE,
+ &vec1_table[0][1], 2,
+ &vec1_table[0][0], 2, 1, 0, 0);
/** calculate sine values for the decorrelation matrix */
for (int i = 0; i < 33; i++)
@@ -929,7 +934,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
0x41400000, 0x41500000, 0x41600000, 0x41700000,
};
int vlctable;
- VLC* vlc;
+ const VLCElem *vlc;
WMAProChannelCtx* ci = &s->channel[c];
int rl_mode = 0;
int cur_coeff = 0;
@@ -940,7 +945,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
ff_dlog(s->avctx, "decode coefficients for channel %i\n", c);
vlctable = get_bits1(&s->gb);
- vlc = &coef_vlc[vlctable];
+ vlc = coef_vlc[vlctable];
if (vlctable) {
run = coef1_run;
@@ -958,17 +963,17 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
int i;
unsigned int idx;
- idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);
+ idx = get_vlc2(&s->gb, vec4_vlc, VLCBITS, VEC4MAXDEPTH);
if ((int)idx < 0) {
for (i = 0; i < 4; i += 2) {
- idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);
+ idx = get_vlc2(&s->gb, vec2_vlc, VLCBITS, VEC2MAXDEPTH);
if ((int)idx < 0) {
uint32_t v0, v1;
- v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
+ v0 = get_vlc2(&s->gb, vec1_vlc, VLCBITS, VEC1MAXDEPTH);
if (v0 == HUFF_VEC1_SIZE - 1)
v0 += ff_wma_get_large_val(&s->gb);
- v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
+ v1 = get_vlc2(&s->gb, vec1_vlc, VLCBITS, VEC1MAXDEPTH);
if (v1 == HUFF_VEC1_SIZE - 1)
v1 += ff_wma_get_large_val(&s->gb);
vals[i ] = av_float2int(v0);
@@ -1059,7 +1064,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1;
val = 45 / s->channel[c].scale_factor_step;
for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) {
- val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH);
+ val += get_vlc2(&s->gb, sf_vlc, SCALEVLCBITS, SCALEMAXDEPTH);
*sf = val;
}
} else {
@@ -1071,7 +1076,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
int val;
int sign;
- idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH);
+ idx = get_vlc2(&s->gb, sf_rl_vlc, VLCBITS, SCALERLMAXDEPTH);
if (!idx) {
uint32_t code = get_bits(&s->gb, 14);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 60/61] avcodec/wmavoice: Avoid unnecessary VLC structure
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (57 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 59/61] avcodec/wmaprodec: Avoid superfluous " Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 61/61] avcodec/vlc: Remove unused macros Andreas Rheinhardt
2023-10-30 23:08 ` [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Everything besides VLC.table is basically write-only
and even VLC.table can be removed by accessing the
underlying table directly.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/wmavoice.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index dd7cc64d63..4e93aadab2 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -60,7 +60,7 @@
/**
* Frame type VLC coding.
*/
-static VLC frame_type_vlc;
+static VLCElem frame_type_vlc[132];
/**
* Adaptive codebook types.
@@ -320,9 +320,9 @@ static av_cold void wmavoice_init_static_data(void)
14, 14, 14, 14
};
- VLC_INIT_STATIC_FROM_LENGTHS(&frame_type_vlc, VLC_NBITS,
- FF_ARRAY_ELEMS(bits), bits,
- 1, NULL, 0, 0, 0, 0, 132);
+ VLC_INIT_STATIC_TABLE_FROM_LENGTHS(frame_type_vlc, VLC_NBITS,
+ FF_ARRAY_ELEMS(bits), bits,
+ 1, NULL, 0, 0, 0, 0);
}
static av_cold void wmavoice_flush(AVCodecContext *ctx)
@@ -1503,7 +1503,7 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx,
int pitch[MAX_BLOCKS], av_uninit(last_block_pitch);
/* Parse frame type ("frame header"), see frame_descs */
- int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)], block_nsamples;
+ int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc, 6, 3)], block_nsamples;
if (bd_idx < 0) {
av_log(ctx, AV_LOG_ERROR,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* [FFmpeg-devel] [PATCH 61/61] avcodec/vlc: Remove unused macros
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (58 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 60/61] avcodec/wmavoice: Avoid unnecessary VLC structure Andreas Rheinhardt
@ 2023-09-26 22:17 ` Andreas Rheinhardt
2023-10-30 23:08 ` [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-26 22:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vlc.h | 41 -----------------------------------------
1 file changed, 41 deletions(-)
diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h
index 679666801a..0cc106c499 100644
--- a/libavcodec/vlc.h
+++ b/libavcodec/vlc.h
@@ -185,47 +185,6 @@ void ff_vlc_free(VLC *vlc);
#define VLC_INIT_OUTPUT_LE 8
#define VLC_INIT_LE (VLC_INIT_INPUT_LE | VLC_INIT_OUTPUT_LE)
-#define VLC_INIT_CUSTOM_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \
- h, i, j, flags, static_size) \
- do { \
- static VLCElem table[static_size]; \
- (vlc)->table = table; \
- (vlc)->table_allocated = static_size; \
- ff_vlc_init_sparse(vlc, bits, a, b, c, d, e, f, g, h, i, j, \
- flags | VLC_INIT_USE_STATIC); \
- } while (0)
-
-#define VLC_INIT_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \
- VLC_INIT_CUSTOM_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \
- h, i, j, 0, static_size)
-
-#define VLC_INIT_LE_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size) \
- VLC_INIT_CUSTOM_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \
- h, i, j, VLC_INIT_LE, static_size)
-
-#define VLC_INIT_CUSTOM_STATIC(vlc, bits, a, b, c, d, e, f, g, flags, static_size) \
- VLC_INIT_CUSTOM_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, \
- NULL, 0, 0, flags, static_size)
-
-#define VLC_INIT_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \
- VLC_INIT_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, NULL, 0, 0, static_size)
-
-#define VLC_INIT_LE_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size) \
- VLC_INIT_LE_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, NULL, 0, 0, static_size)
-
-#define VLC_INIT_STATIC_FROM_LENGTHS(vlc, bits, nb_codes, lens, len_wrap, \
- symbols, symbols_wrap, symbols_size, \
- offset, flags, static_size) \
- do { \
- static VLCElem table[static_size]; \
- (vlc)->table = table; \
- (vlc)->table_allocated = static_size; \
- ff_vlc_init_from_lengths(vlc, bits, nb_codes, lens, len_wrap, \
- symbols, symbols_wrap, symbols_size, \
- offset, flags | VLC_INIT_USE_STATIC, \
- NULL); \
- } while (0)
-
/**
* For static VLCs, the number of bits can often be hardcoded
* at each get_vlc2() callsite. Then using a full VLC would be uneconomical,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: Avoid unnecessary VLC structure
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: " Andreas Rheinhardt
@ 2023-09-27 23:20 ` Michael Niedermayer
2023-09-27 23:44 ` Andreas Rheinhardt
0 siblings, 1 reply; 64+ messages in thread
From: Michael Niedermayer @ 2023-09-27 23:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 826 bytes --]
On Wed, Sep 27, 2023 at 12:17:00AM +0200, Andreas Rheinhardt wrote:
> Everything besides VLC.table is basically write-only
> and only VLC.table needs to be retained.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/mobiclip.c | 41 ++++++++++++++++++-----------------------
> 1 file changed, 18 insertions(+), 23 deletions(-)
This produces (vissible) difference in some files
for example https://samples.ffmpeg.org/game-formats/moflex/B7.moflex
(this doesnt seem to decode correctly before either but it looks
worse here after this change)
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: Avoid unnecessary VLC structure
2023-09-27 23:20 ` Michael Niedermayer
@ 2023-09-27 23:44 ` Andreas Rheinhardt
0 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-09-27 23:44 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Wed, Sep 27, 2023 at 12:17:00AM +0200, Andreas Rheinhardt wrote:
>> Everything besides VLC.table is basically write-only
>> and only VLC.table needs to be retained.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>> libavcodec/mobiclip.c | 41 ++++++++++++++++++-----------------------
>> 1 file changed, 18 insertions(+), 23 deletions(-)
>
> This produces (vissible) difference in some files
>
> for example https://samples.ffmpeg.org/game-formats/moflex/B7.moflex
> (this doesnt seem to decode correctly before either but it looks
> worse here after this change)
>
Correct, I am initializing rl_vlc[1} with the wrong symbols table.
Thanks for spotting this.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
` (59 preceding siblings ...)
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 61/61] avcodec/vlc: Remove unused macros Andreas Rheinhardt
@ 2023-10-30 23:08 ` Andreas Rheinhardt
60 siblings, 0 replies; 64+ messages in thread
From: Andreas Rheinhardt @ 2023-10-30 23:08 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> 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>
> ---
> libavcodec/vlc.c | 68 +++++++++++++++++++++++++++++++
> libavcodec/vlc.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 170 insertions(+)
>
> diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
> index 21b9fffe27..b5de0bd24e 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 nb_elems,
> const int num, const int numbits,
> const VLCcode *buf,
> diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h
> index 3f7c033a78..679666801a 100644
> --- a/libavcodec/vlc.h
> +++ b/libavcodec/vlc.h
> @@ -19,8 +19,11 @@
> #ifndef AVCODEC_VLC_H
> #define AVCODEC_VLC_H
>
> +#include <stddef.h>
> #include <stdint.h>
>
> +#include "libavutil/macros.h"
> +
> #define VLC_MULTI_MAX_SYMBOLS 6
>
> // When changing this, be sure to also update tableprint_vlc.h accordingly.
> @@ -223,4 +226,103 @@ void ff_vlc_free(VLC *vlc);
> NULL); \
> } while (0)
>
> +/**
> + * For static VLCs, the number of bits can often be hardcoded
> + * at each get_vlc2() callsite. Then using a full VLC would be uneconomical,
> + * because only VLC.table would ever be accessed after initialization.
> + * The following functions provide wrappers around the relevant ff_vlc_init_*
> + * functions suitable for said task.
> + *
> + * The ff_vlc_init_tables_* functions are intended to be used for initializing
> + * a series of VLCs. The user initializes a VLCInitState with the details
> + * about the underlying array of VLCElem; it is automatically updated by
> + * the ff_vlc_init_tables_* functions (i.e. table is incremented and size
> + * decremented by the number of elements of the current table).
> + * The VLC_INIT_STATIC_OVERLONG flag is also automatically added.
> + * These functions return a pointer to the table just initialized,
> + * potentially to be used in arrays of pointer to VLC tables.
> + *
> + * The ff_vlc_init_table_* functions are intended to be used for initializing
> + * a single VLC table, given by table and table_size. The VLC_INIT_USE_STATIC
> + * flag is automatically added.
> + */
> +
> +typedef struct VLCInitState {
> + VLCElem *table; ///< points to where the next VLC table will be placed
> + unsigned size; ///< remaining number of elements in table
> +} VLCInitState;
> +
> +#define VLC_INIT_STATE(_table) { .table = (_table), .size = FF_ARRAY_ELEMS(_table) }
> +
> +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);
> +
> +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);
> +
> +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);
> +
> +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);
> +
> +static inline
> +const VLCElem *ff_vlc_init_tables(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,
> + int flags)
> +{
> + return ff_vlc_init_tables_sparse(state, nb_bits, nb_codes,
> + bits, bits_wrap, bits_size,
> + codes, codes_wrap, codes_size,
> + NULL, 0, 0, flags);
> +}
> +
> +#define VLC_INIT_STATIC_SPARSE_TABLE(vlc_table, nb_bits, nb_codes, \
> + bits, bits_wrap, bits_size, \
> + codes, codes_wrap, codes_size, \
> + symbols, symbols_wrap, symbols_size, \
> + flags) \
> + ff_vlc_init_table_sparse(vlc_table, FF_ARRAY_ELEMS(vlc_table), \
> + (nb_bits), (nb_codes), \
> + (bits), (bits_wrap), (bits_size), \
> + (codes), (codes_wrap), (codes_size), \
> + (symbols), (symbols_wrap), (symbols_size), \
> + (flags))
> +
> +#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, \
> + bits, bits_wrap, bits_size, \
> + codes, codes_wrap, codes_size, \
> + flags) \
> + ff_vlc_init_table_sparse(vlc_table, FF_ARRAY_ELEMS(vlc_table), \
> + (nb_bits), (nb_codes), \
> + (bits), (bits_wrap), (bits_size), \
> + (codes), (codes_wrap), (codes_size), \
> + NULL, 0, 0, (flags))
> +
> +#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, \
> + lens, lens_wrap, \
> + syms, syms_wrap, syms_size, \
> + offset, flags) \
> + ff_vlc_init_table_from_lengths(vlc_table, FF_ARRAY_ELEMS(vlc_table), \
> + (nb_bits), (nb_codes), \
> + (lens), (lens_wrap), \
> + (syms), (syms_wrap), (syms_size), \
> + (offset), (flags))
> +
> #endif /* AVCODEC_VLC_H */
Will apply this patchset tonight (with the mobiclip bug fixed) unless
there are objections.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 64+ messages in thread
end of thread, other threads:[~2023-10-30 23:06 UTC | newest]
Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 22:12 [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 02/61] avcodec/vp3: Make VLC tables static where possible Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 03/61] avcodec/vp3: Increase some VLC tables Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 04/61] avcodec/h264_cavlc: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 05/61] avcodec/h264_cavlc: Avoid indirection for coefficient table VLCs Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 06/61] avcodec/h264_cavlc: Remove code duplication Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 07/61] avcodec/asvdec: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 08/61] avcodec/faxcompr: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 09/61] avcodec/h261dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 10/61] avcodec/ituh263dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 11/61] avcodec/msmpeg4_vc1_data: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 12/61] avcodec/svq1dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 13/61] avcodec/svq1dec: Increase size of VLC Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 14/61] avcodec/rv40: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 15/61] avcodec/mpc7: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 16/61] avcodec/intrax8: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 17/61] avcodec/clearvideo: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 18/61] avcodec/atrac9dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 19/61] avcodec/imc: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 20/61] avcodec/refstruct: Add simple API for refcounted objects Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 21/61] avcodec/vp3: Share coefficient VLCs between threads Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 22/61] avcodec/vp3: Avoid complete VLC struct, only use VLCElem* Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 23/61] avcodec/vp3: Reindent after the previous commits Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 24/61] avcodec/rv34: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 25/61] avcodec/rv34: Constify pointer to static object Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 26/61] avcodec/wnv1: Avoid unnecessary VLC structure Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 27/61] avcodec/mv30: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 28/61] avcodec/vqcdec: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: " Andreas Rheinhardt
2023-09-27 23:20 ` Michael Niedermayer
2023-09-27 23:44 ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 30/61] avcodec/mimic: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 31/61] avcodec/imm4: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 32/61] avcodec/lagarith: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 33/61] avcodec/speedhqdec: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 34/61] avcodec/vc1: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 35/61] avcodec/4xm: Avoid unnecessary " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 36/61] avcodec/indeo2: Avoid unnecessary VLC structure Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 37/61] avcodec/mss4: Partially inline max_depth and nb_bits of VLC Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 38/61] avcodec/mpeg4videodec: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 39/61] avcodec/msmpeg4dec: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 40/61] avcodec/aacps: Remove unused AVCodecContext* parameter from ff_ps_apply Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 41/61] avcodec/aacps: Pass logctx as void* instead of AVCodecContext* Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 42/61] avcodec/aacdectab: Deduplicate common decoder tables Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 43/61] avcodec/aacdec_template: Deduplicate VLCs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 44/61] avcodec/aacdec_template: Don't init unused table for fixed-point decoder Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 45/61] avcodec/aactab: Improve included headers Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 46/61] avcodec/aacdec_common: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 47/61] avcodec/aacsbr_template: Deduplicate VLCs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 48/61] avcodec/aacdec_common: Avoid superfluous VLC structures for SBR VLCs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 49/61] avcodec/aacdec_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 50/61] avcodec/aacdec_common: Combine huffman tabs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 51/61] avcodec/aacdec_common: Apply offset for SBR VLCs during init Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 52/61] avcodec/aacps: Move initializing common stuff to aacdec_common.c Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 53/61] avcodec/aacps_common: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 54/61] avcodec/aacps_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 55/61] avcodec/aacps_common: Combine huffman tabels Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 56/61] avcodec/aacps_common: Apply offset for VLCs during init Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 57/61] avcodec/mpegaudiodec_common: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 58/61] avcodec/mpeg12: Avoid unnecessary " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 59/61] avcodec/wmaprodec: Avoid superfluous " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 60/61] avcodec/wmavoice: Avoid unnecessary VLC structure Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 61/61] avcodec/vlc: Remove unused macros Andreas Rheinhardt
2023-10-30 23:08 ` [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git