14#define PTP_TIMEOUT 1000
17#define CAMLIB_WAIT_MS 1000
23 #define CAMLIB_SLEEP(ms) usleep(ms * 1000)
27#define PUB __declspec(dllexport)
33void ptp_verbose_log(
char *fmt, ...);
34__attribute__ ((noreturn))
void ptp_panic(
char *fmt, ...);
37#define CAMLIB_DEFAULT_SIZE 1000000
76 PTP_DEV_PANASONIC = 6,
85 IMG_FORMAT_RAW_JPEG = 4,
92 PTP_IP_USB = (1 << 1),
135 struct PtpDeviceInfo *
di;
171 const char *str_value;
280PUB
int ptp_write_unicode_string(
char *dat,
const char *
string);
281PUB
int ptp_read_unicode_string(
char *buffer,
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) { ((uint8_t *)buf)[0] = out;
return 1; }
289inline static int ptp_write_u16(
void *buf, uint16_t out) { ((uint16_t *)buf)[0] = out;
return 2; }
290inline static int ptp_write_u32(
void *buf, uint32_t out) { ((uint32_t *)buf)[0] = out;
return 4; }
291inline static int ptp_read_u32 (
const void *buf, uint32_t *out) { *out = ((
const uint32_t *)buf)[0];
return 4; }
292inline static int ptp_read_u16 (
const void *buf, uint16_t *out) { *out = ((
const uint16_t *)buf)[0];
return 2; }
293inline static int ptp_read_u8 (
const void *buf, uint8_t *out) { *out = ((
const uint8_t *)buf)[0];
return 1; }
302int ptpip_data_start_packet(
struct PtpRuntime *r,
int data_length);
303int ptpip_data_end_packet(
struct PtpRuntime *r,
void *
data,
int data_length);
306void ptp_update_transaction(
struct PtpRuntime *r,
int t);
309void ptp_set_prop_avail_info(
struct PtpRuntime *r,
int code,
int memb_size,
int cnt,
void *
data);
317#define CAMLIB_INCLUDE_IMPL
319#include "cl_backend.h"
325#ifndef CAMLIB_NO_COMPAT
326 #define ptp_get_last_transaction(...) ptp_get_last_transaction_id(__VA_ARGS__)
327 #define ptp_generic_new(...) ptp_new(__VA_ARGS__)
328 #define ptp_generic_close(...) ptp_close(__VA_ARGS__)
329 #define ptp_generic_reset(...) ptp_reset(__VA_ARGS__)
330 #define ptp_generic_init(...) ptp_init(__VA_ARGS__)
331 #define ptp_generic_send(...) ptp_send(__VA_ARGS__)
332 #define ptp_generic_send_data(...) ptp_send_data(__VA_ARGS__)
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.
PtpConnType
Tells lib what backend and packet style to use.
Definition camlib.h:90
PtpGeneralError
Camlib library errors, not PTP return codes.
Definition camlib.h:40
@ PTP_CHECK_CODE
response code is not PTP_RC_OK
Definition camlib.h:57
@ PTP_NO_DEVICE
No device found (USB)
Definition camlib.h:43
@ PTP_RUNTIME_ERR
Unexpected, unhandled, or illegal behavior.
Definition camlib.h:53
@ PTP_COMMAND_IGNORED
No response.
Definition camlib.h:62
@ PTP_IO_ERR
General IO or communication error.
Definition camlib.h:51
@ PTP_OPEN_FAIL
Found device, but failed to connect.
Definition camlib.h:47
@ PTP_CANCELED
Operation (such as download) was canceled by another thread.
Definition camlib.h:59
@ PTP_NO_PERM
EPERM or other permission denied error.
Definition camlib.h:45
@ PTP_UNSUPPORTED
Operation or functionality isn't implemented or supported.
Definition camlib.h:55
@ PTP_OUT_OF_MEM
malloc failed
Definition camlib.h:49
PtpVendors
Unique camera types - each type should have similar opcodes and behavior.
Definition camlib.h:69
Generic Struct for arrays.
Definition camlib.h:182
Generic PTP command structure - accepted by operation API.
Definition camlib.h:175
Generic event / property change.
Definition camlib.h:167
Linked list to handle currently possible values for a property.
Definition camlib.h:98
Represents a single device connection.
Definition camlib.h:109
PUB int ptp_send(struct PtpRuntime *r, struct PtpCommand *cmd)
Send a command request to the device with no data phase.
PUB 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)
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.
void * userdata
Free pointer to hold per ptp session information.
Definition camlib.h:146
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)
Definition camlib.h:111
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.
uint8_t response_wait_default
Default value for wait_for_response.
Definition camlib.h:156
PUB int ptp_get_event(struct PtpRuntime *r, struct PtpEventContainer *ec)
Try and get an event from the camera over int endpoint (USB-only)
PUB void ptp_close(struct PtpRuntime *r)
Frees PtpRuntime data buffer - doesn't free the actual structure, or device info (yet)
void * comm_backend
For session comm/io structures (holds backend instance pointers)
Definition camlib.h:143
PUB uint8_t * ptp_get_payload(struct PtpRuntime *r)
Get ptr of packet payload in data buffer, after packet header.
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.
uint8_t * data
Global buffer for data reading and writing.
Definition camlib.h:126
struct PtpPropAvail * avail
For devices that implement it, this will hold a linked list of properties and an array of their suppo...
Definition camlib.h:161
int transaction
Definition camlib.h:121
PUB int ptp_get_param_length(struct PtpRuntime *r)
Get number of parameters in packet in data buffer.
int max_packet_size
Definition camlib.h:131
PUB void ptp_mutex_unlock(struct PtpRuntime *r)
Unlock the IO mutex (unless it was kept locked)
pthread_mutex_t * mutex
Optional (see CAMLIB_DONT_USE_MUTEX)
Definition camlib.h:149
PUB int ptp_buffer_resize(struct PtpRuntime *r, size_t size)
Mostly for internal use - realloc the data buffer.
int data_phase_length
For Windows compatibility, this is set to indicate lenth for a data packet that will be sent after a ...
Definition camlib.h:140
PUB int ptp_get_return_code(struct PtpRuntime *r)
Returns the return code (RC) currently in the data buffer.
struct PtpDeviceInfo * di
Info about current connection, used to detect camera type, supported opodes, etc.
Definition camlib.h:135
uint8_t wait_for_response
Optionally wait up to 256 seconds for a response. Some PTP operations require this,...
Definition camlib.h:153
uint8_t operation_kill_switch
Set to 1 when it is no longer safe to run operations (device is unresponsive, pipe issues)
Definition camlib.h:114
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 int ptp_device_type(struct PtpRuntime *r)
Gets type of device from r->di.
uint8_t connection_type
One of enum PtpConnType.
Definition camlib.h:118
PUB int ptp_get_payload_length(struct PtpRuntime *r)
Get length of payload returned by ptp_get_payload.