diff mbox series

[FFmpeg-devel,7/7] avcodec/ac3dec: Make decoders init-threadsafe

Message ID 20201205203340.19357-7-andreas.rheinhardt@gmail.com
State Accepted
Commit 42ee3898c8cfc56b70a68cd3d285953e5802444f
Headers show
Series [FFmpeg-devel,1/7] avcodec/[e]ac3enc: Make encoders init-threadsafe, fix race
Related show

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. 5, 2020, 8:33 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/ac3dec.c       | 5 ++++-
 libavcodec/ac3dec_fixed.c | 2 +-
 libavcodec/ac3dec_float.c | 4 ++--
 3 files changed, 7 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 3e4bec56b1..c7deb56e1c 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -33,6 +33,7 @@ 
 #include "libavutil/crc.h"
 #include "libavutil/downmix_info.h"
 #include "libavutil/opt.h"
+#include "libavutil/thread.h"
 #include "bswapdsp.h"
 #include "internal.h"
 #include "aac_ac3_parser.h"
@@ -183,12 +184,12 @@  static av_cold void ac3_tables_init(void)
  */
 static av_cold int ac3_decode_init(AVCodecContext *avctx)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
     AC3DecodeContext *s = avctx->priv_data;
     int i, ret;
 
     s->avctx = avctx;
 
-    ac3_tables_init();
     if ((ret = ff_mdct_init(&s->imdct_256, 8, 1, 1.0)) < 0 ||
         (ret = ff_mdct_init(&s->imdct_512, 9, 1, 1.0)) < 0)
         return ret;
@@ -226,6 +227,8 @@  static av_cold int ac3_decode_init(AVCodecContext *avctx)
         s->dlyptr[i] = s->delay[i];
     }
 
+    ff_thread_once(&init_static_once, ac3_tables_init);
+
     return 0;
 }
 
diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c
index 662cb8169e..daab433295 100644
--- a/libavcodec/ac3dec_fixed.c
+++ b/libavcodec/ac3dec_fixed.c
@@ -182,5 +182,5 @@  AVCodec ff_ac3_fixed_decoder = {
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
                                                       AV_SAMPLE_FMT_NONE },
     .priv_class     = &ac3_decoder_class,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c
index 5010ee0ca5..b18317f8b3 100644
--- a/libavcodec/ac3dec_float.c
+++ b/libavcodec/ac3dec_float.c
@@ -67,7 +67,7 @@  AVCodec ff_ac3_decoder = {
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
     .priv_class     = &ac3_decoder_class,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
 
 #if CONFIG_EAC3_DECODER
@@ -92,6 +92,6 @@  AVCodec ff_eac3_decoder = {
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
     .priv_class     = &eac3_decoder_class,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif