📄 dc1394_control.c
字号:
raw1394handle_t dc1394_create_handle(int port) { raw1394handle_t handle; int i; dc1394_camerahandle *camera = malloc(sizeof(dc1394_camerahandle)); memset(camera, 0, sizeof(dc1394_camerahandle));#ifdef LIBRAW1394_OLD if (!(handle= raw1394_get_handle()))#else if (!(handle= raw1394_new_handle()))#endif { printf("(%s) Couldn't get raw1394 handle!\n",__FILE__); return NULL; } if (raw1394_set_port(handle, port) < 0) { if (handle != NULL) raw1394_destroy_handle(handle); printf("(%s) Couldn't raw1394_set_port!\n",__FILE__); return NULL; } camera->port = port; camera->ccr_base=0; camera->sw_version=0; for (i=0;i<NUM_MODE_FORMAT7;i++) { camera->format7_csr[i]=0; } raw1394_set_userdata( handle, (void*) camera ); return handle;}intdc1394_destroy_handle( raw1394handle_t handle ){ dc1394_camerahandle *camera; camera = (dc1394_camerahandle*) raw1394_get_userdata( handle ); if(camera) free(camera); if( handle != NULL ) raw1394_destroy_handle(handle); return DC1394_SUCCESS;}intdc1394_is_camera(raw1394handle_t handle, nodeid_t node, dc1394bool_t *value){ octlet_t offset; octlet_t ud_offset = 0; quadlet_t quadval = 0; dc1394bool_t ptgrey; /* Note on Point Grey (PG) cameras: Although not advertised, PG cameras are 'sometimes' compatible with IIDC specs. The following modifications have been tested with a stereo head, the BumbleBee. More cameras should be compatible, please consider contributing to the lib if your PG camera is not recognized. PG cams have a Unit_Spec_ID of 0xB09D, instead of the 0xA02D of classic IIDC cameras. Also, their software revision differs. I could only get a 1.14 version from my BumbleBee, other versions might exist. Damien */ /* get the unit_directory offset */ offset= ROM_ROOT_DIRECTORY; if (GetConfigROMTaggedRegister(handle, node, 0xD1, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { ud_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* get the unit_spec_ID (should be 0x00A02D for 1394 digital camera) */ offset=ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0x12, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { quadval&=0xFFFFFFUL; } ptgrey=(quadval == 0x00B09DUL); if ( ! ( (quadval == 0x00A02DUL) || ptgrey) ) { *value= DC1394_FALSE; return DC1394_SUCCESS; } quadval = 0; /* get the unit_sw_version (should be 0x000100 - 0x000102 for 1394 digital camera) */ /* DRD> without this check, AV/C cameras show up as well */ offset = ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0x13, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { quadval&=0xFFFFFFUL; } //fprintf(stderr,"0x%x\n",quadval); if ((quadval == 0x000100UL) || (quadval == 0x000101UL) || (quadval == 0x000102UL) || ((quadval == 0x000114UL) && ptgrey) || ((quadval == 0x800002UL) && ptgrey)) { *value= DC1394_TRUE; } else { *value= DC1394_FALSE; } return DC1394_SUCCESS;}intdc1394_get_sw_version(raw1394handle_t handle, nodeid_t node, quadlet_t *value){ dc1394_camerahandle *camera; camera = (dc1394_camerahandle*) raw1394_get_userdata( handle ); if (camera != NULL && camera->sw_version != 0) { *value = camera->sw_version; } else { octlet_t offset; octlet_t ud_offset = 0; quadlet_t quadval = 0; /* get the unit_directory offset */ offset= ROM_ROOT_DIRECTORY; if (GetConfigROMTaggedRegister(handle, node, 0xD1, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { ud_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* get the unit_sw_version */ offset = ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0x13, &offset, &quadval)!=DC1394_SUCCESS) { *value= DC1394_FALSE; return DC1394_FAILURE; } else { *value=quadval&0xFFFFFFUL; camera->sw_version=*value; } } return DC1394_SUCCESS;}voiddc1394_print_camera_info(dc1394_camerainfo *info) { quadlet_t value[2]; value[0]= info->euid_64 & 0xffffffff; value[1]= (info->euid_64 >>32) & 0xffffffff; printf("CAMERA INFO\n===============\n"); printf("Node: %x\n", info->id); printf("CCR_Offset: %Lux\n", info->ccr_offset); //L added by tim evers printf("UID: 0x%08x%08x\n", value[1], value[0]); printf("Vendor: %s\tModel: %s\n\n", info->vendor, info->model); fflush(stdout);}intdc1394_get_camera_info(raw1394handle_t handle, nodeid_t node, dc1394_camerainfo *info){ dc1394bool_t iscamera; int retval, len; octlet_t offset; quadlet_t value[2], quadval; unsigned int count; octlet_t ud_offset, udd_offset; dc1394_camerahandle *camera; camera = (dc1394_camerahandle*) raw1394_get_userdata( handle ); if ( (retval= dc1394_is_camera(handle, node, &iscamera)) != DC1394_SUCCESS ) {#ifdef SHOW_ERRORS printf("Error - this is not a camera (get_camera_info)\n");#endif return DC1394_FAILURE; } else if (iscamera != DC1394_TRUE) { return DC1394_FAILURE; } info->handle= handle; info->id= node; /* now get the EUID-64 */ if (GetCameraROMValue(handle, node, ROM_BUS_INFO_BLOCK+0x0C, &value[0]) < 0) { return DC1394_FAILURE; } if (GetCameraROMValue(handle, node, ROM_BUS_INFO_BLOCK+0x10, &value[1]) < 0) { return DC1394_FAILURE; } info->euid_64= ((u_int64_t)value[0] << 32) | (u_int64_t)value[1]; /* get the unit_directory offset */ offset= ROM_ROOT_DIRECTORY; if (GetConfigROMTaggedRegister(handle, node, 0xD1, &offset, &quadval)!=DC1394_SUCCESS) { return DC1394_FAILURE; } else { ud_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* get the unit_dependent_directory offset */ offset= ud_offset; if (GetConfigROMTaggedRegister(handle, node, 0xD4, &offset, &quadval)!=DC1394_SUCCESS) { return DC1394_FAILURE; } else { udd_offset=(quadval & 0xFFFFFFUL)*4+offset; } /* now get the command_regs_base */ offset= udd_offset; if (GetConfigROMTaggedRegister(handle, node, 0x40, &offset, &quadval)!=DC1394_SUCCESS) { return DC1394_FAILURE; } else { info->ccr_offset= (octlet_t)(quadval & 0xFFFFFFUL)*4; if (camera != NULL) camera->ccr_base = CONFIG_ROM_BASE + info->ccr_offset; } /* get the vendor_name_leaf offset (optional) */ offset= udd_offset; info->vendor[0] = '\0'; if (GetConfigROMTaggedRegister(handle, node, 0x81, &offset, &quadval)==DC1394_SUCCESS) { offset=(quadval & 0xFFFFFFUL)*4+offset; /* read in the length of the vendor name */ if (GetCameraROMValue(handle, node, offset, &value[0]) < 0) { return DC1394_FAILURE; } len= (int)(value[0] >> 16)*4-8; /* Tim Evers corrected length value */ if (len > MAX_CHARS) { len= MAX_CHARS; } offset+= 12; count= 0; /* grab the vendor name */ while (len > 0) { if (GetCameraROMValue(handle, node, offset+count, &value[0]) < 0) { return DC1394_FAILURE; } info->vendor[count++]= (value[0] >> 24); info->vendor[count++]= (value[0] >> 16) & 0xFFUL; info->vendor[count++]= (value[0] >> 8) & 0xFFUL; info->vendor[count++]= value[0] & 0xFFUL; len-= 4; } info->vendor[count]= '\0'; } /* get the model_name_leaf offset (optional) */ offset= udd_offset; info->model[0] = '\0'; if (GetConfigROMTaggedRegister(handle, node, 0x82, &offset, &quadval)==DC1394_SUCCESS) { offset=(quadval & 0xFFFFFFUL)*4+offset; /* read in the length of the model name */ if (GetCameraROMValue(handle, node, offset, &value[0]) < 0) { return DC1394_FAILURE; } len= (int)(value[0] >> 16)*4-8; /* Tim Evers corrected length value */ if (len > MAX_CHARS) { len= MAX_CHARS; } offset+= 12; count= 0; /* grab the model name */ while (len > 0) { if (GetCameraROMValue(handle, node, offset+count, &value[0]) < 0) { return DC1394_FAILURE; } info->model[count++]= (value[0] >> 24); info->model[count++]= (value[0] >> 16) & 0xFFUL; info->model[count++]= (value[0] >> 8) & 0xFFUL; info->model[count++]= value[0] & 0xFFUL; len-= 4; } info->model[count]= '\0'; } return DC1394_SUCCESS;}/***************************************************** dc1394_get_camera_misc_info Collects other camera info registers*****************************************************/intdc1394_get_camera_misc_info(raw1394handle_t handle, nodeid_t node, dc1394_miscinfo *info){ quadlet_t value; if (dc1394_get_iso_channel_and_speed(handle, node, &info->iso_channel, &info->iso_speed)!= DC1394_SUCCESS) return DC1394_FAILURE; if (dc1394_get_video_format(handle, node, &info->format) != DC1394_SUCCESS) return DC1394_FAILURE; if (dc1394_get_video_mode(handle, node, &info->mode) != DC1394_SUCCESS) return DC1394_FAILURE; if (dc1394_get_video_framerate(handle, node, &info->framerate) != DC1394_SUCCESS) return DC1394_FAILURE; if (dc1394_get_iso_status(handle, node, &info->is_iso_on) != DC1394_SUCCESS) return DC1394_FAILURE; if (dc1394_query_basic_functionality(handle,node,&value) != DC1394_SUCCESS) return DC1394_FAILURE; else info->mem_channel_number= (value & 0xF); if (info->mem_channel_number>0) { if (dc1394_get_memory_load_ch(handle, node, &info->load_channel) != DC1394_SUCCESS) return DC1394_FAILURE; if (dc1394_get_memory_save_ch(handle, node, &info->save_channel) != DC1394_SUCCESS) return DC1394_FAILURE; } else { info->load_channel=0; info->save_channel=0; } return DC1394_SUCCESS;} /***************************************************** dc1394_get_camera_feature_set Collects the available features for the camera described by node and stores them in features.*****************************************************/intdc1394_get_camera_feature_set(raw1394handle_t handle, nodeid_t node, dc1394_feature_set *features) { int i, j; for (i= FEATURE_MIN, j= 0; i <= FEATURE_MAX; i++, j++) { features->feature[j].feature_id= i; dc1394_get_camera_feature(handle, node, &features->feature[j]); } return DC1394_SUCCESS;}/***************************************************** dc1394_get_camera_feature Stores the bounds and options associated with the feature described by feature->feature_id*****************************************************/intdc1394_get_camera_feature(raw1394handle_t handle, nodeid_t node, dc1394_feature_info *feature) { octlet_t offset; quadlet_t value; unsigned int orig_fid, updated_fid; orig_fid= feature->feature_id; updated_fid= feature->feature_id; // check presence if (dc1394_is_feature_present(handle, node, feature->feature_id, &(feature->available))!=DC1394_SUCCESS) { return DC1394_FAILURE; } if (feature->available == DC1394_FALSE) { return DC1394_SUCCESS; } // get capabilities if (dc1394_query_feature_characteristics(handle, node, feature->feature_id, &value)!=DC1394_SUCCESS) { return DC1394_FAILURE; } switch (feature->feature_id) { case FEATURE_TRIGGER: feature->one_push= DC1394_FALSE; feature->polarity_capable= (value & 0x02000000UL) ? DC1394_TRUE : DC1394_FALSE; feature->trigger_mode_capable_mask= ((value >> 12) & 0x0f); feature->auto_capable= DC1394_FALSE; feature->manual_capable= DC1394_FALSE; break; default: feature->polarity_capable= 0; feature->trigger_mode= 0; feature->one_push= (value & 0x10000000UL) ? DC1394_TRUE : DC1394_FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -