mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
h264_parser: AVC support.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
2f503851c6
commit
d5c0e89e7a
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user