[FFmpeg-devel] [PATCH 37/39] avcodec/speedhq, speedhqenc: Make codecs init-threadsafe
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Thu Dec 10 13:16:55 EET 2020
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 <andreas.rheinhardt at gmail.com>
---
libavcodec/speedhq.c | 4 +---
libavcodec/speedhqenc.c | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c
index 0c08894315..0312ed6f0b 100644
--- a/libavcodec/speedhq.c
+++ b/libavcodec/speedhq.c
@@ -152,8 +152,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;
@@ -570,7 +568,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();
@@ -655,4 +652,5 @@ AVCodec ff_speedhq_decoder = {
.init = speedhq_decode_init,
.decode = speedhq_decode_frame,
.capabilities = AV_CODEC_CAP_DR1,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
};
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index a5bedd5301..dbc638cb82 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -298,7 +298,7 @@ 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
--
2.25.1
More information about the ffmpeg-devel
mailing list