summaryrefslogtreecommitdiff
path: root/src/v4l2/v4l2_camera_proxy.cpp
AgeCommit message (Collapse)Author
2022-01-08v4l2: v4l2_camera_proxy: Add EXPBUF as one of the supported ioctlVedant Paranjape
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>
2021-12-04v4l2: v4l2_camera: Return int in getBufferFd()Hirokazu Honda
V4L2Camera::getBufferFd() returns FileDescriptor. However, the file descriptor is still owned by V4L2Camera. It should rather return an integer to represent V4L2Camera doesn't have the ownership of the file descriptor. 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-01v4l2: Consolidate mutex classes to Mutex and MutexLockerHirokazu Honda
std::mutex and std::unique_lock are used in v4l2 directory, mixing Mutex and MutexLocker. This consolidates them to Mutex and MutexLocker. This also fixes vidioc_dqbuf argument to take Mutex instead of MutexLocker. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-09-10v4l2: v4l2_camera_proxy: Set the compressed flag in enum_fmtPaul Elder
Set the compressed flag in ENUM_FMT if the format is MJPEG. As the only compressed format that libcamera currently supports is MJPEG, this should be sufficient. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-09-10v4l2: v4l2_camera_proxy: Report the proper format name in enum_fmtPaul Elder
Now that libcamera has the V4L2 format names, retrieve and report those names in ENUM_FMT. While at it, refactor the code slightly with PixelFormatInfo. This fixes the test failures on v4l2-compliance with the v4l2 compatilibity layer that were observed in version v4l2-compliance version 1.21.0-4838. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-09-07v4l2: Sum bytesused for all planes when dequeuing bufferLaurent Pinchart
The V4L2 compatibility layer supports the single-planar API only, and thus exposes a single V4L2 buffer plane to applications, regardless of the number of planes in the FrameBuffer. For multi-planar frame buffers, the bytesused value isn't correct as it only takes the first plane into account. Fix it by summing the bytesused values for all FrameBuffer planes. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-09-07libcamera: framebuffer: Prevent modifying the number of metadata planesLaurent Pinchart
The number of metadata planes should always match the number of frame buffer planes. Enforce this by making the vector private and providing accessor functions. As this changes the public API, update all in-tree users accordingly. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
2021-09-07libcamera: Use V4L2PixelFormat::fromPixelFormat()Laurent Pinchart
Replace manual searches for V4L2 pixel format in the PixelFormatInfo with the V4L2PixelFormat::fromPixelFormat() helper function. This prepares for multi-planar support that will modify how V4L2 pixel formats are stored in PixelFormatInfo. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-09-05v4l2: Use V4L2PixelFormat::toPixelFormat()Laurent Pinchart
Replace the open-coded PixelFormat lookup with the V4L2PixelFormat::toPixelFormat() helper function. This simplifies the implementation. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasoboard.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>
2020-10-21v4l2: camera: Prevent shadowing within V4L2Camera::BufferKieran Bingham
Rename the internal member variables to use the post-fixed '_' member variable naming style. This in turn ensures variable shadowing does not occur in the member initializer list of the constructor. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-10-20v4l2: Omit extra semicolonsHirokazu Honda
LOG_DECLARE_CATEGORY macro contains the semicolon. The end semicolon with the macro is unnecessary. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-08-25v4l2: camera: Merge getStreamConfig() with open()Laurent Pinchart
The V4L2CameraProxy always calls V4L2Camera::getStreamConfig() right after V4L2Camera::open(), and never afterwards. Simplify the code by returning the initial configuration from V4L2Camera::open() and removing V4L2Camera::getStreamConfig(). 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>
2020-08-25v4l2: camera_proxy: Store v4l2_pix_format instead of v4l2_formatLaurent Pinchart
The V4L2 compatibility layer only uses the fmt.pix field of curV4L2Format_. There's no need to cache the full v4l2_format, store v4l2_pix_format only and rename the member variable from curV4L2Format_ to v4l2PixFormat_. While at it, group the V4L2-related member variables together in the V4L2CameraProxy class. 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>
2020-08-25v4l2: camera_proxy: Pass const reference to setFmtFromConfig()Laurent Pinchart
The setFmtFromConfig() method doesn't modify its parameter, make it const. 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>
2020-08-05libcamera: camera: Rename name() to id()Niklas Söderlund
Rename Camera::name() to camera::id() to better describe what it represents, a unique and stable ID for the camera. While at it improve the documentation for the camera ID to describe it needs to be stable for a camera between resets of the system. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-07-10v4l2: v4l2_camera_proxy: Use stream config in tryFormatPaul Elder
For handling try_fmt, the values should be filled in by validating the stream configuration, and not by recalculating them or manually checking against the cached list of formats and sizes. Add a new V4L2Camera::validateConfiguration() function to validate a configuration and use it to obtain size, format, stride, and frameSize values. If the format negotiation fails, return error from try_fmt and s_fmt. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-07-10v4l2: v4l2_camera_proxy: Get stride and frameSize from stream configPaul Elder
The stride and frameSize should be obtained through StreamConfiguration rather than PixelFormatInfo, as pipeline handlers might have different values (eg. for alignment). Get the stride and frameSize values from StreamConfiguration instead of from PixelFormatInfo. This removes the need for V4L2CameraProxy's calculation helper functions (bplMultiplier, imageSize, v4l2ToDrm, drmToV4L2, calculateSizeImage) and formats, so remove them. This also removes the need for V4L2CameraProxy::calculateSizeImage, so remove it,. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Serialize accesses to the proxyPaul Elder
Make the V4L2 compatibility layer thread-safe by serializing accesses to the V4L2CameraProxy with a lock. Release the lock when blocking for dqbuf. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Fix buffer flags related to queueingPaul Elder
Fix buffer flags related to queueing and dequeueing: - don't allow a buffer with the same index that is already in the queue to be enqueued again - don't clear the done flag upon qbuf - do clear the done flag upon dqbuf - set the flags in V4L2CameraProxy's internal buffers, and not just in the buffers returned from qbuf Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Don't allow buffers to be freed if still mmapedPaul Elder
In VIDIOC_REQBUFS with count = 0, if the buffers are still mmaped, they should not be allowed to be freed. Add a check for this. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Don't allow streamon if no buffers have been requestedPaul Elder
Make VIDIOC_STREAMON return -EINVAL if no buffers have been allocated with reqbufs. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Check arg->index bounds for querybuf, qbuf, dqbufPaul Elder
There were no bounds checks for the index argument for VIDIOC_QUERYBUF, VIDIOC_QBUF, and VIDIOC_DQBUF. Add them. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera: Don't use libcamera::Semaphore for available buffersPaul Elder
In V4L2, a blocked dqbuf should not not also block a streamoff. This means that on streamoff, the blocked dqbuf must return (with error). We cannot do this with the libcamera semaphore, so pull out the necessary components of a semaphore, and put them into V4L2Camera, so that dqbuf from V4L2CameraProxy can wait on a disjunct condition of the availability of the semaphore or the stopping of the stream. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Clear internal buffer vector on reqbufs 0Paul Elder
If VIDIOC_REQBUFS with count = 0 is called when the stream is not on, clear the proxy's internal vector of buffer. If the stream is on when reqbufs 0 is called, return -EBUSY. Note that this is contrary to what the V4L2 docs say (reqbufs 0 when streaming should also streamoff), but it is how the V4L2 implementation works. v4l2-compliance doesn't seem to care either way, however, so we cater to the implementation, and no longer call streamoff on reqbufs 0. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: noop if streamon when stream is already onPaul Elder
If VIDIOC_STREMAON is called when the stream is already on, do a noop. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Disallow dqbuf when not streamingPaul Elder
Make VIDIOC_DQBUF return -EINVAL if the stream is not turned on. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Implement VIDIOC_ENUM_FRAMESIZESPaul Elder
Implement VIDIOC_ENUM_FRAMESIZES in the V4L2 compatibility layer. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Implement VIDIOC_ENUMINPUT, VIDIOC_G/S_INPUTPaul Elder
Implement VIDIOC_ENUMINPUT, VIDIOC_G_INPUT, and VIDIOC_S_INPUT. Only the zeroth input device is supported, and the info returned by enuminput is hardcoded and basic. This is sufficient to pass v4l2-compliance. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Implement VIDIOC_G/S_PRIORITYPaul Elder
Implement VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY. The behaviour documented in the V4L2 specification doesn't match the implementation in the Linux kernel, implement the latter. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Fix v4l2-compliance support for extended formatsPaul Elder
Fix the following v4l2-compliance error: fail: v4l2-compliance.cpp(652): !(caps & V4L2_CAP_EXT_PIX_FORMAT) Simply add V4L2_CAP_EXT_PIX_FORMAT to capabilities in querycap. In addition, populate the necessary fields in struct v4l2_pix_format to support extended pixel formats in try_fmt and g/s_fmt, and clear the reserved field for enum_fmt. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Check for null arg values in main ioctl handlerPaul Elder
The ioctl handlers currently don't check if arg is null, so if it ever is, it will cause a segfault. Check that arg is null and return -EFAULT in the main vidioc ioctl handler. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Set timestamp monotonic buffer flag on reqbufsPaul Elder
Set buffer flag V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC at VIDIOC_REQBUFS after the buffers have been allocated. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Clear reserved field in reqbufsPaul Elder
Clear the reserved field in arg struct v4l2_reqbuffers of VIDIOC_REQBUFS. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_proxy: Free old buffers on reqbufs > 0Paul Elder
Free buffers, if any were previously allocated, at VIDIOC_REQBUFS with count > 0. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_compat: Support multiple openPaul Elder
Previously, since we acquired the libcamera camera upon open(), it was impossible to support multiple open, as any subsequent opens would return error because the camera would already be acquired. To fix this, we first initialize the camera in the first call to V4L2CameraProxy::open(), just to heat up the stream format cache. We then add ownership by a V4L2CameraFile of a V4L2Camera via the V4L2CameraProxy. All vidioc ioctls prior to reqbufs > 0 (except for s_fmt) are able to access the camera without ownership. A call to reqbufs > 0 (and s_fmt) will take ownership, and the ownership will be released at reqbufs = 0. While ownership is assigned, the eventfd that should be signaled (and cleared) by V4L2Camera and V4L2CameraProxy is set to the V4L2CameraFile that has ownership, and is cleared when the ownership is released. In case close() is called without a reqbufs = 0 first, the ownership is also released on close(). We also use the V4L2CameraFile to contain all the information specific to an open instance of the file. This removes the need to keep track of such information within V4L2CameraProxy via multiple maps from int fd to info. Since V4L2 does not expect reqbufs 0 to ever return error, make V4L2CameraProxy::freeBuffers() return void. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: V4L2CameraProxy: Take V4L2CameraFile as argument for intercepted callsPaul Elder
Prepare for using the V4L2CameraFile as a container for file-specific information in the V4L2 compatibility layer by making it a required argument for all V4L2CameraProxy calls that are directed from V4L2CompatManager, which are intercepted via LD_PRELOAD. Change V4L2CameraFile accordingly. Also change V4L2CompatManager accordingly. Instead of keeping a map of file descriptors to V4L2CameraProxy instances, we keep a map of V4L2CameraFile instances to V4L2CameraProxy instances. When the proxy methods are called, feed the file as a parameter. The dup function is also modified, in that it is removed from V4L2CameraProxy, and is handled completely in V4L2CompatManager, as a map from file descriptors to V4L2CameraFile instances. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-23libcamera: Add support for planar YUV422 and YUV420 formatsDavid Plowman
These formats can be helpful when downstream applications or libraries support them natively (avoiding a costly conversion). Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Tested-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-06-19v4l2: v4l2_compat: Intercept open64, openat64, and mmap64Paul Elder
Some applications (eg. Firefox, Google Chrome, Skype) use open64, openat64, and mmap64 instead of their non-64 versions that we currently intercept. Intercept these calls as well. _LARGEFILE64_SOURCE needs to be set so that the 64-bit symbols are available and not synonymous to the non-64-bit versions on 64-bit systems. Also, since we set _FILE_OFFSET_BITS to 32 to force the various open and mmap symbols that we export to not be the 64-bit versions, our dlsym to get the original open and mmap calls will not automatically be converted to their 64-bit versions. Since we intercept both 32-bit and 64-bit versions of open and mmap, we should be using the 64-bit version to service both. Fetch the 64-bit versions of openat and mmap directly. musl defines the 64-bit symbols as macros that are equivalent to the non-64-bit symbols, so we put compile guards that check if the 64-bit symbols are defined. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # Compile with musl Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-06-18v4l2: Replace explicit DRM FourCCs with libcamera formatsLaurent Pinchart
Use the new pixel format constants to replace usage of macros from drm_fourcc.h. 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-06-17v4l2: v4l2_camera_proxy, v4l2_camera: Check return values of read/writePaul Elder
The return value of the write to the eventfd (to signal POLLIN) from V4L2Camera and the read from the eventfd (to clear POLLIN) from V4L2CameraProxy was ignored. Check the return value, and print an error message. Reported-by: Coverity CID=290743 Reported-by: Coverity CID=290744 Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-09v4l2: v4l2_camera_proxy: Support MJPEGPaul Elder
Add an entry for MJPEG in V4L2CameraProxy's PixelFormatInfo list to allow proper calculation of sizeimage for MJPEG, such that the parameters to mmap can align properly instead of failing. This allows MJPEG to be used in the V4L2 compatibility layer. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-08v4l2: v4l2_camera_proxy: Fix NV24 subsamplingKieran Bingham
The NV24 pixelFormatInfo table entry defines an incorrect horizontal sub-sampling. Update to the correct value. Fixes: 29c5508075c1 ("v4l2: camera_proxy: Create format info array") Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-08v4l2: v4l2_camera_proxy: Fix segfault on restarting streamsPaul Elder
The V4L2 compatibility layer keeps track of the index of the next buffer to be dequeued, to handle VIDIOC_DQBUF. This index is set to 0 on startup and incremented (modulo #frames), and is otherwise never reset. This means that if the last handled frame index is not #frames-1, and the stream is restarted without restarting libcamera and the V4L2 compatilibity layer, the buffer index number won't match with the libcamera buffer index number, causing a segfault. Fix this by resetting the current buffer index to zero on VIDIOC_STREAMON. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-06-08v4l2: v4l2_compat: Add eventfd signaling to support pollingPaul Elder
To support polling, we need to be able to signal when data is available to be read (POLLIN), as well as events (POLLPRI). Add the necessary calls to eventfd to allow signaling POLLIN. We signal POLLIN by writing writing to the eventfd, and clear it by reading from the eventfd, upon VIDIOC_DQBUF. Note that eventfd does not support signaling POLLPRI, so we don't yet support V4L2 events. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-08v4l2: v4l2_camera_proxy: Don't return -EINVAL for zero sizeimage in REQBUFSPaul Elder
If VIDIOC_REQBUFS returns -EINVAL, it signals to the application that the requested buffer or memory type is not supported. If we return -EINVAL due to a zero sizeimage, then the application will think that we don't support a memory type that we actually do. We cannot error on a zero sizeimage, because reqbufs could be called merely to probe what IO methods we support; qv4l2, for example, called reqbufs once with userptr and once more with mmap, both times with count=1. On the other hand, sizeimage will be zero for formats whose size we don't know how to calculate, such as MJPEG. If we try to stream such formats anyway, we will get a floating point exception and crash. Issue a warning for now, and don't return -EINVAL, so that we can continue operation. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-08v4l2: v4l2_camera_proxy: Acquire only one buffer semaphore on VIDIOC_DQBUFPaul Elder
We use a semaphore to atomically keep track of how many buffers are available for dequeueing. The check for how to acquire the semaphore was incorrect, leading to a double acquire upon a successful nonblocking acquire. Fix this. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-06-08v4l2: v4l2_camera_proxy: Fix bounds check for VIDIOC_ENUM_FMTPaul Elder
VIDIOC_ENUM_FMT is meant to return -EINVAL if the requested index is out of bounds. This bounds is obtained from the libcamera Camera's list of formats. The bounds check for this list was incorrect; fix it. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-28v4l2: Relicense V4L2 compatibility layer under LGPLLaurent Pinchart
The V4L2 compatibility layer is licensed under the GPL. It is compiled as a binary separate from libcamera.so, and is loaded into the address space of processes through LD_PRELOAD to intercept calls to the C library. It is our understanding and intent that the GPL license doesn't propagate to the binaries whose calls are intercepted, considering those binaries are not derivative work of the V4L2 compatibility layer and are not designed to be linked to the V4L2 compatibility layer. There is however a possibly grey area if binaries are packaged with a shell script wrapper that loads the V4L2 compatibility layer. This could lead to license-related issues if such packaging is performed by Linux distributions or system integrators. To clarify the intent and lift the doubts, relicense the V4L2 compatibility layer under the LGPL. The V4L2 compatibility layer code itself still benefits from the license protection, while its usage with third-party binaries is clearly allowed as intended. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Acked-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Acked-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>