diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c index 4827354f18..185bd4d667 100644 --- a/libavcodec/mlp_parser.c +++ b/libavcodec/mlp_parser.c @@ -259,65 +259,65 @@ static int mlp_parse(AVCodecParserContext *s, if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { next = buf_size; } else { - if (!mp->in_sync) { - // Not in sync - find a major sync header - - for (i = 0; i < buf_size; i++) { - mp->pc.state = (mp->pc.state << 8) | buf[i]; - if ((mp->pc.state & 0xfffffffe) == 0xf8726fba && - // ignore if we do not have the data for the start of header - mp->pc.index + i >= 7) { - mp->in_sync = 1; - mp->bytes_left = 0; - break; - } - } - if (!mp->in_sync) { - if (ff_combine_frame(&mp->pc, END_NOT_FOUND, &buf, &buf_size) != -1) + // Not in sync - find a major sync header + + for (i = 0; i < buf_size; i++) { + mp->pc.state = (mp->pc.state << 8) | buf[i]; + if ((mp->pc.state & 0xfffffffe) == 0xf8726fba && + // ignore if we do not have the data for the start of header + mp->pc.index + i >= 7) { + mp->in_sync = 1; + mp->bytes_left = 0; + break; + } + } + + if (!mp->in_sync) { + if (ff_combine_frame(&mp->pc, END_NOT_FOUND, &buf, &buf_size) != -1) + av_log(avctx, AV_LOG_WARNING, "ff_combine_frame failed\n"); + return buf_size; + } + + if ((ret = ff_combine_frame(&mp->pc, i - 7, &buf, &buf_size)) < 0) { av_log(avctx, AV_LOG_WARNING, "ff_combine_frame failed\n"); + return ret; + } + + return i - 7; + } + + if (mp->bytes_left == 0) { + // Find length of this packet + + /* Copy overread bytes from last frame into buffer. */ + for(; mp->pc.overread>0; mp->pc.overread--) { + mp->pc.buffer[mp->pc.index++]= mp->pc.buffer[mp->pc.overread_index++]; + } + + if (mp->pc.index + buf_size < 2) { + if (ff_combine_frame(&mp->pc, END_NOT_FOUND, &buf, &buf_size) != -1) + av_log(avctx, AV_LOG_WARNING, "ff_combine_frame failed\n"); + return buf_size; + } + + mp->bytes_left = ((mp->pc.index > 0 ? mp->pc.buffer[0] : buf[0]) << 8) + | (mp->pc.index > 1 ? mp->pc.buffer[1] : buf[1-mp->pc.index]); + mp->bytes_left = (mp->bytes_left & 0xfff) * 2; + if (mp->bytes_left <= 0) { // prevent infinite loop + goto lost_sync; + } + mp->bytes_left -= mp->pc.index; + } + + next = (mp->bytes_left > buf_size) ? END_NOT_FOUND : mp->bytes_left; + + if (ff_combine_frame(&mp->pc, next, &buf, &buf_size) < 0) { + mp->bytes_left -= buf_size; return buf_size; } - if ((ret = ff_combine_frame(&mp->pc, i - 7, &buf, &buf_size)) < 0) { - av_log(avctx, AV_LOG_WARNING, "ff_combine_frame failed\n"); - return ret; - } - - return i - 7; - } - - if (mp->bytes_left == 0) { - // Find length of this packet - - /* Copy overread bytes from last frame into buffer. */ - for(; mp->pc.overread>0; mp->pc.overread--) { - mp->pc.buffer[mp->pc.index++]= mp->pc.buffer[mp->pc.overread_index++]; - } - - if (mp->pc.index + buf_size < 2) { - if (ff_combine_frame(&mp->pc, END_NOT_FOUND, &buf, &buf_size) != -1) - av_log(avctx, AV_LOG_WARNING, "ff_combine_frame failed\n"); - return buf_size; - } - - mp->bytes_left = ((mp->pc.index > 0 ? mp->pc.buffer[0] : buf[0]) << 8) - | (mp->pc.index > 1 ? mp->pc.buffer[1] : buf[1-mp->pc.index]); - mp->bytes_left = (mp->bytes_left & 0xfff) * 2; - if (mp->bytes_left <= 0) { // prevent infinite loop - goto lost_sync; - } - mp->bytes_left -= mp->pc.index; - } - - next = (mp->bytes_left > buf_size) ? END_NOT_FOUND : mp->bytes_left; - - if (ff_combine_frame(&mp->pc, next, &buf, &buf_size) < 0) { - mp->bytes_left -= buf_size; - return buf_size; - } - - mp->bytes_left = 0; + mp->bytes_left = 0; } sync_present = (AV_RB32(buf + 4) & 0xfffffffe) == 0xf8726fba;