int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size)
{
    int i;
    uint32_t state;
    ParseContext *pc = &(h->s.parse_context);
    state= pc->state;
    if(state>13)
        state= 7;
    for(i=0; i<buf_size; i++){
        if(state==7){
            for(; i<buf_size; i++){
                if(!buf[i]){
                    state=2;
                    break;
                }
            }
        }else if(state<=2){
            if(buf[i]==1)   state^= 5;
            else if(buf[i]) state = 7;
            else            state>>=1;
        }else if(state<=5){
            int v= buf[i] & 0x1F;
            if(v==7 || v==8 || v==9){
                if(pc->frame_start_found){
                    i++;
found:
                    pc->state=7;
                    pc->frame_start_found= 0;
                    return i-(state&5);
                }
            }else if(v==1 || v==2 || v==5){
                if(pc->frame_start_found){
                    state+=8;
                    continue;
                }else
                    pc->frame_start_found = 1;
            }
            state= 7;
        }else{
            if(buf[i] & 0x80)
                goto found;
            state= 7;
        }
    }
    pc->state= state;
    return END_NOT_FOUND;
}
['int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size)\n{\n    int i;\n    uint32_t state;\n    ParseContext *pc = &(h->s.parse_context);\n    state= pc->state;\n    if(state>13)\n        state= 7;\n    for(i=0; i<buf_size; i++){\n        if(state==7){\n            for(; i<buf_size; i++){\n                if(!buf[i]){\n                    state=2;\n                    break;\n                }\n            }\n        }else if(state<=2){\n            if(buf[i]==1)   state^= 5;\n            else if(buf[i]) state = 7;\n            else            state>>=1;\n        }else if(state<=5){\n            int v= buf[i] & 0x1F;\n            if(v==7 || v==8 || v==9){\n                if(pc->frame_start_found){\n                    i++;\nfound:\n                    pc->state=7;\n                    pc->frame_start_found= 0;\n                    return i-(state&5);\n                }\n            }else if(v==1 || v==2 || v==5){\n                if(pc->frame_start_found){\n                    state+=8;\n                    continue;\n                }else\n                    pc->frame_start_found = 1;\n            }\n            state= 7;\n        }else{\n            if(buf[i] & 0x80)\n                goto found;\n            state= 7;\n        }\n    }\n    pc->state= state;\n    return END_NOT_FOUND;\n}']