diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 0afe94a909..1a8a530e52 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -36,6 +36,7 @@ #include "libavutil/internal.h" #include "libavutil/mem_internal.h" #include "libavutil/opt.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "internal.h" #include "me_cmp.h" @@ -304,7 +305,7 @@ void ff_ac3_apply_rematrixing(AC3EncodeContext *s) /* * Initialize exponent tables. */ -static av_cold void exponent_init(AC3EncodeContext *s) +static av_cold void exponent_init(void) { int expstr, i, grpsize; @@ -317,9 +318,6 @@ static av_cold void exponent_init(AC3EncodeContext *s) } /* LFE */ exponent_group_tab[0][0][7] = 2; - - if (CONFIG_EAC3_ENCODER && s->eac3) - ff_eac3_exponent_init(); } @@ -2409,6 +2407,7 @@ static av_cold int allocate_buffers(AC3EncodeContext *s) av_cold int ff_ac3_encode_init(AVCodecContext *avctx) { + static AVOnce init_static_once = AV_ONCE_INIT; AC3EncodeContext *s = avctx->priv_data; int ret, frame_size_58; @@ -2448,15 +2447,15 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) s->mdct_init = ff_ac3_float_mdct_init; s->allocate_sample_buffers = ff_ac3_float_allocate_sample_buffers; } - if (CONFIG_EAC3_ENCODER && s->eac3) + if (CONFIG_EAC3_ENCODER && s->eac3) { + static AVOnce init_static_once = AV_ONCE_INIT; + ff_thread_once(&init_static_once, ff_eac3_exponent_init); s->output_frame_header = ff_eac3_output_frame_header; - else + } else s->output_frame_header = ac3_output_frame_header; set_bandwidth(s); - exponent_init(s); - bit_alloc_init(s); ret = s->mdct_init(s); @@ -2473,5 +2472,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) dprint_options(s); + ff_thread_once(&init_static_once, exponent_init); + return 0; } diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c index 428bbfb3c5..d2e67f3214 100644 --- a/libavcodec/ac3enc_fixed.c +++ b/libavcodec/ac3enc_fixed.c @@ -155,7 +155,7 @@ AVCodec ff_ac3_fixed_encoder = { .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }, .priv_class = &ac3enc_class, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, .supported_samplerates = ff_ac3_sample_rate_tab, .channel_layouts = ff_ac3_channel_layouts, .defaults = ac3_defaults, diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c index 99863a9722..571f603182 100644 --- a/libavcodec/ac3enc_float.c +++ b/libavcodec/ac3enc_float.c @@ -153,5 +153,5 @@ AVCodec ff_ac3_encoder = { .supported_samplerates = ff_ac3_sample_rate_tab, .channel_layouts = ff_ac3_channel_layouts, .defaults = ac3_defaults, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c index 8e1032f268..00721aa645 100644 --- a/libavcodec/eac3enc.c +++ b/libavcodec/eac3enc.c @@ -266,5 +266,5 @@ AVCodec ff_eac3_encoder = { .supported_samplerates = ff_ac3_sample_rate_tab, .channel_layouts = ff_ac3_channel_layouts, .defaults = ac3_defaults, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, };