Commit graph

3842 commits

Author SHA1 Message Date
Tomi Valkeinen
bf3dbaece9 py: Switch to non-blocking eventfd
Blocking wait can be easily implemented on top in Python, so rather than
supporting only blocking reads, or supporting both non-blocking and
blocking reads, let's support only non-blocking reads.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:28 +03:00
Tomi Valkeinen
de7f1aa591 py: Use libcamera's Mutex classes
Use libcamera's Mutex and MutexLocker instead of the std versions to get
thread safety annotations.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:26 +03:00
Tomi Valkeinen
dfa86000a6 py: Set EFD_CLOEXEC on eventfd to avoid fd leaking
Set EFD_CLOEXEC on eventfd to avoid fd leaking.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:24 +03:00
Tomi Valkeinen
f4933ee77f py: Use UniqueFD
Use UniqueFD to automate the eventfd lifetime management.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:21 +03:00
Tomi Valkeinen
f814b1b6a9 py: Create PyCameraManager
Wrap the CameraManager with a PyCameraManager class and move the related
code inside the new class.

This helps understanding the life times of the used-to-be global
variables, gets rid of static handleRequestCompleted function, and
allows us to simplify the binding code as the more complex pieces are
inside the class.

There should be no user visible functional changes.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:18 +03:00
Tomi Valkeinen
418cbde04b py: meson: Use libcamera_private dependency
We define -DLIBCAMERA_BASE_PRIVATE to get access to libcamera private
headers, but the correct way to do this is to have a meson dependency to
libcamera_private.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:09 +03:00
Tomi Valkeinen
36ea10a564 py: cam.py: Remove todo comment
The comment is no longer valid.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-18 22:02:07 +03:00
Tomi Valkeinen
4bd2d5191c py: Move ControlValue helpers to py_helpers.cpp
Clean up the py_main.cpp a bit by moving the ControlValue helpers to a
separate file.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-18 22:00:46 +03:00
Tomi Valkeinen
a7f73dd096 py: Add Python logging category
Add Python logging category, and use it in handleRequestCompleted().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-18 22:00:43 +03:00
Tomi Valkeinen
93629989a9 py: cam.py: Fix multi camera capture without -C
-C flag is supposed to affect only the camera that was previously
defined in the arguments. That's not the case, and, e.g.:

cam.py -c2 -C -c3

causes camera 3 to start capturing, but it stops after the initial
Requests have been completed.

Fix the issue by filtering out camera contexts that do not have -C
defined.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-18 22:00:39 +03:00
Laurent Pinchart
777b0e0a65 libcamera: base: Make message.h and mutex.h private
The message.h and mutex.h headers are not used in the libcamera public
API. Make them private to avoid there usage in applications, and to
prevent having to maintain them with a stable ABI.

As mutex.h is used by libcamerasrc, the GStreamer element must switch
from the libcamera_public to the libcamera_private dependency.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-16 14:53:34 +03:00
Laurent Pinchart
b954deff20 meson: Use dependency() instead of find_library() where possible
Usage of find_library() to find dependencies that libcamera needs to
compile against can lead to the library being found even if the
corresponding headers are not installed. This will then result in a
compilation failure. Switch to dependency() for libdw, libunwind and
lttng-ust to fix this, all three libraries come with a pkgconfig file
that is usually installed by the distribution package that contains the
library headers.

Reported-by: Christian Rauch <Rauch.Christian@gmx.de>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-16 14:53:25 +03:00
Laurent Pinchart
dfc6d711c9 libcamera: Allow concurrent use of cameras from same pipeline handler
libcamera implements a pipeline handler locking mechanism based on
advisory locks on media devices, to prevent concurrent access to cameras
from the same pipeline handler from different processes (this only works
between multiple libcamera instances, as other processes won't use
advisory locks on media devices).

A side effect of the implementation prevents multiple cameras created by
the same pipeline handler from being used concurrently. Fix this by
turning the PipelineHandler lock() and unlock() functions into acquire()
and release(), with a use count to replace the boolean lock flag. The
Camera class is updated accordingly.

As a consequence of this change, the IPU3 pipeline handler will fail to
operate properly when the cameras it exposes are operated concurrently.
The android.hardware.camera2.cts.MultiViewTest#testDualCameraPreview
test fails as a result. This should be fixed in the IPU3 pipeline
handler to implement mutual exclusion between cameras.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
2022-08-10 20:33:28 +03:00
Jacopo Mondi
434edb7b44 libcamera: formats: Fix warning for unknown V4L2 pixfmt
Commit f25ad4a2b1 ("libcamera: formats: Reimplement V4L2
PixelFormatInfo::info()") changed the PixelFormatInfo::info(const
V4L2PixelFormat &format) function overload to:

	return info(format.toPixelFormat());

As part of the series that contains such commit, the PixelFormatInfo for the
pixel format applied to a video device is now retrieved at
V4L2VideoDevice::open() time. Some video devices register formats not
available to applications, for example metadata formats or, in the case
of ISP devices, formats to describe the ISP statistics and parameters.

This causes the

	format.toPixelFormat()

call to output a WARN message, which spams the log and unnecessarily alerts
the users.

Augment V4L2PixelFormat::toPixelFormat() with an optional argument to
suppress warnings in the case a V4L2 pixel format is not known, to
restore the behaviour preceding commit f25ad4a2b1 and returns an
invalid PixelFormatInfo without outputting any unnecessary warning
message.

Fixes: f25ad4a2b1 ("libcamera: formats: Reimplement V4L2 PixelFormatInfo::info()")
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-08-10 09:33:30 +02:00
Laurent Pinchart
e1ca213609 ipa: ipu3: Add YAML tuning file support
Replace the manual instantiation of algorithms with an automatic
mechanism based on a tuning data file, provided by the Module base
class. This brings the IPU3 IPA module in line with the RkISP1 IPA
module.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 22:46:23 +03:00
Laurent Pinchart
d1ea82aff9 ipa: ipu3: Register algorithms
To prepare for dynamic instantiation of algorithms from the tuning file,
register the algorithms with the Module class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 22:46:21 +03:00
Laurent Pinchart
639d14e5d3 ipa: ipu3: Add an uncalibrated.yaml tuning data file
Add a tuning data file for uncalibrated sensors, picked by the pipeline
handler when no sensor-specific tuning file is available. The file lists
the 5 algorithms currently instantiated by the IPA module.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 22:46:19 +03:00
Laurent Pinchart
56555b22c3 pipeline: ipu3: Support IPA tuning file
Pass the path name of the YAML IPA tuning file to the IPA module. The
file name is derived from the sensor name ("${sensor_name}.yaml"), with
a fallback to "uncalibrated.yaml".

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 22:46:11 +03:00
Laurent Pinchart
1a6c7477fd libcamera: yaml_parser: Return nullopt on error from YamlObject::get()
The YamlParser::get<>() function returns an std::optional<> to indicate
when YAML parsing failed.

The current implementation returns a default constructed std::optional
in case of errors with

        return {};

This has been reported as generating compiler warnings with a gcc 9.3.0
arm64 cross-compiler:

../src/libcamera/yaml_parser.cpp:184:11: error: ‘<anonymous>’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  184 |   return {};
      |           ^

Replace this with an explicit

	return std::nullopt;

which fixes the warnings and conveys the purpose more explicitly.

Reported-by: Christian Rauch <Rauch.Christian@gmx.de>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-09 22:22:17 +03:00
Laurent Pinchart
1590e9b2b8 cam: sdl_texture: Rename 'pitch' to 'stride'
The libcamera public API uses 'stride' to refer to the line stride.
Rename the SDLTexture::pitch_ member variable for consistency.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-09 21:15:47 +03:00
Daniel Semkowicz
768f1138e9 ipa: rkisp1: Remove unused algorithms includes from rkisp1.cpp
Algorithms are now created dynamically basing on tuning file, so there
is no longer dependency on specific algorithms.

Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-09 17:03:28 +03:00
Laurent Pinchart
fe67032471 libcamera: Make IPA module signing recommended instead of mandatory
Commit b382f67c83 ("libcamera: Make IPA module signing mandatory for
the meantime") made openssl and gnutls dependencies mandatory to work
around the lack of proper IPA module isolation support, which broke
operation without module signatures. This has now been fixed, so IPA
module isolation isn't strictly required anymore.

There are few use cases for disabling module signing completely, given
that the openssl or gnutls dependencies are available on the vast
majority of systems and the overheard introduced by isolating all IPA
modules when signatures are not available is better avoided.
Nonetheless, libcamera should operate properly with forced IPA module
isolation, so we can support those use cases.

Adopt a middle-ground approach to avoid unintentional isolation by
documenting the dependencies as recommended, and warn at meson setup
time if they are not found.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 16:05:58 +03:00
Laurent Pinchart
12f48aa65e libcamera: pub_key: Support openssl as an alternative to gnutls
Support verify IPA signatures with openssl as an alternative to gnutls,
to offer more flexibility in the selection of dependencies. Use gnutls
by default, for no specific reason as both are equally well supported.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 16:05:58 +03:00
Laurent Pinchart
bedef55d95 libcamera: pub_key: Gracefully handle failures to load public key
If the public key fails to load, PubKey::isValid() function returns
false. The only user of the PubKey class, the IPAManager class, doesn't
check that condition, and still calls the PubKey::verify() function,
which leads to a crash.

Fix this by returning false from PubKey::verify() if the key isn't
valid, and log a warning in the IPAManager constructor to report the
issue.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 16:05:58 +03:00
Laurent Pinchart
ea8ff99dca libcamera: meson: Use dependency() to find gnutls
The gnutls library ships a pkgconfig .pc file. Use the standard
dependency() method to locate it, instead of cc.find_library().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 16:05:58 +03:00
Christian Rauch
09c1b081ba libcamera: controls: Generate and use fixed-sized Span types
Define Span types explicitly as either variable- or fixed-sized. This
introduces a new convention for defining Span dimensions in the property
and control value definitions and generates Span types as variable-sized
Span<T> or as fixed-sized Span<T,N>.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-09 13:53:29 +03:00
Laurent Pinchart
293e23e21c cam: kms_sink: Scale the frame buffer to full screen if supported
The KMS sink currently displays the frame buffer on the top-left corner
of the screen, resulting in either a black area on the bottom and right
sides (if the frame buffer is smaller than the display resolution) of in
a restricted field of view (if the frame buffer is larger than the
display resolution). Improve this by scaling the frame buffer to full
screen if supported, and aligning the crop rectangle to the frame buffer
center if the field of view needs to be restricted.

The implementation test for possible composition options, from best to
worst. The tests are performed when the camera is started, as testing
atomic commits requires access to frame buffer objects, which are not
available at configure time. Changing this would require either a large
refactoring of the cam application to provide frame buffers earlier, or
extending the KMS API to support testing commits with dummy buffer
objects. Both are candidates for later development.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 02:31:12 +03:00
Laurent Pinchart
96a5c69970 cam: kms_sink: Make lifetime management of DRM request safer
The drmRequest is KMSSink::processRequest() is created as a naked
pointer, passed to the constructor of the KMSSink::Request object that
stores it in a std::unique_ptr<>, and used later in the function. The
current implementation is safe, but could be prone to both memory leaks
and use-after-free bugs if modified. Improve it by replacing the naked
pointer with a std::unique_ptr<>.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 02:31:10 +03:00
Laurent Pinchart
9165b5973c cam: drm: Add support for test-only commits
Test-only commits are used to test a commit without applying any
modification to the device. This will be used by the KMS sink to test
feature support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-09 02:30:59 +03:00
Laurent Pinchart
fe8941d7d6 cam: sdl_sink: Fix compilation with SDL2 <2.0.16
The SDL_UpdateNVTexture() function, used for NV12 texture support, has
been introduced in SDL2 2.0.16. Compiling against older SDL versions
fails with

../src/cam/sdl_texture_yuv.cpp: In member function ‘virtual void SDLTextureNV12::update(const std::vector<libcamera::Span<const unsigned char> >&)’:
../src/cam/sdl_texture_yuv.cpp:19:2: error: ‘SDL_UpdateNVTexture’ was not declared in this scope; did you mean ‘SDL_UpdateYUVTexture’?
   19 |  SDL_UpdateNVTexture(ptr_, &rect_, data[0].data(), pitch_,
      |  ^~~~~~~~~~~~~~~~~~~
      |  SDL_UpdateYUVTexture

Fix it with conditional compilation based on the SDL version.

Fixes: 7b8df9fe6b ("cam: sdl_sink: Add NV12 texture support")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
2022-08-08 22:39:35 +03:00
Laurent Pinchart
7b8df9fe6b cam: sdl_sink: Add NV12 texture support
Extend the SDL sink with support for NV12 textures, useful on platforms
that don't support packed YUYV formats.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-08 17:53:42 +03:00
Laurent Pinchart
d4a42894b1 cam: sdl_sink: Support multi-planar formats
In order to prepare for NV12 support, implement support for multi-planar
formats in the SDL sink. This mainly consists in passing a vector of
plane data to the SDLTexture::update() function instead of a single
value.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-08 17:25:02 +03:00
Laurent Pinchart
3e0b3a1077 cam: Rename sdl_texture_yuyv.{cpp,h} to sdl_texture_yuv.{cpp,h}
In preparation for the addition of NV12 support in the SDL sink, rename
the sdl_texture_yuyv.{cpp,h} files to just "yuv". Separate
sdl_texture_nv12.{cpp,h} files could be added instead, but given how
short the implementation will be, grouping all YUV formats in a single
file is better.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-08 17:14:04 +03:00
Laurent Pinchart
4b6e624e6a cam: sdl_texture_yuyv: Make line stride configurable
The line stride of the texture is currently hardcoded based on the image
width, which may not match the real stride. Use the stride value from
the stream configuration instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-08 17:13:17 +03:00
David Plowman
26c82ce136 libcamera: Correct typos and omissions for packed 10-bit raw monochrome format
One typo is corrected, and this format is added to one further table
where it was missing entirely.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-04 21:43:32 +03:00
Laurent Pinchart
73570c0637 libcamera: Switch internal YAML files to YAML 1.1
The python3-yaml package (containing the PyYAML Python package) shipped
by Debian stable is documented as a YAML 1.1 parser:

    Python3-yaml is a complete YAML 1.1 parser and emitter for Python3.

PyYAML doesn't implement YAML 1.2 support, but ignores the minor number
of the YAML directive, and thus doesn't choke on the libcamera internal
files used to generate format- and control-related source code that
explicitly state conformance with YAML 1.2. Still, given that we don't
use any feature of YAML 1.2, and that the tuning data files now use YAML
1.1, switch the internal YAML files to version 1.1 as well for
consistency.

The main drawback of YAML 1.1 is that the unquoted literal strings Yes,
No, On and Off will be parsed as booleans. We need to be careful to
avoid those values in YAML files, until libcamera can switch to YAML 1.2
once more recent versions of libyaml get shipped by the distributions we
want to support. This is however not an issue introduced by this change,
as the existing YAML 1.2 files were parsed with the YAML 1.1 string
literal parsing rules anyway.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-04 18:48:27 +03:00
Laurent Pinchart
a55f9c34a7 ipa: rkisp1: Use YAML 1.1 for tuning data files
YAML 1.2 support has been added in libyaml in version 0.2.3. Debian
stable ships version 0.2.2 of libyaml, which causes parse errors of the
tuning tuning data files due to the YAML 1.2 directive at the beginning.
As we don't use any feature of YAML 1.2, downgrade the data files to
YAML 1.1.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-04 18:33:03 +03:00
Laurent Pinchart
961a6cf7ca pipeline: rkisp1: Move ControlInfoMap to IPA module
Currently the pipeline handler advertises controls handled by the IPA
from a ControlInfoMap it manually constructs. This is wrong, as the IPA
module is the component that knows what controls it supports. Fix this
by moving the ControlInfoMap construction to the IPA module, and pass it
to the pipeline handler as a return value from the IPA init() function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Florian Sylvestre <fsylvestre@baylibre.com>
2022-08-04 01:14:13 +03:00
Laurent Pinchart
502ab9a146 libcamera: pipeline: simple: Add support for NXP ISI
Several NXP i.MX8 SoCs (such as the i.MX8MN and i.MX8MP) contain a
camera pipeline made of sensor interfaces (with parallel and/or CSI-2
receivers) and an image processing engine named ISI. The ISI contains an
input crossbar switch and one or more processing pipelines capable of
format conversion and scaling.

This is a good candidate for the simple pipeline handler as a first
step. The i.MX8MP should eventually graduate to having its own pipeline
handler as it also contains two ISP instances (supported by the rkisp1
driver).

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:44:34 +03:00
Laurent Pinchart
83996258a9 libcamera: pipeline: simple: Don't disable links carrying other streams
If a subdev supports the internal routing API, pads unrelated to the
pipeline for a given camera sensor may carry streams for other cameras.
The link setup logic is updated to take this into account, by avoiding
disabling links to unrelated pads.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:44:34 +03:00
Phi-Bang Nguyen
3ee52c167f libcamera: pipeline: simple: Walk pipeline using subdev internal routing
When traversing the media graph to discover a pipeline from the camera
sensor to a video node, all sink-to-source paths inside subdevs are
considered. This can lead to invalid paths being followed, when a subdev
has restrictions on its internal routing.

The V4L2 API supports exposing subdev internal routing to userspace.
Make use of this feature, when implemented by a subdev, to restrict the
internal paths to the currently active routes. If a subdev doesn't
implement the internal routing operations, all source pads are
considered, as done today.

This change is needed to properly support multiple sensors with devices
such as the NXP i.MX8 ISI or the MediaTek i350 and i500 SENINF. Support
for changing routes dynamically will be added later when required.

Signed-off-by: Phi-Bang Nguyen <pnguyen@baylibre.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:44:34 +03:00
Laurent Pinchart
bd25118dec libcamera: pipeline: simple: Setup links in the context of sink entities
To setup links the pipeline handler iterates over all entities in the
pipeline and disables all links but the ones we want to enable. Some
entities don't allow multiple sink links to be enabled, so the iteration
needs to be based on sink entities, disabling all their links first and
then enabling the sink link that is part of the pipeline.

The loop implementation iterates over all Entity instances, and uses
their source link to locate the MediaEntity for the connected sink. The
sink entity is then processed in the context of the source's loop
iteration. This prevents the code from being able to access extra
information about the sink entity, as we only have access to the
MediaEntity, not the Entity.

To prepare for subdev routing support that will require accessing
additional entity information, refactor the loop to process the sink
entity in the context of its Entity instance.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:44:34 +03:00
Jacopo Mondi
fe9c22c8b1 libcamera: pipeline: simple: Reset routing table of subdevs
Reset the routing table of subdevices supporting the V4L2 streams API to
its default state when initializing the pipeline handler. This avoids
issues caused by usage of leftover state.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:44:34 +03:00
Jacopo Mondi
495aac658d libcamera: v4l2_subdevice: Add support for the V4L2 subdev routing API
Extend the V4L2Subdevice class to support getting and setting routing
tables.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:44:28 +03:00
Jacopo Mondi
39d4917619 libcamera: v4l2_subdevice: Collect subdev capabilities
Collect subdev capabilities at open() time.

Model the V4L2SubdevCapabilties as V4L2Capability from the video
device class.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-08-03 17:42:59 +03:00
Jacopo Mondi
8695e02916 libcamera: v4l2_subdevice: Change V4L2Subdevice::Whence
The V4L2Subdevice::Whence enumerations defines two values that should
correspond to the V4L2_SUBDEV_FORMAT_ACTIVE and V4L2_SUBDEV_FORMAT_TRY
definitions.

The V4L2 symbols are defined as:

	V4L2_SUBDEV_FORMAT_TRY = 0,
	V4L2_SUBDEV_FORMAT_ACTIVE = 1,

While the libcamera defined enumeration is:

	enum Whence {
		ActiveFormat,
		TryFormat,
	}

As V4L2Subdevice::Whence values are used to populate data types
defined in v4l2-subdev.h used as arguments to VIDIOC_SUBDEV_*
ioctls, the V4L2Subdevice class is required to adjust their value as:

       subdevFmt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE
                       : V4L2_SUBDEV_FORMAT_TRY;

Drop the adjustment by defining :

	Whence::TryFormat = V4L2_SUBDEV_FORMAT_TRY;
	Whence::ActiveFormat = V4L2_SUBDEV_FORMAT_ACTIVE;

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-03 17:08:34 +03:00
Laurent Pinchart
f676bf2403 include: linux: Add V4L2 subdev internal routing API
The V4L2 subdev internal routing API is under development. Add it
manually to the v4l2-subdev.h kernel header for now.

The code corresponds to the "[PATCH v11 00/36] v4l: routing and streams
support" series as posted to the linux-media mailing list.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:00:46 +03:00
Laurent Pinchart
441fa90879 libcamera: formats: Add AVUY8888 and XVUY8888 formats
Add missing 32-bit packet YUV 4:4:4 formats. These formats are used by
the i.MX8 ISI driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 17:00:46 +03:00
Laurent Pinchart
03b4293025 include: linux: Add V4L2 YUVA32 and YUVX32 pixel formats
These YUV 4:4:4 packed formats are used by the ISI driver. Add them to
videodev2.h.

This is merged in the upstream kernel as 00f6842ef41d ("media: v4l: Add
packed YUV 4:4:4 YUVA and YUVX pixel formats").

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 16:59:37 +03:00
Laurent Pinchart
c1a38a4191 include: drm_fourcc: Add AVUY and XVUY 4:4:4 packet formats
Add FourCCs for the YUV 4:4:4 packed formats AVUY8888 and XVUY8888.

This is merged in the upstream kernel as 53618649ca6d ("drm/fourcc: Add
formats for packed YUV 4:4:4 AVUY and XVUY permutations").

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-08-03 16:59:16 +03:00