MPA_DECODE_HEADER
uint8_t last_buf[LAST_BUF_SIZE];
int last_buf_size;
+ int extrasize;
/* next header (used in free format parsing) */
uint32_t free_format_next_header;
GetBitContext gb;
scale_factor_mult[i][0] = MULLx(norm, FIXR(1.0 * 2.0), FRAC_BITS);
scale_factor_mult[i][1] = MULLx(norm, FIXR(0.7937005259 * 2.0), FRAC_BITS);
scale_factor_mult[i][2] = MULLx(norm, FIXR(0.6299605249 * 2.0), FRAC_BITS);
- ff_dlog(NULL, "%d: norm=%x s=%x %x %x\n", i, norm,
+ ff_dlog(NULL, "%d: norm=%x s=%"PRIx32" %"PRIx32" %"PRIx32"\n", i, norm,
scale_factor_mult[i][0],
scale_factor_mult[i][1],
scale_factor_mult[i][2]);
s->avctx = avctx;
- avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
+ avpriv_float_dsp_init(&s->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
ff_mpadsp_init(&s->mpadsp);
if (avctx->request_sample_fmt == OUT_FMT &&
}
}
-/* handle n = 0 too */
-static inline int get_bitsz(GetBitContext *s, int n)
-{
- return n ? get_bits(s, n) : 0;
-}
-
-
static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos,
int *end_pos2)
{
- if (s->in_gb.buffer && *pos >= s->gb.size_in_bits) {
+ if (s->in_gb.buffer && *pos >= s->gb.size_in_bits - s->extrasize * 8) {
s->gb = s->in_gb;
s->in_gb.buffer = NULL;
+ s->extrasize = 0;
assert((get_bits_count(&s->gb) & 7) == 0);
skip_bits_long(&s->gb, *pos - *end_pos);
*end_pos2 =
int i;
int last_pos, bits_left;
VLC *vlc;
- int end_pos = FFMIN(end_pos2, s->gb.size_in_bits);
+ int end_pos = FFMIN(end_pos2, s->gb.size_in_bits - s->extrasize * 8);
/* low frequencies (called big values) */
s_index = 0;
exponent= exponents[s_index];
- ff_dlog(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n",
- i, g->region_size[i] - j, x, y, exponent);
+ ff_dlog(s->avctx, "region=%d n=%d y=%d exp=%d\n",
+ i, g->region_size[i] - j, y, exponent);
if (y & 16) {
x = y >> 5;
y = y & 0x0f;
if (!s->adu_mode) {
int skip;
const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
- int extrasize = av_clip(get_bits_left(&s->gb) >> 3, 0,
- FFMAX(0, LAST_BUF_SIZE - s->last_buf_size));
+ s->extrasize = av_clip((get_bits_left(&s->gb) >> 3) - s->extrasize, 0,
+ FFMAX(0, LAST_BUF_SIZE - s->last_buf_size));
assert((get_bits_count(&s->gb) & 7) == 0);
/* now we get bits from the main_data_begin offset */
ff_dlog(s->avctx, "seekback:%d, lastbuf:%d\n",
main_data_begin, s->last_buf_size);
- memcpy(s->last_buf + s->last_buf_size, ptr, extrasize);
+ memcpy(s->last_buf + s->last_buf_size, ptr, s->extrasize);
s->in_gb = s->gb;
- init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8);
-#if !UNCHECKED_BITSTREAM_READER
- s->gb.size_in_bits_plus8 += extrasize * 8;
-#endif
+ init_get_bits(&s->gb, s->last_buf, (s->last_buf_size + s->extrasize) * 8);
s->last_buf_size <<= 3;
for (gr = 0; gr < nb_granules && (s->last_buf_size >> 3) < main_data_begin; gr++) {
for (ch = 0; ch < s->nb_channels; ch++) {
}
}
skip = s->last_buf_size - 8 * main_data_begin;
- if (skip >= s->gb.size_in_bits && s->in_gb.buffer) {
- skip_bits_long(&s->in_gb, skip - s->gb.size_in_bits);
+ if (skip >= s->gb.size_in_bits - s->extrasize * 8 && s->in_gb.buffer) {
+ skip_bits_long(&s->in_gb, skip - s->gb.size_in_bits + s->extrasize * 8);
s->gb = s->in_gb;
s->in_gb.buffer = NULL;
+ s->extrasize = 0;
} else {
skip_bits_long(&s->gb, skip);
}
} else {
gr = 0;
+ s->extrasize = 0;
}
for (; gr < nb_granules; gr++) {
uint8_t *sc;
int slen, slen1, slen2;
- /* MPEG1 scale factors */
+ /* MPEG-1 scale factors */
slen1 = slen_table[0][g->scalefac_compress];
slen2 = slen_table[1][g->scalefac_compress];
ff_dlog(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);
s->last_buf_size=0;
if (s->in_gb.buffer) {
align_get_bits(&s->gb);
- i = get_bits_left(&s->gb)>>3;
+ i = (get_bits_left(&s->gb) >> 3) - s->extrasize;
if (i >= 0 && i <= BACKSTEP_SIZE) {
memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);
s->last_buf_size=i;
av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);
s->gb = s->in_gb;
s->in_gb.buffer = NULL;
+ s->extrasize = 0;
}
align_get_bits(&s->gb);
assert((get_bits_count(&s->gb) & 7) == 0);
- i = get_bits_left(&s->gb) >> 3;
-
+ i = (get_bits_left(&s->gb) >> 3) - s->extrasize;
if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) {
if (i < 0)
av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i);
return AVERROR_INVALIDDATA;
header = AV_RB32(buf);
- if (ff_mpa_check_header(header) < 0) {
+
+ ret = avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header);
+ if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Header missing\n");
return AVERROR_INVALIDDATA;
- }
-
- if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
+ } else if (ret == 1) {
/* free format: prepare to compute frame size */
s->frame_size = -1;
return AVERROR_INVALIDDATA;
// Get header and restore sync word
header = AV_RB32(buf) | 0xffe00000;
- if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame
+ ret = avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header);
+ if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid frame header\n");
- return AVERROR_INVALIDDATA;
+ return ret;
}
-
- avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header);
/* update codec info */
avctx->sample_rate = s->sample_rate;
avctx->channels = s->nb_channels;
}
header = (AV_RB32(buf) & 0x000fffff) | s->syncword; // patch header
- if (ff_mpa_check_header(header) < 0) // Bad header, discard block
+ ret = avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header);
+ if (ret < 0) // Bad header, discard block
break;
- avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header);
-
if (ch + m->nb_channels > avctx->channels ||
s->coff[fr] + m->nb_channels > avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "