diff options
author | Rostislav Pehlivanov <atomnuker@gmail.com> | 2015-11-27 14:52:35 +0000 |
---|---|---|
committer | Rostislav Pehlivanov <atomnuker@gmail.com> | 2015-11-27 14:52:35 +0000 |
commit | 3d62e7a30fa552be52d12b31e3e0f79153aff891 (patch) | |
tree | 0aca26f2b4029afb989bee72c27c10f14a3c9405 | |
parent | 8000d484b83aafa752d84fbdbfb352ffe0dc64f8 (diff) | |
download | ffmpeg-3d62e7a30fa552be52d12b31e3e0f79153aff891.tar.gz |
aacenc: make threadsafe
Since the ff_aac_tableinit() can be called by both the encoder and
the decoder (in case of transcoding) this commit shares the AVOnce
variable to prevent this.
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
-rw-r--r-- | libavcodec/aacdec_template.c | 4 | ||||
-rw-r--r-- | libavcodec/aacenc.c | 4 | ||||
-rw-r--r-- | libavcodec/aactab.c | 3 | ||||
-rw-r--r-- | libavcodec/aactab.h | 3 |
4 files changed, 10 insertions, 4 deletions
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 70cffe6a92..82f4fb44ac 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1103,14 +1103,12 @@ static av_cold void aac_static_table_init(void) AAC_RENAME(cbrt_tableinit)(); } -static AVOnce aac_init = AV_ONCE_INIT; - static av_cold int aac_decode_init(AVCodecContext *avctx) { AACContext *ac = avctx->priv_data; int ret; - ret = ff_thread_once(&aac_init, &aac_static_table_init); + ret = ff_thread_once(&aac_table_init, &aac_static_table_init); if (ret != 0) return AVERROR_UNKNOWN; diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index ca6c9dde07..d6cac47f62 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -986,7 +986,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) if (HAVE_MIPSDSPR1) ff_aac_coder_init_mips(s); - ff_aac_tableinit(); + if ((ret = ff_thread_once(&aac_table_init, &ff_aac_tableinit)) != 0) + return AVERROR_UNKNOWN; ff_af_queue_init(avctx, &s->afq); @@ -1029,6 +1030,7 @@ AVCodec ff_aac_encoder = { .encode2 = aac_encode_frame, .close = aac_encode_end, .supported_samplerates = mpeg4audio_sample_rates, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP, diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c index dc9acc1bf3..c6e797ecbf 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 aac_table_init = 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 eb915166a2..05bbd5fab3 100644 --- a/libavcodec/aactab.h +++ b/libavcodec/aactab.h @@ -30,12 +30,15 @@ #ifndef AVCODEC_AACTAB_H #define AVCODEC_AACTAB_H +#include "libavutil/thread.h" #include "libavutil/mem.h" #include "aac.h" #include "aac_tablegen_decl.h" #include <stdint.h> +extern AVOnce aac_table_init; /* Protects ff_aac_tableinit() */ + /* NOTE: * Tables in this file are used by the AAC decoder and will be used by the AAC * encoder. |