static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){

    int vop_found, i, j, bits_left, last_bits;

    uint32_t state;



    H261Context *h = avctx->priv_data;



    if(h){

        bits_left = h->bits_left;

        last_bits = h->last_bits;

    }

    else{

        bits_left = 0;

        last_bits = 0;

    }



    vop_found= pc->frame_start_found;

    state= pc->state;

    if(bits_left!=0 && !vop_found)

        state = state << (8-bits_left) | last_bits;

    i=0;

    if(!vop_found){

        for(i=0; i<buf_size; i++){

            state= (state<<8) | buf[i];

            for(j=0; j<8; j++){

                if(( (  (state<<j)  |  (buf[i]>>(8-j))  )>>(32-20) == 0x10 )&&(((state >> (17-j)) & 0x4000) == 0x0)){

                    i++;

                    vop_found=1;

                    break;

                }

            }

            if(vop_found)

                    break;    

        }

    }

    if(vop_found){

        for(; i<buf_size; i++){

            if(avctx->flags & CODEC_FLAG_TRUNCATED)//XXX ffplay workaround, someone a better solution?

                state= (state<<8) | buf[i];

            for(j=0; j<8; j++){

                if(( (  (state<<j)  |  (buf[i]>>(8-j))  )>>(32-20) == 0x10 )&&(((state >> (17-j)) & 0x4000) == 0x0)){

                    pc->frame_start_found=0;

                    pc->state=-1;

                    return i-3;

                }

            }

        }

    }



    pc->frame_start_found= vop_found;

    pc->state= state;

    return END_NOT_FOUND;

}

static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){

    int vop_found, i, j, bits_left, last_bits;

    uint32_t state;



    H261Context *h = avctx->priv_data;



    if(h){

        bits_left = h->bits_left;

        last_bits = h->last_bits;

    }

    else{

        bits_left = 0;

        last_bits = 0;

    }



    vop_found= pc->frame_start_found;

    state= pc->state;

    if(bits_left!=0 && !vop_found)

        state = state << (8-bits_left) | last_bits;

    i=0;

    if(!vop_found){

        for(i=0; i<buf_size; i++){

            state= (state<<8) | buf[i];

            for(j=0; j<8; j++){

                if(( (  (state<<j)  |  (buf[i]>>(8-j))  )>>(32-20) == 0x10 )&&(((state >> (17-j)) & 0x4000) == 0x0)){

                    i++;

                    vop_found=1;

                    break;

                }

            }

            if(vop_found)

                    break;    

        }

    }

    if(vop_found){

        for(; i<buf_size; i++){

            if(avctx->flags & CODEC_FLAG_TRUNCATED)

                state= (state<<8) | buf[i];

            for(j=0; j<8; j++){

                if(( (  (state<<j)  |  (buf[i]>>(8-j))  )>>(32-20) == 0x10 )&&(((state >> (17-j)) & 0x4000) == 0x0)){

                    pc->frame_start_found=0;

                    pc->state=-1;

                    return i-3;

                }

            }

        }

    }



    pc->frame_start_found= vop_found;

    pc->state= state;

    return END_NOT_FOUND;

}

static int FUNC_0(ParseContext *VAR_0, AVCodecContext* VAR_1, const uint8_t *VAR_2, int VAR_3){

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    uint32_t state;



    H261Context *h = VAR_1->priv_data;



    if(h){

        VAR_7 = h->VAR_7;

        VAR_8 = h->VAR_8;

    }

    else{

        VAR_7 = 0;

        VAR_8 = 0;

    }



    VAR_4= VAR_0->frame_start_found;

    state= VAR_0->state;

    if(VAR_7!=0 && !VAR_4)

        state = state << (8-VAR_7) | VAR_8;

    VAR_5=0;

    if(!VAR_4){

        for(VAR_5=0; VAR_5<VAR_3; VAR_5++){

            state= (state<<8) | VAR_2[VAR_5];

            for(VAR_6=0; VAR_6<8; VAR_6++){

                if(( (  (state<<VAR_6)  |  (VAR_2[VAR_5]>>(8-VAR_6))  )>>(32-20) == 0x10 )&&(((state >> (17-VAR_6)) & 0x4000) == 0x0)){

                    VAR_5++;

                    VAR_4=1;

                    break;

                }

            }

            if(VAR_4)

                    break;    

        }

    }

    if(VAR_4){

        for(; VAR_5<VAR_3; VAR_5++){

            if(VAR_1->flags & CODEC_FLAG_TRUNCATED)

                state= (state<<8) | VAR_2[VAR_5];

            for(VAR_6=0; VAR_6<8; VAR_6++){

                if(( (  (state<<VAR_6)  |  (VAR_2[VAR_5]>>(8-VAR_6))  )>>(32-20) == 0x10 )&&(((state >> (17-VAR_6)) & 0x4000) == 0x0)){

                    VAR_0->frame_start_found=0;

                    VAR_0->state=-1;

                    return VAR_5-3;

                }

            }

        }

    }



    VAR_0->frame_start_found= VAR_4;

    VAR_0->state= state;

    return END_NOT_FOUND;

}

static int FUNC_0(ParseContext *VAR_0, AVCodecContext* VAR_1, const uint8_t *VAR_2, int VAR_3){ int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; uint32_t state; H261Context *h = VAR_1->priv_data; if(h){ VAR_7 = h->VAR_7; VAR_8 = h->VAR_8; } else{ VAR_7 = 0; VAR_8 = 0; } VAR_4= VAR_0->frame_start_found; state= VAR_0->state; if(VAR_7!=0 && !VAR_4)
state = state << (8-VAR_7) | VAR_8; VAR_5=0; if(!VAR_4){ for(VAR_5=0; VAR_5<VAR_3; VAR_5++){ state= (state<<8) | VAR_2[VAR_5]; for(VAR_6=0; VAR_6<8; VAR_6++){ if(( (  (state<<VAR_6)  |  (VAR_2[VAR_5]>>(8-VAR_6))  )>>(32-20) == 0x10 )&&(((state >> (17-VAR_6)) & 0x4000) == 0x0)){ VAR_5++; VAR_4=1; break; } } if(VAR_4)
break; } } if(VAR_4){ for(; VAR_5<VAR_3; VAR_5++){ if(VAR_1->flags & CODEC_FLAG_TRUNCATED)
state= (state<<8) | VAR_2[VAR_5]; for(VAR_6=0; VAR_6<8; VAR_6++){ if(( (  (state<<VAR_6)  |  (VAR_2[VAR_5]>>(8-VAR_6))  )>>(32-20) == 0x10 )&&(((state >> (17-VAR_6)) & 0x4000) == 0x0)){ VAR_0->frame_start_found=0; VAR_0->state=-1; return VAR_5-3; } } } } VAR_0->frame_start_found= VAR_4; VAR_0->state= state; return END_NOT_FOUND; }