diff options
Diffstat (limited to 'libavcodec/atrac3.c')
-rw-r--r-- | libavcodec/atrac3.c | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index c4201fb418..89c877aecb 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -3,20 +3,20 @@ * Copyright (c) 2006-2008 Maxim Poliakovski * Copyright (c) 2006-2008 Benjamin Larsson * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -38,6 +38,7 @@ #include "libavutil/attributes.h" #include "libavutil/float_dsp.h" +#include "libavutil/libm.h" #include "avcodec.h" #include "bytestream.h" #include "fft.h" @@ -104,9 +105,9 @@ typedef struct ATRAC3Context { int scrambled_stream; //@} - AtracGCContext gainc_ctx; - FFTContext mdct_ctx; - AVFloatDSPContext fdsp; + AtracGCContext gainc_ctx; + FFTContext mdct_ctx; + AVFloatDSPContext *fdsp; } ATRAC3Context; static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE]; @@ -139,7 +140,7 @@ static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band) q->mdct_ctx.imdct_calc(&q->mdct_ctx, output, input); /* Perform windowing on the output. */ - q->fdsp.vector_fmul(output, output, mdct_window, MDCT_SIZE); + q->fdsp->vector_fmul(output, output, mdct_window, MDCT_SIZE); } /* @@ -187,8 +188,9 @@ static av_cold int atrac3_decode_close(AVCodecContext *avctx) { ATRAC3Context *q = avctx->priv_data; - av_free(q->units); - av_free(q->decoded_bytes_buffer); + av_freep(&q->units); + av_freep(&q->decoded_bytes_buffer); + av_freep(&q->fdsp); ff_mdct_end(&q->mdct_ctx); @@ -407,17 +409,17 @@ static int decode_tonal_components(GetBitContext *gb, static int decode_gain_control(GetBitContext *gb, GainBlock *block, int num_bands) { - int i, j; + int b, j; int *level, *loc; AtracGainInfo *gain = block->g_block; - for (i = 0; i <= num_bands; i++) { - gain[i].num_points = get_bits(gb, 3); - level = gain[i].lev_code; - loc = gain[i].loc_code; + for (b = 0; b <= num_bands; b++) { + gain[b].num_points = get_bits(gb, 3); + level = gain[b].lev_code; + loc = gain[b].loc_code; - for (j = 0; j < gain[i].num_points; j++) { + for (j = 0; j < gain[b].num_points; j++) { level[j] = get_bits(gb, 4); loc[j] = get_bits(gb, 5); if (j && loc[j] <= loc[j - 1]) @@ -426,8 +428,8 @@ static int decode_gain_control(GetBitContext *gb, GainBlock *block, } /* Clear the unused blocks. */ - for (; i < 4 ; i++) - gain[i].num_points = 0; + for (; b < 4 ; b++) + gain[b].num_points = 0; return 0; } @@ -518,7 +520,7 @@ static void reverse_matrixing(float *su1, float *su2, int *prev_code, } break; default: - assert(0); + av_assert1(0); } } } @@ -673,7 +675,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, /* set the bitstream reader at the start of the second Sound Unit*/ - init_get_bits(&q->gb, ptr1, (avctx->block_align - i) * 8); + init_get_bits8(&q->gb, ptr1, q->decoded_bytes_buffer + avctx->block_align - ptr1); /* Fill the Weighting coeffs delay buffer */ memmove(q->weighting_delay, &q->weighting_delay[2], @@ -747,10 +749,8 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data, /* get output buffer */ frame->nb_samples = SAMPLES_PER_FRAME; - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - } /* Check if we need to descramble and what buffer to pass on. */ if (q->scrambled_stream) { @@ -771,7 +771,7 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data, return avctx->block_align; } -static av_cold void atrac3_init_static_data(AVCodec *codec) +static av_cold void atrac3_init_static_data(void) { int i; @@ -791,6 +791,7 @@ static av_cold void atrac3_init_static_data(AVCodec *codec) static av_cold int atrac3_decode_init(AVCodecContext *avctx) { + static int static_init_done; int i, ret; int version, delay, samples_per_frame, frame_factor; const uint8_t *edata_ptr = avctx->extradata; @@ -801,6 +802,10 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } + if (!static_init_done) + atrac3_init_static_data(); + static_init_done = 1; + /* Take care of the codec-specific extradata. */ if (avctx->extradata_size == 14) { /* Parse the extradata, WAV format */ @@ -829,7 +834,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) avctx->channels, frame_factor); return AVERROR_INVALIDDATA; } - } else if (avctx->extradata_size == 10) { + } else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) { /* Parse the extradata, RM format. */ version = bytestream_get_be32(&edata_ptr); samples_per_frame = bytestream_get_be16(&edata_ptr); @@ -866,8 +871,10 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) if (q->coding_mode == STEREO) av_log(avctx, AV_LOG_DEBUG, "Normal stereo detected.\n"); else if (q->coding_mode == JOINT_STEREO) { - if (avctx->channels != 2) + if (avctx->channels != 2) { + av_log(avctx, AV_LOG_ERROR, "Invalid coding mode\n"); return AVERROR_INVALIDDATA; + } av_log(avctx, AV_LOG_DEBUG, "Joint stereo detected.\n"); } else { av_log(avctx, AV_LOG_ERROR, "Unknown channel coding mode %x!\n", @@ -907,10 +914,10 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) } ff_atrac_init_gain_compensation(&q->gainc_ctx, 4, 3); - avpriv_float_dsp_init(&q->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT); + q->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); - q->units = av_mallocz(sizeof(*q->units) * avctx->channels); - if (!q->units) { + q->units = av_mallocz_array(avctx->channels, sizeof(*q->units)); + if (!q->units || !q->fdsp) { atrac3_decode_close(avctx); return AVERROR(ENOMEM); } @@ -925,7 +932,6 @@ AVCodec ff_atrac3_decoder = { .id = AV_CODEC_ID_ATRAC3, .priv_data_size = sizeof(ATRAC3Context), .init = atrac3_decode_init, - .init_static_data = atrac3_init_static_data, .close = atrac3_decode_close, .decode = atrac3_decode_frame, .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1, |