public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hansverk@cisco.com>
To: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	linux-media <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <m.chehab@samsung.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Ismael Luceno <ismael.luceno@corp.bluecherry.net>,
	pete@sensoray.com, Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [REVIEWv2 PATCH 24/34] v4l2-ctrls/videodev2.h: add u8 and u16 types.
Date: Wed, 12 Feb 2014 15:05:34 +0100	[thread overview]
Message-ID: <52FB7FAE.8000101@cisco.com> (raw)
In-Reply-To: <CAPybu_2Zs+jLT1q+28vbQBU0Lv6NheCPuy9jTSOVcVXv+myMWA@mail.gmail.com>



On 02/12/14 14:40, Ricardo Ribalda Delgado wrote:
> Hello Hans
> 
> 
> 
> On Wed, Feb 12, 2014 at 2:26 PM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>> On 02/12/14 14:13, Ricardo Ribalda Delgado wrote:
>>> Hello Hans
>>>
>>> Thanks for you promptly response
>>>
>>> On Wed, Feb 12, 2014 at 1:40 PM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>>>> On 02/12/14 13:11, Ricardo Ribalda Delgado wrote:
>>>>> Hi Hans
>>>>>
>>>>> Thanks for your reply
>>>>>
>>>>> On Wed, Feb 12, 2014 at 12:20 PM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>>>>>> Hi Ricardo,
>>>>>>
>>>>>> On 02/12/14 11:44, Ricardo Ribalda Delgado wrote:
>>>>>>> Hello Hans
>>>>>>>
>>>>>>> In the case of U8 and U16 data types. Why dont you fill the elem_size
>>>>>>> automatically in v4l2_ctrl and request the driver to fill the field?
>>>>>>
>>>>>> When you create the control the control framework has to know the element
>>>>>> size beforehand as it will use that to allocate the memory containing the
>>>>>> control's value. The control framework is aware of the 'old' control types
>>>>>> and will fill in the elem_size accordingly, but it cannot do that in the
>>>>>> general case for these complex types. I guess it could be filled in by the
>>>>>> framework for the more common types (U8, U16) but I felt it was more
>>>>>> consistent to just require drivers to fill it in manually, rather than have
>>>>>> it set for some types but not for others.
>>>>>>
>>>>>>>
>>>>>>> Other option would be not declaring the basic data types (U8, U16,
>>>>>>> U32...) and use elem_size. Ie. If type==V4L2_CTRL_COMPLEX_TYPES, then
>>>>>>> the type is basic and elem_size is the size of the type. If the type
>>>>>>>> V4L2_CTRL_COMPLEX_TYPES the type is not basic.
>>>>>>
>>>>>> You still need to know the type. Applications have to be able to check for
>>>>>> the type, the element size by itself doesn't tell you how to interpret the
>>>>>> data, you need the type identifier as well.
>>>>>
>>>>> I think that the driver is setting twice the same info. I see no gain
>>>>> in declaring U8, U16 types etc if we still have to set the element
>>>>> size. This is why I believe that we should only declare the "structs".
>>>>
>>>> Just to make sure I understand you: for simple types like U8/U16 you want
>>>> the control framework to fill in elem_size, for more complex types (structs)
>>>> you want the driver to fill in elem_size?
>>>
>>> I dont like that the type contains the size of the element, and then I
>>> have to provide the size again. (Hungarian notation)
>>>
>>> Instead, I think it is better:
>>>
>>> Defines ONLY this two types for simple types:
>>> V4L2_CTRL_COMPLEX_TYPE_SIGNED_INTEGER and
>>> V4L2_CTRL_COMPLEX_TYPE_UNSIGNED_INTEGER and use elem_size to determine
>>> the size.
>>
>> It sounds great, but it isn't in practice because this will produce awful
>> code like this:
>>
>> switch (type) {
>> case V4L2_CTRL_COMPLEX_TYPE_SIGNED_INTEGER:
>>         switch (elem_size) {
>>         case 1: // it's a u8!
>>                 break;
>>         case 2: // it's a u16!
>>                 break;
>>         }
>> etc.
>> }
> 
> I slightly disagree here. Your proposal will produce this code:
> 
> 
> 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;
> case V4L2_CTRL_TYPE_U32:
> ptr.p_s32[idx] = ctrl->default_value;
> break;
> case V4L2_CTRL_TYPE_U64:
> ptr.p_s64[idx] = ctrl->default_value;
> break;
> case V4L2_CTRL_TYPE_S8:
> ptr.p_s8[idx] = ctrl->default_value;
> break;
> case V4L2_CTRL_TYPE_S16:
> ptr.p_s16[idx] = ctrl->default_value;
> break;
> case V4L2_CTRL_TYPE_S32:
> ptr.p_s32[idx] = ctrl->default_value;
> break;
> case V4L2_CTRL_TYPE_S64:
> ptr.p_s64[idx] = ctrl->default_value;
> break;
> 
> instead of:
> 
> 
> case V4L2_CTRL_COMPLEX_TYPE_SIGNED_INTEGER:
> case V4L2_CTRL_COMPLEX_TYPE_UNSIGNED_INTEGER:
> memcpy(&ptr.p[idx],&ctrl->default_value,ctrl->elem_size)

Well, no. default_value is a 64-bit value that you can't just memcpy to
a u8 (certainly not on a big-endian system). It's basically why I split
it up, otherwise I would have used the same trick instead of writing it
out for every type.

Regards,

	Hans

  reply	other threads:[~2014-02-12 14:09 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-10  8:46 [REVIEWv2 PATCH 00/34] Add support for complex controls, use in solo/go7007 Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 01/34] v4l2-ctrls: increase internal min/max/step/def to 64 bit Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 02/34] v4l2-ctrls: add unit string Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 03/34] v4l2-ctrls: use pr_info/cont instead of printk Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 04/34] videodev2.h: add initial support for complex controls Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 05/34] videodev2.h: add struct v4l2_query_ext_ctrl and VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 06/34] v4l2-ctrls: add support for complex types Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 07/34] v4l2: integrate support for VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 08/34] v4l2-ctrls: create type_ops Hans Verkuil
2014-02-12 10:55   ` Ricardo Ribalda Delgado
2014-02-12 11:36     ` Hans Verkuil
2014-02-12 12:03       ` Ricardo Ribalda Delgado
2014-02-12 12:31         ` Hans Verkuil
2014-02-12 13:03           ` Ricardo Ribalda Delgado
2014-02-10  8:46 ` [REVIEWv2 PATCH 09/34] v4l2-ctrls: rewrite copy routines to operate on union v4l2_ctrl_ptr Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 10/34] v4l2-ctrls: compare values only once Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 11/34] v4l2-ctrls: prepare for matrix support: add cols & rows fields Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 12/34] v4l2-ctrls: replace cur by a union v4l2_ctrl_ptr Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 13/34] v4l2-ctrls: use 'new' to access pointer controls Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 14/34] v4l2-ctrls: prepare for matrix support Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 15/34] v4l2-ctrls: type_ops can handle matrix elements Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 16/34] v4l2-ctrls: add matrix support Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 17/34] v4l2-ctrls: return elem_size instead of strlen Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 18/34] v4l2-ctrl: fix error return of copy_to/from_user Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 19/34] DocBook media: document VIDIOC_QUERY_EXT_CTRL Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 20/34] DocBook media: update VIDIOC_G/S/TRY_EXT_CTRLS Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 21/34] DocBook media: fix coding style in the control example code Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 22/34] DocBook media: update control section Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 23/34] v4l2-controls.txt: update to the new way of accessing controls Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 24/34] v4l2-ctrls/videodev2.h: add u8 and u16 types Hans Verkuil
2014-02-12 10:44   ` Ricardo Ribalda Delgado
2014-02-12 11:20     ` Hans Verkuil
2014-02-12 12:11       ` Ricardo Ribalda Delgado
2014-02-12 12:40         ` Hans Verkuil
2014-02-12 13:13           ` Ricardo Ribalda Delgado
2014-02-12 13:26             ` Hans Verkuil
2014-02-12 13:40               ` Ricardo Ribalda Delgado
2014-02-12 14:05                 ` Hans Verkuil [this message]
2014-02-10  8:46 ` [REVIEWv2 PATCH 25/34] DocBook media: document new u8 and u16 control types Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 26/34] v4l2-ctrls: fix comments Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 27/34] v4l2-ctrls/v4l2-controls.h: add MD controls Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 28/34] DocBook media: document new motion detection controls Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 29/34] v4l2: add a motion detection event Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 30/34] DocBook: document new v4l " Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 31/34] solo6x10: implement the new motion detection controls Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 32/34] solo6x10: implement the motion detection event Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 33/34] solo6x10: fix 'dma from stack' warning Hans Verkuil
2014-02-10  8:46 ` [REVIEWv2 PATCH 34/34] go7007: add motion detection support Hans Verkuil
2014-02-12  7:56   ` [REVIEWv2 PATCH 35/34] DocBook media: clarify how the matrix maps to the grid Hans Verkuil
2014-02-12 11:39 ` [REVIEWv2 PATCH 36/34] v4l2-ctrls: break off loop on first changed element Hans Verkuil
2014-02-16 20:14 ` [REVIEWv2 PATCH 00/34] Add support for complex controls, use in solo/go7007 Sakari Ailus
2014-02-17  9:45   ` 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=52FB7FAE.8000101@cisco.com \
    --to=hansverk@cisco.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=m.chehab@samsung.com \
    --cc=pete@sensoray.com \
    --cc=ricardo.ribalda@gmail.com \
    --cc=s.nawrocki@samsung.com \
    /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