This commit prevents the corner case where both the decoder and the encoder could call ff_aac_tableinit() twice during init (in case of transcoding aac-aac).
Signed-off-by: Rostislav Pehlivanov <atomnu...@gmail.com> --- libavcodec/aacdec_template.c | 10 ++++++---- libavcodec/aacenc.c | 5 +---- libavcodec/aactab.c | 3 +++ libavcodec/aactab.h | 3 +++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 620600c..a68ded6 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1081,8 +1081,6 @@ static av_cold void aac_static_table_init(void) AAC_RENAME(ff_aac_sbr_init)(); - ff_aac_tableinit(); - INIT_VLC_STATIC(&vlc_scalefactors, 7, FF_ARRAY_ELEMS(ff_aac_scalefactor_code), ff_aac_scalefactor_bits, @@ -1103,14 +1101,18 @@ static av_cold void aac_static_table_init(void) AAC_RENAME(cbrt_tableinit)(); } -static AVOnce aac_table_init = AV_ONCE_INIT; +static AVOnce aac_dec_tab_init_guard = AV_ONCE_INIT; static av_cold int aac_decode_init(AVCodecContext *avctx) { AACContext *ac = avctx->priv_data; int ret; - ret = ff_thread_once(&aac_table_init, &aac_static_table_init); + ret = ff_thread_once(&aactab_init_guard, &ff_aac_tableinit); + if (ret != 0) + return AVERROR_UNKNOWN; + + ret = ff_thread_once(&aac_dec_tab_init_guard, &aac_static_table_init); if (ret != 0) return AVERROR_UNKNOWN; diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index e49cf4b..d58aff4 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -29,7 +29,6 @@ * add sane pulse detection ***********************************/ -#include "libavutil/thread.h" #include "libavutil/float_dsp.h" #include "libavutil/opt.h" #include "avcodec.h" @@ -47,8 +46,6 @@ #include "psymodel.h" -static AVOnce aac_table_init = AV_ONCE_INIT; - /** * Make AAC audio config object. * @see 1.6.2.1 "Syntax - AudioSpecificConfig" @@ -989,7 +986,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) if (HAVE_MIPSDSPR1) ff_aac_coder_init_mips(s); - if ((ret = ff_thread_once(&aac_table_init, &ff_aac_tableinit)) != 0) + if ((ret = ff_thread_once(&aactab_init_guard, &ff_aac_tableinit)) != 0) return AVERROR_UNKNOWN; ff_af_queue_init(avctx, &s->afq); diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c index dc9acc1..667b0ba 100644 --- a/libavcodec/aactab.c +++ b/libavcodec/aactab.c @@ -27,12 +27,15 @@ * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) */ +#include "libavutil/thread.h" #include "libavutil/mem.h" #include "aac.h" #include "aac_tablegen.h" #include <stdint.h> +AVOnce aactab_init_guard = AV_ONCE_INIT; + DECLARE_ALIGNED(32, float, ff_aac_kbd_long_1024)[1024]; DECLARE_ALIGNED(32, float, ff_aac_kbd_short_128)[128]; DECLARE_ALIGNED(32, int, ff_aac_kbd_long_1024_fixed)[1024]; diff --git a/libavcodec/aactab.h b/libavcodec/aactab.h index 321c5d3..18c46a6 100644 --- a/libavcodec/aactab.h +++ b/libavcodec/aactab.h @@ -30,6 +30,7 @@ #ifndef AVCODEC_AACTAB_H #define AVCODEC_AACTAB_H +#include "libavutil/thread.h" #include "libavutil/mem.h" #include "aac.h" #include "aac_tablegen_decl.h" @@ -40,6 +41,8 @@ * Tables in this file are shared by the AAC decoders and encoder */ +extern AVOnce aactab_init_guard; /* Protects ff_aac_tableinit() */ + /* @name ltp_coef * Table of the LTP coefficients */ -- 2.6.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel