From 11dfa4d15963a7ad71b763261d6d7e3dcded9965 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 21 Oct 2022 23:17:07 +0200 Subject: avcodec/mpeg12: Avoid indirection when accessing rl_vlc tables Signed-off-by: Andreas Rheinhardt --- libavcodec/eamad.c | 3 +-- libavcodec/mdec.c | 3 +-- libavcodec/mpeg12.c | 19 +++++++++++-------- libavcodec/mpeg12dec.c | 28 ++++++++++++---------------- libavcodec/mpeg12vlc.h | 14 +++++++------- libavcodec/speedhqdec.c | 6 ++++-- 6 files changed, 36 insertions(+), 37 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c index de8f488f65..45012c62b8 100644 --- a/libavcodec/eamad.c +++ b/libavcodec/eamad.c @@ -128,7 +128,6 @@ static inline void idct_put(MadContext *t, AVFrame *frame, int16_t *block, static inline int decode_block_intra(MadContext *s, int16_t * block) { int level, i, j, run; - RLTable *rl = &ff_rl_mpeg1; const uint8_t *scantable = ff_zigzag_direct; int16_t *quant_matrix = s->quant_matrix; @@ -142,7 +141,7 @@ static inline int decode_block_intra(MadContext *s, int16_t * block) /* now quantify & encode AC coefficients */ for (;;) { UPDATE_CACHE(re, &s->gb); - GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0); if (level == 127) { break; diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c index a1f85aa0cf..640b671a0f 100644 --- a/libavcodec/mdec.c +++ b/libavcodec/mdec.c @@ -63,7 +63,6 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n) { int level, diff, i, j, run; int component; - RLTable *rl = &ff_rl_mpeg1; const uint8_t *const scantable = a->permutated_scantable; const uint16_t *quant_matrix = a->quant_matrix; const int qscale = a->qscale; @@ -84,7 +83,7 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n) /* now quantify & encode AC coefficients */ for (;;) { UPDATE_CACHE(re, &a->gb); - GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + GET_RL_VLC(level, run, re, &a->gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0); if (level == 127) { break; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index df6aba9d74..351ebf420f 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -63,7 +63,8 @@ static const uint8_t table_mb_btype[11][2] = { { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT }; -av_cold void ff_init_2d_vlc_rl(RLTable *rl, unsigned static_size, int flags) +av_cold void ff_init_2d_vlc_rl(const RLTable *rl, RL_VLC_ELEM rl_vlc[], + unsigned static_size, int flags) { int i; VLCElem table[680] = { 0 }; @@ -94,9 +95,9 @@ av_cold void ff_init_2d_vlc_rl(RLTable *rl, unsigned static_size, int flags) level = rl->table_level[code]; } } - rl->rl_vlc[0][i].len = len; - rl->rl_vlc[0][i].level = level; - rl->rl_vlc[0][i].run = run; + rl_vlc[i].len = len; + rl_vlc[i].level = level; + rl_vlc[i].run = run; } } @@ -122,6 +123,9 @@ VLC ff_mb_ptype_vlc; VLC ff_mb_btype_vlc; VLC ff_mb_pat_vlc; +RL_VLC_ELEM ff_mpeg1_rl_vlc[680]; +RL_VLC_ELEM ff_mpeg2_rl_vlc[674]; + static av_cold void mpeg12_init_vlcs(void) { INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12, @@ -147,8 +151,8 @@ static av_cold void mpeg12_init_vlcs(void) &table_mb_btype[0][1], 2, 1, &table_mb_btype[0][0], 2, 1, 64); - INIT_2D_VLC_RL(ff_rl_mpeg1, 680, 0); - INIT_2D_VLC_RL(ff_rl_mpeg2, 674, 0); + INIT_2D_VLC_RL(ff_rl_mpeg1, ff_mpeg1_rl_vlc, 0); + INIT_2D_VLC_RL(ff_rl_mpeg2, ff_mpeg2_rl_vlc, 0); } av_cold void ff_mpeg12_init_vlcs(void) @@ -231,7 +235,6 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb, int16_t *block, int index, int qscale) { int dc, diff, i = 0, component; - RLTable *rl = &ff_rl_mpeg1; /* DC coefficient */ component = index <= 3 ? 0 : index - 4 + 1; @@ -256,7 +259,7 @@ int ff_mpeg1_decode_block_intra(GetBitContext *gb, while (1) { int level, run, j; - GET_RL_VLC(level, run, re, gb, rl->rl_vlc[0], + GET_RL_VLC(level, run, re, gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0); if (level != 0) { diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index c942be158e..914516bbd9 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -152,7 +152,6 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; - RLTable *rl = &ff_rl_mpeg1; uint8_t *const scantable = s->intra_scantable.permutated; const uint16_t *quant_matrix = s->inter_matrix; const int qscale = s->qscale; @@ -175,7 +174,7 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, } /* now quantify & encode AC coefficients */ for (;;) { - GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], + GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0); if (level != 0) { @@ -241,7 +240,6 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; - RLTable *rl = &ff_rl_mpeg1; uint8_t *const scantable = s->intra_scantable.permutated; const int qscale = s->qscale; @@ -264,7 +262,7 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, /* now quantify & encode AC coefficients */ for (;;) { - GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], + GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0); if (level != 0) { @@ -326,7 +324,6 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; - RLTable *rl = &ff_rl_mpeg1; uint8_t *const scantable = s->intra_scantable.permutated; const uint16_t *quant_matrix; const int qscale = s->qscale; @@ -358,7 +355,7 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, /* now quantify & encode AC coefficients */ for (;;) { - GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], + GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0); if (level != 0) { @@ -416,7 +413,6 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, int16_t *block, int n) { int level, i, j, run; - RLTable *rl = &ff_rl_mpeg1; uint8_t *const scantable = s->intra_scantable.permutated; const int qscale = s->qscale; OPEN_READER(re, &s->gb); @@ -437,7 +433,7 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, /* now quantify & encode AC coefficients */ for (;;) { - GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc, TEX_VLC_BITS, 2, 0); if (level != 0) { i += run; @@ -489,7 +485,7 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, { int level, dc, diff, i, j, run; int component; - RLTable *rl; + const RL_VLC_ELEM *rl_vlc; uint8_t *const scantable = s->intra_scantable.permutated; const uint16_t *quant_matrix; const int qscale = s->qscale; @@ -512,16 +508,16 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, mismatch = block[0] ^ 1; i = 0; if (s->intra_vlc_format) - rl = &ff_rl_mpeg2; + rl_vlc = ff_mpeg2_rl_vlc; else - rl = &ff_rl_mpeg1; + rl_vlc = ff_mpeg1_rl_vlc; { OPEN_READER(re, &s->gb); /* now quantify & encode AC coefficients */ for (;;) { UPDATE_CACHE(re, &s->gb); - GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); if (level == 127) { @@ -575,7 +571,7 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, { int level, dc, diff, i, j, run; int component; - RLTable *rl; + const RL_VLC_ELEM *rl_vlc; uint8_t *const scantable = s->intra_scantable.permutated; const uint16_t *quant_matrix; const int qscale = s->qscale; @@ -595,16 +591,16 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, block[0] = dc * (1 << (3 - s->intra_dc_precision)); i = 0; if (s->intra_vlc_format) - rl = &ff_rl_mpeg2; + rl_vlc = ff_mpeg2_rl_vlc; else - rl = &ff_rl_mpeg1; + rl_vlc = ff_mpeg1_rl_vlc; { OPEN_READER(re, &s->gb); /* now quantify & encode AC coefficients */ for (;;) { UPDATE_CACHE(re, &s->gb); - GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); if (level >= 64 || i > 63) { diff --git a/libavcodec/mpeg12vlc.h b/libavcodec/mpeg12vlc.h index 4fb19371f0..d0083f1124 100644 --- a/libavcodec/mpeg12vlc.h +++ b/libavcodec/mpeg12vlc.h @@ -50,17 +50,17 @@ extern VLC ff_mv_vlc; void ff_mpeg12_init_vlcs(void); -#define INIT_2D_VLC_RL(rl, static_size, flags)\ -{\ - static RL_VLC_ELEM rl_vlc_table[static_size];\ - rl.rl_vlc[0] = rl_vlc_table;\ - ff_init_2d_vlc_rl(&rl, static_size, flags);\ -} +#define INIT_2D_VLC_RL(rl, rl_vlc, flags)\ + ff_init_2d_vlc_rl(&rl, rl_vlc, FF_ARRAY_ELEMS(rl_vlc), flags) extern RLTable ff_rl_mpeg1; extern RLTable ff_rl_mpeg2; -void ff_init_2d_vlc_rl(RLTable *rl, unsigned static_size, int flags); +extern RL_VLC_ELEM ff_mpeg1_rl_vlc[]; +extern RL_VLC_ELEM ff_mpeg2_rl_vlc[]; + +void ff_init_2d_vlc_rl(const RLTable *rl, RL_VLC_ELEM rl_vlc[], + unsigned static_size, int flags); void ff_mpeg1_init_uni_ac_vlc(const RLTable *rl, uint8_t *uni_ac_vlc_len); diff --git a/libavcodec/speedhqdec.c b/libavcodec/speedhqdec.c index 5378b987dc..93b60a4c3d 100644 --- a/libavcodec/speedhqdec.c +++ b/libavcodec/speedhqdec.c @@ -77,6 +77,8 @@ static VLC dc_chroma_vlc_le; static VLC dc_alpha_run_vlc_le; static VLC dc_alpha_level_vlc_le; +static RL_VLC_ELEM speedhq_rl_vlc[674]; + static inline int decode_dc_le(GetBitContext *gb, int component) { int code, diff; @@ -154,7 +156,7 @@ static inline int decode_dct_block(const SHQContext *s, GetBitContext *gb, int l for ( ;; ) { int level, run; UPDATE_CACHE_LE(re, gb); - GET_RL_VLC(level, run, re, gb, ff_rl_speedhq.rl_vlc[0], + GET_RL_VLC(level, run, re, gb, speedhq_rl_vlc, TEX_VLC_BITS, 2, 0); if (level == 127) { break; @@ -564,7 +566,7 @@ static av_cold void speedhq_static_init(void) ff_mpeg12_vlc_dc_chroma_code, 2, 2, INIT_VLC_OUTPUT_LE, 514); - INIT_2D_VLC_RL(ff_rl_speedhq, 674, INIT_VLC_LE); + INIT_2D_VLC_RL(ff_rl_speedhq, speedhq_rl_vlc, INIT_VLC_LE); compute_alpha_vlcs(); } -- cgit v1.2.3