From b05631f7b959fd9ec266a4315db60cc77b655cd9 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Thu, 10 Dec 2020 08:59:09 +0100 Subject: avcodec/speedhq, speedhqenc: Make codecs init-threadsafe The SpeedHQ decoder uses and initializes a RLTable's VLC, yet it also initializes other parts of the RLTable that it does not use. This has downsides besides being wasteful: Because the SpeedHQ encoder also initializes these additional fields, there is a potential for data races (and therefore undefined behaviour). In fact, removing the superfluous initializations from the decoder automatically makes both the decoder and the encoder init-threadsafe. This commit does so. Signed-off-by: Andreas Rheinhardt --- libavcodec/speedhq.c | 4 +--- libavcodec/speedhqenc.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c index 4f6a539ad8..91ba80ebd3 100644 --- a/libavcodec/speedhq.c +++ b/libavcodec/speedhq.c @@ -155,8 +155,6 @@ static const uint8_t unscaled_quant_matrix[64] = { 27, 29, 35, 38, 46, 56, 69, 83 }; -static uint8_t speedhq_static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; - static VLC dc_lum_vlc_le; static VLC dc_chroma_vlc_le; static VLC dc_alpha_run_vlc_le; @@ -648,7 +646,6 @@ static av_cold void speedhq_static_init(void) ff_mpeg12_vlc_dc_chroma_code, 2, 2, INIT_VLC_OUTPUT_LE, 514); - ff_rl_init(&ff_rl_speedhq, speedhq_static_rl_table_store); INIT_2D_VLC_RL(ff_rl_speedhq, 674, INIT_VLC_LE); compute_alpha_vlcs(); @@ -733,5 +730,6 @@ const AVCodec ff_speedhq_decoder = { .init = speedhq_decode_init, .decode = speedhq_decode_frame, .capabilities = AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif /* CONFIG_SPEEDHQ_DECODER */ diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c index 6ff7b447a0..529df4f5b6 100644 --- a/libavcodec/speedhqenc.c +++ b/libavcodec/speedhqenc.c @@ -298,7 +298,7 @@ const AVCodec ff_speedhq_encoder = { .init = ff_mpv_encode_init, .encode2 = ff_mpv_encode_picture, .close = ff_mpv_encode_end, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE -- cgit v1.2.3