Commit graph

3499 commits

Author SHA1 Message Date
Nicholas Roth
0f382a9926 libcamera: Add support for OmniVision OV8858
Support for the OmniVision OV8858 sensor is scheduled for inclusion in
the Linux kernel in version v6.3.

Add support for the sensor in libcamera by providing static properties
and a camera sensor helper in libipa.

The camera sensor helper expresses analogue gain increments in 1/128
step which differs from what is reported in the sensor documentation in
section "5.8 manual exposure compensation/ manual gain compensation" [0]

A more detailed analysis of the sensor gain model is reported at:
2022110617.166892-2-nicholas@rothemail.net/#142267

Record with a \todo note a reference to discussion on the gain model
implementation.

Signed-off-by: Nicholas Roth <nicholas@rothemail.net>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-01-26 18:33:47 +01:00
Mikhail Rudenko
7986d3d3c1 ipa: rkisp1: Raise maximum analogue gain
Omnivision OV4689 sensor driver exposes maximum analogue gain of
16x. Raise kMaxAnalogueGain to 16.0, so that the full gain range can
be used.

Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2023-01-25 18:43:44 +01:00
Mikhail Rudenko
d500930e7d ipa: rkisp1: Add OV4689 tuning file
Add a minimal tuning file for Omnivision OV4689, specifying black
level subtraction level.

Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2023-01-25 18:43:43 +01:00
Mikhail Rudenko
1818b92fd7 libcamera: camera_sensor: Add OV4689 sensor properties
Add an entry to the sensor properties for Omnivision OV4689.

Kernel supports two more types of color bars patterns, which we do not
expose now.

Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2023-01-25 18:43:36 +01:00
Mikhail Rudenko
3643c59617 ipa: camera_sensor_helper: Add OV4689 support
Add support for Omnivision OV4689 image sensor to libipa.

The sensor implements a linear gain equation with analogue gain
control values 0-2047 corresponding to 0x-16x physical gain range.

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2023-01-25 18:42:51 +01:00
David Plowman
13986d6ce3 libcamera: camera: Fix validateColorSpaces to choose "main" colour space
The intention is that the "main" colour space is the colour space of
the largest non-raw stream. Unfortunately the use of "config_[i].size"
is clearly incorrect, and has been copied from prior versions of the
code. This patch corrects the error.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
2023-01-19 21:17:48 +05:30
Laurent Pinchart
d81505b834 libcamera: ipa_module: Relax ipaModuleInfo symbol size check
When an IPA module is loaded, the loadIPAModuleInfo() function validates
the ipaModuleInfo structure. As part of that process, it checks that the
ipaModuleInfo symbol size matches the expected structure size. This
check breaks with clang and ASan, as the LLVM's address sanitizer
implementation includes the redzone after the structure in the symbol
size, currently growing it by 156 bytes (on x86-64). This causes all IPA
modules to fail to load.

Fix the problem by relaxing the size check to only ensure that the
symbol is large enough to contain the structure.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-01-16 18:32:50 +02:00
Daniel Oakley
20e33bc0df py: cam.py: Fix duplicate metadata output if more than one stream
Currently, if there are multiple streams, the --metadata flag will print
the metadata for each request multiple times.

Moving the metadata print logic outside the stream for loop this will no
longer occur.

Signed-off-by: Daniel Oakley <daniel.oakley@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-01-16 18:07:05 +02:00
Jacopo Mondi
3666290f5f libcamera: rkisp1: Re-sort includes
Comply with a checkstyle suggestion and separate inclusion directives.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-01-16 09:52:03 +01:00
Jacopo Mondi
d47965f899 libcamera: bayer_format: Expand documentation
The current documentation of the BayerFormat::transform() function
reports examples on the Bayer components ordering transformation for
horizontal flip (mirroring) but not for vertical flip or for the
combination of the two.

It is useful to complete the documentation to ease understanding of the
transform() function on a sensor's Bayer pattern.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-01-16 09:52:03 +01:00
Laurent Pinchart
aed615e173 libcamera: base: utils: Support C libraries lacking locale support
Not all C libraries include support for locale objects (locale_t) and
the strto*_l() family of functions. A notable example is uClibc that can
be compiled with a hardcoded "C" locale. Compilation then fails as the
newlocale(), freelocale() and strtod_l() functions are not defined.

Fix the compilation breakage by checking for the availability of the
locale_t type, and fall back to strtod() when the type isn't available.
This may not lead to the correct result if support for locale objects
isn't available and the locale isn't hardcoded to "C", but that is such
a corner case that we will likely never encounter it.

Fixes: e8ae254970 ("libcamera: yaml_parser: Use C locale")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2023-01-10 17:25:51 +02:00
Laurent Pinchart
0e3b8d71f5 base: utils: Add and use strtod() helper
The strtod() function is locale-dependent, and thus ill-suited to parse
numbers coming from, for instance, YAML files. The YamlObject class uses
strtod_l() to fix that issue, but that function is not available with
all libc implementations. Correctly handling this problem is becoming
out of scope for the YamlObject class.

As a first step, add a strtod() helper function in the utils namespace
that copies the implementation from YamlObject, and use it in
YamlObject. The core issue will then be fixed in utils::strtod().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-01-10 15:39:18 +02:00
Matti Lehtimäki
504b643761 libcamera: Use C++17 [[fallthrough]] everywhere
Fixes build failure on some build environments.

Signed-off-by: Matti Lehtimäki <matti.lehtimaki@gmail.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-01-05 12:08:34 +02:00
Kieran Bingham
e8ae254970 libcamera: yaml_parser: Use C locale
When parsing configuration files on systems with differing locales, the
use of strtod can produce different results, or in the worst case - fail
to parse expected values.

Fix this by using strtod_l() instead. To avoid constructing and
destructing a locale_t instance for every use of strtod_l(), create an
RAII class that wraps the locale_t and use it to provide a global "C"
locale.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=174
Bug: https://github.com/raspberrypi/libcamera/issues/29
Reported-by: https://github.com/kralo
Reported-by: Hannes Winkler <hanneswinkler2000@web.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-01-03 13:09:52 +00:00
Christian Rauch
e1b81401ca qcam: Show string representation of pixel format
The raw pixel format in form of the fourcc integer is not easily readable.
Use the string representation instead for easier debugging.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
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-12-30 22:16:49 +02:00
Pavel Machek
e83d94915d gstreamer: Add bayer8 support to libcamerasrc element
Bayer8 support is useful on hardware such as Librem 5, as GStreamer
provides easy solution for debayering and display of the camera
data. Add necessary glue to libcamerasrc element.

Signed-off-by: Pavel Machek <pavel@ucw.cz>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-12-24 17:47:19 +02:00
Pavel Machek
21a82ed8a5 libcamera: Simple typo fixes
Fix various typos in the code base.

Signed-off-by: Pavel Machek <pavel@ucw.cz>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-12-24 03:29:51 +02:00
Laurent Pinchart
f5bfa33f59 ipa: raspberrypi: Fix permissions on imx477_scientific.json
The imx477_scientific.json file was added to the source tree with
incorrect executable permission. Fix it.

Fixes: bf66a1d251 ("ipa: raspberrypi: Add a "scientific" tuning for the IMX477")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-22 23:27:23 +02:00
Jacopo Mondi
6479535ee3 libcamera: camera_sensor: Add AR0521 sensor properties
Add an entry to the sensor properties for OnSemi AR0521.

The chip manual list one additional test pattern "PN9 Link integrity
test pattern" not supported by the mainline Linux driver.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-12-22 12:13:16 +01:00
Jacopo Mondi
ff9b8befbb ipa: camera_sensor_helper: Add AR0521 support
Add support for OnSemi AR0521 5Mpx image sensor to libipa.

The sensor analogue gain is implemented as a coarse and a fine factor,
with the coarse gain being a power of two and the fine gain being a
value in the [1.0, 2.0[ range. The mapping between gain codes and gain
values is tabulated in the datasheet, and the table values are very
close but not identical to the mathematical model. Compute the gain
using the model to keep the code shorter, if this causes precision
issues the calculation could be replaced with a table.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-12-22 12:11:21 +01:00
Matthew Goodman
3c70cae5e5 Expose the Request Sequence Number in Python Bindings
The python bindings are missing the ability to read the sequence number
of the Request object from the public API.

Expose the objects sequence number on the pybind11 surfaces to support
applications reading this value.

Signed-off-by: Matthew Goodman <matt@exclosure.io>
[Kieran: Revised commit message]
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-19 15:07:30 +00:00
Naushir Patuck
bf66a1d251 ipa: raspberrypi: Add a "scientific" tuning for the IMX477
Add a tuning file for the IMX477 more suited to scientific applications.
The key differences from the original tuning file are:

- Disable ALSC block completely
- Pure rec709 gamma curve, and no contrast enhance
- New CT curve and CCMs based on the illumination spectrum of a black body
radiator up to about 3600 K and the CIE illuminant D for higher color
temperatures.

Further details on the changes can be found at:
https://forums.raspberrypi.com/viewtopic.php?t=343449

All credit for these changes go to Dr. Rolf Henkel.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: Rolf Henkel <cpixip@pixelcircus.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-19 13:23:10 +00:00
Laurent Pinchart
f0fef545a7 libcamera: Add todo comment in meson.build about switch to dependency('dl')
The dlopen() & co. functions are provided by libdl on some systems, and
but the C library on others. Starting from version 0.62.0, meson handles
this behind the scenes when using dependency('dl'). Add a todo comment
to remember we should replace the manual implementation with a
dependency() call when updating to meson 0.62.0 or newer.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-16 18:48:13 +02:00
Xavier Roumegue
5a8271ad70 libcamera: pipeline: simple: converter: Use generic converter interface
Move the simple converter implementation to a generic V4L2 M2M class
derived from the converter interface. This latter could be used by
other pipeline implementations and as base class for customized V4L2 M2M
converters.

Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-14 16:19:52 +00:00
Xavier Roumegue
f73f4dfad8 libcamera: Declare generic converter interface
Declare a converter Abstract Base Class intended to provide generic
interfaces to hardware offering size and format conversion services on
streams. This is mainly based on the public interfaces of the current
converter class implementation found in the simple pipeline handler.

The main change is the introduction of loadConfiguration() function
which can be used by the concrete implementation to load hardware
specific runtime parameters defined by the application.

Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-14 16:19:52 +00:00
Umang Jain
b026e4a6a0 libcamera: camera_sensor: Rectify test patterns listed for IMX519
The IMX519 driver reports ColorBars and ColorBarsFadeToGray but upon
inspecting the test pattern modes via v4l2-ctl utility, these test
patterns do not comply with MIPI CCS v1.1 (Section 10.1).

Hence, omit from camera-sensor-properties database for now and add a
comment for the same.

Fixes: e3b26b4c4e ("libcamera: camera_sensor: Add IMX519 sensor properties")
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-12 16:48:22 +05:30
Umang Jain
e3b26b4c4e libcamera: camera_sensor: Add IMX519 sensor properties
Add an entry for Arducam IMX519 sensor which has 1220x1220 pixel size
and supports four test pattern modes.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-09 16:03:51 +00:00
Robert Mader
d5fc282eff ipa: rkisp1: Add additional default values to controls
To make things easier for consumers.

Related: https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1450

Signed-off-by: Robert Mader <robert.mader@collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-09 16:03:09 +00:00
Paul Elder
9a913eb910 lc-compliance: simple_capture: Free Requests properly
In the simple capture tests, in the capture functions, the Requests were
auto-deallocated by the function going out of scope after the test
completed. However, before the end of the scope, the Framebuffers that
the Requests referred to were manually freed. Thus when the Requests
were deallocated, they tried to cancel their Framebuffers, which involve
setting the status to cancelled, which obviously causes a segfault
because the Framebuffers had already been freed.

Fix this by moving the list of Requests to a member variable and
deallocating them before deallocating the Framebuffers at stop() time.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-09 16:02:56 +00:00
David Plowman
a6b1ff2e6c py: Support controls that use an array of Rectangles
The Python bindings will now accept, or return, a list or tuple of
libcamera.Rectangle objects for such controls.

This had previously been omitted, but now we have, for example, the
AfWindows control which requires this feature.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-09 16:02:40 +00:00
David Plowman
1bd74b91be libcamera: controls: Change LensPosition units to dioptres
The units for the LensPosition control, previously defined as being in
units of 1 / hyperfocal_distance, are changed to 1 / distance (in
metres).

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-08 11:36:02 +00:00
Jacopo Mondi
4a7c8a98da android: Fix missing space in error message
Add whitespace to correct the error message.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-12-07 08:52:21 +01:00
David Plowman
ea8ae5afff ipa: raspberrypi: imx477: Update tuning file for the latest camera modules
The latest camera modules have a very slightly different IR filter, so
the tuning file is slightly revised to give best results with both old
and new camera modules.

The original tuning file is retained as imx477_v1.json in case anyone
should wish to continue using it.

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>
2022-11-30 14:06:04 +00:00
Naushir Patuck
6b03da662b ipa: raspberrypi: Fix bug in IPA frame drop logic
Fix a bug in the IPA frame dropping (for rate control) logic, where the
metadata for the current context was copied from itself (i.e. a no-op), instead
of being copied from the previous context.

This bug does not occur in normal conditions, only when running with a low
exposure time and unconstrained framerate, which happens in a particular
picamera2 test.

Fixes: 546154b134 ("pipeline: ipa: raspberrypi: Use IPA cookies")
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-11-30 12:41:46 +00:00
Naushir Patuck
ac42f9278e ipa: raspberrypi: agc: Fix digital gain calculation for manual mode
The digital gain calculation uses a total exposure value computed with the
current AGC state. However, this is wrong in the case of manual shutter/gain
controls, as the total exposure value used must be the value computed when the
AGC sent the manual shutter/gain controls to the pipeline handler to action.

To fix this, the IPA now adds the historical AgcStatus structure to the metadata
(tagged with "agc.delayed_status"). This historical AgcStatus structure contains
the total exposure value calculated when the AGC sent the manual shutter/gain
controls to the pipeline handler.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:16:54 +02:00
Naushir Patuck
546154b134 pipeline: ipa: raspberrypi: Use IPA cookies
Pass an IPA cookie from the pipeline handler to the IPA and eventually back to
the pipeline handler through the setDelayedControls signal. This cookie is used
to index the RPiController::Metadata object to be used for the frame.

The IPA cookie is then returned from DelayedControls when the frame with the
applied controls has been returned from the sensor, and eventually passed back
to the IPA from the signalIspPrepare signal.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:16:52 +02:00
Naushir Patuck
44cffefd60 ipa: raspberrypi: Use an array of RPiController::Metadata objects
Allow the IPA to cycle through an array of RPiController::Metadata objects, one
per prepare()/process() invocation, when running the controller algorithms. This
allows historical metadata objects to be retained, and subsequently passed into
the controller algorithms on future frames. At present, only a single index into
this array is used.

This change provides a route to fixing a problem with the AGC algorithm, where
if a manual shutter/gain is requested, the algorithm does not currently retain
any context of the total exposure that it has calculated. As a result, the
wrong digital gain would be applied when the frame with the manual shutter/gain
is processed by the ISP.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:16:49 +02:00
Naushir Patuck
087f0c3c42 ipa: raspberrypi: Add RPiController::Metadata::mergeCopy
Add a new member function to RPiController::Metadata that copies unique
key/value pairs from one object to the other. This is different from
std::map::merge that would remove the key/value pairs from the source object.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:16:47 +02:00
Naushir Patuck
33abc2b31e pipeline: raspberrypi: delayed_controls: Add user cookie to DelayedControls
Allow the caller to provide a cookie value to DelayedControls::reset and
DelayedControls::push. This cookie value is returned from DelayedControls::get
for the frame that has the control values applied to it.

The cookie value is useful in tracking when a set of controls has been applied
to a frame. In a subsequent commit, it will be used by the Raspberry Pi IPA to
track the IPA context used when setting the control values.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:16:45 +02:00
Naushir Patuck
c7524b10e0 pipeline: raspberrypi: delayed_controls: Template the ControlRingBuffer class
Convert ControlRingBuffer to a templated class to allow arbitrary ring buffer
array types to be defined. Rename ControlRingBuffer to RingBuffer to indicate
this.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:15:55 +02:00
Naushir Patuck
dd0a75401f pipeline: raspberrypi: Switch to RPi::DelayedControls
Switch the Raspberry Pi pipeline handler to use the DelayedControls
implementation in the RPi:: namespace. This will allow us to use Raspberry Pi
specific API changes in future commits.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:15:33 +02:00
Naushir Patuck
962f6cdd53 pipeline: raspberrypi: Fork DelayedControls
Fork the libcamera::DelayedControls implementation in the RPi:: namespace, with
the intention of updating the API for Raspberry Pi specific features.

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: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-29 17:15:17 +02:00
Kieran Bingham
96ed45b971 libcamera: v4l2_device: Workaround faulty control menus
Some UVC cameras have been identified that can provide V4L2 menu
controls without any menu items.

This leads to a segfault where we try to construct a
ControlInfo(Span<>,default) with an empty span.

Convert the v4l2ControlInfo and v4l2MenuControlInfo helper functions to
return std::optional<ControlInfo> to be able to account in the caller if
the control is valid, and only add acceptable controls to the supported
control list.

Menu controls without a list of menu items are no longer added as a
valid control and a warning is logged.

This also fixes a potential crash that would have occured in the
unlikely event that a ctrl.minimum was set to less than 0.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=167
Reported-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-11-28 17:15:35 +00:00
Barnabás Pőcze
1cd7646f97 libcamera: framebuffer_allocator: Avoid double map lookup
Use `try_emplace()` on the map instead of `count()`
and `operator[]` to avoid walking the tree twice.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-28 16:11:20 +02:00
Jacopo Mondi
b35f04b3c1 cam: capture_script: Support parsing array controls
Add support for parsing array controls to the cam capture script.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-11-25 12:07:17 +01:00
Florian Sylvestre
87f5d12718 pipeline: rkisp1: Support raw Bayer capture configuration
Implement support for raw Bayer capture during configuration generation,
validation and camera configuration.

While at it, fix a typo in a comment.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-11-25 10:52:07 +02:00
Florian Sylvestre
c8f63760e5 pipeline: rkisp1: Support raw Bayer capture at runtime
Implement support for raw Bayer capture at runtime, from start() to
stop(). Support of raw formats in the camera configuration is split to a
subsequent change to ease review.

In raw mode, the ISP is bypassed. There is no need to provide parameter
buffers, and the ISP will not generate statistics. This requires
multiple changes in the buffer handling:

- The params and stats buffers don't need to be allocated, and the
  corresponding video nodes don't need to be started or stopped.

- The IPA module fillParamsBuffer() operation must not be called in
  queueRequestDevice(). As a result, the IPA module thus doesn't emit
  the paramsBufferReady signal. The main and self path video buffers
  must thus be queued directly in queueRequestDevice().

- The tryCompleteRequest() function must not to wait until the params
  buffer has been dequeued.

- When the frame buffer has been captured, the IPA module
  processStatsBuffer() operation must be called directly to fill request
  metadata.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-11-25 10:52:06 +02:00
Laurent Pinchart
2447d14fa8 pipeline: rkisp1: Fix stream size validation
Unlike RkISP1Path::generateConfiguration(), the validate() function
doesn't take the camera sensor resolution into account but only
considers the absolute minimum and maximum sizes supported by the ISP to
validate the stream size. Fix it by using the same logic as when
generating the configuration.

Instead of passing the sensor resolution to the validate() function,
pass the CameraSensor pointer to prepare for subsequent changes that
will require access to more camera sensor data. While at it, update the
generateConfiguration() function similarly for the same reason.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-11-25 10:52:06 +02:00
Paul Elder
4c30ed47f6 pipeline: rkisp1: Query the driver for formats
Query the driver for the output formats and sizes that it supports,
instead of hardcoding them. This allows future-proofing for formats that
are supported by some but not all versions of the driver.

As the rkisp1 driver currently does not support VIDIOC_ENUM_FRAMESIZES,
fallback to the hardcoded list of supported formats and framesizes. This
feature will be added to the driver in parallel, though we cannot
guarantee that users will have a new enough kernel for it.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-11-25 10:52:06 +02:00
Laurent Pinchart
72721611fa ipa: rkisp1: agc: Support raw capture
Support raw capture by allowing manual control of the exposure time and
analogue gain.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-11-25 10:52:06 +02:00