13#define PTP_TIMEOUT 1000
16#define PTP_WAIT_MS 1000
22 #define PTP_SLEEP(ms) usleep((unsigned int)(ms) * 1000)
26#define PUB __declspec(dllexport)
32#define PTP_DEFAULT_SIZE 1000000
81 PTP_DEV_PANASONIC = 6,
90 IMG_FORMAT_RAW_JPEG = 4,
97 PTP_IP_USB = (1 << 1),
107 unsigned int memb_size;
108 unsigned int memb_cnt;
184 const char *str_value;
188 unsigned int data_of;
189 unsigned int n_entries;
198 unsigned int param_length;
280PUB
int ptp_write_unicode_string(
char *dat,
const char *
string);
281PUB
int ptp_read_unicode_string(
char *buffer,
const char *dat,
int max);
282PUB
int ptp_read_utf8_string(
void *dat,
char *
string,
int max);
283PUB
int ptp_read_string(uint8_t *dat,
char *
string,
int max);
284PUB
int ptp_write_string(uint8_t *dat,
const char *
string);
285PUB
int ptp_write_utf8_string(
void *dat,
const char *
string);
286PUB
int ptp_read_uint16_array(
const uint8_t *dat, uint16_t *buf,
int max,
int *length);
287PUB
int ptp_read_uint16_array_s(uint8_t *bs, uint8_t *be, uint16_t *buf,
int max,
int *length);
288inline static int ptp_write_u8(
void *buf, uint8_t out) {
289 ((uint8_t *)buf)[0] = out;
292inline static int ptp_write_u16(
void *buf, uint16_t out) {
293 uint8_t *b = (uint8_t *)buf;
295 b[1] = (out >> 8) & 0xFF;
298inline static int ptp_write_u32(
void *buf, uint32_t out) {
299 uint8_t *b = (uint8_t *)buf;
301 b[1] = (out >> 8) & 0xFF;
302 b[2] = (out >> 16) & 0xFF;
303 b[3] = (out >> 24) & 0xFF;
306inline static int ptp_read_u8(
const void *buf, uint8_t *out) {
307 const uint8_t *b = (
const uint8_t *)buf;
311inline static int ptp_read_u16(
const void *buf, uint16_t *out) {
312 const uint8_t *b = (
const uint8_t *)buf;
313 *out = (uint16_t)b[0] | ((uint16_t)b[1] << 8);
316inline static int ptp_read_u32(
const void *buf, uint32_t *out) {
317 const uint8_t *b = (
const uint8_t *)buf;
318 *out = (uint32_t)b[0] | ((uint32_t)b[1] << 8) | ((uint32_t)b[2] << 16) | ((uint32_t)b[3] << 24);
321inline static int ptp_read_u64(
const void *buf, uint64_t *out) {
323 ptp_read_u32(buf, &lo);
324 ptp_read_u32((
const uint8_t *)buf + 4, &hi);
325 *out = ((uint64_t)hi << 32) | lo;
341void ptp_update_transaction(
struct PtpRuntime *r,
int t);
344void ptp_set_prop_avail_info(
struct PtpRuntime *r,
int code,
unsigned int memb_size,
unsigned int cnt,
void *
data);
360#ifdef PTP_OLD_FUNC_COMPAT
361 #define ptp_get_last_transaction(...) ptp_get_last_transaction_id(__VA_ARGS__)
362 #define ptp_generic_new(...) ptp_new(__VA_ARGS__)
363 #define ptp_generic_close(...) ptp_close(__VA_ARGS__)
364 #define ptp_generic_reset(...) ptp_reset(__VA_ARGS__)
365 #define ptp_generic_init(...) ptp_init(__VA_ARGS__)
366 #define ptp_generic_send(...) ptp_send(__VA_ARGS__)
367 #define ptp_generic_send_data(...) ptp_send_data(__VA_ARGS__)
PUB int ptp_send(struct PtpRuntime *r, struct PtpCommand *cmd)
Send a command request to the device with no data phase.
PUB int ptp_check_opcode(struct PtpRuntime *r, int opcode)
Check if an opcode is supported by looking through supported props in r->di.
PUB void ptp_init(struct PtpRuntime *r)
Init PtpRuntime locally - uses default recommended settings (USB)
PUB struct PtpRuntime * ptp_new(int options)
Allocate new PtpRuntime based on bitfield options - see PtpConnType.
PUB int ptp_get_last_transaction_id(struct PtpRuntime *r)
Get transaction ID of packet in the data buffer.
PUB void ptp_reset(struct PtpRuntime *r)
Reset all session-specific fields of PtpRuntime - both libusb and libwpd backends call this before es...
PUB void ptp_mutex_lock(struct PtpRuntime *r)
Lock the IO mutex - only should be used by backend.
PUB int ptp_get_event(struct PtpRuntime *r, struct PtpEventContainer *ec)
Try and get an event from the camera over int endpoint (USB-only)
int ptp_dump(struct PtpRuntime *r)
Write r->data to a file called DUMP.
const char * ptp_perror(int rc)
Evaluates PtpGeneralError into string message.
PUB void ptp_close(struct PtpRuntime *r)
Frees PtpRuntime data buffer - doesn't free the actual structure, or device info (yet)
PtpConnType
Tells lib what backend and packet style to use.
PUB int ptp_send_data(struct PtpRuntime *r, const struct PtpCommand *cmd, const void *data, unsigned int length)
Send a command request to the device with a data phase (thread safe)
PUB uint8_t * ptp_get_payload(struct PtpRuntime *r)
Get ptr of packet payload in data buffer, after packet header.
PUB unsigned int ptp_get_payload_length(struct PtpRuntime *r)
Get length of payload returned by ptp_get_payload.
PUB uint32_t ptp_get_param(struct PtpRuntime *r, int i)
Get parameter at index i.
PUB int ptp_check_prop(struct PtpRuntime *r, int code)
Check if a property code is supported by looking through supported props in r->di.
PUB unsigned int ptp_get_param_length(struct PtpRuntime *r)
Get number of parameters in packet in data buffer.
PUB void ptp_verbose_log(char *fmt,...)
Verbose log debugging info, could be called dozens of times per second.
PtpGeneralError
Library errors, not PTP return codes.
@ PTP_CHECK_CODE
response code is not PTP_RC_OK
@ PTP_NO_DEVICE
No device found (USB)
@ PTP_RUNTIME_ERR
Unexpected, unhandled, or illegal behavior.
@ PTP_COMMAND_IGNORED
No response.
@ PTP_IO_ERR
General IO or communication error.
@ PTP_OPEN_FAIL
Found device, but failed to connect.
@ PTP_CANCELED
Operation (such as download) was canceled by another thread.
@ PTP_NO_PERM
EPERM or other permission denied error.
@ PTP_UNSUPPORTED
Operation or functionality isn't implemented or supported.
@ PTP_OUT_OF_MEM
malloc failed
PtpVendors
Unique camera types - each type should have similar opcodes and behavior.
PUB void ptp_mutex_unlock(struct PtpRuntime *r)
Unlock the IO mutex (unless it was kept locked)
PUB int ptp_buffer_resize(struct PtpRuntime *r, size_t size)
Mostly for internal use - realloc the data buffer.
PUB __attribute__((noreturn)) void ptp_panic(char *fmt
Client has no way out, crash the application.
PUB int ptp_get_return_code(struct PtpRuntime *r)
Returns the return code (RC) currently in the data buffer.
PUB void ptp_error_log(char *fmt,...)
Used for critical IO errors, (not runtime errors)
PUB void ptp_mutex_unlock_thread(struct PtpRuntime *r)
Completely unlock the mutex for the current thread, to ensure there isn't a deadlock....
PUB void ptp_report_read_progress(unsigned int size)
Update UI progress on download progress.
PUB int ptp_device_type(struct PtpRuntime *r)
Gets type of device from r->di.
Generic Struct for arrays.
Generic PTP command structure - accepted by operation API.
Stream reader state struct for struct PtpGenericEvent.
Generic event / property change.
Linked list to handle currently possible values for a property.
Represents a single device connection.
void * userdata
Free pointer to hold per ptp session information.
uint8_t io_kill_switch
Set to 1 when it is no longer safe to send any data to the device (socket closed, device unplugged)
FILE * comm_dump
If non-NULL, all reads/writes will be logged to this file.
uint8_t response_wait_default
Default value for wait_for_response.
unsigned int data_filled_length
Size of valid PTP data in data in bytes.
unsigned int max_packet_size
void * comm_backend
For session comm/io structures (holds backend instance pointers)
uint8_t * data
Global buffer for data reading and writing.
struct PtpPropAvail * avail
For devices that implement it, this will hold a linked list of properties and an array of their suppo...
unsigned int data_phase_length
For Windows compatibility, this is set to indicate lenth for a data packet that will be sent after a ...
int transaction
Current transaction ID.
int session
Current session ID.
pthread_mutex_t * mutex
Optional (see PTP_DONT_USE_MUTEX)
unsigned int data_length
Size of data in bytes.
struct PtpDeviceInfo * di
Info about current connection, used to detect camera type, supported opodes, etc.
uint8_t wait_for_response
Optionally wait up to 256 seconds for a response. Some PTP operations require this,...
uint8_t operation_kill_switch
Set to 1 when it is no longer safe to run operations (device is unresponsive, pipe issues)
uint8_t connection_type
One of enum PtpConnType.