aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-27 03:29:12 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-29 00:01:53 +0100
commitda860802adcc2ff123f157d483f408b1faf19b1d (patch)
tree81ac7348442c4904055cd56a6099435b40c0fb96
parent5baee59301bdf7f6dbf80ceaf5d5b38c9b385571 (diff)
downloadffmpeg-da860802adcc2ff123f157d483f408b1faf19b1d.tar.gz
avcodec/svq1dec: Make decoder init-threadsafe
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r--libavcodec/svq1dec.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index e67b460ae3..7aea138060 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -33,6 +33,7 @@
*/
#include "libavutil/crc.h"
+#include "libavutil/thread.h"
#include "avcodec.h"
#include "get_bits.h"
@@ -762,22 +763,8 @@ err:
return result;
}
-static av_cold int svq1_decode_init(AVCodecContext *avctx)
+static av_cold void svq1_static_init(void)
{
- SVQ1Context *s = avctx->priv_data;
- int i;
- int offset = 0;
-
- s->prev = av_frame_alloc();
- if (!s->prev)
- return AVERROR(ENOMEM);
-
- s->width = avctx->width + 3 & ~3;
- s->height = avctx->height + 3 & ~3;
- avctx->pix_fmt = AV_PIX_FMT_YUV410P;
-
- ff_hpeldsp_init(&s->hdsp, avctx->flags);
-
INIT_VLC_STATIC(&svq1_block_type, 2, 4,
&ff_svq1_block_type_vlc[0][1], 2, 1,
&ff_svq1_block_type_vlc[0][0], 2, 1, 6);
@@ -786,7 +773,7 @@ static av_cold int svq1_decode_init(AVCodecContext *avctx)
&ff_mvtab[0][1], 2, 1,
&ff_mvtab[0][0], 2, 1, 176);
- for (i = 0; i < 6; i++) {
+ for (int i = 0, offset = 0; i < 6; i++) {
static const uint8_t sizes[2][6] = { { 14, 10, 14, 18, 16, 18 },
{ 10, 10, 14, 14, 14, 16 } };
static VLC_TYPE table[168][2];
@@ -813,6 +800,24 @@ static av_cold int svq1_decode_init(AVCodecContext *avctx)
INIT_VLC_STATIC(&svq1_inter_mean, 9, 512,
&ff_svq1_inter_mean_vlc[0][1], 4, 2,
&ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434);
+}
+
+static av_cold int svq1_decode_init(AVCodecContext *avctx)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
+ SVQ1Context *s = avctx->priv_data;
+
+ s->prev = av_frame_alloc();
+ if (!s->prev)
+ return AVERROR(ENOMEM);
+
+ s->width = avctx->width + 3 & ~3;
+ s->height = avctx->height + 3 & ~3;
+ avctx->pix_fmt = AV_PIX_FMT_YUV410P;
+
+ ff_hpeldsp_init(&s->hdsp, avctx->flags);
+
+ ff_thread_once(&init_static_once, svq1_static_init);
return 0;
}
@@ -848,4 +853,5 @@ AVCodec ff_svq1_decoder = {
.flush = svq1_flush,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV410P,
AV_PIX_FMT_NONE },
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
};