flac_parser.c: fix issue with looping output for small files.

see trac 1345
https://ffmpeg.org/trac/ffmpeg/ticket/1345

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Chinen 2012-10-14 16:08:43 +09:00 committed by Michael Niedermayer
parent 41bf943f70
commit c73b1a1d80
1 changed files with 9 additions and 5 deletions

View File

@ -541,14 +541,18 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
av_freep(&fpc->best_header); av_freep(&fpc->best_header);
} }
/* Find and score new headers. */ /* Find and score new headers. */
while ((buf && read_end < buf + buf_size && /* buf_size is to zero when padding, so check for this since we do */
/* not want to try to read more input once we have found the end. */
/* Note that as (non-modified) parameters, buf can be non-NULL, */
/* while buf_size is 0. */
while ((buf && buf_size && read_end < buf + buf_size &&
fpc->nb_headers_buffered < FLAC_MIN_HEADERS) fpc->nb_headers_buffered < FLAC_MIN_HEADERS)
|| (!buf && !fpc->end_padded)) { || ((!buf || !buf_size) && !fpc->end_padded)) {
int start_offset; int start_offset;
/* Pad the end once if EOF, to check the final region for headers. */ /* Pad the end once if EOF, to check the final region for headers. */
if (!buf) { if (!buf || !buf_size) {
fpc->end_padded = 1; fpc->end_padded = 1;
buf_size = MAX_FRAME_HEADER_SIZE; buf_size = MAX_FRAME_HEADER_SIZE;
read_end = read_start + MAX_FRAME_HEADER_SIZE; read_end = read_start + MAX_FRAME_HEADER_SIZE;
@ -569,7 +573,7 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
goto handle_error; goto handle_error;
} }
if (buf) { if (buf && buf_size) {
av_fifo_generic_write(fpc->fifo_buf, (void*) read_start, av_fifo_generic_write(fpc->fifo_buf, (void*) read_start,
read_end - read_start, NULL); read_end - read_start, NULL);
} else { } else {