mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/mpegaudiodsp: Make initializing synth windows thread-safe
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>
This commit is contained in:
parent
ead3134150
commit
16bb8247b4
@ -34,11 +34,6 @@
|
|||||||
#include "mpc.h"
|
#include "mpc.h"
|
||||||
#include "mpcdata.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
|
* 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];
|
DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
|
||||||
} MPCContext;
|
} MPCContext;
|
||||||
|
|
||||||
void ff_mpc_init(void);
|
|
||||||
void ff_mpc_dequantize_and_synth(MPCContext *c, int maxband, int16_t **out, int channels);
|
void ff_mpc_dequantize_and_synth(MPCContext *c, int maxband, int16_t **out, int channels);
|
||||||
|
|
||||||
#endif /* AVCODEC_MPC_H */
|
#endif /* AVCODEC_MPC_H */
|
||||||
|
@ -71,7 +71,6 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
|
|||||||
ff_bswapdsp_init(&c->bdsp);
|
ff_bswapdsp_init(&c->bdsp);
|
||||||
ff_mpadsp_init(&c->mpadsp);
|
ff_mpadsp_init(&c->mpadsp);
|
||||||
c->bdsp.bswap_buf((uint32_t *) buf, (const uint32_t *) avctx->extradata, 4);
|
c->bdsp.bswap_buf((uint32_t *) buf, (const uint32_t *) avctx->extradata, 4);
|
||||||
ff_mpc_init();
|
|
||||||
init_get_bits(&gb, buf, 128);
|
init_get_bits(&gb, buf, 128);
|
||||||
|
|
||||||
c->IS = get_bits1(&gb);
|
c->IS = get_bits1(&gb);
|
||||||
@ -114,6 +113,7 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
vlc_initialized = 1;
|
vlc_initialized = 1;
|
||||||
|
ff_mpa_synth_init_fixed();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,6 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
|
|||||||
av_lfg_init(&c->rnd, 0xDEADBEEF);
|
av_lfg_init(&c->rnd, 0xDEADBEEF);
|
||||||
ff_mpadsp_init(&c->mpadsp);
|
ff_mpadsp_init(&c->mpadsp);
|
||||||
|
|
||||||
ff_mpc_init();
|
|
||||||
|
|
||||||
init_get_bits(&gb, avctx->extradata, 16);
|
init_get_bits(&gb, avctx->extradata, 16);
|
||||||
|
|
||||||
skip_bits(&gb, 3);//sample rate
|
skip_bits(&gb, 3);//sample rate
|
||||||
@ -232,6 +230,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
|
|||||||
&mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
|
&mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
|
||||||
}
|
}
|
||||||
vlc_initialized = 1;
|
vlc_initialized = 1;
|
||||||
|
ff_mpa_synth_init_fixed();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -289,8 +289,6 @@ static av_cold void decode_init_static(void)
|
|||||||
scale_factor_mult[i][2]);
|
scale_factor_mult[i][2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
RENAME(ff_mpa_synth_init)(RENAME(ff_mpa_synth_window));
|
|
||||||
|
|
||||||
/* huffman decode tables */
|
/* huffman decode tables */
|
||||||
offset = 0;
|
offset = 0;
|
||||||
for (i = 1; i < 16; i++) {
|
for (i = 1; i < 16; i++) {
|
||||||
@ -408,6 +406,7 @@ static av_cold void decode_init_static(void)
|
|||||||
csa_table[i][3] = ca - cs;
|
csa_table[i][3] = ca - cs;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
RENAME(ff_mpa_synth_init)();
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int decode_init(AVCodecContext * avctx)
|
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_mipsfpu(MPADSPContext *s);
|
||||||
void ff_mpadsp_init_mipsdsp(MPADSPContext *s);
|
void ff_mpadsp_init_mipsdsp(MPADSPContext *s);
|
||||||
|
|
||||||
void ff_mpa_synth_init_float(float *window);
|
void ff_mpa_synth_init_float(void);
|
||||||
void ff_mpa_synth_init_fixed(int32_t *window);
|
void ff_mpa_synth_init_fixed(void);
|
||||||
|
|
||||||
void ff_mpadsp_apply_window_float(float *synth_buf, float *window,
|
void ff_mpadsp_apply_window_float(float *synth_buf, float *window,
|
||||||
int *dither_state, float *samples,
|
int *dither_state, float *samples,
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "libavutil/attributes.h"
|
#include "libavutil/attributes.h"
|
||||||
#include "libavutil/mem.h"
|
#include "libavutil/mem.h"
|
||||||
|
#include "libavutil/thread.h"
|
||||||
#include "dct32.h"
|
#include "dct32.h"
|
||||||
#include "mathops.h"
|
#include "mathops.h"
|
||||||
#include "mpegaudiodsp.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;
|
*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;
|
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];
|
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) */
|
/* cos(pi*i/18) */
|
||||||
#define C1 FIXHR(0.98480775301220805936/2)
|
#define C1 FIXHR(0.98480775301220805936/2)
|
||||||
#define C2 FIXHR(0.93969262078590838405/2)
|
#define C2 FIXHR(0.93969262078590838405/2)
|
||||||
|
@ -1604,11 +1604,12 @@ static av_cold void qdm2_init_static_data(void) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
qdm2_init_vlc();
|
qdm2_init_vlc();
|
||||||
ff_mpa_synth_init_float(ff_mpa_synth_window_float);
|
|
||||||
softclip_table_init();
|
softclip_table_init();
|
||||||
rnd_table_init();
|
rnd_table_init();
|
||||||
init_noise_samples();
|
init_noise_samples();
|
||||||
|
|
||||||
|
ff_mpa_synth_init_float();
|
||||||
|
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user