Reset internal state on corrupted blocks in wavpack decoder.

wavpack_decode_block() supposes that it is called back with the exact
same buffer unless it has returned with an error. With multi-channels
files, wavpack_decode_frame() was breaking this assumption.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Laurent Aimar 2011-09-26 23:37:30 +02:00 committed by Michael Niedermayer
parent fc64434030
commit c2a016ad4d
1 changed files with 13 additions and 10 deletions

View File

@ -1174,6 +1174,15 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
return samplecount * bpp; return samplecount * bpp;
} }
static void wavpack_decode_flush(AVCodecContext *avctx)
{
WavpackContext *s = avctx->priv_data;
int i;
for (i = 0; i < s->fdec_num; i++)
wv_reset_saved_context(s->fdec[i]);
}
static int wavpack_decode_frame(AVCodecContext *avctx, static int wavpack_decode_frame(AVCodecContext *avctx,
void *data, int *data_size, void *data, int *data_size,
AVPacket *avpkt) AVPacket *avpkt)
@ -1206,11 +1215,14 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
if(frame_size < 0 || frame_size > buf_size){ if(frame_size < 0 || frame_size > buf_size){
av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d vs. %d bytes left)\n", av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d vs. %d bytes left)\n",
s->block, frame_size, buf_size); s->block, frame_size, buf_size);
wavpack_decode_flush(avctx);
return -1; return -1;
} }
if((samplecount = wavpack_decode_block(avctx, s->block, data, if((samplecount = wavpack_decode_block(avctx, s->block, data,
data_size, buf, frame_size)) < 0) data_size, buf, frame_size)) < 0) {
wavpack_decode_flush(avctx);
return -1; return -1;
}
s->block++; s->block++;
buf += frame_size; buf_size -= frame_size; buf += frame_size; buf_size -= frame_size;
} }
@ -1219,15 +1231,6 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
return s->samples_left > 0 ? 0 : avpkt->size; return s->samples_left > 0 ? 0 : avpkt->size;
} }
static void wavpack_decode_flush(AVCodecContext *avctx)
{
WavpackContext *s = avctx->priv_data;
int i;
for (i = 0; i < s->fdec_num; i++)
wv_reset_saved_context(s->fdec[i]);
}
AVCodec ff_wavpack_decoder = { AVCodec ff_wavpack_decoder = {
.name = "wavpack", .name = "wavpack",
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,