diff mbox series

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

Message ID 20201230233157.1055287-30-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,01/30] avcodec/opustab: Make array static
Related show

Checks

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

Commit Message

Andreas Rheinhardt Dec. 30, 2020, 11:31 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
The above depends upon ff_check_alignment() being removed first.

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

Patch

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,
 };