diff options
Diffstat (limited to 'libavcodec/ra288.c')
-rw-r--r-- | libavcodec/ra288.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c index 96d8d1ece1..f1b3c8eab5 100644 --- a/libavcodec/ra288.c +++ b/libavcodec/ra288.c @@ -2,20 +2,20 @@ * RealAudio 2.0 (28.8K) * Copyright (c) 2003 The FFmpeg project * - * 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 */ @@ -39,7 +39,7 @@ #define RA288_BLOCKS_PER_FRAME 32 typedef struct RA288Context { - AVFloatDSPContext fdsp; + AVFloatDSPContext *fdsp; DECLARE_ALIGNED(32, float, sp_lpc)[FFALIGN(36, 16)]; ///< LPC coefficients for speech data (spec: A) DECLARE_ALIGNED(32, float, gain_lpc)[FFALIGN(10, 16)]; ///< LPC coefficients for gain (spec: GB) @@ -60,6 +60,15 @@ typedef struct RA288Context { float gain_rec[11]; } RA288Context; +static av_cold int ra288_decode_close(AVCodecContext *avctx) +{ + RA288Context *ractx = avctx->priv_data; + + av_freep(&ractx->fdsp); + + return 0; +} + static av_cold int ra288_decode_init(AVCodecContext *avctx) { RA288Context *ractx = avctx->priv_data; @@ -68,7 +77,14 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx) avctx->channel_layout = AV_CH_LAYOUT_MONO; avctx->sample_fmt = AV_SAMPLE_FMT_FLT; - avpriv_float_dsp_init(&ractx->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT); + if (avctx->block_align <= 0) { + av_log(avctx, AV_LOG_ERROR, "unsupported block align\n"); + return AVERROR_PATCHWELCOME; + } + + ractx->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); + if (!ractx->fdsp) + return AVERROR(ENOMEM); return 0; } @@ -105,14 +121,14 @@ static void decode(RA288Context *ractx, float gain, int cb_coef) for (i=0; i < 5; i++) buffer[i] = codetable[cb_coef][i] * sumsum; - sum = avpriv_scalarproduct_float_c(buffer, buffer, 5) * ((1 << 24) / 5.0); + sum = avpriv_scalarproduct_float_c(buffer, buffer, 5); - sum = FFMAX(sum, 1); + sum = FFMAX(sum, 5.0 / (1<<24)); /* shift and store */ memmove(gain_block, gain_block + 1, 9 * sizeof(*gain_block)); - gain_block[9] = 10 * log10(sum) - 32; + gain_block[9] = 10 * log10(sum) + (10*log10(((1<<24)/5.)) - 32); ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36); } @@ -140,7 +156,9 @@ static void do_hybrid_window(RA288Context *ractx, MAX_BACKWARD_FILTER_LEN + MAX_BACKWARD_FILTER_NONREC, 16)]); - ractx->fdsp.vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 16)); + av_assert2(order>=0); + + ractx->fdsp->vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 16)); convolve(buffer1, work + order , n , order); convolve(buffer2, work + order + n, non_rec, order); @@ -167,7 +185,7 @@ static void backward_filter(RA288Context *ractx, do_hybrid_window(ractx, order, n, non_rec, temp, hist, rec, window); if (!compute_lpc_coefs(temp, order, lpc, 0, 1, 1)) - ractx->fdsp.vector_fmul(lpc, lpc, tab, FFALIGN(order, 16)); + ractx->fdsp->vector_fmul(lpc, lpc, tab, FFALIGN(order, 16)); memmove(hist, hist + n, move_size*sizeof(*hist)); } @@ -190,16 +208,16 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data, return AVERROR_INVALIDDATA; } + ret = init_get_bits8(&gb, buf, avctx->block_align); + if (ret < 0) + return ret; + /* get output buffer */ frame->nb_samples = RA288_BLOCK_SIZE * RA288_BLOCKS_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; - } out = (float *)frame->data[0]; - init_get_bits(&gb, buf, avctx->block_align * 8); - for (i=0; i < RA288_BLOCKS_PER_FRAME; i++) { float gain = amptable[get_bits(&gb, 3)]; int cb_coef = get_bits(&gb, 6 + (i&1)); @@ -231,5 +249,6 @@ AVCodec ff_ra_288_decoder = { .priv_data_size = sizeof(RA288Context), .init = ra288_decode_init, .decode = ra288_decode_frame, + .close = ra288_decode_close, .capabilities = AV_CODEC_CAP_DR1, }; |