[FFmpeg-cvslog] aacenc: make threadsafe

Rostislav Pehlivanov git at videolan.org
Fri Nov 27 15:57:26 CET 2015


ffmpeg | branch: master | Rostislav Pehlivanov <atomnuker at gmail.com> | Fri Nov 27 14:52:35 2015 +0000| [3d62e7a30fa552be52d12b31e3e0f79153aff891] | committer: Rostislav Pehlivanov

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 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3d62e7a30fa552be52d12b31e3e0f79153aff891
---

 libavcodec/aacdec_template.c |    4 +---
 libavcodec/aacenc.c          |    4 +++-
 libavcodec/aactab.c          |    3 +++
 libavcodec/aactab.h          |    3 +++
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 70cffe6..82f4fb4 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 ca6c9dd..d6cac47 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 dc9acc1..c6e797e 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 eb91516..05bbd5f 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.



More information about the ffmpeg-cvslog mailing list