summaryrefslogtreecommitdiff
path: root/libavcodec/atrac9dec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-04 08:25:47 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-08 17:51:46 +0100
commit5ac9d78dd2977e9e9021749e215d7208c2a56f39 (patch)
tree626bb1cf6d75dada9e8b5a51363f65e3cb73b20c /libavcodec/atrac9dec.c
parentf697622f687c22392194d6939914c9a6a01ce69e (diff)
avcodec/atrac9dec: Make tables used to initialize VLCs smaller
The ATRAC9 decoder uses VLCs which are currently initialized with static length tables of type uint8_t and code tables of type uint16_t. Furthermore, in one case the actually desired symbols are in the range -16..15 and in order to achieve this an ad-hoc symbols table of type int16_t is calculated. This commit modifies this process by replacing the codes tables by symbols tables and switching to ff_init_vlc_from_lengths(); the signed symbols are stored in the table after having been shifted by 16 to fit into an uint8_t and are shifted back when the VLC is created. This makes all symbols fit into an uint8_t, saving space. Furthermore, the earlier tables had holes in them (entries with length zero that were inserted because the actually used symbols were not contiguous); these holes are unnecessary in the new approach, leading to further saving. Finally, given that now both lengths as well as symbols are of the same type, they can be combined; this saves a pointer for each VLC. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/atrac9dec.c')
-rw-r--r--libavcodec/atrac9dec.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index a7de037b2c..5a78958059 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -848,6 +848,7 @@ static av_cold int atrac9_decode_init(AVCodecContext *avctx)
GetBitContext gb;
ATRAC9Context *s = avctx->priv_data;
int version, block_config_idx, superframe_idx, alloc_c_len;
+ int ret;
s->avctx = avctx;
@@ -934,22 +935,25 @@ static av_cold int atrac9_decode_init(AVCodecContext *avctx)
for (int i = 1; i < 7; i++) {
const HuffmanCodebook *hf = &at9_huffman_sf_unsigned[i];
- init_vlc(&s->sf_vlc[0][i], ATRAC9_SF_VLC_BITS, hf->size,
- hf->bits, 1, 1, hf->codes,
- 2, 2, 0);
+ ret = ff_init_vlc_from_lengths(&s->sf_vlc[0][i], ATRAC9_SF_VLC_BITS,
+ hf->size, &hf->tab[0][1], 2,
+ &hf->tab[0][0], 2, 1, 0, 0, avctx);
+ if (ret < 0)
+ return ret;
}
/* Signed scalefactor VLCs */
for (int i = 2; i < 6; i++) {
const HuffmanCodebook *hf = &at9_huffman_sf_signed[i];
- int nums = hf->size;
- int16_t sym[32];
- for (int j = 0; j < nums; j++)
- sym[j] = sign_extend(j, hf->value_bits);
-
- ff_init_vlc_sparse(&s->sf_vlc[1][i], ATRAC9_SF_VLC_BITS, hf->size, hf->bits, 1, 1,
- hf->codes, 2, 2, sym, sizeof(*sym), sizeof(*sym), 0);
+ /* 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. */
+ ret = ff_init_vlc_from_lengths(&s->sf_vlc[1][i], ATRAC9_SF_VLC_BITS,
+ hf->size, &hf->tab[0][1], 2,
+ &hf->tab[0][0], 2, 1, -16, 0, avctx);
+ if (ret < 0)
+ return ret;
}
/* Coefficient VLCs */
@@ -957,8 +961,11 @@ static av_cold int atrac9_decode_init(AVCodecContext *avctx)
for (int j = 0; j < 8; j++) {
for (int k = 0; k < 4; k++) {
const HuffmanCodebook *hf = &at9_huffman_coeffs[i][j][k];
- init_vlc(&s->coeff_vlc[i][j][k], 9, hf->size, hf->bits, 1, 1,
- hf->codes, 2, 2, 0);
+ ret = ff_init_vlc_from_lengths(&s->coeff_vlc[i][j][k], 9,
+ hf->size, &hf->tab[0][1], 2,
+ &hf->tab[0][0], 2, 1, 0, 0, avctx);
+ if (ret < 0)
+ return ret;
}
}
}