From acde66082f930b3762d854752613ab191e892c52 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 30 Nov 2020 19:01:16 +0100 Subject: [PATCH] avcodec/vima: Make decoder init-threadsafe Signed-off-by: Andreas Rheinhardt --- libavcodec/vima.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libavcodec/vima.c b/libavcodec/vima.c index 5c7618861f..c9a81e4401 100644 --- a/libavcodec/vima.c +++ b/libavcodec/vima.c @@ -26,13 +26,13 @@ */ #include "libavutil/channel_layout.h" +#include "libavutil/thread.h" #include "adpcm_data.h" #include "avcodec.h" #include "get_bits.h" #include "internal.h" -static int predict_table_init = 0; static uint16_t predict_table[5786 * 2]; static const uint8_t size_table[] = { @@ -84,16 +84,9 @@ static const int8_t *const step_index_tables[] = { index_table4, index_table5, index_table6 }; -static av_cold int decode_init(AVCodecContext *avctx) +static av_cold void predict_table_init(void) { - int start_pos; - - avctx->sample_fmt = AV_SAMPLE_FMT_S16; - - if (predict_table_init) - return 0; - - for (start_pos = 0; start_pos < 64; start_pos++) { + for (int start_pos = 0; start_pos < 64; start_pos++) { unsigned int dest_pos, table_pos; for (table_pos = 0, dest_pos = start_pos; @@ -110,7 +103,15 @@ static av_cold int decode_init(AVCodecContext *avctx) predict_table[dest_pos] = put; } } - predict_table_init = 1; +} + +static av_cold int decode_init(AVCodecContext *avctx) +{ + static AVOnce init_static_once = AV_ONCE_INIT; + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + + ff_thread_once(&init_static_once, predict_table_init); return 0; } @@ -215,4 +216,5 @@ const AVCodec ff_adpcm_vima_decoder = { .init = decode_init, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, };