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
This commit is contained in:
Jason Garrett-Glaser 2010-10-26 07:20:51 +00:00
parent fc3128c9d5
commit 313b52fbff
1 changed files with 13 additions and 21 deletions

View File

@ -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;
}