Commit graph

5598 commits

Author SHA1 Message Date
Laurent Pinchart
32bf7ef239 libcamera: camera_manager: Use std::unique_ptr to store event dispatcher
The CameraManager takes ownership of the dispatcher passed to the
setEventDispatcher() function. Enforces this by using std::unique_ptr<>.

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-01-21 11:13:45 +02:00
Laurent Pinchart
0908669834 Documentation: coding_style: Add object ownership rules
Object ownership is a complex topic that can lead to many issues, from
memory leak to crashes. Document the rules that libcamera enforces to
make object ownership tracking explicit.

This is a first version of the rules and is expected to be expanded as
the library is developed.

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-01-21 11:13:40 +02:00
Laurent Pinchart
bd0c818023 libcamera: signal: Enable documentation generation from signal.h file
signal.cpp is missing a \file signal.h Doxygen directive, preventing
documentation from being generated for the Signal class. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-21 10:52:30 +02:00
Laurent Pinchart
6c27bada1d Documentation: coding_style: Add move semantics to C++11 features
Add the move semantics (move constructor and move assignment) to the
allowed C++11 features, as we extensively use them for the unique and
shared pointers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-21 10:52:30 +02:00
Laurent Pinchart
576c9454cf libcamera: utils: Don't use C++17 nested namespaces
Nesting namespace names in a single namespace declaration is a C++17
feature. As libcamera depends on C++11 only, nest two separate namespace
declarations instead.

Reported-by: Shik Chen <shik@google.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-19 00:52:15 +02:00
Kieran Bingham
479264dfca test: v4l2_device: Add test suite and initial test
Provide a base class to construct a v4l2_device object for further tests
and an initial test which validates the FD handle can not be leaked.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-17 21:55:27 +00:00
Kieran Bingham
e74f3eebb4 libcamera: Add V4L2 Device object
Provide a helper V4L2 device object capable of interacting with the
V4L2 Linux Kernel APIs.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-17 21:55:21 +00:00
Kieran Bingham
e399a0745b libcamera: event_dispatcher_poll: Fix trivial spelling
Correct the spelling of 'notifiers'.

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-01-17 21:31:33 +00:00
Kieran Bingham
d67841a990 libcamera: log: Fix coding style warnings
The checkstyle utility highlights some minor warnings against the logger
implementation.

Fix these up.

Fixes: edbd2059d8 ("libcamera: Add initial logger")
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-17 21:31:33 +00:00
Kieran Bingham
5651334119 libcamera: timer: Fix 32 bit wrap
The msec parameter was multiplied as a 32 bit value when converting to
nanosecond resolution. This wraps at 4.2949 seconds, and causes timers
longer than this to fail.

Fix the multiplication to upcast to 64 bit using an unsigned long long
specifier on the multiplier.

While we're here, initialise the two integer class members in the
constructor initialiser list.

Fixes: 1a57bcb8d1 ("libcamera: Add event notification infrastructure")
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-17 21:31:33 +00:00
Kieran Bingham
74fb6ec3dc test: timer: Add a 32 bit wraparound test
Add a test which catches a timer running longer than the nanosecond
resolution of 32 bits.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-17 21:31:33 +00:00
Kieran Bingham
b523982920 test: timer: Initialise all variables
The ManagedTimer does not initialise the integer 'interval_' variable.

This is set before used, and should not break - but for completeness
(and to cover static analysers) initialise the variable in the
initialiser list.

Fixes: 034ea86802 ("test: Add timer test")

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-17 21:31:28 +00:00
Kieran Bingham
2b63efe092 include: linux: Import V4L2 uAPI headers from Linux v4.19
Import the following files from the Linux UAPI to keep our V4L2
interface in sync:

	media-bus-format.h
	v4l2-common.h
	v4l2-controls.h
	v4l2-mediabus.h
	v4l2-subdev.h
	videodev2.h

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-17 16:37:03 +02:00
Laurent Pinchart
557a53267a Documentation: coding_style: Allow C++11 variadic templates
We make use of the C++11 variadic templates feature in the signal&slot
implementation, mark it as allowed in the coding style documentation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-16 18:24:27 +02:00
Laurent Pinchart
62eae99ed2 libcamera: camera_manager: Turn enumerator into a unique_ptr<>
Convey the fact that the CameraManager class owns the DeviceEnumerator
instance it creates by using std::unique_ptr<> to store the pointer.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-16 18:23:43 +02:00
Laurent Pinchart
a2f095947f libcamera: utils: Implement C++14 make_unique<>()
C++14 introduces std::make_unique<>() that makes it easier to initialize
unique_ptr<> instances. As libcamera is limited to C++11, implement our
own version of the function in the libcamera::utils namespace.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-16 18:23:43 +02:00
Laurent Pinchart
f388aa7041 libcamera: device_enumerator: Don't mark the search() function as const
While the DeviceEnumerator::search() function doesn't modify the
instance directly, it returns a non-const pointer to a MediaEntity that
is owned by the DeviceEnumerator instance. This breaks the const
semantics. Don't mark the function as const.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-16 18:23:43 +02:00
Laurent Pinchart
3e6090a17a libcamera: event_dispatcher_poll: Constify argument to processNotifiers
The EventDispatcherPoll::processNotifiers() function doesn't modify the
argument it receives, make it const.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-16 18:23:43 +02:00
Laurent Pinchart
6ee4050182 libcamera: pipeline_handler: Rename handlers() method to factories()
The PipelineHandlerFactory::handlers() static method returns a list of
factories, not a list of handlers. Rename it accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-16 18:23:43 +02:00
Laurent Pinchart
619d312462 Documentation: Exclude pipeline handlers directory
The pipeline handlers don't define APIs, neither public not internal.
There is thus no need to generate Doxygen documentation from thoses
classes. Add them to the EXCLUDE files pattern.

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>
2019-01-16 18:23:43 +02:00
Laurent Pinchart
6c87662ee9 libcamera: camera_manager: Improve class documentation
Move documentation from the \file directive to the CameraManager class,
as it documents the class, not the file. Improve the documentation to
provide a brief overview of how the camera manager operates, and fix a
few typos and inconsistencies.

The documentation mentions hotplug even though it isn't implement yet,
as this is a planned feature. More improvements are needed for the
documentation of the CameraManager member functions, and will be added
as part of the API improvements in the near future.

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>
2019-01-16 18:23:43 +02:00
Laurent Pinchart
34018d23d7 libcamera: pipeline_handler: Don't index factories by name
Pipeline handler factories are register in a map indexed by their name,
and the list of names is used to expose the factories and look them up.
This is unnecessary cumbersome, we can instead store factories in a
vector and expose it directly. The pipeline factory users will still
have access to the factory names through the factory name() function.

The PipelineHandlerFactory::create() method becomes so simple that it
can be inlined in its single caller, removing the unneeded usage of the
DeviceEnumerator in the factory.

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>
2019-01-16 18:23:42 +02:00
Kieran Bingham
a5e86d4396 meson: Utilise default compiler options
Remove our custom declarations for cpp_std=c++11, -Wall, -Wextra and
-Werror, instead prefering to use the built-in default_option parameters
from meson.

Our custom compiler flags (such as -Wno-unused-parameter) are
maintained.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-15 21:14:35 +00:00
Jacopo Mondi
f1caaaf387 libcamera: Debug printouts fixes
Address a few issues I missed during patch review.

Minor cosmetic change.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-15 09:44:01 +01:00
Jacopo Mondi
fd0339da1a libcamera: Add debug printouts
Add a few debug printouts that help follow the library intialization
process: what pipeline handlers are registered, what media devices are
created, and which pipeline manager gets matches with the current
system.

The resulting output is the following, on IPU3 devices:
DBG pipeline_handler.cpp:119 Pipeline handler: "PipeHandlerVimc" registered
DBG pipeline_handler.cpp:119 Pipeline handler: "PipelineHandlerIPU3" registered
DBG device_enumerator.cpp:214 New media device: ipu3-imgu created from: /dev/media0
DBG device_enumerator.cpp:214 New media device: ipu3-cio2 created from: /dev/media1
DBG device_enumerator.cpp:255 Succesfull match for media device: ipu3-cio2
DBG device_enumerator.cpp:255 Succesfull match for media device: ipu3-imgu
DBG pipeline_handler.cpp:150 Pipeline handler: "PipelineHandlerIPU3" matched

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-15 09:29:00 +01:00
Kieran Bingham
bced32d514 libcamera: log: Fix unknown log level representation
Commit 99a3e7bcfb ("libcamera: log: Add a LogFatal log level")
expanded the text representation of the log levels to support the FATAL
string, but left the default unknown match at four characters.

This code should never expect to be executed, but for completeness match
the string lengths by adding an extra character to the result.

Fixes: 99a3e7bcfb ("libcamera: log: Add a LogFatal log level")
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-14 22:24:22 +00:00
Jacopo Mondi
d833c1d39e test: media_device: Add link handling test
Add a test unit that exercise link handling on the VIMC media graph.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-14 17:54:56 +01:00
Jacopo Mondi
d85767a8c8 test: media_device: Make MediaDeviceTest a MediaDevicePrintTest
As a new class for test link handling will be added as a separate test,
it makes no sense to have a generic "MediaDeviceTest" class. Rename it
in "MediaDevicePrintTest", and make it run only printing test.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-14 17:54:56 +01:00
Kieran Bingham
4bf28fa225 test: media_device: Convert to foreach
Prevent duplication of boilerplate code as the suite grows by
establishing the foreach pattern in the media_device test suite.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-14 17:54:56 +01:00
Kieran Bingham
e3c4994812 Documentation: quieten sphinx-build output
The output of the sphinx-build for our documentation is overly verbose.
Reduce this output to warnings and errors with the '-q' quiet option.

Acked-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-14 09:57:34 +00:00
Laurent Pinchart
e42683b40d Documentation: Add placeholder for Doxygen-generated API documentation
Until we have better Sphinx + Doxygen integration, replace the relative
external link to the API documentation with a placeholder directory,
which will be populated with the Doxygen-generated doc when exporting
documentation to the website. This is needed as the Sphinx documentation
is exported to the root of the website, linking to ../api-html is thus
not possible.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-11 17:17:22 +02:00
Laurent Pinchart
159c496b51 Documentation: Update copyright years
Happy new year :-)

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-11 15:26:31 +02:00
Laurent Pinchart
c8e2c5adda Documentation: Link to the API documentation generated by Doxygen
Add a link in the toctree to the API documentation.

sphinx doesn't seem to support relative external links, but we can trick
it into thinking the link is absolute by adding '#://' at the end.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-11 15:26:31 +02:00
Laurent Pinchart
f21090516d Documentation: Make the toctree more web-friendly
The toctree is displayed in the navigation bar at the top of the page.
Add short names to the entries that replicate the names currently used
on libcamera.org.

Remove the link to the index and search pages, as the former is empty,
and the latter can be accessed directory from the navigation bar search
box.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-11 15:26:31 +02:00
Laurent Pinchart
68ea206456 Documentation: Add custom theme
The theme replicates the look and feel of the libcamera.org website.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-11 15:26:25 +02:00
Laurent Pinchart
824ed85553 libcamera: device_enumerator: Fix memory leak in error path
The DeviceEnumerator::create() function allocates a
DeviceEnumeratorUdev and fails to delete it in the error path, causing a
memory leak. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-10 15:28:04 +02:00
Laurent Pinchart
93a037efff libcamera: Document missing parameters and return values
Several functions are missing documentation for some of them parameters
and/or for their return value. Fix this.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-10 15:27:59 +02:00
Laurent Pinchart
afcec99b99 libcamera: Update libcamera.h
libcamera.h hasn't been updated with the recently added public headers
event_notifier.h, signal.h and timer.h. Add them.

The event_dispatcher_poll.h header, which used to be public, is now
private, but hasn't been removed from libcamera.h. Remove it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-10 15:27:49 +02:00
Jacopo Mondi
4e78147df9 libcamera: Add link handling functions
Add a function to the MediaLink class to set the state of a link to
enabled or disabled. The function makes use of an internal MediaDevice
method, which is defined private and only accessible by the MediaLink
setEnabled() function itself.

Also add to MediaDevice a function to reset all links registered in the
media graph.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-09 09:16:47 +01:00
Jacopo Mondi
b65feafe32 libcamera: media_device: Add functions to get a MediaLink
Add three overloaded functions 'link()' to retrieve a link between two
pads. Each overloaded implementation exposes a different method to
identify the source and sink pads.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-08 21:38:42 +01:00
Jacopo Mondi
6275a14215 libcamera: Add pointer to MediaDevice to MediaObject
Add a MediaDevice member field to the MediaObject class hierarcy.
Each media object now has a reference to the media device it belongs to,
and which it has been created by.

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>
2019-01-08 21:38:40 +01:00
Laurent Pinchart
aed8c7823e test: Add event notifier test
The test covers read notification and notifier enable/disable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-08 16:23:16 +02:00
Laurent Pinchart
034ea86802 test: Add timer test
The test covers timer start, timeout, restart after completion, restart
before completion and multiple timers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-08 16:23:16 +02:00
Laurent Pinchart
f151895c3f test: Add signal/slot test
The test covers signal connection, disconnection through all the
provided methods, emission, parameters, and connection of a signal to
multiple slots.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-08 16:23:16 +02:00
Laurent Pinchart
03815afdc8 test: Rename list test to list-cameras
The list test generates a list binary in the test directory, which
conflicts with the C++ std::list header of the same name. The binary
gets included instead of the header file, breaking compilation.

Rename the test to avoid this.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-08 16:23:16 +02:00
Laurent Pinchart
8356f8a6ab libcamera: Add a poll-based event dispatcher
Provide a poll-based event dispatcher implementation as convenience for
applications that don't need a custom event loop. The poll-based
dispatcher is automatically instantiated if the application doesn't
provide its own dispatcher.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-08 16:23:16 +02:00
Laurent Pinchart
1a57bcb8d1 libcamera: Add event notification infrastructure
Add three new classes, EventDispatcher, EventNotifier and Timer, that
define APIs for file descriptor event notification and timers. The
implementation of the EventDispatcher is meant to be provided to
libcamera by the application.

The event dispatcher is integrated twith the camera manager to implement
automatic registration of timers and events.

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-01-08 16:23:16 +02:00
Laurent Pinchart
d0fd42a4fd libcamera: Add signal/slot communication mechanism
Introduce a Signal class that allows connecting event sources (signals)
to event listeners (slots) without adding any boilerplate code usually
associated with the observer or listener design patterns.

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-01-08 16:23:16 +02:00
Laurent Pinchart
8b0de29c41 libcamera: camera_manager: Make the class a singleton
There can only be a single camera manager instance in the application.
Creating it as a singleton helps avoiding mistakes. It also allows the
camera manager to be used as a storage of global data, such as the
future event dispatcher.

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-01-08 16:23:16 +02:00
Laurent Pinchart
f3829b5745 libcamera: log: Pad timestamp fields with zeros
The logger prints the timestamp fields with a fixed width, but pads them
with spaces instead of zeros. Fix this.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-08 16:23:16 +02:00