diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-22 13:30:07 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-12-08 17:51:47 +0100 |
commit | 94a55f28aa2cd0c5afb5ee621cfcca746781079c (patch) | |
tree | 640f6590240714b355bff7b0f0573c24232be02d | |
parent | d5d1c697bd0844a676eeb7761b130b6dd951edee (diff) | |
download | ffmpeg-94a55f28aa2cd0c5afb5ee621cfcca746781079c.tar.gz |
avcodec/atrac: Make generating tables thread-safe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r-- | libavcodec/atrac.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/libavcodec/atrac.c b/libavcodec/atrac.c index 12e8997dbc..bf9878be45 100644 --- a/libavcodec/atrac.c +++ b/libavcodec/atrac.c @@ -30,6 +30,8 @@ #include <stdio.h> #include <string.h> +#include "libavutil/thread.h" + #include "avcodec.h" #include "atrac.h" @@ -45,22 +47,23 @@ static const float qmf_48tap_half[24] = { -0.043596379, -0.099384367, 0.13207909, 0.46424159 }; -av_cold void ff_atrac_generate_tables(void) +static av_cold void atrac_generate_tables(void) { - int i; - float s; - /* Generate scale factors */ - if (!ff_atrac_sf_table[63]) - for (i=0 ; i<64 ; i++) - ff_atrac_sf_table[i] = pow(2.0, (i - 15) / 3.0); + for (int i = 0; i < 64; i++) + ff_atrac_sf_table[i] = pow(2.0, (i - 15) / 3.0); /* Generate the QMF window. */ - if (!qmf_window[47]) - for (i=0 ; i<24; i++) { - s = qmf_48tap_half[i] * 2.0; - qmf_window[i] = qmf_window[47 - i] = s; - } + for (int i = 0; i < 24; i++) { + float s = qmf_48tap_half[i] * 2.0; + qmf_window[i] = qmf_window[47 - i] = s; + } +} + +av_cold void ff_atrac_generate_tables(void) +{ + static AVOnce init_static_once = AV_ONCE_INIT; + ff_thread_once(&init_static_once, atrac_generate_tables); } av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset, |