diff mbox series

[FFmpeg-devel,v2,085/162] avcodec/indeo2: Make decoder thread-safe

Message ID 20201120072116.818090-86-andreas.rheinhardt@gmail.com
State Accepted
Commit 0d71ac319f74a85add9c62c31461b4dd4dcfcabd
Headers show
Series VLC, esp. init_vlc patches | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 20, 2020, 7:19 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/indeo2.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c
index 5a9c0e77be..5721308267 100644
--- a/libavcodec/indeo2.c
+++ b/libavcodec/indeo2.c
@@ -25,6 +25,7 @@ 
  */
 
 #include "libavutil/attributes.h"
+#include "libavutil/thread.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
@@ -225,8 +226,16 @@  static int ir2_decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
+static av_cold void ir2_init_static(void)
+{
+    INIT_VLC_STATIC_FROM_LENGTHS(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
+                                 &ir2_tab[0][1], 2, &ir2_tab[0][0], 2, 1,
+                                 0, INIT_VLC_OUTPUT_LE, 1 << CODE_VLC_BITS);
+}
+
 static av_cold int ir2_decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     Ir2Context * const ic = avctx->priv_data;
 
     ic->avctx = avctx;
@@ -237,9 +246,7 @@  static av_cold int ir2_decode_init(AVCodecContext *avctx)
     if (!ic->picture)
         return AVERROR(ENOMEM);
 
-    INIT_VLC_STATIC_FROM_LENGTHS(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
-                                 &ir2_tab[0][1], 2, &ir2_tab[0][0], 2, 1,
-                                 0, INIT_VLC_OUTPUT_LE, 1 << CODE_VLC_BITS);
+    ff_thread_once(&init_static_once, ir2_init_static);
 
     return 0;
 }
@@ -263,4 +270,5 @@  AVCodec ff_indeo2_decoder = {
     .close          = ir2_decode_end,
     .decode         = ir2_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };