@@ -34,11 +34,6 @@
#include "mpc.h"
#include "mpcdata.h"
-av_cold void ff_mpc_init(void)
-{
- ff_mpa_synth_init_fixed(ff_mpa_synth_window_fixed);
-}
-
/**
* Process decoded Musepack data and produce PCM
*/
@@ -70,7 +70,6 @@ typedef struct MPCContext {
DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
} MPCContext;
-void ff_mpc_init(void);
void ff_mpc_dequantize_and_synth(MPCContext *c, int maxband, int16_t **out, int channels);
#endif /* AVCODEC_MPC_H */
@@ -64,7 +64,6 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
ff_bswapdsp_init(&c->bdsp);
ff_mpadsp_init(&c->mpadsp);
c->bdsp.bswap_buf((uint32_t *) buf, (const uint32_t *) avctx->extradata, 4);
- ff_mpc_init();
init_get_bits(&gb, buf, 128);
c->IS = get_bits1(&gb);
@@ -109,6 +108,7 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
}
}
vlc_initialized = 1;
+ ff_mpa_synth_init_fixed();
return 0;
}
@@ -126,8 +126,6 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
av_lfg_init(&c->rnd, 0xDEADBEEF);
ff_mpadsp_init(&c->mpadsp);
- ff_mpc_init();
-
init_get_bits(&gb, avctx->extradata, 16);
skip_bits(&gb, 3);//sample rate
@@ -171,6 +169,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
&q_syms, -((8 << j) - 1));
}
vlc_initialized = 1;
+ ff_mpa_synth_init_fixed();
return 0;
}
@@ -289,8 +289,6 @@ static av_cold void decode_init_static(void)
scale_factor_mult[i][2]);
}
- RENAME(ff_mpa_synth_init)(RENAME(ff_mpa_synth_window));
-
/* huffman decode tables */
offset = 0;
for (i = 1; i < 16; i++) {
@@ -408,6 +406,7 @@ static av_cold void decode_init_static(void)
csa_table[i][3] = ca - cs;
#endif
}
+ RENAME(ff_mpa_synth_init)();
}
static av_cold int decode_init(AVCodecContext * avctx)
@@ -67,8 +67,8 @@ void ff_mpadsp_init_x86_tabs(void);
void ff_mpadsp_init_mipsfpu(MPADSPContext *s);
void ff_mpadsp_init_mipsdsp(MPADSPContext *s);
-void ff_mpa_synth_init_float(float *window);
-void ff_mpa_synth_init_fixed(int32_t *window);
+void ff_mpa_synth_init_float(void);
+void ff_mpa_synth_init_fixed(void);
void ff_mpadsp_apply_window_float(float *synth_buf, float *window,
int *dither_state, float *samples,
@@ -22,6 +22,7 @@
#include "libavutil/attributes.h"
#include "libavutil/mem.h"
+#include "libavutil/thread.h"
#include "dct32.h"
#include "mathops.h"
#include "mpegaudiodsp.h"
@@ -192,7 +193,7 @@ void RENAME(ff_mpa_synth_filter)(MPADSPContext *s, MPA_INT *synth_buf_ptr,
*synth_buf_offset = offset;
}
-av_cold void RENAME(ff_mpa_synth_init)(MPA_INT *window)
+static av_cold void mpa_synth_init(MPA_INT *window)
{
int i, j;
@@ -221,6 +222,17 @@ av_cold void RENAME(ff_mpa_synth_init)(MPA_INT *window)
window[512+128+16*i+j] = window[64*i+48-j];
}
+static av_cold void mpa_synth_window_init(void)
+{
+ mpa_synth_init(RENAME(ff_mpa_synth_window));
+}
+
+av_cold void RENAME(ff_mpa_synth_init)(void)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
+ ff_thread_once(&init_static_once, mpa_synth_window_init);
+}
+
/* cos(pi*i/18) */
#define C1 FIXHR(0.98480775301220805936/2)
#define C2 FIXHR(0.93969262078590838405/2)
@@ -1604,11 +1604,12 @@ static av_cold void qdm2_init_static_data(void) {
return;
qdm2_init_vlc();
- ff_mpa_synth_init_float(ff_mpa_synth_window_float);
softclip_table_init();
rnd_table_init();
init_noise_samples();
+ ff_mpa_synth_init_float();
+
done = 1;
}
These arrays are used by the Musepack decoders, the MPEG audio decoders as well as qdm2 and up until now, these arrays might be initialized more than once, leading to potential data races as well as unnecessary initializations. Therefore this commit ensures that each array will only be initialized once. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavcodec/mpc.c | 5 ----- libavcodec/mpc.h | 1 - libavcodec/mpc7.c | 2 +- libavcodec/mpc8.c | 3 +-- libavcodec/mpegaudiodec_template.c | 3 +-- libavcodec/mpegaudiodsp.h | 4 ++-- libavcodec/mpegaudiodsp_template.c | 14 +++++++++++++- libavcodec/qdm2.c | 3 ++- 8 files changed, 20 insertions(+), 15 deletions(-)