diff mbox series

[FFmpeg-devel,184/191] avcodec/asvdec: Make decoders init-threadsafe

Message ID 20201123193739.1249300-22-andreas.rheinhardt@gmail.com
State Accepted
Commit 103e8edd5eda20e343102bba65fb04aad73a232c
Headers show
Series VLC, esp. init_vlc patches | expand

Checks

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

Commit Message

Andreas Rheinhardt Nov. 23, 2020, 7:37 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/asvdec.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index 6b6d7b3fa7..d40535bed4 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -25,6 +25,7 @@ 
 
 #include "libavutil/attributes.h"
 #include "libavutil/mem.h"
+#include "libavutil/thread.h"
 
 #include "asv.h"
 #include "avcodec.h"
@@ -45,13 +46,8 @@  static VLC dc_ccp_vlc;
 static VLC ac_ccp_vlc;
 static VLC asv2_level_vlc;
 
-static av_cold void init_vlcs(ASV1Context *a)
+static av_cold void init_vlcs(void)
 {
-    static int done = 0;
-
-    if (!done) {
-        done = 1;
-
         INIT_VLC_STATIC(&ccp_vlc, CCP_VLC_BITS, 17,
                         &ff_asv_ccp_tab[0][1], 2, 1,
                         &ff_asv_ccp_tab[0][0], 2, 1, 32);
@@ -67,7 +63,6 @@  static av_cold void init_vlcs(ASV1Context *a)
         INIT_LE_VLC_STATIC(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
                            &ff_asv2_level_tab[0][1], 4, 2,
                            &ff_asv2_level_tab[0][0], 4, 2, 1024);
-    }
 }
 
 static inline int asv1_get_level(GetBitContext *gb)
@@ -286,6 +281,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
 static av_cold int decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     ASV1Context *const a = avctx->priv_data;
     const int scale      = avctx->codec_id == AV_CODEC_ID_ASV1 ? 1 : 2;
     int i;
@@ -297,7 +293,6 @@  static av_cold int decode_init(AVCodecContext *avctx)
     ff_asv_common_init(avctx);
     ff_blockdsp_init(&a->bdsp, avctx);
     ff_idctdsp_init(&a->idsp, avctx);
-    init_vlcs(a);
     ff_init_scantable(a->idsp.idct_permutation, &a->scantable, ff_asv_scantab);
     avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 
@@ -316,6 +311,8 @@  static av_cold int decode_init(AVCodecContext *avctx)
                              a->inv_qscale;
     }
 
+    ff_thread_once(&init_static_once, init_vlcs);
+
     return 0;
 }
 
@@ -340,6 +337,7 @@  AVCodec ff_asv1_decoder = {
     .close          = decode_end,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
 
@@ -353,5 +351,6 @@  AVCodec ff_asv2_decoder = {
     .init           = decode_init,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif