Commit graph

4263 commits

Author SHA1 Message Date
Jacopo Mondi
ad1cd9e33f libcamera: imx8-isi: Remove mbusCode from formatsMap_
Now that the media bus code selection procedure does not depend
on the ISICameraConfiguration::formatsMap_ remove the association
between PixelFormat supported by the ISI and the media bus code produced
by the sensor.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Tested-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-30 18:42:03 +02:00
Jacopo Mondi
680cde6005 libcamera: imx8-isi: Split Bayer/YUV config generation
At generateConfiguration() a YUV/RGB pixel format is preferred for the
StillCapture/VideoRecording/Viewfinder roles, but currently there are no
guarantees in place that the sensor provides a non-Bayer bus format from
which YUV/RGB can be generated.

This makes the default configuration generated for those roles not to
work if the sensor is a RAW-only one.

To improve the situation split the configuration generation in two,
one for YUV modes and one for Raw Bayer mode.

StreamRoles assigned to a YUV mode will try to first generate a YUV
configuration and then fallback to RAW if that's what the sensor can
provide.

As an additional requirement, for YUV streams, the generated mode has to
be validated with the sensor to confirm the desired sizes can be
generated as the ISI cannot up-scale. In order to test a format use the
newly introduced CameraSensor::tryFormat().

Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Tested-by: Daniel Scally <dan.scally@ideasonboard.com>
2023-04-30 18:41:17 +02:00
Jacopo Mondi
608af3127c libcamera: camera_sensor: Add tryFormat()
Add a function to the CameraSensor class that allows to test a format
without applying it to the subdevice and without modifying any control
value associated with the camera sensor.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-30 18:40:19 +02:00
Jacopo Mondi
14995410fe libcamera: imx8-isi: Automatically select media bus code
The ISICameraConfiguration::validate() function selects which media
bus format to configure the sensor with based on the pixel format
of the first configured stream using the media bus code associated to it
in the formatsMap_ map.

In order to remove the PixelFormamt-to-mbus-code association in
formatsMap_ provide a wrapper function for the newly introduced
getRawMediaBusFormat() and getYuvMediaBusFormat() that automatically
selects what media bus format to use based on the first stream pixel
format.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Tested-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-30 18:40:18 +02:00
Jacopo Mondi
dd78f2f8ad libcamera: imx8-isi: Break out YUV format selection
As per the RAW format selection, the media bus format selection
procedure relies on the direct association of PixelFormat and media
bus code in the formatsMap_ map.

As the ISI can generate YUV and RGB formats from any non-Bayer media
bus format, break out the YUV/RGB media bus format selection to a
separate function.

The newly introduced getYuvMediaBusFormat() tests a list of
known-supported media bus formats against the list of media bus
formats supported by the sensor and tries to prefer media bus
codes with the same encoding as the requested PixelFormat.

Use the newly introduced function in
ISICameraConfiguration::validateYuv() to make sure the sensor can
produce a YUV/RGB media bus format.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Tested-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-30 18:40:18 +02:00
Jacopo Mondi
87fed43253 libcamera: imx8-isi: Break out RAW format selection
The current implementation of the ISI pipeline handler handles
translation of PixelFormat to media bus formats from the sensor
through a centralized map.

As the criteria to select the correct media bus code depends on if the
output PixelFormat is a RAW Bayer format or not, start by splitting
the RAW media bus code procedure selection out by adding a function
for such purpose to the ISICameraData class.

Add the function to the ISICameraData and not to the
ISICameraConfiguration because:
- The sensor is a property of CameraData
- The same function will be re-used by the ISIPipelineHandler
  during CameraConfiguration generation.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Tested-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-30 18:40:18 +02:00
Barnabás Pőcze
701b201cf3 Documentation: guides: pipeline-handler: Fix spelling error
Both {Camera,PipelineHandler}::generateConfiguration() take a list
of `StreamRole` objects, and not a list of `StreamRoles` objects.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-28 15:21:24 +03:00
Umang Jain
e191001939 apps: cam: kms_sink: Drop unique_ptr<> from DRM::AtomicRequest
There is no need to wrap DRM::AtomicRequest in std::unique_ptr<>
in KMSSink::start(). Remove it so that the syntax becomes similar to
what we have in KMSSink::stop().

No functional changes intended.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-26 12:07:03 +05:30
Mattijs Korpershoek
683c6da83f test: controls: control_info_map: Test default constructor
ControlInfoMap can be default-constructed. In that case, some of its
members (like idmap_) can be a nullptr, and ControlInfoMap.find() will segfault.

Add a test with a default constructed ControlInfoMap to cover this.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-04-20 10:54:12 +01:00
Mattijs Korpershoek
3dc2605bda libcamera: controls: guard ControlInfoMap against nullptr idmap_
It's possible to construct a Camera with an unsafe controlInfo_.
This is the case in the Simple pipeline, where the camera controls are
not populated.

With Simple, if we attempt to set a Control, we end up with a segfault
because the default constructor for ControlInfoMap doesn't
intialized idmap_ which is initialized at class declaration time as

  const ControlIdMap *idmap_ = nullptr;

Add some safeguards in ControlInfoMap to handle this case.

Link: https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html
Suggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-04-20 10:54:12 +01:00
Barnabás Pőcze
46852241a3 libcamera: device_enumerator_udev: Use std::string_view
In `udevNotify()`, constructing an std::string from the device's
associated action is unnecessary as it is only compared against static
strings, and for that purpose an std::string_view works just as well,
while being cheaper to construct.

In the same vein, an std::string_view can be used to store the device's
devnode initially, and the string construction can be deferred until it
is needed.

Furthermore, previously `udev_device_get_devnode()` was called twice.
The extra call is now removed.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-19 11:04:31 +03:00
Jacopo Mondi
e0a51061bc libcamera: formats: Add 14-bits Bayer RAW formats
Add formats definition and mappings for 14-bits Bayer RAW formats.

Add definitions for non-packed and CSI-2 packed variants.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
2023-04-18 17:28:39 +02:00
Barnabás Pőcze
f99b0f7f8f libcamera: device_enumerator_udev: Remove devnum from dependency map
Previously, after `addV4L2Device()` had seen all dependecies, it would
remove the `MediaDeviceDeps` object from the `pending_` list, which
would result in it being destroyed. However, there would still be
(dangling) pointers to this object in `devMap_` that were added in
`addUdevDevice()` (line 103). So remove the entry with the given devnum
when it is removed from the corresponding `MediaDeviceDeps` object.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-18 10:41:51 +03:00
David Plowman
98fc381c68 ipa: raspberrypi: agc: Add "shadows" constraint mode
The "shadows" constraint mode actually exists in a number of tuning
files, but had been omitted from the list of supported modes.

Signed-off-by: David Plowman <david.plowman@raspberrypi.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>
2023-04-12 12:00:43 +03:00
Harvey Yang
c1cc37b2ee utils: ipc: Update parser.py
Make the local mojom library the first priority in the sys path, to
avoid mixing the local one with the system one in build.

Tested on chromebook soraka-libcamera.

Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-04-05 08:24:11 +03:00
Gabby George
44eed506c2 doc: ipa: Clarify IPA acronym in its namespace description
Clarify IPA's acronym by specifying what "IPA" stands for as part of the
ipa namespaces' "brief" doxygen-generated description. This allows
visitors to the docs to immediately have an idea of the purpose of the
IPA namespace at a glance. Because of the prevalence and importance of
the IPA namespace and functionality, the fact that it stands for "Image
Processing Algorithm" should be accessible to even casual perusers of
the docs.

Signed-off-by: Gabby George <gabbymg94@gmail.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>
2023-04-05 08:24:11 +03:00
Laurent Pinchart
436b38fd89 libcamera: Open files with O_CLOEXEC
Files opened internally in libcamera without the O_CLOEXEC file will
remain open upon a call to one of the exec(3) functions. As exec()
doesn't destroy local or global objects, this can lead to various side
effects. Avoid this by opening file descriptors with O_CLOEXEC for all
internal files.

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>
2023-04-05 07:18:30 +03:00
Laurent Pinchart
4cd9cb4a90 meson: Really fix git version parsing
The previous attempt to fix git version parsing in commit d34cefad17
("meson: Fix git version parsing") was too naive, and didn't take into
account cases where the libcamera git version contains no or multiple
'+' signs.

Fixing this is more complex than a one-liner change, as meson doesn't
support Python-style slicing of arrays or a length method on strings.
The simplest and most versatile option is to patch the version string in
the gen-version.sh script. Do so, and clarify the comments related to
version handling in meson.build.

Fixes: d34cefad17 ("meson: Fix git version parsing")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2023-04-05 07:16:07 +03:00
Naushir Patuck
ac7511dc4c ipa: raspberrypi: Generalise the focus reporting code
Use the generalised focus statistics structure to compute the centre
window focus FoM value. This avoids needed to hard-code a specific
grid size.

Remove the focus reporting algorithm as the functionality is duplicated
by this bit of IPA code. Remove focus_status.h as it is no longer needed.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
Nick Hollinghurst
43f57f26b4 ipa: raspberrypi: Generalise the autofocus algorithm
Remove any hard-coded assumptions about the target hardware platform
from the autofocus algorithm. Instead, use the "target" string provided
by the camera tuning config and generalised statistics structures to
determing parameters such as grid and region sizes.

Additionally, PDAF statistics are represented by a generalised region
statistics structure to be device agnostic.

These changes also require the autofocus algorithm to initialise
region weights on the first frame's prepare()/process() call rather
than during initialisation.

Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
Naushir Patuck
e51a9f7b94 ipa: raspberrypi: Generalise the agc algorithm
Remove any hard-coded assumptions about the target hardware platform
from the AGC algorithm. Instead, use the "target" string provided by
the camera tuning config and generalised statistics structures to
determing parameters such as grid and region sizes.

This change replaces all hard-coded arrays with equivalent std::vector
types.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
Naushir Patuck
e145decf36 ipa: raspberrypi: Make RegionStats::get() always return a Region struct
Update the overloaded RegionStats::get() and RegionStats::getFloating()
member functions to return a Region struct for consistency.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
Naushir Patuck
d8685a579c ipa: raspberrypi: Generalise the contrast algorithm
Generalise the contrast algorithm code by removing any hard-coded
assumptions about the target hardware platform. Instead, the algorithm
code creates a generic Pwl that gets returned to the IPA, where it gets
converted to the bcm2835 hardware specific lookup table.

As a drive-by, remove an unused mutex.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
David Plowman
a82d08973f ipa: raspberrypi: alsc: Use a better type name for sparse arrays
The algorithm uses the data type std::vector<std::array<double, 4>> to
represent the large sparse matrices that are XY (X, Y being the ALSC
grid size) high but with only 4 non-zero elements on each row.

Replace this slightly long type name by SparseArray<double>.

No functional changes.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
David Plowman
c557de126e ipa: raspberrypi: alsc: Replace std::vectors by Array2D class
The Array2D class is a very thin wrapper round std::vector that can be
used almost identically in the code, but it carries its 2D size with
it so that we aren't passing it around all the time.

All the std::vectors that were X * Y in size (X and Y being the ALSC
grid size) have been replaced. The sparse matrices that are XY * 4 in
size have not been as they are somewhat different, are used
differently, require more code changes, and actually make things more
confusing if everything looks like an Array2D but are not the same.

There should be no change in algorithm behaviour at all.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
Naushir Patuck
af946958da ipa: raspberrypi: Generalise the ALSC algorithm
Remove any hard-coded assumptions about the target hardware platform
from the ALSC algorithm. Instead, use the "target" string provided by
the camera tuning config and generalised statistics structures to
determing parameters such as grid and region sizes.

The ALSC calculations use run-time allocated arrays/vectors on every
frame. Allocating these might add a non-trivial run-time penalty.
Replace these dynamic allocations with a set of reusable pre-allocated
vectors during the init phase.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
Naushir Patuck
f6cc78b446 ipa: raspberrypi: Add hardware configuration to the controller
Add a new Controller::HardwareConfig structure that captures the
hardware statistics grid/histogram sizes and pipeline widths. This
ensures there is a single centralised places for these parameters.

Add a getHardwareConfig() helper function to retrieve these values for a
given hardware target.

Update the statistics populating routine in the IPA to use the values
from this structure instead of the hardcoded numbers.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:18 +01:00
Naushir Patuck
cf6df17958 ipa: raspberrypi Store the target string in the controller
The target string may be used by algorithms to determine the running
hardware target.

Store the target string provided by the camera tuning files in the
controller state. Add a getTarget() member function to retrieve this
string.

Validate the correct hardware target ("bcm2835") during the IPA
initialisation phase.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-31 13:29:17 +01:00
Naushir Patuck
f7bf0be653 ipa: raspberrypi: Fix default frame durations calculation
Fix a bug in the default frame durations calculation where the min/max
values are swapped round. This is a rarely travelled code path, so has
not actually caused a reported failure.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-28 14:12:20 +01:00
Naushir Patuck
6e88911338 ipa: raspberrypi: Ensure shutter speed and gain are clipped in the AGC
Make a copy of the CameraMode structure on a switch mode call. This
replaces the existing lastSensitivity_ field.

Limit the AGC gain calculations to the minimum value given by the
CameraMode structure. The maximum value remains unclipped as any gain
over the sensor maximum will be made up by digital gain.

Rename clipShutter to limitShutter for consistency, and have the latter
limit the shutter speed to both upper and lower bounds.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-28 14:12:18 +01:00
Naushir Patuck
f0b9eaeaa8 ipa: raspberrypi: Use the new sensor limits fields in CameraMode
Use the new analogue gain and shutter speed limit fields in the ipa
code when reporting back the control value limits and calculating the
analogue gain code to use. This also replaces the now unused (and
removed) maxSensorGainCode_ field.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-28 14:11:56 +01:00
Naushir Patuck
d6e85bdfe9 ipa: raspberrypi: Add sensor mode limits to CameraMode
Add fields in the CameraMode structure to capture the mode specific
limits for analogue gain and shutter speed. For convenience, also add
fields for minimum and maximum frame durations.

Populate these new fields when setting up the CameraMode structure.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-28 14:11:41 +01:00
Elias Naur
d942bdc913 libcamera: v4l2_device: openat(2) with O_CLOEXEC to cleanup after exec(3)
When an executable using libcamera calls exec(3) while a camera is in
use, file descriptors corresponding to the V4L2 video devices are kept
open has they have been created without O_CLOEXEC. This results in the
video devices staying busy, preventing the new executable from using
them:

[91] ERROR V4L2 v4l2_videodevice.cpp:1047 /dev/video0[149:cap]: Unableto set format: Resource busy

Fix this by opening video devices with O_CLOEXEC, which is generally a
good idea in libraries.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-03-26 11:48:18 +03:00
Kieran Bingham
e39f046f66 libcamera: camera: Ensure queued requests are invalid
Invalid, or not correctly reset requests can cause undefined behaviour
in the pipeline handlers due to unexpected request state.

If the status has not been reset to Request::RequestPending, it is
either not new, or has not been correctly procesed through
Request::reuse().

This can be caught early by validating the status of the request when it
is queued to a camera.

Reject invalid requests before processing them in the pipeline handlers.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:47:59 +00:00
Kieran Bingham
d9371444c4 meson: libcamera: Report IPA signature method
Use the Configuration section to report which dependency is used to
handle IPA module signatures.

In the event that it is not found, report directly in the configuration
that modules are Isolated.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:45:35 +00:00
Kieran Bingham
ffa3afdd61 ipa: libipa: Add OV2685 Camera Sensor Helper
Provide a CameraSensorHelper for the OV2685, along with the
corresponding camera sensor properties.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:40:41 +00:00
Kieran Bingham
8c0ae95865 ipa: libipa: Add OV5647 Camera Sensor Helper
Provide a CameraSensorHelper for the OV5647 as used in the Raspberry Pi
Camera Module v1.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Christopher Obbard <chris.obbard@collabora.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:34:28 +00:00
Tomi Valkeinen
b3cefd4c0e py: cam: Fix demosaic overflow issue
The demosaic code first expands the buffer datatype to uint16, and then
shifts the data left so that the 8, 10 and 12 bitspp formats all become
16 bitspp.

It then, eventually, uses np.einsum to calculate averages, but this
averaging sums multiple uint16 values together, and stores them in
uint16 storage. As in the first step we shifted the values left,
possibly getting values close to the maximum of uint16 range, we, of
course, overflow when summing them together. This leads to rather bad
looking images.

Fix this by dropping the original shift. It serves no purpose, and is
probably a remnant of some early testing code. This way the largest
numbers we are summing together are 12 bit values, and as we use a 3x3
window from which we fetch values, for a single rgb plane, the max
number of 12 bit values is 5 (for green). Sum of 5 12 bit values is well
below the 16 bit maximum.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:33:43 +00:00
Dave Jones
afc5ea57b4 ipa: raspberrypi: Fix crash under LTO
When compiled with LTO (the default on Ubuntu), the global static
objects camHelpers and algorithms cause a crash in raspberrypi_ipa_proxy
at runtime as they're not allocated by the time the registration
routines execute.

This is a fairly crude fix which just converts the global static objects
into local static objects inside an equivalently named function.

Signed-off-by: Dave Jones <dave.jones@canonical.com>
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:32:10 +00:00
Laurent Pinchart
d34cefad17 meson: Fix git version parsing
When extracting the build metadata from the git version, we use the
string strip() method to remove the version prefix. This is incorrect,
as the strip() method takes a set of characters to be removed, not a
literal string. Fix it by splitting the git version string on the '+'
character and keeping the suffix.

Fixes: 02518e598e ("meson: Rewrite .replace usage")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Michael Riesch <michael.riesch@wolfvision.net>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:30:58 +00:00
Nicolas Dufresne
2ccca099d3 libcamera: base: Make the registration of log categories atomic
Logger::create() is not currently thread safe and causes crashes
noticeable on RaspberryPi 4. This adds a mutex around the creation
of categories.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:30:22 +00:00
Michael Riesch
f852b7fbc4 meson: Align handling of build metadata
The build metadata is split off correctly from the version string
obtained with utils/gen-version.sh, but for the meson project version
this step is not carried out. However, since libcamera uses Semantic
Versioning, it should be possible to add build metadata to the meson
project version. Align the handling of the build metadata to resolve
this mismatch.

Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
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>
2023-03-09 18:41:16 +02:00
Suhrid Subramaniam
16546269aa libcamera: converter: Check converter validity
The ConverterFactoryBase::create() function returns a nullptr when no
converter is found. The only caller, SimpleCameraData::init(), checks if
the converter is valid with isValid(), but doesn't check if the pointer
is null, which can lead to a crash.

We could check both pointer validity and converter validity in the
caller, but to limit the complexity in callers, it is better to check
the converter validity in the create() function and return a null
pointer when no valid converter is found.

Signed-off-by: Suhrid Subramaniam <suhrid.subramaniam@mediatek.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-03-09 18:40:40 +02:00
David Plowman
1957219d7e ipa: raspberrypi: imx296: Minor tuning updates
Some updates to the tuning for the imx296 sensors.

For the colour variant:

* Minor change to the AWB curve, making things a little less green.
* Updated CCMs that reduce colour saturation to a more accurate level.
  Thanks to Dr. Rolf Henkel for these measurements and calculations.
* Sharpening has been toned down quite a lot.
* rpi.focus algorithm added so that the focus measure can be accessed.

The sharpening and focus changes are applied to the mono version of
the sensor too as we expect similar characteristics.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-07 21:55:05 +00:00
David Plowman
85541db7bb ipa: raspberrypi: agc: Fix overflow in Y value calculation
The maxVal variable in the computeInitialY function needs to be a
uint64_t, otherwise the subsequent multiplications in the function
can overflow on relatively high resolution images (when the counts in
the regions go over 16 bits).

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-07 21:55:05 +00:00
Naushir Patuck
2a261d911f pipeline: raspberrypi: Iterate over all Unicam instances in match()
On Raspberry Pi Compute Module platforms, it is possible to attach a
single camera device only to the secondary Unicam port. The current
logic of PipelineHandlerRPi::match() will return a failure during
enumeration of the first Unicam media device (due to no sensor attached,
or sensor failure) and thus the second Unicam media device will never be
enumerated.

Fix this by looping over all Unicam instances in PipelineHandlerRPi::match()
until a camera is correctly registered, or return a failure otherwise.

Reported-on: https://github.com/raspberrypi/libcamera/issues/44
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-07 21:55:05 +00:00
Naushir Patuck
471cbc0ef7 pipeline: raspberrypi: Add a Unicam timeout override config options
Add a new parameter to the pipeline handler config file named
"unicam_timeout_value_ms" to allow users to override the automatically
computed Unicam timeout value.

This value is given in milliseconds, and setting a value of 0 (the
default value) disables the override.

An example use of this parameter would be if an application configured a
RAW stream, and provides buffers for the stream on every request. If the
application holds off on sending requests for a particular reason (e.g.
a timelapse use case), then we will possibly hit the watchdog timeout as
it is only a small multiple of the frame length. This override allows an
application to select a larger value with the knowledge that it may
space requests longer than the calculated timeout value.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-07 21:55:05 +00:00
Naushir Patuck
9648e85994 ipa: raspberrypi: Better heuristics for calculating Unicam timeout
The existing mechanism of setting a timeout value simply uses the
maximum possible frame length advertised by the sensor mode. This can be
problematic when, for example, the IMX477 sensor can use a frame length
of over 600 seconds. However, for typical usage the frame length will
never go over several 100s of milliseconds, making the timeout very
impractical.

Store a list of the last 10 frame length values requested by the AGC. On
startup, and at the end of every frame, take the maximum frame length
value from this list and return that to the pipeline handler through the
setCameraTimeoutValue() signal. This allows the timeout value to better
track the actual sensor usage.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-07 21:55:05 +00:00
Naushir Patuck
b6d84ed456 pipeline: ipa: raspberrypi: Change Unicam timeout handling
Add an explicit helper function setCameraTimeout() in the pipeline
handler to set the Unicam timeout value. This function is signalled from
the IPA to set up an appropriate timeout. This replaces the
maxSensorFrameLengthMs value parameter returned back from
IPARPi::start().

Adjust the timeout to be 5x the maximum frame duration reported by the
IPA.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-07 21:55:05 +00:00
Jacopo Mondi
cde9293cf9 ipa: rkisp1: lsc: Fix integer division error
The RkISP1 implementation of the LensShadingCorrection algorithm has been
made adaptive to the scene color temperature in commit 14c869c00f ("ipa:
rkisp1: Take into account color temperature during LSC algorithm").

The LSC algorithm interpolates the correction factors using the
table's reference color temperatures. When calculating the interpolation
coefficients, an unintended integer division makes both coefficient
zeros resulting in a completely black image.

Fix this by type casting to double one of the division operands.

Fixes: 14c869c00f ("ipa: rkisp1: Take into account color temperature during LSC algorithm")
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2023-03-06 18:12:10 +01:00