summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2020-08-30 19:04:47 +0200
committerMarcus Meissner <marcus@jet.franken.de>2020-08-30 19:04:47 +0200
commit9a396c14cd486a3f134b94b089b273cb05032ca3 (patch)
tree2f9c1415267d94c2dd1d9919d8b5ca75a575954c
parente7d77b2b6f7d8e5b0ec36d7a37441a119b87af1c (diff)
downloadlibgphoto2-9a396c14cd486a3f134b94b089b273cb05032ca3.tar.gz
try jpeg fetching from TCPIP port
-rw-r--r--camlibs/ptp2/fujiptpip.c68
-rw-r--r--camlibs/ptp2/library.c15
-rw-r--r--camlibs/ptp2/ptp.h2
3 files changed, 85 insertions, 0 deletions
diff --git a/camlibs/ptp2/fujiptpip.c b/camlibs/ptp2/fujiptpip.c
index c53ea4f34..e9b2ac0fc 100644
--- a/camlibs/ptp2/fujiptpip.c
+++ b/camlibs/ptp2/fujiptpip.c
@@ -223,6 +223,11 @@ ptp_fujiptpip_evt_read (PTPParams* params, PTPIPHeader *hdr, unsigned char** dat
}
static uint16_t
+ptp_fujiptpip_jpg_read (PTPParams* params, PTPIPHeader *hdr, unsigned char** data) {
+ return ptp_fujiptpip_generic_read (params, params->jpgfd, hdr, data, 0);
+}
+
+static uint16_t
ptp_fujiptpip_check_event (PTPParams* params) {
PTPContainer event;
uint16_t ret;
@@ -704,6 +709,21 @@ ptp_fujiptpip_init_event (PTPParams* params, const char *address)
return GP_ERROR_IO;
} while (1);
GP_LOG_D ("fujiptpip event connected!");
+ tries = 2;
+ saddr.sin_family = AF_INET;
+ saddr.sin_port = htons(eventport+1);
+ do {
+ if (-1 != connect (params->jpgfd, (struct sockaddr*)&saddr, sizeof(struct sockaddr_in)))
+ break;
+ if ((errno == ECONNREFUSED) && (tries--)) {
+ GP_LOG_D ("jpeg connect failed, retrying after short wait");
+ usleep(100*1000);
+ continue;
+ }
+ GP_LOG_E ("could not connect event");
+ close (params->jpgfd);
+ return GP_ERROR_IO;
+ } while (1);
return GP_OK;
#else
GP_LOG_E ("Windows currently not supported, neeeds a winsock port.");
@@ -797,6 +817,47 @@ ptp_fujiptpip_event_wait (PTPParams* params, PTPContainer* event) {
return ptp_fujiptpip_event (params, event, PTP_EVENT_CHECK);
}
+uint16_t
+ptp_fujiptpip_jpeg (PTPParams* params, unsigned char** xdata, unsigned int xsize)
+{
+#ifndef WIN32
+ fd_set infds;
+ struct timeval timeout;
+ int ret;
+ unsigned char* data = NULL;
+ PTPIPHeader hdr;
+
+ while (1) {
+ FD_ZERO(&infds);
+ FD_SET(params->jpgfd, &infds);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 1;
+
+ ret = select (params->jpgfd+1, &infds, NULL, NULL, &timeout);
+ if (1 != ret) {
+ if (-1 == ret) {
+ GP_LOG_D ("select returned error, errno is %d", errno);
+ return PTP_ERROR_IO;
+ }
+ return PTP_ERROR_TIMEOUT;
+ }
+
+ ret = ptp_fujiptpip_jpg_read (params, &hdr, &data);
+ if (ret != PTP_RC_OK)
+ return ret;
+ GP_LOG_D ("length %d", hdr.length);
+ break;
+ }
+
+ free (data);
+ return PTP_RC_OK;
+#else
+ GP_LOG_E ("not supported currently on Windows");
+ return PTP_RC_OK;
+#endif
+}
+
+
int
ptp_fujiptpip_connect (PTPParams* params, const char *address) {
char *addr, *s, *p;
@@ -858,6 +919,13 @@ ptp_fujiptpip_connect (PTPParams* params, const char *address) {
close (params->cmdfd);
return GP_ERROR_BAD_PARAMETERS;
}
+ params->jpgfd = socket (PF_INET, SOCK_STREAM, 0);
+ if (params->jpgfd == -1) {
+ perror ("socket jpg");
+ close (params->evtfd);
+ close (params->cmdfd);
+ return GP_ERROR_BAD_PARAMETERS;
+ }
if (-1 == connect (params->cmdfd, (struct sockaddr*)&saddr, sizeof(struct sockaddr_in))) {
perror ("connect cmd");
close (params->cmdfd);
diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c
index 760140cc5..ea0cc6b13 100644
--- a/camlibs/ptp2/library.c
+++ b/camlibs/ptp2/library.c
@@ -3478,6 +3478,21 @@ enable_liveview:
unsigned char *ximage = NULL;
int tries = 10;
+ if (params->jpgfd) {
+ unsigned int size;
+
+ C_PTP (ptp_fujiptpip_jpeg (params, &ximage, &size));
+ gp_file_append (file, (char*)ximage, size);
+ free (ximage);
+
+ gp_file_set_mime_type (file, GP_MIME_JPEG);
+ gp_file_set_name (file, "fuji_preview.jpg");
+ gp_file_set_mtime (file, time(NULL));
+
+ SET_CONTEXT_P(params, NULL);
+ return GP_OK;
+ }
+
while (tries--) {
ret = ptp_getobjectinfo (params, preview_object, &oi);
if (ret == PTP_RC_OK) break;
diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h
index ff641d1f9..85432c9dc 100644
--- a/camlibs/ptp2/ptp.h
+++ b/camlibs/ptp2/ptp.h
@@ -3528,6 +3528,8 @@ uint16_t ptp_fujiptpip_event_wait (PTPParams* params, PTPContainer* event);
uint16_t ptp_fujiptpip_event_check (PTPParams* params, PTPContainer* event);
uint16_t ptp_fujiptpip_event_check_queue(PTPParams* params, PTPContainer* event);
+uint16_t ptp_fujiptpip_jpeg (PTPParams* params, unsigned char** xdata, unsigned int xsize);
+
uint16_t ptp_getdeviceinfo (PTPParams* params, PTPDeviceInfo* deviceinfo);
uint16_t ptp_generic_no_data (PTPParams* params, uint16_t opcode, unsigned int cnt, ...);