Commit graph

2829 commits

Author SHA1 Message Date
Naushir Patuck
7b84a17e21 pipeline: raspberrypi: Return all ISP resolutions from generateConfiguration()
The libcamerasrc gstreamer component does seem to not allow stream resolutions
that are not advertised by PipelineHandler::generateConfiguration(). This has
been raised in a bug report [1].

Fix this behavior by advertising a SizeRange from the minimum ISP resolution, up
to the sensor resolution from PipelineHandlerRPi::generateConfiguration().

[1] https://bugs.libcamera.org/show_bug.cgi?id=105

Fixes: f16acb275c ("pipeline: raspberrypi: Restrict the advertised maximum ISP output resolution")
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>
2022-01-19 10:51:28 +00:00
David Plowman
b2290573c0 pipeline: raspberrypi: Simplify calculation of sensor's native Bayer order
Now that the sensor is defined to list mbus codes using its native
(untransformed) Bayer order, the method of obtaining it can be
simplified. We don't have to try and reset the flips, we just use the
value directly from the sensor.

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-01-19 10:27:07 +00:00
David Plowman
7f1e39e3e2 libcamera: camera_sensor: Clear camera flips after opening the device
We clear the V4L2_CID_HFLIP and V4L2_CID_VFLIP controls immediately
after opening the camera device. This means the camera's Bayer format
and mbus codes will be in the sensor's "native" order, and we document
this to be the case so that it can be relied upon.

Clearing the flips is harmless where sensor flips do not affect the
Bayer order.

This also fixes a bug in the Raspberry Pi pipeline handler where the
native Bayer order was being computed wrongly, but the new behaviour
here will be helpful to other pipeline handlers too. A subsequent
commit will tidy up the Raspberry Pi pipeline handler in this area as
it can now be simplified.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Fixes: 83a5128161 (pipeline: raspberrypi: Convert the pipeline handler to use media controller)
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-01-19 10:27:07 +00:00
Laurent Pinchart
61670bb338 v4l2: v4l2_camera_proxy: Use file description in debug messages
Debug messages in V4L2CameraProxy print the numerical file descriptor,
which isn't very human-friendly. Replace it with the V4L2CameraFile
description that includes the full path. While at it, refactor the
messages to use __func__ instead of manually copying function names.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-01-14 14:02:49 +02:00
Laurent Pinchart
fc96573697 v4l2: v4l2_compat_manager: Store V4L2CameraFile in mmaps_
The mmaps_ map stores a pointer to the V4L2CameraProxy to avoid
increasing the reference count on the V4L2CameraFile shared pointer
needlessly. While this provides a small optimization, it prevents
accessing the V4L2CameraFile from the munmap() function which doesn't
take an fd as argument.

To prepare for improved debugging that will require access to
V4L2CameraFile in munmap(), store the V4L2CameraFile pointer in mmaps_.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-01-14 14:02:49 +02:00
Laurent Pinchart
c006f96485 v4l2: v4l2_camera_proxy: Drop trace message from freeBuffers()
The freeBuffers() function is only called from vidioc_reqbufs(), which
already logs a trace message. Remove the duplicate.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-01-14 14:02:49 +02:00
Laurent Pinchart
07d5fff29c v4l2: v4l2_camera_file: Store file description
Create a string that describe the file from the path and file
descriptor. This will be used in log messages to clearly identify which
file an operation is related to.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-01-14 14:02:49 +02:00
Laurent Pinchart
43c86fb0c6 v4l2: v4l2_compat_manager: Print path and fd in openat()
The V4L2 compat layer prints debug messages that mention the file
descriptor of the video device, but no message that links the device
path to the file descriptor. Fix it by adding a debug message in
openat().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-01-14 14:02:49 +02:00
Laurent Pinchart
bc3d27234e v4l2: v4l2_camera_proxy: Zero flags in VIDIOC_REQBUFS
The V4L2 compatibility layer doesn't support any of the VIDIOC_REQBUFS
flags. They are all correctly ignored, but also need to be zeroed
before returning to indicate that they haven't been taken into account.

This fixes a v4l2-compliance failure:

Buffer ioctls (Input 0):
                fail: ../../utils/v4l2-compliance/v4l2-test-buffers.cpp(682): coherent
        test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL

Fixes: aa45336399 ("include: linux: Update kernel headers to version v5.16-rc7")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Vedant Paranjape <vedantparanjape160201@gmail.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-01-14 14:02:38 +02:00
Naushir Patuck
eff9de397a pipeline: raspberrypi: Demote the category of a logging message
Switch the "no buffers available" log message from Info to Debug so that it does
not get output by default.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.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-01-10 17:12:15 +02:00
David Plowman
63dcbc7cf2 libcamera: pipeline: raspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control
If the sensor exposes the V4L2_CID_NOTIFY_GAINS control, assume it
means the sensor wants to be told the latest colour gains.

We store whether the control exists and if so its default value, to
save us checking for it on every frame.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-01-08 15:52:09 +02:00
David Plowman
d7bdfd3111 libcamera: v4l2_device: Add support for integer array controls
V4L2Device::setControl and V4L2Device::updateControl are both updated
to handle ControlTypeInteger32 array controls.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-01-08 15:48:59 +02:00
Vedant Paranjape
d769a59566 v4l2: v4l2_camera_proxy: Add EXPBUF as one of the supported ioctl
To support DMABUF as one of the memory buffer, we need to implement
EXPBUF in the v4l2 compat layer.

This patch implements vidioc_expbuf as one of the supported ioctls.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=89
Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.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>
2022-01-08 15:42:09 +02:00
Naushir Patuck
44d59841e1 pipeline: raspberrypi: Add support for Video Mux and Bridge devices
This change will allow the pipeline handler to enumerate and control Video
Mux or Bridge devices that may be attached between sensors and a particular
Unicam instance. Cascaded mux or bridge devices are also handled.

A new member function RPiCameraData::enumerateVideoDevices(), called from
PipelineHandlerRPi::registerCamera(), is used to identify and open all mux and
bridge subdevices present in the sensor -> Unicam link.

Relevant links are enabled/disabled and pad formats correctly set in
PipelineHandlerRPi::configure() before the camera is started.

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-01-06 12:28:24 +00:00
Naushir Patuck
8400cb0711 pipeline: raspberrypi: Move sensor entity detection out of registerCamera()
Enumerate the sensor device entities in PipelineHandlerRPi::match() and loop
over PipelineHandlerRPi::registerCamera() for each sensor found. This will
allow the pipeline handler to register multiple cameras attached to a single
Unicam instance with a Video Mux device.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-01-06 12:28:24 +00:00
Kieran Bingham
cd7863503a libcamera: pkg-config: Do not hardcode version
The pkg-config version should not be hardcoded, and it should match the
version of the library, ideally with point releases where possible.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-01-06 11:29:58 +00:00
Laurent Pinchart
152adad97a libcamera: pipeline_handler: Make lock() and unlock() thread-safe
The PipelineHandler lock() and unlock() functions are documented as
thread-safe, but they're not. Fix them using a mutex.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-01-03 15:31:19 +02:00
Laurent Pinchart
ec6921d7f7 libcamera: media_device: Move recursive lock handling to pipeline handler
The MediaDevice lock is meant to prevent concurrent usage of multiple
cameras from the same pipeline handlers. As media devices are acquired
by pipeline handlers, we can't have multiple pipeline handlers trying to
lock the same media device. The recursive locking detection can thus be
moved to the pipeline handler. This simplifies the media device
implementation that now implements true lock semantics, and prepares for
support of concurrent camera usage.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-01-03 15:31:14 +02:00
Laurent Pinchart
46b32fa0e4 libcamera: controls: Use ASSERT() instead of assert()
The ASSERT() macro integrates with the logging infrastructure, use it to
replace assert().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-01-03 15:31:13 +02:00
Laurent Pinchart
22b61a4f30 libcamera: pipeline: simple: Rename Entity::link to sourceLink
The Entity::link member has an ambiguous name. Rename it to sourceLink
to clarify that it stores the link on the source pad.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-29 21:35:16 +02:00
Paul Elder
57c2171238 android: Increase result metadata size
Increase the initial size of the result metadata, as we will be adding
more entries in the near future.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-22 16:10:10 -06:00
Paul Elder
f4ec026d28 android: camera_capabilities: Fix the type of the capability vector
The type of elements of the capability vector that is set in the static
metadata must be uint8_t. The enum will not suffice, as it is int32_t.
Fix this.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-22 16:10:10 -06:00
Paul Elder
86ab84677f android: camera_metadata: Add setEntry helper
Add setEntry() helper, that automatically detects if updateEntry() or
addEntry() should be used.

Note that updateEntry() will fail if the entry was not yet added, and
addEntry() will fail is the entry was already added. They are silent
failures that cause unexpected values to find their way into the android
metadata instance.

Previously this helper was not necessary, as (with respect to the
current use case) the preview template generator would always add a key
so the other template generators that used the preview template as
boilerplate could reliably use updateEntry(). The preview template
generator will soon decide based on capabilities whether or not to add
keys, so the other template generators need a helper to decide whether
to use updateEntry() or addEntry().

For now only implement it for enums and arithmetic values, as they will
mainly be used in populating templates.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-22 16:07:17 -06:00
Paul Elder
733d690b93 android: camera_capabilities: Set read sensor settings capability
A libcamera camera that supports the manual sensor capability also
satisfies all the requirements for the read sensor settings capability.
Set it.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-22 16:07:14 -06:00
Paul Elder
955c996ea6 android: camera_capabilities: Add messages for lack of FULL support
Print messages when some feature is missing that causes hardware level
FULL to not be supported.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-22 16:06:37 -06:00
David Plowman
13fdf9d0dc libcamera: pipeline: raspberrypi: Support color spaces
The Raspberry Pi pipeline handler now sets color spaces correctly.

In generateConfiguration() it sets them to reasonable default values
based on the stream role.

validate() now calls validateColorSpaces() to ensure that the
requested color spaces are sensible, before proceeding to check what
the hardware can deliver.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-13 11:29:02 +02:00
David Plowman
5e5eadabd8 libcamera: camera: Add validateColorSpaces to CameraConfiguration class
This function forces raw streams to have the "raw" color space, and
also optionally makes all non-raw output streams to share the same
color space as some platforms may require this.

When sharing color spaces we take the shared value to be the one from
the largest of these streams. This choice is ultimately arbitrary, but
can be appropriate if smaller output streams are used for image
analysis rather than human consumption, when the precise colours may
be less important.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-13 11:29:02 +02:00
David Plowman
4a56809981 libcamera: v4l2_subdevice: Support passing ColorSpaces to V4L2 subdevices
The ColorSpace from the StreamConfiguration is now handled
appropriately in the V4L2Subdevice.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-13 11:29:02 +02:00
David Plowman
c8a4b52e3a libcamera: v4l2_subdevice: Add colorSpace field to V4L2SubdeviceFormat
This adds a ColorSpace field to the V4L2SubdeviceFormat so that we can
set and request particular color spaces from V4L2.

This commit simply adds the field and fixes some occurrences of brace
initializers that would otherwise be broken. A subsequent commit will
pass and retrieve the value correctly to/from V4l2 itself.

Signed-off-by: David Plowman <david.plowman@raspberrypi.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>
2021-12-13 11:29:01 +02:00
David Plowman
3e520cadf1 libcamera: video_device: Support passing ColorSpaces to V4L2 video devices
The ColorSpace from the StreamConfiguration is now handled
appropriately in the V4L2VideoDevice.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-13 11:29:01 +02:00
David Plowman
e86aed6166 libcamera: video_device: Convert between ColorSpace class and V4L2 formats
Add functions to the V4L2Device class to convert to and from
libcamera ColorSpace.

These functions are added to the base V4L2Device class so that they can
be shared both by the video device class and subdevices.

With the ColorSpace class, the color space and related other fields
are stored together, corresponding to a number of fields in the
various different V4L2 format structures. Template functions are
therefore a convenient implementation, and we must explicitly
instantiate the templates that will be needed.

Note that unset color spaces are converted to requests for the
device's "default" color space.

Signed-off-by: David Plowman <david.plowman@raspberrypi.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>
2021-12-13 11:29:01 +02:00
David Plowman
96f990ea6c libcamera: stream: Add ColorSpace fields to StreamConfiguration
This is so that applications can choose appropriate color spaces which
will then be passed down to the V4L2 devices.

The ColorSpace field is actually optional. If it is not set you will
get the camera's default color space.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-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: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-13 11:29:01 +02:00
David Plowman
ddb5e9d37e libcamera: Add ColorSpace class
This class represents a color space by defining its color primaries,
the transfer (gamma) function it uses, the YCbCr encoding and whether
the output is full or limited range.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-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: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-13 11:29:01 +02:00
Jacopo Mondi
015fa7f718 android: Remove CameraWorker
The CameraWorker class purpose was to handle acquire fences for incoming
capture requests directed to libcamera.

Now that fences are handled by the core library, it is not required to
handle them in the HAL and the CameraWorker and CaptureRequest classes
can be dropped.

Update the core in CameraDevice class accordingly to queue Requests
directly to the libcamera::Camera and set the release_fence to the
value of the FrameBuffer::fence() for streams of type ::Direct.

While at it make CameraRequest::StreamBuffer::fence a UniqueFD to ease
the management of the fences file descriptor values.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
7aef77130a libcamera: pipeline_handler: Prepare Request
Before queueing a request to the device, any synchronization fence from
the Request framebuffers has to be waited on.

Connect the Request::Private::prepared signal to the function that
queues requests to the hardware and call Request::Private::prepare().

When the waiting request queue is inspected, verify if it has completed its
preparation phase and queue it to the device.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
3fb3c0d791 libcamera: request: Add Request::Private::prepare()
Add a prepare() function to the Private Request representation.

The prepare() function is used by the PipelineHandler class to
prepare a Request to be queued to the hardware.

The current implementation of prepare() handles the fences associated
with the Framebuffers part of a Request. The function starts an event
notifier for each of those and emits the Request::prepared signal when
all fences have been signalled or an optional timeout has expired.

The optional timeout allows to interrupt blocked waits and notify the
Request as failed so that it can be cancelled.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
f6b6f15b54 libcamera: pipeline: Introduce stopDevice()
Since a queue of waiting Requests has been introduced, not all Requests
queued to the PipelineHandler are immediately queued to the device.

As a Camera can be stopped at any time, it is required to complete the
waiting requests after the ones queued to the device had been completed.

Introduce a pure virtual PipelineHandler::stopDevice() function to be
implemented by pipeline handlers and make the PipelineHandler::stop()
function call it before completing pending requests.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
6cd5c958b7 libcamera: pipeline_handler: Split request queueing
In order to prepare to handle synchronization fences at Request
queueing time, split the PipelineHandler::queueRequest() function in
two, by creating a list of waiting requests and introducing the
doQueueRequest() function that queues requests to the device in the
order the pipeline has received them.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
a645898af5 libcamera: request: Add Fence to Request::addBuffer()
Add an optional fence parameter to Request::addBuffer() to allow
associating a Fence with a FrameBuffer.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
7a34707bfd libcamera: framebuffer: Add Fence to FrameBuffer
Add to the FrameBuffer::Private class a unique pointer to a
Fence.

The Fence will be used to signal the availability of the Framebuffer for
incoming data transfer.

The Fence will be associated to a FrameBuffer at Request::addBuffer()
time, and if correctly signalled, reset by the core at Request queue
time.

If a FrameBuffer completes with errors, due to a Fence wait failure, the
Fence will still be owned by the FrameBuffer and it is application
responsibility to correctly reset it before reusing the buffer.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
8ac8ecb1e1 libcamera: fence: Introduce Fence
Introduce a Fence class which models a synchronization primitive that
allows to notify the availability of a resource.

The Fence is modeled as a wrapper of a UniqueFD instance where
read events are used to signal the Fence. The class can be later
extended to support additional signalling mechanisms.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Laurent Pinchart
db37335ee0 libcamera: request: Make Request class Extensible
Implement the D-Pointer design pattern in the Request class to allow
changing internal data without affecting the public ABI.

Move the internal fields that are not needed to implement the public
API to the Request::Private class already. This allows to remove
the friend class declaration for the PipelineHandler class, which can
now use the Request::Private API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Move all internal fields to Request::Private and remove friend  declaration]
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Jacopo Mondi
6705596e29 libcamera: Print Timer identifier
The Timer debug output does not report to which timer a condition refers
to. Fix that by printing the Timer address.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-11 17:53:40 +01:00
Naushir Patuck
f16acb275c pipeline: raspberrypi: Restrict the advertised maximum ISP output resolution
Limit the advertised ISP output sizes available to the sensor resolution in
PipelineHandlerRPi::generateConfiguration(). The user is free to configure a
larger resolution than this, and this will work. However, this stops strange
behavior in applications that use the V4L2 compatability layer to run, and
request the largest possible advertised resolution, which is much larger than
the sensor resolution.

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>
2021-12-08 14:45:30 +00:00
Naushir Patuck
5964420570 pipeline: raspberrypi: Reduce logging verbosity
Demote a couple of lines of logging to Debug level to reduce the verbosity of
the log output during startup.

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>
2021-12-08 14:45:30 +00:00
Laurent Pinchart
1c88396a54 libcamera: media_device: Skip all non-data links during enumeration
The MediaDevice::populateLinks() function iterates over data links by
skipping interface links. This isn't very future-proof, it will break if
the kernel adds new types of links. Fix it by only considering data
links instead of blacklisting interface links.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-12-07 19:09:38 +02:00
Laurent Pinchart
e788807371 libcamera: Use utils::abs_diff()
Use the new utils::abs_diff() function where appropriate to replace
manual implementations.

While at it fix a header ordering issue in
src/libcamera/pipeline/raspberrypi/raspberrypi.cpp.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-12-07 19:09:35 +02:00
Laurent Pinchart
f413f944d7 libcamera: base: utils: Add abs_diff() utility function
The abs_diff() function computes the absolute difference of two
elements. This may seem trivial at first, but can lead to unexpected
results when operating on unsigned operands. A common implementation
of the absolute difference of two unsigned int (used through the
libcamera code base) is

	std::abs(static_cast<int>(a - b))

but doesn't return the expected result when either a or b is larger than
UINT_MAX / 2 due to overflows. The abs_diff() function offers a safe
alternative.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-12-07 19:09:31 +02:00
Laurent Pinchart
72679c682e libcamera: base: shared_fd: Don't dup() an invalid fd
The SharedFD::dup() implementation calls the C library dup() function on
the fd. When the SharedFD instance is invalid, this produces an invalid
fd, which is the correct behaviour, but logs an error message.

Fix it by returning an invalid UniqueFD directly when the SharedFD is
invalid. This also saves a system call, which is always nice to do.

Fixes: fcf98514cb ("libcamera: base: file_descriptor: Return UniqueFD from dup()")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-12-07 19:09:22 +02:00
Umang Jain
37c41aa6a6 android: Apply 1% tolerance to minFrameDuration capping
We have some stream resolution which can provide slightly better
frame duration than what we cap (i.e. 1/30 fps). The problem with
this is CTS complains if the camera goes faster during the test
than minFrameDuration reported for that resolution. For instance,

1080p minFrameDuration:
	- Nautilus : 33282000ns
	- Soraka   : 33147000ns

Both are less than capped minFrameDuration 1/30 fps (33333333.33ns).

This patch considers this situation and doesn't cap the
minFrameDuration if the hardware can provide frame durations slightly
better. The tolerance considered is 1% only from the cap.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-12-07 21:32:03 +05:30