Support setting the framerate

This commit is contained in:
Martijn Braam
2020-09-14 17:07:37 +02:00
parent f7299add53
commit 5c0611c64f
2 changed files with 27 additions and 6 deletions

27
main.c
View File

@@ -36,6 +36,7 @@ static unsigned int rear_entity_id;
static char rear_dev[260];
static int rear_width = -1;
static int rear_height = -1;
static int rear_rate = 30;
static int rear_rotate = 0;
static int rear_fmt = V4L2_PIX_FMT_RGB24;
static int rear_mbus = MEDIA_BUS_FMT_RGB888_1X24;
@@ -46,6 +47,7 @@ static unsigned int front_entity_id;
static char front_dev[260];
static int front_width = -1;
static int front_height = -1;
static int front_rate = 30;
static int front_rotate = 0;
static int front_fmt = V4L2_PIX_FMT_RGB24;
static int front_mbus = MEDIA_BUS_FMT_RGB888_1X24;
@@ -203,12 +205,25 @@ v4l2_ctrl_set(int fd, uint32_t id, int val)
}
static void
init_sensor(char *fn, int width, int height, int mbus)
init_sensor(char *fn, int width, int height, int mbus, int rate)
{
int fd;
struct v4l2_subdev_frame_interval interval;
struct v4l2_subdev_format fmt;
fd = open(fn, O_RDWR);
g_printerr("Setting sensor rate to %d\n", rate);
interval.pad = 0;
interval.interval.numerator = 1;
interval.interval.denominator = rate;
if (xioctl(fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, &interval) == -1) {
errno_exit("VIDIOC_SUBDEV_S_FRAME_INTERVAL");
}
g_printerr("Driver returned %d/%d frameinterval\n",
interval.interval.numerator, interval.interval.denominator);
g_printerr("Setting sensor to %dx%d fmt %d\n",
width, height, mbus);
fmt.pad = 0;
@@ -376,7 +391,7 @@ process_image(const int *p, int size)
strftime(timestamp, 30, "%F %T", &tim);
sprintf(fname, "%s/Pictures/Photo-%s.jpg", getenv("HOME"), timestamp);
printf("Saving image\n");
gdk_pixbuf_save(pixbufrot, fname, "jpeg", &error, "quality", "85", NULL);
gdk_pixbuf_save(pixbufrot, fname, "jpeg", &error, "quality", "100", NULL);
if (error != NULL) {
g_printerr(error->message);
g_clear_error(&error);
@@ -514,6 +529,8 @@ config_ini_handler(void *user, const char *section, const char *name,
rear_width = strtoint(value, NULL, 10);
} else if (strcmp(name, "height") == 0) {
rear_height = strtoint(value, NULL, 10);
} else if (strcmp(name, "rate") == 0) {
rear_rate = strtoint(value, NULL, 10);
} else if (strcmp(name, "rotate") == 0) {
rear_rotate = strtoint(value, NULL, 10);
} else if (strcmp(name, "fmt") == 0) {
@@ -558,6 +575,8 @@ config_ini_handler(void *user, const char *section, const char *name,
front_width = strtoint(value, NULL, 10);
} else if (strcmp(name, "height") == 0) {
front_height = strtoint(value, NULL, 10);
} else if (strcmp(name, "rate") == 0) {
front_rate = strtoint(value, NULL, 10);
} else if (strcmp(name, "rotate") == 0) {
front_rotate = strtoint(value, NULL, 10);
} else if (strcmp(name, "fmt") == 0) {
@@ -665,7 +684,7 @@ setup_rear()
current_fmt = rear_fmt;
current_rotate = rear_rotate;
// Find camera node
init_sensor(rear_dev, rear_width, rear_height, rear_mbus);
init_sensor(rear_dev, rear_width, rear_height, rear_mbus, rear_rate);
return 0;
}
@@ -702,7 +721,7 @@ setup_front()
current_fmt = front_fmt;
current_rotate = front_rotate;
// Find camera node
init_sensor(front_dev, front_width, front_height, front_mbus);
init_sensor(front_dev, front_width, front_height, front_mbus, front_rate);
return 0;
}

View File

@@ -3,8 +3,9 @@ csi=sun6i-csi
[rear]
driver=ov5640
width=1920
height=1080
width=2592
height=1944
rate=15
fmt=BGGR8
rotate=270
@@ -12,5 +13,6 @@ rotate=270
driver=gc2145
width=800
height=600
rate=30
fmt=BGGR8
rotate=90