* [yavta PATCH 2/3] Support extended controls, including 64-bit integers.
2012-04-12 8:41 [yavta PATCH 1/3] Support integer menus Sakari Ailus
@ 2012-04-12 8:41 ` Sakari Ailus
2012-04-12 8:41 ` [yavta PATCH 3/3] Support additional dpcm compressed bayer formats Sakari Ailus
2012-04-13 19:47 ` [yavta PATCH 1/3] Support integer menus Laurent Pinchart
2 siblings, 0 replies; 8+ messages in thread
From: Sakari Ailus @ 2012-04-12 8:41 UTC (permalink / raw)
To: linux-media; +Cc: laurent.pinchart
Fall back to regular S_CTRL / G_CTRL if extended controls aren't available.
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
yavta.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 100 insertions(+), 29 deletions(-)
diff --git a/yavta.c b/yavta.c
index 8db6e1e..532fb1f 100644
--- a/yavta.c
+++ b/yavta.c
@@ -249,40 +249,104 @@ static void video_close(struct device *dev)
close(dev->fd);
}
-static void uvc_get_control(struct device *dev, unsigned int id)
+static unsigned int get_control_type(struct device *dev, unsigned int id)
{
- struct v4l2_control ctrl;
+ struct v4l2_queryctrl query;
+ int ret;
+
+ memset(&query, 0, sizeof(query));
+
+ query.id = id;
+ ret = ioctl(dev->fd, VIDIOC_QUERYCTRL, &query);
+ if (ret == -1)
+ return V4L2_CTRL_TYPE_INTEGER;
+
+ return query.type;
+}
+
+static int get_control(struct device *dev, unsigned int id, int type,
+ int64_t *val)
+{
+ struct v4l2_ext_controls ctrls;
+ struct v4l2_ext_control ctrl;
int ret;
+
+ memset(&ctrls, 0, sizeof(ctrls));
+ memset(&ctrl, 0, sizeof(ctrl));
+
+ ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(id);
+ ctrls.count = 1;
+ ctrls.controls = &ctrl;
ctrl.id = id;
- ret = ioctl(dev->fd, VIDIOC_G_CTRL, &ctrl);
- if (ret < 0) {
- printf("unable to get control: %s (%d).\n",
- strerror(errno), errno);
- return;
+ ret = ioctl(dev->fd, VIDIOC_G_EXT_CTRLS, &ctrls);
+ if (ret != -1) {
+ if (type == V4L2_CTRL_TYPE_INTEGER64)
+ *val = ctrl.value64;
+ else
+ *val = ctrl.value;
+ return 0;
+ }
+ if (errno == EINVAL || errno == ENOTTY) {
+ struct v4l2_control old;
+
+ old.id = id;
+ ret = ioctl(dev->fd, VIDIOC_G_CTRL, &old);
+ if (ret != -1) {
+ *val = old.value;
+ return 0;
+ }
}
- printf("Control 0x%08x value %u\n", id, ctrl.value);
+ printf("unable to get control 0x%8.8x: %s (%d).\n",
+ id, strerror(errno), errno);
+ return -1;
}
-static void uvc_set_control(struct device *dev, unsigned int id, int value)
+static void set_control(struct device *dev, unsigned int id, int type,
+ int64_t val)
{
- struct v4l2_control ctrl;
+ struct v4l2_ext_controls ctrls;
+ struct v4l2_ext_control ctrl;
+ int is_64 = type == V4L2_CTRL_TYPE_INTEGER64;
+ int64_t old_val = val;
int ret;
+
+ memset(&ctrls, 0, sizeof(ctrls));
+ memset(&ctrl, 0, sizeof(ctrl));
+
+ ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(id);
+ ctrls.count = 1;
+ ctrls.controls = &ctrl;
ctrl.id = id;
- ctrl.value = value;
+ if (is_64)
+ ctrl.value64 = val;
+ else
+ ctrl.value = val;
- ret = ioctl(dev->fd, VIDIOC_S_CTRL, &ctrl);
- if (ret < 0) {
- printf("unable to set control: %s (%d).\n",
- strerror(errno), errno);
+ ret = ioctl(dev->fd, VIDIOC_S_EXT_CTRLS, &ctrls);
+ if (ret != -1) {
+ if (is_64)
+ val = ctrl.value64;
+ else
+ val = ctrl.value;
+ } else if (errno == EINVAL || errno == ENOTTY) {
+ struct v4l2_control old;
+
+ old.id = id;
+ ret = ioctl(dev->fd, VIDIOC_S_CTRL, &old);
+ if (ret != -1)
+ val = old.value;
+ }
+ if (ret == -1) {
+ printf("unable to set control 0x%8.8x: %s (%d).\n",
+ id, strerror(errno), errno);
return;
}
-
- printf("Control 0x%08x set to %u, is %u\n", id, value,
- ctrl.value);
+
+ printf("Control 0x%08x set to %lld, is %lld\n", id, old_val, val);
}
static int video_get_format(struct device *dev)
@@ -588,7 +652,8 @@ static void video_list_controls(struct device *dev)
struct v4l2_queryctrl query;
struct v4l2_control ctrl;
unsigned int nctrls = 0;
- char value[12];
+ char value[24];
+ int64_t val64;
int ret;
#ifndef V4L2_CTRL_FLAG_NEXT_CTRL
@@ -608,18 +673,17 @@ static void video_list_controls(struct device *dev)
if (query.flags & V4L2_CTRL_FLAG_DISABLED)
continue;
- ctrl.id = query.id;
- ret = ioctl(dev->fd, VIDIOC_G_CTRL, &ctrl);
- if (ret < 0)
- strcpy(value, "n/a");
- else
- sprintf(value, "%d", ctrl.value);
-
if (query.type == V4L2_CTRL_TYPE_CTRL_CLASS) {
printf("--- %s (class 0x%08x) ---\n", query.name, query.id);
continue;
}
+ ret = get_control(dev, query.id, query.type, &val64);
+ if (ret < 0)
+ strcpy(value, "n/a");
+ else
+ sprintf(value, "%d", val64);
+
printf("control 0x%08x `%s' min %d max %d step %d default %d current %s.\n",
query.id, query.name, query.minimum, query.maximum,
query.step, query.default_value, value);
@@ -1420,10 +1484,17 @@ int main(int argc, char *argv[])
dev.memtype = memtype;
- if (do_get_control)
- uvc_get_control(&dev, ctrl_name);
+ if (do_get_control) {
+ int64_t val;
+ ret = get_control(&dev, ctrl_name,
+ get_control_type(&dev, ctrl_name), &val);
+ if (ret >= 0)
+ printf("Control 0x%08x value %lld\n", ctrl_name, val);
+ }
+
if (do_set_control)
- uvc_set_control(&dev, ctrl_name, ctrl_value);
+ set_control(&dev, ctrl_name, get_control_type(&dev, ctrl_name),
+ ctrl_value);
if (do_list_controls)
video_list_controls(&dev);
--
1.7.2.5
^ permalink raw reply related [flat|nested] 8+ messages in thread* [yavta PATCH 3/3] Support additional dpcm compressed bayer formats.
2012-04-12 8:41 [yavta PATCH 1/3] Support integer menus Sakari Ailus
2012-04-12 8:41 ` [yavta PATCH 2/3] Support extended controls, including 64-bit integers Sakari Ailus
@ 2012-04-12 8:41 ` Sakari Ailus
2012-04-13 19:17 ` Laurent Pinchart
2012-04-13 19:47 ` [yavta PATCH 1/3] Support integer menus Laurent Pinchart
2 siblings, 1 reply; 8+ messages in thread
From: Sakari Ailus @ 2012-04-12 8:41 UTC (permalink / raw)
To: linux-media; +Cc: laurent.pinchart
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
yavta.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/yavta.c b/yavta.c
index 532fb1f..a89d475 100644
--- a/yavta.c
+++ b/yavta.c
@@ -149,7 +149,10 @@ static struct {
{ "SGBRG8", V4L2_PIX_FMT_SGBRG8 },
{ "SGRBG8", V4L2_PIX_FMT_SGRBG8 },
{ "SRGGB8", V4L2_PIX_FMT_SRGGB8 },
+ { "SBGGR10_DPCM8", V4L2_PIX_FMT_SBGGR10DPCM8 },
+ { "SGBRG10_DPCM8", V4L2_PIX_FMT_SGBRG10DPCM8 },
{ "SGRBG10_DPCM8", V4L2_PIX_FMT_SGRBG10DPCM8 },
+ { "SRGGB10_DPCM8", V4L2_PIX_FMT_SRGGB10DPCM8 },
{ "SBGGR10", V4L2_PIX_FMT_SBGGR10 },
{ "SGBRG10", V4L2_PIX_FMT_SGBRG10 },
{ "SGRBG10", V4L2_PIX_FMT_SGRBG10 },
--
1.7.2.5
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [yavta PATCH 1/3] Support integer menus.
2012-04-12 8:41 [yavta PATCH 1/3] Support integer menus Sakari Ailus
2012-04-12 8:41 ` [yavta PATCH 2/3] Support extended controls, including 64-bit integers Sakari Ailus
2012-04-12 8:41 ` [yavta PATCH 3/3] Support additional dpcm compressed bayer formats Sakari Ailus
@ 2012-04-13 19:47 ` Laurent Pinchart
2012-04-13 19:57 ` Rémi Denis-Courmont
2012-04-13 20:13 ` Sakari Ailus
2 siblings, 2 replies; 8+ messages in thread
From: Laurent Pinchart @ 2012-04-13 19:47 UTC (permalink / raw)
To: Sakari Ailus; +Cc: linux-media
Hi Sakari,
Thanks for the patch.
The code looks fine, but unfortunately breaks compilation when using kernel
headers < v3.5 (which is a pretty common case as of today ;-)).
V4L2_CTRL_TYPE_INTEGER_MENU is an enumerated value, not a pre-processor
#define, so it's difficult to test for it using conditional compilation.
Maybe including a copy of videodev2.h in the yavta repository is the best
option ?
On Thursday 12 April 2012 11:41:33 Sakari Ailus wrote:
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
> yavta.c | 18 +++++++++++-------
> 1 files changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/yavta.c b/yavta.c
> index 72679c2..8db6e1e 100644
> --- a/yavta.c
> +++ b/yavta.c
> @@ -564,19 +564,22 @@ static int video_enable(struct device *dev, int
> enable) return 0;
> }
>
> -static void video_query_menu(struct device *dev, unsigned int id,
> - unsigned int min, unsigned int max)
> +static void video_query_menu(struct device *dev, struct v4l2_queryctrl
> *query) {
> struct v4l2_querymenu menu;
> int ret;
>
> - for (menu.index = min; menu.index <= max; menu.index++) {
> - menu.id = id;
> + for (menu.index = query->minimum; menu.index <= query->maximum;
> + menu.index++) {
> + menu.id = query->id;
> ret = ioctl(dev->fd, VIDIOC_QUERYMENU, &menu);
> if (ret < 0)
> continue;
>
> - printf(" %u: %.32s\n", menu.index, menu.name);
> + if (query->type == V4L2_CTRL_TYPE_MENU)
> + printf(" %u: %.32s\n", menu.index, menu.name);
> + else
> + printf(" %u: %lld\n", menu.index, menu.value);
> };
> }
>
> @@ -621,8 +624,9 @@ static void video_list_controls(struct device *dev)
> query.id, query.name, query.minimum, query.maximum,
> query.step, query.default_value, value);
>
> - if (query.type == V4L2_CTRL_TYPE_MENU)
> - video_query_menu(dev, query.id, query.minimum, query.maximum);
> + if (query.type == V4L2_CTRL_TYPE_MENU ||
> + query.type == V4L2_CTRL_TYPE_INTEGER_MENU)
> + video_query_menu(dev, &query);
>
> nctrls++;
> }
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 8+ messages in thread