aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-07-24 12:18:39 (GMT)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-07-24 12:45:56 (GMT)
commit3bbc07f94c3bf49e2828902dfeb3f6f2e6953336 (patch)
treeeabf27fc04fd80cb27275e5573b339b78ff89cf8
parent00dca626855904e955ec4c164505a0bc34db671d (diff)
Prevent activating an already active size
Changing resolution is costly, as we need first to wait for pending buffers and stop streaming. So, optimize resolution switch by not trying to activate the already activated resolution.
-rw-r--r--src/callbacks.c35
-rw-r--r--src/v4l.c16
-rw-r--r--src/v4l.h1
3 files changed, 36 insertions, 16 deletions
diff --git a/src/callbacks.c b/src/callbacks.c
index 0b193c8..3db9ba5 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -364,29 +364,32 @@ void on_change_size_activate (GtkWidget * widget, cam * cam)
{
gchar const *name;
gchar *title;
+ int width, height;
name = gtk_widget_get_name (widget);
- printf("name = %s\n",name);
+
if (strcmp (name, "small") == 0) {
- cam->width = cam->min_width;
- cam->height = cam->min_height;
- if (cam->debug) {
- printf ("\nsmall\n");
- }
+ width = cam->min_width;
+ height = cam->min_height;
} else if (strcmp (name, "medium") == 0) {
- cam->width = cam->max_width / 2;
- cam->height = cam->max_height / 2;
- if (cam->debug) {
- printf ("\nmed\n");
- }
+ width = cam->max_width / 2;
+ height = cam->max_height / 2;
} else {
- cam->width = cam->max_width;
- cam->height = cam->max_height;
- if (cam->debug) {
- printf ("\nlarge\n");
- }
+ width = cam->max_width;
+ height = cam->max_height;
}
+ try_set_win_info(cam, &width, &height);
+
+ /* Nothing to do, so just return */
+ if (width == cam->width && height == cam->height)
+ return;
+
+ cam->width = width;
+ cam->height = height;
+
+ printf("name = %s\n",name);
+
if (cam->read == FALSE)
stop_streaming(cam);
set_win_info (cam);
diff --git a/src/v4l.c b/src/v4l.c
index 47c0fe6..f2eff32 100644
--- a/src/v4l.c
+++ b/src/v4l.c
@@ -258,6 +258,22 @@ void get_win_info(cam * cam)
}
}
+void try_set_win_info(cam * cam, int *x, int *y)
+{
+ gchar *msg;
+ struct v4l2_format fmt;
+
+ memset(&fmt, 0, sizeof(fmt));
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ fmt.fmt.pix.pixelformat = cam->pixformat;
+ fmt.fmt.pix.width = *x;
+ fmt.fmt.pix.height = *y;
+ if (!v4l2_ioctl(cam->dev, VIDIOC_TRY_FMT, &fmt)) {
+ *x = fmt.fmt.pix.width;
+ *y = fmt.fmt.pix.height;
+ }
+}
+
void set_win_info(cam * cam)
{
gchar *msg;
diff --git a/src/v4l.h b/src/v4l.h
index 1c07641..b29bb42 100644
--- a/src/v4l.h
+++ b/src/v4l.h
@@ -86,6 +86,7 @@ typedef struct camera {
} cam;
void camera_cap (cam *);
+void try_set_win_info(cam * cam, int *x, int *y);
void set_win_info (cam * cam);
void get_pic_info (cam *);
void get_win_info (cam *);

Privacy Policy