summaryrefslogtreecommitdiff
path: root/libavcodec/motionpixels.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-17 10:50:01 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-24 11:35:03 +0100
commitaf7acbb4b87ae44560dd4223b39c031c54923b63 (patch)
tree9d4d642a27e248e368ae15f6da089be3f1c6555e /libavcodec/motionpixels.c
parentcc18bcdd5204feff6724486f72fafcad15640362 (diff)
avcodec/motionpixels: Make decoder init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/motionpixels.c')
-rw-r--r--libavcodec/motionpixels.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
index 927f9fdc14..909299b5ef 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"
@@ -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,
};