public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <m.chehab@samsung.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com,
	s.nawrocki@samsung.com, ismael.luceno@corp.bluecherry.net,
	pete@sensoray.com, sakari.ailus@iki.fi,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [REVIEWv3 PATCH 24/35] v4l2-ctrls/videodev2.h: add u8 and u16 types.
Date: Wed, 12 Mar 2014 11:44:53 -0300	[thread overview]
Message-ID: <20140312114453.06236492@samsung.com> (raw)
In-Reply-To: <1392631070-41868-25-git-send-email-hverkuil@xs4all.nl>

Em Mon, 17 Feb 2014 10:57:39 +0100
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> These are needed by the upcoming patches for the motion detection
> matrices.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/v4l2-core/v4l2-ctrls.c | 45 ++++++++++++++++++++++++++++++++----
>  include/media/v4l2-ctrls.h           |  4 ++++
>  include/uapi/linux/videodev2.h       |  4 ++++
>  3 files changed, 49 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index 1886b79..ca4271b 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -1145,6 +1145,10 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
>  		return !strcmp(ptr1.p_char + idx, ptr2.p_char + idx);
>  	case V4L2_CTRL_TYPE_INTEGER64:
>  		return ptr1.p_s64[idx] == ptr2.p_s64[idx];
> +	case V4L2_CTRL_TYPE_U8:
> +		return ptr1.p_u8[idx] == ptr2.p_u8[idx];
> +	case V4L2_CTRL_TYPE_U16:
> +		return ptr1.p_u16[idx] == ptr2.p_u16[idx];

Please replace V4L2_CTRL_TYPE_INTEGER64 and V4L2_CTRL_TYPE_INTEGER to
V4L2_CTRL_TYPE_S64 and V4L2_CTRL_TYPE_S32 and add an alias for those previous
names at videodev2.h:

#define V4L2_CTRL_TYPE_INTEGER64	V4L2_CTRL_TYPE_S64
#define V4L2_CTRL_TYPE_INTEGER		V4L2_CTRL_TYPE_S32

Please notice that there's no reason at all to deprecate the old names,
so we'll keep the above defines forever.

Yet, now that we're using U<bitsize> for some types, let's standardize this to
the other types too, as it makes the API more consistent.

Also, I won't doubt that we'll eventually need S8, S16, U32, U64 types in
the future.

>  	default:
>  		if (ctrl->is_int)
>  			return ptr1.p_s32[idx] == ptr2.p_s32[idx];
> @@ -1172,6 +1176,12 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
>  	case V4L2_CTRL_TYPE_BOOLEAN:
>  		ptr.p_s32[idx] = ctrl->default_value;
>  		break;
> +	case V4L2_CTRL_TYPE_U8:
> +		ptr.p_u8[idx] = ctrl->default_value;
> +		break;
> +	case V4L2_CTRL_TYPE_U16:
> +		ptr.p_u16[idx] = ctrl->default_value;
> +		break;
>  	default:
>  		idx *= ctrl->elem_size;
>  		memset(ptr.p + idx, 0, ctrl->elem_size);
> @@ -1208,6 +1218,12 @@ static void std_log(const struct v4l2_ctrl *ctrl)
>  	case V4L2_CTRL_TYPE_STRING:
>  		pr_cont("%s", ptr.p_char);
>  		break;
> +	case V4L2_CTRL_TYPE_U8:
> +		pr_cont("%u", (unsigned)*ptr.p_u8);
> +		break;
> +	case V4L2_CTRL_TYPE_U16:
> +		pr_cont("%u", (unsigned)*ptr.p_u16);
> +		break;
>  	default:
>  		pr_cont("unknown type %d", ctrl->type);
>  		break;
> @@ -1238,6 +1254,10 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
>  		return ROUND_TO_RANGE(ptr.p_s32[idx], u32, ctrl);
>  	case V4L2_CTRL_TYPE_INTEGER64:
>  		return ROUND_TO_RANGE(ptr.p_s64[idx], u64, ctrl);
> +	case V4L2_CTRL_TYPE_U8:
> +		return ROUND_TO_RANGE(ptr.p_u8[idx], u8, ctrl);
> +	case V4L2_CTRL_TYPE_U16:
> +		return ROUND_TO_RANGE(ptr.p_u16[idx], u16, ctrl);
>  
>  	case V4L2_CTRL_TYPE_BOOLEAN:
>  		ptr.p_s32[idx] = !!ptr.p_s32[idx];
> @@ -1470,6 +1490,8 @@ static int check_range(enum v4l2_ctrl_type type,
>  		if (step != 1 || max > 1 || min < 0)
>  			return -ERANGE;
>  		/* fall through */
> +	case V4L2_CTRL_TYPE_U8:
> +	case V4L2_CTRL_TYPE_U16:
>  	case V4L2_CTRL_TYPE_INTEGER:
>  	case V4L2_CTRL_TYPE_INTEGER64:
>  		if (step == 0 || min > max || def < min || def > max)
> @@ -1768,12 +1790,25 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
>  		rows = 1;
>  	is_matrix = cols > 1 || rows > 1;
>  
> -	if (type == V4L2_CTRL_TYPE_INTEGER64)
> +	/* Prefill elem_size for all types handled by std_type_ops */
> +	switch (type) {
> +	case V4L2_CTRL_TYPE_INTEGER64:
>  		elem_size = sizeof(s64);
> -	else if (type == V4L2_CTRL_TYPE_STRING)
> +		break;
> +	case V4L2_CTRL_TYPE_STRING:
>  		elem_size = max + 1;
> -	else if (type < V4L2_CTRL_COMPLEX_TYPES)
> -		elem_size = sizeof(s32);
> +		break;
> +	case V4L2_CTRL_TYPE_U8:
> +		elem_size = sizeof(u8);
> +		break;
> +	case V4L2_CTRL_TYPE_U16:
> +		elem_size = sizeof(u16);
> +		break;
> +	default:
> +		if (type < V4L2_CTRL_COMPLEX_TYPES)
> +			elem_size = sizeof(s32);
> +		break;
> +	}
>  	tot_ctrl_size = elem_size * cols * rows;
>  
>  	/* Sanity checks */
> @@ -3114,6 +3149,8 @@ int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
>  	case V4L2_CTRL_TYPE_MENU:
>  	case V4L2_CTRL_TYPE_INTEGER_MENU:
>  	case V4L2_CTRL_TYPE_BITMASK:
> +	case V4L2_CTRL_TYPE_U8:
> +	case V4L2_CTRL_TYPE_U16:
>  		if (ctrl->is_matrix)
>  			return -EINVAL;
>  		ret = check_range(ctrl->type, min, max, step, def);
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index 7d72328..2ccad5f 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -39,12 +39,16 @@ struct poll_table_struct;
>  /** union v4l2_ctrl_ptr - A pointer to a control value.
>   * @p_s32:	Pointer to a 32-bit signed value.
>   * @p_s64:	Pointer to a 64-bit signed value.
> + * @p_u8:	Pointer to a 8-bit unsigned value.
> + * @p_u16:	Pointer to a 16-bit unsigned value.
>   * @p_char:	Pointer to a string.
>   * @p:		Pointer to a complex value.
>   */
>  union v4l2_ctrl_ptr {
>  	s32 *p_s32;
>  	s64 *p_s64;
> +	u8 *p_u8;
> +	u16 *p_u16;
>  	char *p_char;
>  	void *p;
>  };
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 858a6f3..8b70f51 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -1228,6 +1228,8 @@ struct v4l2_ext_control {
>  		__s32 value;
>  		__s64 value64;
>  		char *string;
> +		__u8 *p_u8;
> +		__u16 *p_u16;
>  		void *p;
>  	};
>  } __attribute__ ((packed));
> @@ -1257,6 +1259,8 @@ enum v4l2_ctrl_type {
>  
>  	/* Complex types are >= 0x0100 */
>  	V4L2_CTRL_COMPLEX_TYPES	     = 0x0100,
> +	V4L2_CTRL_TYPE_U8	     = 0x0100,
> +	V4L2_CTRL_TYPE_U16	     = 0x0101,

Huh? Why are those two compound types?

If all you want is to have a "matrix" set of types, IMO, the
best would be to do, instead

enum v4l2_ctrl_type {
	/* Basic types */
	V4L2_CTRL_TYPE_S32	     = 1,
	V4L2_CTRL_TYPE_BOOLEAN	     = 2,
	V4L2_CTRL_TYPE_MENU	     = 3,
	V4L2_CTRL_TYPE_BUTTON	     = 4,
	V4L2_CTRL_TYPE_S64           = 5,
	V4L2_CTRL_TYPE_CTRL_CLASS    = 6,
	V4L2_CTRL_TYPE_STRING        = 7,
	V4L2_CTRL_TYPE_BITMASK       = 8,
	V4L2_CTRL_TYPE_INTEGER_MENU  = 9,
	V4L2_CTRL_TYPE_U8	     = 10,
	V4L2_CTRL_TYPE_U16	     = 11,

	/* Modifiers */
	V4L2_CTRL_TYPE_MATRIX	     = 0x100
};

That way, a matrix of S32 would have type = V4L2_CTRL_TYPE_S32 | V4L2_CTRL_TYPE_MATRIX.

A matrix of U16 would be V4L2_CTRL_TYPE_U16 | V4L2_CTRL_TYPE_MATRIX, and so on.


>  };
>  
>  /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */


-- 

Regards,
Mauro

  reply	other threads:[~2014-03-12 14:45 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-17  9:57 [REVIEWv3 PATCH 00/35] Add support for complex controls, use in solo/go7007 Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 01/35] v4l2-ctrls: increase internal min/max/step/def to 64 bit Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 02/35] v4l2-ctrls: add unit string Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 03/35] v4l2-ctrls: use pr_info/cont instead of printk Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 04/35] videodev2.h: add initial support for complex controls Hans Verkuil
2014-03-11 19:34   ` Mauro Carvalho Chehab
2014-03-11 20:23     ` Hans Verkuil
2014-03-11 23:48       ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 05/35] videodev2.h: add struct v4l2_query_ext_ctrl and VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-03-11 19:42   ` Mauro Carvalho Chehab
2014-03-11 20:29     ` Hans Verkuil
2014-03-11 23:35       ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 06/35] v4l2-ctrls: add support for complex types Hans Verkuil
2014-03-11 20:14   ` Mauro Carvalho Chehab
2014-03-11 20:43     ` Hans Verkuil
2014-03-11 23:43       ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 07/35] v4l2: integrate support for VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 08/35] v4l2-ctrls: create type_ops Hans Verkuil
2014-03-11 20:22   ` Mauro Carvalho Chehab
2014-03-11 20:49     ` Hans Verkuil
2014-03-11 23:56       ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 09/35] v4l2-ctrls: rewrite copy routines to operate on union v4l2_ctrl_ptr Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 10/35] v4l2-ctrls: compare values only once Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 11/35] v4l2-ctrls: prepare for matrix support: add cols & rows fields Hans Verkuil
2014-03-12 10:34   ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 12/35] v4l2-ctrls: replace cur by a union v4l2_ctrl_ptr Hans Verkuil
2014-03-12 10:38   ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 13/35] v4l2-ctrls: use 'new' to access pointer controls Hans Verkuil
2014-03-12 10:40   ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 14/35] v4l2-ctrls: prepare for matrix support Hans Verkuil
2014-03-12 10:42   ` Mauro Carvalho Chehab
2014-03-12 12:21     ` Hans Verkuil
2014-03-12 13:00       ` Mauro Carvalho Chehab
2014-03-12 13:00       ` Mauro Carvalho Chehab
2014-03-12 13:41         ` Hans Verkuil
2014-03-12 13:44         ` Sylwester Nawrocki
2014-02-17  9:57 ` [REVIEWv3 PATCH 15/35] v4l2-ctrls: type_ops can handle matrix elements Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 16/35] v4l2-ctrls: add matrix support Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 17/35] v4l2-ctrls: return elem_size instead of strlen Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 18/35] v4l2-ctrl: fix error return of copy_to/from_user Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 19/35] DocBook media: document VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-03-12 14:13   ` Mauro Carvalho Chehab
2014-03-13  7:58     ` Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 20/35] DocBook media: update VIDIOC_G/S/TRY_EXT_CTRLS Hans Verkuil
2014-03-12 14:20   ` Mauro Carvalho Chehab
2014-03-13 12:18     ` Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 21/35] DocBook media: fix coding style in the control example code Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 22/35] DocBook media: update control section Hans Verkuil
2014-02-19 23:15   ` Sakari Ailus
2014-03-12 14:27   ` Mauro Carvalho Chehab
2014-02-17  9:57 ` [REVIEWv3 PATCH 23/35] v4l2-controls.txt: update to the new way of accessing controls Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 24/35] v4l2-ctrls/videodev2.h: add u8 and u16 types Hans Verkuil
2014-03-12 14:44   ` Mauro Carvalho Chehab [this message]
2014-02-17  9:57 ` [REVIEWv3 PATCH 25/35] DocBook media: document new u8 and u16 control types Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 26/35] v4l2-ctrls: fix comments Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 27/35] v4l2-ctrls/v4l2-controls.h: add MD controls Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 28/35] DocBook media: document new motion detection controls Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 29/35] v4l2: add a motion detection event Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 30/35] DocBook: document new v4l " Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 31/35] solo6x10: implement the new motion detection controls Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 32/35] solo6x10: implement the motion detection event Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 33/35] solo6x10: fix 'dma from stack' warning Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 34/35] solo6x10: check dma_map_sg() return value Hans Verkuil
2014-02-17  9:57 ` [REVIEWv3 PATCH 35/35] go7007: add motion detection support Hans Verkuil
2014-02-19  8:28 ` [REVIEWv3 PATCH 00/35] Add support for complex controls, use in solo/go7007 Ricardo Ribalda Delgado
2014-02-19  8:54   ` Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140312114453.06236492@samsung.com \
    --to=m.chehab@samsung.com \
    --cc=hans.verkuil@cisco.com \
    --cc=hverkuil@xs4all.nl \
    --cc=ismael.luceno@corp.bluecherry.net \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=pete@sensoray.com \
    --cc=s.nawrocki@samsung.com \
    --cc=sakari.ailus@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox