[libcamera-devel] [PATCH v2 0/7] Introduce formats:: namespace for libcamera pixel formats

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Jun 10 01:23:16 CEST 2020


Hello,

This patch series is an attempt to fix a problem caused by a direct
dependency on drm_fourcc.h in the libcamera public API.

libcamera specifies pixel formats using the DRM pixel format FourCC and
modifiers. This requires both internal code and applications to include
drm_fourcc.h. For internal code, we carry a copy of the header to avoid
external dependencies. For third-party applications, however,
drm_fourcc.h needs to be accessible from system includes. It turns out
that the file is shipped by two different packages:

- libdrm, which typically installs it in /usr/include/libdrm/
- kernel headers or libc headers, which typically installs it in
  /usr/include/drm

We don't want to make libdrm a dependency for applications using
libcamera. Unfortunately, depending on drm_fourcc.h being provided by
the distribution kernel headers or libc headers package causes issues,
as not all distributions install the header in /usr/include/drm/. Ubuntu
and Gentoo do, but Debian and Arch don't.

The best option may be to remove the dependency on the macros provided
by drm_fourcc.h, while keeping the pixel format numerical values
identical. This is what this patch series attempts to do.

Patch 1/7 creates a new libcamera::formats:: namespace and populates it
with constants (in the form of constexpr) for all supported pixel
formats. The values are automatically generated from a list of formats,
stored in formats.yaml, and the numerical values for the DRM FourCCs and
modifiers are extracted from drm_fourcc.h.

Patches 2/7 to 7/8 then replace usage of the DRM_FORMAT_* macros through
the code.

Laurent Pinchart (7):
  libcamera: Define constants for pixel formats in the public API
  gst: Replace explicit DRM FourCCs with libcamera formats
  qcam: Replace explicit DRM FourCCs with libcamera formats
  v4l2: Replace explicit DRM FourCCs with libcamera formats
  test: Replace explicit DRM FourCCs with libcamera formats
  libcamera: pipeline: Replace explicit DRM FourCCs with libcamera
    formats
  libcamera: Replace explicit DRM FourCCs with libcamera formats

 include/libcamera/formats.h.in                |  44 ++++++
 include/libcamera/gen-formats.py              | 118 ++++++++++++++
 include/libcamera/meson.build                 |  22 +++
 include/libcamera/pixel_format.h              |   2 -
 src/android/camera_device.cpp                 |   9 +-
 src/gstreamer/gstlibcamera-utils.cpp          |  62 ++++----
 src/libcamera/formats.cpp                     | 148 +++++++++---------
 src/libcamera/formats.yaml                    | 124 +++++++++++++++
 src/libcamera/pipeline/ipu3/ipu3.cpp          |  16 +-
 .../pipeline/raspberrypi/raspberrypi.cpp      |  10 +-
 src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  19 +--
 src/libcamera/pipeline/vimc/vimc.cpp          |  11 +-
 src/libcamera/pixel_format.cpp                |   4 +-
 src/libcamera/v4l2_pixelformat.cpp            |  83 +++++-----
 src/qcam/dng_writer.cpp                       |  17 +-
 src/qcam/format_converter.cpp                 |  36 +++--
 src/qcam/viewfinder.cpp                       |  10 +-
 src/v4l2/v4l2_camera_proxy.cpp                |  29 ++--
 test/v4l2_videodevice/buffer_cache.cpp        |   3 +-
 19 files changed, 540 insertions(+), 227 deletions(-)
 create mode 100644 include/libcamera/formats.h.in
 create mode 100755 include/libcamera/gen-formats.py
 create mode 100644 src/libcamera/formats.yaml

-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list