X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmpeg12.c;h=56b456a0783b5e8a00fb2db3892283bc36ab77a4;hb=31304587da246672a240216d95298bb0ba9f9c64;hp=87f673d121312a41449e84032799090da71a6d9e;hpb=e68c7a4abe9c259af44e3cc1414674743e76cc32;p=ffmpeg diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 87f673d1213..56b456a0783 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1869,7 +1869,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, } } eos: // end of slice - *buf += get_bits_count(&s->gb)/8 - 1; + *buf += (get_bits_count(&s->gb)-1)/8; //printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y); return 0; } @@ -2182,29 +2182,43 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) int i; uint32_t state= pc->state; - i=0; - if(!pc->frame_start_found){ - for(i=0; i 1/4 + 1 first_SEQEXT -> 0/2 + 2 first field start -> 3/0 + 3 second_SEQEXT -> 2/0 + 4 searching end +*/ + + for(i=0; iframe_start_found>=0 && pc->frame_start_found<=4); + if(pc->frame_start_found&1){ + if(state == EXT_START_CODE && (buf[i]&0xF0) != 0x80) + pc->frame_start_found--; + else if(state == EXT_START_CODE+2){ + if((buf[i]&3) == 3) pc->frame_start_found= 0; + else pc->frame_start_found= (pc->frame_start_found+1)&3; + } + state++; + }else{ i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1; - if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ + if(pc->frame_start_found==0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ i++; - pc->frame_start_found=1; - break; + pc->frame_start_found=4; } if(state == SEQ_END_CODE){ pc->state=-1; return i+1; } - } - } - - if(pc->frame_start_found){ - /* EOF considered as end of frame */ - if (buf_size == 0) - return 0; - for(; iframe_start_found==2 && state == SEQ_START_CODE) + pc->frame_start_found= 0; + if(pc->frame_start_found<4 && state == EXT_START_CODE) + pc->frame_start_found++; + if(pc->frame_start_found == 4 && (state&0xFFFFFF00) == 0x100){ if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ pc->frame_start_found=0; pc->state=-1;