⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dc1394_control.c

📁 较新版本的libdc1394
💻 C
📖 第 1 页 / 共 5 页
字号:
        case MODE_1280x960_YUV422:            return 614400;  //1280x960/2        case MODE_1280x960_RGB:            return 921600;  //1280x960x3/4        case MODE_1280x960_MONO:            return 307200;  //1280x960/4        case MODE_1600x1200_YUV422:            return 960000;  //1600x1200/2        case MODE_1600x1200_RGB:            return 1440000; //1600x1200x3/4        case MODE_1600x1200_MONO:            return 480000;  //1600x1200/4        case MODE_1280x960_MONO16:            return 614400;  //1280x960/2        case MODE_1600x1200_MONO16:            return 960000;  //1600x1200/2        default:            printf("(%s) Improper mode specified: %d\n", __FILE__, mode);            break;        }        break;    case FORMAT_STILL_IMAGE:        printf("(%s) Don't know how many quadlets per frame for "               "FORMAT_STILL_IMAGE mode:%d\n", __FILE__, mode);        break;    case FORMAT_SCALABLE_IMAGE_SIZE:        printf("(%s) Don't know how many quadlets per frame for "               "FORMAT_SCALABLE_IMAGE mode:%d\n", __FILE__, mode);        break;    default:        printf("(%s) Improper format specified: %d\n", __FILE__, format);        break;    }    return -1;}static intGetCameraROMValue(raw1394handle_t handle, nodeid_t node,                  octlet_t offset, quadlet_t *value) {    int retval, retry= MAX_RETRIES;    /* retry a few times if necessary (addition by PDJ) */    while(retry--)     {        retval= raw1394_read(handle, 0xffc0 | node, CONFIG_ROM_BASE + offset,                             4, value);#ifdef LIBRAW1394_OLD        if (retval >= 0)        {            int ack= retval >> 16;            int rcode= retval & 0xffff;#ifdef SHOW_ERRORS            printf("ROM read ack of %x rcode of %x\n", ack, rcode);#endif            if ( ((ack == ACK_PENDING) || (ack == ACK_LOCAL)) &&                 (rcode == RESP_COMPLETE) )            {                 /* conditionally byte swap the value */                *value= ntohl(*value);                 return 0;            }        }#else        if (!retval)        {            /* conditionally byte swap the value */            *value= ntohl(*value);            return retval;        }        else if (errno != EAGAIN)        {            return retval;        }#endif /* LIBRAW1394_VERSION <= 0.8.2 */        usleep(SLOW_DOWN);    }        *value= ntohl(*value);    return retval;}intGetCameraControlRegister(raw1394handle_t handle, nodeid_t node,                         octlet_t offset, quadlet_t *value){    int retval, retry= MAX_RETRIES;    dc1394_camerahandle *camera;    camera = (dc1394_camerahandle*) raw1394_get_userdata( handle );    /* get the ccr_base address if not yet retrieved */    if (camera != NULL && camera->ccr_base == 0)    {        dc1394_camerainfo info;        if ( dc1394_get_camera_info(handle, node, &info) != DC1394_SUCCESS )            return -1;    }    else if (camera == NULL)        return -1;    /* retry a few times if necessary (addition by PDJ) */    while(retry--)     {        retval= raw1394_read(handle, 0xffc0 | node, camera->ccr_base + offset,                             4, value);#ifdef LIBRAW1394_OLD        if (retval >= 0)        {            int ack= retval >> 16;            int rcode= retval & 0xffff;#ifdef SHOW_ERRORS            printf("CCR read ack of %x rcode of %x\n", ack, rcode);#endif            if ( ((ack == ACK_PENDING) || (ack == ACK_LOCAL)) &&                 (rcode == RESP_COMPLETE) )            {                 /* conditionally byte swap the value */                *value= ntohl(*value);                 return 0;            }        }#else        if (!retval)        {            /* conditionally byte swap the value (addition by PDJ) */            *value= ntohl(*value);              return retval;         }        else if (errno != EAGAIN)        {            return retval;        }#endif /* LIBRAW1394_VERSION <= 0.8.2 */        usleep(SLOW_DOWN);    }        *value= ntohl(*value);    return retval;}intSetCameraControlRegister(raw1394handle_t handle, nodeid_t node,                         octlet_t offset, quadlet_t value){    int retval, retry= MAX_RETRIES;    dc1394_camerahandle *camera;    camera = (dc1394_camerahandle*) raw1394_get_userdata( handle );    /* get the ccr_base address if not yet retrieved */    if (camera != NULL && camera->ccr_base == 0)    {        dc1394_camerainfo info;        if ( dc1394_get_camera_info(handle, node, &info) != DC1394_SUCCESS )            return -1;    }    else if (camera == NULL)        return -1;    /* conditionally byte swap the value (addition by PDJ) */    value= htonl(value);    /* retry a few times if necessary */    while(retry--)    {        retval= raw1394_write(handle, 0xffc0 | node, camera->ccr_base + offset, 4,                              &value);#ifdef LIBRAW1394_OLD        if (retval >= 0)        {            int ack= retval >> 16;            int rcode= retval & 0xffff;#ifdef SHOW_ERRORS            printf("CCR write ack of %x rcode of %x\n", ack, rcode);#endif            if ( ((ack == ACK_PENDING) || (ack == ACK_LOCAL) ||                  (ack == ACK_COMPLETE)) &&                 ((rcode == RESP_COMPLETE) || (rcode == RESP_SONY_HACK)) )             {                return 0;            }                                }#else        if (!retval || (errno != EAGAIN))        {            return retval;        }#endif /* LIBRAW1394_VERSION <= 0.8.2 */        usleep(SLOW_DOWN);    }    return retval;}static intIsFeatureBitSet(quadlet_t value, unsigned int feature){    if (feature >= FEATURE_ZOOM)    {      if (feature >= FEATURE_CAPTURE_SIZE) {	feature+= 12;      }        feature-= FEATURE_ZOOM;    }    else    {        feature-= FEATURE_MIN;    }    value&=(0x80000000UL >> feature);    if (value>0)      return DC1394_TRUE;    else      return DC1394_FALSE;}static int SetFeatureValue(raw1394handle_t handle, nodeid_t node,                unsigned int feature, unsigned int value){    quadlet_t curval;    octlet_t offset;    int retval;    FEATURE_TO_VALUE_OFFSET(feature, offset);    if (GetCameraControlRegister(handle, node, offset, &curval) < 0)    {        return DC1394_FAILURE;    }    retval= SetCameraControlRegister(handle, node, offset,                                    (curval & 0xFFFFF000UL) |                                     (value & 0xFFFUL));    return (retval ? DC1394_FAILURE : DC1394_SUCCESS);}static intGetFeatureValue(raw1394handle_t handle, nodeid_t node,                unsigned int feature, unsigned int *value){    quadlet_t quadval;    octlet_t offset;    int retval;    FEATURE_TO_VALUE_OFFSET(feature, offset);    if (!(retval= GetCameraControlRegister(handle, node, offset, &quadval)))    {        *value= (unsigned int)(quadval & 0xFFFUL);    }    return (retval ? DC1394_FAILURE : DC1394_SUCCESS);}static intGetConfigROMTaggedRegister(raw1394handle_t handle, nodeid_t node,			   unsigned int tag, octlet_t *offset, quadlet_t *value){  unsigned int block_length;  int i;  //fprintf(stderr,"tag\n");  // get the block length  if (GetCameraROMValue(handle,node,*offset,value)<0) {    //fprintf(stderr,"rom probe failed for tag 0x%x\n",tag);    return DC1394_FAILURE;  }    //fprintf(stderr,"tag\n");  block_length=*value>>16;  if (*offset+block_length*4>CSR_CONFIG_ROM_END) {    block_length=(CSR_CONFIG_ROM_END-*offset)/4;  }  // find the tag and return the result  for (i=0;i<block_length;i++) {    *offset+=4;    if (GetCameraROMValue(handle,node,*offset,value)<0) {      //fprintf(stderr,"rom probe failed for tag 0x%x\n",tag);      return DC1394_FAILURE;    }    else {      if ((*value>>24)==tag) {	//fprintf(stderr,"got tag 0x%x\n",tag);	return DC1394_SUCCESS;      }    }  }  //fprintf(stderr,"failed for tag 0x%x\n",tag);  return DC1394_FAILURE;}/**********************//* External functions *//**********************/nodeid_t* dc1394_get_camera_nodes(raw1394handle_t handle, int *numCameras,                        int showCameras) {    nodeid_t * nodes;     dc1394bool_t isCamera;    int numNodes;    int i;      dc1394_camerainfo caminfo;    numNodes= raw1394_get_nodecount(handle);    *numCameras= 0;    /* we know that the computer isn't a camera so there are only       numNodes-1 possible camera nodes */    nodes=(nodeid_t*)calloc(numNodes - 1, sizeof(nodeid_t));    for (i= 0; i < (numNodes - 1); i++)     {        nodes[i]= DC1394_NO_CAMERA;    }    for (i= 0; i < numNodes; i++)     {      dc1394_is_camera(handle, i, &isCamera);        if (isCamera) 	  {            nodes[*numCameras]= i;            (*numCameras)++;            if (showCameras)            {                if (dc1394_get_camera_info(handle, i, &caminfo)                    == DC1394_SUCCESS)                 {                    dc1394_print_camera_info(&caminfo);                }                else                 {                    printf("Couldn't get camera info (%d)!\n", i);                }            }        }        /*	  else         {            printf("node %d is not a camera\n", i);        }	*/    }    return nodes; }/********************************************************************** dc1394_get_camera_nodes This returns the available cameras on the bus. It returns the node id's in the same index as the id specified the ids array contains a list of the low quadlet of the unique camera  ids. Returns -1 in numCameras and NULL from the call if there is a problem,  otherwise the number of cameras and the nodeid_t array from the call***********************************************************************/nodeid_t* dc1394_get_sorted_camera_nodes(raw1394handle_t handle,int numIds,                                int *ids, int *numCameras,                               int showCameras) {    int numNodes, i,j, uid, foundId, extraId;    dc1394bool_t isCamera;    nodeid_t *nodes;    dc1394_camerainfo caminfo;    *numCameras= 0;    numNodes= raw1394_get_nodecount(handle);    /* we know that the computer isn't a camera so there are only       numNodes-1 possible camera nodes */    nodes= (nodeid_t*)calloc(numNodes - 1, sizeof(nodeid_t));    for (i= 0; i < (numNodes - 1); i++)     {      nodes[i]= DC1394_NO_CAMERA;   }    extraId= numIds;    for (i= 0; i < numNodes; i++)     {        dc1394_is_camera(handle, i, &isCamera);        if (isCamera)        {            (*numCameras)++;            dc1394_get_camera_info(handle, i, &caminfo);            if (showCameras) dc1394_print_camera_info(&caminfo);            uid= caminfo.euid_64 & 0xffffffff;            foundId= 0;            for (j= 0; j < numIds; j++)             {                if (ids[j] == uid)                 {                    nodes[j]= i;                    foundId= 1;                    break;                }            }            /* if it isn't then we need to put it in one of the extra               spaces- but check first to make sure we aren't overflowing               our bounds */            if (foundId == 0)             {                if (extraId >= (numNodes-1))                 {                    *numCameras= -1;                    free(nodes);                    return NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -