diff mbox series

[FFmpeg-devel,28/30] avcodec/dvdec: Make decoder init-threadsafe

Message ID 20201230233157.1055287-28-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,01/30] avcodec/opustab: Make array static | expand

Checks

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

Commit Message

Andreas Rheinhardt Dec. 30, 2020, 11:31 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/dvdec.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index 85619a42a8..e36df10d1b 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -39,6 +39,7 @@ 
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/thread.h"
 
 #include "avcodec.h"
 #include "dv.h"
@@ -141,12 +142,6 @@  static void dv_init_static(void)
     uint8_t    new_dv_vlc_run[NB_DV_VLC * 2];
     int16_t  new_dv_vlc_level[NB_DV_VLC * 2];
     int i, j;
-    static int done = 0;
-
-    if (done)
-        return;
-
-    done = 1;
 
     /* it's faster to include sign bit in a generic VLC parsing scheme */
     for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) {
@@ -239,6 +234,7 @@  static void dv_init_weight_tables(DVVideoContext *ctx, const AVDVProfile *d)
 
 static av_cold int dvvideo_decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     DVVideoContext *s = avctx->priv_data;
     int i;
 
@@ -258,7 +254,7 @@  static av_cold int dvvideo_decode_init(AVCodecContext *avctx)
     s->idct_put[0] = s->idsp.idct_put;
     s->idct_put[1] = ff_simple_idct248_put;
 
-    dv_init_static();
+    ff_thread_once(&init_static_once, dv_init_static);
 
     return ff_dvvideo_init(avctx);
 }
@@ -694,4 +690,5 @@  AVCodec ff_dvvideo_decoder = {
     .decode         = dvvideo_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
     .max_lowres     = 3,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };