From 313b52fbfff47ed934cdeccaebda9b3406466575 Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Tue, 26 Oct 2010 07:20:51 +0000 Subject: Clean up ALACdec Do decode init in the init function instead of at the first frame. Fix some possible crash cases. Originally committed as revision 25572 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/alac.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'libavcodec/alac.c') diff --git a/libavcodec/alac.c b/libavcodec/alac.c index 07b03c126f..c5a8b5d8c6 100644 --- a/libavcodec/alac.c +++ b/libavcodec/alac.c @@ -65,9 +65,6 @@ typedef struct { AVCodecContext *avctx; GetBitContext gb; - /* init to 0; first frame decode should initialize from extradata and - * set this to 1 */ - int context_initialized; int numchannels; int bytespersample; @@ -471,21 +468,7 @@ static int alac_decode_frame(AVCodecContext *avctx, /* short-circuit null buffers */ if (!inbuffer || !input_buffer_size) - return input_buffer_size; - - /* initialize from the extradata */ - if (!alac->context_initialized) { - if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) { - av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n", - ALAC_EXTRADATA_SIZE); - return input_buffer_size; - } - if (alac_set_info(alac)) { - av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n"); - return input_buffer_size; - } - alac->context_initialized = 1; - } + return -1; init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8); @@ -493,7 +476,7 @@ static int alac_decode_frame(AVCodecContext *avctx, if (channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n", MAX_CHANNELS); - return input_buffer_size; + return -1; } /* 2^result = something to do with output waiting. @@ -678,10 +661,19 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) { ALACContext *alac = avctx->priv_data; alac->avctx = avctx; - alac->context_initialized = 0; - alac->numchannels = alac->avctx->channels; + /* initialize from the extradata */ + if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) { + av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n", + ALAC_EXTRADATA_SIZE); + return -1; + } + if (alac_set_info(alac)) { + av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n"); + return -1; + } + return 0; } -- cgit v1.2.3