summaryrefslogtreecommitdiff
path: root/libavcodec/aacenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-19 16:54:45 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-24 11:35:03 +0100
commit195d8ce85eb73ff283f85dcee63383ec4081e3e7 (patch)
tree9e71532be20394daa1fdc4b1e637251ada721d40 /libavcodec/aacenc.c
parentc4b4cd775af0f4b83c34fd595c05d2fa99018323 (diff)
avcodec/aac*: Make initializing ff_aac_pow*sf_tab thread-safe
This table is currently initialized up to three times: Once by the encoder and twice by the decoders (once by the fixed and once by the floating-point decoder); each of these initializations is guarded by an AVOnce, yet the fact that there are three of them implies that there might be data races (the fact that each entry is only written to once (to its final value) when initializing means that this is safe in practice, yet it is still undefined behaviour). Fix this by only initializing the table from one place that is guarded by a single AVOnce. This also avoids unnecessary duplications of the init code. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/aacenc.c')
-rw-r--r--libavcodec/aacenc.c12
1 files changed, 1 insertions, 11 deletions
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index bb203981b2..274e5ca294 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -30,7 +30,6 @@
***********************************/
#include "libavutil/libm.h"
-#include "libavutil/thread.h"
#include "libavutil/float_dsp.h"
#include "libavutil/opt.h"
#include "avcodec.h"
@@ -49,8 +48,6 @@
#include "psymodel.h"
-static AVOnce aac_table_init = AV_ONCE_INIT;
-
static void put_pce(PutBitContext *pb, AVCodecContext *avctx)
{
int i, j;
@@ -951,11 +948,6 @@ static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s)
return 0;
}
-static av_cold void aac_encode_init_tables(void)
-{
- ff_aac_tableinit();
-}
-
static av_cold int aac_encode_init(AVCodecContext *avctx)
{
AACEncContext *s = avctx->priv_data;
@@ -1107,10 +1099,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
if (HAVE_MIPSDSP)
ff_aac_coder_init_mips(s);
- if ((ret = ff_thread_once(&aac_table_init, &aac_encode_init_tables)) != 0)
- return AVERROR_UNKNOWN;
-
ff_af_queue_init(avctx, &s->afq);
+ ff_aac_tableinit();
return 0;
}