diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-15 21:39:19 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-12-08 17:51:45 +0100 |
commit | ee1ddd308be9dc9d2c323d176d03939c30ad4b9d (patch) | |
tree | 465763049410d8aa0a80fa14e0c6e86181939c62 /libavcodec/mobiclip.c | |
parent | 866c2ef183cded8de150402d3ec06449a87d961b (diff) | |
download | ffmpeg-ee1ddd308be9dc9d2c323d176d03939c30ad4b9d.tar.gz |
avcodec/mobiclip: Make decoder init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/mobiclip.c')
-rw-r--r-- | libavcodec/mobiclip.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index e50e4d18c5..a31a09f86d 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -23,6 +23,7 @@ #include <inttypes.h> #include "libavutil/avassert.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "bytestream.h" @@ -274,8 +275,32 @@ typedef struct MobiClipContext { static VLC rl_vlc[2]; static VLC mv_vlc[2][16]; +static av_cold void mobiclip_init_static(void) +{ + INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[0], MOBI_RL_VLC_BITS, 104, + bits0, sizeof(*bits0), + syms0, sizeof(*syms0), sizeof(*syms0), + 0, 0, 1 << MOBI_RL_VLC_BITS); + INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[1], MOBI_RL_VLC_BITS, 104, + bits0, sizeof(*bits0), + syms1, sizeof(*syms1), sizeof(*syms1), + 0, 0, 1 << MOBI_RL_VLC_BITS); + for (int i = 0; i < 2; i++) { + static VLC_TYPE vlc_buf[2 * 16 << MOBI_MV_VLC_BITS][2]; + for (int j = 0; j < 16; j++) { + mv_vlc[i][j].table = &vlc_buf[(16 * i + j) << MOBI_MV_VLC_BITS]; + mv_vlc[i][j].table_allocated = 1 << MOBI_MV_VLC_BITS; + ff_init_vlc_from_lengths(&mv_vlc[i][j], MOBI_MV_VLC_BITS, mv_len[j], + mv_bits[i][j], sizeof(*mv_bits[i][j]), + mv_syms[i][j], sizeof(*mv_syms[i][j]), sizeof(*mv_syms[i][j]), + 0, INIT_VLC_USE_NEW_STATIC, NULL); + } + } +} + static av_cold int mobiclip_init(AVCodecContext *avctx) { + static AVOnce init_static_once = AV_ONCE_INIT; MobiClipContext *s = avctx->priv_data; if (avctx->width & 15 || avctx->height & 15) { @@ -298,25 +323,7 @@ static av_cold int mobiclip_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } - INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[0], MOBI_RL_VLC_BITS, 104, - bits0, sizeof(*bits0), - syms0, sizeof(*syms0), sizeof(*syms0), - 0, 0, 1 << MOBI_RL_VLC_BITS); - INIT_VLC_STATIC_FROM_LENGTHS(&rl_vlc[1], MOBI_RL_VLC_BITS, 104, - bits0, sizeof(*bits0), - syms1, sizeof(*syms1), sizeof(*syms1), - 0, 0, 1 << MOBI_RL_VLC_BITS); - for (int i = 0; i < 2; i++) { - static VLC_TYPE vlc_buf[2 * 16 << MOBI_MV_VLC_BITS][2]; - for (int j = 0; j < 16; j++) { - mv_vlc[i][j].table = &vlc_buf[(16 * i + j) << MOBI_MV_VLC_BITS]; - mv_vlc[i][j].table_allocated = 1 << MOBI_MV_VLC_BITS; - ff_init_vlc_from_lengths(&mv_vlc[i][j], MOBI_MV_VLC_BITS, mv_len[j], - mv_bits[i][j], sizeof(*mv_bits[i][j]), - mv_syms[i][j], sizeof(*mv_syms[i][j]), sizeof(*mv_syms[i][j]), - 0, INIT_VLC_USE_NEW_STATIC, NULL); - } - } + ff_thread_once(&init_static_once, mobiclip_init_static); return 0; } @@ -1343,5 +1350,5 @@ AVCodec ff_mobiclip_decoder = { .flush = mobiclip_flush, .close = mobiclip_close, .capabilities = AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; |