Commit graph

1033 commits

Author SHA1 Message Date
Niklas Söderlund
65ea2422d2 libcamera: camera: extend camera object to support configuration of streams
Extend the camera to support reading and configuring formats for
groups of streams. The implementation in the Camera are minimalistic as
the heavy lifting are done by the pipeline handler implementations.

The most important functionality the camera provides in this context is
validation of data structures passed to it from the application and
access control to the pipeline handler.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 08:12:18 +01:00
Niklas Söderlund
75476f86d2 libcamera: camera: extend camera object to support streams
A camera consists of one or more video streams originating from the same
video source. The different streams could for example have access to
different hardware blocks in the video pipeline and therefore be able to
process the video source in different ways.

All static information describing each stream need to be recorded at
camera creation. After a camera is created an application can retrieve
the static information about its streams at any time.

Update all pipeline handlers to register one stream per camera, this
will be extended in the future for some of the pipelines.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 08:11:33 +01:00
Laurent Pinchart
ff96eb2ebb libcamera: camera: Add acquire() and release()
Exclusive access must be obtained before performing operations that
change the device state. Define an internal flag to track ownership and
provide a means of protecting functions that change device
configuration.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-02-01 08:11:33 +01:00
Niklas Söderlund
51d442d5a1 libcamera: stream: add initial StreamConfiguration structure
Add an initial StreamConfiguration implementation to hold configuration
data for a single stream of a Camera. In its current form not many
configuration parameters are supported but it's expected the number of
options will grow over time.

At this stage the pixel format is represented as an unsigned int to
allow for easy mapping to the V4L2 API. This might be subject to change
in the future as we finalize how libcamera shall represent pixel
formats.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 08:11:33 +01:00
Niklas Söderlund
50e184d3f1 libcamera: stream: add initial Stream class
Add an initial Stream implementation. The idea is that once capability
support is added to the library each stream will describe its
capabilities using this class. An application will then select one or
more streams based on these capabilities and use them to configure the
camera and capture.

At this stage the Stream class is empty as capabilities are yet to be
added. The class is still useful as it will be used to communicate how
many streams a Camera object provides.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-02-01 08:11:33 +01:00
Laurent Pinchart
92d9df6924 libcamera: camera: Fix operator= definition
The class assignment operator is usually defined as returning a
reference to the object, to allow a = b = c statements. While the return
type makes no difference when deleting the operator in a class
definition, it's still a good practice to use the correct return type.
Fix it in the Camera and CameraManager classes.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-31 11:03:21 +02:00
Laurent Pinchart
eae59ca2cd libcamera: signal: Don't use reinterpret_cast<>() to perform downcasts
Use static_cast<>() instead of reinterpret_cast<>() to perform
downcasts, as reinterpret_cast<>() isn't meant (and guaranteed to be
safe) for that purpose.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-27 17:50:29 +02:00
Laurent Pinchart
8897260976 libcamera: camera_manager: Add method to unregister a camera
The new removeCamera() method is meant to be used by pipeline handlers
to unregister a camera in case of device disconnection.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-01-24 22:24:15 +02:00
Niklas Söderlund
124aaffde0 libcamera: camera: Add disconnection notification
As camera object have the potential to outlive the hardware they
represent, there is a need to inform the camera that the underlying
device has been disconnected, and in turn to notify applications.

Implement a disconnection notification mechanism that can be used by
pipeline handlers to notify the camera of disconnection. The camera then
block all new API calls and emit the disconnected signal.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-01-24 22:24:15 +02:00
Niklas Söderlund
5b02e03199 libcamera: camera: Associate cameras with their pipeline handler
The PipelineHandler which creates a Camera is responsible for serving
any operation requested by the user. In order forward the public API
calls, the camera needs to store a reference to its pipeline handler.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v1:

- Create pipeline handlers is shared pointers, make them inherit from
  std::enable_shared_from_this<> and stored them in shared pointers.
2019-01-24 22:24:11 +02:00
Laurent Pinchart
4d470eb37f libcamera: event_dispatcher: Add interrupt() function
The new interrupt() function allows interrupting in-progress blocking
processEvents() calls. This is useful to stop running event loops.

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-01-23 18:51:56 +02:00
Laurent Pinchart
21ff749a79 libcamera: camera: Handle camera objects through shared pointers
The Camera class is explicitly reference-counted to manage the lifetime
of camera objects. Replace this open-coded implementation with usage of
the std::shared_ptr<> class.

This API change prevents pipeline handlers from subclassing the Camera
class. This isn't deemed to be an issue. Mark the class final to make
this explicit.

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-21 11:13:53 +02:00
Laurent Pinchart
f3695e9b09 libcamera: camera_manager: Register cameras with the camera manager
Cameras are listed through a double indirection, first iterating over
all available pipeline handlers, and then listing the cameras they each
support. To simplify the API make the pipeline handlers register the
cameras with the camera manager directly, which lets the camera manager
easily expose the list of all available cameras.

The PipelineHandler API gets simplified as the handlers don't need to
expose the list of cameras they have created.

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:49 +02:00
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
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
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
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
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
6b0c2f027a libcamera: camera_manager: Sort includes alphabetically
Alphabetically sorted includes help finding where to insert new include
statements, and avoiding duplicates.

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:23 +02:00
Laurent Pinchart
6ddbf354d5 libcamera: camera_manager: Remove put() method
The method is declared but not implemented. 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:12 +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
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
8c10082a9e libcamera: Add Camera class
Provide a Camera class which represents our main interface to handling
camera devices. This is a rework of Kieran's initial proposal and
Laurent's documentation of the file changed to fit the device
enumerators needs.

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:57:58 +01:00
Jacopo Mondi
c81bc473fd libcamera: include: Import media.h from Linux v4.19
In order to avoid depending on system headers that may be outdated compared
to the kernel version available at runtime, import the Linux kernel headers
related to the APIs that libcamera requires a recent version of. This allows
libcamera to use the latest kernel APIs even when compiled on older systems.
The library must of course test at runtime whether those APIs are available
and fallback to older APIs in order to support older kernels.

Import media.h for the recent media controller APIs. The file is extracted
verbatim from kernel v4.19.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2018-12-19 10:30:28 +01:00
Laurent Pinchart
830031892b build: Clean up file names variables
The build system defines two variables, public_api and sources, that
store the names of the public headers and the source files respectively.
These files will need to be referenced when generating documentation
from source code, so let's make the variable names more descriptive:

- Rename public_api to libcamera_api and use the files() function
- Rename sources to libcamera_sources
- Add a libcamera_headers variable to hold the internal headers

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-12-11 20:28:34 +02:00
Laurent Pinchart
cc7d204b2c libcamera: Use the logger instead of cout
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-12-06 16:43:45 +02:00
Laurent Pinchart
0713202dc0 Add boilerplate headers comments and include guards
The initial main.cpp and libcamera.h files are missing boilerplate
header comments. libcamera.h is further missing include guards. Add
them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-12-06 16:33:36 +02:00
Kieran Bingham
df77f99386 meson: Replace tabs for spaces
Tabs are disliked within the meson build system.
Replace indentation by spaces, in all existing locations.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-11-28 11:08:35 +00:00
Kieran Bingham
66051636c5 include: Install include files
The include directory was defined but not installed.

Add it to the meson build structure to incorporate it as part of the
library install.

To facilitate the same include paths in our internal includes, update
the structure for headers to match the install structure.

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>
2018-11-27 12:10:57 +00:00
Kieran Bingham
708d3c9fc0 build: Provide initial meson infrastructure
Define the starting points for the libcamera build using
meson and ninja build components.

An initial 'dummy' library class is created, and a test binary links
against the shared library calling it's init_lib() function.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-10-24 12:22:19 +01:00