diff mbox series

[FFmpeg-devel,176/191] avcodec/aactab: Make AAC encoder and decoders actually init-threadsafe

Message ID 20201123193739.1249300-14-andreas.rheinhardt@gmail.com
State Accepted
Commit 7184b811690a816861976af2acac18df05512001
Headers show
Series VLC, esp. init_vlc patches | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 23, 2020, 7:37 p.m. UTC
Commit 1a29804558c13ef512d9ef73a9b0d782af4fa5f2 guarded several
initializations of static data in the AAC decoders with an AVOnce and
set the FF_CODEC_CAP_INIT_THREADSAFE flag, believing the former to be
sufficient for the latter. It wasn't, because several of these static
tables are shared with other components, so that there might be data
races if they are initialized from multiple threads. This affected
initializing the ff_sine_* tables as well as initializing the
ff_aac_pow*sf_tab tables (shared between both decoders and encoder) as
well as ff_aac_kbd_* tables (shared between encoder and floating point
decoder).

Commit 3d62e7a30fa552be52d12b31e3e0f79153aff891 set the
FF_CODEC_CAP_INIT_THREADSAFE flag for the AAC encoder. More explicitly,
this commit used the same AVOnce to guard initializing ff_aac_pow*sf_tab
in the encoder and to guard initializing the static data of each
decoder; the ensuing catastrophe was "fixed" in commit
ec0719264cb9a9d5cbaf225da48929aea24997a3 by using a single AVOnce
for each codec again. But the codec cap has not been removed and
therefore the encoder claimed to be init-threadsafe, but wasn't, because
of the same tables as above.

The ff_sine_* tables as well as ff_aac_pow*sf_tab tables have already
been fixed; this commit deals with the ff_aac_kbd_* tables, making the
encoder as well as the floating-point decoder init-threadsafe (the
fixed-point decoder is it already).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/aactab.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index b9d1336d97..abe5fd7567 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -45,13 +45,19 @@  float ff_aac_pow34sf_tab[428];
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_long_1024)[1024];
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_short_128)[128];
 
-av_cold void ff_aac_float_common_init(void)
+static av_cold void aac_float_common_init(void)
 {
     ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
     ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
     ff_init_ff_sine_windows(10);
     ff_init_ff_sine_windows(7);
 }
+
+av_cold void ff_aac_float_common_init(void)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    ff_thread_once(&init_static_once, aac_float_common_init);
+}
 #endif
 
 const uint8_t ff_aac_num_swb_1024[] = {