[FFmpeg-devel] [PATCH 068/114] avcodec/mpeg4videodec: Make studio VLCs static
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Tue Nov 10 12:48:05 EET 2020
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavcodec/mpeg4video.h | 4 --
libavcodec/mpeg4videodec.c | 87 ++++++++++++++++----------------------
2 files changed, 36 insertions(+), 55 deletions(-)
diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index 3de598465f..e919db87a5 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -115,10 +115,6 @@ typedef struct Mpeg4DecContext {
int cplx_estimation_trash_p;
int cplx_estimation_trash_b;
- VLC studio_intra_tab[12];
- VLC studio_luma_dc;
- VLC studio_chroma_dc;
-
int rgb;
} Mpeg4DecContext;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index a03bd240a8..a94fe16056 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -53,6 +53,9 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb);
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 const int mb_type_b_map[4] = {
MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
@@ -1820,7 +1823,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;
- VLC *cur_vlc = &ctx->studio_intra_tab[0];
+ const VLC *cur_vlc = &studio_intra_tab[0];
uint8_t *const scantable = s->intra_scantable.permutated;
const uint16_t *quant_matrix;
uint32_t flc;
@@ -1834,14 +1837,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, ctx->studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
quant_matrix = s->intra_matrix;
} else {
cc = (n & 1) + 1;
if (ctx->rgb)
- dct_dc_size = get_vlc2(&s->gb, ctx->studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
else
- dct_dc_size = get_vlc2(&s->gb, ctx->studio_chroma_dc.table, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc.table, STUDIO_INTRA_BITS, 2);
quant_matrix = s->chroma_intra_matrix;
}
@@ -1878,7 +1881,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 = &ctx->studio_intra_tab[ac_state_tab[group][1]];
+ cur_vlc = &studio_intra_tab[ac_state_tab[group][1]];
if (group == 0) {
/* End of Block */
@@ -3501,36 +3504,33 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
}
#endif
-static av_cold int init_studio_vlcs(Mpeg4DecContext *ctx)
+static av_cold void init_studio_vlcs(void)
{
- int i, ret;
-
- for (i = 0; i < 12; i++) {
- ret = ff_init_vlc_from_lengths(&ctx->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, 0);
-
- if (ret < 0)
- return ret;
- }
-
- ret = ff_init_vlc_from_lengths(&ctx->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);
- if (ret < 0)
- return ret;
-
- ret = ff_init_vlc_from_lengths(&ctx->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);
- if (ret < 0)
- return ret;
-
- return 0;
+ if (studio_chroma_dc.table_size)
+ return;
+
+ for (unsigned i = 0, offset = 0; i < 12; i++) {
+ static VLC_TYPE vlc_buf[6498][2];
+
+ studio_intra_tab[i].table = &vlc_buf[offset];
+ studio_intra_tab[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
+ ff_init_vlc_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, INIT_VLC_USE_NEW_STATIC);
+ offset += studio_intra_tab[i].table_size;
+ }
+
+ INIT_VLC_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);
+
+ INIT_VLC_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);
}
static av_cold int decode_init(AVCodecContext *avctx)
@@ -3548,8 +3548,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
return ret;
ff_mpeg4videodec_static_init();
- if ((ret = init_studio_vlcs(ctx)) < 0)
- return ret;
+ init_studio_vlcs();
s->h263_pred = 1;
s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */
@@ -3561,20 +3560,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
return 0;
}
-static av_cold int decode_end(AVCodecContext *avctx)
-{
- Mpeg4DecContext *ctx = avctx->priv_data;
- int i;
-
- for (i = 0; i < 12; i++)
- ff_free_vlc(&ctx->studio_intra_tab[i]);
-
- ff_free_vlc(&ctx->studio_luma_dc);
- ff_free_vlc(&ctx->studio_chroma_dc);
-
- return ff_h263_decode_end(avctx);
-}
-
static const AVOption mpeg4_options[] = {
{"quarter_sample", "1/4 subpel MC", offsetof(MpegEncContext, quarter_sample), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, 0},
{"divx_packed", "divx style packed b frames", offsetof(MpegEncContext, divx_packed), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, 0},
@@ -3595,7 +3580,7 @@ AVCodec ff_mpeg4_decoder = {
.id = AV_CODEC_ID_MPEG4,
.priv_data_size = sizeof(Mpeg4DecContext),
.init = decode_init,
- .close = decode_end,
+ .close = ff_h263_decode_end,
.decode = ff_h263_decode_frame,
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY |
--
2.25.1
More information about the ffmpeg-devel
mailing list