Mercurial > libavcodec.hg
comparison h264.c @ 4592:9fc8acda3223 libavcodec
rewrite find_frame_end()
new code correctly splits long start codes, also its about twice as fast
author | michael |
---|---|
date | Sun, 25 Feb 2007 02:38:08 +0000 |
parents | 644687c58928 |
children | a96d905dcbaa |
comparison
equal
deleted
inserted
replaced
4591:16c24b902f43 | 4592:9fc8acda3223 |
---|---|
7988 uint32_t state; | 7988 uint32_t state; |
7989 ParseContext *pc = &(h->s.parse_context); | 7989 ParseContext *pc = &(h->s.parse_context); |
7990 //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); | 7990 //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); |
7991 // mb_addr= pc->mb_addr - 1; | 7991 // mb_addr= pc->mb_addr - 1; |
7992 state= pc->state; | 7992 state= pc->state; |
7993 for(i=0; i<=buf_size; i++){ | 7993 if(state>13) |
7994 if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){ | 7994 state= 7; |
7995 tprintf("find_frame_end new startcode = %08x, frame_start_found = %d, pos = %d\n", state, pc->frame_start_found, i); | 7995 |
7996 if(pc->frame_start_found){ | 7996 for(i=0; i<buf_size; i++){ |
7997 // If there isn't one more byte in the buffer | 7997 if(state==7){ |
7998 // the test on first_mb_in_slice cannot be done yet | 7998 for(; i<buf_size; i++){ |
7999 // do it at next call. | 7999 if(!buf[i]){ |
8000 if (i >= buf_size) break; | 8000 state=2; |
8001 if (buf[i] & 0x80) { | 8001 break; |
8002 // first_mb_in_slice is 0, probably the first nal of a new | 8002 } |
8003 // slice | 8003 } |
8004 tprintf("find_frame_end frame_end_found, state = %08x, pos = %d\n", state, i); | 8004 }else if(state<=2){ |
8005 pc->state=-1; | 8005 if(buf[i]==1) state^= 5; //2->7, 1->4, 0->5 |
8006 else if(buf[i]) state = 7; | |
8007 else state>>=1; //2->1, 1->0, 0->0 | |
8008 }else if(state<=5){ | |
8009 int v= buf[i] & 0x1F; | |
8010 if(v==7 || v==8 || v==9){ | |
8011 if(pc->frame_start_found){ | |
8012 i++; | |
8013 found: | |
8014 pc->state=7; | |
8006 pc->frame_start_found= 0; | 8015 pc->frame_start_found= 0; |
8007 return i-4; | 8016 return i-(state&5); |
8008 } | 8017 } |
8009 } | 8018 }else if(v==1 || v==2 || v==5){ |
8010 pc->frame_start_found = 1; | 8019 if(pc->frame_start_found){ |
8011 } | 8020 state+=8; |
8012 if((state&0xFFFFFF1F) == 0x107 || (state&0xFFFFFF1F) == 0x108 || (state&0xFFFFFF1F) == 0x109){ | 8021 continue; |
8013 if(pc->frame_start_found){ | 8022 }else |
8014 pc->state=-1; | 8023 pc->frame_start_found = 1; |
8015 pc->frame_start_found= 0; | 8024 } |
8016 return i-4; | 8025 state= 7; |
8017 } | 8026 }else{ |
8018 } | 8027 if(buf[i] & 0x80) |
8019 if (i<buf_size) | 8028 goto found; |
8020 state= (state<<8) | buf[i]; | 8029 state= 7; |
8021 } | 8030 } |
8022 | 8031 } |
8023 pc->state= state; | 8032 pc->state= state; |
8024 return END_NOT_FOUND; | 8033 return END_NOT_FOUND; |
8025 } | 8034 } |
8026 | 8035 |
8027 #ifdef CONFIG_H264_PARSER | 8036 #ifdef CONFIG_H264_PARSER |
8038 | 8047 |
8039 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { | 8048 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { |
8040 *poutbuf = NULL; | 8049 *poutbuf = NULL; |
8041 *poutbuf_size = 0; | 8050 *poutbuf_size = 0; |
8042 return buf_size; | 8051 return buf_size; |
8052 } | |
8053 | |
8054 if(next<0){ | |
8055 find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state | |
8043 } | 8056 } |
8044 | 8057 |
8045 *poutbuf = (uint8_t *)buf; | 8058 *poutbuf = (uint8_t *)buf; |
8046 *poutbuf_size = buf_size; | 8059 *poutbuf_size = buf_size; |
8047 return next; | 8060 return next; |