[libcamera-devel,18/31] libcamera: controls: Add a 'size' yaml property

Message ID 20200229164254.23604-19-laurent.pinchart@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: Add support for array controls
Related show

Commit Message

Laurent Pinchart Feb. 29, 2020, 4:42 p.m. UTC
From: Jacopo Mondi <jacopo@jmondi.org>

Add a 'size' property to the control yaml description, to convey the
size constraints of array constrols. The semantics of the property
contents is currently unspecified, but its presence triggers the
generation of an array control (Control<Span<const T>>).

Example:

  - BayerGains:
      type: float
      description: Gains to apply to the four Bayer colour components for white balance
      size: [4]

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/gen-controls.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Kieran Bingham March 5, 2020, 2:53 p.m. UTC | #1
Hi

On 29/02/2020 16:42, Laurent Pinchart wrote:
> From: Jacopo Mondi <jacopo@jmondi.org>
> 
> Add a 'size' property to the control yaml description, to convey the
> size constraints of array constrols. The semantics of the property

/constrols/controls/

> contents is currently unspecified, but its presence triggers the
> generation of an array control (Control<Span<const T>>).
> 
> Example:
> 
>   - BayerGains:
>       type: float
>       description: Gains to apply to the four Bayer colour components for white balance
>       size: [4]
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Will we define dynamic sizes ? Or min/max options?

Presuming that this is 'just' for fixed size compound controls so far,
and there will be more to come on this later:

At some point we may want/need a schema and validator for this.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/libcamera/gen-controls.py | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py
> index 6f020a327827..ff8bda6b16c1 100755
> --- a/src/libcamera/gen-controls.py
> +++ b/src/libcamera/gen-controls.py
> @@ -42,9 +42,14 @@ ${description}
>          name, ctrl = ctrl.popitem()
>          id_name = snake_case(name).upper()
>  
> +        if ctrl.get('size'):
> +            ctrl_type = 'Span<const %s>' % ctrl['type']
> +        else:
> +            ctrl_type = ctrl['type']
> +
>          info = {
>              'name': name,
> -            'type': ctrl['type'],
> +            'type': ctrl_type,
>              'description': format_description(ctrl['description']),
>              'id_name': id_name,
>          }
> @@ -92,9 +97,14 @@ def generate_h(controls):
>  
>          ids.append('\t' + id_name + ' = ' + str(id_value) + ',')
>  
> +        if ctrl.get('size'):
> +            ctrl_type = 'Span<const %s>' % ctrl['type']
> +        else:
> +            ctrl_type = ctrl['type']
> +
>          info = {
>              'name': name,
> -            'type': ctrl['type'],
> +            'type': ctrl_type,
>          }
>  
>          enum = ctrl.get('enum')
>
Laurent Pinchart March 6, 2020, 2:43 p.m. UTC | #2
Hi Kieran,

On Thu, Mar 05, 2020 at 02:53:05PM +0000, Kieran Bingham wrote:
> On 29/02/2020 16:42, Laurent Pinchart wrote:
> > From: Jacopo Mondi <jacopo@jmondi.org>
> > 
> > Add a 'size' property to the control yaml description, to convey the
> > size constraints of array constrols. The semantics of the property
> 
> /constrols/controls/
> 
> > contents is currently unspecified, but its presence triggers the
> > generation of an array control (Control<Span<const T>>).
> > 
> > Example:
> > 
> >   - BayerGains:
> >       type: float
> >       description: Gains to apply to the four Bayer colour components for white balance
> >       size: [4]
> > 
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> Will we define dynamic sizes ? Or min/max options?

Both I believe :-) I can see use cases for [n], [3x3], [4x2xn] or [nxm].

> Presuming that this is 'just' for fixed size compound controls so far,
> and there will be more to come on this later:

The array control support implementation supports dynamic sizes. We'll
have to figure out how to express that properly in yaml, and what to do
with the information, but I don't expect it to affect the ControlValue
or ControlList classes. The information may be added to the Control
class to add dynamic validation (or just query) at some point.

> At some point we may want/need a schema and validator for this.

Yes :-)

> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> > ---
> >  src/libcamera/gen-controls.py | 14 ++++++++++++--
> >  1 file changed, 12 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py
> > index 6f020a327827..ff8bda6b16c1 100755
> > --- a/src/libcamera/gen-controls.py
> > +++ b/src/libcamera/gen-controls.py
> > @@ -42,9 +42,14 @@ ${description}
> >          name, ctrl = ctrl.popitem()
> >          id_name = snake_case(name).upper()
> >  
> > +        if ctrl.get('size'):
> > +            ctrl_type = 'Span<const %s>' % ctrl['type']
> > +        else:
> > +            ctrl_type = ctrl['type']
> > +
> >          info = {
> >              'name': name,
> > -            'type': ctrl['type'],
> > +            'type': ctrl_type,
> >              'description': format_description(ctrl['description']),
> >              'id_name': id_name,
> >          }
> > @@ -92,9 +97,14 @@ def generate_h(controls):
> >  
> >          ids.append('\t' + id_name + ' = ' + str(id_value) + ',')
> >  
> > +        if ctrl.get('size'):
> > +            ctrl_type = 'Span<const %s>' % ctrl['type']
> > +        else:
> > +            ctrl_type = ctrl['type']
> > +
> >          info = {
> >              'name': name,
> > -            'type': ctrl['type'],
> > +            'type': ctrl_type,
> >          }
> >  
> >          enum = ctrl.get('enum')

Patch

diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py
index 6f020a327827..ff8bda6b16c1 100755
--- a/src/libcamera/gen-controls.py
+++ b/src/libcamera/gen-controls.py
@@ -42,9 +42,14 @@  ${description}
         name, ctrl = ctrl.popitem()
         id_name = snake_case(name).upper()
 
+        if ctrl.get('size'):
+            ctrl_type = 'Span<const %s>' % ctrl['type']
+        else:
+            ctrl_type = ctrl['type']
+
         info = {
             'name': name,
-            'type': ctrl['type'],
+            'type': ctrl_type,
             'description': format_description(ctrl['description']),
             'id_name': id_name,
         }
@@ -92,9 +97,14 @@  def generate_h(controls):
 
         ids.append('\t' + id_name + ' = ' + str(id_value) + ',')
 
+        if ctrl.get('size'):
+            ctrl_type = 'Span<const %s>' % ctrl['type']
+        else:
+            ctrl_type = ctrl['type']
+
         info = {
             'name': name,
-            'type': ctrl['type'],
+            'type': ctrl_type,
         }
 
         enum = ctrl.get('enum')