diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-30 19:01:16 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-05-02 04:02:13 +0200 |
commit | acde66082f930b3762d854752613ab191e892c52 (patch) | |
tree | c5d7151744024d010e117723a18b96f3f5e861ea /libavcodec/vima.c | |
parent | 58ca07320bed139f81ece73dbbf8718e316d392a (diff) |
avcodec/vima: Make decoder init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/vima.c')
-rw-r--r-- | libavcodec/vima.c | 24 |
1 files 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, }; |