2001-07-22 16:18:56 +02:00
|
|
|
/*
|
|
|
|
* MPEG Audio decoder
|
2009-01-19 16:46:40 +01:00
|
|
|
* Copyright (c) 2001, 2002 Fabrice Bellard
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-05-26 00:45:33 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 17:30:46 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2001-07-22 16:18:56 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2002-05-26 00:45:33 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-07-22 16:18:56 +02:00
|
|
|
*
|
2002-05-26 00:45:33 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 17:30:46 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 23:43:26 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-07-22 16:18:56 +02:00
|
|
|
*/
|
2003-03-06 12:32:04 +01:00
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2011-09-27 19:15:24 +02:00
|
|
|
* MPEG Audio decoder
|
2005-12-17 19:14:38 +01:00
|
|
|
*/
|
2003-03-06 12:32:04 +01:00
|
|
|
|
2011-12-18 02:23:57 +01:00
|
|
|
#define UNCHECKED_BITSTREAM_READER 1
|
|
|
|
|
2011-04-02 11:50:10 +02:00
|
|
|
#include "libavutil/audioconvert.h"
|
2001-07-22 16:18:56 +02:00
|
|
|
#include "avcodec.h"
|
2009-04-13 18:20:26 +02:00
|
|
|
#include "get_bits.h"
|
2011-05-09 14:55:24 +02:00
|
|
|
#include "mathops.h"
|
2011-05-16 17:52:01 +02:00
|
|
|
#include "mpegaudiodsp.h"
|
2001-07-22 16:18:56 +02:00
|
|
|
|
|
|
|
/*
|
2001-09-16 00:40:28 +02:00
|
|
|
* TODO:
|
|
|
|
* - test lsf / mpeg25 extensively.
|
2001-07-22 16:18:56 +02:00
|
|
|
*/
|
|
|
|
|
2005-10-18 22:16:43 +02:00
|
|
|
#include "mpegaudio.h"
|
2007-05-20 15:40:07 +02:00
|
|
|
#include "mpegaudiodecheader.h"
|
2005-01-31 13:16:21 +01:00
|
|
|
|
2011-05-17 15:22:25 +02:00
|
|
|
#define BACKSTEP_SIZE 512
|
|
|
|
#define EXTRABYTES 24
|
|
|
|
|
|
|
|
/* layer 3 "granule" */
|
|
|
|
typedef struct GranuleDef {
|
|
|
|
uint8_t scfsi;
|
|
|
|
int part2_3_length;
|
|
|
|
int big_values;
|
|
|
|
int global_gain;
|
|
|
|
int scalefac_compress;
|
|
|
|
uint8_t block_type;
|
|
|
|
uint8_t switch_point;
|
|
|
|
int table_select[3];
|
|
|
|
int subblock_gain[3];
|
|
|
|
uint8_t scalefac_scale;
|
|
|
|
uint8_t count1table_select;
|
|
|
|
int region_size[3]; /* number of huffman codes in each region */
|
|
|
|
int preflag;
|
|
|
|
int short_start, long_end; /* long/short band indexes */
|
|
|
|
uint8_t scale_factors[40];
|
2011-11-07 21:54:49 +01:00
|
|
|
DECLARE_ALIGNED(16, INTFLOAT, sb_hybrid)[SBLIMIT * 18]; /* 576 samples */
|
2011-05-17 15:22:25 +02:00
|
|
|
} GranuleDef;
|
|
|
|
|
|
|
|
typedef struct MPADecodeContext {
|
|
|
|
MPA_DECODE_HEADER
|
2011-09-27 19:15:24 +02:00
|
|
|
uint8_t last_buf[2 * BACKSTEP_SIZE + EXTRABYTES];
|
2011-05-17 15:22:25 +02:00
|
|
|
int last_buf_size;
|
|
|
|
/* next header (used in free format parsing) */
|
|
|
|
uint32_t free_format_next_header;
|
|
|
|
GetBitContext gb;
|
|
|
|
GetBitContext in_gb;
|
2011-05-14 14:17:15 +02:00
|
|
|
DECLARE_ALIGNED(32, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2];
|
2011-05-17 15:22:25 +02:00
|
|
|
int synth_buf_offset[MPA_MAX_CHANNELS];
|
2011-05-14 14:17:15 +02:00
|
|
|
DECLARE_ALIGNED(32, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
|
2011-05-17 15:22:25 +02:00
|
|
|
INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
|
|
|
|
GranuleDef granules[2][2]; /* Used in Layer 3 */
|
|
|
|
int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
|
|
|
|
int dither_state;
|
2011-10-22 14:44:16 +02:00
|
|
|
int err_recognition;
|
2011-05-17 15:22:25 +02:00
|
|
|
AVCodecContext* avctx;
|
|
|
|
MPADSPContext mpadsp;
|
2011-09-06 18:17:45 +02:00
|
|
|
AVFrame frame;
|
2011-05-17 15:22:25 +02:00
|
|
|
} MPADecodeContext;
|
|
|
|
|
2010-05-11 21:52:42 +02:00
|
|
|
#if CONFIG_FLOAT
|
2010-05-13 20:06:44 +02:00
|
|
|
# define SHR(a,b) ((a)*(1.0f/(1<<(b))))
|
2010-05-11 21:52:42 +02:00
|
|
|
# define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
|
2010-05-13 19:58:17 +02:00
|
|
|
# define FIXR(x) ((float)(x))
|
|
|
|
# define FIXHR(x) ((float)(x))
|
2010-05-11 21:52:42 +02:00
|
|
|
# define MULH3(x, y, s) ((s)*(y)*(x))
|
|
|
|
# define MULLx(x, y, s) ((y)*(x))
|
|
|
|
# define RENAME(a) a ## _float
|
2011-05-16 18:06:30 +02:00
|
|
|
# define OUT_FMT AV_SAMPLE_FMT_FLT
|
2010-05-11 21:52:42 +02:00
|
|
|
#else
|
|
|
|
# define SHR(a,b) ((a)>>(b))
|
2011-09-27 19:15:24 +02:00
|
|
|
/* WARNING: only correct for positive numbers */
|
2010-05-11 21:52:42 +02:00
|
|
|
# define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
|
|
|
|
# define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
|
|
|
|
# define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
|
|
|
|
# define MULH3(x, y, s) MULH((s)*(x), y)
|
|
|
|
# define MULLx(x, y, s) MULL(x,y,s)
|
2011-05-17 14:07:08 +02:00
|
|
|
# define RENAME(a) a ## _fixed
|
2011-05-16 18:06:30 +02:00
|
|
|
# define OUT_FMT AV_SAMPLE_FMT_S16
|
2010-05-11 21:52:42 +02:00
|
|
|
#endif
|
2005-02-01 22:27:18 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/****************/
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
#define HEADER_SIZE 4
|
|
|
|
|
2007-05-19 02:06:02 +02:00
|
|
|
#include "mpegaudiodata.h"
|
2001-09-16 00:40:28 +02:00
|
|
|
#include "mpegaudiodectab.h"
|
|
|
|
|
|
|
|
/* vlc structure for decoding layer 3 huffman tables */
|
2005-12-17 19:14:38 +01:00
|
|
|
static VLC huff_vlc[16];
|
2008-07-31 14:09:11 +02:00
|
|
|
static VLC_TYPE huff_vlc_tables[
|
2011-09-27 19:15:24 +02:00
|
|
|
0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 +
|
|
|
|
142 + 204 + 190 + 170 + 542 + 460 + 662 + 414
|
2008-07-31 14:09:11 +02:00
|
|
|
][2];
|
|
|
|
static const int huff_vlc_tables_sizes[16] = {
|
2011-09-27 19:15:24 +02:00
|
|
|
0, 128, 128, 128, 130, 128, 154, 166,
|
|
|
|
142, 204, 190, 170, 542, 460, 662, 414
|
2008-07-31 14:09:11 +02:00
|
|
|
};
|
2001-09-16 00:40:28 +02:00
|
|
|
static VLC huff_quad_vlc[2];
|
2011-09-27 19:15:24 +02:00
|
|
|
static VLC_TYPE huff_quad_vlc_tables[128+16][2];
|
|
|
|
static const int huff_quad_vlc_tables_sizes[2] = { 128, 16 };
|
2001-09-16 00:40:28 +02:00
|
|
|
/* computed from band_size_long */
|
2003-02-11 17:35:48 +01:00
|
|
|
static uint16_t band_index_long[9][23];
|
2009-10-28 19:42:52 +01:00
|
|
|
#include "mpegaudio_tablegen.h"
|
2001-09-16 00:40:28 +02:00
|
|
|
/* intensity stereo coef table */
|
2010-05-11 21:52:42 +02:00
|
|
|
static INTFLOAT is_table[2][16];
|
|
|
|
static INTFLOAT is_table_lsf[2][2][16];
|
2011-05-19 14:36:21 +02:00
|
|
|
static INTFLOAT csa_table[8][4];
|
2011-11-07 21:54:49 +01:00
|
|
|
/** Window for MDCT. Note that only the component [0,17] and [20,37] are used,
|
|
|
|
the components 18 and 19 are there only to assure 128-bit alignment for asm
|
|
|
|
*/
|
|
|
|
DECLARE_ALIGNED(16, static INTFLOAT, mdct_win)[8][40];
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2010-06-28 06:55:36 +02:00
|
|
|
static int16_t division_tab3[1<<6 ];
|
|
|
|
static int16_t division_tab5[1<<8 ];
|
|
|
|
static int16_t division_tab9[1<<11];
|
|
|
|
|
|
|
|
static int16_t * const division_tabs[4] = {
|
|
|
|
division_tab3, division_tab5, NULL, division_tab9
|
|
|
|
};
|
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* lower 2 bits: modulo 3, higher bits: shift */
|
2003-02-11 17:35:48 +01:00
|
|
|
static uint16_t scale_factor_modshift[64];
|
2001-09-16 00:40:28 +02:00
|
|
|
/* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
|
2003-02-11 17:35:48 +01:00
|
|
|
static int32_t scale_factor_mult[15][3];
|
2001-09-16 00:40:28 +02:00
|
|
|
/* mult table for layer 2 group quantization */
|
|
|
|
|
|
|
|
#define SCALE_GEN(v) \
|
2010-05-11 21:52:42 +02:00
|
|
|
{ FIXR_OLD(1.0 * (v)), FIXR_OLD(0.7937005259 * (v)), FIXR_OLD(0.6299605249 * (v)) }
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2005-06-01 23:19:00 +02:00
|
|
|
static const int32_t scale_factor_mult2[3][3] = {
|
2002-06-01 16:34:29 +02:00
|
|
|
SCALE_GEN(4.0 / 3.0), /* 3 steps */
|
|
|
|
SCALE_GEN(4.0 / 5.0), /* 5 steps */
|
|
|
|
SCALE_GEN(4.0 / 9.0), /* 9 steps */
|
2001-09-16 00:40:28 +02:00
|
|
|
};
|
|
|
|
|
2008-01-11 22:34:05 +01:00
|
|
|
/**
|
|
|
|
* Convert region offsets to region sizes and truncate
|
|
|
|
* size to big_values.
|
|
|
|
*/
|
2011-09-27 19:15:24 +02:00
|
|
|
static void ff_region_offset2size(GranuleDef *g)
|
|
|
|
{
|
|
|
|
int i, k, j = 0;
|
|
|
|
g->region_size[2] = 576 / 2;
|
|
|
|
for (i = 0; i < 3; i++) {
|
2008-01-11 22:34:05 +01:00
|
|
|
k = FFMIN(g->region_size[i], g->big_values);
|
|
|
|
g->region_size[i] = k - j;
|
|
|
|
j = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static void ff_init_short_region(MPADecodeContext *s, GranuleDef *g)
|
|
|
|
{
|
2008-01-11 22:34:05 +01:00
|
|
|
if (g->block_type == 2)
|
|
|
|
g->region_size[0] = (36 / 2);
|
|
|
|
else {
|
|
|
|
if (s->sample_rate_index <= 2)
|
|
|
|
g->region_size[0] = (36 / 2);
|
|
|
|
else if (s->sample_rate_index != 8)
|
|
|
|
g->region_size[0] = (54 / 2);
|
|
|
|
else
|
|
|
|
g->region_size[0] = (108 / 2);
|
|
|
|
}
|
|
|
|
g->region_size[1] = (576 / 2);
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2)
|
|
|
|
{
|
2008-01-11 22:34:05 +01:00
|
|
|
int l;
|
2011-09-27 19:15:24 +02:00
|
|
|
g->region_size[0] = band_index_long[s->sample_rate_index][ra1 + 1] >> 1;
|
2008-01-11 22:34:05 +01:00
|
|
|
/* should not overflow */
|
|
|
|
l = FFMIN(ra1 + ra2 + 2, 22);
|
2011-09-27 19:15:24 +02:00
|
|
|
g->region_size[1] = band_index_long[s->sample_rate_index][ l] >> 1;
|
2008-01-11 22:34:05 +01:00
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g)
|
|
|
|
{
|
2008-01-11 22:34:05 +01:00
|
|
|
if (g->block_type == 2) {
|
|
|
|
if (g->switch_point) {
|
|
|
|
/* if switched mode, we handle the 36 first samples as
|
|
|
|
long blocks. For 8000Hz, we handle the 48 first
|
|
|
|
exponents as long blocks (XXX: check this!) */
|
|
|
|
if (s->sample_rate_index <= 2)
|
|
|
|
g->long_end = 8;
|
|
|
|
else if (s->sample_rate_index != 8)
|
|
|
|
g->long_end = 6;
|
|
|
|
else
|
|
|
|
g->long_end = 4; /* 8000 Hz */
|
|
|
|
|
|
|
|
g->short_start = 2 + (s->sample_rate_index != 8);
|
|
|
|
} else {
|
2011-09-27 19:15:24 +02:00
|
|
|
g->long_end = 0;
|
2008-01-11 22:34:05 +01:00
|
|
|
g->short_start = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g->short_start = 13;
|
2011-09-27 19:15:24 +02:00
|
|
|
g->long_end = 22;
|
2008-01-11 22:34:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* layer 1 unscaling */
|
|
|
|
/* n = number of bits of the mantissa minus 1 */
|
|
|
|
static inline int l1_unscale(int n, int mant, int scale_factor)
|
|
|
|
{
|
|
|
|
int shift, mod;
|
2003-02-11 17:35:48 +01:00
|
|
|
int64_t val;
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
shift = scale_factor_modshift[scale_factor];
|
|
|
|
mod = shift & 3;
|
2001-09-16 00:40:28 +02:00
|
|
|
shift >>= 2;
|
2011-09-27 19:15:24 +02:00
|
|
|
val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]);
|
|
|
|
shift += n;
|
2002-06-01 16:34:29 +02:00
|
|
|
/* NOTE: at this point, 1 <= shift >= 21 + 15 */
|
|
|
|
return (int)((val + (1LL << (shift - 1))) >> shift);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int l2_unscale_group(int steps, int mant, int scale_factor)
|
|
|
|
{
|
|
|
|
int shift, mod, val;
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
shift = scale_factor_modshift[scale_factor];
|
|
|
|
mod = shift & 3;
|
2001-09-16 00:40:28 +02:00
|
|
|
shift >>= 2;
|
2002-06-01 16:34:29 +02:00
|
|
|
|
|
|
|
val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];
|
|
|
|
/* NOTE: at this point, 0 <= shift <= 21 */
|
|
|
|
if (shift > 0)
|
|
|
|
val = (val + (1 << (shift - 1))) >> shift;
|
|
|
|
return val;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */
|
|
|
|
static inline int l3_unscale(int value, int exponent)
|
|
|
|
{
|
|
|
|
unsigned int m;
|
|
|
|
int e;
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
e = table_4_3_exp [4 * value + (exponent & 3)];
|
|
|
|
m = table_4_3_value[4 * value + (exponent & 3)];
|
|
|
|
e -= exponent >> 2;
|
|
|
|
assert(e >= 1);
|
2001-09-16 00:40:28 +02:00
|
|
|
if (e > 31)
|
2005-01-31 05:06:47 +01:00
|
|
|
return 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
m = (m + (1 << (e - 1))) >> e;
|
2005-02-02 00:43:07 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2011-11-27 19:07:19 +01:00
|
|
|
static av_cold void decode_init_static(void)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
2001-09-16 00:40:28 +02:00
|
|
|
int i, j, k;
|
2011-11-03 20:53:43 +01:00
|
|
|
int offset;
|
|
|
|
|
|
|
|
/* scale factors table for layer 1/2 */
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
int shift, mod;
|
|
|
|
/* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
|
|
|
|
shift = i / 3;
|
|
|
|
mod = i % 3;
|
|
|
|
scale_factor_modshift[i] = mod | (shift << 2);
|
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
/* scale factor multiply for layer 1 */
|
|
|
|
for (i = 0; i < 15; i++) {
|
|
|
|
int n, norm;
|
|
|
|
n = i + 2;
|
|
|
|
norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
|
|
|
|
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);
|
2011-11-16 02:23:10 +01:00
|
|
|
av_dlog(NULL, "%d: norm=%x s=%x %x %x\n", i, norm,
|
2011-11-03 20:53:43 +01:00
|
|
|
scale_factor_mult[i][0],
|
|
|
|
scale_factor_mult[i][1],
|
|
|
|
scale_factor_mult[i][2]);
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
RENAME(ff_mpa_synth_init)(RENAME(ff_mpa_synth_window));
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
/* huffman decode tables */
|
|
|
|
offset = 0;
|
|
|
|
for (i = 1; i < 16; i++) {
|
|
|
|
const HuffTable *h = &mpa_huff_tables[i];
|
|
|
|
int xsize, x, y;
|
|
|
|
uint8_t tmp_bits [512];
|
|
|
|
uint16_t tmp_codes[512];
|
2006-08-24 01:40:03 +02:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
memset(tmp_bits , 0, sizeof(tmp_bits ));
|
|
|
|
memset(tmp_codes, 0, sizeof(tmp_codes));
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
xsize = h->xsize;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
j = 0;
|
|
|
|
for (x = 0; x < xsize; x++) {
|
|
|
|
for (y = 0; y < xsize; y++) {
|
|
|
|
tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->bits [j ];
|
|
|
|
tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++];
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
/* XXX: fail test */
|
|
|
|
huff_vlc[i].table = huff_vlc_tables+offset;
|
|
|
|
huff_vlc[i].table_allocated = huff_vlc_tables_sizes[i];
|
|
|
|
init_vlc(&huff_vlc[i], 7, 512,
|
|
|
|
tmp_bits, 1, 1, tmp_codes, 2, 2,
|
|
|
|
INIT_VLC_USE_NEW_STATIC);
|
|
|
|
offset += huff_vlc_tables_sizes[i];
|
|
|
|
}
|
|
|
|
assert(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
huff_quad_vlc[i].table = huff_quad_vlc_tables+offset;
|
|
|
|
huff_quad_vlc[i].table_allocated = huff_quad_vlc_tables_sizes[i];
|
|
|
|
init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
|
|
|
|
mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1,
|
|
|
|
INIT_VLC_USE_NEW_STATIC);
|
|
|
|
offset += huff_quad_vlc_tables_sizes[i];
|
|
|
|
}
|
|
|
|
assert(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables));
|
|
|
|
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
k = 0;
|
|
|
|
for (j = 0; j < 22; j++) {
|
|
|
|
band_index_long[i][j] = k;
|
|
|
|
k += band_size_long[i][j];
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-11-03 20:53:43 +01:00
|
|
|
band_index_long[i][22] = k;
|
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
/* compute n ^ (4/3) and store it in mantissa/exp format */
|
|
|
|
|
|
|
|
mpegaudio_tableinit();
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (ff_mpa_quant_bits[i] < 0) {
|
|
|
|
for (j = 0; j < (1 << (-ff_mpa_quant_bits[i]+1)); j++) {
|
|
|
|
int val1, val2, val3, steps;
|
|
|
|
int val = j;
|
|
|
|
steps = ff_mpa_quant_steps[i];
|
|
|
|
val1 = val % steps;
|
|
|
|
val /= steps;
|
|
|
|
val2 = val % steps;
|
|
|
|
val3 = val / steps;
|
|
|
|
division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
|
2011-09-27 19:15:24 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 20:53:43 +01:00
|
|
|
}
|
2010-06-28 06:55:36 +02:00
|
|
|
|
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
for (i = 0; i < 7; i++) {
|
|
|
|
float f;
|
|
|
|
INTFLOAT v;
|
|
|
|
if (i != 6) {
|
|
|
|
f = tan((double)i * M_PI / 12.0);
|
|
|
|
v = FIXR(f / (1.0 + f));
|
|
|
|
} else {
|
|
|
|
v = FIXR(1.0);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-11-03 20:53:43 +01:00
|
|
|
is_table[0][ i] = v;
|
|
|
|
is_table[1][6 - i] = v;
|
|
|
|
}
|
|
|
|
/* invalid values */
|
|
|
|
for (i = 7; i < 16; i++)
|
|
|
|
is_table[0][i] = is_table[1][i] = 0.0;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
double f;
|
|
|
|
int e, k;
|
|
|
|
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
e = -(j + 1) * ((i + 1) >> 1);
|
|
|
|
f = pow(2.0, e / 4.0);
|
|
|
|
k = i & 1;
|
|
|
|
is_table_lsf[j][k ^ 1][i] = FIXR(f);
|
|
|
|
is_table_lsf[j][k ][i] = FIXR(1.0);
|
2011-11-16 02:23:10 +01:00
|
|
|
av_dlog(NULL, "is_table_lsf %d %d: %f %f\n",
|
2011-11-03 20:53:43 +01:00
|
|
|
i, j, (float) is_table_lsf[j][0][i],
|
|
|
|
(float) is_table_lsf[j][1][i]);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-11-03 20:53:43 +01:00
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
float ci, cs, ca;
|
|
|
|
ci = ci_table[i];
|
|
|
|
cs = 1.0 / sqrt(1.0 + ci * ci);
|
|
|
|
ca = cs * ci;
|
2011-05-19 14:36:21 +02:00
|
|
|
#if !CONFIG_FLOAT
|
2011-11-03 20:53:43 +01:00
|
|
|
csa_table[i][0] = FIXHR(cs/4);
|
|
|
|
csa_table[i][1] = FIXHR(ca/4);
|
|
|
|
csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4);
|
|
|
|
csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4);
|
2011-05-19 14:36:21 +02:00
|
|
|
#else
|
2011-11-03 20:53:43 +01:00
|
|
|
csa_table[i][0] = cs;
|
|
|
|
csa_table[i][1] = ca;
|
|
|
|
csa_table[i][2] = ca + cs;
|
|
|
|
csa_table[i][3] = ca - cs;
|
2011-05-19 14:36:21 +02:00
|
|
|
#endif
|
2011-11-03 20:53:43 +01:00
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
/* compute mdct windows */
|
|
|
|
for (i = 0; i < 36; i++) {
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < 4; j++) {
|
2011-11-03 20:53:43 +01:00
|
|
|
double d;
|
|
|
|
|
|
|
|
if (j == 2 && i % 3 != 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d = sin(M_PI * (i + 0.5) / 36.0);
|
|
|
|
if (j == 1) {
|
|
|
|
if (i >= 30) d = 0;
|
|
|
|
else if (i >= 24) d = sin(M_PI * (i - 18 + 0.5) / 12.0);
|
|
|
|
else if (i >= 18) d = 1;
|
|
|
|
} else if (j == 3) {
|
|
|
|
if (i < 6) d = 0;
|
|
|
|
else if (i < 12) d = sin(M_PI * (i - 6 + 0.5) / 12.0);
|
|
|
|
else if (i < 18) d = 1;
|
2005-02-01 22:27:18 +01:00
|
|
|
}
|
2011-11-03 20:53:43 +01:00
|
|
|
//merge last stage of imdct into the window coefficients
|
|
|
|
d *= 0.5 / cos(M_PI * (2 * i + 19) / 72);
|
|
|
|
|
|
|
|
if (j == 2)
|
|
|
|
mdct_win[j][i/3] = FIXHR((d / (1<<5)));
|
2011-11-16 02:23:10 +01:00
|
|
|
else {
|
|
|
|
int idx = i < 18 ? i : i + 2;
|
|
|
|
mdct_win[j][idx] = FIXHR((d / (1<<5)));
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 20:53:43 +01:00
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-11-03 20:53:43 +01:00
|
|
|
/* NOTE: we do frequency inversion adter the MDCT by changing
|
|
|
|
the sign of the right window coefs */
|
|
|
|
for (j = 0; j < 4; j++) {
|
2011-11-16 02:23:10 +01:00
|
|
|
for (i = 0; i < 40; i += 2) {
|
2011-11-03 20:53:43 +01:00
|
|
|
mdct_win[j + 4][i ] = mdct_win[j][i ];
|
|
|
|
mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1];
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2011-11-03 19:59:37 +01:00
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-11-03 19:59:37 +01:00
|
|
|
static av_cold int decode_init(AVCodecContext * avctx)
|
|
|
|
{
|
2011-11-27 19:07:19 +01:00
|
|
|
static int initialized_tables = 0;
|
2011-11-03 19:59:37 +01:00
|
|
|
MPADecodeContext *s = avctx->priv_data;
|
|
|
|
|
2011-11-27 19:07:19 +01:00
|
|
|
if (!initialized_tables) {
|
|
|
|
decode_init_static();
|
|
|
|
initialized_tables = 1;
|
|
|
|
}
|
|
|
|
|
2011-11-03 19:59:37 +01:00
|
|
|
s->avctx = avctx;
|
|
|
|
|
|
|
|
ff_mpadsp_init(&s->mpadsp);
|
|
|
|
|
|
|
|
avctx->sample_fmt= OUT_FMT;
|
|
|
|
s->err_recognition = avctx->err_recognition;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2005-01-15 15:59:47 +01:00
|
|
|
if (avctx->codec_id == CODEC_ID_MP3ADU)
|
|
|
|
s->adu_mode = 1;
|
2011-09-06 18:17:45 +02:00
|
|
|
|
|
|
|
avcodec_get_frame_defaults(&s->frame);
|
|
|
|
avctx->coded_frame = &s->frame;
|
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-02 23:38:28 +01:00
|
|
|
#define C3 FIXHR(0.86602540378443864676/2)
|
2011-11-07 21:54:49 +01:00
|
|
|
#define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36)
|
|
|
|
#define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36)
|
|
|
|
#define C6 FIXHR(1.93185165257813657349/4) //0.5 / cos(pi*(15)/36)
|
2006-08-21 14:12:43 +02:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* 12 points IMDCT. We compute it "by hand" by factorizing obvious
|
|
|
|
cases. */
|
2010-05-11 21:52:42 +02:00
|
|
|
static void imdct12(INTFLOAT *out, INTFLOAT *in)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
2010-05-11 21:52:42 +02:00
|
|
|
INTFLOAT in0, in1, in2, in3, in4, in5, t1, t2;
|
2005-02-03 04:28:27 +01:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
in0 = in[0*3];
|
|
|
|
in1 = in[1*3] + in[0*3];
|
|
|
|
in2 = in[2*3] + in[1*3];
|
|
|
|
in3 = in[3*3] + in[2*3];
|
|
|
|
in4 = in[4*3] + in[3*3];
|
|
|
|
in5 = in[5*3] + in[4*3];
|
2005-02-02 23:38:28 +01:00
|
|
|
in5 += in3;
|
|
|
|
in3 += in1;
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
in2 = MULH3(in2, C3, 2);
|
|
|
|
in3 = MULH3(in3, C3, 4);
|
|
|
|
|
|
|
|
t1 = in0 - in4;
|
2011-11-07 21:54:49 +01:00
|
|
|
t2 = MULH3(in1 - in5, C4, 2);
|
2011-09-27 19:15:24 +02:00
|
|
|
|
|
|
|
out[ 7] =
|
|
|
|
out[10] = t1 + t2;
|
|
|
|
out[ 1] =
|
|
|
|
out[ 4] = t1 - t2;
|
|
|
|
|
|
|
|
in0 += SHR(in4, 1);
|
|
|
|
in4 = in0 + in2;
|
|
|
|
in5 += 2*in1;
|
2011-11-07 21:54:49 +01:00
|
|
|
in1 = MULH3(in5 + in3, C5, 1);
|
2011-09-27 19:15:24 +02:00
|
|
|
out[ 8] =
|
|
|
|
out[ 9] = in4 + in1;
|
|
|
|
out[ 2] =
|
|
|
|
out[ 3] = in4 - in1;
|
|
|
|
|
|
|
|
in0 -= in2;
|
2011-11-07 21:54:49 +01:00
|
|
|
in5 = MULH3(in5 - in3, C6, 2);
|
2011-09-27 19:15:24 +02:00
|
|
|
out[ 0] =
|
|
|
|
out[ 5] = in0 - in5;
|
|
|
|
out[ 6] =
|
|
|
|
out[11] = in0 + in5;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return the number of decoded frames */
|
|
|
|
static int mp_decode_layer1(MPADecodeContext *s)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
2001-09-16 00:40:28 +02:00
|
|
|
int bound, i, v, n, ch, j, mant;
|
2003-02-11 17:35:48 +01:00
|
|
|
uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT];
|
|
|
|
uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2005-12-17 19:14:38 +01:00
|
|
|
if (s->mode == MPA_JSTEREO)
|
2001-09-16 00:40:28 +02:00
|
|
|
bound = (s->mode_ext + 1) * 4;
|
|
|
|
else
|
|
|
|
bound = SBLIMIT;
|
|
|
|
|
|
|
|
/* allocation bits */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < bound; i++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
allocation[ch][i] = get_bits(&s->gb, 4);
|
|
|
|
}
|
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = bound; i < SBLIMIT; i++)
|
2001-09-16 00:40:28 +02:00
|
|
|
allocation[0][i] = get_bits(&s->gb, 4);
|
|
|
|
|
|
|
|
/* scale factors */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < bound; i++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
if (allocation[ch][i])
|
|
|
|
scale_factors[ch][i] = get_bits(&s->gb, 6);
|
|
|
|
}
|
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = bound; i < SBLIMIT; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
if (allocation[0][i]) {
|
|
|
|
scale_factors[0][i] = get_bits(&s->gb, 6);
|
|
|
|
scale_factors[1][i] = get_bits(&s->gb, 6);
|
|
|
|
}
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* compute samples */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < 12; j++) {
|
|
|
|
for (i = 0; i < bound; i++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
n = allocation[ch][i];
|
|
|
|
if (n) {
|
|
|
|
mant = get_bits(&s->gb, n + 1);
|
|
|
|
v = l1_unscale(n, mant, scale_factors[ch][i]);
|
|
|
|
} else {
|
|
|
|
v = 0;
|
|
|
|
}
|
|
|
|
s->sb_samples[ch][j][i] = v;
|
|
|
|
}
|
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = bound; i < SBLIMIT; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
n = allocation[0][i];
|
|
|
|
if (n) {
|
|
|
|
mant = get_bits(&s->gb, n + 1);
|
|
|
|
v = l1_unscale(n, mant, scale_factors[0][i]);
|
|
|
|
s->sb_samples[0][j][i] = v;
|
|
|
|
v = l1_unscale(n, mant, scale_factors[1][i]);
|
|
|
|
s->sb_samples[1][j][i] = v;
|
|
|
|
} else {
|
|
|
|
s->sb_samples[0][j][i] = 0;
|
|
|
|
s->sb_samples[1][j][i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mp_decode_layer2(MPADecodeContext *s)
|
|
|
|
{
|
|
|
|
int sblimit; /* number of used subbands */
|
|
|
|
const unsigned char *alloc_table;
|
|
|
|
int table, bit_alloc_bits, i, j, ch, bound, v;
|
|
|
|
unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
|
|
|
|
unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
|
|
|
|
unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;
|
|
|
|
int scale, qindex, bits, steps, k, l, m, b;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* select decoding table */
|
2007-05-21 00:50:29 +02:00
|
|
|
table = ff_mpa_l2_select_table(s->bit_rate / 1000, s->nb_channels,
|
2011-09-27 19:15:24 +02:00
|
|
|
s->sample_rate, s->lsf);
|
|
|
|
sblimit = ff_mpa_sblimit_table[table];
|
2007-05-19 02:13:35 +02:00
|
|
|
alloc_table = ff_mpa_alloc_tables[table];
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2005-12-17 19:14:38 +01:00
|
|
|
if (s->mode == MPA_JSTEREO)
|
2001-09-16 00:40:28 +02:00
|
|
|
bound = (s->mode_ext + 1) * 4;
|
|
|
|
else
|
|
|
|
bound = sblimit;
|
|
|
|
|
2011-01-29 17:46:18 +01:00
|
|
|
av_dlog(s->avctx, "bound=%d sblimit=%d\n", bound, sblimit);
|
2004-02-04 16:49:55 +01:00
|
|
|
|
|
|
|
/* sanity check */
|
2011-09-27 19:15:24 +02:00
|
|
|
if (bound > sblimit)
|
|
|
|
bound = sblimit;
|
2004-02-04 16:49:55 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* parse bit allocation */
|
|
|
|
j = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < bound; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
bit_alloc_bits = alloc_table[j];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (ch = 0; ch < s->nb_channels; ch++)
|
2001-09-16 00:40:28 +02:00
|
|
|
bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);
|
|
|
|
j += 1 << bit_alloc_bits;
|
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = bound; i < sblimit; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
bit_alloc_bits = alloc_table[j];
|
|
|
|
v = get_bits(&s->gb, bit_alloc_bits);
|
|
|
|
bit_alloc[0][i] = v;
|
|
|
|
bit_alloc[1][i] = v;
|
|
|
|
j += 1 << bit_alloc_bits;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
/* scale codes */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < sblimit; i++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2005-12-17 19:14:38 +01:00
|
|
|
if (bit_alloc[ch][i])
|
2001-09-16 00:40:28 +02:00
|
|
|
scale_code[ch][i] = get_bits(&s->gb, 2);
|
|
|
|
}
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* scale factors */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < sblimit; i++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
if (bit_alloc[ch][i]) {
|
|
|
|
sf = scale_factors[ch][i];
|
2011-09-27 19:15:24 +02:00
|
|
|
switch (scale_code[ch][i]) {
|
2001-09-16 00:40:28 +02:00
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
sf[0] = get_bits(&s->gb, 6);
|
|
|
|
sf[1] = get_bits(&s->gb, 6);
|
|
|
|
sf[2] = get_bits(&s->gb, 6);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
sf[0] = get_bits(&s->gb, 6);
|
|
|
|
sf[1] = sf[0];
|
|
|
|
sf[2] = sf[0];
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sf[0] = get_bits(&s->gb, 6);
|
|
|
|
sf[2] = get_bits(&s->gb, 6);
|
|
|
|
sf[1] = sf[0];
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sf[0] = get_bits(&s->gb, 6);
|
|
|
|
sf[2] = get_bits(&s->gb, 6);
|
|
|
|
sf[1] = sf[2];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* samples */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (k = 0; k < 3; k++) {
|
|
|
|
for (l = 0; l < 12; l += 3) {
|
2001-09-16 00:40:28 +02:00
|
|
|
j = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < bound; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
bit_alloc_bits = alloc_table[j];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
b = bit_alloc[ch][i];
|
|
|
|
if (b) {
|
|
|
|
scale = scale_factors[ch][i][k];
|
|
|
|
qindex = alloc_table[j+b];
|
2007-05-19 02:13:35 +02:00
|
|
|
bits = ff_mpa_quant_bits[qindex];
|
2001-09-16 00:40:28 +02:00
|
|
|
if (bits < 0) {
|
2010-06-28 06:55:36 +02:00
|
|
|
int v2;
|
2001-09-16 00:40:28 +02:00
|
|
|
/* 3 values at the same time */
|
|
|
|
v = get_bits(&s->gb, -bits);
|
2010-06-28 06:55:36 +02:00
|
|
|
v2 = division_tabs[qindex][v];
|
|
|
|
steps = ff_mpa_quant_steps[qindex];
|
|
|
|
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[ch][k * 12 + l + 0][i] =
|
2011-09-27 19:15:24 +02:00
|
|
|
l2_unscale_group(steps, v2 & 15, scale);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[ch][k * 12 + l + 1][i] =
|
2010-06-28 06:55:36 +02:00
|
|
|
l2_unscale_group(steps, (v2 >> 4) & 15, scale);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[ch][k * 12 + l + 2][i] =
|
2010-06-28 06:55:36 +02:00
|
|
|
l2_unscale_group(steps, v2 >> 8 , scale);
|
2001-09-16 00:40:28 +02:00
|
|
|
} else {
|
2011-09-27 19:15:24 +02:00
|
|
|
for (m = 0; m < 3; m++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
v = get_bits(&s->gb, bits);
|
|
|
|
v = l1_unscale(bits - 1, v, scale);
|
|
|
|
s->sb_samples[ch][k * 12 + l + m][i] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s->sb_samples[ch][k * 12 + l + 0][i] = 0;
|
|
|
|
s->sb_samples[ch][k * 12 + l + 1][i] = 0;
|
|
|
|
s->sb_samples[ch][k * 12 + l + 2][i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* next subband in alloc table */
|
2005-12-17 19:14:38 +01:00
|
|
|
j += 1 << bit_alloc_bits;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
/* XXX: find a way to avoid this duplication of code */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = bound; i < sblimit; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
bit_alloc_bits = alloc_table[j];
|
|
|
|
b = bit_alloc[0][i];
|
|
|
|
if (b) {
|
|
|
|
int mant, scale0, scale1;
|
|
|
|
scale0 = scale_factors[0][i][k];
|
|
|
|
scale1 = scale_factors[1][i][k];
|
|
|
|
qindex = alloc_table[j+b];
|
2007-05-19 02:13:35 +02:00
|
|
|
bits = ff_mpa_quant_bits[qindex];
|
2001-09-16 00:40:28 +02:00
|
|
|
if (bits < 0) {
|
|
|
|
/* 3 values at the same time */
|
|
|
|
v = get_bits(&s->gb, -bits);
|
2007-05-19 02:13:35 +02:00
|
|
|
steps = ff_mpa_quant_steps[qindex];
|
2001-09-16 00:40:28 +02:00
|
|
|
mant = v % steps;
|
|
|
|
v = v / steps;
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[0][k * 12 + l + 0][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l2_unscale_group(steps, mant, scale0);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[1][k * 12 + l + 0][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l2_unscale_group(steps, mant, scale1);
|
|
|
|
mant = v % steps;
|
|
|
|
v = v / steps;
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[0][k * 12 + l + 1][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l2_unscale_group(steps, mant, scale0);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[1][k * 12 + l + 1][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l2_unscale_group(steps, mant, scale1);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[0][k * 12 + l + 2][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l2_unscale_group(steps, v, scale0);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[1][k * 12 + l + 2][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l2_unscale_group(steps, v, scale1);
|
|
|
|
} else {
|
2011-09-27 19:15:24 +02:00
|
|
|
for (m = 0; m < 3; m++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
mant = get_bits(&s->gb, bits);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[0][k * 12 + l + m][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l1_unscale(bits - 1, mant, scale0);
|
2005-12-17 19:14:38 +01:00
|
|
|
s->sb_samples[1][k * 12 + l + m][i] =
|
2001-09-16 00:40:28 +02:00
|
|
|
l1_unscale(bits - 1, mant, scale1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s->sb_samples[0][k * 12 + l + 0][i] = 0;
|
|
|
|
s->sb_samples[0][k * 12 + l + 1][i] = 0;
|
|
|
|
s->sb_samples[0][k * 12 + l + 2][i] = 0;
|
|
|
|
s->sb_samples[1][k * 12 + l + 0][i] = 0;
|
|
|
|
s->sb_samples[1][k * 12 + l + 1][i] = 0;
|
|
|
|
s->sb_samples[1][k * 12 + l + 2][i] = 0;
|
|
|
|
}
|
|
|
|
/* next subband in alloc table */
|
2005-12-17 19:14:38 +01:00
|
|
|
j += 1 << bit_alloc_bits;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
/* fill remaining samples to zero */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = sblimit; i < SBLIMIT; i++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
s->sb_samples[ch][k * 12 + l + 0][i] = 0;
|
|
|
|
s->sb_samples[ch][k * 12 + l + 1][i] = 0;
|
|
|
|
s->sb_samples[ch][k * 12 + l + 2][i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 3 * 12;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
#define SPLIT(dst,sf,n) \
|
|
|
|
if (n == 3) { \
|
|
|
|
int m = (sf * 171) >> 9; \
|
|
|
|
dst = sf - 3 * m; \
|
|
|
|
sf = m; \
|
|
|
|
} else if (n == 4) { \
|
|
|
|
dst = sf & 3; \
|
|
|
|
sf >>= 2; \
|
|
|
|
} else if (n == 5) { \
|
|
|
|
int m = (sf * 205) >> 10; \
|
|
|
|
dst = sf - 5 * m; \
|
|
|
|
sf = m; \
|
|
|
|
} else if (n == 6) { \
|
|
|
|
int m = (sf * 171) >> 10; \
|
|
|
|
dst = sf - 6 * m; \
|
|
|
|
sf = m; \
|
|
|
|
} else { \
|
|
|
|
dst = 0; \
|
2010-05-11 22:33:48 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2,
|
|
|
|
int n3)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
2010-05-11 22:33:48 +02:00
|
|
|
SPLIT(slen[3], sf, n3)
|
|
|
|
SPLIT(slen[2], sf, n2)
|
|
|
|
SPLIT(slen[1], sf, n1)
|
2001-09-16 00:40:28 +02:00
|
|
|
slen[0] = sf;
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g,
|
2003-02-11 17:35:48 +01:00
|
|
|
int16_t *exponents)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
2003-02-11 17:35:48 +01:00
|
|
|
const uint8_t *bstab, *pretab;
|
2001-09-16 00:40:28 +02:00
|
|
|
int len, i, j, k, l, v0, shift, gain, gains[3];
|
2003-02-11 17:35:48 +01:00
|
|
|
int16_t *exp_ptr;
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
exp_ptr = exponents;
|
2011-09-27 19:15:24 +02:00
|
|
|
gain = g->global_gain - 210;
|
|
|
|
shift = g->scalefac_scale + 1;
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
bstab = band_size_long[s->sample_rate_index];
|
2001-09-16 00:40:28 +02:00
|
|
|
pretab = mpa_pretab[g->preflag];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < g->long_end; i++) {
|
2006-08-25 15:46:56 +02:00
|
|
|
v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift) + 400;
|
2001-09-16 00:40:28 +02:00
|
|
|
len = bstab[i];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = len; j > 0; j--)
|
2001-09-16 00:40:28 +02:00
|
|
|
*exp_ptr++ = v0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g->short_start < 13) {
|
2011-09-27 19:15:24 +02:00
|
|
|
bstab = band_size_short[s->sample_rate_index];
|
2001-09-16 00:40:28 +02:00
|
|
|
gains[0] = gain - (g->subblock_gain[0] << 3);
|
|
|
|
gains[1] = gain - (g->subblock_gain[1] << 3);
|
|
|
|
gains[2] = gain - (g->subblock_gain[2] << 3);
|
2011-09-27 19:15:24 +02:00
|
|
|
k = g->long_end;
|
|
|
|
for (i = g->short_start; i < 13; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
len = bstab[i];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (l = 0; l < 3; l++) {
|
2006-08-25 15:46:56 +02:00
|
|
|
v0 = gains[l] - (g->scale_factors[k++] << shift) + 400;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = len; j > 0; j--)
|
|
|
|
*exp_ptr++ = v0;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle n = 0 too */
|
|
|
|
static inline int get_bitsz(GetBitContext *s, int n)
|
|
|
|
{
|
2011-09-27 19:15:24 +02:00
|
|
|
return n ? get_bits(s, n) : 0;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-02-03 14:15:55 +01:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
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) {
|
|
|
|
s->gb = s->in_gb;
|
|
|
|
s->in_gb.buffer = NULL;
|
2007-02-03 14:15:55 +01:00
|
|
|
assert((get_bits_count(&s->gb) & 7) == 0);
|
|
|
|
skip_bits_long(&s->gb, *pos - *end_pos);
|
2011-09-27 19:15:24 +02:00
|
|
|
*end_pos2 =
|
|
|
|
*end_pos = *end_pos2 + get_bits_count(&s->gb) - *pos;
|
|
|
|
*pos = get_bits_count(&s->gb);
|
2007-02-03 14:15:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-11 23:20:33 +02:00
|
|
|
/* Following is a optimized code for
|
|
|
|
INTFLOAT v = *src
|
|
|
|
if(get_bits1(&s->gb))
|
|
|
|
v = -v;
|
|
|
|
*dst = v;
|
|
|
|
*/
|
|
|
|
#if CONFIG_FLOAT
|
2011-09-27 19:15:24 +02:00
|
|
|
#define READ_FLIP_SIGN(dst,src) \
|
|
|
|
v = AV_RN32A(src) ^ (get_bits1(&s->gb) << 31); \
|
|
|
|
AV_WN32A(dst, v);
|
2010-05-11 23:20:33 +02:00
|
|
|
#else
|
2011-09-27 19:15:24 +02:00
|
|
|
#define READ_FLIP_SIGN(dst,src) \
|
|
|
|
v = -get_bits1(&s->gb); \
|
|
|
|
*(dst) = (*(src) ^ v) - v;
|
2010-05-11 23:20:33 +02:00
|
|
|
#endif
|
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
|
2006-08-26 14:19:05 +02:00
|
|
|
int16_t *exponents, int end_pos2)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
|
|
|
int s_index;
|
2006-08-25 15:58:27 +02:00
|
|
|
int i;
|
2006-08-26 14:19:05 +02:00
|
|
|
int last_pos, bits_left;
|
2001-09-16 00:40:28 +02:00
|
|
|
VLC *vlc;
|
2011-09-27 19:15:24 +02:00
|
|
|
int end_pos = FFMIN(end_pos2, s->gb.size_in_bits);
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
/* low frequencies (called big values) */
|
|
|
|
s_index = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 3; i++) {
|
2006-08-25 15:58:27 +02:00
|
|
|
int j, k, l, linbits;
|
2001-09-16 00:40:28 +02:00
|
|
|
j = g->region_size[i];
|
|
|
|
if (j == 0)
|
|
|
|
continue;
|
|
|
|
/* select vlc table */
|
2011-09-27 19:15:24 +02:00
|
|
|
k = g->table_select[i];
|
|
|
|
l = mpa_huff_data[k][0];
|
2001-09-16 00:40:28 +02:00
|
|
|
linbits = mpa_huff_data[k][1];
|
2011-09-27 19:15:24 +02:00
|
|
|
vlc = &huff_vlc[l];
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
if (!l) {
|
|
|
|
memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * 2 * j);
|
|
|
|
s_index += 2 * j;
|
2006-08-24 02:03:51 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* read huffcode and compute each couple */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (; j > 0; j--) {
|
2010-05-11 21:52:42 +02:00
|
|
|
int exponent, x, y;
|
2010-05-11 23:31:54 +02:00
|
|
|
int v;
|
2011-09-27 19:15:24 +02:00
|
|
|
int pos = get_bits_count(&s->gb);
|
2006-08-26 14:19:05 +02:00
|
|
|
|
|
|
|
if (pos >= end_pos){
|
|
|
|
// av_log(NULL, AV_LOG_ERROR, "pos: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);
|
2007-02-03 14:15:55 +01:00
|
|
|
switch_buffer(s, &pos, &end_pos, &end_pos2);
|
2006-08-26 14:19:05 +02:00
|
|
|
// av_log(NULL, AV_LOG_ERROR, "new pos: %d %d\n", pos, end_pos);
|
2011-09-27 19:15:24 +02:00
|
|
|
if (pos >= end_pos)
|
2006-08-26 14:19:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-08-25 14:26:34 +02:00
|
|
|
y = get_vlc2(&s->gb, vlc->table, 7, 3);
|
2006-08-24 03:12:26 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
if (!y) {
|
2006-08-24 03:12:26 +02:00
|
|
|
g->sb_hybrid[s_index ] =
|
|
|
|
g->sb_hybrid[s_index+1] = 0;
|
|
|
|
s_index += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-08-25 15:36:27 +02:00
|
|
|
exponent= exponents[s_index];
|
2006-08-24 02:03:51 +02:00
|
|
|
|
2011-01-29 17:46:18 +01:00
|
|
|
av_dlog(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n",
|
2006-08-25 15:36:27 +02:00
|
|
|
i, g->region_size[i] - j, x, y, exponent);
|
2011-09-27 19:15:24 +02:00
|
|
|
if (y & 16) {
|
2006-08-25 16:42:32 +02:00
|
|
|
x = y >> 5;
|
|
|
|
y = y & 0x0f;
|
2011-09-27 19:15:24 +02:00
|
|
|
if (x < 15) {
|
|
|
|
READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(expval_table)[exponent] + x)
|
|
|
|
} else {
|
2006-08-25 13:55:20 +02:00
|
|
|
x += get_bitsz(&s->gb, linbits);
|
2011-09-27 19:15:24 +02:00
|
|
|
v = l3_unscale(x, exponent);
|
2010-05-11 23:31:54 +02:00
|
|
|
if (get_bits1(&s->gb))
|
|
|
|
v = -v;
|
|
|
|
g->sb_hybrid[s_index] = v;
|
2006-08-25 13:55:20 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
if (y < 15) {
|
|
|
|
READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(expval_table)[exponent] + y)
|
|
|
|
} else {
|
2006-08-25 13:55:20 +02:00
|
|
|
y += get_bitsz(&s->gb, linbits);
|
2011-09-27 19:15:24 +02:00
|
|
|
v = l3_unscale(y, exponent);
|
2010-05-11 23:31:54 +02:00
|
|
|
if (get_bits1(&s->gb))
|
|
|
|
v = -v;
|
|
|
|
g->sb_hybrid[s_index+1] = v;
|
2006-08-25 13:55:20 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
} else {
|
2006-08-25 16:42:32 +02:00
|
|
|
x = y >> 5;
|
|
|
|
y = y & 0x0f;
|
|
|
|
x += y;
|
2011-09-27 19:15:24 +02:00
|
|
|
if (x < 15) {
|
|
|
|
READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(expval_table)[exponent] + x)
|
|
|
|
} else {
|
2006-08-25 16:42:32 +02:00
|
|
|
x += get_bitsz(&s->gb, linbits);
|
2011-09-27 19:15:24 +02:00
|
|
|
v = l3_unscale(x, exponent);
|
2010-05-11 23:31:54 +02:00
|
|
|
if (get_bits1(&s->gb))
|
|
|
|
v = -v;
|
|
|
|
g->sb_hybrid[s_index+!!y] = v;
|
2006-08-25 16:42:32 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
g->sb_hybrid[s_index + !y] = 0;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
s_index += 2;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* high frequencies */
|
|
|
|
vlc = &huff_quad_vlc[g->count1table_select];
|
2011-09-27 19:15:24 +02:00
|
|
|
last_pos = 0;
|
2001-09-16 00:40:28 +02:00
|
|
|
while (s_index <= 572) {
|
2006-08-25 15:58:27 +02:00
|
|
|
int pos, code;
|
2001-09-16 00:40:28 +02:00
|
|
|
pos = get_bits_count(&s->gb);
|
|
|
|
if (pos >= end_pos) {
|
2011-09-27 19:15:24 +02:00
|
|
|
if (pos > end_pos2 && last_pos) {
|
2006-08-28 18:15:40 +02:00
|
|
|
/* some encoders generate an incorrect size for this
|
|
|
|
part. We must go back into the data */
|
|
|
|
s_index -= 4;
|
|
|
|
skip_bits_long(&s->gb, last_pos - pos);
|
2008-07-20 16:58:49 +02:00
|
|
|
av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos);
|
2011-11-19 03:03:21 +01:00
|
|
|
if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
|
2006-11-15 18:58:35 +01:00
|
|
|
s_index=0;
|
2006-08-28 18:15:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-08-26 14:19:05 +02:00
|
|
|
// av_log(NULL, AV_LOG_ERROR, "pos2: %d %d %d %d\n", pos, end_pos, end_pos2, s_index);
|
2007-02-03 14:15:55 +01:00
|
|
|
switch_buffer(s, &pos, &end_pos, &end_pos2);
|
2006-08-26 14:19:05 +02:00
|
|
|
// av_log(NULL, AV_LOG_ERROR, "new pos2: %d %d %d\n", pos, end_pos, s_index);
|
2011-09-27 19:15:24 +02:00
|
|
|
if (pos >= end_pos)
|
2006-08-26 14:19:05 +02:00
|
|
|
break;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
last_pos = pos;
|
2002-07-09 12:35:10 +02:00
|
|
|
|
2006-08-24 03:01:39 +02:00
|
|
|
code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1);
|
2011-01-29 17:46:18 +01:00
|
|
|
av_dlog(s->avctx, "t=%d code=%d\n", g->count1table_select, code);
|
2011-09-27 19:15:24 +02:00
|
|
|
g->sb_hybrid[s_index+0] =
|
|
|
|
g->sb_hybrid[s_index+1] =
|
|
|
|
g->sb_hybrid[s_index+2] =
|
|
|
|
g->sb_hybrid[s_index+3] = 0;
|
|
|
|
while (code) {
|
|
|
|
static const int idxtab[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 };
|
2010-05-11 23:10:55 +02:00
|
|
|
int v;
|
2011-09-27 19:15:24 +02:00
|
|
|
int pos = s_index + idxtab[code];
|
|
|
|
code ^= 8 >> idxtab[code];
|
|
|
|
READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(exp_table)+exponents[pos])
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
s_index += 4;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2006-08-26 14:19:05 +02:00
|
|
|
/* skip extension bits */
|
2007-02-03 13:42:12 +01:00
|
|
|
bits_left = end_pos2 - get_bits_count(&s->gb);
|
2006-08-26 14:19:05 +02:00
|
|
|
//av_log(NULL, AV_LOG_ERROR, "left:%d buf:%p\n", bits_left, s->in_gb.buffer);
|
2011-11-19 03:03:21 +01:00
|
|
|
if (bits_left < 0 && (s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) {
|
2008-07-20 16:58:49 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
|
2006-11-15 18:58:35 +01:00
|
|
|
s_index=0;
|
2011-11-19 03:03:21 +01:00
|
|
|
} else if (bits_left > 0 && (s->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE))) {
|
2008-07-20 16:58:49 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left);
|
2011-09-27 19:15:24 +02:00
|
|
|
s_index = 0;
|
2006-08-26 14:19:05 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * (576 - s_index));
|
2006-08-26 14:19:05 +02:00
|
|
|
skip_bits_long(&s->gb, bits_left);
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
i = get_bits_count(&s->gb);
|
2007-02-03 14:15:55 +01:00
|
|
|
switch_buffer(s, &i, &end_pos, &end_pos2);
|
2007-02-03 13:42:12 +01:00
|
|
|
|
2001-07-22 16:18:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* Reorder short blocks from bitstream order to interleaved order. It
|
|
|
|
would be faster to do it in parsing, but the code would be far more
|
|
|
|
complicated */
|
|
|
|
static void reorder_block(MPADecodeContext *s, GranuleDef *g)
|
|
|
|
{
|
2006-08-24 10:40:09 +02:00
|
|
|
int i, j, len;
|
2010-05-11 21:52:42 +02:00
|
|
|
INTFLOAT *ptr, *dst, *ptr1;
|
|
|
|
INTFLOAT tmp[576];
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
if (g->block_type != 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g->switch_point) {
|
2011-09-27 19:15:24 +02:00
|
|
|
if (s->sample_rate_index != 8)
|
2001-09-16 00:40:28 +02:00
|
|
|
ptr = g->sb_hybrid + 36;
|
2011-09-27 19:15:24 +02:00
|
|
|
else
|
2001-09-16 00:40:28 +02:00
|
|
|
ptr = g->sb_hybrid + 48;
|
|
|
|
} else {
|
|
|
|
ptr = g->sb_hybrid;
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = g->short_start; i < 13; i++) {
|
|
|
|
len = band_size_short[s->sample_rate_index][i];
|
2001-09-16 00:40:28 +02:00
|
|
|
ptr1 = ptr;
|
2011-09-27 19:15:24 +02:00
|
|
|
dst = tmp;
|
|
|
|
for (j = len; j > 0; j--) {
|
2006-08-24 10:40:09 +02:00
|
|
|
*dst++ = ptr[0*len];
|
|
|
|
*dst++ = ptr[1*len];
|
|
|
|
*dst++ = ptr[2*len];
|
|
|
|
ptr++;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
ptr += 2 * len;
|
2006-08-24 10:40:09 +02:00
|
|
|
memcpy(ptr1, tmp, len * 3 * sizeof(*ptr1));
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ISQRT2 FIXR(0.70710678118654752440)
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
|
|
|
int i, j, k, l;
|
2010-05-11 21:52:42 +02:00
|
|
|
int sf_max, sf, len, non_zero_found;
|
|
|
|
INTFLOAT (*is_tab)[16], *tab0, *tab1, tmp0, tmp1, v1, v2;
|
2001-09-16 00:40:28 +02:00
|
|
|
int non_zero_found_short[3];
|
|
|
|
|
|
|
|
/* intensity stereo */
|
|
|
|
if (s->mode_ext & MODE_EXT_I_STEREO) {
|
|
|
|
if (!s->lsf) {
|
|
|
|
is_tab = is_table;
|
|
|
|
sf_max = 7;
|
|
|
|
} else {
|
|
|
|
is_tab = is_table_lsf[g1->scalefac_compress & 1];
|
|
|
|
sf_max = 16;
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
tab0 = g0->sb_hybrid + 576;
|
|
|
|
tab1 = g1->sb_hybrid + 576;
|
|
|
|
|
|
|
|
non_zero_found_short[0] = 0;
|
|
|
|
non_zero_found_short[1] = 0;
|
|
|
|
non_zero_found_short[2] = 0;
|
|
|
|
k = (13 - g1->short_start) * 3 + g1->long_end - 3;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 12; i >= g1->short_start; i--) {
|
2001-09-16 00:40:28 +02:00
|
|
|
/* for last band, use previous scale factor */
|
|
|
|
if (i != 11)
|
|
|
|
k -= 3;
|
|
|
|
len = band_size_short[s->sample_rate_index][i];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (l = 2; l >= 0; l--) {
|
2001-09-16 00:40:28 +02:00
|
|
|
tab0 -= len;
|
|
|
|
tab1 -= len;
|
|
|
|
if (!non_zero_found_short[l]) {
|
|
|
|
/* test if non zero band. if so, stop doing i-stereo */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < len; j++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
if (tab1[j] != 0) {
|
|
|
|
non_zero_found_short[l] = 1;
|
|
|
|
goto found1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sf = g1->scale_factors[k + l];
|
|
|
|
if (sf >= sf_max)
|
|
|
|
goto found1;
|
|
|
|
|
|
|
|
v1 = is_tab[0][sf];
|
|
|
|
v2 = is_tab[1][sf];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
tmp0 = tab0[j];
|
2010-05-11 21:52:42 +02:00
|
|
|
tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
|
|
|
|
tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
} else {
|
2011-09-27 19:15:24 +02:00
|
|
|
found1:
|
2001-09-16 00:40:28 +02:00
|
|
|
if (s->mode_ext & MODE_EXT_MS_STEREO) {
|
|
|
|
/* lower part of the spectrum : do ms stereo
|
|
|
|
if enabled */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
tmp0 = tab0[j];
|
|
|
|
tmp1 = tab1[j];
|
2010-05-11 21:52:42 +02:00
|
|
|
tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
|
|
|
|
tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-17 19:14:38 +01:00
|
|
|
non_zero_found = non_zero_found_short[0] |
|
2011-09-27 19:15:24 +02:00
|
|
|
non_zero_found_short[1] |
|
|
|
|
non_zero_found_short[2];
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = g1->long_end - 1;i >= 0;i--) {
|
|
|
|
len = band_size_long[s->sample_rate_index][i];
|
2001-09-16 00:40:28 +02:00
|
|
|
tab0 -= len;
|
|
|
|
tab1 -= len;
|
|
|
|
/* test if non zero band. if so, stop doing i-stereo */
|
|
|
|
if (!non_zero_found) {
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < len; j++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
if (tab1[j] != 0) {
|
|
|
|
non_zero_found = 1;
|
|
|
|
goto found2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* for last band, use previous scale factor */
|
2011-09-27 19:15:24 +02:00
|
|
|
k = (i == 21) ? 20 : i;
|
2001-09-16 00:40:28 +02:00
|
|
|
sf = g1->scale_factors[k];
|
|
|
|
if (sf >= sf_max)
|
|
|
|
goto found2;
|
|
|
|
v1 = is_tab[0][sf];
|
|
|
|
v2 = is_tab[1][sf];
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
tmp0 = tab0[j];
|
2010-05-11 21:52:42 +02:00
|
|
|
tab0[j] = MULLx(tmp0, v1, FRAC_BITS);
|
|
|
|
tab1[j] = MULLx(tmp0, v2, FRAC_BITS);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
} else {
|
2011-09-27 19:15:24 +02:00
|
|
|
found2:
|
2001-09-16 00:40:28 +02:00
|
|
|
if (s->mode_ext & MODE_EXT_MS_STEREO) {
|
|
|
|
/* lower part of the spectrum : do ms stereo
|
|
|
|
if enabled */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
tmp0 = tab0[j];
|
|
|
|
tmp1 = tab1[j];
|
2010-05-11 21:52:42 +02:00
|
|
|
tab0[j] = MULLx(tmp0 + tmp1, ISQRT2, FRAC_BITS);
|
|
|
|
tab1[j] = MULLx(tmp0 - tmp1, ISQRT2, FRAC_BITS);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (s->mode_ext & MODE_EXT_MS_STEREO) {
|
|
|
|
/* ms stereo ONLY */
|
|
|
|
/* NOTE: the 1/sqrt(2) normalization factor is included in the
|
|
|
|
global gain */
|
|
|
|
tab0 = g0->sb_hybrid;
|
|
|
|
tab1 = g1->sb_hybrid;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 576; i++) {
|
|
|
|
tmp0 = tab0[i];
|
|
|
|
tmp1 = tab1[i];
|
2001-09-16 00:40:28 +02:00
|
|
|
tab0[i] = tmp0 + tmp1;
|
|
|
|
tab1[i] = tmp0 - tmp1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-19 14:36:21 +02:00
|
|
|
#if CONFIG_FLOAT
|
|
|
|
#define AA(j) do { \
|
|
|
|
float tmp0 = ptr[-1-j]; \
|
|
|
|
float tmp1 = ptr[ j]; \
|
|
|
|
ptr[-1-j] = tmp0 * csa_table[j][0] - tmp1 * csa_table[j][1]; \
|
|
|
|
ptr[ j] = tmp0 * csa_table[j][1] + tmp1 * csa_table[j][0]; \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define AA(j) do { \
|
|
|
|
int tmp0 = ptr[-1-j]; \
|
|
|
|
int tmp1 = ptr[ j]; \
|
|
|
|
int tmp2 = MULH(tmp0 + tmp1, csa_table[j][0]); \
|
2011-09-27 19:15:24 +02:00
|
|
|
ptr[-1-j] = 4 * (tmp2 - MULH(tmp1, csa_table[j][2])); \
|
|
|
|
ptr[ j] = 4 * (tmp2 + MULH(tmp0, csa_table[j][3])); \
|
2011-05-19 14:36:21 +02:00
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void compute_antialias(MPADecodeContext *s, GranuleDef *g)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
2011-05-19 14:36:21 +02:00
|
|
|
INTFLOAT *ptr;
|
2005-02-02 02:37:33 +01:00
|
|
|
int n, i;
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
/* we antialias only "long" bands */
|
|
|
|
if (g->block_type == 2) {
|
|
|
|
if (!g->switch_point)
|
|
|
|
return;
|
|
|
|
/* XXX: check this for 8000Hz case */
|
|
|
|
n = 1;
|
|
|
|
} else {
|
|
|
|
n = SBLIMIT - 1;
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
ptr = g->sb_hybrid + 18;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = n; i > 0; i--) {
|
2011-05-19 14:36:21 +02:00
|
|
|
AA(0);
|
|
|
|
AA(1);
|
|
|
|
AA(2);
|
|
|
|
AA(3);
|
|
|
|
AA(4);
|
|
|
|
AA(5);
|
|
|
|
AA(6);
|
|
|
|
AA(7);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
|
|
|
ptr += 18;
|
2004-01-08 22:08:57 +01:00
|
|
|
}
|
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static void compute_imdct(MPADecodeContext *s, GranuleDef *g,
|
|
|
|
INTFLOAT *sb_samples, INTFLOAT *mdct_buf)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
2011-11-07 21:54:49 +01:00
|
|
|
INTFLOAT *win, *out_ptr, *ptr, *buf, *ptr1;
|
2010-05-11 21:52:42 +02:00
|
|
|
INTFLOAT out2[12];
|
|
|
|
int i, j, mdct_long_end, sblimit;
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
/* find last non zero block */
|
2011-09-27 19:15:24 +02:00
|
|
|
ptr = g->sb_hybrid + 576;
|
2001-09-16 00:40:28 +02:00
|
|
|
ptr1 = g->sb_hybrid + 2 * 18;
|
|
|
|
while (ptr >= ptr1) {
|
2010-05-11 21:52:42 +02:00
|
|
|
int32_t *p;
|
2001-09-16 00:40:28 +02:00
|
|
|
ptr -= 6;
|
2011-09-27 19:15:24 +02:00
|
|
|
p = (int32_t*)ptr;
|
|
|
|
if (p[0] | p[1] | p[2] | p[3] | p[4] | p[5])
|
2001-09-16 00:40:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sblimit = ((ptr - g->sb_hybrid) / 18) + 1;
|
|
|
|
|
|
|
|
if (g->block_type == 2) {
|
|
|
|
/* XXX: check for 8000 Hz */
|
|
|
|
if (g->switch_point)
|
|
|
|
mdct_long_end = 2;
|
|
|
|
else
|
|
|
|
mdct_long_end = 0;
|
|
|
|
} else {
|
|
|
|
mdct_long_end = sblimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = mdct_buf;
|
|
|
|
ptr = g->sb_hybrid;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < mdct_long_end; j++) {
|
2011-11-07 21:54:49 +01:00
|
|
|
int win_idx = (g->switch_point && j < 2) ? 0 : g->block_type;
|
2001-09-16 00:40:28 +02:00
|
|
|
/* apply window & overlap with previous buffer */
|
|
|
|
out_ptr = sb_samples + j;
|
|
|
|
/* select window */
|
2011-11-07 21:54:49 +01:00
|
|
|
win = mdct_win[win_idx + (4 & -(j & 1))];
|
|
|
|
s->mpadsp.RENAME(imdct36)(out_ptr, buf, ptr, win);
|
2011-09-27 19:15:24 +02:00
|
|
|
out_ptr += 18 * SBLIMIT;
|
|
|
|
ptr += 18;
|
|
|
|
buf += 18;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = mdct_long_end; j < sblimit; j++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
/* select frequency inversion */
|
2011-11-07 21:54:49 +01:00
|
|
|
win = mdct_win[2 + (4 & -(j & 1))];
|
2001-09-16 00:40:28 +02:00
|
|
|
out_ptr = sb_samples + j;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 6; i++) {
|
2005-02-02 23:38:28 +01:00
|
|
|
*out_ptr = buf[i];
|
|
|
|
out_ptr += SBLIMIT;
|
|
|
|
}
|
|
|
|
imdct12(out2, ptr + 0);
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 6; i++) {
|
2010-05-11 21:52:42 +02:00
|
|
|
*out_ptr = MULH3(out2[i ], win[i ], 1) + buf[i + 6*1];
|
|
|
|
buf[i + 6*2] = MULH3(out2[i + 6], win[i + 6], 1);
|
2001-09-16 00:40:28 +02:00
|
|
|
out_ptr += SBLIMIT;
|
|
|
|
}
|
2005-02-02 23:38:28 +01:00
|
|
|
imdct12(out2, ptr + 1);
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 6; i++) {
|
2010-05-11 21:52:42 +02:00
|
|
|
*out_ptr = MULH3(out2[i ], win[i ], 1) + buf[i + 6*2];
|
|
|
|
buf[i + 6*0] = MULH3(out2[i + 6], win[i + 6], 1);
|
2005-02-02 23:38:28 +01:00
|
|
|
out_ptr += SBLIMIT;
|
|
|
|
}
|
|
|
|
imdct12(out2, ptr + 2);
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 6; i++) {
|
2010-05-11 21:52:42 +02:00
|
|
|
buf[i + 6*0] = MULH3(out2[i ], win[i ], 1) + buf[i + 6*0];
|
|
|
|
buf[i + 6*1] = MULH3(out2[i + 6], win[i + 6], 1);
|
2005-02-02 23:38:28 +01:00
|
|
|
buf[i + 6*2] = 0;
|
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
ptr += 18;
|
|
|
|
buf += 18;
|
|
|
|
}
|
|
|
|
/* zero bands */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = sblimit; j < SBLIMIT; j++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
/* overlap */
|
|
|
|
out_ptr = sb_samples + j;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 18; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
*out_ptr = buf[i];
|
2011-09-27 19:15:24 +02:00
|
|
|
buf[i] = 0;
|
2001-09-16 00:40:28 +02:00
|
|
|
out_ptr += SBLIMIT;
|
|
|
|
}
|
|
|
|
buf += 18;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main layer3 decoding function */
|
|
|
|
static int mp_decode_layer3(MPADecodeContext *s)
|
|
|
|
{
|
2011-05-31 19:38:01 +02:00
|
|
|
int nb_granules, main_data_begin;
|
2006-08-26 14:19:05 +02:00
|
|
|
int gr, ch, blocksplit_flag, i, j, k, n, bits_pos;
|
2009-11-05 00:33:08 +01:00
|
|
|
GranuleDef *g;
|
2010-05-11 21:52:42 +02:00
|
|
|
int16_t exponents[576]; //FIXME try INTFLOAT
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
/* read side info */
|
|
|
|
if (s->lsf) {
|
|
|
|
main_data_begin = get_bits(&s->gb, 8);
|
2011-05-31 19:38:01 +02:00
|
|
|
skip_bits(&s->gb, s->nb_channels);
|
2001-09-16 00:40:28 +02:00
|
|
|
nb_granules = 1;
|
|
|
|
} else {
|
|
|
|
main_data_begin = get_bits(&s->gb, 9);
|
|
|
|
if (s->nb_channels == 2)
|
2011-05-31 19:38:01 +02:00
|
|
|
skip_bits(&s->gb, 3);
|
2001-09-16 00:40:28 +02:00
|
|
|
else
|
2011-05-31 19:38:01 +02:00
|
|
|
skip_bits(&s->gb, 5);
|
2001-09-16 00:40:28 +02:00
|
|
|
nb_granules = 2;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2009-11-05 00:33:08 +01:00
|
|
|
s->granules[ch][0].scfsi = 0;/* all scale factors are transmitted */
|
|
|
|
s->granules[ch][1].scfsi = get_bits(&s->gb, 4);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
for (gr = 0; gr < nb_granules; gr++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2011-01-29 17:46:18 +01:00
|
|
|
av_dlog(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch);
|
2009-11-05 00:33:08 +01:00
|
|
|
g = &s->granules[ch][gr];
|
2001-09-16 00:40:28 +02:00
|
|
|
g->part2_3_length = get_bits(&s->gb, 12);
|
2011-09-27 19:15:24 +02:00
|
|
|
g->big_values = get_bits(&s->gb, 9);
|
|
|
|
if (g->big_values > 288) {
|
2007-03-12 13:36:41 +01:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n");
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-11-14 21:35:15 +01:00
|
|
|
}
|
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
g->global_gain = get_bits(&s->gb, 8);
|
|
|
|
/* if MS stereo only is selected, we precompute the
|
|
|
|
1/sqrt(2) renormalization factor */
|
2005-12-17 19:14:38 +01:00
|
|
|
if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
|
2001-09-16 00:40:28 +02:00
|
|
|
MODE_EXT_MS_STEREO)
|
|
|
|
g->global_gain -= 2;
|
|
|
|
if (s->lsf)
|
|
|
|
g->scalefac_compress = get_bits(&s->gb, 9);
|
|
|
|
else
|
|
|
|
g->scalefac_compress = get_bits(&s->gb, 4);
|
2007-08-09 02:13:31 +02:00
|
|
|
blocksplit_flag = get_bits1(&s->gb);
|
2001-09-16 00:40:28 +02:00
|
|
|
if (blocksplit_flag) {
|
|
|
|
g->block_type = get_bits(&s->gb, 2);
|
2011-09-27 19:15:24 +02:00
|
|
|
if (g->block_type == 0) {
|
2008-07-20 16:58:49 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "invalid block type\n");
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-11-14 21:35:15 +01:00
|
|
|
}
|
2007-08-09 02:13:31 +02:00
|
|
|
g->switch_point = get_bits1(&s->gb);
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 2; i++)
|
2001-09-16 00:40:28 +02:00
|
|
|
g->table_select[i] = get_bits(&s->gb, 5);
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 3; i++)
|
2001-09-16 00:40:28 +02:00
|
|
|
g->subblock_gain[i] = get_bits(&s->gb, 3);
|
2008-01-11 22:34:05 +01:00
|
|
|
ff_init_short_region(s, g);
|
2001-09-16 00:40:28 +02:00
|
|
|
} else {
|
2008-01-11 22:34:05 +01:00
|
|
|
int region_address1, region_address2;
|
2001-09-16 00:40:28 +02:00
|
|
|
g->block_type = 0;
|
|
|
|
g->switch_point = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 3; i++)
|
2001-09-16 00:40:28 +02:00
|
|
|
g->table_select[i] = get_bits(&s->gb, 5);
|
|
|
|
/* compute huffman coded region sizes */
|
|
|
|
region_address1 = get_bits(&s->gb, 4);
|
|
|
|
region_address2 = get_bits(&s->gb, 3);
|
2011-01-29 17:46:18 +01:00
|
|
|
av_dlog(s->avctx, "region1=%d region2=%d\n",
|
2001-09-16 00:40:28 +02:00
|
|
|
region_address1, region_address2);
|
2008-01-11 22:34:05 +01:00
|
|
|
ff_init_long_region(s, g, region_address1, region_address2);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2008-01-11 22:34:05 +01:00
|
|
|
ff_region_offset2size(g);
|
|
|
|
ff_compute_band_indexes(s, g);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
g->preflag = 0;
|
|
|
|
if (!s->lsf)
|
2007-08-09 02:13:31 +02:00
|
|
|
g->preflag = get_bits1(&s->gb);
|
2011-09-27 19:15:24 +02:00
|
|
|
g->scalefac_scale = get_bits1(&s->gb);
|
2007-08-09 02:13:31 +02:00
|
|
|
g->count1table_select = get_bits1(&s->gb);
|
2011-01-29 17:46:18 +01:00
|
|
|
av_dlog(s->avctx, "block_type=%d switch_point=%d\n",
|
2001-09-16 00:40:28 +02:00
|
|
|
g->block_type, g->switch_point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
if (!s->adu_mode) {
|
|
|
|
const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
|
|
|
|
assert((get_bits_count(&s->gb) & 7) == 0);
|
|
|
|
/* now we get bits from the main_data_begin offset */
|
|
|
|
av_dlog(s->avctx, "seekback: %d\n", main_data_begin);
|
|
|
|
//av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size);
|
2006-08-26 14:19:05 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES);
|
|
|
|
s->in_gb = s->gb;
|
2006-11-14 23:06:28 +01:00
|
|
|
init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8);
|
2011-12-31 19:36:48 +01:00
|
|
|
#if !UNCHECKED_BITSTREAM_READER
|
2011-12-17 17:19:24 +01:00
|
|
|
s->gb.size_in_bits_plus8 += EXTRABYTES * 8;
|
|
|
|
#endif
|
2012-01-01 01:13:06 +01:00
|
|
|
skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin));
|
2011-12-30 22:08:21 +01:00
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2012-01-01 01:13:06 +01:00
|
|
|
for (gr = 0; gr < nb_granules; gr++) {
|
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2011-12-30 22:08:21 +01:00
|
|
|
g = &s->granules[ch][gr];
|
2012-01-01 01:13:06 +01:00
|
|
|
if (get_bits_count(&s->gb) < 0) {
|
|
|
|
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));
|
|
|
|
if (get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer) {
|
|
|
|
skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits);
|
|
|
|
s->gb = s->in_gb;
|
|
|
|
s->in_gb.buffer = NULL;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
bits_pos = get_bits_count(&s->gb);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
if (!s->lsf) {
|
2003-02-11 17:35:48 +01:00
|
|
|
uint8_t *sc;
|
2001-09-16 00:40:28 +02:00
|
|
|
int slen, slen1, slen2;
|
|
|
|
|
|
|
|
/* MPEG1 scale factors */
|
|
|
|
slen1 = slen_table[0][g->scalefac_compress];
|
|
|
|
slen2 = slen_table[1][g->scalefac_compress];
|
2011-01-29 17:46:18 +01:00
|
|
|
av_dlog(s->avctx, "slen1=%d slen2=%d\n", slen1, slen2);
|
2001-09-16 00:40:28 +02:00
|
|
|
if (g->block_type == 2) {
|
|
|
|
n = g->switch_point ? 17 : 18;
|
|
|
|
j = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
if (slen1) {
|
|
|
|
for (i = 0; i < n; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = get_bits(&s->gb, slen1);
|
2011-09-27 19:15:24 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < n; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = 0;
|
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
if (slen2) {
|
|
|
|
for (i = 0; i < 18; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = get_bits(&s->gb, slen2);
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < 3; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < 21; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = 0;
|
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
} else {
|
2009-11-05 00:33:08 +01:00
|
|
|
sc = s->granules[ch][0].scale_factors;
|
2001-09-16 00:40:28 +02:00
|
|
|
j = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (k = 0; k < 4; k++) {
|
|
|
|
n = k == 0 ? 6 : 5;
|
2001-09-16 00:40:28 +02:00
|
|
|
if ((g->scfsi & (0x8 >> k)) == 0) {
|
|
|
|
slen = (k < 2) ? slen1 : slen2;
|
2011-09-27 19:15:24 +02:00
|
|
|
if (slen) {
|
|
|
|
for (i = 0; i < n; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = get_bits(&s->gb, slen);
|
2011-09-27 19:15:24 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < n; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = 0;
|
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
} else {
|
|
|
|
/* simply copy from last granule */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < n; i++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
g->scale_factors[j] = sc[j];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g->scale_factors[j++] = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int tindex, tindex2, slen[4], sl, sf;
|
|
|
|
|
|
|
|
/* LSF scale factors */
|
2011-09-27 19:15:24 +02:00
|
|
|
if (g->block_type == 2)
|
2001-09-16 00:40:28 +02:00
|
|
|
tindex = g->switch_point ? 2 : 1;
|
2011-09-27 19:15:24 +02:00
|
|
|
else
|
2001-09-16 00:40:28 +02:00
|
|
|
tindex = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
sf = g->scalefac_compress;
|
|
|
|
if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {
|
|
|
|
/* intensity stereo case */
|
|
|
|
sf >>= 1;
|
|
|
|
if (sf < 180) {
|
|
|
|
lsf_sf_expand(slen, sf, 6, 6, 0);
|
|
|
|
tindex2 = 3;
|
|
|
|
} else if (sf < 244) {
|
|
|
|
lsf_sf_expand(slen, sf - 180, 4, 4, 0);
|
|
|
|
tindex2 = 4;
|
|
|
|
} else {
|
|
|
|
lsf_sf_expand(slen, sf - 244, 3, 0, 0);
|
|
|
|
tindex2 = 5;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* normal case */
|
|
|
|
if (sf < 400) {
|
|
|
|
lsf_sf_expand(slen, sf, 5, 4, 4);
|
|
|
|
tindex2 = 0;
|
|
|
|
} else if (sf < 500) {
|
|
|
|
lsf_sf_expand(slen, sf - 400, 5, 4, 0);
|
|
|
|
tindex2 = 1;
|
|
|
|
} else {
|
|
|
|
lsf_sf_expand(slen, sf - 500, 3, 0, 0);
|
|
|
|
tindex2 = 2;
|
|
|
|
g->preflag = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
j = 0;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (k = 0; k < 4; k++) {
|
|
|
|
n = lsf_nsf_table[tindex2][tindex][k];
|
2001-09-16 00:40:28 +02:00
|
|
|
sl = slen[k];
|
2011-09-27 19:15:24 +02:00
|
|
|
if (sl) {
|
|
|
|
for (i = 0; i < n; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = get_bits(&s->gb, sl);
|
2011-09-27 19:15:24 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < n; i++)
|
2006-08-24 13:18:41 +02:00
|
|
|
g->scale_factors[j++] = 0;
|
|
|
|
}
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
/* XXX: should compute exact size */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (; j < 40; j++)
|
2001-09-16 00:40:28 +02:00
|
|
|
g->scale_factors[j] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
exponents_from_scale_factors(s, g, exponents);
|
|
|
|
|
|
|
|
/* read Huffman coded residue */
|
2006-11-14 23:06:28 +01:00
|
|
|
huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);
|
2001-09-16 00:40:28 +02:00
|
|
|
} /* ch */
|
|
|
|
|
|
|
|
if (s->nb_channels == 2)
|
2009-11-05 00:33:08 +01:00
|
|
|
compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]);
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2009-11-05 00:33:08 +01:00
|
|
|
g = &s->granules[ch][gr];
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
reorder_block(s, g);
|
2011-05-19 14:36:21 +02:00
|
|
|
compute_antialias(s, g);
|
2005-12-17 19:14:38 +01:00
|
|
|
compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
} /* gr */
|
2011-09-27 19:15:24 +02:00
|
|
|
if (get_bits_count(&s->gb) < 0)
|
2006-11-14 23:06:28 +01:00
|
|
|
skip_bits_long(&s->gb, -get_bits_count(&s->gb));
|
2001-09-16 00:40:28 +02:00
|
|
|
return nb_granules * 18;
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static int mp_decode_frame(MPADecodeContext *s, OUT_INT *samples,
|
|
|
|
const uint8_t *buf, int buf_size)
|
2001-09-16 00:40:28 +02:00
|
|
|
{
|
2011-09-06 18:17:45 +02:00
|
|
|
int i, nb_frames, ch, ret;
|
2005-01-31 13:16:21 +01:00
|
|
|
OUT_INT *samples_ptr;
|
2001-09-16 00:40:28 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* skip error protection field */
|
|
|
|
if (s->error_protection)
|
2007-08-09 02:57:36 +02:00
|
|
|
skip_bits(&s->gb, 16);
|
2001-09-16 00:40:28 +02:00
|
|
|
|
|
|
|
switch(s->layer) {
|
|
|
|
case 1:
|
2008-03-20 10:38:55 +01:00
|
|
|
s->avctx->frame_size = 384;
|
2001-09-16 00:40:28 +02:00
|
|
|
nb_frames = mp_decode_layer1(s);
|
|
|
|
break;
|
|
|
|
case 2:
|
2008-03-20 10:38:55 +01:00
|
|
|
s->avctx->frame_size = 1152;
|
2001-09-16 00:40:28 +02:00
|
|
|
nb_frames = mp_decode_layer2(s);
|
|
|
|
break;
|
|
|
|
case 3:
|
2008-03-20 10:38:55 +01:00
|
|
|
s->avctx->frame_size = s->lsf ? 576 : 1152;
|
2001-09-16 00:40:28 +02:00
|
|
|
default:
|
|
|
|
nb_frames = mp_decode_layer3(s);
|
2006-08-26 14:19:05 +02:00
|
|
|
|
2006-08-27 13:42:40 +02:00
|
|
|
s->last_buf_size=0;
|
2011-09-27 19:15:24 +02:00
|
|
|
if (s->in_gb.buffer) {
|
2006-08-27 13:42:40 +02:00
|
|
|
align_get_bits(&s->gb);
|
2011-09-27 19:15:24 +02:00
|
|
|
i = get_bits_left(&s->gb)>>3;
|
|
|
|
if (i >= 0 && i <= BACKSTEP_SIZE) {
|
2006-08-27 13:42:40 +02:00
|
|
|
memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);
|
|
|
|
s->last_buf_size=i;
|
2011-09-27 19:15:24 +02:00
|
|
|
} else
|
2008-07-20 16:58:49 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i);
|
2011-09-27 19:15:24 +02:00
|
|
|
s->gb = s->in_gb;
|
|
|
|
s->in_gb.buffer = NULL;
|
2006-08-27 13:42:40 +02:00
|
|
|
}
|
|
|
|
|
2006-08-26 14:19:05 +02:00
|
|
|
align_get_bits(&s->gb);
|
|
|
|
assert((get_bits_count(&s->gb) & 7) == 0);
|
2011-09-27 19:15:24 +02:00
|
|
|
i = get_bits_left(&s->gb) >> 3;
|
2006-08-27 13:42:40 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) {
|
|
|
|
if (i < 0)
|
2008-09-16 03:49:32 +02:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i);
|
2011-09-27 19:15:24 +02:00
|
|
|
i = FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);
|
2006-08-28 18:15:40 +02:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
assert(i <= buf_size - HEADER_SIZE && i >= 0);
|
2006-08-28 18:15:40 +02:00
|
|
|
memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);
|
2006-08-27 13:42:40 +02:00
|
|
|
s->last_buf_size += i;
|
2011-09-06 18:17:45 +02:00
|
|
|
}
|
2006-08-26 14:19:05 +02:00
|
|
|
|
2011-09-06 18:17:45 +02:00
|
|
|
/* get output buffer */
|
|
|
|
if (!samples) {
|
|
|
|
s->frame.nb_samples = s->avctx->frame_size;
|
|
|
|
if ((ret = s->avctx->get_buffer(s->avctx, &s->frame)) < 0) {
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
samples = (OUT_INT *)s->frame.data[0];
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
2008-08-31 22:26:28 +02:00
|
|
|
|
2001-09-16 00:40:28 +02:00
|
|
|
/* apply the synthesis filter */
|
2011-09-27 19:15:24 +02:00
|
|
|
for (ch = 0; ch < s->nb_channels; ch++) {
|
2001-09-16 00:40:28 +02:00
|
|
|
samples_ptr = samples + ch;
|
2011-09-27 19:15:24 +02:00
|
|
|
for (i = 0; i < nb_frames; i++) {
|
2010-06-19 11:56:05 +02:00
|
|
|
RENAME(ff_mpa_synth_filter)(
|
2011-05-16 17:52:01 +02:00
|
|
|
&s->mpadsp,
|
2010-06-19 11:56:05 +02:00
|
|
|
s->synth_buf[ch], &(s->synth_buf_offset[ch]),
|
2010-05-11 21:52:42 +02:00
|
|
|
RENAME(ff_mpa_synth_window), &s->dither_state,
|
2005-12-22 02:10:11 +01:00
|
|
|
samples_ptr, s->nb_channels,
|
2001-09-16 00:40:28 +02:00
|
|
|
s->sb_samples[ch][i]);
|
|
|
|
samples_ptr += 32 * s->nb_channels;
|
|
|
|
}
|
|
|
|
}
|
2008-08-31 22:26:28 +02:00
|
|
|
|
2005-01-31 13:16:21 +01:00
|
|
|
return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
|
2001-09-16 00:40:28 +02:00
|
|
|
}
|
|
|
|
|
2011-09-06 18:17:45 +02:00
|
|
|
static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
|
2009-04-07 17:59:50 +02:00
|
|
|
AVPacket *avpkt)
|
2001-07-22 16:18:56 +02:00
|
|
|
{
|
2011-09-27 19:15:24 +02:00
|
|
|
const uint8_t *buf = avpkt->data;
|
|
|
|
int buf_size = avpkt->size;
|
2001-07-22 16:18:56 +02:00
|
|
|
MPADecodeContext *s = avctx->priv_data;
|
2003-02-11 17:35:48 +01:00
|
|
|
uint32_t header;
|
2006-08-26 14:19:05 +02:00
|
|
|
int out_size;
|
2001-07-22 16:18:56 +02:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
if (buf_size < HEADER_SIZE)
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-08-26 14:19:05 +02:00
|
|
|
|
2007-06-02 03:41:07 +02:00
|
|
|
header = AV_RB32(buf);
|
2011-09-27 19:15:24 +02:00
|
|
|
if (ff_mpa_check_header(header) < 0) {
|
2009-06-30 05:57:27 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Header missing\n");
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-08-26 14:19:05 +02:00
|
|
|
}
|
|
|
|
|
2011-10-17 09:28:53 +02:00
|
|
|
if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
|
2006-08-26 14:19:05 +02:00
|
|
|
/* free format: prepare to compute frame size */
|
|
|
|
s->frame_size = -1;
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-08-26 14:19:05 +02:00
|
|
|
}
|
|
|
|
/* update codec info */
|
2011-09-27 19:15:24 +02:00
|
|
|
avctx->channels = s->nb_channels;
|
2011-02-05 18:59:48 +01:00
|
|
|
avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
|
2010-07-27 12:08:34 +02:00
|
|
|
if (!avctx->bit_rate)
|
|
|
|
avctx->bit_rate = s->bit_rate;
|
2006-08-26 14:19:05 +02:00
|
|
|
avctx->sub_id = s->layer;
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
if (s->frame_size <= 0 || s->frame_size > buf_size) {
|
2006-08-26 14:19:05 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-09-08 10:27:51 +02:00
|
|
|
}else if(s->frame_size < buf_size){
|
2011-09-08 21:04:26 +02:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, "incorrect frame size - multiple frames in buffer?\n");
|
2007-05-28 00:34:49 +02:00
|
|
|
buf_size= s->frame_size;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
2006-08-26 14:19:05 +02:00
|
|
|
|
2011-09-06 18:17:45 +02:00
|
|
|
out_size = mp_decode_frame(s, NULL, buf, buf_size);
|
2011-09-27 19:15:24 +02:00
|
|
|
if (out_size >= 0) {
|
2011-09-06 18:17:45 +02:00
|
|
|
*got_frame_ptr = 1;
|
|
|
|
*(AVFrame *)data = s->frame;
|
2006-10-30 03:19:55 +01:00
|
|
|
avctx->sample_rate = s->sample_rate;
|
|
|
|
//FIXME maybe move the other codec info stuff from above here too
|
2011-09-27 16:39:54 +02:00
|
|
|
} else {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");
|
|
|
|
/* Only return an error if the bad frame makes up the whole packet.
|
|
|
|
If there is more data in the packet, just consume the bad frame
|
|
|
|
instead of returning an error, which would discard the whole
|
|
|
|
packet. */
|
2011-09-06 18:17:45 +02:00
|
|
|
*got_frame_ptr = 0;
|
2011-09-27 16:39:54 +02:00
|
|
|
if (buf_size == avpkt->size)
|
|
|
|
return out_size;
|
|
|
|
}
|
2006-08-26 14:19:05 +02:00
|
|
|
s->frame_size = 0;
|
2009-06-30 05:57:27 +02:00
|
|
|
return buf_size;
|
2001-07-22 16:18:56 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
static void flush(AVCodecContext *avctx)
|
|
|
|
{
|
2006-11-14 21:39:20 +01:00
|
|
|
MPADecodeContext *s = avctx->priv_data;
|
2008-01-11 19:20:42 +01:00
|
|
|
memset(s->synth_buf, 0, sizeof(s->synth_buf));
|
2011-09-27 19:15:24 +02:00
|
|
|
s->last_buf_size = 0;
|
2006-11-14 21:39:20 +01:00
|
|
|
}
|
|
|
|
|
2010-07-01 23:08:20 +02:00
|
|
|
#if CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER
|
2011-09-06 18:17:45 +02:00
|
|
|
static int decode_frame_adu(AVCodecContext *avctx, void *data,
|
|
|
|
int *got_frame_ptr, AVPacket *avpkt)
|
2005-01-15 15:59:47 +01:00
|
|
|
{
|
2011-09-27 19:15:24 +02:00
|
|
|
const uint8_t *buf = avpkt->data;
|
|
|
|
int buf_size = avpkt->size;
|
2005-01-15 15:59:47 +01:00
|
|
|
MPADecodeContext *s = avctx->priv_data;
|
|
|
|
uint32_t header;
|
|
|
|
int len, out_size;
|
|
|
|
|
|
|
|
len = buf_size;
|
|
|
|
|
|
|
|
// Discard too short frames
|
|
|
|
if (buf_size < HEADER_SIZE) {
|
2011-10-25 18:45:39 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
2005-01-15 15:59:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (len > MPA_MAX_CODED_FRAME_SIZE)
|
|
|
|
len = MPA_MAX_CODED_FRAME_SIZE;
|
|
|
|
|
|
|
|
// Get header and restore sync word
|
2007-06-02 03:41:07 +02:00
|
|
|
header = AV_RB32(buf) | 0xffe00000;
|
2005-01-15 15:59:47 +01:00
|
|
|
|
2005-01-30 15:04:56 +01:00
|
|
|
if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame
|
2011-10-25 18:45:39 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid frame header\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
2005-01-15 15:59:47 +01:00
|
|
|
}
|
|
|
|
|
2011-10-17 09:28:53 +02:00
|
|
|
avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header);
|
2005-01-15 15:59:47 +01:00
|
|
|
/* update codec info */
|
|
|
|
avctx->sample_rate = s->sample_rate;
|
2011-09-27 19:15:24 +02:00
|
|
|
avctx->channels = s->nb_channels;
|
2010-07-27 12:08:34 +02:00
|
|
|
if (!avctx->bit_rate)
|
|
|
|
avctx->bit_rate = s->bit_rate;
|
2005-01-15 15:59:47 +01:00
|
|
|
avctx->sub_id = s->layer;
|
|
|
|
|
2008-03-20 10:36:04 +01:00
|
|
|
s->frame_size = len;
|
2005-01-15 15:59:47 +01:00
|
|
|
|
2011-09-27 19:54:25 +02:00
|
|
|
#if FF_API_PARSE_FRAME
|
2011-09-27 19:15:24 +02:00
|
|
|
if (avctx->parse_only)
|
2006-08-26 14:19:05 +02:00
|
|
|
out_size = buf_size;
|
2011-09-27 19:15:24 +02:00
|
|
|
else
|
2011-09-27 19:54:25 +02:00
|
|
|
#endif
|
2011-09-06 18:17:45 +02:00
|
|
|
out_size = mp_decode_frame(s, NULL, buf, buf_size);
|
|
|
|
|
|
|
|
*got_frame_ptr = 1;
|
|
|
|
*(AVFrame *)data = s->frame;
|
2005-01-15 15:59:47 +01:00
|
|
|
|
|
|
|
return buf_size;
|
|
|
|
}
|
2010-07-01 23:08:20 +02:00
|
|
|
#endif /* CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER */
|
2005-01-15 15:59:47 +01:00
|
|
|
|
2010-07-01 23:08:20 +02:00
|
|
|
#if CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER
|
2008-04-26 15:56:52 +02:00
|
|
|
|
2008-04-26 16:22:43 +02:00
|
|
|
/**
|
|
|
|
* Context for MP3On4 decoder
|
|
|
|
*/
|
|
|
|
typedef struct MP3On4DecodeContext {
|
2011-09-06 18:17:45 +02:00
|
|
|
AVFrame *frame;
|
2011-09-27 19:15:24 +02:00
|
|
|
int frames; ///< number of mp3 frames per block (number of mp3 decoder instances)
|
|
|
|
int syncword; ///< syncword patch
|
|
|
|
const uint8_t *coff; ///< channel offsets in output buffer
|
2008-04-26 16:22:43 +02:00
|
|
|
MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance
|
2011-09-25 18:30:16 +02:00
|
|
|
OUT_INT *decoded_buf; ///< output buffer for decoded samples
|
2008-04-26 16:22:43 +02:00
|
|
|
} MP3On4DecodeContext;
|
|
|
|
|
2008-04-26 15:56:52 +02:00
|
|
|
#include "mpeg4audio.h"
|
|
|
|
|
2005-02-15 21:58:32 +01:00
|
|
|
/* Next 3 arrays are indexed by channel config number (passed via codecdata) */
|
2011-09-27 19:15:24 +02:00
|
|
|
|
|
|
|
/* number of mp3 decoder instances */
|
|
|
|
static const uint8_t mp3Frames[8] = { 0, 1, 1, 2, 3, 3, 4, 5 };
|
|
|
|
|
2011-09-25 18:46:54 +02:00
|
|
|
/* offsets into output buffer, assume output order is FL FR C LFE BL BR SL SR */
|
2008-04-26 16:08:34 +02:00
|
|
|
static const uint8_t chan_offset[8][5] = {
|
2011-09-27 19:15:24 +02:00
|
|
|
{ 0 },
|
|
|
|
{ 0 }, // C
|
|
|
|
{ 0 }, // FLR
|
|
|
|
{ 2, 0 }, // C FLR
|
|
|
|
{ 2, 0, 3 }, // C FLR BS
|
|
|
|
{ 2, 0, 3 }, // C FLR BLRS
|
|
|
|
{ 2, 0, 4, 3 }, // C FLR BLRS LFE
|
|
|
|
{ 2, 0, 6, 4, 3 }, // C FLR BLRS BLR LFE
|
2005-02-15 21:58:32 +01:00
|
|
|
};
|
|
|
|
|
2011-09-25 18:52:11 +02:00
|
|
|
/* mp3on4 channel layouts */
|
|
|
|
static const int16_t chan_layout[8] = {
|
|
|
|
0,
|
|
|
|
AV_CH_LAYOUT_MONO,
|
|
|
|
AV_CH_LAYOUT_STEREO,
|
|
|
|
AV_CH_LAYOUT_SURROUND,
|
|
|
|
AV_CH_LAYOUT_4POINT0,
|
|
|
|
AV_CH_LAYOUT_5POINT0,
|
|
|
|
AV_CH_LAYOUT_5POINT1,
|
|
|
|
AV_CH_LAYOUT_7POINT1
|
|
|
|
};
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2011-09-25 18:30:16 +02:00
|
|
|
static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
|
|
|
|
{
|
|
|
|
MP3On4DecodeContext *s = avctx->priv_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < s->frames; i++)
|
|
|
|
av_free(s->mp3decctx[i]);
|
|
|
|
|
|
|
|
av_freep(&s->decoded_buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-15 21:58:32 +01:00
|
|
|
|
|
|
|
static int decode_init_mp3on4(AVCodecContext * avctx)
|
|
|
|
{
|
|
|
|
MP3On4DecodeContext *s = avctx->priv_data;
|
2008-04-26 15:56:52 +02:00
|
|
|
MPEG4AudioConfig cfg;
|
2005-02-15 21:58:32 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if ((avctx->extradata_size < 2) || (avctx->extradata == NULL)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n");
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
|
2011-10-21 17:25:30 +02:00
|
|
|
avpriv_mpeg4audio_get_config(&cfg, avctx->extradata,
|
|
|
|
avctx->extradata_size * 8, 1);
|
2008-04-26 15:56:52 +02:00
|
|
|
if (!cfg.chan_config || cfg.chan_config > 7) {
|
2005-02-15 21:58:32 +01:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
2011-09-27 19:15:24 +02:00
|
|
|
s->frames = mp3Frames[cfg.chan_config];
|
|
|
|
s->coff = chan_offset[cfg.chan_config];
|
|
|
|
avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
|
2011-09-25 18:52:11 +02:00
|
|
|
avctx->channel_layout = chan_layout[cfg.chan_config];
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2008-04-26 16:18:29 +02:00
|
|
|
if (cfg.sample_rate < 16000)
|
|
|
|
s->syncword = 0xffe00000;
|
|
|
|
else
|
|
|
|
s->syncword = 0xfff00000;
|
|
|
|
|
2005-02-15 21:58:32 +01:00
|
|
|
/* Init the first mp3 decoder in standard way, so that all tables get builded
|
|
|
|
* We replace avctx->priv_data with the context of the first decoder so that
|
|
|
|
* decode_init() does not have to be changed.
|
2008-02-13 10:26:10 +01:00
|
|
|
* Other decoders will be initialized here copying data from the first context
|
2005-02-15 21:58:32 +01:00
|
|
|
*/
|
|
|
|
// Allocate zeroed memory for the first decoder context
|
|
|
|
s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
|
2011-09-25 20:32:42 +02:00
|
|
|
if (!s->mp3decctx[0])
|
|
|
|
goto alloc_fail;
|
2005-02-15 21:58:32 +01:00
|
|
|
// Put decoder context in place to make init_decode() happy
|
|
|
|
avctx->priv_data = s->mp3decctx[0];
|
|
|
|
decode_init(avctx);
|
2011-09-06 18:17:45 +02:00
|
|
|
s->frame = avctx->coded_frame;
|
2005-02-15 21:58:32 +01:00
|
|
|
// Restore mp3on4 context pointer
|
|
|
|
avctx->priv_data = s;
|
|
|
|
s->mp3decctx[0]->adu_mode = 1; // Set adu mode
|
|
|
|
|
|
|
|
/* Create a separate codec/context for each frame (first is already ok).
|
|
|
|
* Each frame is 1 or 2 channels - up to 5 frames allowed
|
|
|
|
*/
|
|
|
|
for (i = 1; i < s->frames; i++) {
|
|
|
|
s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
|
2011-09-25 20:32:42 +02:00
|
|
|
if (!s->mp3decctx[i])
|
|
|
|
goto alloc_fail;
|
2005-02-15 21:58:32 +01:00
|
|
|
s->mp3decctx[i]->adu_mode = 1;
|
2007-03-12 13:36:41 +01:00
|
|
|
s->mp3decctx[i]->avctx = avctx;
|
2011-09-25 18:16:34 +02:00
|
|
|
s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp;
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
|
2011-09-25 18:30:16 +02:00
|
|
|
/* Allocate buffer for multi-channel output if needed */
|
|
|
|
if (s->frames > 1) {
|
|
|
|
s->decoded_buf = av_malloc(MPA_FRAME_SIZE * MPA_MAX_CHANNELS *
|
|
|
|
sizeof(*s->decoded_buf));
|
|
|
|
if (!s->decoded_buf)
|
|
|
|
goto alloc_fail;
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-09-25 18:30:16 +02:00
|
|
|
alloc_fail:
|
|
|
|
decode_close_mp3on4(avctx);
|
|
|
|
return AVERROR(ENOMEM);
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-25 19:39:04 +02:00
|
|
|
static void flush_mp3on4(AVCodecContext *avctx)
|
2005-02-15 21:58:32 +01:00
|
|
|
{
|
|
|
|
int i;
|
2011-09-25 19:39:04 +02:00
|
|
|
MP3On4DecodeContext *s = avctx->priv_data;
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2011-09-25 19:39:04 +02:00
|
|
|
for (i = 0; i < s->frames; i++) {
|
|
|
|
MPADecodeContext *m = s->mp3decctx[i];
|
|
|
|
memset(m->synth_buf, 0, sizeof(m->synth_buf));
|
|
|
|
m->last_buf_size = 0;
|
|
|
|
}
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 18:17:45 +02:00
|
|
|
static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
|
|
|
|
int *got_frame_ptr, AVPacket *avpkt)
|
2005-02-15 21:58:32 +01:00
|
|
|
{
|
2011-09-27 19:15:24 +02:00
|
|
|
const uint8_t *buf = avpkt->data;
|
|
|
|
int buf_size = avpkt->size;
|
2005-02-15 21:58:32 +01:00
|
|
|
MP3On4DecodeContext *s = avctx->priv_data;
|
|
|
|
MPADecodeContext *m;
|
2008-04-26 16:36:34 +02:00
|
|
|
int fsize, len = buf_size, out_size = 0;
|
2005-02-15 21:58:32 +01:00
|
|
|
uint32_t header;
|
2011-09-06 18:17:45 +02:00
|
|
|
OUT_INT *out_samples;
|
2005-02-15 21:58:32 +01:00
|
|
|
OUT_INT *outptr, *bp;
|
2011-09-06 18:17:45 +02:00
|
|
|
int fr, j, n, ch, ret;
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2011-09-06 18:17:45 +02:00
|
|
|
/* get output buffer */
|
|
|
|
s->frame->nb_samples = MPA_FRAME_SIZE;
|
|
|
|
if ((ret = avctx->get_buffer(avctx, s->frame)) < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
|
|
|
|
return ret;
|
2011-09-25 19:04:39 +02:00
|
|
|
}
|
2011-09-06 18:17:45 +02:00
|
|
|
out_samples = (OUT_INT *)s->frame->data[0];
|
2009-09-23 13:33:44 +02:00
|
|
|
|
2005-02-15 21:58:32 +01:00
|
|
|
// Discard too short frames
|
2008-04-26 14:39:45 +02:00
|
|
|
if (buf_size < HEADER_SIZE)
|
2011-09-27 17:49:50 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2005-02-15 21:58:32 +01:00
|
|
|
|
|
|
|
// If only one decoder interleave is not needed
|
2011-09-25 18:30:16 +02:00
|
|
|
outptr = s->frames == 1 ? out_samples : s->decoded_buf;
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2008-04-26 16:33:09 +02:00
|
|
|
avctx->bit_rate = 0;
|
|
|
|
|
2011-09-25 19:04:39 +02:00
|
|
|
ch = 0;
|
2005-02-15 21:58:32 +01:00
|
|
|
for (fr = 0; fr < s->frames; fr++) {
|
2008-04-26 15:08:16 +02:00
|
|
|
fsize = AV_RB16(buf) >> 4;
|
2008-04-26 14:51:52 +02:00
|
|
|
fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);
|
2011-09-27 19:15:24 +02:00
|
|
|
m = s->mp3decctx[fr];
|
|
|
|
assert(m != NULL);
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2008-04-26 16:18:29 +02:00
|
|
|
header = (AV_RB32(buf) & 0x000fffff) | s->syncword; // patch header
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2008-04-26 16:41:29 +02:00
|
|
|
if (ff_mpa_check_header(header) < 0) // Bad header, discard block
|
|
|
|
break;
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2011-10-17 09:28:53 +02:00
|
|
|
avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header);
|
2011-09-25 19:04:39 +02:00
|
|
|
|
|
|
|
if (ch + m->nb_channels > avctx->channels) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
|
|
|
|
"channel count\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
ch += m->nb_channels;
|
|
|
|
|
2008-04-26 16:10:31 +02:00
|
|
|
out_size += mp_decode_frame(m, outptr, buf, fsize);
|
2011-09-27 19:15:24 +02:00
|
|
|
buf += fsize;
|
|
|
|
len -= fsize;
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2011-09-27 19:15:24 +02:00
|
|
|
if (s->frames > 1) {
|
2008-04-26 15:03:41 +02:00
|
|
|
n = m->avctx->frame_size*m->nb_channels;
|
2005-02-15 21:58:32 +01:00
|
|
|
/* interleave output data */
|
2008-04-26 16:28:18 +02:00
|
|
|
bp = out_samples + s->coff[fr];
|
2011-09-27 19:15:24 +02:00
|
|
|
if (m->nb_channels == 1) {
|
|
|
|
for (j = 0; j < n; j++) {
|
2011-09-25 18:30:16 +02:00
|
|
|
*bp = s->decoded_buf[j];
|
2008-04-26 16:30:06 +02:00
|
|
|
bp += avctx->channels;
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-09-27 19:15:24 +02:00
|
|
|
for (j = 0; j < n; j++) {
|
2011-09-25 18:30:16 +02:00
|
|
|
bp[0] = s->decoded_buf[j++];
|
|
|
|
bp[1] = s->decoded_buf[j];
|
2011-09-27 19:15:24 +02:00
|
|
|
bp += avctx->channels;
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-26 16:33:09 +02:00
|
|
|
avctx->bit_rate += m->bit_rate;
|
2005-02-15 21:58:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update codec info */
|
|
|
|
avctx->sample_rate = s->mp3decctx[0]->sample_rate;
|
|
|
|
|
2011-09-06 18:17:45 +02:00
|
|
|
s->frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT));
|
|
|
|
*got_frame_ptr = 1;
|
|
|
|
*(AVFrame *)data = *s->frame;
|
|
|
|
|
2005-02-15 21:58:32 +01:00
|
|
|
return buf_size;
|
|
|
|
}
|
2010-07-01 23:08:20 +02:00
|
|
|
#endif /* CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER */
|
2005-02-15 21:58:32 +01:00
|
|
|
|
2010-05-11 21:52:42 +02:00
|
|
|
#if !CONFIG_FLOAT
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_MP1_DECODER
|
2011-09-23 21:11:15 +02:00
|
|
|
AVCodec ff_mp1_decoder = {
|
|
|
|
.name = "mp1",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.id = CODEC_ID_MP1,
|
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
|
|
|
.decode = decode_frame,
|
2011-09-27 19:54:25 +02:00
|
|
|
#if FF_API_PARSE_FRAME
|
2011-09-06 18:17:45 +02:00
|
|
|
.capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
|
|
|
|
#else
|
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2011-09-27 19:54:25 +02:00
|
|
|
#endif
|
2011-09-23 21:11:15 +02:00
|
|
|
.flush = flush,
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
|
2009-01-13 20:32:08 +01:00
|
|
|
};
|
|
|
|
#endif
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_MP2_DECODER
|
2011-09-23 21:11:15 +02:00
|
|
|
AVCodec ff_mp2_decoder = {
|
|
|
|
.name = "mp2",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.id = CODEC_ID_MP2,
|
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
|
|
|
.decode = decode_frame,
|
2011-09-27 19:54:25 +02:00
|
|
|
#if FF_API_PARSE_FRAME
|
2011-09-06 18:17:45 +02:00
|
|
|
.capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
|
|
|
|
#else
|
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2011-09-27 19:54:25 +02:00
|
|
|
#endif
|
2011-09-23 21:11:15 +02:00
|
|
|
.flush = flush,
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
|
2001-07-22 16:18:56 +02:00
|
|
|
};
|
2006-09-27 21:54:07 +02:00
|
|
|
#endif
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_MP3_DECODER
|
2011-09-23 21:11:15 +02:00
|
|
|
AVCodec ff_mp3_decoder = {
|
|
|
|
.name = "mp3",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.id = CODEC_ID_MP3,
|
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
|
|
|
.decode = decode_frame,
|
2011-09-27 19:54:25 +02:00
|
|
|
#if FF_API_PARSE_FRAME
|
2011-09-06 18:17:45 +02:00
|
|
|
.capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
|
|
|
|
#else
|
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2011-09-27 19:54:25 +02:00
|
|
|
#endif
|
2011-09-23 21:11:15 +02:00
|
|
|
.flush = flush,
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
|
2002-04-15 04:28:05 +02:00
|
|
|
};
|
2006-09-27 21:54:07 +02:00
|
|
|
#endif
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_MP3ADU_DECODER
|
2011-09-23 21:11:15 +02:00
|
|
|
AVCodec ff_mp3adu_decoder = {
|
|
|
|
.name = "mp3adu",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.id = CODEC_ID_MP3ADU,
|
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
|
|
|
.decode = decode_frame_adu,
|
2011-09-27 19:54:25 +02:00
|
|
|
#if FF_API_PARSE_FRAME
|
2011-09-06 18:17:45 +02:00
|
|
|
.capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1,
|
|
|
|
#else
|
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2011-09-27 19:54:25 +02:00
|
|
|
#endif
|
2011-09-23 21:11:15 +02:00
|
|
|
.flush = flush,
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
|
2005-01-15 15:59:47 +01:00
|
|
|
};
|
2006-09-27 21:54:07 +02:00
|
|
|
#endif
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_MP3ON4_DECODER
|
2011-09-23 21:11:15 +02:00
|
|
|
AVCodec ff_mp3on4_decoder = {
|
|
|
|
.name = "mp3on4",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.id = CODEC_ID_MP3ON4,
|
|
|
|
.priv_data_size = sizeof(MP3On4DecodeContext),
|
|
|
|
.init = decode_init_mp3on4,
|
|
|
|
.close = decode_close_mp3on4,
|
|
|
|
.decode = decode_frame_mp3on4,
|
2011-09-06 18:17:45 +02:00
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2011-09-25 19:39:04 +02:00
|
|
|
.flush = flush_mp3on4,
|
2011-09-23 21:11:15 +02:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
|
2005-02-15 21:58:32 +01:00
|
|
|
};
|
2006-09-27 21:54:07 +02:00
|
|
|
#endif
|
2010-05-11 21:52:42 +02:00
|
|
|
#endif
|