[libcamera-devel,0/7] libcamera: Map multiple V4L2 formats to a single libcamera::format
mbox series

Message ID 20220715135007.53574-1-jacopo@jmondi.org
Headers show
Series
  • libcamera: Map multiple V4L2 formats to a single libcamera::format
Related show

Message

Jacopo Mondi July 15, 2022, 1:50 p.m. UTC
This series addresses the requirement of mapping multiple V4L2 pixel formats
to a single libcamera format. Specifically, it allows to map V4L2_PIX_FMT_JPEG
and V4L2_PIX_FMT_MJPEG to libcamera::formats::MJPEG.

The series starts by allowing to associate mulitple V4L2 FourCC in
PixelFormatInfo and re-introduces toV4L2PixelFormat() in V4L2VideoDevice in
order to select among from the list of V4L2 formats the first one supported
from the video device.

Patch [7/8] adds a multiplanar flag to V4L2VideoDevice::toV4L2PixelFormat() to
allow selection of the contiguous or non-contiguous format versions.

Finally, the last patch associates V4L2_PIX_FMT_JPEG to formats::MJPEG.

Tested with a UVC camera.

Pavel, could you please test on the pinephone please ?

Thanks
   j

Jacopo Mondi (7):
  libcamera: formats: Support multiple V4L2 pixel formats
  libcamera: formats: Search PixelFormatInfo on multiple formats
  libcamera: v4l2_pixelformat: Return a format list in fromPixelFormat()
  libcamera: v4l2_videodevice: Reintroduce toV4L2PixelFormat()
  libcamera: v4l2_videodevice: Match formats supported by the device
  libcamera: v4l2_videodevice: Add multiplanar argument to
    toV4L2PixelFormat
  libcamera: formats: Map V4L2_PIX_FMT_JPEG to formats::MJPEG

 Documentation/guides/pipeline-handler.rst     |   7 +-
 include/libcamera/internal/formats.h          |   4 +-
 include/libcamera/internal/v4l2_device.h      |   1 +
 include/libcamera/internal/v4l2_pixelformat.h |   6 +-
 include/libcamera/internal/v4l2_videodevice.h |   9 +-
 src/libcamera/formats.cpp                     | 262 +++++++++---------
 src/libcamera/pipeline/ipu3/cio2.cpp          |   2 +-
 src/libcamera/pipeline/ipu3/imgu.cpp          |   2 +-
 .../pipeline/raspberrypi/raspberrypi.cpp      |  34 ++-
 src/libcamera/pipeline/rkisp1/rkisp1_path.cpp |   6 +-
 src/libcamera/pipeline/simple/converter.cpp   |   8 +-
 src/libcamera/pipeline/simple/simple.cpp      |   4 +-
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp  |   6 +-
 src/libcamera/pipeline/vimc/vimc.cpp          |   8 +-
 src/libcamera/v4l2_device.cpp                 |  15 +
 src/libcamera/v4l2_pixelformat.cpp            |  18 +-
 src/libcamera/v4l2_videodevice.cpp            |  41 ++-
 src/v4l2/v4l2_camera_proxy.cpp                |   6 +-
 test/libtest/buffer_source.cpp                |   2 +-
 19 files changed, 258 insertions(+), 183 deletions(-)

--
2.36.1

Comments

Pavel Machek July 15, 2022, 8:59 p.m. UTC | #1
On Fri 2022-07-15 15:50:00, Jacopo Mondi wrote:
> This series addresses the requirement of mapping multiple V4L2 pixel formats
> to a single libcamera format. Specifically, it allows to map V4L2_PIX_FMT_JPEG
> and V4L2_PIX_FMT_MJPEG to libcamera::formats::MJPEG.
> 
> The series starts by allowing to associate mulitple V4L2 FourCC in
> PixelFormatInfo and re-introduces toV4L2PixelFormat() in V4L2VideoDevice in
> order to select among from the list of V4L2 formats the first one supported
> from the video device.
> 
> Patch [7/8] adds a multiplanar flag to V4L2VideoDevice::toV4L2PixelFormat() to
> allow selection of the contiguous or non-contiguous format versions.
> 
> Finally, the last patch associates V4L2_PIX_FMT_JPEG to formats::MJPEG.
> 
> Tested with a UVC camera.
> 
> Pavel, could you please test on the pinephone please ?

FWIW, Reviewed-by: Pavel Machek <pavel@ucw.cz> . And yes, I'll try to
find time to test it.

Best regards,

								Pavel
Pavel Machek July 16, 2022, 10:15 a.m. UTC | #2
Hi!

> This series addresses the requirement of mapping multiple V4L2 pixel formats
> to a single libcamera format. Specifically, it allows to map V4L2_PIX_FMT_JPEG
> and V4L2_PIX_FMT_MJPEG to libcamera::formats::MJPEG.
> 
> The series starts by allowing to associate mulitple V4L2 FourCC in
> PixelFormatInfo and re-introduces toV4L2PixelFormat() in V4L2VideoDevice in
> order to select among from the list of V4L2 formats the first one supported
> from the video device.
> 
> Patch [7/8] adds a multiplanar flag to V4L2VideoDevice::toV4L2PixelFormat() to
> allow selection of the contiguous or non-contiguous format versions.
> 
> Finally, the last patch associates V4L2_PIX_FMT_JPEG to formats::MJPEG.
> 
> Tested with a UVC camera.
> 
> Pavel, could you please test on the pinephone please ?

I tried to do quick testing, but it is not trivial as I have to patch
libcamera to get it work on PinePhone at all. I could not get it to
work so far.

Best regards,
								Pavel
Jacopo Mondi July 23, 2022, 10:21 a.m. UTC | #3
Hi Pavel,

On Sat, Jul 16, 2022 at 12:15:20PM +0200, Pavel Machek wrote:
> Hi!
>
> > This series addresses the requirement of mapping multiple V4L2 pixel formats
> > to a single libcamera format. Specifically, it allows to map V4L2_PIX_FMT_JPEG
> > and V4L2_PIX_FMT_MJPEG to libcamera::formats::MJPEG.
> >
> > The series starts by allowing to associate mulitple V4L2 FourCC in
> > PixelFormatInfo and re-introduces toV4L2PixelFormat() in V4L2VideoDevice in
> > order to select among from the list of V4L2 formats the first one supported
> > from the video device.
> >
> > Patch [7/8] adds a multiplanar flag to V4L2VideoDevice::toV4L2PixelFormat() to
> > allow selection of the contiguous or non-contiguous format versions.
> >
> > Finally, the last patch associates V4L2_PIX_FMT_JPEG to formats::MJPEG.
> >
> > Tested with a UVC camera.
> >
> > Pavel, could you please test on the pinephone please ?
>
> I tried to do quick testing, but it is not trivial as I have to patch
> libcamera to get it work on PinePhone at all. I could not get it to
> work so far.
>

Thanks for testing!

Turns out I have a pinephone as well, and I spent the last days trying
to set it up to test libcamera there.

The result is that I have sent a v2 of this series with one additional
patch on top and had to massage the video driver a bit to make it
slightly more compliant with libcamera requirements.

With these two branches:

- postmarket os patches + ov5640 backport + sun6i-csi
https://git.sr.ht/~jmondi_/linux/log/pinephone/orange-pi-5.17-20220429-1618/postmarketos
- JPEG/MJPEG mapping
https://git.sr.ht/~jmondi_/libcamera/log/jmondi/pinephone

I'm able to capture from ov5640 in YUYV and JPEG formats in different
resolutions:
$ cam -c2 -C --stream pixelformat=YUYV,width=640,height=480
$ cam -c2 -C --stream pixelformat=MJPEG,width=1920,height=1080 -F

I've been able to inspect the YUYV image and they're ok, the JPEG one
can't be opened with my viewer and I've not investigated why. I recall
I tested JPEG with the ov5640 driver in a CSI-2 setup and it worked.
Not sure if the sun6i csi receiver plays a role here ?

Anyway, I tried NV12 and it fails because of a wrong plane mapping.
Haven't investigated yet but I presume it's because we map NV12 to the
contiguous planar format version. The JPEG/MJPEG series would help
mapping formats::NV12 to the right V4L2 format version, but I haven't
done that it yet.

Capturing in full resolution doesn't work. The sensor hangs and I
presume it is because of the sensor driver. The long list of changes
now upstreamed for the ov5640 sensor modes only apply to CSI-2 setups,
as I haven't got a parallel setup to test with at the time. The series
has been tested on a parallel setup by other media developers and no
breakages were reported, but the fact the sensor hangs makes me think
it's driver's fault.

Hope this serves as a base for further investigations!

Thanks
   j

> Best regards,
> 								Pavel
> --
> People of Russia, stop Putin before his war on Ukraine escalates.
Pavel Machek July 23, 2022, 6 p.m. UTC | #4
Hi!

> Thanks for testing!
> 
> Turns out I have a pinephone as well, and I spent the last days trying
> to set it up to test libcamera there.

Nice!

> The result is that I have sent a v2 of this series with one additional
> patch on top and had to massage the video driver a bit to make it
> slightly more compliant with libcamera requirements.
> 
> With these two branches:
> 
> - postmarket os patches + ov5640 backport + sun6i-csi
> https://git.sr.ht/~jmondi_/linux/log/pinephone/orange-pi-5.17-20220429-1618/postmarketos
> - JPEG/MJPEG mapping
> https://git.sr.ht/~jmondi_/libcamera/log/jmondi/pinephone
> 
> I'm able to capture from ov5640 in YUYV and JPEG formats in different
> resolutions:
> $ cam -c2 -C --stream pixelformat=YUYV,width=640,height=480
> $ cam -c2 -C --stream pixelformat=MJPEG,width=1920,height=1080 -F

> I've been able to inspect the YUYV image and they're ok, the JPEG one
> can't be opened with my viewer and I've not investigated why. I recall
> I tested JPEG with the ov5640 driver in a CSI-2 setup and it worked.

JPEG works for me. At some resolution/fps setting I was getting
corruption in YUYV (?), and there JPEG got corrupted, too.

> Capturing in full resolution doesn't work. The sensor hangs and I
> presume it is because of the sensor driver. The long list of changes
> now upstreamed for the ov5640 sensor modes only apply to CSI-2

This worked for me:

#build/src/cam/cam  -c /base/i2c-csi/rear-camera@4c  -spixelformat=JPEG,width=2592,height=1944 --sdl -C20 -F/tmp/delme.#

frame_interval was 10 iirc. This, too:

#build/src/qcam/qcam -r gles -spixelformat=SBGGR8,width=2592,height=1944 -c /base/i2c-csi/rear-camera@4c

SBGGR8 works for me at high resolutions, while YUYV works at low
resolutions. I have to adjust frame_interval for some stuff to work.

Best regards,
								Pavel