Commit graph

1555 commits

Author SHA1 Message Date
Laurent Pinchart
4321f6e96e utils: raspberrypi: ctt: json_pretty_print: Make output file a class member
Instead of passing the output file to every method of the printer class,
make it a class member.

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>
2020-07-03 18:15:38 +03:00
Laurent Pinchart
926fe94e4c utils: raspberrypi: ctt: json_pretty_print: Turn printer into a class
Instead of passing a state dictionary to every method, turn the printer
into a class and store the state internally.

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>
2020-07-03 18:15:32 +03:00
Laurent Pinchart
1a5b168592 utils: raspberrypi: ctt: json_pretty_print: Fix printer test
The ctt_pretty_print_json.py file supports being run standalone to test
the code. It however suffers from multiple issues:

- The same input file name is hardcoded, and doesn't exist in the
  repository
- The input file name is used instead of JSON data

Fix both issues and make the input file selectable on the command line.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
2020-07-03 18:15:19 +03:00
David Plowman
fd2b55cb3f ipa: raspberrypi: Enable focus measure without recompile
Previously, output of the focus measure could not be enabled without
recompiling (because of the RPI_LOGGING_ENABLE macro). This uses the
libcamera logging mechanism instead, so can be enabled/disabled at
runtime.

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>
2020-07-03 04:24:00 +03:00
Niklas Söderlund
73b18967b6 libcamera: ipu3: cio2: Do not proxy signal
Do not proxy the signal in the CI2Device when there is no need for it,
remove it.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-07-03 00:10:07 +02:00
Niklas Söderlund
c3648da6e9 libcamera: ipu3: Make it easier to read when a request may be completed
It's confusing to read the code and understand that a request is only
completed before being processed by the ImgU if it only contains a
single RAW buffer. Add a boolean variable with a explanatory name to
make this clearer, no functional change.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-07-03 00:10:04 +02:00
Niklas Söderlund
8e137b0819 libcamera: raspberrypi: Document vc_sm_cma pointer sharing with IPA
Sharing a pointer with the IPA is fragile as it will not work with all
IPC mechanisms. Document that it's a temporary workaround that should be
reworked.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-07-03 00:08:31 +02:00
Andrej Shadura
8dbd0049e0 ipa/pipeline: rkisp1: Fix spelling
Fix a typo in the word "unknown".

Suggested-by: IOhannes m zmölnig <umlaeute@debian.org>
Signed-off-by: Andrej Shadura <andrewsh@debian.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-07-01 17:11:29 +01:00
Laurent Pinchart
e7aa92a883 utils: raspberrypi: ctt: Fix pycodestyle W605
W605 invalid escape sequence '\.'

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
2020-06-29 17:38:18 +03:00
Niklas Söderlund
6bc4af7d0b libcamera: ipu3: cio2: Use Size::isNull()
Use the Size::isNull() helper instead of using local code.

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-06-29 16:17:38 +02:00
Laurent Pinchart
7fc65e9680 libcamera: geometry: Add isNull() function to Size class
It's common for code to check if a size is null. Add a helper function
to do so.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-06-29 16:17:34 +02:00
Jacopo Mondi
d8848693bf libcamera: raspberrypi: Fail on unsupported stream role
When an unsupported stream roles is requested to
generateConfiguration(), the function shall fail instead of simply
ignoring the request.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-06-29 09:39:56 +02:00
Jacopo Mondi
b7dfefb882 libcamera: raspberrypi: Refuse invalid roles configuration
The generateConfiguration() implementation does not check if the
requested list of roles can actually be satisfied. The camera API
documentation prescribes the function shall fail in that case, instead
of silently adjust the returned configuration.

Fix this by implementing the same logic as the validate() function
implements, as the pipeline handler supports one raw stream and up to
two output streams.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-06-29 09:39:36 +02:00
Jacopo Mondi
a3e6c2b3d9 libcamera: ipu3: Fix wrong indentation
Fix wrong parameter indent in generateConfiguration() function
implementation.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-06-29 09:35:45 +02:00
Jacopo Mondi
5267ca8e02 libcamera: ipu3: Accept an empty roles list
The IPU3 pipeline handler that does not support receiving an empty list
of roles at generateConfiguration() time. This contradicts the camera
API which allows application to generate empty CameraConfiguration to
be later manually filled.

Fix this by returning an empty CameraConfiguration if the list of
requested roles is empty. While at it, align the style with the other
pipeline handlers.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-06-29 09:35:17 +02:00
Jacopo Mondi
83d37d5466 libcamera: ipu3: Improve error on multiple raw streams request
Improve the error message emitted when multiple raw streams are
requested.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-06-29 09:33:49 +02:00
Niklas Söderlund
d130c55073 libcamera: ipu3: imgu: Use unique_ptr for video and subdevices
Instead of manually deleting the video and subdevices in the destructor
use std::unique_ptr.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
1e0cd804f0 libcamera: ipu3: imgu: Remove ImgUOutput
The struct ImgUOutput now only contains one member that is in use, the
video device. Remove the struct and use the video device directly
instead.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
003645f598 libcamera: ipu3: Remove IPU3Stream
The pipeline specific subclass of the pipeline is empty, remove it.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
1f59558777 libcamera: ipu3: Remove the active flag from IPU3Stream
The active_ flag is only used inside one function, remove the global
flag and handle it inside the single function.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
5bbef188f6 libcamera: ipu3: Do not duplicate data in IPU3Stream
Do not keep the duplicated ImgUDevice::ImgUOutput information in both
the stream and camera data classes. Remove it from the stream and only
access it from the camera data class.

Which stream is which can instead be checked by comparing it to the
known streams in camera data. This match how streams are checked in
other parts of the code making the pipeline more coherent.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
b80c01843c libcamera: ipu3: imgu: Use specific functions to configure each sink
When the IPU3 pipeline only provided streams to applications that came
from the ImgU it made sense to have a generic function to configure all
the different outputs. With the addition of the RAW stream this begins
to be cumbersome to read and make sense of in the PipelineHandlerIPU3
code. Replace the generic function that takes a specific argument for
which sink to configure with a specific function for each sink.

This makes the code easier to follow as it's always clear which of the
ImgU sinks are being configured without knowing the content of a
generically named variable. It also paves the way for future
improvements.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
d275243979 libcamera: ipu3: imgu: Mark things that are internal as private
Mark all variables and functions that are only used internally as
private.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
2ea9d2c1d0 libcamera: ipu3: imgu: Do not cache index
The numerical index of the imgu is only used to create its name in
string form. There is no need to keep it around after that, remove it.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
dd391df851 libcamera: ipu3: imgu: Move the ImgUDevice class to separate files
In preparation of refactoring the IPU3 pipeline handler breakout the
ImgUDevice into its own .cpp and .h file, no functional change.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
942f6c5ceb libcamera: ipu3: Remove usage of IPU3CameraData from ImgUDevice
The IPU3CameraData argument to allocateBuffers() and freeBuffers() is no
longer used and can be removed.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
72e36e8d8d libcamera: ipu3: Always import buffers for ImgU sinks
When the IPU3 pipeline was first developed sinks of the ImgU that where
not active still needed to have buffers allocated to allow streaming to
start. This is no longer true, it's enough that the sinks have imported
buffers to allow streaming to start. As we already need to import
buffers for stream that are active we can align the two cases and always
import buffers.

With this there is no longer a reason to store the allocated
FrameBuffers to keep them alive and the vector tracking them can be
removed.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
dcb3e7e2df libcamera: ipu3: Import instead of allocate statistic buffers
Statistics buffers are not yet used by the IPU3 pipeline, they are never
queued to the statistics video device or in any other way consumed. The
kernel driver will however not allow video streaming to start if buffers
are not either allocated or imported on the statistics video device.
Instead of allocating the buffers wasting memory that is never used,
import buffers.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Niklas Söderlund
76332f0f8a libcamera: ipu3: Remove unused name_ filed from IPU3Stream
The field is never used, remove it.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-28 14:25:46 +02:00
Laurent Pinchart
39fa976b46 libcamera: Summarize licensing terms in COPYING.rst
Storing detailed licensing information in SPDX headers and in the DEP5
file gives precise information to handle license compliance, but lacks a
high-level overview. Summmarize the licensing terms in a COPYING.rst
file to facilitate understanding of the libcamera project licenses, and
to clarify that closed-source third-party IPA modules are permitted.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
2020-06-26 15:18:25 +03:00
Niklas Söderlund
40148cfcaf libcamera: ipu3: Allow zero-copy RAW stream capture
With the refactored CIO2 interface it's now easy to add zero-copy for
buffers in the RAW stream. Use the internally allocated buffers inside
the CIO2Device if no buffer for the RAW stream is provided by the
application, or use the application-provided buffer if any.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Niklas Söderlund
a96eb0cc8f libcamera: ipu3: cio2: Hide buffer allocation and freeing from users
The allocation and freeing of buffers for the CIO2 is handled in the
IPU3 pipeline handlers start() and stop() functions. These functions
also call CIO2Device start() and stop() at the appropriate times so
move the CIO2 buffer allocation/freeing inside the CIO2Device and reduce
the complexity of the exposed interface.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Niklas Söderlund
bb82835bc5 libcamera: ipu3: cio2: Make the V4L2 devices private
In order to make the CIO2 easier to extend with new features make the
V4L2 devices (sensor, CIO2 and video device) private members. This
requires a few helper functions to be added to allow for the IPU3 driver
to still be able to interact with all parts of the CIO2. These helper
functions will later be extended to add new features to the IPU3
pipeline.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Niklas Söderlund
d2c94456d9 libcamera: ipu3: cio2: Add function to generate configuration
Collect the code used to generate configurations for the CIO2 block in
the CIO2Device class. This allows simplifying the code and allow further
changes to only happen at one code location.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Niklas Söderlund
906ff25ef8 libcamera: ipu3: cio2: Consolidate information about formats
Instead of spreading the mapping between media bus codes and V4L2 FourCC
all over the CIO2 code collect it in a single map and extract the data
from it. This is done in preparation of adding PixelFormat information
to the mix.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Niklas Söderlund
6bd3d7259f libcamera: ipu3: cio2: Move the CIO2Device class to separate files
In preparation of refactoring the IPU3 pipeline handler breakout the
CIO2Device into its own .cpp and .h file, no functional change.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Niklas Söderlund
2cd9556021 libcamera: ipu3: Calculate number of buffers for ImgU
Decouple the number of buffers to allocate for the ImgU from the number
of buffers allocated for the CIO2. Instead of blindly following the CIO2
pick the maximum number of buffers requested for any stream facing
applications.

This is potentially wasteful, as each stream could allocate just as many
buffers as requested by the application instead of the maximum from the
set. But this is not more wasteful than what is already used by the
pipeline and should be fixed on top after the decoupling of the two
processing units.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Niklas Söderlund
e00b7b7c1a libcamera: ipu3: Breakout stream assignment to new function
Selecting which stream is the most suitable for the requested
configuration is mixed with adjusting the requested format when
validating configurations. This is hard to read and got worse when
support for Bayer formats was added. Break it out to a separate
function.

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-06-26 13:32:29 +02:00
Niklas Söderlund
82ddb680a8 libcamera: ipu3: Fold mediaBusToFormat() into only caller
Make the code easier to read and refactor.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-26 13:32:29 +02:00
Chris Chinchilla
cbf0a92185 libcamera: pipeline_handler: Correct small typo in acquireMediaDevice description
Correct a small typo in the method description.

Fixes: d6a8860747 ("libcamera: pipeline_handler: Keep track of MediaDevice")
Signed-off-by: Chris Chinchilla <chris@gregariousmammal.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-06-26 11:22:01 +01:00
Chris Chinchilla
e284261cf0 libcamera: pipeline_handler: Fix incorrect method in CameraData docs
The pipeline handler documentation incorrectly references an old API
usage of setCameraData, which should have been updated to
registerCamera() while updating pipeline handlers to ensure they all
have a pipeline-specific "CameraData" allocation.

Update the remaining documentation reference.

Fixes: b581b9576a ("libcamera: pipeline_handler: Make pipeline-specific data mandatory")
Signed-off-by: Chris Chinchilla <chris@gregariousmammal.com>
Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-06-26 11:12:11 +01:00
Naushir Patuck
0396380614 libcamera: pipeline: raspberrypi: Add StreamFormats to StreamConfiguration
In generateConfiguration(), add the device node specific formats to the
StreamConfiguration for each StreamRole requested.

Signed-off-by: Naushir Patuck <naush@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>
2020-06-25 17:47:51 +03:00
David Plowman
23e15e72f9 ipa: rpi: Add "focus" algorithm
Adds FocusStatus to the image metadata, containing contrast measurements
across the image. Optionally also prints a contrast measure to the
console, to aid in manual adjustment of the lens. Note that it is not an
actual auto-focus algorithm that can drive a lens!

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25 17:47:51 +03:00
Paul Elder
0952f2014d v4l2: v4l2_camera_proxy: Serialize accesses to the proxy
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-25 23:47:13 +09:00
Paul Elder
12fa2fe020 v4l2: v4l2_camera_proxy: Fix buffer flags related to queueing
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-25 23:47:13 +09:00
Paul Elder
3f01ccf24b v4l2: v4l2_camera_proxy: Don't allow buffers to be freed if still mmaped
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-25 23:47:13 +09:00
Paul Elder
4d150c7faf v4l2: v4l2_camera_proxy: Don't allow streamon if no buffers have been requested
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-25 23:47:13 +09:00
Paul Elder
609036a9e6 v4l2: v4l2_camera_proxy: Check arg->index bounds for querybuf, qbuf, dqbuf
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-25 23:47:13 +09:00
Paul Elder
9909ce33f9 v4l2: v4l2_camera: Clear pending requests on freeBuffers and streamOff
V4L2 allows buffer queueing before streamon while libcamera does not.
The compatibility layer thus saves these buffers in a pending queue
until streamon, and then automatically queues them. However, this
pending queue is not cleared when the buffers are freed, so the
following sequence of actions will cause a use-after-free:

1. queue buffers
2. free buffers
   - buffers from 1. stay in pending queue but have been freed
3. queue buffers
4. streamon
   - buffers from 1. are enqueued, then the buffers from 3. are
     enqueued. Use-after-free segfault when libcamera tries to handle
     the enqueued buffers from 1.

Fix this by clearing the pending request queue upon buffers being freed.
Also clear the pending request queue on streamOff, for correctness.

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-25 23:47:13 +09:00
Paul Elder
566ccd75ca v4l2: v4l2_camera: Don't use libcamera::Semaphore for available buffers
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-25 23:47:13 +09:00