/*
* MPEG Audio decoder
- * Copyright (c) 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2001, 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
*
*/
/**
- * @file mpegaudiodec.c
+ * @file libavcodec/mpegaudiodec.c
* MPEG Audio decoder.
*/
#include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
#include "dsputil.h"
/*
* - test lsf / mpeg25 extensively.
*/
-/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
- audio decoder */
-#ifdef CONFIG_MPEGAUDIO_HP
-# define USE_HIGHPRECISION
-#endif
-
#include "mpegaudio.h"
#include "mpegaudiodecheader.h"
};
#endif
-static void int_pow_init(void)
+static av_cold void int_pow_init(void)
{
int i, a;
}
#endif
-static int decode_init(AVCodecContext * avctx)
+static av_cold int decode_init(AVCodecContext * avctx)
{
MPADecodeContext *s = avctx->priv_data;
static int init=0;
s->avctx = avctx;
-#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
- avctx->sample_fmt= SAMPLE_FMT_S32;
-#else
- avctx->sample_fmt= SAMPLE_FMT_S16;
-#endif
+ avctx->sample_fmt= OUT_FMT;
s->error_recognition= avctx->error_recognition;
if(avctx->antialias_algo != FF_AA_FLOAT)
int n, norm;
n = i + 2;
norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
- scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
- scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
- scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
+ scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm, FRAC_BITS);
+ scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm, FRAC_BITS);
+ scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm, FRAC_BITS);
dprintf(avctx, "%d: norm=%x s=%x %x %x\n",
i, norm,
scale_factor_mult[i][0],
for(i=1;i<16;i++) {
const HuffTable *h = &mpa_huff_tables[i];
int xsize, x, y;
- unsigned int n;
uint8_t tmp_bits [512];
uint16_t tmp_codes[512];
memset(tmp_codes, 0, sizeof(tmp_codes));
xsize = h->xsize;
- n = xsize * xsize;
j = 0;
for(x=0;x<xsize;x++) {
int sum1;
sum1 = (*sum) >> OUT_SHIFT;
*sum &= (1<<OUT_SHIFT)-1;
- if (sum1 < OUT_MIN)
- sum1 = OUT_MIN;
- else if (sum1 > OUT_MAX)
- sum1 = OUT_MAX;
- return sum1;
+ return av_clip(sum1, OUT_MIN, OUT_MAX);
}
/* signed 16x16 -> 32 multiply add accumulate */
int sum1;
sum1 = (int)((*sum) >> OUT_SHIFT);
*sum &= (1<<OUT_SHIFT)-1;
- if (sum1 < OUT_MIN)
- sum1 = OUT_MIN;
- else if (sum1 > OUT_MAX)
- sum1 = OUT_MAX;
- return sum1;
+ return av_clip(sum1, OUT_MIN, OUT_MAX);
}
# define MULS(ra, rb) MUL64(ra, rb)
#define SUM8(op, sum, w, p) \
{ \
- op(sum, (w)[0 * 64], p[0 * 64]); \
- op(sum, (w)[1 * 64], p[1 * 64]); \
- op(sum, (w)[2 * 64], p[2 * 64]); \
- op(sum, (w)[3 * 64], p[3 * 64]); \
- op(sum, (w)[4 * 64], p[4 * 64]); \
- op(sum, (w)[5 * 64], p[5 * 64]); \
- op(sum, (w)[6 * 64], p[6 * 64]); \
- op(sum, (w)[7 * 64], p[7 * 64]); \
+ op(sum, (w)[0 * 64], (p)[0 * 64]); \
+ op(sum, (w)[1 * 64], (p)[1 * 64]); \
+ op(sum, (w)[2 * 64], (p)[2 * 64]); \
+ op(sum, (w)[3 * 64], (p)[3 * 64]); \
+ op(sum, (w)[4 * 64], (p)[4 * 64]); \
+ op(sum, (w)[5 * 64], (p)[5 * 64]); \
+ op(sum, (w)[6 * 64], (p)[6 * 64]); \
+ op(sum, (w)[7 * 64], (p)[7 * 64]); \
}
#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
op2(sum2, (w2)[7 * 64], tmp);\
}
-void ff_mpa_synth_init(MPA_INT *window)
+void av_cold ff_mpa_synth_init(MPA_INT *window)
{
int i;
OUT_INT *samples, int incr,
int32_t sb_samples[SBLIMIT])
{
- int32_t tmp[32];
register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p;
- int j, offset, v;
+ int j, offset;
OUT_INT *samples2;
#if FRAC_BITS <= 15
+ int32_t tmp[32];
int sum, sum2;
#else
int64_t sum, sum2;
#endif
- dct32(tmp, sb_samples);
-
offset = *synth_buf_offset;
synth_buf = synth_buf_ptr + offset;
- for(j=0;j<32;j++) {
- v = tmp[j];
#if FRAC_BITS <= 15
+ dct32(tmp, sb_samples);
+ for(j=0;j<32;j++) {
/* NOTE: can cause a loss in precision if very high amplitude
sound */
- v = av_clip_int16(v);
-#endif
- synth_buf[j] = v;
+ synth_buf[j] = av_clip_int16(tmp[j]);
}
+#else
+ dct32(synth_buf, sb_samples);
+#endif
+
/* copy to avoid wrap */
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
t2 = tmp[i + 1];
t3 = tmp[i + 3];
s1 = MULH(2*(t3 + t2), icos36h[j]);
- s3 = MULL(t3 - t2, icos36[8 - j]);
+ s3 = MULL(t3 - t2, icos36[8 - j], FRAC_BITS);
t0 = s0 + s1;
t1 = s0 - s1;
v2 = is_tab[1][sf];
for(j=0;j<len;j++) {
tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
+ tab0[j] = MULL(tmp0, v1, FRAC_BITS);
+ tab1[j] = MULL(tmp0, v2, FRAC_BITS);
}
} else {
found1:
for(j=0;j<len;j++) {
tmp0 = tab0[j];
tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
+ tab0[j] = MULL(tmp0 + tmp1, ISQRT2, FRAC_BITS);
+ tab1[j] = MULL(tmp0 - tmp1, ISQRT2, FRAC_BITS);
}
}
}
v2 = is_tab[1][sf];
for(j=0;j<len;j++) {
tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
+ tab0[j] = MULL(tmp0, v1, FRAC_BITS);
+ tab1[j] = MULL(tmp0, v2, FRAC_BITS);
}
} else {
found2:
for(j=0;j<len;j++) {
tmp0 = tab0[j];
tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
+ tab0[j] = MULL(tmp0 + tmp1, ISQRT2, FRAC_BITS);
+ tab1[j] = MULL(tmp0 - tmp1, ISQRT2, FRAC_BITS);
}
}
}
for(ch=0;ch<s->nb_channels;ch++) {
g = &granules[ch][gr];
if(get_bits_count(&s->gb)<0){
- av_log(s->avctx, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skipping granule %d\n",
+ av_log(s->avctx, AV_LOG_DEBUG, "mdb:%d, lastbuf:%d skipping granule %d\n",
main_data_begin, s->last_buf_size, gr);
skip_bits_long(&s->gb, g->part2_3_length);
memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid));
static int decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
- const uint8_t * buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
MPADecodeContext *s = avctx->priv_data;
uint32_t header;
int out_size;
OUT_INT *out_samples = data;
-retry:
if(buf_size < HEADER_SIZE)
return -1;
header = AV_RB32(buf);
if(ff_mpa_check_header(header) < 0){
- buf++;
-// buf_size--;
- av_log(avctx, AV_LOG_ERROR, "Header missing skipping one byte.\n");
- goto retry;
+ av_log(avctx, AV_LOG_ERROR, "Header missing\n");
+ return -1;
}
- if (ff_mpegaudio_decode_header(s, header) == 1) {
+ if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
/* free format: prepare to compute frame size */
s->frame_size = -1;
return -1;
avctx->bit_rate = s->bit_rate;
avctx->sub_id = s->layer;
+ if(*data_size < 1152*avctx->channels*sizeof(OUT_INT))
+ return -1;
+ *data_size = 0;
+
if(s->frame_size<=0 || s->frame_size > buf_size){
av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
return -1;
s->last_buf_size= 0;
}
-#ifdef CONFIG_MP3ADU_DECODER
+#if CONFIG_MP3ADU_DECODER
static int decode_frame_adu(AVCodecContext * avctx,
void *data, int *data_size,
- const uint8_t * buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
MPADecodeContext *s = avctx->priv_data;
uint32_t header;
int len, out_size;
return buf_size;
}
- ff_mpegaudio_decode_header(s, header);
+ ff_mpegaudio_decode_header((MPADecodeHeader *)s, header);
/* update codec info */
avctx->sample_rate = s->sample_rate;
avctx->channels = s->nb_channels;
}
#endif /* CONFIG_MP3ADU_DECODER */
-#ifdef CONFIG_MP3ON4_DECODER
+#if CONFIG_MP3ON4_DECODER
/**
* Context for MP3On4 decoder
}
-static int decode_close_mp3on4(AVCodecContext * avctx)
+static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
{
MP3On4DecodeContext *s = avctx->priv_data;
int i;
static int decode_frame_mp3on4(AVCodecContext * avctx,
void *data, int *data_size,
- const uint8_t * buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
MP3On4DecodeContext *s = avctx->priv_data;
MPADecodeContext *m;
int fsize, len = buf_size, out_size = 0;
OUT_INT *outptr, *bp;
int fr, j, n;
+ if(*data_size < MPA_FRAME_SIZE * MPA_MAX_CHANNELS * s->frames * sizeof(OUT_INT))
+ return -1;
+
*data_size = 0;
// Discard too short frames
if (buf_size < HEADER_SIZE)
if (ff_mpa_check_header(header) < 0) // Bad header, discard block
break;
- ff_mpegaudio_decode_header(m, header);
+ ff_mpegaudio_decode_header((MPADecodeHeader *)m, header);
out_size += mp_decode_frame(m, outptr, buf, fsize);
buf += fsize;
len -= fsize;
}
#endif /* CONFIG_MP3ON4_DECODER */
-#ifdef CONFIG_MP2_DECODER
+#if CONFIG_MP1_DECODER
+AVCodec mp1_decoder =
+{
+ "mp1",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_MP1,
+ sizeof(MPADecodeContext),
+ decode_init,
+ NULL,
+ NULL,
+ decode_frame,
+ CODEC_CAP_PARSE_ONLY,
+ .flush= flush,
+ .long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
+};
+#endif
+#if CONFIG_MP2_DECODER
AVCodec mp2_decoder =
{
"mp2",
.long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
};
#endif
-#ifdef CONFIG_MP3_DECODER
+#if CONFIG_MP3_DECODER
AVCodec mp3_decoder =
{
"mp3",
.long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
};
#endif
-#ifdef CONFIG_MP3ADU_DECODER
+#if CONFIG_MP3ADU_DECODER
AVCodec mp3adu_decoder =
{
"mp3adu",
.long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
};
#endif
-#ifdef CONFIG_MP3ON4_DECODER
+#if CONFIG_MP3ON4_DECODER
AVCodec mp3on4_decoder =
{
"mp3on4",