Skip to content

Commit

Permalink
fix(sensors/camera): fixed camera sensor priority.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 8, 2022
1 parent 95c7188 commit 4a3dcde
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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?

Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>\n");
printf("* Copyright (C) 2022 Federico Di Pierro <[email protected]>\n");
exit(EXIT_SUCCESS);
} else {
fprintf(stderr, "Unrecognized option: %s.\n", argv[i]);
Expand Down
21 changes: 3 additions & 18 deletions src/modules/sensors/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.");
Expand Down

0 comments on commit 4a3dcde

Please sign in to comment.