Commit graph

652 commits

Author SHA1 Message Date
Laurent Pinchart
33d3c4e204 libcamera: request: Add cookie to make request tracking easier
Applications often have to map requests queued to a camera to external
resources. To make this easy, add a 64-bit integer cookie to the Request
class that is set when the request is created and can be retrieved at
any time, especially in the request completion handler. The cookie is
completely transparent for libcamera and is never modified.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:40 +03:00
Laurent Pinchart
185fe3d4b4 libcamera: pipeline_handler: Simplify request completion
libcamera guarantees that requests complete in sequence. This
requirement is currently pushed down to pipeline handlers. Three out of
four of our pipeline handlers implement that requirement based on the
sole assumption that buffers will always complete in sequeuence, while
the IPU3 pipeline handler implements a more complex logic.

It turns out that the logic can be moved to the base PipelineHandler
class with support from the Request class. Do so to simplify the
pipeline handlers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:40 +03:00
Laurent Pinchart
a775234d66 libcamera: camera: Don't check buffer count before freeing buffers
There's no need to check if buffers have been allocated before freeing
them as the BufferPool::destroyBuffers() method is a no-op when no
buffers have been allocated. Document this fact explicitly, and remove
the buffer count check.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:39 +03:00
Laurent Pinchart
e8e80bfa8d libcamera: camera: Don't move buffers away from request at completion
For a historical reason that isn't fully understood, the request
completion handler in the Camera class moves all buffers away from the
request's buffer map to a local variable before emitting the request
completion signal. There's no reason to do so, and it makes it
impossible for requests to access buffers in their destructor. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:38 +03:00
Niklas Söderlund
c4b9ccb45a libcamera: utils: Add clamp()
C++11 does not support std::clamp(), add a custom implementation in
utils.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-13 21:27:47 +09:00
Laurent Pinchart
3e14a1bcb0 libcamera: event_notifier_poll: Fix notifier unregistration during event processing
An event notifier may be unregistered from its activated signal. This
can cause the notifiers set entry in notifiers_ to be deleted while
processNotifiers() is looping over the notifiers_ map, leading to
problems.

To fix this, add a flag to the EventNotifierPoll class to indicate that
event processing is in progress. If the flag is set, the notifiers_
entry is not deleted during notifier unregistration, but will be deleted
by the event processing loop.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-13 07:47:36 +03:00
Niklas Söderlund
8f1dbd6a92 libcamera: ipa_module: Fix open source license verification
The second argument to std::array is the size of the array, not of the
elements it contains. Fix this by turning the std::array into a simple
array of const char pointers.

Fixes: 099815b853 ("libcamera: ipa_module: add isOpenSource")
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2019-07-13 13:07:24 +09:00
Paul Elder
bfbc25785f libcamera: process: fix error checking
The return value of a read() call is mistakenly checked for nonzero
rather than less than zero. Fix this.

Fixes: df23ab95f3 ("libcamera: process: fix compilation on Chromium OS")
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2019-07-12 17:48:30 +09:00
Paul Elder
df23ab95f3 libcamera: process: fix compilation on Chromium OS
Commit 3d20beca66 ("libcamera: Add Process and ProcessManager
classes") causes the build to fail in the Chromium OS build environment,
because the return values of some function calls marked with the
__warn_unused_result__ attribute are ignored. Fix this.

Fixes: 3d20beca66 ("libcamera: Add Process and ProcessManager classes")
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 17:37:44 +09:00
Paul Elder
2d5b3a236e libcamera: ipa: meson: build dummy IPA that needs isolation
Add the dummy IPA that needs isolation to meson. At the same time, clean
up the IPA meson to facilitate adding more IPAs.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 16:32:29 +09:00
Paul Elder
403f68d847 libcamera: ipa: add dummy IPA that needs to be isolated
Add a dummy IPA that needs to be isolated.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 16:32:29 +09:00
Paul Elder
47a81cb9f6 libcamera: ipa_manager: use proxy
Make IPAManager isolate an IPA in a Proxy if the IPA's license is not
open source, before returning the IPA to the caller. For now, only use
the default Linux IPA proxy, and only LGPL 2.1+ is considered open
source.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 16:32:29 +09:00
Paul Elder
131a88795e libcamera: proxy: add default linux IPA proxy
Add a skeletal default linux IPA proxy. It currently lacks the IPA proxy
protocol itself.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 16:32:29 +09:00
Paul Elder
c2a8217df5 libcamera: add IPA proxy
Add an IPAProxy class whose implementations will act as a proxy between a
pipeline handler and an isolated IPA interface. Also add an IPAProxyFactory
that will construct the IPAProxy implementations as necessary.

Update Doxygen to ignore the directory where IPAProxy implementations will
reside.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 16:32:29 +09:00
Paul Elder
3d20beca66 libcamera: Add Process and ProcessManager classes
Add a Process class to abstract a process, and a ProcessManager singleton
to monitor and manage the processes.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 16:32:29 +09:00
Paul Elder
099815b853 libcamera: ipa_module: add isOpenSource
Add a method to IPAModule to check if the module is open source.
This uses the license field of the member IPAModuleInfo.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 15:52:37 +09:00
Paul Elder
dfc9a8db09 libcamera: ipa_module_info: add license field
Add a field to IPAModuleInfo to contain the license of the module.

This license field will be used to determine whether the IPA module
should be run in an isolated process or not. If the license is open
source, then the IPA module will be allowed to run without process
isolation, if the user enables it. If the license is not open source,
then the IPA module will be run with process isolation.

Update the dummy IPA and IPA test to conform to the new struct layout.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 15:52:30 +09:00
Paul Elder
60f5d472d9 libcamera: logging: add logging API for applications
Currently the log file and the log level can only be set via environment
variables, but applications may also want to set the log file and the
log level at run time. Provide an API for this.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-12 13:46:48 +09:00
Laurent Pinchart
56c2e65300 libcamera: signal: Fix Object handling in multiple inheritance cases
The SlotBase implementation stores the receiver object pointer as a void
pointer internally. The pointer is then cast back to an Object pointer
when the receiver object class derives from Object. When the receiver is
an object that inherits from both the Object class and other classes,
the Object data members may not be stored at the beginning of the object
memory. The cast back to an Object pointer is thus incorrect.

Fix this by casting the receiver object pointer to an Object pointer
where the type of the receiver object is known, and pass it along with
the receiver void pointer to the SlotBase class. The SlotBase class
stores both pointers internally, and doesn't need the isObject_ field
anymore as the same information is obtained from checking if the Object
pointer is null.

To avoid confusing the two pointers, use the same naming scheme through
the whole implementation: "obj" points to a receiver object as an
unknown type, and "object" to the receiver object cast to an Object. The
latter is null when the receiver object doesn't inherit from the Object
class.

To further clarify the code, remove direct access to the SlotBase "obj"
and "object" fields as much as possible. They are replaced by two new
methods :

- SlotBase::disconnect() to disconnect a signal from the slot's receiver
  object
- SlotBase::match() to test if an object pointer matches the slot

The match() method is a template method with a specialisation for the
Object type, to compare either the obj or the object pointer depending
on the type of the parameter. This is required as the Object destructor
calls the SignalBase::disconnect() method for signal connected to the
object, and passes a pointer to Object to that method, while the actual
object may have a different address due to the issue explained above.
The pointer must thus be compared with the stored Object pointer in that
case, not to the pointer to the receiver object.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-11 16:38:24 +03:00
Laurent Pinchart
cc3ae13d9e libcamera: signal: Support cross-thread signals
Allow signals to cross thread boundaries by posting them to the
recipient through messages instead of calling the slot directly when the
recipient lives in a different thread.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-11 11:57:37 +03:00
Laurent Pinchart
01b930964a libcamera: thread: Add a messaging passing API
Create a new Message class to model a message that can be passed to an
object living in another thread. Only an invalid message type is
currently defined, more messages will be added in the future.

The Thread class is extended with a messages queue, and the Object class
with thread affinity.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-11 10:20:15 +03:00
Laurent Pinchart
525b19c410 libcamera: Add thread support
The new Thread class wraps std::thread in order to integrate it with the
Object, Signal and EventDispatcher classes. By default new threads run
an internal event loop, and their run() method can be overloaded to
provide a custom thread loop.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-11 09:47:16 +03:00
Paul Elder
10ec09025d libcamera: skip auto version generation when building for Chromium OS
Commit b817bcec6b ("libcamera: Auto generate version information")
causes the build to fail in the Chromium OS build environment, because
git update-index tries to take a lock (ie. write) in the git repo that
is outside of the build directory.

The solution is to simply skip git update-index if we are building in
the Chromium OS build environment, and this decision is made if the
build directory is not a subdirectory of the source directory.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-11 12:22:40 +09:00
Laurent Pinchart
c4281ba3bb libcamera: Rework automatic version generation to avoid rebuilds
Commit b817bcec6b ("libcamera: Auto generate version information")
generates version information in order to automatically include it
various locations (Sphinx and Doxygen documentation, libcamera::version
variable available at runtime, and version.h available at compile time).
Unfortunately this causes lots of unnecessary rebuilds when modifying
the git tree state, which hinders development.

The problem is caused by the generated version.h being listed as a
dependency for the whole libcamera. This is required as meson (to the
best of my knowledge) doesn't provide a way to explicitly specify the
dependency of a single object file (camera_manager.o in this case, as
camera_manager.cpp is the only consumer of the generated version string)
on the custom target used to generate version.h. The dependency can't be
automatically detected at build time, like dependencies on normal
headers that are generated by parsing the source, because the version.h
header may not exist yet. The build could then fail in a racy way.

This change attempts at solving the issue by generating a version.cpp
instead of a version.h to set the git-based version. This minimises the
number of files that need to be rebuild when then git tree state
changes, while retaining the main purpose of the original automatic
version generation, the ability to access the git-based version string
at runtime. We however lose the ability to access git-based version
information at build time in an application building against libcamera,
but there is no expected use case for this.

The version string is moved from the libcamera namespace to the
CameraManager class in order to avoid including version.h inside
libcamera (in version.cpp and in camera_manager.cpp), which would create
dependencies causing more rebuild steps, as described above.

On the other hand, major, minor and patch level version numbers are
useful at build time. This commit changes the generation of version.h in
order to add three macros named LIBCAMERA_VERSION_MAJOR,
LIBCAMERA_VERSION_MINOR and LIBCAMERA_VERSION_PATCH for this purpose.
version.h is not included by any other libcamera header or source file,
and thus doesn't force a rebuild of the library.

The Sphinx and Doxygen documentation keep their git-based version
information, which is set during the configuration of the build and then
doesn't track git commits. We may want to investigate how to improve
this, but given that git-based version for the documentation has very
few use cases outside of tagging nightly builds, this isn't considered
an issue at the moment.

The documentation install directory now uses the base version string, in
order to avoid increasing the number of documentation directories
needlessly. This shouldn't cause any issue as the API should not change
without a change to the version number.

The version number generation and handling code now also standardises
the version variables to not start with a 'v' prefix in meson, in order
to simplify their handling. The prefix is added when generating the
relevant files.

Note that we go back to specifying the fallback version in the main
meson.build, in the call to the project() function. For the time being I
believe this should be a good compromise to avoid unnecessary
recompilation, and moving the fallback version to a different file for
tarball releases can be built on top of this.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-09 12:34:10 +03:00
Kieran Bingham
843e4466cd qcam: Update window title with FPS
Provide an average FPS in the QCam title bar to show the current rate of
frame processing.

The QCam compilation is updated to process the Qt MoC headers to support
signals and slots accordingly.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-04 22:11:27 +01:00
Kieran Bingham
2976dd6a7e qcam: Add the version string to the title
Provide the version string reported by the libcamera library on the qcam
test utility.

This helps confirm the exact version of the library that is being used
while testing.

The version string is stored in the MainWindow so that it can be reused
without reconstructing.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-04 22:11:27 +01:00
Kieran Bingham
b3ad7b8654 qcam: Move static timestamp to MainWindow
The 'last' buffer timestamp is stored as a static. Rename the variable
to a more descritive 'lastBufferTime' and move it to the class instance.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-04 22:11:27 +01:00
Kieran Bingham
b817bcec6b libcamera: Auto generate version information
Generate a version string, and provide a global string object which
allows applications to interrogate the current libcamera version
information.

The version header is automatically updated by meson on each build.
The string roughly follows the semver [0] conventions of
major.minor.patch-label as a value.

[0] https://semver.org/

A script (utils/gen-version.sh) is provided which is modelled upon the
processing from autoconf's git-version-gen. The gen-version.sh script
will look for tags in the form vX.Y as starting points for the version
string. While the repository does not have any matching tags, v0.0 will
be assumed, resulting in versions with both major and minor being set to
'0', and the patch count resulting from the number of patches in the
history to that point.

Finally, a uniquely identifying shortened hash is provided from git:

	v0.0.509+0ec0edf7

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-04 22:11:27 +01:00
Jacopo Mondi
79e03cdf40 libcamera: v4l2_videodevice: Re-group operations
Group together operations to enumerate formats and operations to handle
memory handling, alternating public and private operations but
respecting the ordering within each group. Cosmetic change only.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-04 11:17:29 +02:00
Paul Elder
851bf31df8 libcamera: ipa_module: elfLoadSymbol find symbol regardless of size
Make elfLoadSymbol more generic by making the symbol size an output
rather than an input. Also move the memcpy out of elfLoadSymbol.

If the size of struct IPAModuleInfo changes between versions, we still
want to be able to load it and perhaps do conversions for backwards
compatibility. In this case the size should not be a restriction when
searching for the symbol.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-04 11:51:29 +09:00
Paul Elder
d68a29771f libcamera: ipa_module: add path to module loading error message
Add an error message to tell, if an IPA module failed to load, the
path to the IPA module shared object that was attempted to be loaded.

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>
2019-07-04 11:51:01 +09:00
Paul Elder
83e3300a2d libcamera: ipa_module: add path getter
Add a method to IPAModule to get the path of the IPA module shared
object that the IPAModule was constructed from.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-02 23:18:03 +09:00
Laurent Pinchart
9ea9dc5830 libcamera: pipeline: vimc: Add controls support
Implement control support in the VIMC pipeline handler by dynamically
querying the V4L2 device for the supported V4L2 controls and populating
the list of camera controls accordingly.

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>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-02 16:59:43 +03:00
Kieran Bingham
e441f2c7f4 libcamera: pipeline: uvcvideo: Add controls support
Implement control support in the UVC pipeline handler by dynamically
querying the V4L2 device for the supported V4L2 controls and populating
the list of camera controls accordingly.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
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>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-02 16:59:38 +03:00
Laurent Pinchart
57d9d25a0e libcamera: controls: Add a set of initial controls
Add an initial set of controls to demonstrate how controls are defined.

Proper documentation for each control is missing.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-02 16:59:36 +03:00
Kieran Bingham
b69ea51c7c libcamera: request: Add a ControlList
Provide a ControlList on request objects to facilitate setting controls.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-02 16:59:32 +03:00
Laurent Pinchart
0adc13ff76 libcamera: controls: Extend ControlList to access controls by ID
The ControlList class implements a map from control specifier to control
ID. To avoid constant lookups of ControlInfo when using the class in the
libcamera core or in pipeline handlers, the map uses ControlInfo
pointers instead of ControlId values. This is however not very
convenient for applications or pipeline handlers, as they would be
forced to first look up the ControlInfo pointers for the controls they
want to access. Facilitate ease of use of ControlLists by implementing
an internal lookup of the ControlInfo from the controls provided by the
Camera.

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: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-02 16:59:29 +03:00
Kieran Bingham
b9bf9514eb libcamera: camera: Provide a list of ControlInfo
Extend the Camera class to expose the controls it supports. Each
pipeline should generate a list of controls supported by each camera it
creates. These are represented by a ControlInfoMap, and an associated
ControlList of default values.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
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: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-02 16:59:28 +03:00
Kieran Bingham
20d5640ca4 libcamera: controls: Introduce control-related data types
Add a set of data types to support controls:

- ControlValue stores a control type and value in a generic way
- ControlId enumerates all the control identifiers
- ControlIdentifier declares the types of a control and map their names
- ControlInfo stores runtime information for controls
- ControlList contains a set of control info and value pairs

The control definitions map is generated from the controls documentation
to ensure that the two will always be synchronised.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
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>
2019-07-02 16:59:20 +03:00
Laurent Pinchart
a110cc94ab libcamera: v4l2_device: Add method to retrieve all supported controls
Add a new controls() method to the V4L2Device class to retrieve the map
of all supported controls. This is needed in order to dynamically query
the supported controls, for instance for drivers that support different
sets of controls depending on the device model.

To make the API easier to use, create a type alias for the control ID to
ControlInfo and use it.

Remove the getControlInfo() method that is not used externally, as it
can now be replaced by accessing the full list of controls.

Update the CameraSensor API accordingly.

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: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-02 16:59:19 +03:00
Laurent Pinchart
bd0245a0dc libcamera: v4l2_controls: Add min and max to V4L2ControlInfo
Add min() and max() methods to V4L2ControlInfo to report the control's
minimum and maximum value respectively.

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: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-02 16:59:17 +03:00
Laurent Pinchart
f137451817 libcamera: ipc: unix: Make socket operation asynchronous
Blocking socket operation when receiving messages may lead to long
delays, and possibly a complete deadlock, if the remote side delays
sending of the payload after the header, or doesn't send the payload at
all. To avoid this, make the socket non-blocking and implement a simple
state machine to receive the header synchronously with the socket read
notification. The payload read is still synchronous with the receive()
method to avoid data copies.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-02 02:37:18 +03:00
Niklas Söderlund
13dd7a01ec libcamera: ipc: unix: Add a IPC mechanism based on Unix sockets
To be able to isolate an IPA component in a separate process an IPC
mechanism is needed to communicate with it. Add an IPC mechanism based
on Unix sockets which allows users to pass both data and file descriptors
to and from the IPA process.

The implementation allows users to send both data and file descriptors
in the same message. This allows users to more easily implement
serialization and deserialization of objects as all elements belonging
to an object can be sent in one message.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-02 02:25:49 +03:00
Niklas Söderlund
08b2e03a8a libcamera: timer: Stop timer when it is deleted
If a timer is running while it's deleted it is still register with the
event dispatcher. This causes a segmentation fault when the timer
time-out and its signal is emitted. Fix this my stopping the timer when
it's deleted.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-01 23:48:03 +02:00
Niklas Söderlund
0116a940ba libcamera: v4l2_device: Fix variable-sized object initialization
Compiling with clang renders errors as a variable-sized arrays are not
allowed to be initialized. Solve this by using memset() for v4l2Ctrls
which is the only one of the two arrays that needs to be zeroed.

    ../../src/libcamera/v4l2_device.cpp:155:37: error: variable-sized object may not be initialized
        const V4L2ControlInfo *controlInfo[count] = {};
                                           ^~~~~
    ../../src/libcamera/v4l2_device.cpp:156:36: error: variable-sized object may not be initialized
	    struct v4l2_ext_control v4l2Ctrls[count] = {};
					      ^~~~~
    ../../src/libcamera/v4l2_device.cpp:227:37: error: variable-sized object may not be initialized
	    const V4L2ControlInfo *controlInfo[count] = {};
					       ^~~~~
    ../../src/libcamera/v4l2_device.cpp:228:36: error: variable-sized object may not be initialized
	    struct v4l2_ext_control v4l2Ctrls[count] = {};
					      ^~~~~
Fixes: eb068f4e67 ("libcamera: v4l2_device: Implement get and set controls")
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>
2019-06-30 13:49:52 +02:00
Jacopo Mondi
6948ec44c7 libcamera: v4l2_device: Fix control enumeration bug
When enumerating the available V4L2 controls at video device open
time set the V4L2_CTRL_FLAG_NEXT_CTRL flag if an unsupported control
type is encountered to prevent infinite loops.

While at it, downgrade the message reporting the unsupported control
type to Debug, as it is not an error worth being reported unconditionally.

Fixes: 030ce6491e ("libcamera: v4l2_device: List valid controls at open")
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-06-27 10:16:10 +02:00
Kieran Bingham
caf25dc5cf libcamera: event_dispatcher_poll: Remove struct keyword from for-range
When using -std=c++11, GCC versions 6.2 and 6.3 take objection to
declaring a struct type when using a range based iterator:

    event_dispatcher_poll.cpp:231:13: error: types may not be defined
	in a for-range-declaration [-Werror]

		for (const struct pollfd &pfd : pollfds) {
		           ^~~~~~

	cc1plus: all warnings being treated as errors

Removing the keyword 'struct' ensures that the compiler does not try to
declare the type, and instead uses the type as already defined by the
relevant poll.h header.

This issue does not affect later compiler versions.

Reported-by: [autobuild.buildroot.net] Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  http://autobuild.buildroot.net/results/f6dd4c60c04892c8b1669e6000fce7edb2b6349e/

Fixes: 8356f8a6ab ("libcamera: Add a poll-based event dispatcher")
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-06-25 21:35:23 +01:00
Helen Koike
059ed93beb cam: capture: Stop stream when queueRequest() fails
queueRequest() is called after starting the stream.
If it fails, the stream should be stopped, otherwise it can get a
"Device or resource busy" error, due to VIDIOC_REQBUFS ioctls being
called after VIDIOC_STREAMON without VIDIOC_STREAMOFF in-between.

Signed-off-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-06-25 20:40:41 +01:00
Jacopo Mondi
cb21bb3311 libcamera: ipu3: Set pipe_mode based on stream configuration
Set the ImgU pipe_mode control based on the active stream configuration.
Use 'Video' pipe mode unless the viewfinder stream is not active.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-06-25 14:03:49 +02:00
Jacopo Mondi
3ef81b7f7f libcamera: camera_sensor: Add V4L2 control operations
Add operations to get and set control and to retrieve the informations
on a V4L2 control. For simple camera sensors, the operations are
directly called on the underlying V4L2 subdevice.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-06-25 14:01:47 +02:00