diff mbox series

[FFmpeg-devel,2/3] avcodec/mlpdec: Make decoders init-threadsafe

Message ID 20201121121728.1018014-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 34aa85cd9113bde646af51440aa4528314ddfae3
Headers show
Series [FFmpeg-devel,1/3] avcodec/mlp: Make initializing CRCs thread-safe
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. 21, 2020, 12:17 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/mlpdec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 1a2c0f29ac..ec346868c6 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -30,6 +30,7 @@ 
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/thread.h"
 #include "get_bits.h"
 #include "internal.h"
 #include "libavutil/crc.h"
@@ -205,7 +206,6 @@  static VLC huff_vlc[3];
 
 static av_cold void init_static(void)
 {
-    if (!huff_vlc[0].bits) {
         INIT_VLC_STATIC(&huff_vlc[0], VLC_BITS, 18,
                     &ff_mlp_huffman_tables[0][0][1], 2, 1,
                     &ff_mlp_huffman_tables[0][0][0], 2, 1, VLC_STATIC_SIZE);
@@ -215,7 +215,6 @@  static av_cold void init_static(void)
         INIT_VLC_STATIC(&huff_vlc[2], VLC_BITS, 15,
                     &ff_mlp_huffman_tables[2][0][1], 2, 1,
                     &ff_mlp_huffman_tables[2][0][0], 2, 1, VLC_STATIC_SIZE);
-    }
 
     ff_mlp_init_crc();
 }
@@ -279,15 +278,17 @@  static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp,
 
 static av_cold int mlp_decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     MLPDecodeContext *m = avctx->priv_data;
     int substr;
 
-    init_static();
     m->avctx = avctx;
     for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
         m->substream[substr].lossless_check_data = 0xffffffff;
     ff_mlpdsp_init(&m->dsp);
 
+    ff_thread_once(&init_static_once, init_static);
+
     return 0;
 }
 
@@ -1339,6 +1340,7 @@  AVCodec ff_mlp_decoder = {
     .init           = mlp_decode_init,
     .decode         = read_access_unit,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
 #if CONFIG_TRUEHD_DECODER
@@ -1351,5 +1353,6 @@  AVCodec ff_truehd_decoder = {
     .init           = mlp_decode_init,
     .decode         = read_access_unit,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif /* CONFIG_TRUEHD_DECODER */