[FFmpeg-cvslog] avcodec/j2kenc: Make encoder init-threadsafe

Andreas Rheinhardt git at videolan.org
Wed May 12 07:48:07 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri May  7 05:08:13 2021 +0200| [99ed54334053bb78a37545c4844cff6b4c9e658d] | committer: Andreas Rheinhardt

avcodec/j2kenc: Make encoder init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=99ed54334053bb78a37545c4844cff6b4c9e658d
---

 libavcodec/j2kenc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 17eb959d73..82ad3284b5 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -74,6 +74,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avstring.h"
+#include "libavutil/thread.h"
 
 #define NMSEDEC_BITS 7
 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
@@ -591,6 +592,7 @@ static void init_luts(void)
         lut_nmsedec_ref0[i] = FFMAX(((i * i - (i << NMSEDEC_BITS) + (1 << 2 * NMSEDEC_FRACBITS) + (1 << (NMSEDEC_FRACBITS - 1))) & mask)
                                     << 1, 0);
     }
+    ff_jpeg2000_init_tier1_luts();
 }
 
 /* tier-1 routines */
@@ -1713,6 +1715,7 @@ static int parse_layer_rates(Jpeg2000EncoderContext *s)
 
 static av_cold int j2kenc_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     int i, ret;
     Jpeg2000EncoderContext *s = avctx->priv_data;
     Jpeg2000CodingStyle *codsty = &s->codsty;
@@ -1779,8 +1782,7 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
             return ret;
     }
 
-    ff_jpeg2000_init_tier1_luts();
-    init_luts();
+    ff_thread_once(&init_static_once, init_luts);
 
     init_quantization(s);
     if ((ret=init_tiles(s)) < 0)
@@ -1849,5 +1851,5 @@ const AVCodec ff_jpeg2000_encoder = {
         AV_PIX_FMT_NONE
     },
     .priv_class     = &j2k_class,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };



More information about the ffmpeg-cvslog mailing list