gst: provider: Do not hide v4l2deviceprovider
diff mbox series

Message ID 20240506022555.992573-1-qi.hou@nxp.com
State Changes Requested
Headers show
Series
  • gst: provider: Do not hide v4l2deviceprovider
Related show

Commit Message

Qi Hou May 6, 2024, 2:25 a.m. UTC
Currently libcameraprovider hides "v4l2deviceprovider" to avoid devices
being duplicated. When running "gst-gst-device-monitor-1.0 Video",
device monitor probes device providers one by one and sends bus message
to gst-device-monitor to print device information.

There is one case that libcameraprovider and v4l2deviceprovider both
exit, libcameraprovider fails to probe device while v4l2deviceprovider
probes successfully. "gst-device-monitor Video" will show nothing as
v4l2deviceprovider is hidden and the bus message it uses to convey
device information is dropped.

To fix this issue, not to hide v4l2deviceprovider when do
gst_libcamera_provider_init().

Signed-off-by: Hou Qi <qi.hou@nxp.com>
---
 src/gstreamer/gstlibcameraprovider.cpp | 4 ----
 1 file changed, 4 deletions(-)

Comments

Umang Jain May 6, 2024, 2:33 p.m. UTC | #1
Hi Hou Qi

On 06/05/24 7:55 am, Hou Qi wrote:
> Currently libcameraprovider hides "v4l2deviceprovider" to avoid devices
> being duplicated. When running "gst-gst-device-monitor-1.0 Video",
> device monitor probes device providers one by one and sends bus message
> to gst-device-monitor to print device information.
>
> There is one case that libcameraprovider and v4l2deviceprovider both
> exit, libcameraprovider fails to probe device while v4l2deviceprovider
> probes successfully. "gst-device-monitor Video" will show nothing as
> v4l2deviceprovider is hidden and the bus message it uses to convey
> device information is dropped.
>
> To fix this issue, not to hide v4l2deviceprovider when do
> gst_libcamera_provider_init().

I think this just circumvents the issue rather than fixing it. I would 
be more interested in knowing /why/ libcameraprovider can't probe it.

Can you explain on the use case / your case in this regards please? OR

Can you enable the debug and see if holds any clue on the problem ?

For e.g.

($) LIBCAMERA_LOG_LEVELS=0 GST_DEBUG=2 gst-device-monitor-1.0 Source/Video

Also, gst-device-monitor provides option to include hidden providers:

   -i, --include-hidden              Include devices from hidden device 
providers.



>
> Signed-off-by: Hou Qi <qi.hou@nxp.com>
> ---
>   src/gstreamer/gstlibcameraprovider.cpp | 4 ----
>   1 file changed, 4 deletions(-)
>
> diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
> index ce3e0a08..454e7aaa 100644
> --- a/src/gstreamer/gstlibcameraprovider.cpp
> +++ b/src/gstreamer/gstlibcameraprovider.cpp
> @@ -227,10 +227,6 @@ gst_libcamera_provider_probe(GstDeviceProvider *provider)
>   static void
>   gst_libcamera_provider_init(GstLibcameraProvider *self)
>   {
> -	GstDeviceProvider *provider = GST_DEVICE_PROVIDER(self);
> -
> -	/* Avoid devices being duplicated. */
> -	gst_device_provider_hide_provider(provider, "v4l2deviceprovider");
>   }
>   
>   static void
Laurent Pinchart May 6, 2024, 6:38 p.m. UTC | #2
On Mon, May 06, 2024 at 08:03:53PM +0530, Umang Jain wrote:
> Hi Hou Qi
> 
> On 06/05/24 7:55 am, Hou Qi wrote:
> > Currently libcameraprovider hides "v4l2deviceprovider" to avoid devices
> > being duplicated. When running "gst-gst-device-monitor-1.0 Video",
> > device monitor probes device providers one by one and sends bus message
> > to gst-device-monitor to print device information.
> >
> > There is one case that libcameraprovider and v4l2deviceprovider both
> > exit, libcameraprovider fails to probe device while v4l2deviceprovider
> > probes successfully. "gst-device-monitor Video" will show nothing as
> > v4l2deviceprovider is hidden and the bus message it uses to convey
> > device information is dropped.
> >
> > To fix this issue, not to hide v4l2deviceprovider when do
> > gst_libcamera_provider_init().
> 
> I think this just circumvents the issue rather than fixing it. I would 
> be more interested in knowing /why/ libcameraprovider can't probe it.

Possibly because not all V4L2 devices are in scope for libcamera ?

Hiding the provider isn't a very nice solution, but duplicating devices
isn't good either. The approach taken by pipewire is to query libcamera
for the list of devices it supports, and ignoring them in the V4L2
source element. I wonder if something similar could be done for
GStreamer.

> Can you explain on the use case / your case in this regards please? OR
> 
> Can you enable the debug and see if holds any clue on the problem ?
> 
> For e.g.
> 
> ($) LIBCAMERA_LOG_LEVELS=0 GST_DEBUG=2 gst-device-monitor-1.0 Source/Video
> 
> Also, gst-device-monitor provides option to include hidden providers:
> 
>    -i, --include-hidden              Include devices from hidden device 
> providers.
> 
> > Signed-off-by: Hou Qi <qi.hou@nxp.com>
> > ---
> >   src/gstreamer/gstlibcameraprovider.cpp | 4 ----
> >   1 file changed, 4 deletions(-)
> >
> > diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
> > index ce3e0a08..454e7aaa 100644
> > --- a/src/gstreamer/gstlibcameraprovider.cpp
> > +++ b/src/gstreamer/gstlibcameraprovider.cpp
> > @@ -227,10 +227,6 @@ gst_libcamera_provider_probe(GstDeviceProvider *provider)
> >   static void
> >   gst_libcamera_provider_init(GstLibcameraProvider *self)
> >   {
> > -	GstDeviceProvider *provider = GST_DEVICE_PROVIDER(self);
> > -
> > -	/* Avoid devices being duplicated. */
> > -	gst_device_provider_hide_provider(provider, "v4l2deviceprovider");
> >   }
> >   
> >   static void
Nicolas Dufresne May 6, 2024, 7:51 p.m. UTC | #3
Le lundi 06 mai 2024 à 21:38 +0300, Laurent Pinchart a écrit :
> On Mon, May 06, 2024 at 08:03:53PM +0530, Umang Jain wrote:
> > Hi Hou Qi
> > 
> > On 06/05/24 7:55 am, Hou Qi wrote:
> > > Currently libcameraprovider hides "v4l2deviceprovider" to avoid devices
> > > being duplicated. When running "gst-gst-device-monitor-1.0 Video",
> > > device monitor probes device providers one by one and sends bus message
> > > to gst-device-monitor to print device information.
> > > 
> > > There is one case that libcameraprovider and v4l2deviceprovider both
> > > exit, libcameraprovider fails to probe device while v4l2deviceprovider
> > > probes successfully. "gst-device-monitor Video" will show nothing as
> > > v4l2deviceprovider is hidden and the bus message it uses to convey
> > > device information is dropped.
> > > 
> > > To fix this issue, not to hide v4l2deviceprovider when do
> > > gst_libcamera_provider_init().
> > 
> > I think this just circumvents the issue rather than fixing it. I would 
> > be more interested in knowing /why/ libcameraprovider can't probe it.
> 
> Possibly because not all V4L2 devices are in scope for libcamera ?
> 
> Hiding the provider isn't a very nice solution, but duplicating devices
> isn't good either. The approach taken by pipewire is to query libcamera
> for the list of devices it supports, and ignoring them in the V4L2
> source element. I wonder if something similar could be done for
> GStreamer.

Do you have links to that ? I was not ware that you could mix v4l2 and libcamera
in pipewire today.

In GStreamer, its a bit less evident, there is no framework for libcamera
provider to cherry-pick some devices and hide them for other providers. Its a
Linux only problem, so it might not be super evident to get code there for a
mess we are the author of.

Nicolas

> 
> > Can you explain on the use case / your case in this regards please? OR
> > 
> > Can you enable the debug and see if holds any clue on the problem ?
> > 
> > For e.g.
> > 
> > ($) LIBCAMERA_LOG_LEVELS=0 GST_DEBUG=2 gst-device-monitor-1.0 Source/Video
> > 
> > Also, gst-device-monitor provides option to include hidden providers:
> > 
> >    -i, --include-hidden              Include devices from hidden device 
> > providers.
> > 
> > > Signed-off-by: Hou Qi <qi.hou@nxp.com>
> > > ---
> > >   src/gstreamer/gstlibcameraprovider.cpp | 4 ----
> > >   1 file changed, 4 deletions(-)
> > > 
> > > diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
> > > index ce3e0a08..454e7aaa 100644
> > > --- a/src/gstreamer/gstlibcameraprovider.cpp
> > > +++ b/src/gstreamer/gstlibcameraprovider.cpp
> > > @@ -227,10 +227,6 @@ gst_libcamera_provider_probe(GstDeviceProvider *provider)
> > >   static void
> > >   gst_libcamera_provider_init(GstLibcameraProvider *self)
> > >   {
> > > -	GstDeviceProvider *provider = GST_DEVICE_PROVIDER(self);
> > > -
> > > -	/* Avoid devices being duplicated. */
> > > -	gst_device_provider_hide_provider(provider, "v4l2deviceprovider");
> > >   }
> > >   
> > >   static void
>
Barnabás Pőcze May 6, 2024, 8:56 p.m. UTC | #4
Hi


2024. május 6., hétfő 21:51 keltezéssel, Nicolas Dufresne <nicolas@ndufresne.ca> írta:

> Le lundi 06 mai 2024 à 21:38 +0300, Laurent Pinchart a écrit :
> > On Mon, May 06, 2024 at 08:03:53PM +0530, Umang Jain wrote:
> > > Hi Hou Qi
> > >
> > > On 06/05/24 7:55 am, Hou Qi wrote:
> > > > Currently libcameraprovider hides "v4l2deviceprovider" to avoid devices
> > > > being duplicated. When running "gst-gst-device-monitor-1.0 Video",
> > > > device monitor probes device providers one by one and sends bus message
> > > > to gst-device-monitor to print device information.
> > > >
> > > > There is one case that libcameraprovider and v4l2deviceprovider both
> > > > exit, libcameraprovider fails to probe device while v4l2deviceprovider
> > > > probes successfully. "gst-device-monitor Video" will show nothing as
> > > > v4l2deviceprovider is hidden and the bus message it uses to convey
> > > > device information is dropped.
> > > >
> > > > To fix this issue, not to hide v4l2deviceprovider when do
> > > > gst_libcamera_provider_init().
> > >
> > > I think this just circumvents the issue rather than fixing it. I would
> > > be more interested in knowing /why/ libcameraprovider can't probe it.
> >
> > Possibly because not all V4L2 devices are in scope for libcamera ?
> >
> > Hiding the provider isn't a very nice solution, but duplicating devices
> > isn't good either. The approach taken by pipewire is to query libcamera
> > for the list of devices it supports, and ignoring them in the V4L2
> > source element. I wonder if something similar could be done for
> > GStreamer.
> 
> Do you have links to that ? I was not ware that you could mix v4l2 and libcamera
> in pipewire today.

I believe it was always possible. The only recent thing is camera de-duplication,
which was introduced in wireplumber not so long ago:

  https://gitlab.freedesktop.org/pipewire/wireplumber/-/merge_requests/525


> [...]


Regards,
Barnabás Pőcze
Nicolas Dufresne May 7, 2024, 7 p.m. UTC | #5
Le lundi 06 mai 2024 à 20:56 +0000, Barnabás Pőcze a écrit :
> Hi
> 
> 
> 2024. május 6., hétfő 21:51 keltezéssel, Nicolas Dufresne <nicolas@ndufresne.ca> írta:
> 
> > Le lundi 06 mai 2024 à 21:38 +0300, Laurent Pinchart a écrit :
> > > On Mon, May 06, 2024 at 08:03:53PM +0530, Umang Jain wrote:
> > > > Hi Hou Qi

[...]

> > > > 
> > 
> > Do you have links to that ? I was not ware that you could mix v4l2 and libcamera
> > in pipewire today.
> 
> I believe it was always possible. The only recent thing is camera de-duplication,
> which was introduced in wireplumber not so long ago:
> 
>   https://gitlab.freedesktop.org/pipewire/wireplumber/-/merge_requests/525

Didn't know, thanks. They coded knowledge of this in a central place, a place we
don't have in GStreamer. The monitor is completely agnostic code (it does not
even know the difference between audio/video or GPU devices). Though, what we
can do is filtering in each implementation.

I think the solution is to split the work between libcamera and v4l2 providers.
In short, libcamera should only expose MC centric devices and v4l2 provider
should filter out any MC centric devices.

In short, anything MC centric shall be ignored from v4l2src, its something I
wanted to do anyway, since using v4l2 video device (which imho should not have
been video devices to avoid confusion) without configuring the MC just bugs out
and break generic software. So v4l2src will pick UVC devices and non-MC centric
device (device with a static MC pipeline like most hdmi capture).

Then libcamera provider will filter out UVC, which I think is the only non-MC
centric device supported, and offer all the ISP or MC centric devices.

Finally, pipewire provider will mask both libcamera and v4l2 provider, cause its
expected to be a superset, and we expect software to use that so the software
can work inside a sandbox like flatpak.

So here's my take as maintainer of both component, if you can redo this M with
the proposed filtering and make a matching MR against GStreamer, I'm ready to
accept. In libcamera, you will have to only enable this new code for the version
of GStreamer your gstv4l2 changes hits, so we'll need to coordinate. The
existing behaviour will have to remain meanwhile.

Nicolas

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
index ce3e0a08..454e7aaa 100644
--- a/src/gstreamer/gstlibcameraprovider.cpp
+++ b/src/gstreamer/gstlibcameraprovider.cpp
@@ -227,10 +227,6 @@  gst_libcamera_provider_probe(GstDeviceProvider *provider)
 static void
 gst_libcamera_provider_init(GstLibcameraProvider *self)
 {
-	GstDeviceProvider *provider = GST_DEVICE_PROVIDER(self);
-
-	/* Avoid devices being duplicated. */
-	gst_device_provider_hide_provider(provider, "v4l2deviceprovider");
 }
 
 static void