diff mbox series

[FFmpeg-devel,21/39] avcodec/h261dec: Make decoder init-threadsafe

Message ID 20201210111657.2276739-22-andreas.rheinhardt@gmail.com
State Accepted
Commit 7afc6d71a0b140d1615a2ccf52d2e0d55044e786
Headers show
Series Make mpegvideo encoders init-threadsafe
Related show

Checks

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

Commit Message

Andreas Rheinhardt Dec. 10, 2020, 11:16 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/h261dec.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Anton Khirnov Jan. 18, 2021, 10:46 a.m. UTC | #1
Quoting Andreas Rheinhardt (2020-12-10 12:16:39)
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/h261dec.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)

Looks ok
diff mbox series

Patch

diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 6b680a862d..61cd38caed 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -26,6 +26,7 @@ 
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/thread.h"
 #include "avcodec.h"
 #include "mpeg_er.h"
 #include "mpegutils.h"
@@ -47,12 +48,8 @@  static VLC h261_mtype_vlc;
 static VLC h261_mv_vlc;
 static VLC h261_cbp_vlc;
 
-static av_cold void h261_decode_init_vlc(H261Context *h)
+static av_cold void h261_decode_init_static(void)
 {
-    static int done = 0;
-
-    if (!done) {
-        done = 1;
         INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
                         ff_h261_mba_bits, 1, 1,
                         ff_h261_mba_code, 1, 1, 662);
@@ -66,11 +63,11 @@  static av_cold void h261_decode_init_vlc(H261Context *h)
                         &ff_h261_cbp_tab[0][1], 2, 1,
                         &ff_h261_cbp_tab[0][0], 2, 1, 512);
         INIT_FIRST_VLC_RL(ff_h261_rl_tcoeff, 552);
-    }
 }
 
 static av_cold int h261_decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     H261Context *h          = avctx->priv_data;
     MpegEncContext *const s = &h->s;
 
@@ -81,10 +78,10 @@  static av_cold int h261_decode_init(AVCodecContext *avctx)
     s->low_delay   = 1;
     avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 
-    h261_decode_init_vlc(h);
-
     h->gob_start_code_skipped = 0;
 
+    ff_thread_once(&init_static_once, h261_decode_init_static);
+
     return 0;
 }
 
@@ -684,6 +681,6 @@  AVCodec ff_h261_decoder = {
     .close          = h261_decode_end,
     .decode         = h261_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
     .max_lowres     = 3,
 };