From 1d5d666601b6dc9319f8a539c40d016e3aef932e Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Thu, 10 Dec 2020 06:39:41 +0100 Subject: [PATCH] avcodec/msmpeg4: Factor out common RLTable initialization code Up until now, both the msmpeg4 decoders and encoders initialized several RLTables common to them (the decoders also initialized the VLCs of these RLTables). This is an obstacle to making these codecs init-threadsafe. So move this initialization to ff_msmpeg4_common_init() that already contains this initialization code. This allows to reuse the AVOnce used for initializing ff_v2_dc_lum/chroma_table which automatically makes initializing these RLTables thread-safe. Reviewed-by: Anton Khirnov Signed-off-by: Andreas Rheinhardt --- libavcodec/msmpeg4.c | 12 +++++++++++- libavcodec/msmpeg4data.c | 1 - libavcodec/msmpeg4data.h | 1 - libavcodec/msmpeg4dec.c | 5 +---- libavcodec/msmpeg4enc.c | 3 --- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c index 6673b452319..16b6f189509 100644 --- a/libavcodec/msmpeg4.c +++ b/libavcodec/msmpeg4.c @@ -103,6 +103,16 @@ static av_cold void init_h263_dc_for_msmpeg4(void) } } +static av_cold void msmpeg4_common_init_static(void) +{ + static uint8_t rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3]; + + for (int i = 0; i < NB_RL_TABLES; i++) + ff_rl_init(&ff_rl_table[i], rl_table_store[i]); + + init_h263_dc_for_msmpeg4(); +} + av_cold void ff_msmpeg4_common_init(MpegEncContext *s) { static AVOnce init_static_once = AV_ONCE_INIT; @@ -145,7 +155,7 @@ av_cold void ff_msmpeg4_common_init(MpegEncContext *s) } //Note the default tables are set in common_init in mpegvideo.c - ff_thread_once(&init_static_once, init_h263_dc_for_msmpeg4); + ff_thread_once(&init_static_once, msmpeg4_common_init_static); } /* predict coded block */ diff --git a/libavcodec/msmpeg4data.c b/libavcodec/msmpeg4data.c index fb0c6185bfd..890aeb5670d 100644 --- a/libavcodec/msmpeg4data.c +++ b/libavcodec/msmpeg4data.c @@ -33,7 +33,6 @@ uint32_t ff_v2_dc_lum_table[512][2]; uint32_t ff_v2_dc_chroma_table[512][2]; -uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3]; VLC ff_msmp4_mb_i_vlc; VLC ff_msmp4_dc_luma_vlc[2]; diff --git a/libavcodec/msmpeg4data.h b/libavcodec/msmpeg4data.h index 68a1d14f55e..87b4057d971 100644 --- a/libavcodec/msmpeg4data.h +++ b/libavcodec/msmpeg4data.h @@ -59,7 +59,6 @@ extern const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64]; #define NB_RL_TABLES 6 extern RLTable ff_rl_table[NB_RL_TABLES]; -extern uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3]; extern uint32_t ff_v2_dc_lum_table[512][2]; extern uint32_t ff_v2_dc_chroma_table[512][2]; diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c index 8fcd5b94cdd..ef8d510a02a 100644 --- a/libavcodec/msmpeg4dec.c +++ b/libavcodec/msmpeg4dec.c @@ -295,7 +295,7 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; static volatile int done = 0; - int i, ret; + int ret; MVTable *mv; if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) @@ -307,9 +307,6 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) ff_msmpeg4_common_init(s); if (!done) { - for(i=0;i