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

📄 ptp.c

📁 Media transfer protocol implementation on POSIX. Have detailed readme on how to move to windows
💻 C
📖 第 1 页 / 共 5 页
字号:
 * Switches the camera display to on and lets the user * select what to transfer. Sends a 0xc011 event when started  * and 0xc013 if direct transfer aborted. * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_initiate_direct_transfer (PTPParams* params, uint32_t *out){	PTPContainer ptp;	uint16_t ret;	PTP_CNT_INIT(ptp);	ptp.Code   = PTP_OC_CANON_InitiateDirectTransferEx2;	ptp.Nparam = 1;	ptp.Param1 = 0xf;	ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);	if ((ret == PTP_RC_OK) && (ptp.Nparam>0))		*out = ptp.Param1;	return ret;}/** * ptp_canon_get_target_handles: * params:	PTPParams* *              PTPCanon_directtransfer_entry **out *              unsigned int *outsize *  * Retrieves direct transfer entries specifying the images to transfer * from the camera (to be retrieved after 0xc011 event). * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_get_target_handles (PTPParams* params,	PTPCanon_directtransfer_entry **entries, unsigned int *cnt){	PTPContainer ptp;	uint16_t ret;	unsigned char *out = NULL, *cur;	int i;	unsigned int size;		PTP_CNT_INIT(ptp);	ptp.Code   = PTP_OC_CANON_GetTargetHandles;	ptp.Nparam = 0;	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &out, &size);	if (ret != PTP_RC_OK)		return ret;	*cnt = dtoh32a(out);	*entries = malloc(sizeof(PTPCanon_directtransfer_entry)*(*cnt));	cur = out+4;	for (i=0;i<*cnt;i++) {		unsigned char len;		(*entries)[i].oid = dtoh32a(cur);		(*entries)[i].str = ptp_unpack_string(params, cur, 4, &len);		cur += 4+(cur[4]*2+1);	}	free (out);	return PTP_RC_OK;}/** * ptp_canon_endshootingmode: * params:	PTPParams* *  * This operation is observed after pressing the Disconnect  * button on the Remote Capture app. It emits a StorageInfoChanged  * event via the interrupt pipe and pushes the StorageInfoChanged * and CANON_CameraModeChange events onto the event stack * (see operation PTP_OC_CANON_CheckEvent). * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_endshootingmode (PTPParams* params){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_EndShootingMode;	ptp.Nparam=0;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_viewfinderon: * params:	PTPParams* *  * Prior to start reading viewfinder images, one  must call this operation. * Supposedly, this operation affects the value of the CANON_ViewfinderMode * property. * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_viewfinderon (PTPParams* params){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_ViewfinderOn;	ptp.Nparam=0;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_viewfinderoff: * params:	PTPParams* *  * Before changing the shooting mode, or when one doesn't need to read * viewfinder images any more, one must call this operation. * Supposedly, this operation affects the value of the CANON_ViewfinderMode * property. * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_viewfinderoff (PTPParams* params){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_ViewfinderOff;	ptp.Nparam=0;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_aeafawb: * params:	PTPParams* * 		uint32_t p1 	- Yet unknown parameter, * 				  value 7 works *  * Called AeAfAwb (auto exposure, focus, white balance) * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_aeafawb (PTPParams* params, uint32_t p1){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_DoAeAfAwb;	ptp.Param1=p1;	ptp.Nparam=1;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_checkevent: * params:	PTPParams* *  * The camera has a FIFO stack, in which it accumulates events. * Partially these events are communicated also via the USB interrupt pipe * according to the PTP USB specification, partially not. * This operation returns from the device a block of data, empty, * if the event stack is empty, or filled with an event's data otherwise. * The event is removed from the stack in the latter case. * The Remote Capture app sends this command to the camera all the time * of connection, filling with it the gaps between other operations.  * * Return values: Some PTP_RC_* code. * Upon success : PTPUSBEventContainer* event	- is filled with the event data *						  if any *                int *isevent			- returns 1 in case of event *						  or 0 otherwise **/uint16_tptp_canon_checkevent (PTPParams* params, PTPUSBEventContainer* event, int* isevent){	uint16_t ret;	PTPContainer ptp;	unsigned char *evdata = NULL;	unsigned int len;		*isevent=0;	PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_CheckEvent;	ptp.Nparam=0;	len=0;	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &evdata, &len);	if (evdata!=NULL) {		if (ret == PTP_RC_OK) {        		ptp_unpack_EC(params, evdata, event, len);    			*isevent=1;        	}		free(evdata);	}	return ret;}/** * ptp_canon_focuslock: * * This operation locks the focus. It is followed by the CANON_GetChanges(?) * operation in the log.  * It affects the CANON_MacroMode property.  * * params:	PTPParams* * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_focuslock (PTPParams* params){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_FocusLock;	ptp.Nparam=0;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_focusunlock: * * This operation unlocks the focus. It is followed by the CANON_GetChanges(?) * operation in the log.  * It sets the CANON_MacroMode property value to 1 (where it occurs in the log). *  * params:	PTPParams* * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_focusunlock (PTPParams* params){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_FocusUnlock;	ptp.Nparam=0;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_initiatecaptureinmemory: *  * This operation starts the image capture according to the current camera * settings. When the capture has happened, the camera emits a CaptureComplete * event via the interrupt pipe and pushes the CANON_RequestObjectTransfer, * CANON_DeviceInfoChanged and CaptureComplete events onto the event stack * (see operation CANON_CheckEvent). From the CANON_RequestObjectTransfer * event's parameter one can learn the just captured image's ObjectHandle. * The image is stored in the camera's own RAM. * On the next capture the image will be overwritten! * * params:	PTPParams* * * Return values: Some PTP_RC_* code. * **/uint16_tptp_canon_initiatecaptureinmemory (PTPParams* params){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_InitiateCaptureInMemory;	ptp.Nparam=0;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}uint16_tptp_canon_9012 (PTPParams* params){	PTPContainer ptp;		PTP_CNT_INIT(ptp);	ptp.Code=0x9012;	ptp.Nparam=0;	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);}/** * ptp_canon_getpartialobject: * * This operation is used to read from the device a data  * block of an object from a specified offset. * * params:	PTPParams* *      uint32_t handle - the handle of the requested object *      uint32_t offset - the offset in bytes from the beginning of the object *      uint32_t size - the requested size of data block to read *      uint32_t pos - 1 for the first block, 2 - for a block in the middle, *                  3 - for the last block * * Return values: Some PTP_RC_* code. *      char **block - the pointer to the block of data read *      uint32_t* readnum - the number of bytes read * **/uint16_tptp_canon_getpartialobject (PTPParams* params, uint32_t handle, 				uint32_t offset, uint32_t size,				uint32_t pos, unsigned char** block, 				uint32_t* readnum){	uint16_t ret;	PTPContainer ptp;	unsigned char *data=NULL;	unsigned int len;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_GetPartialObjectEx;	ptp.Param1=handle;	ptp.Param2=offset;	ptp.Param3=size;	ptp.Param4=pos;	ptp.Nparam=4;	len=0;	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);	if (ret==PTP_RC_OK) {		*block=data;		*readnum=ptp.Param1;	}	return ret;}/** * ptp_canon_getviewfinderimage: * * This operation can be used to read the image which is currently * in the camera's viewfinder. The image size is 320x240, format is JPEG. * Of course, prior to calling this operation, one must turn the viewfinder * on with the CANON_ViewfinderOn command. * Invoking this operation many times, one can get live video from the camera! *  * params:	PTPParams* *  * Return values: Some PTP_RC_* code. *      char **image - the pointer to the read image *      unit32_t *size - the size of the image in bytes * **/uint16_tptp_canon_getviewfinderimage (PTPParams* params, unsigned char** image, uint32_t* size){	uint16_t ret;	PTPContainer ptp;	unsigned int len;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_GetViewfinderImage;	ptp.Nparam=0;	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, image, &len);	if (ret==PTP_RC_OK) *size=ptp.Param1;	return ret;}/** * ptp_canon_getchanges: * * This is an interesting operation, about the effect of which I am not sure. * This command is called every time when a device property has been changed  * with the SetDevicePropValue operation, and after some other operations. * This operation reads the array of Device Properties which have been changed * by the previous operation. * Probably, this operation is even required to make those changes work. * * params:	PTPParams* *  * Return values: Some PTP_RC_* code. *      uint16_t** props - the pointer to the array of changed properties *      uint32_t* propnum - the number of elements in the *props array * **/uint16_tptp_canon_getchanges (PTPParams* params, uint16_t** props, uint32_t* propnum){	uint16_t ret;	PTPContainer ptp;	unsigned char* data=NULL;	unsigned int len;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_GetChanges;	ptp.Nparam=0;	len=0;	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);	if (ret == PTP_RC_OK)        	*propnum=ptp_unpack_uint16_t_array(params,data,0,props);	free(data);	return ret;}/** * ptp_canon_getobjectinfo: * * This command reads a specified object's record in a device's filesystem, * or the records of all objects belonging to a specified folder (association). *   * params:	PTPParams* *      uint32_t store - StorageID, *      uint32_t p2 - Yet unknown (0 value works OK) *      uint32_t parent - Parent Object Handle *                      # If Parent Object Handle is 0xffffffff,  *                      # the Parent Object is the top level folder. *      uint32_t handle - Object Handle *                      # If Object Handle is 0, the records of all objects  *                      # belonging to the Parent Object are read. *                      # If Object Handle is not 0, only the record of this  *                      # Object is read. * * Return values: Some PTP_RC_* code. *      PTPCANONFolderEntry** entries - the pointer to the folder entry array *      uint32_t* entnum - the number of elements of the array * **/uint16_tptp_canon_getobjectinfo (PTPParams* params, uint32_t store, uint32_t p2, 			    uint32_t parent, uint32_t handle, 			    PTPCANONFolderEntry** entries, uint32_t* entnum){	uint16_t ret;	PTPContainer ptp;	unsigned char *data = NULL;	unsigned int len;		PTP_CNT_INIT(ptp);	ptp.Code=PTP_OC_CANON_GetObjectInfoEx;	ptp.Param1=store;	ptp.Param2=p2;	ptp.Param3=parent;	ptp.Param4=handle;	ptp.Nparam=4;	len=0;	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);	if (ret == PTP_RC_OK) {		int i;		*entnum=ptp.Param1;		*entries=calloc(*entnum, sizeof(PTPCANONFolderEntry));		if (*entries!=NULL) {			for(i=0; i<(*entnum); i++)				ptp_unpack_Canon_FE(params,					data+i*PTP_CANON_FolderEntryLen,					&((*entries)[i]) );		} else {			ret=PTP_ERROR_IO; /* Cannot allocate memory */		}	}	free(data);	return ret;}/** * ptp_canon_get_objecthandle_by_name: * * This command looks up the specified object on the camera. * * Format is "A:\\PATH". * * The 'A' is the VolumeLabel from GetStorageInfo, * my IXUS has "A" for the card and "V" for internal memory. *   * params:	PTPParams* *      char* name - path name * * Return values: Some PTP_RC_* code. *      uint32_t *oid - PTP object id. * **/uint16_tptp_canon_get_objecthandle_by_name (PTPParams* params, char* name, uint32_t* objectid){	uint16_t ret;	PTPContainer ptp;	unsigned char *data = NULL;	uint8_t len;	PTP_CNT_INIT (ptp);	ptp.Code=PTP_OC_CANON_GetObjectHandleByName;	ptp.Nparam=0;	len=0;	data = malloc (2*(strlen(name)+1)+2);	memset (data, 0, 2*(strlen(name)+1)+2);	ptp_pack_string (params, name, data, 0, &len);	ret=ptp_transaction (params, &ptp, PTP_DP_SENDDATA, (len+1)*2+1, &data, NULL);	free (data);	*objectid = ptp.Param1;	return ret;}/** * ptp_canon_get_customize_data: * * This command downloads the specified theme slot, including jpegs * and wav files. *   * params:	PTPParams* *      uint32_t themenr - nr of theme * * Return values: Some PTP_RC_* code. *      unsigned char **data - pointer to data pointer *      unsigned int  *size - size of data returned * **/uint16_tptp_canon_get_customize_data (PTPParams* params, uint32_t themenr,		unsigned char **data, unsigned int *size){	PTPContainer ptp;	*data = NULL;

⌨️ 快捷键说明

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