/* finds the end of the current frame in the bitstream.  */
static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
/* finds the end of the current frame in the bitstream.  */
static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
{
        for(i=0; i<buf_size; i++){
            state= (state<<8) | buf[i];
            if(state == 0xFFD8){
                i++;
                vop_found=1;
                break;
            }
        }
    }
    if(vop_found){
        if (buf_size == 0)
            return 0;
        for(; i<buf_size; i++){
            state= (state<<8) | buf[i];
            if(state == 0xFFD8){
                pc->frame_start_found=0;
                pc->state=0;
                return i-1;
            }
        }
    }
    pc->frame_start_found= vop_found;
    pc->state= state;
    return END_NOT_FOUND;
}