[FFmpeg-devel] [PATCH 30/30] avcodec/dvenc: Make encoder init-threadsafe

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Thu Dec 31 01:31:57 EET 2020


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
The above depends upon ff_check_alignment() being removed first.

 libavcodec/dvenc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 21a8b841f6..35b6f71e46 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -32,6 +32,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/thread.h"
 
 #include "avcodec.h"
 #include "dv.h"
@@ -67,8 +68,6 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
         return ret;
     }
 
-    dv_vlc_map_tableinit();
-
     memset(&fdsp,0, sizeof(fdsp));
     memset(&mecc,0, sizeof(mecc));
     memset(&pdsp,0, sizeof(pdsp));
@@ -83,6 +82,13 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
     s->fdct[0]    = fdsp.fdct;
     s->fdct[1]    = fdsp.fdct248;
 
+#if !CONFIG_HARDCODED_TABLES
+    {
+        static AVOnce init_static_once = AV_ONCE_INIT;
+        ff_thread_once(&init_static_once, dv_vlc_map_tableinit);
+    }
+#endif
+
     return ff_dvvideo_init(avctx);
 }
 
@@ -1226,4 +1232,5 @@ AVCodec ff_dvvideo_encoder = {
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE
     },
     .priv_class     = &dvvideo_encode_class,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.25.1



More information about the ffmpeg-devel mailing list