Added main loop for loading new frames
This commit is contained in:
parent
6190add3bc
commit
38ec7621fc
27
main.c
27
main.c
|
@ -19,6 +19,7 @@ struct buffer {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct buffer *buffers;
|
struct buffer *buffers;
|
||||||
|
static int *outbuffer;
|
||||||
static unsigned int n_buffers;
|
static unsigned int n_buffers;
|
||||||
static char *rear_dev_name;
|
static char *rear_dev_name;
|
||||||
static char *front_dev_name;
|
static char *front_dev_name;
|
||||||
|
@ -245,8 +246,10 @@ init_device(int fd)
|
||||||
g_printerr("Driver returned %dx%d fmt %d\n",
|
g_printerr("Driver returned %dx%d fmt %d\n",
|
||||||
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
||||||
fmt.fmt.pix.pixelformat);
|
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. */
|
/* Buggy driver paranoia. */
|
||||||
unsigned int min = fmt.fmt.pix.width * 2;
|
unsigned int min = fmt.fmt.pix.width * 2;
|
||||||
|
@ -274,11 +277,13 @@ init_device(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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,
|
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data(p, GDK_COLORSPACE_RGB,
|
||||||
FALSE, 8, 640, 480, 2 * 640, NULL, NULL);
|
FALSE, 8, 640, 480, 2 * 640,
|
||||||
gtk_image_set_from_pixbuf(preview_image, pixbuf);
|
NULL, NULL);
|
||||||
|
gtk_image_set_from_pixbuf(preview_image, pixbuf
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -361,7 +366,7 @@ read_frame(int fd)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
get_frame(int fd)
|
get_frame(int fd)
|
||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -393,11 +398,13 @@ get_frame(int fd)
|
||||||
}
|
}
|
||||||
/* EAGAIN - continue select loop. */
|
/* EAGAIN - continue select loop. */
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
config_ini_handler(void *user, const char *section, const char *name,
|
config_ini_handler(void *user, const char *section, const char *name,
|
||||||
const char *value) {
|
const char *value)
|
||||||
|
{
|
||||||
if (strcmp(section, "preview") == 0) {
|
if (strcmp(section, "preview") == 0) {
|
||||||
if (strcmp(name, "width") == 0) {
|
if (strcmp(name, "width") == 0) {
|
||||||
preview_width = strtol(value, NULL, 10);
|
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) {
|
} else if (strcmp(name, "fmt") == 0) {
|
||||||
if (strcmp(value, "RGB") == 0) {
|
if (strcmp(value, "RGB") == 0) {
|
||||||
preview_fmt = V4L2_PIX_FMT_RGB24;
|
preview_fmt = V4L2_PIX_FMT_RGB24;
|
||||||
} else if (strcmp(value, "UYVY8") == 0) {
|
} else if (strcmp(value, "UYVY") == 0) {
|
||||||
preview_fmt = V4L2_PIX_FMT_UYVY;
|
preview_fmt = V4L2_PIX_FMT_UYVY;
|
||||||
|
} else if (strcmp(value, "YUYV") == 0) {
|
||||||
|
preview_fmt = V4L2_PIX_FMT_YUYV;
|
||||||
} else if (strcmp(value, "JPEG") == 0) {
|
} else if (strcmp(value, "JPEG") == 0) {
|
||||||
preview_fmt = V4L2_PIX_FMT_JPEG;
|
preview_fmt = V4L2_PIX_FMT_JPEG;
|
||||||
} else if (strcmp(value, "NV12") == 0) {
|
} else if (strcmp(value, "NV12") == 0) {
|
||||||
|
@ -502,7 +511,9 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
init_device(fd);
|
init_device(fd);
|
||||||
start_capturing(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_widget_show(window);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
Loading…
Reference in New Issue