diff mbox series

[FFmpeg-devel,163/217] avcodec/4xm: Make decoder init-threadsafe

Message ID 20201202042244.519127-29-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure
Related show

Checks

Context Check Description
andriy/x86 warning Failed to apply patch

Commit Message

Andreas Rheinhardt Dec. 2, 2020, 4:21 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/4xm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index 336c651d31..00a8e0b1f3 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -30,6 +30,7 @@ 
 #include "libavutil/frame.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "blockdsp.h"
 #include "bswapdsp.h"
@@ -245,7 +246,7 @@  static void idct(int16_t block[64])
     }
 }
 
-static av_cold void init_vlcs(FourXContext *f)
+static av_cold void init_vlcs(void)
 {
     static VLC_TYPE table[2][4][32][2];
     int i, j;
@@ -987,6 +988,7 @@  static av_cold int decode_end(AVCodecContext *avctx)
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     FourXContext * const f = avctx->priv_data;
     int ret;
 
@@ -1014,13 +1016,14 @@  static av_cold int decode_init(AVCodecContext *avctx)
     ff_blockdsp_init(&f->bdsp, avctx);
     ff_bswapdsp_init(&f->bbdsp);
     f->avctx = avctx;
-    init_vlcs(f);
 
     if (f->version > 2)
         avctx->pix_fmt = AV_PIX_FMT_RGB565;
     else
         avctx->pix_fmt = AV_PIX_FMT_BGR555;
 
+    ff_thread_once(&init_static_once, init_vlcs);
+
     return 0;
 }
 
@@ -1034,4 +1037,5 @@  AVCodec ff_fourxm_decoder = {
     .close          = decode_end,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };