summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_device.cpp
AgeCommit message (Collapse)Author
2023-03-26libcamera: v4l2_device: openat(2) with O_CLOEXEC to cleanup after exec(3)Elias Naur
When an executable using libcamera calls exec(3) while a camera is in use, file descriptors corresponding to the V4L2 video devices are kept open has they have been created without O_CLOEXEC. This results in the video devices staying busy, preventing the new executable from using them: [91] ERROR V4L2 v4l2_videodevice.cpp:1047 /dev/video0[149:cap]: Unableto set format: Resource busy Fix this by opening video devices with O_CLOEXEC, which is generally a good idea in libraries. Signed-off-by: Elias Naur <mail@eliasnaur.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-11-28libcamera: v4l2_device: Workaround faulty control menusKieran Bingham
Some UVC cameras have been identified that can provide V4L2 menu controls without any menu items. This leads to a segfault where we try to construct a ControlInfo(Span<>,default) with an empty span. Convert the v4l2ControlInfo and v4l2MenuControlInfo helper functions to return std::optional<ControlInfo> to be able to account in the caller if the control is valid, and only add acceptable controls to the supported control list. Menu controls without a list of menu items are no longer added as a valid control and a warning is logged. This also fixes a potential crash that would have occured in the unlikely event that a ctrl.minimum was set to less than 0. Bug: https://bugs.libcamera.org/show_bug.cgi?id=167 Reported-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-10-04libcamera: v4l2_device: List controls when setting file descriptorLaurent Pinchart
The base V4L2Device class is bound to a video device node by either open(), which opens the device node and creates a new file descriptor, or setFd(), which takes an already open file descriptor. The former populates the V4L2Device instance controls, while the latter doesn't. This prevents using controls on V4L2 M2M devices. Fix it by populating controls in setFd(), which is called by open(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com>
2022-09-29libcamera: v4l2_device: Log control id instead of errorIdxUmang Jain
v4l2_ext_controls.errorIdx (in the case of single failing control for VIDIOC_*_EXT_CTRLS calls) represents the index of that control. Since it is a single control, we can print the control id rather than its index. This improves logging as the id can be easily co-related with the controls while reading the log. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-05libcamera: v4l2_device: Report device node on failureKieran Bingham
When the V4L2Device fails to open, it is not clear what device caused the failure. The Entity name is presented, but not the device node. Provide it. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-05libcamera: v4l2_device: Map YCbCrEncoding::None to V4L2Laurent Pinchart
The ycbcrEncodingToV4l2 map is missing the YCbCrEncoding::None encoding, which results in a failure of V4L2Device::fromColorSpace() to convert color spaces from libcamera to V4L2 for RGB formats. Fix it by adding the missing encoding. As V4L2 has no such encoding, use V4L2_YCBCR_ENC_DEFAULT as the value doesn't matter. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-09-01libcamera: colorspace: Rectify the ColorSpace::Srgb presetUmang Jain
Rectify the ColorSpace::Srgb to denote that it does not use any Y'Cbcr encoding and uses full range. The kernel on the other hand, recommends to use Rec601 as the encoding for V4L2_COLORSPACE_SRGB. It is not very explicit but it can be inferred that the kernel assumes V4L2_COLORSPACE_SRGB is a YUV-encoded one. However, when the data is in RGB, no encoding is required (and this is denoted by YcbcrEncoding::None in libcamera). Hence, to be clear on the libcamera colorspace API, rectify the ColorSpace::Srgb preset to use YcbcrEncoding::None and full range. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-09-01libcamera: v4l2_device: Adjust colorspace based on pixel formatUmang Jain
V4L2 has no "none" YCbCr encoding, and thus reports an encoding for all formats, including RGB and raw formats. This causes the libcamera ColorSpace to report incorrect encodings for non-YUV formats. Fix it by overriding the encoding reported by the kernel to YCbCrEncoding::None for non-YUV pixel formats and media bus formats. Similarly, override the quantization range of non-YUV formats to full range, as limited range isn't used for RGB and raw formats. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-25libcamera: color_space: Rename Jpeg to SyccLaurent Pinchart
The JPEG color space is badly name, as the JPEG specification (ITU-T T.81) doesn't define any particular color space: The interchange format does not specify a complete coded image representation. Application-dependent information, e.g. colour space, is outside the scope of this Specification. The JFIF specification (ITU-T T.871) is clearer as it requires ITU-R BT.601 YCbCr encoding and a full quantization range: The interpretations of Y, CB, and CR are derived from the E'Y, E'Cb, and E'Cr signals defined in the 625-line specification of Rec. ITU-R BT.601, but these signals are normalized so as to permit the usage of the full range of 256 levels of the 8-bit binary encoding of the Y component. It however doesn't specify color primaries or a transfer function explicitly. It only mentions the latter when describing the conversion from YCbCr to RGB: The inverse relationship for computing full scale 8-bit per colour channel gamma pre-corrected RGB values (following Rec. ITU-R BT.601 gamma pre-correction and colour primary specifications) from YCbCr colours (with 256 levels per component) can be computed as follows: [...] Given that ITU-R BT.601-5 (1995) didn't specify color primaries or a transfer function, and that the later ITU-R BT.601-7 (2011) version specifies color primaries for the 625-line variant that do not match sRGB, the JPEG color space in libcamera is badly named. This is confirmed by ITU-T T.871: As this Recommendation | International Standard is based on the prior informally-circulated JFIF version 1.02 specification that was produced in 1992, which referenced Rec. ITU-R BT.601 (formerly CCIR 601), it references that specification for definition of the E'Y, E'Cb, and E'Cr signals that correspond to the YCBCR values specified herein. However, since the development of the prior JFIF version 1.02 specification, additional industry specifications have been developed, Rec. ITU-R BT.601 has been updated, and common industry practice has emerged which often follows the sYCC specification in IEC 61966-2-1/Amd.1. The difference between the use of the colour interpretation specification in this Recommendation | International Standard and that of the sYCC specification may be considered negligible in practice. Rename the color space to sYCC, as its definition matches the sYCC standard, and indicate that it is typically used to encode JPEG images. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-01-08libcamera: v4l2_device: Add support for integer array controlsDavid Plowman
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>
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-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-09-02libcamera: Drop emitter object pointer from signal argumentsLaurent Pinchart
Many signals used in internal and public APIs carry the emitter pointer as a signal argument. This was done to allow slots connected to multiple signal instances to differentiate between emitters. While starting from a good intention of facilitating the implementation of slots, it turned out to be a bad API design as the signal isn't meant to know what it will be connected to, and thus shouldn't carry parameters that are solely meant to support a use case specific to the connected slot. These pointers turn out to be unused in all slots but one. In the only case where it is needed, it can be obtained by wrapping the slot in a lambda function when connecting the signal. Do so, and drop the emitter pointer from all signals. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-08-12libcamera: controls: Create ControlInfoMap with ControlIdMapJacopo Mondi
ControlInfoMap does not have a ControlId map associated, but rather creates one with the generateIdMap() function at creation time. As a consequence, when in the need to de-serialize a ControlInfoMap all the ControlId it contains are created by the deserializer instance, not being able to discern if the controls the ControlIdMap refers to are the global libcamera controls (and properties) or instances local to the V4L2 device that has first initialized the controls. As a consequence the ControlId stored in a de-serialized map will always be newly created entities, preventing lookup by ControlId reference on a de-serialized ControlInfoMap. In order to make it possible to use globally available ControlId instances whenever possible, create ControlInfoMap with a reference to an externally allocated ControlIdMap instead of generating one internally. As a consequence the class constructors take and additional argument, which might be not pleasant to type in, but enforces the concepts that ControlInfoMap should be created with controls part of the same id map. As the ControlIdMap the ControlInfoMap refers to needs to be allocated externally: - Use the globally available controls::controls (or properties::properties) id map when referring to libcamera controls - The V4L2 device that creates ControlInfoMap by parsing the device's controls has to allocate a ControlIdMap - The ControlSerializer that de-serializes a ControlInfoMap has to create and store the ControlIdMap the de-serialized info map refers to Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-09libcamera: Rename 'method' to 'function'Laurent Pinchart
Usage of 'method' to refer to member functions comes from Java. The C++ standard uses the term 'function' only. Replace 'method' with 'function' or 'member function' through the whole code base and documentation. While at it, fix two typos (s/backeng/backend/). The BoundMethod and Object::invokeMethod() are left as-is here, and will be addressed separately. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-06-25libcamera/base: Move event_notifier to baseKieran Bingham
Move the event notifier, and associated header updates. Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-06-25libcamera/base: Move extended base functionalityKieran Bingham
Move the functionality for the following components to the new base support library: - BoundMethod - EventDispatcher - EventDispatcherPoll - Log - Message - Object - Signal - Semaphore - Thread - Timer While it would be preferable to see these split to move one component per commit, these components are all interdependent upon each other, which leaves us with one big change performing the move for all of them. Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-06-25libcamera/base: Move utils to the base libraryKieran Bingham
Move the utils functionality to the libcamera/base library. Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-06-14libcamera: V4L2Device: Support v4l2 menu controlHirokazu Honda
This adds a support of v4l2 menu. The control info for v4l2 menu contains indices without names and 64bit values of querymenu. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-06-07libcamera: V4L2Device: Remove the controls order assumption in updateControls()Hirokazu Honda
The original updateControls() has the assumption that ctrls and v4l2Ctrls lists are in the same order. It is dependent on the caller implementation though. This changes updateControls() implementation so that it works without the assumption. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-05-25Revert "libcamera: V4L2Device: Remove the controls order assumption in ↵Laurent Pinchart
updateControls()" This reverts commit 34bee5e84ecba01e0ded5cacbc46c277c5a0edba. The commit introduced a breakage in the master branch, reported by linux-surface users already. Let's revert it while discussing the propert fix. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Acked-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Tested-by: Umang Jain <umang.jain@ideasonboard.com>
2021-05-25libcamera: V4L2Device: Remove the controls order assumption in updateControls()Hirokazu Honda
The original updateControls() has the assumption that ctrls and v4l2Ctrls lists are in the same order. It is dependent on the caller implementation though. This changes updateControls() implementation so that it works without the assumption. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-05-24libcamera: V4L2Control: remove V4L2Control classesHirokazu Honda
V4L2ControlId and V4L2ControlInfo are just convenience classes to create ControlId and ControlInfo from v4l2_query_ext_control. Therefore, there is no need of being a class. It is used only from V4L2Device. This removes the classes and put the equivalent functions of creating ControlId and ControlInfo in v4l2_device.cpp. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-05-11libcamera: camera_sensor: Fix frame lengths calculated by sensorInfo()David Plowman
The minimum and maximum vblanking can change when a new format is applied to the sensor subdevice, so be sure to retrieve up-to-date values. The V4L2Device acquires the new updateControlInfo() method to perform this function, and which the CameraSensor calls automatically if its setFormat method is used to update the sensor. However, not all pipeline handlers invoke the setFormat method directly, so the new method must be made publicly available for pipeline handlers to call if they need to. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> 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: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-04-26libcamera: V4L2Device: Use Span in updateControls()Hirokazu Honda
V4L2Device::updateControls() takes two arguments, raw array and its size, for the v4l2_ext_control values. This replaces it with libcamera::Span. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> 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> Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2021-04-26libcamera: V4L2Device: Replace VLA with std::vector in setControls()Hirokazu Honda
The original code uses Variable-Length-Array, which is not officially supported in C++. This replaces the array with std::vector. 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: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2021-04-26libcamera: V4L2Device: Replace VLA with std::vector in getControls()Hirokazu Honda
The original code uses Variable-Length-Array, which is not officially supported in C++. This replaces the array with std::vector. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo@jmondi.org>
2020-11-15libcamera: Move EventDispatcher to internal APILaurent Pinchart
There's no user of the EventDispatcher (and the related EventNotifier and Timer classes) outside of libcamera. Move those classes to the internal API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-10libcamera: v4l2_device: Move start of frame detection to V4L2DeviceNiklas Söderlund
The V4L2_EVENT_FRAME_SYNC event may occur on both V4L2 video-devices (V4L2VideoDevice) and sub-devices (V4L2Subdevice). Move the start of frame detection to the common base class of the two, V4L2Device. There is no functional change. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-28libcamera: v4l2_device: Remove unused set of retNiklas Söderlund
The last assignment of the ret variable in getControls() is not consumed so it's unnecessary to set it. This likely originates from a similar code flow in setControls() where the ret variable is later consumed. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-09-29libcamera: Allow access to v4l2_query_ext_ctrl structure for a V4L2 controlDavid Plowman
The V4L2Device::controlInfo method simply returns a pointer to the v4l2_query_ext_ctrl structure for the given control, which has already been retrieved and stored. Signed-off-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: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-08-05libcamera: v4l2_device: Add method to lookup device pathNiklas Söderlund
Add a method to lookup a V4L2 devices path in sysfs. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-05-16libcamera: Move internal headers to include/libcamera/internal/Laurent Pinchart
The libcamera internal headers are located in src/libcamera/include/. The directory is added to the compiler headers search path with a meson include_directories() directive, and internal headers are included with (e.g. for the internal semaphore.h header) #include "semaphore.h" All was well, until libcxx decided to implement the C++20 synchronization library. The __threading_support header gained a #include <semaphore.h> to include the pthread's semaphore support. As include_directories() adds src/libcamera/include/ to the compiler search path with -I, the internal semaphore.h is included instead of the pthread version. Needless to say, the compiler isn't happy. Three options have been considered to fix this issue: - Use -iquote instead of -I. The -iquote option instructs gcc to only consider the header search path for headers included with the "" version. Meson unfortunately doesn't support this option. - Rename the internal semaphore.h header. This was deemed to be the beginning of a long whack-a-mole game, where namespace clashes with system libraries would appear over time (possibly dependent on particular system configurations) and would need to be constantly fixed. - Move the internal headers to another directory to create a unique namespace through path components. This causes lots of churn in all the existing source files through the all project. The first option would be best, but isn't available to us due to missing support in meson. Even if -iquote support was added, we would need to fix the problem before a new version of meson containing the required support would be released. The third option is thus the only practical solution available. Bite the bullet, and do it, moving headers to include/libcamera/internal/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2020-04-28libcamera: v4l2_device: Simplify usage of getControls()Laurent Pinchart
The V4L2Device::getControls() function takes a ControlList that needs to be pre-populated with dummy entries for the controls that need to be read. This is a cumbersome API, especially when reading a single control. Make it nicer by passing the list of V4L2 controls as a vector of control IDs, and returning a ControlList. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-04-26libcamera: v4l2_device: Update documentationJacopo Mondi
Compound controls are now supported, but they're still listed as unsupported in some parts of the V4L2Device class documentation. Fix this by removing those parts. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-03-23libcamera: v4l2_device: Enable enumeration of U8 controlsJacopo Mondi
Enable the enumeration of V4L2 array controls with V4L2_CTRL_TYPE_U8 type. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-23libcamera: v4l2_device: Support reading U8 array controlsJacopo Mondi
Add support to retrieve the value of array controls of type V4L2_CTRL_TYPE_U8. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-03-23libcamera: v4l2_device: Support writing array U8 controlsJacopo Mondi
Add support to write array controls of type V4L2_CTRL_TYPE_U8. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-03-23libcamera: v4l2_controls: Cache query control informationJacopo Mondi
Cache the V4L2 control info retrieved with VIDIOC_QUERY_EXT_CTRL at control listing time for later use. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-03-20libcamera: controls: Rename ControlRange to ControlInfoLaurent Pinchart
To prepare for storage of additional information in the ControlRange structure, rename it to ControlInfo. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-03-20libcamera: v4l2_controls: Fix usage of strerror()Jacopo Mondi
On failure, the return code from V4L2Device::ioctl() is the negative error code set by the failed ::ioctl() system call. When the return code of V4L2Device::ioctl() is provided to strerror() it has to be negated again to obtain the positive error code. Fix a few wrong usages of the return code which provided to the strerror() function a negative error code. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-01-14libcamera: Switch from utils::make_unique to std::make_uniqueLaurent Pinchart
Now that we're using C++-14, drop utils::make_unique for std::make_unique. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-03libcamera: v4l2_device, v4l2_videodevice: call open system call directlyPaul Elder
We are preparing to integrate the V4L2 adaptation layer, which will intercept open() calls (among others) via LD_PRELOAD. To prevent libcamera's own open() calls from being intercepted, replace them with a direct syscall. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-11-20libcamera: controls: Index ControlList by unsigned intLaurent Pinchart
In preparation for serialization, index the ControlList by unsigned int. This will allow deserializing a ControlList without requiring external information. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-15libcamera: controls: Merge ControlInfoMap and V4L2ControlInfoMapLaurent Pinchart
The ControlInfoMap and V4L2ControlInfoMap classes are very similar, with the latter adding convenience accessors based on numerical IDs for the former, as well as a cached idmap. Both features can be useful for ControlInfoMap in the context of serialisation, and merging the two classes will further simplify the IPA API. Import all the features of V4L2ControlInfoMap into ControlInfoMap, turning the latter into a real class. A few new constructors and assignment operators are added for completeness. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-15libcamera: v4l2_controls: Derive V4L2ControlInfoMap from ControlInfoMapLaurent Pinchart
Replace the std::map<> used as the base type for V4L2ControlInfoMap by ControlInfoMap, which is an alias for an std::unsorted_map<> with the same key and value types. This shortens the code. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-15libcamera: v4l2_controls: Store a ControlRange in V4L2ControlInfoMapLaurent Pinchart
V4L2ControlRange only offers a convenience constructor for a ControlRange. Store the ControlRange instead of V4L2ControlRange in V4L2ControlInfoMap to make the map less dependent on V4L2 types. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-15libcamera: v4l2_controls: Replace V4L2ControlInfo with V4L2ControlRangeLaurent Pinchart
The V4L2ControlInfo class only stores a ControlRange. Make it inherit from ControlRange to provide a convenience constructor from a struct v4l2_query_ext_ctrl and rename it to V4L2ControlRange. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-15libcamera: v4l2_controls: Index V4L2ControlInfoMap by ControlId *Laurent Pinchart
To bring the libcamera and V4L2 control info maps closer, index the latter by ControlId * like the former. As V4L2ControlInfoMap is widely indexed by V4L2 numerical IDs, add accessors based on numerical IDs. This allows complete removal of the ControId pointer from the V4L2ControlInfo, as the ControId is accessible as the key when iterating over the map. A handful of users have to be modified to adapt to the change. The controlInfo argument from V4L2Device::updateControls() can also be removed as it itsn't used anymore. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-10-15libcamera: v4l2_controls: Move V4L2ControlId out of V4L2ControlInfoJacopo Mondi
In order to reconcile the libcamera and V4L2 control info maps, we need to move the V4L2ControlId embedded in V4L2ControlInfo map out of the class. Store the V4L2ControlId instances in the V4L2Device that creates them, and only reference them from V4L2ControlInfo. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>