From 3fa6d205338c2c019eb024e9b79b5b07c2d72dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= <Reimar.Doeffinger@gmx.de> Date: Sat, 18 Feb 2012 10:29:58 +0100 Subject: [PATCH] H264 parser: enable header parsing/frame type detection for is_avc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de> --- libavcodec/h264_parser.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index c9dea81a491..3d557599e0d 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -166,12 +166,25 @@ static inline int parse_nal_units(AVCodecParserContext *s, return 0; for(;;) { - int src_length, dst_length, consumed; + int src_length, dst_length, consumed, nalsize = 0; + if (h->is_avc) { + int i; + if (h->nal_length_size >= buf_end - buf) break; + nalsize = 0; + for (i = 0; i < h->nal_length_size; i++) + nalsize = (nalsize << 8) | *buf++; + if (nalsize <= 0 || nalsize > buf_end - buf) { + av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); + break; + } + src_length = nalsize; + } else { buf = avpriv_mpv_find_start_code(buf, buf_end, &state); if(buf >= buf_end) break; --buf; src_length = buf_end - buf; + } switch (state & 0x1f) { case NAL_SLICE: case NAL_IDR_SLICE: @@ -267,7 +280,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, return 0; /* no need to evaluate the rest */ } - buf += consumed; + buf += h->is_avc ? nalsize : consumed; } if (q264) return 0; @@ -316,7 +329,6 @@ 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) { @@ -332,7 +344,6 @@ static int h264_parse(AVCodecParserContext *s, if (s->flags & PARSER_FLAG_ONCE) { s->flags &= PARSER_FLAG_COMPLETE_FRAMES; } - } *poutbuf = buf; *poutbuf_size = buf_size; -- GitLab