From 3b31859dd179252b0fc946748181a99f03a6035a Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Wed, 26 Jun 2019 17:57:35 +0200 Subject: preview now works. --- camlibs/lumix/lumix.c | 176 +++++++++++++++++++------------------------------- 1 file changed, 67 insertions(+), 109 deletions(-) diff --git a/camlibs/lumix/lumix.c b/camlibs/lumix/lumix.c index 3f8652e31..ab55aa601 100644 --- a/camlibs/lumix/lumix.c +++ b/camlibs/lumix/lumix.c @@ -25,6 +25,7 @@ #include "config.h" #include +#include #include #include #include @@ -96,6 +97,7 @@ char* cameraShutterSpeed = "B"; // //placeholder to store the value of the shutt int captureDuration = 10; //placeholder to store the value of the bulb shot this should be taken as input. note that my primary goal is in fact to perform bulb captures. but this should be extended for sure to take Shutter Speed capture as set in camera static int NumberPix(Camera *camera); +static char* loadCmd (Camera *camera,char* cmd); typedef struct { char *data; @@ -114,6 +116,8 @@ struct _CameraPrivateLibrary { int numpics; LumixPicture *pics; + + int liveview; }; @@ -136,7 +140,67 @@ camera_config_set (Camera *camera, CameraWidget *window, GPContext *context) static int camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context) { - return GP_OK; + int sock = 0, valread; + struct sockaddr_in serv_addr; + unsigned char buffer[65536]; + GPPortInfo info; + char *xpath; + int i, start, end, tries; + + loadCmd (camera, RECMODE); + + if (!camera->pl->liveview) { + loadCmd(camera,"cam.cgi?mode=startstream&value=49199"); + camera->pl->liveview = 1; + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + GP_LOG_E("\n Socket creation error \n"); + return GP_ERROR; + } + + gp_port_get_info (camera->port, &info); + gp_port_info_get_path (info, &xpath); /* xpath now contains tcp:192.168.1.1 */ + + memset(&serv_addr, 0, sizeof(serv_addr)); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(49199); + serv_addr.sin_addr.s_addr = 0; + + if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { + GP_LOG_E("bind Failed: %d", errno); + return GP_ERROR; + } + } else { + /* this reminds the camera we are still doing it */ + loadCmd(camera,"cam.cgi?mode=getstate"); + } + tries = 3; + while (tries--) { + valread = recv ( sock , buffer, sizeof(buffer), 0); + if (valread == -1) { + GP_LOG_E("recv failed: %d", errno); + return GP_ERROR; + } + + GP_LOG_DATA(buffer,valread,"read from udp port"); + + if (valread == 0) + continue; + + start = end = -1; + for (i = 0; iMicrosoft Winsock control in VB - Winsock1.Protocol = sckUDPProtocol - ' Port, der überwacht werden soll - nPort = 49199 - ' Eigene IP ermitteln - sOwnIP = Winsock1.LocalIP - - ' Port an die IP "binden" -Winsock1.Bind nPort, sOwnIP - -'geht nur im 'recmode' -txtStatus.Text = Inet1.OpenURL("http://" & CameraIP.Text & "/cam.cgi?mode=camcmd&value=recmode") 'Inet1 ->Microsoft Inet control - -txtStatus.Text = Inet1.OpenURL("http://" & CameraIP.Text & "/cam.cgi?mode=startstream&value=49199") - -Timer1.Enabled = True 'damit der Datenfluß nicht abbricht - -txtStatus.Text = Inet1.OpenURL("http://" & CameraIP.Text & "/cam.cgi?mode=setsetting_ &type=liveviewsize&value=vga") - -... - -Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) -Dim sData As String -Dim bArray As Variant - -On Error Resume Next - -'im Stream werden ganze Bilder übertragen 'Header ist 167 Byte, Rest - JPG -'Das JPEG-Bild beginnt also bei Byte 168 (Lumix GX7) - -Winsock1.GetData sData, vbString - -sData = Mid(sData, 168) - -bArray = sData - -ImageBox1.ReadBinary2 bArray 'ImageBox1 ist the csxImage OCX - -End Sub - -Private Sub Timer1_Timer() -Dim dummy As Variant - -If CameraIP.Text > "" Then - -If Not Inet2.StillExecuting Then -dummy = Inet2.OpenURL("http://" & CameraIP.Text & "/cam.cgi?mode=startstream_ &value=49199") -'Inet2 ->Microsoft Inet control -End If - -End If - -End Sub -*/ -struct sockaddr_in address; -int sock = 0, valread; -struct sockaddr_in serv_addr; -char *hello = "Hello from client"; -char buffer[1024] = {0}; -if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) -{ -printf("\n Socket creation error \n"); -return -1; -} - -memset(&serv_addr, '0', sizeof(serv_addr)); - -serv_addr.sin_family = AF_INET; -serv_addr.sin_port = htons(49199); - -// Convert IPv4 and IPv6 addresses from text to binary form -if(inet_pton(AF_INET, CAMERAIP, &serv_addr.sin_addr)<=0) -{ -printf("\nInvalid address/ Address not supported \n"); -return -1; -} - -if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) -{ -printf("\nConnection Failed \n"); -return -1; -} -valread = read( sock , buffer, 1024); -printf("%s\n",buffer ); -return 0; - - -} -return GP_OK; -#endif } -- cgit v1.2.1