[FFmpeg-cvslog] avcodec/svq1dec: Make decoder init-threadsafe
Andreas Rheinhardt
git at videolan.org
Sun Nov 29 01:39:33 EET 2020
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Fri Nov 27 03:29:12 2020 +0100| [da860802adcc2ff123f157d483f408b1faf19b1d] | committer: Andreas Rheinhardt
avcodec/svq1dec: Make decoder init-threadsafe
Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=da860802adcc2ff123f157d483f408b1faf19b1d
---
libavcodec/svq1dec.c | 38 ++++++++++++++++++++++----------------
1 file 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,
};
More information about the ffmpeg-cvslog
mailing list