Commit graph

4465 commits

Author SHA1 Message Date
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
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
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
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
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
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
Laurent Pinchart
ce24c052de libcamera: log: Add an ASSERT macro
The ASSERT() macro is similar to the assert() macro defined by the C
standard, but uses the libcamera logging infrastructure.

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-01-08 16:23:16 +02:00
Laurent Pinchart
99a3e7bcfb libcamera: log: Add a LogFatal log level
The LogFatal log level is similar to the LogError level, but
additionally abort program execution. This is useful to implement
assertion handlers.

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-01-08 16:23:16 +02:00
Kieran Bingham
eda3cfa1e3 libcamera: media_object: Rename major/minor functions
The system libraries define macro's for major/minor through
<sys/types.h> on some versions of GCC/GLibc.

To prevent namespace collisions with these macros, rename our major and
minor device node accessors.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-08 13:14:29 +00:00
Laurent Pinchart
5af15d1931 libcamera: pipeline_handler: Improve documentation
Miscellaneous documentation improvements for the PipelineHandler and
related classes.

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-04 00:23:33 +02:00
Laurent Pinchart
2d73fd9eca libcamera: pipeline_handler: Remove unneeded forward declaration
There's no need to forward-declare the PipelineManagerFactory class.
Remove it.

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-04 00:23:32 +02:00
Laurent Pinchart
1e04362d6e libcamera: device_enumerator: Improve documentation
Miscellaneous documentation improvements for the DeviceEnumerator and
related classes.

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-04 00:23:30 +02:00
Laurent Pinchart
a87cb586e2 libcamera: device_enumerator: Constify argument to search function
The DeviceEnumerator::search() function doesn't need to modify its
DeviceMatch argument, make it const.

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-04 00:23:29 +02:00
Laurent Pinchart
079c5fe63d libcamera: device_enumerator: Fix wording of log message
The log message still refers to the DeviceInfo class that has been
removed. Replace it with a reference to MediaDevice.

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-04 00:23:27 +02:00
Laurent Pinchart
b63209a793 libcamera: device_enumerator: Downgrade skipped device errors to warnings
When a device is skipped by the udev-based enumerator a message is
logged. Downgrade its severity to warning as the error isn't fatal.

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-04 00:23:26 +02:00
Laurent Pinchart
9f5d6ee69f libcamera: device_enumerator: Fix indentation
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-04 00:23:24 +02:00
Jacopo Mondi
171f4c0a0d libcamera: Use 'struct' for structure types
Add back the 'struct' keyword for structure types.
C++ allows omitting the 'struct' keywork. Add it back to make clear
we're dealing with structures and not class types.

While at there re-sort fields of media_v2_* type in populate() function
to reflect the declaration order in the kernel headers.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-03 09:16:31 +01:00
Jacopo Mondi
4e5a93da83 libcamera: media_device: Minor cleanup in findInterface()
Do not compare an usigned int with -1 to avoid going through cast.
Also align function parameters and long assignement lines while at there.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-03 09:10:50 +01:00
Laurent Pinchart
c59272f417 libcamera: media_device: Zero media graph arrays when querying topology
This silences valgrind that otherwise warns about usage of uninitialized
values. While not strictly required as the kernel should fill the whole
arrays in MEDIA_IOC_G_TOPOLOGY, the extra cost, in a non-critical path,
is negligible compared to the ability to run without valgrind warnings.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02 13:29:45 +02:00
Jacopo Mondi
1b80471805 libcamera: media_device: Make getEntityByName() const
The function does not modify the instance state. Mark it as const.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-02 12:21:45 +01:00
Jacopo Mondi
ea3fa2680c libcamera: media_device: Tiny valid() documentation improvement
Mention in the valid() method documentation, that a media graph has to
be populated to be valid.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-01-02 12:21:15 +01:00
Jacopo Mondi
d83269aae0 libcamera: device_enumerator: Use MediaDevice
Replace usage of the DeviceInfo class with MediaDevice in the
DeviceEnumerator and remove the DeviceInfo class.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02 12:59:04 +02:00
Jacopo Mondi
d4af90d729 libcamera: media_device: Create entities with major and minor numbers
Extend the MediaEntity object with device node major and minor numbers,
and retrieve them from the media graph using interfaces. They will be
used by the DeviceEnumerator to retrieve the devnode path.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02 12:53:55 +02:00
Jacopo Mondi
14291e50b7 libcamera: media_device: Add DeviceInfo features
Add the features of the DeviceInfo class needed to replace it with
MediaDevice.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02 12:35:18 +02:00
Laurent Pinchart
7e9e508093 libcamera: Remove libcamera class
The class was just a placeholder, now that we have other objects
defined, remove it along with the associated test.

The libcamera/libcamera.h header is kept as a shortcut to include the
whole libcamera public API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-02 03:28:19 +02:00
Laurent Pinchart
a591cc8655 libcamera: mediadevice: Improve documentation
Improve the documentation of the media device operation, including how
it handles the lifetime of media objects.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-02 02:38:10 +02:00
Laurent Pinchart
dc647a6707 libcamera: mediadevice: Reorder functions in declaration order
In order to simplify navigation in the .cpp file, order functions in the
declaration order in the .h file.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-02 02:36:29 +02:00
Laurent Pinchart
492019745d libcamera: mediadevice: Make getEntityByName() public
The function is useful as a public API, make it public.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-02 02:35:36 +02:00
Laurent Pinchart
67dce611e5 libcamera: mediadevice: Fix graph parsing error handling
Most errors recorded during graph parsing are logged but not propagated
to the caller. Fix this and delete objects that are created but not
successfully added to the graph to avoid memory leaks. As the error code
returned from the addObject() and populate*() functions doesn't matter
much, turn them into bool functions.

Additionally, add a way to query whether the media graph was valid, and
clear objects before populating the graph to avoid leaking them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-01-02 02:35:25 +02:00
Jacopo Mondi
363824662f libcamera: Add MediaDevice class
The MediaDevice object implements handling and configuration of the media
graph associated with a media device.

The class allows enumeration of all pads, links and entities registered in
the media graph.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2018-12-31 19:00:57 +01:00
Jacopo Mondi
f0e16f0389 libcamera: Add MediaObject class hierarchy
Add a class hierarcy to represent all media objects a media graph represents.
Add a base MediaObject class, which retains the global unique object id,
and define the derived MediaEntity, MediaLink and MediaPad classes.

This hierarchy will be used by the MediaDevice objects which represents and
handles the media graph.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2018-12-31 18:56:41 +01:00
Niklas Söderlund
167f751701 libcamera: pipeline: vimc: add pipeline handler for vimc
Provide a pipeline handler for the virtual vimc driver.

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>
2018-12-31 00:58:31 +01:00
Niklas Söderlund
1c4f156332 libcamera: camera_manager: add CameraManager class
Provide a CameraManager class which will handle listing, instancing,
destruction and lifetime management of cameras.

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>
2018-12-31 00:58:30 +01:00
Niklas Söderlund
7f8ef1bb99 libcamera: pipeline_handler: add PipelineHandler class
Provide a PipelineHandler which represents a handler for one or more
media devices and provides one or more cameras.

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>
2018-12-31 00:58:29 +01:00
Niklas Söderlund
01107c2490 libcamera: device_enumerator: add documentation
Document the intended use-case of the different elements of the device
enumerator.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2018-12-31 00:58:27 +01:00
Niklas Söderlund
06e2ac2e2f libcamera: device_enumerator: add factory for DeviceEnumerators
Provide a factory for DeviceEnumerator objects. Depending on which
libraries are available there will be different ways to enumerate
information in the system. This factory hides this from the rest of the
library.

Currently udev enumeration is the only supported implementation, a sysfs
implementation is another method that surely will be added in the
future.

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>
2018-12-31 00:58:23 +01:00