Added main loop for loading new frames

This commit is contained in:
Martijn Braam 2020-01-25 14:34:37 +01:00
parent 6190add3bc
commit 38ec7621fc
No known key found for this signature in database
GPG Key ID: C4280ACB000B060F
2 changed files with 165 additions and 153 deletions

27
main.c
View File

@ -19,6 +19,7 @@ struct buffer {
};
struct buffer *buffers;
static int *outbuffer;
static unsigned int n_buffers;
static char *rear_dev_name;
static char *front_dev_name;
@ -245,8 +246,10 @@ init_device(int fd)
g_printerr("Driver returned %dx%d fmt %d\n",
fmt.fmt.pix.width, fmt.fmt.pix.height,
fmt.fmt.pix.pixelformat);
preview_width = fmt.fmt.pix.width;
preview_height = fmt.fmt.pix.height;
}
preview_fmt = fmt.fmt.pix.pixelformat;
/* Buggy driver paranoia. */
unsigned int min = fmt.fmt.pix.width * 2;
@ -274,11 +277,13 @@ init_device(int fd)
}
static void
process_image(const void *p, int size)
process_image(const int *p, int size)
{
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data(p, GDK_COLORSPACE_RGB,
FALSE, 8, 640, 480, 2 * 640, NULL, NULL);
gtk_image_set_from_pixbuf(preview_image, pixbuf);
FALSE, 8, 640, 480, 2 * 640,
NULL, NULL);
gtk_image_set_from_pixbuf(preview_image, pixbuf
);
}
static int
@ -361,7 +366,7 @@ read_frame(int fd)
return 1;
}
static void
static gboolean
get_frame(int fd)
{
while (1) {
@ -393,11 +398,13 @@ get_frame(int fd)
}
/* EAGAIN - continue select loop. */
}
return TRUE;
}
static int
config_ini_handler(void *user, const char *section, const char *name,
const char *value) {
const char *value)
{
if (strcmp(section, "preview") == 0) {
if (strcmp(name, "width") == 0) {
preview_width = strtol(value, NULL, 10);
@ -406,8 +413,10 @@ config_ini_handler(void *user, const char *section, const char *name,
} else if (strcmp(name, "fmt") == 0) {
if (strcmp(value, "RGB") == 0) {
preview_fmt = V4L2_PIX_FMT_RGB24;
} else if (strcmp(value, "UYVY8") == 0) {
} else if (strcmp(value, "UYVY") == 0) {
preview_fmt = V4L2_PIX_FMT_UYVY;
} else if (strcmp(value, "YUYV") == 0) {
preview_fmt = V4L2_PIX_FMT_YUYV;
} else if (strcmp(value, "JPEG") == 0) {
preview_fmt = V4L2_PIX_FMT_JPEG;
} else if (strcmp(value, "NV12") == 0) {
@ -502,7 +511,9 @@ main(int argc, char *argv[])
init_device(fd);
start_capturing(fd);
get_frame(fd);
// Get a new frame every 34ms ~30fps
g_timeout_add(34, get_frame, fd);
gtk_widget_show(window);
gtk_main();

View File

@ -4,3 +4,4 @@ rear=/dev/video0
[preview]
width=640
height=480
fmt=YUYV