[FFmpeg-devel] [PATCH 189/191] avcodec/ivi: Make initializing VLCs thread-safe

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon Nov 23 21:37:37 EET 2020


This automatically makes indeo4/5 init-threadsafe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavcodec/indeo4.c |  1 +
 libavcodec/indeo5.c |  2 +-
 libavcodec/ivi.c    | 13 ++++++++-----
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavcodec/indeo4.c b/libavcodec/indeo4.c
index 4bfc6cdd74..e2778af6ca 100644
--- a/libavcodec/indeo4.c
+++ b/libavcodec/indeo4.c
@@ -713,4 +713,5 @@ AVCodec ff_indeo4_decoder = {
     .close          = ff_ivi_decode_close,
     .decode         = ff_ivi_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/indeo5.c b/libavcodec/indeo5.c
index ac15d31fef..3ee7a0e1d6 100644
--- a/libavcodec/indeo5.c
+++ b/libavcodec/indeo5.c
@@ -693,5 +693,5 @@ AVCodec ff_indeo5_decoder = {
     .close          = ff_ivi_decode_close,
     .decode         = ff_ivi_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c
index 5e1180a5f0..a5074e9980 100644
--- a/libavcodec/ivi.c
+++ b/libavcodec/ivi.c
@@ -30,6 +30,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/thread.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
@@ -157,14 +158,11 @@ static int ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag)
                     (flag ? INIT_VLC_USE_NEW_STATIC : 0) | INIT_VLC_OUTPUT_LE);
 }
 
-av_cold void ff_ivi_init_static_vlc(void)
+static av_cold void ivi_init_static_vlc(void)
 {
     int i;
     static VLC_TYPE table_data[8192 * 16][2];
-    static int initialized_vlcs = 0;
 
-    if (initialized_vlcs)
-        return;
     for (i = 0; i < 8; i++) {
         ivi_mb_vlc_tabs[i].table = table_data + i * 2 * 8192;
         ivi_mb_vlc_tabs[i].table_allocated = 8192;
@@ -175,7 +173,12 @@ av_cold void ff_ivi_init_static_vlc(void)
         ivi_create_huff_from_desc(&ivi_blk_huff_desc[i],
                                   &ivi_blk_vlc_tabs[i], 1);
     }
-    initialized_vlcs = 1;
+}
+
+av_cold void ff_ivi_init_static_vlc(void)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    ff_thread_once(&init_static_once, ivi_init_static_vlc);
 }
 
 /*
-- 
2.25.1



More information about the ffmpeg-devel mailing list