[FFmpeg-cvslog] avcodec/atrac9dec: Don't use unnecessarily large VLC tables
Andreas Rheinhardt
git at videolan.org
Tue Nov 24 12:49:10 EET 2020
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Wed Nov 4 05:38:31 2020 +0100| [659c61ba7caaa98a3ae6c3a3347b6ff557a4a084] | committer: Andreas Rheinhardt
avcodec/atrac9dec: Don't use unnecessarily large VLC tables
Using more bits for a VLC than the longest code has has no advantage.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=659c61ba7caaa98a3ae6c3a3347b6ff557a4a084
---
libavcodec/atrac9dec.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index ecf95f1777..0477b304d2 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -26,6 +26,8 @@
#include "libavutil/lfg.h"
#include "libavutil/float_dsp.h"
+#define ATRAC9_SF_VLC_BITS 8
+
typedef struct ATRAC9ChannelData {
int band_ext;
int q_unit_cnt;
@@ -272,7 +274,8 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
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, 9, 1);
+ int val = c->scalefactors[i - 1] + get_vlc2(gb, tab->table,
+ ATRAC9_SF_VLC_BITS, 1);
c->scalefactors[i] = val & ((1 << len) - 1);
}
@@ -302,7 +305,7 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
const VLC *tab = &s->sf_vlc[1][len];
for (int i = 0; i < unit_cnt; i++) {
- int dist = get_vlc2(gb, tab->table, 9, 1);
+ int dist = get_vlc2(gb, tab->table, ATRAC9_SF_VLC_BITS, 1);
c->scalefactors[i] = baseline[i] + dist;
}
@@ -325,7 +328,8 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
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, 9, 1);
+ int val = c->scalefactors[i - 1] + get_vlc2(gb, tab->table,
+ ATRAC9_SF_VLC_BITS, 1);
c->scalefactors[i] = val & ((1 << len) - 1);
}
@@ -930,7 +934,8 @@ 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], 9, hf->size, hf->bits, 1, 1, hf->codes,
+ init_vlc(&s->sf_vlc[0][i], ATRAC9_SF_VLC_BITS, hf->size,
+ hf->bits, 1, 1, hf->codes,
2, 2, 0);
}
@@ -943,7 +948,7 @@ static av_cold int atrac9_decode_init(AVCodecContext *avctx)
for (int j = 0; j < nums; j++)
sym[j] = sign_extend(j, hf->value_bits);
- ff_init_vlc_sparse(&s->sf_vlc[1][i], 9, hf->size, hf->bits, 1, 1,
+ 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);
}
More information about the ffmpeg-cvslog
mailing list