ptp2: use ARRAY abstraction for PTPParams::canon_props

This commit is contained in:
axxel
2024-10-13 13:32:39 +02:00
committed by Marcus Meissner
parent 6ae9eec4de
commit 12872f0f76
4 changed files with 33 additions and 29 deletions

View File

@@ -1698,12 +1698,20 @@ ptp_pack_EOS_CustomFuncEx (PTPParams* params, unsigned char* data, char* str)
static inline PTPDevicePropDesc*
ptp_find_eos_devicepropdesc(PTPParams *params, uint32_t dpc)
{
for (unsigned j=0; j < params->canon_props_len; j++)
if (params->canon_props[j].DevicePropCode == dpc)
return &params->canon_props[j];
for_each (PTPDevicePropDesc*, pdpd, params->canon_props)
if (pdpd->DevicePropCode == dpc)
return pdpd;
return NULL;
}
/* this helper is required, since array_push_back contains a "return GP_ERROR_NO_MEMEORY" statement */
static int
_swallow_error_push_back_dpd(PTPDevicePropDescs *dpds, PTPDevicePropDesc new)
{
array_push_back(dpds, new);
return 0;
}
static PTPDevicePropDesc*
_lookup_or_allocate_canon_prop(PTPParams *params, uint32_t dpc)
{
@@ -1712,14 +1720,14 @@ _lookup_or_allocate_canon_prop(PTPParams *params, uint32_t dpc)
if (dpd)
return dpd;
unsigned j = params->canon_props_len;
params->canon_props = realloc(params->canon_props, sizeof(params->canon_props[0])*(j+1));
memset (&params->canon_props[j],0,sizeof(params->canon_props[j]));
params->canon_props[j].DevicePropCode = dpc;
params->canon_props[j].GetSet = 1;
params->canon_props[j].FormFlag = PTP_DPFF_None;
params->canon_props_len = j+1;
return &params->canon_props[j];
PTPDevicePropDesc new = {0};
new.DevicePropCode = dpc;
new.GetSet = 1;
if (_swallow_error_push_back_dpd(&params->canon_props, new))
return NULL;
else
return &params->canon_props.val[params->canon_props.len-1];
}
#define PTP_CANON_SET_INFO( ENTRY, MSG, ...) \
@@ -2331,8 +2339,7 @@ static unsigned int olcsizes[0x15][13] = {
* EOS R also 7 bytes
* 7 bytes: 01 01 a0 0c 00 0c 00
*/
uint16_t dpc = PTP_DPC_CANON_EOS_ShutterSpeed;
dpd = _lookup_or_allocate_canon_prop(params, dpc);
dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_ShutterSpeed);
if (olcver >= 0x14) { /* taken from northofyou branch */
dpd->CurrentValue.u16 = curdata[curoff+7];
} else {
@@ -2340,7 +2347,7 @@ static unsigned int olcsizes[0x15][13] = {
}
e[i].type = PTP_EOSEvent_PropertyChanged;
e[i].u.propid = dpc;
e[i].u.propid = dpd->DevicePropCode;
break;
}
case 0x0004: { /* Aperture */
@@ -2351,8 +2358,7 @@ static unsigned int olcsizes[0x15][13] = {
* EOS M6 Mark 2:
* 9 bytes: 01 03 00 58 00 2d 00 30 00
*/
uint16_t dpc = PTP_DPC_CANON_EOS_Aperture;
dpd = _lookup_or_allocate_canon_prop(params, dpc);
dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_Aperture);
if (olcver >= 0x12) {
dpd->CurrentValue.u16 = curdata[curoff+7]; /* RP, R5, etc */
} else {
@@ -2360,19 +2366,18 @@ static unsigned int olcsizes[0x15][13] = {
}
e[i].type = PTP_EOSEvent_PropertyChanged;
e[i].u.propid = dpc;
e[i].u.propid = dpd->DevicePropCode;
break;
}
case 0x0008: { /* ISO */
/* 4 bytes: 01 01 00 78 */
/* EOS M6 Mark2: 01 01 00 6b 68 28 */
/* this seem to be the ISO record */
uint16_t dpc = PTP_DPC_CANON_EOS_ISOSpeed;
dpd = _lookup_or_allocate_canon_prop(params, dpc);
dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_ISOSpeed);
dpd->CurrentValue.u16 = curdata[curoff+3]; /* just use last byte */
e[i].type = PTP_EOSEvent_PropertyChanged;
e[i].u.propid = dpc;
e[i].u.propid = dpd->DevicePropCode;
break;
}
case 0x0040: { /* Exposure Indicator */

View File

@@ -141,8 +141,8 @@ have_eos_prop(PTPParams *params, uint16_t vendor, uint16_t prop) {
/* The special Canon EOS property set gets special treatment. */
if ((params->deviceinfo.VendorExtensionID != PTP_VENDOR_CANON) || (vendor != PTP_VENDOR_CANON))
return 0;
for (i=0;i<params->canon_props_len;i++)
if (params->canon_props[i].DevicePropCode == prop)
for (i=0;i<params->canon_props.len;i++)
if (params->canon_props.val[i].DevicePropCode == prop)
return 1;
return 0;
}

View File

@@ -2087,11 +2087,8 @@ ptp_free_params (PTPParams *params)
free (params->objects);
free_array (&params->storageids);
free (params->events);
for (i=0;i<params->canon_props_len;i++) {
ptp_free_devicepropdesc (&params->canon_props[i]);
}
free (params->canon_props);
free_array_recusive (&params->canon_props, ptp_free_devicepropdesc);
free_array_recusive (&params->eos_events, ptp_free_eos_event);
for (i=0;i<params->dpd_cache_len;i++)

View File

@@ -122,6 +122,7 @@ static inline uint32_t _post_inc(uint32_t* o, int n)
GP_LOG_E ("Out of memory: 'realloc' of %ld bytes failed.", ((ARRAY)->len + (LEN)) * sizeof((ARRAY)->val[0])); \
return GP_ERROR_NO_MEMORY; \
} \
memset((ARRAY)->val + (ARRAY)->len, 0, LEN); \
} while(0)
#define array_push_back(ARRAY, VAL) do { \
@@ -3865,7 +3866,6 @@ typedef void (* PTPDebugFunc) (void *data, const char *format, va_list args)
;
typedef ARRAY_OF(MTPObjectProp) MTPObjectProps;
typedef ARRAY_OF(PTPCanonEOSEvent) PTPCanonEOSEvents;
struct _PTPObject {
uint32_t oid;
@@ -3913,6 +3913,9 @@ typedef struct _PanasonicLiveViewSize PanasonicLiveViewSize;
#define PTP_DP_GETDATA 0x0002 /* receiving data */
#define PTP_DP_DATA_MASK 0x00ff /* data phase mask */
typedef ARRAY_OF(PTPCanonEOSEvent) PTPCanonEOSEvents;
typedef ARRAY_OF(PTPDevicePropDesc) PTPDevicePropDescs;
struct _PTPParams {
/* device flags */
uint32_t device_flags;
@@ -3985,8 +3988,7 @@ struct _PTPParams {
unsigned int dpd_cache_len;
/* PTP: Canon specific flags list */
PTPDevicePropDesc *canon_props;
unsigned int canon_props_len;
PTPDevicePropDescs canon_props;
int canon_viewfinder_on;
int canon_event_mode;