kee

Offline IOU signer with QR as transport
git clone https://holbrook.no/src/kee
Info | Log | Files | Refs | README | LICENSE

commit c05ae36358e2431a116e711a3f70155d08894a52
parent dc057e8038f66bf9f82ba527b7ce81c8f1a87494
Author: lash <dev@holbrook.no>
Date:   Mon, 11 Mar 2024 12:55:19 +0000

Add v4l2 camera device scan and list

Diffstat:
Asrc/camera.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/camera.h | 13+++++++++++++
Msrc/gtk/main.c | 8++++++++
Msrc/gtk/ui.c | 4++++
4 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/src/camera.c b/src/camera.c @@ -0,0 +1,65 @@ +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <linux/videodev2.h> + +#include "err.h" +#include "debug.h" +#include "camera.h" + +//#define KEE_VIDEO_DEVICE_TEMPLATE "/dev/video%d" + + +int kee_camera_scan(struct kee_camera_devices *devices) { + int r; + int fd; + int devnum; + struct kee_camera_devices *p; + struct v4l2_capability video_cap; + char s[1024]; + + p = devices; + memset(p, 0, sizeof(struct kee_camera_devices)); + devnum = 0; + while (1) { + //sprintf(dev.path, KEE_VIDEO_DEVICE_TEMPLATE, devnum); + sprintf(p->path, "/dev/video%d", devnum); + fd = open(p->path, O_RDONLY); + if (fd < 0) { + break; + } + r = ioctl(fd, VIDIOC_QUERYCAP, &video_cap); + if (r == -1) { + debug_log(DEBUG_ERROR, "could not get video cap"); + kee_camera_free(devices); + return -1; + } + if ((video_cap.device_caps & V4L2_CAP_VIDEO_CAPTURE) == 0) { + sprintf(s, "%s is not a capture video device", p->path); + debug_log(DEBUG_DEBUG, s); + devnum++; + continue; + } + strcpy(p->label, (char*)video_cap.card); + p->next = calloc(1, sizeof(struct kee_camera_devices)); + if (p->next == NULL) { + debug_log(DEBUG_ERROR, "could not allocate video cap struct"); + kee_camera_free(devices); + return -1; + } + sprintf(s, "found camera: %s (%s)", p->label, p->path); + debug_log(DEBUG_INFO, s); + p = p->next; + devnum++; + } + return ERR_OK; +} + +void kee_camera_free(struct kee_camera_devices *devices) { + if (devices->next != NULL) { + kee_camera_free(devices->next); + } + free(devices->next); +} diff --git a/src/camera.h b/src/camera.h @@ -0,0 +1,13 @@ +#ifndef _KEE_CAMERA_H +#define _KEE_CAMERA_H + +struct kee_camera_devices { + char label[128]; + char path[128]; + struct kee_camera_devices *next; +}; + +int kee_camera_scan(struct kee_camera_devices *devices); +void kee_camera_free(struct kee_camera_devices *devices); + +#endif // _KEE_CAMERA_H diff --git a/src/gtk/main.c b/src/gtk/main.c @@ -7,6 +7,7 @@ #include "context.h" #include "menu.h" #include "settings.h" +#include "camera.h" static void startup(GtkApplication *app, KeeUicontext *ctx) { @@ -28,6 +29,12 @@ int main(int argc, char **argv) { struct kee_settings settings; struct kee_context ctx; struct ui_container ui; + struct kee_camera_devices camera_devices; + + r = kee_camera_scan(&camera_devices); + if (r) { + return r; + } r = ui_init(&ui); if (r) { @@ -51,5 +58,6 @@ int main(int argc, char **argv) { r = g_application_run (G_APPLICATION (ui.gapp), argc, argv); g_object_unref(ui.gapp); + kee_camera_free(&camera_devices); return r; } diff --git a/src/gtk/ui.c b/src/gtk/ui.c @@ -49,6 +49,10 @@ GtkWidget* ui_build_unlock(struct ui_container *ui) { return GTK_WIDGET(box); } +//static GtkWidget* ui_build_scan_videochooser(struct ui_container *ui) { +// return NULL; +//} + static GtkWidget* ui_build_scan(struct ui_container *ui) { GtkWidget *label;