[v2,0/3] gstreamer: Generate controls from control_ids_*.yaml files
mbox series

Message ID 20240813124722.22425-1-jaslo@ziska.de
Headers show
Series
  • gstreamer: Generate controls from control_ids_*.yaml files
Related show

Message

Jaslo Ziska Aug. 13, 2024, 12:25 p.m. UTC
Hi everyone,

this is the second version of the patch set to implement gstreamer controls
from the yaml files.
This now depends on "[PATCH 00/10] libcamera: Improve code generation for
controls" for the code generation.

The following things changed:

The (old) third commit fixing a typo has been removed as it is already merged.

The first commit is new: it removes the auto-focus-mode property from the
device provider where it has been added on accident.

The commit message has been updated in the second commit.

The third commit, which adds the code that generates the gstreamer controls,
now makes use of jinja2 and the new controls.py file. As a consequence the
whole code generation has been redone.

There are also some new features:

It is now possible to read the metadata returned by requests from the gstreamer
properties. This is done using a new function readMetadata() which reads the
ControlList in requestCompleted().

Before a control is set it is now checked whether this control is actually
supported by the camera. This is done by checking the cameras ControlInfoMap.

The Rectangle type is now supported.

Some checks were added to make sure the arrays passed to the element have the
correct length.

Best regards,

Jaslo

Jaslo Ziska (3):
  gstreamer: Remove auto-focus-mode property from device provider
  gstreamer: Remove auto-focus-mode property from libcamerasrc
  gstreamer: Generate controls from control_ids_*.yaml files

 src/gstreamer/gstlibcamera-controls.cpp.in | 296 +++++++++++++++++++++
 src/gstreamer/gstlibcamera-controls.h      |  43 +++
 src/gstreamer/gstlibcameraprovider.cpp     |  15 --
 src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
 src/gstreamer/meson.build                  |  10 +
 utils/codegen/controls.py                  |   8 +
 utils/codegen/gen-gst-controls.py          | 151 +++++++++++
 utils/codegen/meson.build                  |   1 +
 8 files changed, 528 insertions(+), 46 deletions(-)
 create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
 create mode 100644 src/gstreamer/gstlibcamera-controls.h
 create mode 100755 utils/codegen/gen-gst-controls.py

--
2.46.0

Comments

Laurent Pinchart Sept. 26, 2024, 10:04 p.m. UTC | #1
Hi Jaslo,

I think this series is close to being ready, and I would be very happy
to merge this much awaited feature. Do you plan to send a v3 ?

On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
> Hi everyone,
> 
> this is the second version of the patch set to implement gstreamer controls
> from the yaml files.
> This now depends on "[PATCH 00/10] libcamera: Improve code generation for
> controls" for the code generation.
> 
> The following things changed:
> 
> The (old) third commit fixing a typo has been removed as it is already merged.
> 
> The first commit is new: it removes the auto-focus-mode property from the
> device provider where it has been added on accident.
> 
> The commit message has been updated in the second commit.
> 
> The third commit, which adds the code that generates the gstreamer controls,
> now makes use of jinja2 and the new controls.py file. As a consequence the
> whole code generation has been redone.
> 
> There are also some new features:
> 
> It is now possible to read the metadata returned by requests from the gstreamer
> properties. This is done using a new function readMetadata() which reads the
> ControlList in requestCompleted().
> 
> Before a control is set it is now checked whether this control is actually
> supported by the camera. This is done by checking the cameras ControlInfoMap.
> 
> The Rectangle type is now supported.
> 
> Some checks were added to make sure the arrays passed to the element have the
> correct length.
> 
> Best regards,
> 
> Jaslo
> 
> Jaslo Ziska (3):
>   gstreamer: Remove auto-focus-mode property from device provider
>   gstreamer: Remove auto-focus-mode property from libcamerasrc
>   gstreamer: Generate controls from control_ids_*.yaml files
> 
>  src/gstreamer/gstlibcamera-controls.cpp.in | 296 +++++++++++++++++++++
>  src/gstreamer/gstlibcamera-controls.h      |  43 +++
>  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
>  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
>  src/gstreamer/meson.build                  |  10 +
>  utils/codegen/controls.py                  |   8 +
>  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
>  utils/codegen/meson.build                  |   1 +
>  8 files changed, 528 insertions(+), 46 deletions(-)
>  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
>  create mode 100644 src/gstreamer/gstlibcamera-controls.h
>  create mode 100755 utils/codegen/gen-gst-controls.py
Jaslo Ziska Sept. 30, 2024, 9:11 a.m. UTC | #2
Hi Laurent,

Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> Hi Jaslo,
>
> I think this series is close to being ready, and I would be very 
> happy
> to merge this much awaited feature. Do you plan to send a v3 ?

Yes, I very much plan on continuing to work on this. I was a 
pretty busy the past month but I should have more time later in 
October.

Unfortunately, I don't think that the series is quite ready. 
Nicolas had requested some bigger changes in v1 which still need 
to be discussed and implemented and I also want to add the 
readable/writeable and minimum/maximum properties to the yaml 
files (although this could also be done separately after merging).

Best regards,

Jaslo

> On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
>> Hi everyone,
>> 
>> this is the second version of the patch set to implement 
>> gstreamer controls
>> from the yaml files.
>> This now depends on "[PATCH 00/10] libcamera: Improve code 
>> generation for
>> controls" for the code generation.
>> 
>> The following things changed:
>> 
>> The (old) third commit fixing a typo has been removed as it is 
>> already merged.
>> 
>> The first commit is new: it removes the auto-focus-mode 
>> property from the
>> device provider where it has been added on accident.
>> 
>> The commit message has been updated in the second commit.
>> 
>> The third commit, which adds the code that generates the 
>> gstreamer controls,
>> now makes use of jinja2 and the new controls.py file. As a 
>> consequence the
>> whole code generation has been redone.
>> 
>> There are also some new features:
>> 
>> It is now possible to read the metadata returned by requests 
>> from the gstreamer
>> properties. This is done using a new function readMetadata() 
>> which reads the
>> ControlList in requestCompleted().
>> 
>> Before a control is set it is now checked whether this control 
>> is actually
>> supported by the camera. This is done by checking the cameras 
>> ControlInfoMap.
>> 
>> The Rectangle type is now supported.
>> 
>> Some checks were added to make sure the arrays passed to the 
>> element have the
>> correct length.
>> 
>> Best regards,
>> 
>> Jaslo
>> 
>> Jaslo Ziska (3):
>>   gstreamer: Remove auto-focus-mode property from device 
>>   provider
>>   gstreamer: Remove auto-focus-mode property from libcamerasrc
>>   gstreamer: Generate controls from control_ids_*.yaml files
>> 
>>  src/gstreamer/gstlibcamera-controls.cpp.in | 296 
>>  +++++++++++++++++++++
>>  src/gstreamer/gstlibcamera-controls.h      |  43 +++
>>  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
>>  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
>>  src/gstreamer/meson.build                  |  10 +
>>  utils/codegen/controls.py                  |   8 +
>>  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
>>  utils/codegen/meson.build                  |   1 +
>>  8 files changed, 528 insertions(+), 46 deletions(-)
>>  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
>>  create mode 100644 src/gstreamer/gstlibcamera-controls.h
>>  create mode 100755 utils/codegen/gen-gst-controls.py
Nicolas Dufresne Sept. 30, 2024, 2:42 p.m. UTC | #3
Hi,

Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a écrit :
> Hi Laurent,
> 
> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> > Hi Jaslo,
> > 
> > I think this series is close to being ready, and I would be very 
> > happy
> > to merge this much awaited feature. Do you plan to send a v3 ?
> 
> Yes, I very much plan on continuing to work on this. I was a 
> pretty busy the past month but I should have more time later in 
> October.
> 
> Unfortunately, I don't think that the series is quite ready. 
> Nicolas had requested some bigger changes in v1 which still need 
> to be discussed and implemented and I also want to add the 
> readable/writeable and minimum/maximum properties to the yaml 
> files (although this could also be done separately after merging).

My proposal is to program a subset to be exposed as properties, the one that are
obviously usable and that the documentation make sense. I think you did a great
job on the generator and adding features later to support controls that have
more complex semantic is better then trying to support them all in one go today.

If the selection is all rw, the marking of that can wait. Min/max would be my
preference to have, but as we are breaking the API anyway still, we can also do
small break in the gstreamer element later too (as long as its well reported in
the release notes).

Nicolas 

> 
> Best regards,
> 
> Jaslo
> 
> > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
> > > Hi everyone,
> > > 
> > > this is the second version of the patch set to implement 
> > > gstreamer controls
> > > from the yaml files.
> > > This now depends on "[PATCH 00/10] libcamera: Improve code 
> > > generation for
> > > controls" for the code generation.
> > > 
> > > The following things changed:
> > > 
> > > The (old) third commit fixing a typo has been removed as it is 
> > > already merged.
> > > 
> > > The first commit is new: it removes the auto-focus-mode 
> > > property from the
> > > device provider where it has been added on accident.
> > > 
> > > The commit message has been updated in the second commit.
> > > 
> > > The third commit, which adds the code that generates the 
> > > gstreamer controls,
> > > now makes use of jinja2 and the new controls.py file. As a 
> > > consequence the
> > > whole code generation has been redone.
> > > 
> > > There are also some new features:
> > > 
> > > It is now possible to read the metadata returned by requests 
> > > from the gstreamer
> > > properties. This is done using a new function readMetadata() 
> > > which reads the
> > > ControlList in requestCompleted().
> > > 
> > > Before a control is set it is now checked whether this control 
> > > is actually
> > > supported by the camera. This is done by checking the cameras 
> > > ControlInfoMap.
> > > 
> > > The Rectangle type is now supported.
> > > 
> > > Some checks were added to make sure the arrays passed to the 
> > > element have the
> > > correct length.
> > > 
> > > Best regards,
> > > 
> > > Jaslo
> > > 
> > > Jaslo Ziska (3):
> > >   gstreamer: Remove auto-focus-mode property from device 
> > >   provider
> > >   gstreamer: Remove auto-focus-mode property from libcamerasrc
> > >   gstreamer: Generate controls from control_ids_*.yaml files
> > > 
> > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 
> > >  +++++++++++++++++++++
> > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
> > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
> > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
> > >  src/gstreamer/meson.build                  |  10 +
> > >  utils/codegen/controls.py                  |   8 +
> > >  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
> > >  utils/codegen/meson.build                  |   1 +
> > >  8 files changed, 528 insertions(+), 46 deletions(-)
> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.h
> > >  create mode 100755 utils/codegen/gen-gst-controls.py
Jaslo Ziska Oct. 2, 2024, 10:04 a.m. UTC | #4
Hi Nicolas,

Nicolas Dufresne <nicolas@ndufresne.ca> writes:
> Hi,
>
> Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a écrit :
>> Hi Laurent,
>> 
>> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
>> > Hi Jaslo,
>> > 
>> > I think this series is close to being ready, and I would be 
>> > very 
>> > happy
>> > to merge this much awaited feature. Do you plan to send a v3 
>> > ?
>> 
>> Yes, I very much plan on continuing to work on this. I was a 
>> pretty busy the past month but I should have more time later in 
>> October.
>> 
>> Unfortunately, I don't think that the series is quite ready. 
>> Nicolas had requested some bigger changes in v1 which still 
>> need 
>> to be discussed and implemented and I also want to add the 
>> readable/writeable and minimum/maximum properties to the yaml 
>> files (although this could also be done separately after 
>> merging).
>
> My proposal is to program a subset to be exposed as properties, 
> the one that are
> obviously usable and that the documentation make sense. I think 
> you did a great
> job on the generator and adding features later to support 
> controls that have
> more complex semantic is better then trying to support them all 
> in one go today.

Sounds good. Where would you suggest the list of controls to be 
exposed should be? Maybe just a plain list in the Python generator 
file?

> If the selection is all rw, the marking of that can wait. 
> Min/max would be my
> preference to have, but as we are breaking the API anyway still, 
> we can also do
> small break in the gstreamer element later too (as long as its 
> well reported in
> the release notes).

You also suggested a GStreamer property that returns a 
GstStructure which lists all the actually present controls for the 
camera and their actual limits. Do you still want this implemented 
and if so how do you imagine this structure to be laid out?

Best regards,

Jaslo

>
> Nicolas 
>
>> 
>> Best regards,
>> 
>> Jaslo
>> 
>> > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
>> > > Hi everyone,
>> > > 
>> > > this is the second version of the patch set to implement 
>> > > gstreamer controls
>> > > from the yaml files.
>> > > This now depends on "[PATCH 00/10] libcamera: Improve code 
>> > > generation for
>> > > controls" for the code generation.
>> > > 
>> > > The following things changed:
>> > > 
>> > > The (old) third commit fixing a typo has been removed as it 
>> > > is 
>> > > already merged.
>> > > 
>> > > The first commit is new: it removes the auto-focus-mode 
>> > > property from the
>> > > device provider where it has been added on accident.
>> > > 
>> > > The commit message has been updated in the second commit.
>> > > 
>> > > The third commit, which adds the code that generates the 
>> > > gstreamer controls,
>> > > now makes use of jinja2 and the new controls.py file. As a 
>> > > consequence the
>> > > whole code generation has been redone.
>> > > 
>> > > There are also some new features:
>> > > 
>> > > It is now possible to read the metadata returned by 
>> > > requests 
>> > > from the gstreamer
>> > > properties. This is done using a new function 
>> > > readMetadata() 
>> > > which reads the
>> > > ControlList in requestCompleted().
>> > > 
>> > > Before a control is set it is now checked whether this 
>> > > control 
>> > > is actually
>> > > supported by the camera. This is done by checking the 
>> > > cameras 
>> > > ControlInfoMap.
>> > > 
>> > > The Rectangle type is now supported.
>> > > 
>> > > Some checks were added to make sure the arrays passed to 
>> > > the 
>> > > element have the
>> > > correct length.
>> > > 
>> > > Best regards,
>> > > 
>> > > Jaslo
>> > > 
>> > > Jaslo Ziska (3):
>> > >   gstreamer: Remove auto-focus-mode property from device 
>> > >   provider
>> > >   gstreamer: Remove auto-focus-mode property from 
>> > >   libcamerasrc
>> > >   gstreamer: Generate controls from control_ids_*.yaml 
>> > >   files
>> > > 
>> > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 
>> > >  +++++++++++++++++++++
>> > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
>> > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
>> > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
>> > >  src/gstreamer/meson.build                  |  10 +
>> > >  utils/codegen/controls.py                  |   8 +
>> > >  utils/codegen/gen-gst-controls.py          | 151 
>> > >  +++++++++++
>> > >  utils/codegen/meson.build                  |   1 +
>> > >  8 files changed, 528 insertions(+), 46 deletions(-)
>> > >  create mode 100644 
>> > >  src/gstreamer/gstlibcamera-controls.cpp.in
>> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.h
>> > >  create mode 100755 utils/codegen/gen-gst-controls.py
Laurent Pinchart Oct. 2, 2024, 11:22 a.m. UTC | #5
On Wed, Oct 02, 2024 at 12:04:08PM +0200, Jaslo Ziska wrote:
> Nicolas Dufresne <nicolas@ndufresne.ca> writes:
> > Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a écrit :
> >> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> >> > Hi Jaslo,
> >> > 
> >> > I think this series is close to being ready, and I would be very happy
> >> > to merge this much awaited feature. Do you plan to send a v3 ?
> >> 
> >> Yes, I very much plan on continuing to work on this. I was a 
> >> pretty busy the past month but I should have more time later in 
> >> October.
> >> 
> >> Unfortunately, I don't think that the series is quite ready. 
> >> Nicolas had requested some bigger changes in v1 which still need 
> >> to be discussed and implemented and I also want to add the 
> >> readable/writeable and minimum/maximum properties to the yaml 
> >> files (although this could also be done separately after 
> >> merging).
> >
> > My proposal is to program a subset to be exposed as properties, the one that are
> > obviously usable and that the documentation make sense. I think you did a great
> > job on the generator and adding features later to support controls that have
> > more complex semantic is better then trying to support them all 
> > in one go today.
> 
> Sounds good. Where would you suggest the list of controls to be 
> exposed should be? Maybe just a plain list in the Python generator 
> file?

The other option is to store the information in the yaml files. I don't
have a very strong opinion, the yaml files have the advantage that all
the data related to controls will be in a single place, but the
generator script has the advantage of keeping all gstreamer-related data
close to the gstreamer element. That may be useful when it will be time
to move libcamerasrc from the libcamera repository to the gstreamer
repository (if we ever do so). On the other hand, tha yaml files are not
installed, so there would still be issues.

Complete brainstorming mode, I'm wondering if at some point in the
future it would make sense to handle the gstreamer controls in a more
dynamic fashion by querying libcamera at runtime instead of using code
generation. This doesn't invalidate the approach you've taken here, I
think code generation is good for the time being.

> > If the selection is all rw, the marking of that can wait. Min/max would be my
> > preference to have, but as we are breaking the API anyway still, we can also do
> > small break in the gstreamer element later too (as long as its well reported in
> > the release notes).
> 
> You also suggested a GStreamer property that returns a 
> GstStructure which lists all the actually present controls for the 
> camera and their actual limits. Do you still want this implemented 
> and if so how do you imagine this structure to be laid out?
> 
> >> > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
> >> > > Hi everyone,
> >> > > 
> >> > > this is the second version of the patch set to implement gstreamer controls
> >> > > from the yaml files.
> >> > > This now depends on "[PATCH 00/10] libcamera: Improve code generation for
> >> > > controls" for the code generation.
> >> > > 
> >> > > The following things changed:
> >> > > 
> >> > > The (old) third commit fixing a typo has been removed as it is already merged.
> >> > > 
> >> > > The first commit is new: it removes the auto-focus-mode property from the
> >> > > device provider where it has been added on accident.
> >> > > 
> >> > > The commit message has been updated in the second commit.
> >> > > 
> >> > > The third commit, which adds the code that generates the gstreamer controls,
> >> > > now makes use of jinja2 and the new controls.py file. As a consequence the
> >> > > whole code generation has been redone.
> >> > > 
> >> > > There are also some new features:
> >> > > 
> >> > > It is now possible to read the metadata returned by requests from the gstreamer
> >> > > properties. This is done using a new function readMetadata() which reads the
> >> > > ControlList in requestCompleted().
> >> > > 
> >> > > Before a control is set it is now checked whether this control is actually
> >> > > supported by the camera. This is done by checking the cameras ControlInfoMap.
> >> > > 
> >> > > The Rectangle type is now supported.
> >> > > 
> >> > > Some checks were added to make sure the arrays passed to the element have the
> >> > > correct length.
> >> > > 
> >> > > Best regards,
> >> > > 
> >> > > Jaslo
> >> > > 
> >> > > Jaslo Ziska (3):
> >> > >   gstreamer: Remove auto-focus-mode property from device provider
> >> > >   gstreamer: Remove auto-focus-mode property from libcamerasrc
> >> > >   gstreamer: Generate controls from control_ids_*.yaml files
> >> > > 
> >> > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 +++++++++++++++++++++
> >> > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
> >> > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
> >> > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
> >> > >  src/gstreamer/meson.build                  |  10 +
> >> > >  utils/codegen/controls.py                  |   8 +
> >> > >  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
> >> > >  utils/codegen/meson.build                  |   1 +
> >> > >  8 files changed, 528 insertions(+), 46 deletions(-)
> >> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
> >> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.h
> >> > >  create mode 100755 utils/codegen/gen-gst-controls.py
Jaslo Ziska Oct. 2, 2024, 5:27 p.m. UTC | #6
Hi Laurent,

Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> On Wed, Oct 02, 2024 at 12:04:08PM +0200, Jaslo Ziska wrote:
>> Nicolas Dufresne <nicolas@ndufresne.ca> writes:
>> > Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a 
>> > écrit :
>> >> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
>> >> > Hi Jaslo,
>> >> > 
>> >> > I think this series is close to being ready, and I would 
>> >> > be very happy
>> >> > to merge this much awaited feature. Do you plan to send a 
>> >> > v3 ?
>> >> 
>> >> Yes, I very much plan on continuing to work on this. I was a 
>> >> pretty busy the past month but I should have more time later 
>> >> in 
>> >> October.
>> >> 
>> >> Unfortunately, I don't think that the series is quite ready. 
>> >> Nicolas had requested some bigger changes in v1 which still 
>> >> need 
>> >> to be discussed and implemented and I also want to add the 
>> >> readable/writeable and minimum/maximum properties to the 
>> >> yaml 
>> >> files (although this could also be done separately after 
>> >> merging).
>> >
>> > My proposal is to program a subset to be exposed as 
>> > properties, the one that are
>> > obviously usable and that the documentation make sense. I 
>> > think you did a great
>> > job on the generator and adding features later to support 
>> > controls that have
>> > more complex semantic is better then trying to support them 
>> > all 
>> > in one go today.
>> 
>> Sounds good. Where would you suggest the list of controls to be 
>> exposed should be? Maybe just a plain list in the Python 
>> generator 
>> file?
>
> The other option is to store the information in the yaml files. 
> I don't
> have a very strong opinion, the yaml files have the advantage 
> that all
> the data related to controls will be in a single place, but the
> generator script has the advantage of keeping all 
> gstreamer-related data
> close to the gstreamer element. That may be useful when it will 
> be time
> to move libcamerasrc from the libcamera repository to the 
> gstreamer
> repository (if we ever do so). On the other hand, tha yaml files 
> are not
> installed, so there would still be issues.

Putting it inside the yaml would be an option, but I don't know 
whether having GStreamer specific stuff there is so good. But I 
think this will likely change anyway.

> Complete brainstorming mode, I'm wondering if at some point in 
> the
> future it would make sense to handle the gstreamer controls in a 
> more
> dynamic fashion by querying libcamera at runtime instead of 
> using code
> generation. This doesn't invalidate the approach you've taken 
> here, I
> think code generation is good for the time being.

If you mean that the GStreamer properties should get added later 
at runtime then this is unfortunately not possible. This is 
because the GStreamer controls are GObject properties and those 
need to be installed when the GObject object class is initialized. 
And because this happens before the GStreamer element is 
constructed (and therefore also before libcamera gets involved) it 
is not possible to know which properties are present and with 
which ranges.

The one thing that Nicolas suggested is adding a special property 
to the GStreamer element which can then return the available 
properties and their ranges at runtime. That would be the 
GstStructure which I was asking about.

Best regards,

Jaslo

>> > If the selection is all rw, the marking of that can wait. 
>> > Min/max would be my
>> > preference to have, but as we are breaking the API anyway 
>> > still, we can also do
>> > small break in the gstreamer element later too (as long as 
>> > its well reported in
>> > the release notes).
>> 
>> You also suggested a GStreamer property that returns a 
>> GstStructure which lists all the actually present controls for 
>> the 
>> camera and their actual limits. Do you still want this 
>> implemented 
>> and if so how do you imagine this structure to be laid out?
>> 
>> >> > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska 
>> >> > wrote:
>> >> > > Hi everyone,
>> >> > > 
>> >> > > this is the second version of the patch set to implement 
>> >> > > gstreamer controls
>> >> > > from the yaml files.
>> >> > > This now depends on "[PATCH 00/10] libcamera: Improve 
>> >> > > code generation for
>> >> > > controls" for the code generation.
>> >> > > 
>> >> > > The following things changed:
>> >> > > 
>> >> > > The (old) third commit fixing a typo has been removed as 
>> >> > > it is already merged.
>> >> > > 
>> >> > > The first commit is new: it removes the auto-focus-mode 
>> >> > > property from the
>> >> > > device provider where it has been added on accident.
>> >> > > 
>> >> > > The commit message has been updated in the second 
>> >> > > commit.
>> >> > > 
>> >> > > The third commit, which adds the code that generates the 
>> >> > > gstreamer controls,
>> >> > > now makes use of jinja2 and the new controls.py file. As 
>> >> > > a consequence the
>> >> > > whole code generation has been redone.
>> >> > > 
>> >> > > There are also some new features:
>> >> > > 
>> >> > > It is now possible to read the metadata returned by 
>> >> > > requests from the gstreamer
>> >> > > properties. This is done using a new function 
>> >> > > readMetadata() which reads the
>> >> > > ControlList in requestCompleted().
>> >> > > 
>> >> > > Before a control is set it is now checked whether this 
>> >> > > control is actually
>> >> > > supported by the camera. This is done by checking the 
>> >> > > cameras ControlInfoMap.
>> >> > > 
>> >> > > The Rectangle type is now supported.
>> >> > > 
>> >> > > Some checks were added to make sure the arrays passed to 
>> >> > > the element have the
>> >> > > correct length.
>> >> > > 
>> >> > > Best regards,
>> >> > > 
>> >> > > Jaslo
>> >> > > 
>> >> > > Jaslo Ziska (3):
>> >> > >   gstreamer: Remove auto-focus-mode property from device 
>> >> > >   provider
>> >> > >   gstreamer: Remove auto-focus-mode property from 
>> >> > >   libcamerasrc
>> >> > >   gstreamer: Generate controls from control_ids_*.yaml 
>> >> > >   files
>> >> > > 
>> >> > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 
>> >> > >  +++++++++++++++++++++
>> >> > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
>> >> > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
>> >> > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
>> >> > >  src/gstreamer/meson.build                  |  10 +
>> >> > >  utils/codegen/controls.py                  |   8 +
>> >> > >  utils/codegen/gen-gst-controls.py          | 151 
>> >> > >  +++++++++++
>> >> > >  utils/codegen/meson.build                  |   1 +
>> >> > >  8 files changed, 528 insertions(+), 46 deletions(-)
>> >> > >  create mode 100644 
>> >> > >  src/gstreamer/gstlibcamera-controls.cpp.in
>> >> > >  create mode 100644 
>> >> > >  src/gstreamer/gstlibcamera-controls.h
>> >> > >  create mode 100755 utils/codegen/gen-gst-controls.py
Laurent Pinchart Oct. 2, 2024, 8:22 p.m. UTC | #7
On Wed, Oct 02, 2024 at 07:27:34PM +0200, Jaslo Ziska wrote:
> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> > On Wed, Oct 02, 2024 at 12:04:08PM +0200, Jaslo Ziska wrote:
> >> Nicolas Dufresne <nicolas@ndufresne.ca> writes:
> >> > Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a écrit :
> >> >> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> >> >> > Hi Jaslo,
> >> >> > 
> >> >> > I think this series is close to being ready, and I would be very happy
> >> >> > to merge this much awaited feature. Do you plan to send a v3 ?
> >> >> 
> >> >> Yes, I very much plan on continuing to work on this. I was a 
> >> >> pretty busy the past month but I should have more time later in 
> >> >> October.
> >> >> 
> >> >> Unfortunately, I don't think that the series is quite ready. 
> >> >> Nicolas had requested some bigger changes in v1 which still need 
> >> >> to be discussed and implemented and I also want to add the 
> >> >> readable/writeable and minimum/maximum properties to the  yaml 
> >> >> files (although this could also be done separately after 
> >> >> merging).
> >> >
> >> > My proposal is to program a subset to be exposed as 
> >> > properties, the one that are
> >> > obviously usable and that the documentation make sense. I 
> >> > think you did a great
> >> > job on the generator and adding features later to support 
> >> > controls that have
> >> > more complex semantic is better then trying to support them all 
> >> > in one go today.
> >> 
> >> Sounds good. Where would you suggest the list of controls to be 
> >> exposed should be? Maybe just a plain list in the Python generator 
> >> file?
> >
> > The other option is to store the information in the yaml files. I don't
> > have a very strong opinion, the yaml files have the advantage that all
> > the data related to controls will be in a single place, but the
> > generator script has the advantage of keeping all gstreamer-related data
> > close to the gstreamer element. That may be useful when it will be time
> > to move libcamerasrc from the libcamera repository to the gstreamer
> > repository (if we ever do so). On the other hand, tha yaml files are not
> > installed, so there would still be issues.
> 
> Putting it inside the yaml would be an option, but I don't know 
> whether having GStreamer specific stuff there is so good. But I 
> think this will likely change anyway.
> 
> > Complete brainstorming mode, I'm wondering if at some point in the
> > future it would make sense to handle the gstreamer controls in a more
> > dynamic fashion by querying libcamera at runtime instead of using code
> > generation. This doesn't invalidate the approach you've taken here, I
> > think code generation is good for the time being.
> 
> If you mean that the GStreamer properties should get added later 
> at runtime then this is unfortunately not possible. This is 
> because the GStreamer controls are GObject properties and those 
> need to be installed when the GObject object class is initialized. 
> And because this happens before the GStreamer element is 
> constructed (and therefore also before libcamera gets involved) it 
> is not possible to know which properties are present and with 
> which ranges.

You can get the list of all the controls that libcamera supports from
libcamera::controls::controls. It's a global ControlIdMap variable, a
map from control numerical ids to ControlId instances. The ControlId
class gives you the control numerical id, its name, type, number of
elements if it's an array, and enumerators. We're adding the control
namespace as well, and could add additional information if needed. We
don't need to go this way though.

> The one thing that Nicolas suggested is adding a special property 
> to the GStreamer element which can then return the available 
> properties and their ranges at runtime. That would be the 
> GstStructure which I was asking about.
> 
> >> > If the selection is all rw, the marking of that can wait. 
> >> > Min/max would be my
> >> > preference to have, but as we are breaking the API anyway 
> >> > still, we can also do
> >> > small break in the gstreamer element later too (as long as 
> >> > its well reported in
> >> > the release notes).
> >> 
> >> You also suggested a GStreamer property that returns a 
> >> GstStructure which lists all the actually present controls for 
> >> the 
> >> camera and their actual limits. Do you still want this 
> >> implemented 
> >> and if so how do you imagine this structure to be laid out?
> >> 
> >> >> > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska 
> >> >> > wrote:
> >> >> > > Hi everyone,
> >> >> > > 
> >> >> > > this is the second version of the patch set to implement 
> >> >> > > gstreamer controls
> >> >> > > from the yaml files.
> >> >> > > This now depends on "[PATCH 00/10] libcamera: Improve 
> >> >> > > code generation for
> >> >> > > controls" for the code generation.
> >> >> > > 
> >> >> > > The following things changed:
> >> >> > > 
> >> >> > > The (old) third commit fixing a typo has been removed as 
> >> >> > > it is already merged.
> >> >> > > 
> >> >> > > The first commit is new: it removes the auto-focus-mode 
> >> >> > > property from the
> >> >> > > device provider where it has been added on accident.
> >> >> > > 
> >> >> > > The commit message has been updated in the second 
> >> >> > > commit.
> >> >> > > 
> >> >> > > The third commit, which adds the code that generates the 
> >> >> > > gstreamer controls,
> >> >> > > now makes use of jinja2 and the new controls.py file. As 
> >> >> > > a consequence the
> >> >> > > whole code generation has been redone.
> >> >> > > 
> >> >> > > There are also some new features:
> >> >> > > 
> >> >> > > It is now possible to read the metadata returned by 
> >> >> > > requests from the gstreamer
> >> >> > > properties. This is done using a new function 
> >> >> > > readMetadata() which reads the
> >> >> > > ControlList in requestCompleted().
> >> >> > > 
> >> >> > > Before a control is set it is now checked whether this 
> >> >> > > control is actually
> >> >> > > supported by the camera. This is done by checking the 
> >> >> > > cameras ControlInfoMap.
> >> >> > > 
> >> >> > > The Rectangle type is now supported.
> >> >> > > 
> >> >> > > Some checks were added to make sure the arrays passed to 
> >> >> > > the element have the
> >> >> > > correct length.
> >> >> > > 
> >> >> > > Best regards,
> >> >> > > 
> >> >> > > Jaslo
> >> >> > > 
> >> >> > > Jaslo Ziska (3):
> >> >> > >   gstreamer: Remove auto-focus-mode property from device provider
> >> >> > >   gstreamer: Remove auto-focus-mode property from libcamerasrc
> >> >> > >   gstreamer: Generate controls from control_ids_*.yaml files
> >> >> > > 
> >> >> > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 +++++++++++++++++++++
> >> >> > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
> >> >> > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
> >> >> > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
> >> >> > >  src/gstreamer/meson.build                  |  10 +
> >> >> > >  utils/codegen/controls.py                  |   8 +
> >> >> > >  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
> >> >> > >  utils/codegen/meson.build                  |   1 +
> >> >> > >  8 files changed, 528 insertions(+), 46 deletions(-)
> >> >> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
> >> >> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.h
> >> >> > >  create mode 100755 utils/codegen/gen-gst-controls.py
Jaslo Ziska Oct. 3, 2024, 10:18 a.m. UTC | #8
Hi Laurent,

Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> On Wed, Oct 02, 2024 at 07:27:34PM +0200, Jaslo Ziska wrote:
>> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
>> > On Wed, Oct 02, 2024 at 12:04:08PM +0200, Jaslo Ziska wrote:
>> >> Nicolas Dufresne <nicolas@ndufresne.ca> writes:
>> >> > Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a 
>> >> > écrit :
>> >> >> Laurent Pinchart <laurent.pinchart@ideasonboard.com> 
>> >> >> writes:
>> >> >> > Hi Jaslo,
>> >> >> > 
>> >> >> > I think this series is close to being ready, and I 
>> >> >> > would be very happy
>> >> >> > to merge this much awaited feature. Do you plan to send 
>> >> >> > a v3 ?
>> >> >> 
>> >> >> Yes, I very much plan on continuing to work on this. I 
>> >> >> was a 
>> >> >> pretty busy the past month but I should have more time 
>> >> >> later in 
>> >> >> October.
>> >> >> 
>> >> >> Unfortunately, I don't think that the series is quite 
>> >> >> ready. 
>> >> >> Nicolas had requested some bigger changes in v1 which 
>> >> >> still need 
>> >> >> to be discussed and implemented and I also want to add 
>> >> >> the 
>> >> >> readable/writeable and minimum/maximum properties to the 
>> >> >> yaml 
>> >> >> files (although this could also be done separately after 
>> >> >> merging).
>> >> >
>> >> > My proposal is to program a subset to be exposed as 
>> >> > properties, the one that are
>> >> > obviously usable and that the documentation make sense. I 
>> >> > think you did a great
>> >> > job on the generator and adding features later to support 
>> >> > controls that have
>> >> > more complex semantic is better then trying to support 
>> >> > them all 
>> >> > in one go today.
>> >> 
>> >> Sounds good. Where would you suggest the list of controls to 
>> >> be 
>> >> exposed should be? Maybe just a plain list in the Python 
>> >> generator 
>> >> file?
>> >
>> > The other option is to store the information in the yaml 
>> > files. I don't
>> > have a very strong opinion, the yaml files have the advantage 
>> > that all
>> > the data related to controls will be in a single place, but 
>> > the
>> > generator script has the advantage of keeping all 
>> > gstreamer-related data
>> > close to the gstreamer element. That may be useful when it 
>> > will be time
>> > to move libcamerasrc from the libcamera repository to the 
>> > gstreamer
>> > repository (if we ever do so). On the other hand, tha yaml 
>> > files are not
>> > installed, so there would still be issues.
>> 
>> Putting it inside the yaml would be an option, but I don't know 
>> whether having GStreamer specific stuff there is so good. But I 
>> think this will likely change anyway.
>> 
>> > Complete brainstorming mode, I'm wondering if at some point 
>> > in the
>> > future it would make sense to handle the gstreamer controls 
>> > in a more
>> > dynamic fashion by querying libcamera at runtime instead of 
>> > using code
>> > generation. This doesn't invalidate the approach you've taken 
>> > here, I
>> > think code generation is good for the time being.
>> 
>> If you mean that the GStreamer properties should get added 
>> later 
>> at runtime then this is unfortunately not possible. This is 
>> because the GStreamer controls are GObject properties and those 
>> need to be installed when the GObject object class is 
>> initialized. 
>> And because this happens before the GStreamer element is 
>> constructed (and therefore also before libcamera gets involved) 
>> it 
>> is not possible to know which properties are present and with 
>> which ranges.
>
> You can get the list of all the controls that libcamera supports 
> from
> libcamera::controls::controls. It's a global ControlIdMap 
> variable, a
> map from control numerical ids to ControlId instances. The 
> ControlId
> class gives you the control numerical id, its name, type, number 
> of
> elements if it's an array, and enumerators. We're adding the 
> control
> namespace as well, and could add additional information if 
> needed. We
> don't need to go this way though.

Ah yes, I think that would work too, I never thought about it that 
way. This still would not help with the actually available 
controls for the camera unfortunately.

I don't know which way would be the proper or better way to do it, 
both ways have their pros and cons.

Using the yaml files and the code generator has more flexibility 
but adds the complexity of the extra code. And using the 
libcamera::controls::controls variable would probably simplify the 
code but makes the GStreamer element dependent on the information 
which are exposed by the variable.

I'm open to both possibilities. Does anyone have opinions on this?

Best regards,

Jaslo

>> The one thing that Nicolas suggested is adding a special 
>> property 
>> to the GStreamer element which can then return the available 
>> properties and their ranges at runtime. That would be the 
>> GstStructure which I was asking about.
>> 
>> >> > If the selection is all rw, the marking of that can wait. 
>> >> > Min/max would be my
>> >> > preference to have, but as we are breaking the API anyway 
>> >> > still, we can also do
>> >> > small break in the gstreamer element later too (as long as 
>> >> > its well reported in
>> >> > the release notes).
>> >> 
>> >> You also suggested a GStreamer property that returns a 
>> >> GstStructure which lists all the actually present controls 
>> >> for 
>> >> the 
>> >> camera and their actual limits. Do you still want this 
>> >> implemented 
>> >> and if so how do you imagine this structure to be laid out?
>> >> 
>> >> >> > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska 
>> >> >> > wrote:
>> >> >> > > Hi everyone,
>> >> >> > > 
>> >> >> > > this is the second version of the patch set to 
>> >> >> > > implement 
>> >> >> > > gstreamer controls
>> >> >> > > from the yaml files.
>> >> >> > > This now depends on "[PATCH 00/10] libcamera: Improve 
>> >> >> > > code generation for
>> >> >> > > controls" for the code generation.
>> >> >> > > 
>> >> >> > > The following things changed:
>> >> >> > > 
>> >> >> > > The (old) third commit fixing a typo has been removed 
>> >> >> > > as 
>> >> >> > > it is already merged.
>> >> >> > > 
>> >> >> > > The first commit is new: it removes the 
>> >> >> > > auto-focus-mode 
>> >> >> > > property from the
>> >> >> > > device provider where it has been added on accident.
>> >> >> > > 
>> >> >> > > The commit message has been updated in the second 
>> >> >> > > commit.
>> >> >> > > 
>> >> >> > > The third commit, which adds the code that generates 
>> >> >> > > the 
>> >> >> > > gstreamer controls,
>> >> >> > > now makes use of jinja2 and the new controls.py file. 
>> >> >> > > As 
>> >> >> > > a consequence the
>> >> >> > > whole code generation has been redone.
>> >> >> > > 
>> >> >> > > There are also some new features:
>> >> >> > > 
>> >> >> > > It is now possible to read the metadata returned by 
>> >> >> > > requests from the gstreamer
>> >> >> > > properties. This is done using a new function 
>> >> >> > > readMetadata() which reads the
>> >> >> > > ControlList in requestCompleted().
>> >> >> > > 
>> >> >> > > Before a control is set it is now checked whether 
>> >> >> > > this 
>> >> >> > > control is actually
>> >> >> > > supported by the camera. This is done by checking the 
>> >> >> > > cameras ControlInfoMap.
>> >> >> > > 
>> >> >> > > The Rectangle type is now supported.
>> >> >> > > 
>> >> >> > > Some checks were added to make sure the arrays passed 
>> >> >> > > to 
>> >> >> > > the element have the
>> >> >> > > correct length.
>> >> >> > > 
>> >> >> > > Best regards,
>> >> >> > > 
>> >> >> > > Jaslo
>> >> >> > > 
>> >> >> > > Jaslo Ziska (3):
>> >> >> > >   gstreamer: Remove auto-focus-mode property from 
>> >> >> > >   device provider
>> >> >> > >   gstreamer: Remove auto-focus-mode property from 
>> >> >> > >   libcamerasrc
>> >> >> > >   gstreamer: Generate controls from 
>> >> >> > >   control_ids_*.yaml files
>> >> >> > > 
>> >> >> > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 
>> >> >> > >  +++++++++++++++++++++
>> >> >> > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
>> >> >> > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
>> >> >> > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 
>> >> >> > >  ++--
>> >> >> > >  src/gstreamer/meson.build                  |  10 +
>> >> >> > >  utils/codegen/controls.py                  |   8 +
>> >> >> > >  utils/codegen/gen-gst-controls.py          | 151 
>> >> >> > >  +++++++++++
>> >> >> > >  utils/codegen/meson.build                  |   1 +
>> >> >> > >  8 files changed, 528 insertions(+), 46 deletions(-)
>> >> >> > >  create mode 100644 
>> >> >> > >  src/gstreamer/gstlibcamera-controls.cpp.in
>> >> >> > >  create mode 100644 
>> >> >> > >  src/gstreamer/gstlibcamera-controls.h
>> >> >> > >  create mode 100755 utils/codegen/gen-gst-controls.py
Laurent Pinchart Oct. 3, 2024, 12:10 p.m. UTC | #9
On Thu, Oct 03, 2024 at 12:18:54PM +0200, Jaslo Ziska wrote:
> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> > On Wed, Oct 02, 2024 at 07:27:34PM +0200, Jaslo Ziska wrote:
> >> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> >> > On Wed, Oct 02, 2024 at 12:04:08PM +0200, Jaslo Ziska wrote:
> >> >> Nicolas Dufresne <nicolas@ndufresne.ca> writes:
> >> >> > Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a écrit :
> >> >> >> Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> >> >> >> > Hi Jaslo,
> >> >> >> > 
> >> >> >> > I think this series is close to being ready, and I would be very happy
> >> >> >> > to merge this much awaited feature. Do you plan to send a v3 ?
> >> >> >> 
> >> >> >> Yes, I very much plan on continuing to work on this. I was a 
> >> >> >> pretty busy the past month but I should have more time later in 
> >> >> >> October.
> >> >> >> 
> >> >> >> Unfortunately, I don't think that the series is quite ready. 
> >> >> >> Nicolas had requested some bigger changes in v1 which still need 
> >> >> >> to be discussed and implemented and I also want to add the 
> >> >> >> readable/writeable and minimum/maximum properties to the yaml 
> >> >> >> files (although this could also be done separately after merging).
> >> >> >
> >> >> > My proposal is to program a subset to be exposed as properties, the one that are
> >> >> > obviously usable and that the documentation make sense. I think you did a great
> >> >> > job on the generator and adding features later to support controls that have
> >> >> > more complex semantic is better then trying to support them all in one go today.
> >> >> 
> >> >> Sounds good. Where would you suggest the list of controls to be 
> >> >> exposed should be? Maybe just a plain list in the Python generator 
> >> >> file?
> >> >
> >> > The other option is to store the information in the yaml files. I don't
> >> > have a very strong opinion, the yaml files have the advantage that all
> >> > the data related to controls will be in a single place, but the
> >> > generator script has the advantage of keeping all gstreamer-related data
> >> > close to the gstreamer element. That may be useful when it will be time
> >> > to move libcamerasrc from the libcamera repository to the gstreamer
> >> > repository (if we ever do so). On the other hand, tha yaml files are not
> >> > installed, so there would still be issues.
> >> 
> >> Putting it inside the yaml would be an option, but I don't know 
> >> whether having GStreamer specific stuff there is so good. But I 
> >> think this will likely change anyway.
> >> 
> >> > Complete brainstorming mode, I'm wondering if at some point in the
> >> > future it would make sense to handle the gstreamer controls in a more
> >> > dynamic fashion by querying libcamera at runtime instead of using code
> >> > generation. This doesn't invalidate the approach you've taken here, I
> >> > think code generation is good for the time being.
> >> 
> >> If you mean that the GStreamer properties should get added later 
> >> at runtime then this is unfortunately not possible. This is 
> >> because the GStreamer controls are GObject properties and those 
> >> need to be installed when the GObject object class is initialized. 
> >> And because this happens before the GStreamer element is 
> >> constructed (and therefore also before libcamera gets involved) it 
> >> is not possible to know which properties are present and with 
> >> which ranges.
> >
> > You can get the list of all the controls that libcamera supports from
> > libcamera::controls::controls. It's a global ControlIdMap variable, a
> > map from control numerical ids to ControlId instances. The ControlId
> > class gives you the control numerical id, its name, type, number of
> > elements if it's an array, and enumerators. We're adding the control
> > namespace as well, and could add additional information if needed. We
> > don't need to go this way though.
> 
> Ah yes, I think that would work too, I never thought about it that 
> way. This still would not help with the actually available 
> controls for the camera unfortunately.
> 
> I don't know which way would be the proper or better way to do it, 
> both ways have their pros and cons.
> 
> Using the yaml files and the code generator has more flexibility 
> but adds the complexity of the extra code. And using the 
> libcamera::controls::controls variable would probably simplify the 
> code but makes the GStreamer element dependent on the information 
> which are exposed by the variable.

One thing missing in ControlId (beside the namespace that we will add
soon) that you would need for libcamerasrc is documentation. I'm not too
keen on adding that to ControlId, it's lots of text, which would
probably then need localization.

> I'm open to both possibilities. Does anyone have opinions on this?

I think it's more important at this point to have a working version than
a perfect version, so I'm fine continuing with the current approach.

> >> The one thing that Nicolas suggested is adding a special property 
> >> to the GStreamer element which can then return the available 
> >> properties and their ranges at runtime. That would be the 
> >> GstStructure which I was asking about.
> >> 
> >> >> > If the selection is all rw, the marking of that can wait. 
> >> >> > Min/max would be my
> >> >> > preference to have, but as we are breaking the API anyway 
> >> >> > still, we can also do
> >> >> > small break in the gstreamer element later too (as long as 
> >> >> > its well reported in
> >> >> > the release notes).
> >> >> 
> >> >> You also suggested a GStreamer property that returns a 
> >> >> GstStructure which lists all the actually present controls for the 
> >> >> camera and their actual limits. Do you still want this implemented 
> >> >> and if so how do you imagine this structure to be laid out?
> >> >> 
> >> >> >> > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
> >> >> >> > > Hi everyone,
> >> >> >> > > 
> >> >> >> > > this is the second version of the patch set to implement gstreamer controls
> >> >> >> > > from the yaml files.
> >> >> >> > > This now depends on "[PATCH 00/10] libcamera: Improve code generation for
> >> >> >> > > controls" for the code generation.
> >> >> >> > > 
> >> >> >> > > The following things changed:
> >> >> >> > > 
> >> >> >> > > The (old) third commit fixing a typo has been removed as it is already merged.
> >> >> >> > > 
> >> >> >> > > The first commit is new: it removes the auto-focus-mode property from the
> >> >> >> > > device provider where it has been added on accident.
> >> >> >> > > 
> >> >> >> > > The commit message has been updated in the second commit.
> >> >> >> > > 
> >> >> >> > > The third commit, which adds the code that generates the gstreamer controls,
> >> >> >> > > now makes use of jinja2 and the new controls.py file. As a consequence the
> >> >> >> > > whole code generation has been redone.
> >> >> >> > > 
> >> >> >> > > There are also some new features:
> >> >> >> > > 
> >> >> >> > > It is now possible to read the metadata returned by requests from the gstreamer
> >> >> >> > > properties. This is done using a new function readMetadata() which reads the
> >> >> >> > > ControlList in requestCompleted().
> >> >> >> > > 
> >> >> >> > > Before a control is set it is now checked whether this control is actually
> >> >> >> > > supported by the camera. This is done by checking the cameras ControlInfoMap.
> >> >> >> > > 
> >> >> >> > > The Rectangle type is now supported.
> >> >> >> > > 
> >> >> >> > > Some checks were added to make sure the arrays passed to the element have the
> >> >> >> > > correct length.
> >> >> >> > > 
> >> >> >> > > Best regards,
> >> >> >> > > 
> >> >> >> > > Jaslo
> >> >> >> > > 
> >> >> >> > > Jaslo Ziska (3):
> >> >> >> > >   gstreamer: Remove auto-focus-mode property from device provider
> >> >> >> > >   gstreamer: Remove auto-focus-mode property from libcamerasrc
> >> >> >> > >   gstreamer: Generate controls from control_ids_*.yaml files
> >> >> >> > > 
> >> >> >> > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 +++++++++++++++++++++
> >> >> >> > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
> >> >> >> > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
> >> >> >> > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
> >> >> >> > >  src/gstreamer/meson.build                  |  10 +
> >> >> >> > >  utils/codegen/controls.py                  |   8 +
> >> >> >> > >  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
> >> >> >> > >  utils/codegen/meson.build                  |   1 +
> >> >> >> > >  8 files changed, 528 insertions(+), 46 deletions(-)
> >> >> >> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
> >> >> >> > >  create mode 100644 src/gstreamer/gstlibcamera-controls.h
> >> >> >> > >  create mode 100755 utils/codegen/gen-gst-controls.py
Nicolas Dufresne Oct. 3, 2024, 2:16 p.m. UTC | #10
Le mercredi 02 octobre 2024 à 14:22 +0300, Laurent Pinchart a écrit :
> On Wed, Oct 02, 2024 at 12:04:08PM +0200, Jaslo Ziska wrote:
> > Nicolas Dufresne <nicolas@ndufresne.ca> writes:
> > > Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a écrit :
> > > > Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> > > > > Hi Jaslo,
> > > > > 
> > > > > I think this series is close to being ready, and I would be very happy
> > > > > to merge this much awaited feature. Do you plan to send a v3 ?
> > > > 
> > > > Yes, I very much plan on continuing to work on this. I was a 
> > > > pretty busy the past month but I should have more time later in 
> > > > October.
> > > > 
> > > > Unfortunately, I don't think that the series is quite ready. 
> > > > Nicolas had requested some bigger changes in v1 which still need 
> > > > to be discussed and implemented and I also want to add the 
> > > > readable/writeable and minimum/maximum properties to the yaml 
> > > > files (although this could also be done separately after 
> > > > merging).
> > > 
> > > My proposal is to program a subset to be exposed as properties, the one that are
> > > obviously usable and that the documentation make sense. I think you did a great
> > > job on the generator and adding features later to support controls that have
> > > more complex semantic is better then trying to support them all 
> > > in one go today.
> > 
> > Sounds good. Where would you suggest the list of controls to be 
> > exposed should be? Maybe just a plain list in the Python generator 
> > file?
> 
> The other option is to store the information in the yaml files. I don't
> have a very strong opinion, the yaml files have the advantage that all
> the data related to controls will be in a single place, but the
> generator script has the advantage of keeping all gstreamer-related data
> close to the gstreamer element. That may be useful when it will be time
> to move libcamerasrc from the libcamera repository to the gstreamer
> repository (if we ever do so). On the other hand, tha yaml files are not
> installed, so there would still be issues.

I would start simple and close to GStreamer at this stage. So just a list in the
generator works for me.

> 
> Complete brainstorming mode, I'm wondering if at some point in the
> future it would make sense to handle the gstreamer controls in a more
> dynamic fashion by querying libcamera at runtime instead of using code
> generation. This doesn't invalidate the approach you've taken here, I
> think code generation is good for the time being.

GObject properties have to be setup at class instance creation time, which can
only happen once (unlike instance creation or the contructor). That limits how
"dynamic" this can be. Dynamic class creation is possible, but have never been
done for possibly hot-pluggable devices (even though I will likely disable UVC
support in our GStreamer element as folks are struggling getting on part support
as what the v4l2src offers).

The code generator is by far a lot more straightforward to follow and maintain
in my opinion. In the long term, we can use a hand written property to expose
the map of supported properties, which isn't different when you use libcamera
directly, since the properties comes in that form.

Nicolas

> 
> > > If the selection is all rw, the marking of that can wait. Min/max would be my
> > > preference to have, but as we are breaking the API anyway still, we can also do
> > > small break in the gstreamer element later too (as long as its well reported in
> > > the release notes).
> > 
> > You also suggested a GStreamer property that returns a 
> > GstStructure which lists all the actually present controls for the 
> > camera and their actual limits. Do you still want this implemented 
> > and if so how do you imagine this structure to be laid out?
> > 
> > > > > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
> > > > > > Hi everyone,
> > > > > > 
> > > > > > this is the second version of the patch set to implement gstreamer controls
> > > > > > from the yaml files.
> > > > > > This now depends on "[PATCH 00/10] libcamera: Improve code generation for
> > > > > > controls" for the code generation.
> > > > > > 
> > > > > > The following things changed:
> > > > > > 
> > > > > > The (old) third commit fixing a typo has been removed as it is already merged.
> > > > > > 
> > > > > > The first commit is new: it removes the auto-focus-mode property from the
> > > > > > device provider where it has been added on accident.
> > > > > > 
> > > > > > The commit message has been updated in the second commit.
> > > > > > 
> > > > > > The third commit, which adds the code that generates the gstreamer controls,
> > > > > > now makes use of jinja2 and the new controls.py file. As a consequence the
> > > > > > whole code generation has been redone.
> > > > > > 
> > > > > > There are also some new features:
> > > > > > 
> > > > > > It is now possible to read the metadata returned by requests from the gstreamer
> > > > > > properties. This is done using a new function readMetadata() which reads the
> > > > > > ControlList in requestCompleted().
> > > > > > 
> > > > > > Before a control is set it is now checked whether this control is actually
> > > > > > supported by the camera. This is done by checking the cameras ControlInfoMap.
> > > > > > 
> > > > > > The Rectangle type is now supported.
> > > > > > 
> > > > > > Some checks were added to make sure the arrays passed to the element have the
> > > > > > correct length.
> > > > > > 
> > > > > > Best regards,
> > > > > > 
> > > > > > Jaslo
> > > > > > 
> > > > > > Jaslo Ziska (3):
> > > > > >   gstreamer: Remove auto-focus-mode property from device provider
> > > > > >   gstreamer: Remove auto-focus-mode property from libcamerasrc
> > > > > >   gstreamer: Generate controls from control_ids_*.yaml files
> > > > > > 
> > > > > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 +++++++++++++++++++++
> > > > > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
> > > > > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
> > > > > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
> > > > > >  src/gstreamer/meson.build                  |  10 +
> > > > > >  utils/codegen/controls.py                  |   8 +
> > > > > >  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
> > > > > >  utils/codegen/meson.build                  |   1 +
> > > > > >  8 files changed, 528 insertions(+), 46 deletions(-)
> > > > > >  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
> > > > > >  create mode 100644 src/gstreamer/gstlibcamera-controls.h
> > > > > >  create mode 100755 utils/codegen/gen-gst-controls.py
>
Nicolas Dufresne Oct. 3, 2024, 2:19 p.m. UTC | #11
Hi,

Le jeudi 03 octobre 2024 à 15:10 +0300, Laurent Pinchart a écrit :
> On Thu, Oct 03, 2024 at 12:18:54PM +0200, Jaslo Ziska wrote:
> > Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> > > On Wed, Oct 02, 2024 at 07:27:34PM +0200, Jaslo Ziska wrote:
> > > > Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> > > > > On Wed, Oct 02, 2024 at 12:04:08PM +0200, Jaslo Ziska wrote:
> > > > > > Nicolas Dufresne <nicolas@ndufresne.ca> writes:
> > > > > > > Le lundi 30 septembre 2024 à 11:11 +0200, Jaslo Ziska a écrit :
> > > > > > > > Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:
> > > > > > > > > Hi Jaslo,
> > > > > > > > > 
> > > > > > > > > I think this series is close to being ready, and I would be very happy
> > > > > > > > > to merge this much awaited feature. Do you plan to send a v3 ?
> > > > > > > > 
> > > > > > > > Yes, I very much plan on continuing to work on this. I was a 
> > > > > > > > pretty busy the past month but I should have more time later in 
> > > > > > > > October.
> > > > > > > > 
> > > > > > > > Unfortunately, I don't think that the series is quite ready. 
> > > > > > > > Nicolas had requested some bigger changes in v1 which still need 
> > > > > > > > to be discussed and implemented and I also want to add the 
> > > > > > > > readable/writeable and minimum/maximum properties to the yaml 
> > > > > > > > files (although this could also be done separately after merging).
> > > > > > > 
> > > > > > > My proposal is to program a subset to be exposed as properties, the one that are
> > > > > > > obviously usable and that the documentation make sense. I think you did a great
> > > > > > > job on the generator and adding features later to support controls that have
> > > > > > > more complex semantic is better then trying to support them all in one go today.
> > > > > > 
> > > > > > Sounds good. Where would you suggest the list of controls to be 
> > > > > > exposed should be? Maybe just a plain list in the Python generator 
> > > > > > file?
> > > > > 
> > > > > The other option is to store the information in the yaml files. I don't
> > > > > have a very strong opinion, the yaml files have the advantage that all
> > > > > the data related to controls will be in a single place, but the
> > > > > generator script has the advantage of keeping all gstreamer-related data
> > > > > close to the gstreamer element. That may be useful when it will be time
> > > > > to move libcamerasrc from the libcamera repository to the gstreamer
> > > > > repository (if we ever do so). On the other hand, tha yaml files are not
> > > > > installed, so there would still be issues.
> > > > 
> > > > Putting it inside the yaml would be an option, but I don't know 
> > > > whether having GStreamer specific stuff there is so good. But I 
> > > > think this will likely change anyway.
> > > > 
> > > > > Complete brainstorming mode, I'm wondering if at some point in the
> > > > > future it would make sense to handle the gstreamer controls in a more
> > > > > dynamic fashion by querying libcamera at runtime instead of using code
> > > > > generation. This doesn't invalidate the approach you've taken here, I
> > > > > think code generation is good for the time being.
> > > > 
> > > > If you mean that the GStreamer properties should get added later 
> > > > at runtime then this is unfortunately not possible. This is 
> > > > because the GStreamer controls are GObject properties and those 
> > > > need to be installed when the GObject object class is initialized. 
> > > > And because this happens before the GStreamer element is 
> > > > constructed (and therefore also before libcamera gets involved) it 
> > > > is not possible to know which properties are present and with 
> > > > which ranges.
> > > 
> > > You can get the list of all the controls that libcamera supports from
> > > libcamera::controls::controls. It's a global ControlIdMap variable, a
> > > map from control numerical ids to ControlId instances. The ControlId
> > > class gives you the control numerical id, its name, type, number of
> > > elements if it's an array, and enumerators. We're adding the control
> > > namespace as well, and could add additional information if needed. We
> > > don't need to go this way though.
> > 
> > Ah yes, I think that would work too, I never thought about it that 
> > way. This still would not help with the actually available 
> > controls for the camera unfortunately.
> > 
> > I don't know which way would be the proper or better way to do it, 
> > both ways have their pros and cons.
> > 
> > Using the yaml files and the code generator has more flexibility 
> > but adds the complexity of the extra code. And using the 
> > libcamera::controls::controls variable would probably simplify the 
> > code but makes the GStreamer element dependent on the information 
> > which are exposed by the variable.
> 
> One thing missing in ControlId (beside the namespace that we will add
> soon) that you would need for libcamerasrc is documentation. I'm not too
> keen on adding that to ControlId, it's lots of text, which would
> probably then need localization.

We have stopped localization of non-user facing text in GStreamer. That means
the documentation (including properties, signal, enums description), debug
traces and internal errors are not translated.

Nicolas

> 
> > I'm open to both possibilities. Does anyone have opinions on this?
> 
> I think it's more important at this point to have a working version than
> a perfect version, so I'm fine continuing with the current approach.
> 
> > > > The one thing that Nicolas suggested is adding a special property 
> > > > to the GStreamer element which can then return the available 
> > > > properties and their ranges at runtime. That would be the 
> > > > GstStructure which I was asking about.
> > > > 
> > > > > > > If the selection is all rw, the marking of that can wait. 
> > > > > > > Min/max would be my
> > > > > > > preference to have, but as we are breaking the API anyway 
> > > > > > > still, we can also do
> > > > > > > small break in the gstreamer element later too (as long as 
> > > > > > > its well reported in
> > > > > > > the release notes).
> > > > > > 
> > > > > > You also suggested a GStreamer property that returns a 
> > > > > > GstStructure which lists all the actually present controls for the 
> > > > > > camera and their actual limits. Do you still want this implemented 
> > > > > > and if so how do you imagine this structure to be laid out?
> > > > > > 
> > > > > > > > > On Tue, Aug 13, 2024 at 02:25:04PM +0200, Jaslo Ziska wrote:
> > > > > > > > > > Hi everyone,
> > > > > > > > > > 
> > > > > > > > > > this is the second version of the patch set to implement gstreamer controls
> > > > > > > > > > from the yaml files.
> > > > > > > > > > This now depends on "[PATCH 00/10] libcamera: Improve code generation for
> > > > > > > > > > controls" for the code generation.
> > > > > > > > > > 
> > > > > > > > > > The following things changed:
> > > > > > > > > > 
> > > > > > > > > > The (old) third commit fixing a typo has been removed as it is already merged.
> > > > > > > > > > 
> > > > > > > > > > The first commit is new: it removes the auto-focus-mode property from the
> > > > > > > > > > device provider where it has been added on accident.
> > > > > > > > > > 
> > > > > > > > > > The commit message has been updated in the second commit.
> > > > > > > > > > 
> > > > > > > > > > The third commit, which adds the code that generates the gstreamer controls,
> > > > > > > > > > now makes use of jinja2 and the new controls.py file. As a consequence the
> > > > > > > > > > whole code generation has been redone.
> > > > > > > > > > 
> > > > > > > > > > There are also some new features:
> > > > > > > > > > 
> > > > > > > > > > It is now possible to read the metadata returned by requests from the gstreamer
> > > > > > > > > > properties. This is done using a new function readMetadata() which reads the
> > > > > > > > > > ControlList in requestCompleted().
> > > > > > > > > > 
> > > > > > > > > > Before a control is set it is now checked whether this control is actually
> > > > > > > > > > supported by the camera. This is done by checking the cameras ControlInfoMap.
> > > > > > > > > > 
> > > > > > > > > > The Rectangle type is now supported.
> > > > > > > > > > 
> > > > > > > > > > Some checks were added to make sure the arrays passed to the element have the
> > > > > > > > > > correct length.
> > > > > > > > > > 
> > > > > > > > > > Best regards,
> > > > > > > > > > 
> > > > > > > > > > Jaslo
> > > > > > > > > > 
> > > > > > > > > > Jaslo Ziska (3):
> > > > > > > > > >   gstreamer: Remove auto-focus-mode property from device provider
> > > > > > > > > >   gstreamer: Remove auto-focus-mode property from libcamerasrc
> > > > > > > > > >   gstreamer: Generate controls from control_ids_*.yaml files
> > > > > > > > > > 
> > > > > > > > > >  src/gstreamer/gstlibcamera-controls.cpp.in | 296 +++++++++++++++++++++
> > > > > > > > > >  src/gstreamer/gstlibcamera-controls.h      |  43 +++
> > > > > > > > > >  src/gstreamer/gstlibcameraprovider.cpp     |  15 --
> > > > > > > > > >  src/gstreamer/gstlibcamerasrc.cpp          |  50 ++--
> > > > > > > > > >  src/gstreamer/meson.build                  |  10 +
> > > > > > > > > >  utils/codegen/controls.py                  |   8 +
> > > > > > > > > >  utils/codegen/gen-gst-controls.py          | 151 +++++++++++
> > > > > > > > > >  utils/codegen/meson.build                  |   1 +
> > > > > > > > > >  8 files changed, 528 insertions(+), 46 deletions(-)
> > > > > > > > > >  create mode 100644 src/gstreamer/gstlibcamera-controls.cpp.in
> > > > > > > > > >  create mode 100644 src/gstreamer/gstlibcamera-controls.h
> > > > > > > > > >  create mode 100755 utils/codegen/gen-gst-controls.py
>