summaryrefslogtreecommitdiff
path: root/src/libcamera
AgeCommit message (Collapse)Author
2022-01-06pipeline: raspberrypi: Move sensor entity detection out of registerCamera()Naushir Patuck
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-06libcamera: pkg-config: Do not hardcode versionKieran Bingham
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-03libcamera: pipeline_handler: Make lock() and unlock() thread-safeLaurent Pinchart
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-03libcamera: media_device: Move recursive lock handling to pipeline handlerLaurent Pinchart
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-03libcamera: controls: Use ASSERT() instead of assert()Laurent Pinchart
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>
2021-12-29libcamera: pipeline: simple: Rename Entity::link to sourceLinkLaurent Pinchart
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-13libcamera: pipeline: raspberrypi: Support color spacesDavid Plowman
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-13libcamera: camera: Add validateColorSpaces to CameraConfiguration classDavid Plowman
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-13libcamera: v4l2_subdevice: Support passing ColorSpaces to V4L2 subdevicesDavid Plowman
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-13libcamera: v4l2_subdevice: Add colorSpace field to V4L2SubdeviceFormatDavid Plowman
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-13libcamera: video_device: Support passing ColorSpaces to V4L2 video devicesDavid Plowman
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-13libcamera: video_device: Convert between ColorSpace class and V4L2 formatsDavid Plowman
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-13libcamera: stream: Add ColorSpace fields to StreamConfigurationDavid Plowman
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-13libcamera: Add ColorSpace classDavid Plowman
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-11libcamera: pipeline_handler: Prepare RequestJacopo Mondi
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-11libcamera: request: Add Request::Private::prepare()Jacopo Mondi
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-11libcamera: pipeline: Introduce stopDevice()Jacopo Mondi
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-11libcamera: pipeline_handler: Split request queueingJacopo Mondi
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-11libcamera: request: Add Fence to Request::addBuffer()Jacopo Mondi
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-11libcamera: framebuffer: Add Fence to FrameBufferJacopo Mondi
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-11libcamera: fence: Introduce FenceJacopo Mondi
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-11libcamera: request: Make Request class ExtensibleLaurent Pinchart
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-11libcamera: Print Timer identifierJacopo Mondi
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-08pipeline: raspberrypi: Restrict the advertised maximum ISP output resolutionNaushir Patuck
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-08pipeline: raspberrypi: Reduce logging verbosityNaushir Patuck
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-07libcamera: media_device: Skip all non-data links during enumerationLaurent Pinchart
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-07libcamera: Use utils::abs_diff()Laurent Pinchart
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-07libcamera: base: utils: Add abs_diff() utility functionLaurent Pinchart
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-07libcamera: base: shared_fd: Don't dup() an invalid fdLaurent Pinchart
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: fcf98514cb4e ("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-07pipeline: raspberrypi: Return the sensor formats from generateConfiguration()Naushir Patuck
Return the available sensor PixelFormats and sizes from generateConfiguration() if the StreamRole is set to StreamRole::Raw. The existing code returns the PixelFormats and sizes for all other StreamRole types. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-12-06libcamera: pipeline: ipu3: Apply a requested test pattern modeHirokazu Honda
This introduces a way to set controls immediately for a capture in ipu3 pipeline handler. It enables to apply a test pattern mode per frame. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-06libcamera: camera_sensor: Enable to set a test pattern modeHirokazu Honda
This adds a function to set a camera sensor driver a test pattern mode. CameraSensor initializes the test pattern mode by Off. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-06libcamera: camera_sensor: Reference test pattern modes by enum typeHirokazu Honda
The CameraSensor stores TestPatternModes as an int32_t. This prevents the compiler from verifying the usage against the defined enum types. Fix references to the TestPatternMode to store the value as the TestPatternModeEnum type which is defined by the control generator. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-06libcamera: framebuffer: Enable attaching additional data to FrameBufferHirokazu Honda
We cannot have a subclass of FrameBuffer because it is marked as final. This adds a FrameBuffer constructor with FrameBuffer::Private. So we can attach some additional resources with FrameBuffer through a customized FrameBuffer::Private class. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-06libcamera: ipu3: Only process focus if we have a lensKieran Bingham
If there is no lens detected by the system, then we will not be able to set the control, so we can skip processing of the list. Furthermore, if the IPA has not set a V4L2_CID_FOCUS_ABSOLUTE control, then a warning will be printed as the lensControls.get() will not succeed. Break out of the control parsing when there is no CameraLens device, or if there is no absolute focus control set by the IPA. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-12-04libcamera: base: shared_fd: Add comparison operatorsLaurent Pinchart
Add == and != comparison operators between two SharedFD instances, and use them to replace manuel get() calls. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: base: shared_fd: Rename fd() to get()Laurent Pinchart
For consistency with UniqueFD, rename the fd() function to get(). Renaming UniqueFD::get() to fd() would have been another option, but was rejected to keep as close as possible to the std::shared_ptr<> and std::unique_ptr<> APIs. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
2021-12-04libcamera: base: Rename FileDescriptor to SharedFDLaurent Pinchart
Now that we have a UniqueFD class, the name FileDescriptor is ambiguous. Rename it to SharedFD. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: pipeline: raspberrypi: DmaHeaps: Use UniqueFD for a file descriptorHirokazu Honda
Manages a file descriptor owned by DmaHeaps for a dma handle by UniqueFD. Furthermore, DmaHeaps::alloc() creates a new file descriptor and the returned file descriptor is owned by a caller. This also clarifies it by changing the returned value to UniqueFD. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: v4l2_videodevice: Pass FileDescriptor to open()Laurent Pinchart
The V4L2VideoDevice::open() function that takes an open file handle duplicates it internally, and leaves the original handle untouched. This is documented but not enforced through language constructs. Fix it by passing a FileDescriptor to the function. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: v4l2_videodevice: Use fd for a file descriptorHirokazu Honda
Manages file descriptors owned by V4L2VideoDevice by UniqueFD. This also changes the return type of exportDmabufFd to UniqueFD from FileDescriptor in order to represent a caller owns the returned file file descriptor. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: v4l2_device: Use UniqueFD for a file descriptorHirokazu Honda
Manages a file descriptor owned by V4L2Device for a v4l2 device node by UniqueFD. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: media_device: Manage fd by UniqueFDHirokazu Honda
Manages a file descriptor owned by MediaDevice for a media device node by UniqueFD. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: process: Manage pipe fds by UniqueFDHirokazu Honda
Manages the file descriptors owned by Process for pipe by UniqueFDs. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> 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-04libcamera: ipc_unixsocket: Fix file descriptor leakLaurent Pinchart
The file descriptor created for the remote side of the socket is passed to the forked process, but never closed. Fix the leak. The fix can be tested by running the unixsocket_ipc unit test under valgrind with `valgrind --track-fds=yes ./test/ipc/unixsocket_ipc`. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: ipc_unixsocket: Use UniqueFD for a file descriptorHirokazu Honda
IPCUnixSocket::create() creates two file descriptors. One of them is stored in IPCUnixSocket and the other is returned to a caller. This clarifies the ownership using UniqueFD. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04libcamera: file: Manage fd by UniqueFDHirokazu Honda
Manages the file descriptor owned by File by UniqueFD. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> 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-04libcamera: event_dispatcher_poll: Manage fd by UniqueFDHirokazu Honda
Manages the event file descriptor owned by EventDispatcherPoll by UniqueFD. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> 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-03libcamera: base: file_descriptor: Return UniqueFD from dup()Laurent Pinchart
The dup() function returns a duplicate of the file descriptor. Wrapping it in a FileDescriptor isn't wrong as such, but it prevents from using it in contexts where a UniqueFD is needed. As the duplicate is guaranteed to have a single owner when created, return it as a UniqueFD instead. A FileDescriptor can easily be created from the UniqueFD if desired. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-03libcamera: base: file_descriptor: Add constructor from UniqueFDHirokazu Honda
Add a FileDescriptor constructor that takes a UniqueFD, transfering ownership of the file descriptor to the FileDescriptor. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>