#include "libavutil/attributes.h"
#include "libavutil/float_dsp.h"
#include "libavutil/libm.h"
+#include "libavutil/mem_internal.h"
+#include "libavutil/thread.h"
+
#include "avcodec.h"
#include "bytestream.h"
#include "fft.h"
/* variable length coding (VLC) */
if (selector != 1) {
for (i = 0; i < num_codes; i++) {
- huff_symb = get_vlc2(gb, spectral_coeff_tab[selector-1].table,
- ATRAC3_VLC_BITS, 1);
- huff_symb += 1;
- code = huff_symb >> 1;
- if (huff_symb & 1)
- code = -code;
- mantissas[i] = code;
+ mantissas[i] = get_vlc2(gb, spectral_coeff_tab[selector-1].table,
+ ATRAC3_VLC_BITS, 1);
}
} else {
for (i = 0; i < num_codes; i++) {
static av_cold void atrac3_init_static_data(void)
{
VLC_TYPE (*table)[2] = atrac3_vlc_table;
+ const uint8_t (*hufftabs)[2] = atrac3_hufftabs;
int i;
init_imdct_window();
for (i = 0; i < 7; i++) {
spectral_coeff_tab[i].table = table;
spectral_coeff_tab[i].table_allocated = 256;
- init_vlc(&spectral_coeff_tab[i], ATRAC3_VLC_BITS, huff_tab_sizes[i],
- huff_bits[i], 1, 1,
- huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
+ ff_init_vlc_from_lengths(&spectral_coeff_tab[i], ATRAC3_VLC_BITS, huff_tab_sizes[i],
+ &hufftabs[0][1], 2,
+ &hufftabs[0][0], 2, 1,
+ -31, INIT_VLC_USE_NEW_STATIC, NULL);
+ hufftabs += huff_tab_sizes[i];
table += 256;
}
}
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
{
- static int static_init_done;
+ static AVOnce init_static_once = AV_ONCE_INIT;
int i, js_pair, ret;
int version, delay, samples_per_frame, frame_factor;
const uint8_t *edata_ptr = avctx->extradata;
return AVERROR(EINVAL);
}
- if (!static_init_done)
- atrac3_init_static_data();
- static_init_done = 1;
-
/* Take care of the codec-specific extradata. */
if (avctx->codec_id == AV_CODEC_ID_ATRAC3AL) {
version = 4;
return AVERROR_INVALIDDATA;
}
- if (avctx->block_align > 1024 || avctx->block_align <= 0)
+ if (avctx->block_align > 4096 || avctx->block_align <= 0)
return AVERROR(EINVAL);
q->decoded_bytes_buffer = av_mallocz(FFALIGN(avctx->block_align, 4) +
if (!q->units)
return AVERROR(ENOMEM);
+ ff_thread_once(&init_static_once, atrac3_init_static_data);
+
return 0;
}
-AVCodec ff_atrac3_decoder = {
+const AVCodec ff_atrac3_decoder = {
.name = "atrac3",
.long_name = NULL_IF_CONFIG_SMALL("ATRAC3 (Adaptive TRansform Acoustic Coding 3)"),
.type = AVMEDIA_TYPE_AUDIO,
.capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
};
-AVCodec ff_atrac3al_decoder = {
+const AVCodec ff_atrac3al_decoder = {
.name = "atrac3al",
.long_name = NULL_IF_CONFIG_SMALL("ATRAC3 AL (Adaptive TRansform Acoustic Coding 3 Advanced Lossless)"),
.type = AVMEDIA_TYPE_AUDIO,
.capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
};