diff options
Diffstat (limited to 'libavcodec/alac.c')
-rw-r--r-- | libavcodec/alac.c | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/libavcodec/alac.c b/libavcodec/alac.c index ab9fb81..6b5078f 100644 --- a/libavcodec/alac.c +++ b/libavcodec/alac.c @@ -2,20 +2,20 @@ * ALAC (Apple Lossless Audio Codec) decoder * Copyright (c) 2005 David Hammerton * - * 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 */ @@ -108,7 +108,7 @@ static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsam return x; } -static void bastardized_rice_decompress(ALACContext *alac, +static int bastardized_rice_decompress(ALACContext *alac, int32_t *output_buffer, int output_size, int readsamplesize, /* arg_10 */ @@ -130,6 +130,9 @@ static void bastardized_rice_decompress(ALACContext *alac, /* standard rice encoding */ int k; /* size of extra bits */ + if(get_bits_left(&alac->gb) <= 0) + return -1; + /* read k, that is bits as is */ k = av_log2((history >> 9) + 3); x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize); @@ -175,6 +178,7 @@ static void bastardized_rice_decompress(ALACContext *alac, history = 0; } } + return 0; } static inline int sign_only(int v) @@ -347,6 +351,17 @@ static void interleave_stereo_24(int32_t *buffer[MAX_CHANNELS], } } +static void interleave_stereo_32(int32_t *buffer[MAX_CHANNELS], + int32_t *buffer_out, int numsamples) +{ + int i; + + for (i = 0; i < numsamples; i++) { + *buffer_out++ = buffer[0][i]; + *buffer_out++ = buffer[1][i]; + } +} + static int alac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { @@ -438,12 +453,14 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, if (alac->extra_bits) { for (i = 0; i < outputsamples; i++) { + if(get_bits_left(&alac->gb) <= 0) + return -1; for (ch = 0; ch < channels; ch++) alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits); } } for (ch = 0; ch < channels; ch++) { - bastardized_rice_decompress(alac, + int ret = bastardized_rice_decompress(alac, alac->predicterror_buffer[ch], outputsamples, readsamplesize, @@ -451,6 +468,8 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, alac->setinfo_rice_kmodifier, ricemodifier[ch] * alac->setinfo_rice_historymult / 4, (1 << alac->setinfo_rice_kmodifier) - 1); + if(ret<0) + return ret; /* adaptive FIR filter */ if (prediction_type[ch] == 15) { @@ -479,6 +498,8 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, } else { /* not compressed, easy case */ for (i = 0; i < outputsamples; i++) { + if(get_bits_left(&alac->gb) <= 0) + return -1; for (ch = 0; ch < channels; ch++) { alac->outputsamples_buffer[ch][i] = get_sbits_long(&alac->gb, alac->setinfo_sample_size); @@ -523,6 +544,16 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data, outbuffer[i] = alac->outputsamples_buffer[0][i] << 8; } break; + case 32: + if (channels == 2) { + interleave_stereo_32(alac->outputsamples_buffer, + (int32_t *)alac->frame.data[0], outputsamples); + } else { + int32_t *outbuffer = (int32_t *)alac->frame.data[0]; + for (i = 0; i < outputsamples; i++) + outbuffer[i] = alac->outputsamples_buffer[0][i]; + } + break; } if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8) @@ -619,6 +650,7 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) switch (alac->setinfo_sample_size) { case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16; break; + case 32: case 24: avctx->sample_fmt = AV_SAMPLE_FMT_S32; break; default: av_log_ask_for_sample(avctx, "Sample depth %d is not supported.\n", |