avcodec/asvdec: Make decoders init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2020-11-23 03:49:05 +01:00
parent 3e11a7866d
commit 103e8edd5e

View File

@ -25,6 +25,7 @@
#include "libavutil/attributes.h"
#include "libavutil/mem.h"
#include "libavutil/thread.h"
#include "asv.h"
#include "avcodec.h"
@ -45,13 +46,8 @@ static VLC dc_ccp_vlc;
static VLC ac_ccp_vlc;
static VLC asv2_level_vlc;
static av_cold void init_vlcs(ASV1Context *a)
static av_cold void init_vlcs(void)
{
static int done = 0;
if (!done) {
done = 1;
INIT_VLC_STATIC(&ccp_vlc, CCP_VLC_BITS, 17,
&ff_asv_ccp_tab[0][1], 2, 1,
&ff_asv_ccp_tab[0][0], 2, 1, 32);
@ -67,7 +63,6 @@ static av_cold void init_vlcs(ASV1Context *a)
INIT_LE_VLC_STATIC(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
&ff_asv2_level_tab[0][1], 4, 2,
&ff_asv2_level_tab[0][0], 4, 2, 1024);
}
}
static inline int asv1_get_level(GetBitContext *gb)
@ -286,6 +281,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
static av_cold int decode_init(AVCodecContext *avctx)
{
static AVOnce init_static_once = AV_ONCE_INIT;
ASV1Context *const a = avctx->priv_data;
const int scale = avctx->codec_id == AV_CODEC_ID_ASV1 ? 1 : 2;
int i;
@ -297,7 +293,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
ff_asv_common_init(avctx);
ff_blockdsp_init(&a->bdsp, avctx);
ff_idctdsp_init(&a->idsp, avctx);
init_vlcs(a);
ff_init_scantable(a->idsp.idct_permutation, &a->scantable, ff_asv_scantab);
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
@ -316,6 +311,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
a->inv_qscale;
}
ff_thread_once(&init_static_once, init_vlcs);
return 0;
}
@ -340,6 +337,7 @@ AVCodec ff_asv1_decoder = {
.close = decode_end,
.decode = decode_frame,
.capabilities = AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
};
#endif
@ -353,5 +351,6 @@ AVCodec ff_asv2_decoder = {
.init = decode_init,
.decode = decode_frame,
.capabilities = AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
};
#endif