diff mbox series

[FFmpeg-devel,47/72] avcodec/svq1dec: Make decoder init-threadsafe

Message ID 20201127174652.2838198-2-andreas.rheinhardt@gmail.com
State Accepted
Commit da860802adcc2ff123f157d483f408b1faf19b1d
Headers show
Series [FFmpeg-devel,01/45] avcodec/a64multienc: Fix memleak upon init failure
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 27, 2020, 5:46 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/svq1dec.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

Comments

Michael Niedermayer Nov. 27, 2020, 7:10 p.m. UTC | #1
On Fri, Nov 27, 2020 at 06:46:27PM +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/svq1dec.c | 38 ++++++++++++++++++++++----------------
>  1 file changed, 22 insertions(+), 16 deletions(-)

probably ok

thx

[...]
diff mbox series

Patch

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,
 };