camlib
Documentation for camlib is still a work-in-progress
Loading...
Searching...
No Matches
PtpRuntime Struct Reference

Holds all camlib instance info. More...

#include <camlib.h>

Public Member Functions

int ptp_get_return_code (struct PtpRuntime *r)
 Returns the return code (RC) currently in the data buffer.
 
int ptp_get_param_length (struct PtpRuntime *r)
 Get number of parameters in packet in data buffer.
 
uint32_t ptp_get_param (struct PtpRuntime *r, int i)
 Get parameter at index i.
 
int ptp_get_last_transaction_id (struct PtpRuntime *r)
 Get transaction ID of packet in the data buffer.
 
uint8_t * ptp_get_payload (struct PtpRuntime *r)
 Get ptr of packet payload in data buffer, after packet header.
 
int ptp_get_payload_length (struct PtpRuntime *r)
 Get length of payload returned by ptp_get_payload.
 
struct PtpRuntimeptp_new (int options)
 Allocate new PtpRuntime based on bitfield options - see PtpConnType.
 
void ptp_reset (struct PtpRuntime *r)
 Reset all session-specific fields of PtpRuntime - both libusb and libwpd backends call this before establishing connection, so calling this is not required.
 
void ptp_init (struct PtpRuntime *r)
 Init PtpRuntime locally - uses default recommended settings (USB)
 
void ptp_close (struct PtpRuntime *r)
 Frees PtpRuntime data buffer - doesn't free the actual structure, or device info (yet)
 
int ptp_send (struct PtpRuntime *r, struct PtpCommand *cmd)
 Send a command request to the device with no data phase.
 
int ptp_send_data (struct PtpRuntime *r, struct PtpCommand *cmd, void *data, int length)
 Send a command request to the device with a data phase (thread safe)
 
int ptp_get_event (struct PtpRuntime *r, struct PtpEventContainer *ec)
 Try and get an event from the camera over int endpoint (USB-only)
 
void ptp_mutex_unlock (struct PtpRuntime *r)
 Unlock the IO mutex (unless it was kept locked)
 
void ptp_mutex_keep_locked (struct PtpRuntime *r)
 Keep the mutex locked one more time for the current thread.
 
void ptp_mutex_lock (struct PtpRuntime *r)
 Lock the IO mutex - only should be used by backend.
 
int ptp_device_type (struct PtpRuntime *r)
 Gets type of device from r->di.
 
int ptp_check_opcode (struct PtpRuntime *r, int opcode)
 Check if an opcode is supported by looking through supported props in r->di.
 
int ptp_check_prop (struct PtpRuntime *r, int code)
 Check if a property code is supported by looking through supported props in r->di.
 
int ptp_buffer_resize (struct PtpRuntime *r, size_t size)
 Mostly for internal use - realloc the data buffer.
 
int ptp_set_generic_property (struct PtpRuntime *r, const char *name, int value)
 Set a generic property - abstraction over SetDeviceProp.
 
int ptp_pre_take_picture (struct PtpRuntime *r)
 Call before taking a picture - this is generally for 'focusing' On some cameras this does nothing.
 
int ptp_take_picture (struct PtpRuntime *r)
 Call after calling ptp_pre_take_picture - this time a picture will be taken.
 
int ptp_open_session (struct PtpRuntime *r)
 Open a new session - required for most commands.
 
int ptp_close_session (struct PtpRuntime *r)
 
int ptp_get_device_info (struct PtpRuntime *r, struct PtpDeviceInfo *di)
 
int ptp_init_capture (struct PtpRuntime *r, int storage_id, int object_format)
 
int ptp_init_open_capture (struct PtpRuntime *r, int storage_id, int object_format)
 
int ptp_terminate_open_capture (struct PtpRuntime *r, int trans)
 
int ptp_get_storage_info (struct PtpRuntime *r, int id, struct PtpStorageInfo *si)
 
int ptp_send_object_info (struct PtpRuntime *r, int storage_id, int handle, struct PtpObjectInfo *oi)
 
int ptp_get_prop_value (struct PtpRuntime *r, int code)
 
int ptp_set_prop_value (struct PtpRuntime *r, int code, int value)
 
int ptp_set_prop_value_data (struct PtpRuntime *r, int code, void *data, int length)
 
int ptp_get_prop_desc (struct PtpRuntime *r, int code, struct PtpPropDesc *pd)
 
int ptp_get_object_handles (struct PtpRuntime *r, int id, int format, int in, struct PtpArray **a)
 Gets a list of object handles in a storage device or folder.
 
int ptp_get_object_info (struct PtpRuntime *r, uint32_t handle, struct PtpObjectInfo *oi)
 
int ptp_move_object (struct PtpRuntime *r, int storage_id, int handle, int folder)
 
int ptp_delete_object (struct PtpRuntime *r, int handle, int format_code)
 
int ptp_get_thumbnail (struct PtpRuntime *r, int handle)
 Raw JPEG data is accessible from ptp_get_payload()
 
int ptp_get_partial_object (struct PtpRuntime *r, uint32_t handle, int offset, int max)
 
int ptp_get_object (struct PtpRuntime *r, int handle)
 Download an object.
 
int ptp_download_object (struct PtpRuntime *r, int handle, FILE *stream, size_t max)
 Download an object from handle, to a local file (uses GetPartialObject)
 
int ptp_get_all_known (struct PtpRuntime *r, struct PtpGenericEvent **s, int *length)
 Recieve a generic list of all properties received in DeviceInfo This is similar to getting all events, but for first startup when you know nothing. Some vendors do this, but this gets all the properties manually.
 
int ptpip_init_events (struct PtpRuntime *r)
 
int ptpip_init_command_request (struct PtpRuntime *r, char *device_name)
 

Public Attributes

uint8_t io_kill_switch
 Set to 1 to kill all IO operations. By default, this is 1. When a valid connection is achieved by libusb, libwpd, and tcp backends, it will be set to 0. On IO error, it will be set to 1.
 
uint8_t connection_type
 One of enum PtpConnType.
 
int transaction
 
int session
 
uint8_t * data
 Global buffer for data reading and writing.
 
int data_length
 
int max_packet_size
 
struct PtpDeviceInfo * di
 Info about current connection, used to detect camera type, supported opodes, etc.
 
int device_type
 
int data_phase_length
 For Windows compatibility, this is set to indicate lenth for a data packet that will be sent after a command packet. Will be set to zero when ptp_send_bulk_packets is called.
 
void * comm_backend
 For session comm/io structures (holds backend instance pointers)
 
void * userdata
 
pthread_mutex_t * mutex
 Optional (see CAMLIB_DONT_USE_MUTEX)
 
uint8_t wait_for_response
 Optionally wait up to 256 seconds for a response. Some PTP operations require this, such as EOS capture.
 
uint8_t response_wait_default
 Default value for wait_for_response.
 
struct PtpPropAvailavail
 For devices that implement it, this will hold a linked list of properties and an array of their supported values. generic_ functions will reject set property calls if an invalid value is written.
 

Detailed Description

Holds all camlib instance info.

Member Function Documentation

◆ ptp_buffer_resize()

int ptp_buffer_resize ( struct PtpRuntime * r,
size_t size )

Mostly for internal use - realloc the data buffer.

Note
r->data will be reassigned, any old references must be updated

◆ ptp_check_opcode()

int ptp_check_opcode ( struct PtpRuntime * r,
int opcode )

Check if an opcode is supported by looking through supported props in r->di.

Returns
1 if yes, 0 if no

◆ ptp_check_prop()

int ptp_check_prop ( struct PtpRuntime * r,
int code )

Check if a property code is supported by looking through supported props in r->di.

Returns
1 if yes, 0 if no

◆ ptp_device_type()

int ptp_device_type ( struct PtpRuntime * r)

Gets type of device from r->di.

Returns
enum PtpDeviceType

◆ ptp_get_all_known()

int ptp_get_all_known ( struct PtpRuntime * r,
struct PtpGenericEvent ** s,
int * length )

Recieve a generic list of all properties received in DeviceInfo This is similar to getting all events, but for first startup when you know nothing. Some vendors do this, but this gets all the properties manually.

Parameters
[out]sOutput structure, caller must free

◆ ptp_get_last_transaction_id()

int ptp_get_last_transaction_id ( struct PtpRuntime * r)

Get transaction ID of packet in the data buffer.

Note
Not thread safe.

◆ ptp_get_param()

uint32_t ptp_get_param ( struct PtpRuntime * r,
int i )

Get parameter at index i.

Note
Not thread safe.

◆ ptp_get_param_length()

int ptp_get_param_length ( struct PtpRuntime * r)

Get number of parameters in packet in data buffer.

Note
Not thread safe.

◆ ptp_get_partial_object()

int ptp_get_partial_object ( struct PtpRuntime * r,
uint32_t handle,
int offset,
int max )
Note
Not thread safe.

◆ ptp_get_payload()

uint8_t * ptp_get_payload ( struct PtpRuntime * r)

Get ptr of packet payload in data buffer, after packet header.

Note
Not thread safe.

◆ ptp_get_payload_length()

int ptp_get_payload_length ( struct PtpRuntime * r)

Get length of payload returned by ptp_get_payload.

Note
Not thread safe.

◆ ptp_get_return_code()

int ptp_get_return_code ( struct PtpRuntime * r)

Returns the return code (RC) currently in the data buffer.

Note
Not thread safe.

◆ ptp_get_thumbnail()

int ptp_get_thumbnail ( struct PtpRuntime * r,
int handle )

Raw JPEG data is accessible from ptp_get_payload()

Note
Not thread safe.

◆ ptp_mutex_keep_locked()

void ptp_mutex_keep_locked ( struct PtpRuntime * r)

Keep the mutex locked one more time for the current thread.

Note
When calling a thread-safe function, this will garuntee the mutex locked, in the case that you want to continue using the buffer. Must be unlocked or will cause deadlock.
camlib uses a recursive mutex.

◆ ptp_pre_take_picture()

int ptp_pre_take_picture ( struct PtpRuntime * r)

Call before taking a picture - this is generally for 'focusing' On some cameras this does nothing.

Note
This is meant for a onMouseDown-like event. ptp_take_picture should be called on onMouseUp

◆ ptp_set_generic_property()

int ptp_set_generic_property ( struct PtpRuntime * r,
const char * name,
int value )

Set a generic property - abstraction over SetDeviceProp.

Note
May reject writes if an invalid property is found (see event code)

◆ ptpip_init_command_request()

int ptpip_init_command_request ( struct PtpRuntime * r,
char * device_name )
Note
PTP/IP only

◆ ptpip_init_events()

int ptpip_init_events ( struct PtpRuntime * r)
Note
PTP/IP only

Member Data Documentation

◆ connection_type

uint8_t PtpRuntime::connection_type

One of enum PtpConnType.

Note
Is set to USB by default

◆ data

uint8_t* PtpRuntime::data

Global buffer for data reading and writing.

Note
This is volatile - it will grow in size (pointer will change) when needed.

◆ di

struct PtpDeviceInfo* PtpRuntime::di

Info about current connection, used to detect camera type, supported opodes, etc.

Note
Set by ptp_parse_device_info.

◆ max_packet_size

int PtpRuntime::max_packet_size
Note
For optimization on libusb, as many bytes as possible should be read at once. Generally this is 512, but certain comm backends can manage more. For TCP, this isn't used.

◆ transaction

int PtpRuntime::transaction
Note
The transaction ID and session ID is managed by the packet generator functions

◆ wait_for_response

uint8_t PtpRuntime::wait_for_response

Optionally wait up to 256 seconds for a response. Some PTP operations require this, such as EOS capture.

Note
Not thread safe. Will be reset after each operation.

The documentation for this struct was generated from the following files: