From 4a3dcde8109c9d789748fe1273593a74319c01c3 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 8 Nov 2022 21:30:46 +0100 Subject: [PATCH] fix(sensors/camera): fixed camera sensor priority. Signed-off-by: Federico Di Pierro --- TODO.md | 3 +++ src/main.c | 2 +- src/modules/sensors/camera.c | 21 +++------------------ 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/TODO.md b/TODO.md index bd79aac..fc110e5 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,9 @@ ## 5.x - [ ] Keep it up to date with possible ddcutil api changes +### Camera +- [x] Fix capture -> avoid setting priority to a low value + ### Pipewire - [ ] Fix set_camera_setting() impl -> how to get current value? how to set a new value? diff --git a/src/main.c b/src/main.c index 862de94..baa2f6b 100644 --- a/src/main.c +++ b/src/main.c @@ -39,7 +39,7 @@ static void check_opts(int argc, char *argv[]) { printf("Clightd: dbus API to easily set screen backlight, gamma temperature and get ambient brightness through webcam frames capture or ALS devices.\n"); printf("* Current version: %s\n", VERSION); printf("* https://github.com/FedeDP/Clightd\n"); - printf("* Copyright (C) 2021 Federico Di Pierro \n"); + printf("* Copyright (C) 2022 Federico Di Pierro \n"); exit(EXIT_SUCCESS); } else { fprintf(stderr, "Unrecognized option: %s.\n", argv[i]); diff --git a/src/modules/sensors/camera.c b/src/modules/sensors/camera.c index 2a64384..de90cbc 100644 --- a/src/modules/sensors/camera.c +++ b/src/modules/sensors/camera.c @@ -162,23 +162,14 @@ static struct v4l2_control *set_camera_setting(void *priv, uint32_t id, float va return NULL; } -static void inline fill_crop_rect(crop_info_t *cr, struct v4l2_rect *rect) { - const double height_pct = cr[Y_AXIS].area_pct[1] - cr[Y_AXIS].area_pct[0]; - rect->height = height_pct * state.height; - rect->top = cr[Y_AXIS].area_pct[0] * state.height; - - const double width_pct = cr[X_AXIS].area_pct[1] - cr[X_AXIS].area_pct[0]; - rect->width = width_pct * state.width; - rect->left = cr[X_AXIS].area_pct[0] * state.width; -} - static int set_camera_fmt(void) { struct v4l2_format fmt = {0}; fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = 160; fmt.fmt.pix.height = 120; - fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; + fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; fmt.fmt.pix.pixelformat = state.pixelformat; + if (-1 == xioctl(VIDIOC_S_FMT, &fmt)) { perror("Setting Pixel Format"); return -1; @@ -210,12 +201,6 @@ static int check_camera_caps(void) { return -1; } - /* Try to set lowest device priority level. No need to quit if this is not supported. */ - enum v4l2_priority priority = V4L2_PRIORITY_BACKGROUND; - if (-1 == xioctl(VIDIOC_S_PRIORITY, &priority)) { - INFO("Failed to set priority\n"); - } - /* Check supported formats */ struct v4l2_fmtdesc fmtdesc = {0}; fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -227,7 +212,7 @@ static int check_camera_caps(void) { } fmtdesc.index++; } - + /* No supported formats found? */ if (state.pixelformat == 0) { perror("Device does not support neither GREY nor YUYV nor MJPEG pixelformats.");