summaryrefslogtreecommitdiff
path: root/libavcodec/h264.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-07-23 17:38:41 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-07-23 17:40:21 +0200
commit1bf371b24ebd0804d2cc041b45eba295b02d80c6 (patch)
treeadab48328e663a8f21d503aa85ff5ce4bf871348 /libavcodec/h264.c
parent54256482cbc0ef334c076d3b07bc6023588495f2 (diff)
avcodec/h264: factor is_extra() out
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/h264.c')
-rw-r--r--libavcodec/h264.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index ba3a7898cf..f4fcef0847 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1819,6 +1819,28 @@ static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
return 0;
}
+static int is_extra(const uint8_t *buf, int buf_size)
+{
+ int cnt= buf[5]&0x1f;
+ const uint8_t *p= buf+6;
+ while(cnt--){
+ int nalsize= AV_RB16(p) + 2;
+ if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
+ return 0;
+ p += nalsize;
+ }
+ cnt = *(p++);
+ if(!cnt)
+ return 0;
+ while(cnt--){
+ int nalsize= AV_RB16(p) + 2;
+ if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
+ return 0;
+ p += nalsize;
+ }
+ return 1;
+}
+
static int h264_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
@@ -1870,27 +1892,9 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data,
return buf_index;
}
if(h->is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
- int cnt= buf[5]&0x1f;
- const uint8_t *p= buf+6;
- while(cnt--){
- int nalsize= AV_RB16(p) + 2;
- if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
- goto not_extra;
- p += nalsize;
- }
- cnt = *(p++);
- if(!cnt)
- goto not_extra;
- while(cnt--){
- int nalsize= AV_RB16(p) + 2;
- if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
- goto not_extra;
- p += nalsize;
- }
-
- return ff_h264_decode_extradata(h, buf, buf_size);
+ if (is_extra(buf, buf_size))
+ return ff_h264_decode_extradata(h, buf, buf_size);
}
-not_extra:
buf_index = decode_nal_units(h, buf, buf_size, 0);
if (buf_index < 0)