diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index d794b7b221..8020d298c4 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -34,30 +34,48 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size) { - int i; + int i, j; uint32_t state; ParseContext *pc = &(h->s.parse_context); + int next_avc= h->is_avc ? 0 : buf_size; + //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); // mb_addr= pc->mb_addr - 1; state= pc->state; if(state>13) state= 7; + if(h->is_avc && !h->nal_length_size) + av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n"); + for(i=0; i= next_avc) { + int nalsize = 0; + i = next_avc; + for(j = 0; j < h->nal_length_size; j++) + nalsize = (nalsize << 8) | buf[i++]; + if(nalsize <= 0 || nalsize > buf_size - i){ + av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i); + return buf_size; + } + next_avc= i + nalsize; + state= 5; + } + if(state==7){ #if HAVE_FAST_UNALIGNED /* we check istate= state; + if(h->is_avc) + return next_avc; return END_NOT_FOUND; found: pc->state=7; pc->frame_start_found= 0; + if(h->is_avc) + return next_avc; return i-(state&5); } @@ -278,6 +300,7 @@ static int h264_parse(AVCodecParserContext *s, } } + if(!h->is_avc){ parse_nal_units(s, avctx, buf, buf_size); if (h->sei_cpb_removal_delay >= 0) { @@ -293,6 +316,7 @@ static int h264_parse(AVCodecParserContext *s, if (s->flags & PARSER_FLAG_ONCE) { s->flags &= PARSER_FLAG_COMPLETE_FRAMES; } + } *poutbuf = buf; *poutbuf_size = buf_size;