[FFmpeg-devel] [PATCH v2 045/162] avcodec/motionpixels: Make decoder init-threadsafe

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Fri Nov 20 09:19:18 EET 2020


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavcodec/motionpixels.c          | 12 ++++++++++--
 libavcodec/motionpixels_tablegen.h |  3 +--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
index 22deb9d1bd..b08a2f624b 100644
--- a/libavcodec/motionpixels.c
+++ b/libavcodec/motionpixels.c
@@ -19,6 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/thread.h"
+
+#include "config.h"
+
 #include "avcodec.h"
 #include "get_bits.h"
 #include "bswapdsp.h"
@@ -64,6 +68,7 @@ static av_cold int mp_decode_end(AVCodecContext *avctx)
 
 static av_cold int mp_decode_init(AVCodecContext *avctx)
 {
+    av_unused static AVOnce init_static_once = AV_ONCE_INIT;
     MotionPixelsContext *mp = avctx->priv_data;
     int w4 = (avctx->width  + 3) & ~3;
     int h4 = (avctx->height + 3) & ~3;
@@ -73,7 +78,6 @@ static av_cold int mp_decode_init(AVCodecContext *avctx)
         return AVERROR_INVALIDDATA;
     }
 
-    motionpixels_tableinit();
     mp->avctx = avctx;
     ff_bswapdsp_init(&mp->bdsp);
     mp->changes_map = av_mallocz_array(avctx->width, h4);
@@ -88,6 +92,10 @@ static av_cold int mp_decode_init(AVCodecContext *avctx)
     if (!mp->frame)
         return AVERROR(ENOMEM);
 
+#if !CONFIG_HARDCODED_TABLES
+    ff_thread_once(&init_static_once, motionpixels_tableinit);
+#endif
+
     return 0;
 }
 
@@ -347,5 +355,5 @@ AVCodec ff_motionpixels_decoder = {
     .close          = mp_decode_end,
     .decode         = mp_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/motionpixels_tablegen.h b/libavcodec/motionpixels_tablegen.h
index 9239b6a667..fd10c80cba 100644
--- a/libavcodec/motionpixels_tablegen.h
+++ b/libavcodec/motionpixels_tablegen.h
@@ -84,8 +84,7 @@ static av_cold void mp_build_rgb_yuv_table(YuvPixel *p)
 
 static av_cold void motionpixels_tableinit(void)
 {
-    if (!mp_rgb_yuv_table[0].u)
-        mp_build_rgb_yuv_table(mp_rgb_yuv_table);
+    mp_build_rgb_yuv_table(mp_rgb_yuv_table);
 }
 #endif /* CONFIG_HARDCODED_TABLES */
 
-- 
2.25.1



More information about the ffmpeg-devel mailing list