summaryrefslogtreecommitdiff
path: root/v4l2-apps/libv4l/libv4lconvert/control
diff options
context:
space:
mode:
authorhans@rhel5-devel.localdomain <hans@rhel5-devel.localdomain>2009-05-20 07:23:00 +0200
committerhans@rhel5-devel.localdomain <hans@rhel5-devel.localdomain>2009-05-20 07:23:00 +0200
commit34a210b573f9c8ff8f07077f239be95d9d9248c5 (patch)
treed7a5f1bd73afbaa0a7a8ef7d2de10a03c6c5265e /v4l2-apps/libv4l/libv4lconvert/control
parenta077e421fe63a7102f6bbaa7057df7690e239cf6 (diff)
downloadmediapointer-dvb-s2-34a210b573f9c8ff8f07077f239be95d9d9248c5.tar.gz
mediapointer-dvb-s2-34a210b573f9c8ff8f07077f239be95d9d9248c5.tar.bz2
libv4l: add fake controls controlling the software h- and v-flipping
From: Hans de Goede <hdegoede@redhat.com> When we need to go through the fake mmap buffer anyways, we can add fake controls at no cost. So in the case of webcams which only support non standard pixformats, export fake flipping controls, as this can be done at no (performace) cost (until the user activates them). Priority: normal Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'v4l2-apps/libv4l/libv4lconvert/control')
-rw-r--r--v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.c42
-rw-r--r--v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.h12
2 files changed, 49 insertions, 5 deletions
diff --git a/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.c b/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.c
index 1ffd05cc4..b120aa2fc 100644
--- a/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.c
+++ b/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.c
@@ -198,12 +198,13 @@ static void v4lcontrol_init_flags(struct v4lcontrol_data *data)
}
}
-struct v4lcontrol_data *v4lcontrol_create(int fd)
+struct v4lcontrol_data *v4lcontrol_create(int fd, int always_needs_conversion)
{
int shm_fd;
int i, init = 0;
char *s, shm_name[256];
struct v4l2_capability cap;
+ struct v4l2_queryctrl ctrl;
struct v4lcontrol_data *data = calloc(1, sizeof(struct v4lcontrol_data));
@@ -214,6 +215,17 @@ struct v4lcontrol_data *v4lcontrol_create(int fd)
v4lcontrol_init_flags(data);
+ /* If the device always needs conversion, we can add fake controls at no cost
+ (no cost when not activated by the user that is) */
+ if (always_needs_conversion || v4lcontrol_needs_conversion(data)) {
+ ctrl.id = V4L2_CID_HFLIP;
+ if (syscall(SYS_ioctl, data->fd, VIDIOC_QUERYCTRL, &ctrl) == -1)
+ data->controls |= 1 << V4LCONTROL_HFLIP;
+ ctrl.id = V4L2_CID_VFLIP;
+ if (syscall(SYS_ioctl, data->fd, VIDIOC_QUERYCTRL, &ctrl) == -1)
+ data->controls |= 1 << V4LCONTROL_VFLIP;
+ }
+
/* Allow overriding through environment */
if ((s = getenv("LIBV4LCONTROL_FLAGS")))
data->flags = strtol(s, NULL, 0);
@@ -313,6 +325,26 @@ struct v4l2_queryctrl fake_controls[V4LCONTROL_COUNT] = {
.default_value = 255,
.flags = 0
},
+{
+ .id = V4L2_CID_HFLIP,
+ .type = V4L2_CTRL_TYPE_BOOLEAN,
+ .name = "Horizontal flip",
+ .minimum = 0,
+ .maximum = 1,
+ .step = 1,
+ .default_value = 0,
+ .flags = 0
+},
+{
+ .id = V4L2_CID_VFLIP,
+ .type = V4L2_CTRL_TYPE_BOOLEAN,
+ .name = "Vertical flip",
+ .minimum = 0,
+ .maximum = 1,
+ .step = 1,
+ .default_value = 0,
+ .flags = 0
+},
};
int v4lcontrol_vidioc_queryctrl(struct v4lcontrol_data *data, void *arg)
@@ -390,8 +422,14 @@ int v4lcontrol_get_flags(struct v4lcontrol_data *data)
int v4lcontrol_get_ctrl(struct v4lcontrol_data *data, int ctrl)
{
- if (data->controls & (1 << ctrl))
+ if (data->controls & (1 << ctrl)) {
+ /* Special case for devices with flipped input */
+ if ((ctrl == V4LCONTROL_HFLIP && (data->flags & V4LCONTROL_HFLIPPED)) ||
+ (ctrl == V4LCONTROL_VFLIP && (data->flags & V4LCONTROL_VFLIPPED)))
+ return !data->shm_values[ctrl];
+
return data->shm_values[ctrl];
+ }
return 0;
}
diff --git a/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.h b/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.h
index 28308bc55..43ef7c49f 100644
--- a/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.h
+++ b/v4l2-apps/libv4l/libv4lconvert/control/libv4lcontrol.h
@@ -28,12 +28,18 @@
#define V4LCONTROL_ROTATED_90_JPEG 0x04
/* Controls */
-enum { V4LCONTROL_WHITEBALANCE, V4LCONTROL_NORMALIZE,
- V4LCONTROL_NORM_LOW_BOUND, V4LCONTROL_NORM_HIGH_BOUND, V4LCONTROL_COUNT };
+enum {
+ V4LCONTROL_WHITEBALANCE,
+ V4LCONTROL_NORMALIZE,
+ V4LCONTROL_NORM_LOW_BOUND,
+ V4LCONTROL_NORM_HIGH_BOUND,
+ V4LCONTROL_HFLIP,
+ V4LCONTROL_VFLIP,
+ V4LCONTROL_COUNT };
struct v4lcontrol_data;
-struct v4lcontrol_data* v4lcontrol_create(int fd);
+struct v4lcontrol_data* v4lcontrol_create(int fd, int always_needs_conversion);
void v4lcontrol_destroy(struct v4lcontrol_data *data);
/* Functions used by v4lprocessing to get the control state */