Commit graph

4322 commits

Author SHA1 Message Date
Kieran Bingham
1de9518f51 libcamera: properties: Provide a Devices camera property
Provide a new Camera property that allows pipeline handlers to list any
kernel device used to operate the camera. This allows other frameworks
and daemons such as PipeWire to better understand the resources consumed
by a Camera and consider ignoring those resources when enumerating
camera devices on a system.

Tested-by: Ashok Sidipotu <ashok.sidipotu@collabora.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-06-17 22:52:34 +01:00
Kieran Bingham
75ddd20209 libcamera: camera_manager: Move {add,remove}Camera to internal
The CameraManager exposes addCamera and removeCamera as public API
calls, while they should never be called from an application. These
calls are only expected to be used by PipelineHandlers to update the
CameraManager that a new Camera has been created and allow the Camera
Manager to expose it to applications.

Remove the public calls and update the private implementations such that
they can be used directly by the PipelineHandler through the internal
CameraManager::Private provided by the Extensible class.

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Tested-by: Ashok Sidipotu <ashok.sidipotu@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-06-17 22:52:32 +01:00
Kieran Bingham
7144fe6f9c libcamera: camera_manager: Move private implementation to internal
The CameraManager makes use of the Extensible pattern to provide an
internal private implementation that is not exposed in the public API.

Move the Private declaration to an internal header to make it available
from other internal components in preperation for reducing the surface
area of the public interface of the CameraManager.

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Tested-by: Ashok Sidipotu <ashok.sidipotu@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-06-17 22:52:26 +01:00
Kieran Bingham
f36c05c21e libcamera: internal: request: convert to pragma once
Remove the verbose #ifndef/#define/#endif pattern for maintaining
header idempotency, and replace it with a simple #pragma once.

This simplifies the headers, and prevents redundant changes when
header files get moved.

The internal/request.h was missed at the time of the original
conversion. Update it.

Fixes: df131ad088 ("libcamera: internal: Convert to pragma once")
Tested-by: Ashok Sidipotu <ashok.sidipotu@collabora.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-06-17 22:52:24 +01:00
Naushir Patuck
0ee9339331 ipa: rpi: agc: Gracefully handle missing agc modes
If a metering/exposure/constraint mode is not listed in the sensor
tuning file, and a control for the missing mode is set on the agc, we
terminate the application with a fatal log message.

Instead of this fatal termination, log a warning message and switch to
the appropriate default mode so that the application continues running.

Bug: https://github.com/raspberrypi/libcamera/issues/59
Bug: https://github.com/ayufan/camera-streamer/issues/67
Signed-off-by: Naushir Patuck <naush@raspberrypi.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-06-07 20:39:32 +01:00
Naushir Patuck
5242b78c0b ipa: rpi: agc: Use std::string instead of char arrays
Replace the char array strings in struct AgcStatus with std::string
objects. This simplifies the string handling in the source code.

Signed-off-by: Naushir Patuck <naush@raspberrypi.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-06-07 20:31:02 +01:00
Naushir Patuck
c6ff999053 ipa: rpi: tunings: Add missing short and long exposure profiles
Some sensor tuning files were missing the short and/or long exposure
mode profiles. Add the missing items to the relevant files.

As a drive-by, rename the "sport" exposure profile to "short" for the
IMX290 tuning.

Signed-off-by: Naushir Patuck <naush@raspberrypi.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-06-07 20:30:05 +01:00
Jacopo Mondi
e58121cfc1 libcamera: rkisp1: Fix enumeration of RAW formats
The current implementation enumerates a single RAW format (the sensor's
resolution) and does that regardless of what role the
CameraConfiguration has been generated for.

Fix this by:
- Enumerate RAW StreamFormats only when the requested role is
  StreamRole::Raw
- Add all the sensor's provided resolutions that fit the video device
  output maximum size

Before this patch, a single RAW size was enumerated in stream formats

 * Pixelformat: SRGGB10 (4208x3120)-(4208x3120)/(+1,+1)
  - 4208x3120

With this patch applied all sensor's supported resolutions are
enumerated but only when the stream role RAW is explicitly requested

 * Pixelformat: SRGGB10 (1048x780)-(4208x3120)/(+0,+0)
  - 1048x780
  - 2104x1560
  - 4032x3024
  - 4208x3120

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2023-06-06 18:59:26 +02:00
Jacopo Mondi
d45da036a4 libcamera: rkisp1: Assign sizes to roles
Currently each RkISP1 path (main and self) generate a configuration
by bounding the sensor's resolution to their respective maximum output
aspect ratio and size.

	Size maxResolution = maxResolution_.boundedToAspectRatio(resolution)
					   .boundedTo(resolution);

In the case of self path, whose maximum size is 1920x1920, the generated
configuration could get assigned unusual sizes, as the result of the
above operation.

As an example, with the imx258 sensor whose resolution is 4208x3118, the
resulting size for the Viewfinder use case is an unusual 1920x1423.

Fix this by assigning to each role a desired output size:
- Use the sensor's resolution for StillCapture and Raw
- Use 1080p for Viewfinder and VideoRecording

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-06 18:59:26 +02:00
Jacopo Mondi
311e5bc1a8 libcamera: rkisp1: Crop on ISP before downscaling
Crop on the resizer sink pad before downscaling to the aspect ratio
of the desired output size.

Cropping the input frame to the output aspect ratio allows to maintain
the correct picture proportions, as otherwise downscaling would change
the image geometry.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2023-06-06 18:59:26 +02:00
Jacopo Mondi
c6124d757c libcamera: rkisp1: Generate config using main path
The generateConfiguration() implementation in the Rockchip RkISP1
pipeline handler uses by default the self path (if available) for
the Viewfinder and VideoRecording StreamRoles.

The validate() implementation, at the contrary, prefers using the main
path, when available, for all streams.

As the self-path is limited in output resolution to 1920x1920,
generating a configuration using the self path limits the maximum
stream size to 1920x1920, while higher resolutions can be obtained by
using the main path.

Align the generateConfiguration() implementation to the validate() one
by using the main path by default if available.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=180
Reported-by: libcamera@luigi311.com
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-06-06 18:59:25 +02:00
Naushir Patuck
fab47108e1 ipa: rpi: Set lens position to hyperfocal on startup
On the first ipa->configure() call, set the lens position (if a lens is
present) to the default position. Typically this would be the hyperfocal
position based on the tuning data.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-06 18:22:20 +03:00
Naushir Patuck
d66ff77759 pipeline: ipa: rpi: Return lens controls from ipa->configure()
In addition to sensor controls, return lens controls from
IpaBase::configure() back to the pipeline handler. If there are lens
controls present in the ControlList, action them in the pipeline handler
as part of the configure routine.

Signed-off-by: Naushir Patuck <naush@raspberrypi.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-06-06 18:21:00 +03:00
Naushir Patuck
bdba31cc02 libcamera: controls: Define a default lens position behaviour
Update the AfMode control description to explicitly define a
startup/default behaviour.

On startup, the camera will move the lens to the position given by the
default value of the LensPosition control if operating in manual focus
mode. Typically this would be the hyperfocal position of the lens.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-06 18:19:51 +03:00
Jacopo Mondi
ea93e7899f ipa: rkisp1: agc: Restore minimum analogue gain limit
Commit a3178dd039 ("ipa: rkisp1: agc: drop hard-coded analogue gain range")
removed both minimum and maximum limits for the analogue gain value.

However, as some sensors can potentially have a minimum gain lower than
1.0, restore the check for the minimum limit.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-06 18:17:35 +03:00
Jacopo Mondi
db86713ec1 ipa: ipu3: agc: Drop hard-codec analogue gain max
As the sensor's analogue gain range is known, drop the arbitrary
maximum limit for the sensor analogue gain.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Tested-by: Daniel Scally <dan.scally@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-06 18:17:35 +03:00
Benjamin Bara
0a37c203da libipa: camera_sensor_helper: Restore alphabetical order
The addition of the CameraSensorHelperImx327 class was not correctly
inserted in alphabetical sort order.

Move it to the correct location.

Fixes: 7d5b38e2ef ("libipa: camera_sensor_helper: Add IMX327 helper")
Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Benjamin Bara <benjamin.bara@skidata.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-06-06 18:14:37 +03:00
Laurent Pinchart
f65a73f3c8 libcamera: controls: Drop reference to IPA in controls documentation
The controls relates to the public API, which doesn't expose IPA modules
as they are internal to libcamera. Replace the mention of "IPA" in the
controls documentation.

While at it, fix a small text reflow issue.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-06-05 20:00:02 +03:00
Naushir Patuck
a0271e72a8 ipa: rpi: Handle controls for mono variant sensors
Do not advertise colour related controls (i.e. [A]WB, colour saturation)
in the ControlInfoMap of available controls returned out to the
application.

Silently ignore these controls in the control handler in case applications
don't use the advertised ControlInfoMap to validate controls.

As a drive-by fix, don't advertise controls::ColourCorrectionMatrix in
the ControlInfoMap as it is not handled by the IPA.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-05 11:40:31 +03:00
Naushir Patuck
54340ef70f camera_sensor: ipa: core: Add CFA pattern to IPACameraSensorInfo
Add a new cfaPattern field to the IPACameraSensorInfo to pass the
CFA/Bayer pattern for the current sensor configuration to the IPA.
This field takes a value from properties::draft::ColorFilterArrangementEnum.

Populate cfaPattern in CameraSensor::sensorInfo(), called by the
pipeline handler before it calls ipa->init() and ipa->config().

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-05 11:40:25 +03:00
Tomi Valkeinen
f44df6f4fa py: unittests.py: Fix type checker warnings
Fix type checker warnings by dropping unused imports and using _ for
variable names that are not used.

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>
2023-06-04 16:10:51 +03:00
Tomi Valkeinen
a1f0556a46 py: Fix code formatting
Fix code formatting.

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>
2023-06-04 12:25:35 +03:00
Tomi Valkeinen
f513fd70ba subprojects: Drop leftovers of pybind11
The pybind11 subproject was removed in commit ad4719c10c ("py: Move to
mainline pybind11 version"), but two traces remained, one in .gitignore
and a second one as a meson.build for pybind11. Remove them.

Fixes: ad4719c10c ("py: Move to mainline pybind11 version")
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>
2023-06-04 11:48:00 +03:00
Naushir Patuck
49fd9e52f4 ipa: rpi: imx296: Small refinements to the IMX296 mono sensor tuning
Update the noise profile and reference lux level with newly taken
calibration pictures. Remove GEQ/cross-talk processing block as this is
a mono sensor.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-02 07:40:37 +03:00
Tomi Valkeinen
ad4719c10c py: Move to mainline pybind11 version
We are using pybind11 'smart_holder' branch to solve the Camera
destructor issue (see the comment in this patch, or the commit
that originally added Python bindings support).

As it would be very nice to use the mainline pybind11 (which is packaged
in distributions), this patch adds a workaround allowing us to move to
the mainline pybind11 version.

The workaround is simply creating a custom holder class
(PyCameraSmartPtr), used only for the Camera, which wraps around the
shared_ptr. This makes the compiler happy.

Moving to mainline pybind11 is achieved with:

- Change the pybind11 wrap to point to the mainline pybdind11 version

- Tell pybind11 to always use shared_ptr<> as the holder for
  PyCameraManager, as we use the singleton pattern for the
  PyCameraManager, and using shared_ptr<> to manage it is a requirement

- Tell pybind11 to always use PyCameraSmartPtr<> as the holder for Camera

- Change the meson.build file to use a system-installed pybind11

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>
2023-05-31 19:48:02 +03:00
Tomi Valkeinen
51dc505d63 py: unittests.py: Add weakref helpers and use del
Add helpers to check if a weakref or a list of weakrefs is alive or
dead.

Also use 'del' for local variables instead of setting the variable to
None. This makes debugging the test easier as the locals will be gone
from locals() dict.

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>
2023-05-30 18:29:10 +03:00
Tomi Valkeinen
1fb31ac4f4 py: Use exceptions instead of returning error codes
We have multiple methods which return an error code, mimicking the C++
API. Using exceptions is more natural in the Python API, so change all
those methods to raise an Exception instead.

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>
2023-05-30 18:29:09 +03:00
Tomi Valkeinen
5b2f1ce501 py: Move ColorSpace and Transform classes to separate files
Move ColorSpace and Transform classes to separate files from the main
py_main.cpp, for clarity.

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>
2023-05-30 18:29:08 +03:00
Tomi Valkeinen
9506da142b py: Fix CameraManager.version property
The current CameraManager.version doesn't work at all (raises a
TypeError), as that's not how you use expose C++ static methods as
Python class methods.

Fix it.

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>
2023-05-30 18:29:08 +03:00
Laurent Pinchart
b9ecd85ed1 android: mm: Stub libhardware for build tests
Commit 66c618f378aa ("android: mm: generic: use
GRALLOC_HARDWARE_MODULE_ID") made libhardware a required dependency for
the Android camera HAL on non-Chrome OS platforms. This isn't an issue
for real devices, as Android provides libhardware, but it prevents
compile-testing the camera HAL on traditional Linux systems.

To restore the compile-test coverage, stub the libhardware function used
by the camera HAL when libhardware isn't found.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> # meson build test
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-05-30 18:29:08 +03:00
Mattijs Korpershoek
1450e09a08 android: mm: generic: use GRALLOC_HARDWARE_MODULE_ID
PlatformFrameBufferAllocator is an abstraction over gralloc.
Right now hardwareModule_ points towards a CAMERA_HARDWARE_MODULE_ID.

When gralloc_open() is called we observe:
libcamera: DEBUG HAL camera3_hal.cpp:75 Open camera gpu0
libcamera: ERROR Camera camera.cpp:524 Camera in Configured state trying acquire() requiring state Available
01-23 14:14:04.742   370   416 E libcamera: FATAL HAL generic_frame_buffer_allocator.cpp:105 gralloc_open() failed: -87

Which is wrong, gralloc_open() is attempting to re-open the camera HAL,
instead of the gralloc HAL.

Point to a GRALLOC_HARDWARE_MODULE_ID instead so that we can request
buffers from gralloc in android.

Note: this adds new dependencies on android's libhardware [1] and on libdl.

[1] https://android.googlesource.com/platform/hardware/libhardware

Fixes: c58662c577 ("android: Introduce PlatformFrameBufferAllocator")
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.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>
2023-05-30 18:29:08 +03:00
Benjamin Bara
76e1cb9f71 libcamera: camera_sensor: Add Sony IMX327 sensor properties
Copy the sensor properties from Sony IMX290, as the IMX327 is a variant
of it.

Signed-off-by: Benjamin Bara <benjamin.bara@skidata.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
[Kieran: Adjust sort order]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-05-24 22:01:34 +01:00
Naushir Patuck
58f38082e1 pipeline: rpi: ipa_base: Parse config files after platformRegister()
If a user uses a pipeline handler config file where a custom timeout
value is specified, it would lead to a segmentation fault when
loadPipelineConfiguration() tried to access the as yet uninitialised
V4L2VideoDevice object.

To fix this, parse the pipeline handler config file only after fully
initialising and registering the pipeline handler and V4L2VideoDevice
objects.

Fixes: 6c71ee1f15 ("pipeline: raspberrypi: Introduce PipelineHandlerBase class")
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-05-24 21:59:20 +01:00
Benjamin Bara
7d5b38e2ef libipa: camera_sensor_helper: Add IMX327 helper
Add support for the Sony IMX327, which is added to the kernel with
commit 2d41947ec2c0 ("media: i2c: imx290: Add support for imx327
variant"). It is basically a derivate of the IMX290, therefore also
derive the helper.

Signed-off-by: Benjamin Bara <benjamin.bara@skidata.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-05-19 18:25:59 +01:00
Benjamin Bara
a3178dd039 ipa: rkisp1: agc: drop hard-coded analogue gain range
As the sensor's analogue gain range is known (read-out in
IPARkISP1::configure()), drop the limiting hard-coded range.
This enables better performance in low-light conditions for sensors with
a higher gain (e.g. the imx327).

Signed-off-by: Benjamin Bara <benjamin.bara@skidata.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-05-19 18:25:55 +01:00
Laurent Pinchart
e8fccaea46 meson: Fix usage of overwritten pipeline variable
When iterating over enabled pipelines and IPA modules, libcamera
descends into subdirectories in a recursive manner, which involves
nested loops. Both the outer and inner loops use the same loop variable
named 'pipeline'. As the outer loop uses the variable after descending
into the inner directory, it ends up using an incorrect value. Fix it by
moving all use of the variable before the subdir() call, and add a
comment that warns about the issue to avoid reintroducing it.

Fixes: e8526c0c2b ("ipa: meson: Allow nested IPA directory structures")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2023-05-09 06:35:47 +03:00
Jacopo Mondi
120e313450 libcamera: ipa_manager: Allow IPA loading in nested subdirs
Now that we allow IPA modules to live in nested directories for the
RaspberryPi platform, it is required to allow parsing one more level
to be able to run libcamera from the source directory.

Without this patch the $(builddir)/src/ipa/rpi/vc4/ipa_rpi_vc4.so
IPA module cannot be loaded.

The issue is only present when running from the source directory
as when libcamera is installed all IPA modules are deployed to a single
$(prefix)/$(libcamera_libdir)/libamera/ location.

Fixes: 46aefed208 ("pipeline: meson: Allow nested pipeline handler directory structures")
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2023-05-08 18:37:25 +02:00
Elias Naur
4c71ec00c2 libcamera: v4l2_videodevice: Use O_CLOEXEC when exporting DMA buffers
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.

The O_CLOEXEC flag should also be set when obtaining file handles from
the V4L2 VIDIOC_EXPBUF operation, but was missed during the updates to
both d942bdc913 ("libcamera: v4l2_device: openat(2) with O_CLOEXEC to
cleanup after exec(3)") and 436b38fd89 ("libcamera: Open files with
O_CLOEXEC").

Set the O_CLOEXEC flag on calls to ioctl(VIDIOC_EXPBUF).

Fixes: 436b38fd89 ("libcamera: Open files with O_CLOEXEC")
Signed-off-by: Elias Naur <mail@eliasnaur.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-05-08 11:56:14 +03:00
Kieran Bingham
1c512d4065 v4l2: Move the v4l2 compat layer to libexec/libcamera
Move the v4l2-compat.so shared library installation to the libcamera
directory under libexec. This is the same location that the proxy
workers live and will facilitate easier packaging of the V4L2
compatibility layer with distributions.

Create a new libcamera_libexecdir variable within meson to simplify
representation of this path and update the proxy worker meson.build
infrastructure to make use of it as well.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-05-04 20:05:02 +01:00
Naushir Patuck
0fbf6b57a7 pipeline: raspberrypi: Add stream flags to RPi::Stream
Add a flags_ field to indicate stream state information in RPi::Stream.
This replaces the existing external_ and importOnly_ boolean flags.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:59:24 +03:00
Naushir Patuck
6c71ee1f15 pipeline: raspberrypi: Introduce PipelineHandlerBase class
Create a new PipelineHandlerBase class that handles general purpose
housekeeping duties for the Raspberry Pi pipeline handler. Code the
implementation of new class is essentially pulled from the existing
pipeline/rpi/vc4/raspberrypi.cpp file with a small amount of
refactoring.

Create a derived PipelineHandlerVc4 class from PipelineHandlerBase that
handles the VC4 pipeline specific tasks of the pipeline handler. Again,
code for this class implementation is taken from the existing
pipeline/rpi/vc4/raspberrypi.cpp with a small amount of
refactoring.

The goal of this change is to allow third parties to implement their own
pipeline handlers running on the Raspberry Pi without duplicating all of
the pipeline handler housekeeping tasks.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:59:24 +03:00
Naushir Patuck
fd29edccae pipeline: raspberrypi: Make RPi::Stream::name() return const std::string &
Return a const std::string reference from RPi::Stream::name() to avoid
copying a string when not needed.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:59:24 +03:00
David Plowman
503bebd0ed ipa: raspberrypi: agc: Move weights out of AGC
The region weights for the the AGC zones are handled by the AGC
algorithm. Apply them directly in the IPA (vc4.cpp) to the statistics
that we pass to the AGC.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:58:57 +03:00
Naushir Patuck
d903fdbe31 ipa: raspberrypi: Introduce IpaBase class
Create a new IpaBase class that handles general purpose housekeeping
duties for the Raspberry Pi IPA. The implementation of the new class
is essentially pulled from the existing ipa/rpi/vc4/raspberrypi.cpp file
with a minimal amount of refactoring.

Create a derived IpaVc4 class from IpaBase that handles the VC4 pipeline
specific tasks of the IPA. Again, code for this class implementation is
taken from the existing ipa/rpi/vc4/raspberrypi.cpp with a
minimal amount of refactoring.

The goal of this change is to allow third parties to implement their own
IPA running on the Raspberry Pi without duplicating all of the IPA
housekeeping tasks.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:50:15 +03:00
Naushir Patuck
cea3de4226 pipeline: ipa: raspberrypi: Restructure the IPA mojom interface
Restructure the IPA mojom interface to be more consistent in the use
of the API. Function parameters are now grouped into *Params structures
and results are now returned in *Results structures.

The following pipeline -> IPA interfaces have been removed:

signalQueueRequest(libcamera.ControlList controls);
signalIspPrepare(ISPConfig data);
signalStatReady(uint32 bufferId, uint32 ipaContext);

and replaced with:

prepareIsp(PrepareParams params);
processStats(ProcessParams params);

signalQueueRequest() is now encompassed within prepareIsp().

The following IPA -> pipeline interfaces have been removed:

runIsp(uint32 bufferId);
embeddedComplete(uint32 bufferId);
statsMetadataComplete(uint32 bufferId, libcamera.ControlList controls);

and replaced with the following async calls:

prepareIspComplete(BufferIds buffers);
processStatsComplete(BufferIds buffers);
metadataReady(libcamera.ControlList metadata);

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:50:15 +03:00
Naushir Patuck
48e059fa3c pipeline: raspberrypi: rpi_stream: Set invalid buffer to id == 0
At present, the RPiStream buffer ids == -1 indicates an invalid value.
As a simplification, use id == 0 to indicate an invalid value. This
allows for better code readability.

As a consequence of this, use unsigned int for the buffer id values.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:50:14 +03:00
Naushir Patuck
726e9274ea pipeline: ipa: raspberrypi: Refactor and move the Raspberry Pi code
Split the Raspberry Pi pipeline handler and IPA source code into common
and VC4/BCM2835 specific file structures.

For the pipeline handler, the common code files now live in
src/libcamera/pipeline/rpi/common/
and the VC4-specific files in src/libcamera/pipeline/rpi/vc4/.

For the IPA, the common code files now live in
src/ipa/rpi/{cam_helper,controller}/
and the vc4 specific files in src/ipa/rpi/vc4/. With this change, the
camera tuning files are now installed under share/libcamera/ipa/rpi/vc4/.

To build the pipeline and IPA, the meson configuration options have now
changed from "raspberrypi" to "rpi/vc4":

meson setup build -Dipas=rpi/vc4 -Dpipelines=rpi/vc4

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 20:47:40 +03:00
Naushir Patuck
46aefed208 pipeline: meson: Allow nested pipeline handler directory structures
The current pipeline handler build files require a flat directory
struture for each pipeline handler. Modify the build files to remove
this restriction and allow a directory structure such as:

src/libcamera/pipeline/
  |- raspberrypi
      |- common
      |- vc4
  |- rkisp1
  |- ipu3

where each subdir (e.g. raspberrypi/common, raspberrypi/vc4) has its own
meson.build file. Such a directory structure will be introduced for the
Raspberry Pi pipeline handler in a future commit.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 19:10:22 +03:00
Naushir Patuck
e8526c0c2b ipa: meson: Allow nested IPA directory structures
The current IPA build files require a flat directory structure for the
IPAs. Modify the build files to remove this restriction and allow a
directory structure such as:

src/ipa
  |- raspberrypi
      |- common
      |- cam_helpers
      |- controller
      |- vc4
  |- rkisp1
  |- ipu3

where each subdir (e.g. raspberrypi/common, raspberrypi/cam_helper) has
its own meson.build file. Such a directory structure will be introduced
for the Raspberry Pi IPA in a future commit.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 19:08:23 +03:00
Naushir Patuck
6388449a79 libcamera: ipa: Remove character restriction on the IPA name
Remove the restriction on using the '/' character in the IPA name
string. This allows more flexibility in IPA directory structures where
different IPA modules might live in subdirectories under the usual
src/ipa/<platform>/ top level directory.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-04 18:47:53 +03:00