diff options
author | Jason Garrett-Glaser <darkshikari@gmail.com> | 2010-10-26 07:20:51 +0000 |
---|---|---|
committer | Jason Garrett-Glaser <darkshikari@gmail.com> | 2010-10-26 07:20:51 +0000 |
commit | 313b52fbfff47ed934cdeccaebda9b3406466575 (patch) | |
tree | 0dc98815b25373c8181aa76cde85d0e288d365ff /libavcodec/alac.c | |
parent | fc3128c9d57ac7d3c572d87e3a0c5b8107eca3f4 (diff) | |
download | ffmpeg-313b52fbfff47ed934cdeccaebda9b3406466575.tar.gz |
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
Diffstat (limited to 'libavcodec/alac.c')
-rw-r--r-- | libavcodec/alac.c | 34 |
1 files changed, 13 insertions, 21 deletions
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; } |