]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/motionpixels: Make decoder init-threadsafe
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 17 Nov 2020 09:50:01 +0000 (10:50 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 24 Nov 2020 10:35:03 +0000 (11:35 +0100)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/motionpixels.c
libavcodec/motionpixels_tablegen.h

index 927f9fdc14015e93c5c3226ede4ac7fdf1b8d396..909299b5ef454132d14cdc2de35dc7ddcb030d41 100644 (file)
  * 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"
@@ -65,6 +69,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;
@@ -74,7 +79,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);
@@ -89,6 +93,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;
 }
 
@@ -348,5 +356,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,
 };
index 9239b6a66730bb862ba8002b71685d84322b7a65..fd10c80cbac5cf3e37b1556d0625b29c7db60df8 100644 (file)
@@ -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 */