diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-05-07 05:49:27 +0300 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-05-12 07:00:14 +0300 |
commit | 3c26773ae28ebd6a549491d432a6990450b068cf (patch) | |
tree | f1993c04a8d762de1b9aa80e95dea41cb6df7eac /libavcodec/jpeg2000dec.c | |
parent | b43e946b71e144a4ce5e83cd18e5a07155edb26f (diff) |
avcodec/jpeg2000dec: Make decoder init-threadsafe
The JPEG-2000 decoder and encoder share common luts; the decoder
initializes them once, guarded by a dedicated AVOnce, whereas
the encoder initializes them always during init. This means that
the decoder is not init-threadsafe; in fact there is a potential
data race because these luts can be initialized while an active
decoder/encoder is using them.
Fix this and make the decoder init-threadsafe by making the
initialization function guard initialization itself with a dedicated
AVOnce.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/jpeg2000dec.c')
-rw-r--r-- | libavcodec/jpeg2000dec.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 1295c96305..e62f7b19e6 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -34,7 +34,6 @@ #include "libavutil/imgutils.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" -#include "libavutil/thread.h" #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -2473,18 +2472,12 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) return 0; } -static av_cold void jpeg2000_init_static_data(void) -{ - ff_jpeg2000_init_tier1_luts(); -} - static av_cold int jpeg2000_decode_init(AVCodecContext *avctx) { - static AVOnce init_static_once = AV_ONCE_INIT; Jpeg2000DecoderContext *s = avctx->priv_data; - ff_thread_once(&init_static_once, jpeg2000_init_static_data); ff_jpeg2000dsp_init(&s->dsp); + ff_jpeg2000_init_tier1_luts(); return 0; } @@ -2588,5 +2581,6 @@ const AVCodec ff_jpeg2000_decoder = { .decode = jpeg2000_decode_frame, .priv_class = &jpeg2000_class, .max_lowres = 5, - .profiles = NULL_IF_CONFIG_SMALL(ff_jpeg2000_profiles) + .profiles = NULL_IF_CONFIG_SMALL(ff_jpeg2000_profiles), + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; |