X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fimc.c;h=2a420f5bcf0961933e145ff911449de8992bb380;hb=deca86eab1623b3391b7113b4ac6e74b8408639d;hp=7360b640969414456313847aa5500def143e1b78;hpb=3644d4724120defabf83b726caf097552fbb417d;p=ffmpeg diff --git a/libavcodec/imc.c b/libavcodec/imc.c index 7360b640969..2a420f5bcf0 100644 --- a/libavcodec/imc.c +++ b/libavcodec/imc.c @@ -19,11 +19,11 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** - * @file imc.c IMC - Intel Music Coder + * @file + * IMC - Intel Music Coder * A mdct based codec using a 256 points large transform * divied into 32 bands with some mix of scale factors. * Only mono is supported. @@ -37,11 +37,13 @@ #define ALT_BITSTREAM_READER #include "avcodec.h" -#include "bitstream.h" +#include "get_bits.h" #include "dsputil.h" +#include "fft.h" #include "imcdata.h" +#define IMC_BLOCK_SIZE 64 #define IMC_FRAME_ID 0x21 #define BANDS 32 #define COEFFS 256 @@ -79,18 +81,26 @@ typedef struct { int codewords[COEFFS]; ///< raw codewords read from bitstream float sqrt_tab[30]; GetBitContext gb; - VLC huffman_vlc[4][4]; int decoder_reset; float one_div_log2; DSPContext dsp; FFTContext fft; - DECLARE_ALIGNED_16(FFTComplex, samples[COEFFS/2]); - DECLARE_ALIGNED_16(float, out_samples[COEFFS]); + DECLARE_ALIGNED(16, FFTComplex, samples)[COEFFS/2]; + DECLARE_ALIGNED(16, float, out_samples)[COEFFS]; } IMCContext; +static VLC huffman_vlc[4][4]; + +#define VLC_TABLES_SIZE 9512 + +static const int vlc_offsets[17] = { + 0, 640, 1156, 1732, 2308, 2852, 3396, 3924, + 4452, 5220, 5860, 6628, 7268, 7908, 8424, 8936, VLC_TABLES_SIZE}; -static int imc_decode_init(AVCodecContext * avctx) +static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2]; + +static av_cold int imc_decode_init(AVCodecContext * avctx) { int i, j; IMCContext *q = avctx->priv_data; @@ -102,8 +112,9 @@ static int imc_decode_init(AVCodecContext * avctx) q->old_floor[i] = 1.0; /* Build mdct window, a simple sine window normalized with sqrt(2) */ + ff_sine_window_init(q->mdct_sine_window, COEFFS); for(i = 0; i < COEFFS; i++) - q->mdct_sine_window[i] = sin((i + 0.5) / 512.0 * M_PI) * sqrt(2.0); + q->mdct_sine_window[i] *= sqrt(2.0); for(i = 0; i < COEFFS/2; i++){ q->post_cos[i] = cos(i / 256.0 * M_PI); q->post_sin[i] = sin(i / 256.0 * M_PI); @@ -134,15 +145,19 @@ static int imc_decode_init(AVCodecContext * avctx) /* initialize the VLC tables */ for(i = 0; i < 4 ; i++) { for(j = 0; j < 4; j++) { - init_vlc (&q->huffman_vlc[i][j], 9, imc_huffman_sizes[i], + huffman_vlc[i][j].table = &vlc_tables[vlc_offsets[i * 4 + j]]; + huffman_vlc[i][j].table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j]; + init_vlc(&huffman_vlc[i][j], 9, imc_huffman_sizes[i], imc_huffman_lens[i][j], 1, 1, - imc_huffman_bits[i][j], 2, 2, 1); + imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC); } } q->one_div_log2 = 1/log(2); ff_fft_init(&q->fft, 7, 1); dsputil_init(&q->dsp, avctx); + avctx->sample_fmt = SAMPLE_FMT_S16; + avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; return 0; } @@ -209,10 +224,10 @@ static void imc_read_level_coeffs(IMCContext* q, int stream_format_code, int* le int s; s = stream_format_code >> 1; - hufftab[0] = &q->huffman_vlc[s][0]; - hufftab[1] = &q->huffman_vlc[s][1]; - hufftab[2] = &q->huffman_vlc[s][2]; - hufftab[3] = &q->huffman_vlc[s][3]; + hufftab[0] = &huffman_vlc[s][0]; + hufftab[1] = &huffman_vlc[s][1]; + hufftab[2] = &huffman_vlc[s][2]; + hufftab[3] = &huffman_vlc[s][3]; cb_sel = imc_cb_select[s]; if(stream_format_code & 4) @@ -347,7 +362,7 @@ static int bit_allocation (IMCContext* q, int stream_format_code, int freebits, iacc = 0; for(j = (stream_format_code & 0x2)?4:0; j < BANDS; j++) { - cwlen = clip((int)((q->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6); + cwlen = av_clip((int)((q->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6); q->bitsBandT[j] = cwlen; summer += q->bandWidthT[j] * cwlen; @@ -455,7 +470,7 @@ static void imc_get_skip_coeff(IMCContext* q) { q->skipFlagBits[i] = band_tab[i+1] - band_tab[i]; for(j = band_tab[i]; j < band_tab[i+1]; j++) { - if ((q->skipFlags[j] = get_bits(&q->gb,1))) + if ((q->skipFlags[j] = get_bits1(&q->gb))) q->skipFlagCount[i]++; } } else { @@ -486,7 +501,7 @@ static void imc_get_skip_coeff(IMCContext* q) { if (j < band_tab[i+1]) { q->skipFlagBits[i]++; - if ((q->skipFlags[j] = get_bits(&q->gb,1))) + if ((q->skipFlags[j] = get_bits1(&q->gb))) q->skipFlagCount[i]++; } } @@ -626,8 +641,10 @@ static int imc_get_coeffs (IMCContext* q) { static int imc_decode_frame(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buf, int buf_size) + AVPacket *avpkt) { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; IMCContext *q = avctx->priv_data; @@ -636,13 +653,16 @@ static int imc_decode_frame(AVCodecContext * avctx, int flag; int bits, summer; int counter, bitscount; - uint16_t *buf16 = (uint16_t *) buf; + uint16_t buf16[IMC_BLOCK_SIZE / 2]; - /* FIXME: input should not be modified */ - for(i = 0; i < FFMIN(buf_size, avctx->block_align) / 2; i++) - buf16[i] = bswap_16(buf16[i]); + if (buf_size < IMC_BLOCK_SIZE) { + av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n"); + return -1; + } + for(i = 0; i < IMC_BLOCK_SIZE / 2; i++) + buf16[i] = bswap_16(((const uint16_t*)buf)[i]); - init_get_bits(&q->gb, buf, 512); + init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8); /* Check the frame header */ imc_hdr = get_bits(&q->gb, 9); @@ -789,11 +809,11 @@ static int imc_decode_frame(AVCodecContext * avctx, *data_size = COEFFS * sizeof(int16_t); - return avctx->block_align; + return IMC_BLOCK_SIZE; } -static int imc_decode_close(AVCodecContext * avctx) +static av_cold int imc_decode_close(AVCodecContext * avctx) { IMCContext *q = avctx->priv_data; @@ -804,10 +824,11 @@ static int imc_decode_close(AVCodecContext * avctx) AVCodec imc_decoder = { .name = "imc", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_IMC, .priv_data_size = sizeof(IMCContext), .init = imc_decode_init, .close = imc_decode_close, .decode = imc_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("IMC (Intel Music Coder)"), };