aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/h264_parser.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-10-03 20:25:43 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-10-03 23:43:22 +0200
commitd5c0e89e7a5e5a2502cbbd429f3c8cbc2c4d2313 (patch)
tree9daaf19ec0690856e4f0a0e2563cbe8f2e4d737e /libavcodec/h264_parser.c
parent2f503851c688637ea5e7848fb7e009b9812be591 (diff)
downloadandroid_external_ffmpeg-d5c0e89e7a5e5a2502cbbd429f3c8cbc2c4d2313.tar.gz
android_external_ffmpeg-d5c0e89e7a5e5a2502cbbd429f3c8cbc2c4d2313.tar.bz2
android_external_ffmpeg-d5c0e89e7a5e5a2502cbbd429f3c8cbc2c4d2313.zip
h264_parser: AVC support.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/h264_parser.c')
-rw-r--r--libavcodec/h264_parser.c32
1 files changed, 28 insertions, 4 deletions
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<buf_size; i++){
+ if(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 i<buf_size instead of i+3/7 because its simpler
* and there should be FF_INPUT_BUFFER_PADDING_SIZE bytes at the end
*/
# if HAVE_FAST_64BIT
- while(i<buf_size && !((~*(const uint64_t*)(buf+i) & (*(const uint64_t*)(buf+i) - 0x0101010101010101ULL)) & 0x8080808080808080ULL))
+ while(i<next_avc && !((~*(const uint64_t*)(buf+i) & (*(const uint64_t*)(buf+i) - 0x0101010101010101ULL)) & 0x8080808080808080ULL))
i+=8;
# else
- while(i<buf_size && !((~*(const uint32_t*)(buf+i) & (*(const uint32_t*)(buf+i) - 0x01010101U)) & 0x80808080U))
+ while(i<next_avc && !((~*(const uint32_t*)(buf+i) & (*(const uint32_t*)(buf+i) - 0x01010101U)) & 0x80808080U))
i+=4;
# endif
#endif
- for(; i<buf_size; i++){
+ for(; i<next_avc; i++){
if(!buf[i]){
state=2;
break;
@@ -89,11 +107,15 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si
}
}
pc->state= 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;