diff options
author | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-01-31 10:52:41 +0100 |
---|---|---|
committer | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-02-01 08:12:18 +0100 |
commit | 65ea2422d24a30736e457fdefe31956b4428ae0f (patch) | |
tree | bb94a471d9dbdad7106d97bf56f4715a9354bf74 | |
parent | 0d913813b53564e83980f53204bb517095c866f9 (diff) |
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>
-rw-r--r-- | include/libcamera/camera.h | 6 | ||||
-rw-r--r-- | src/libcamera/camera.cpp | 66 |
2 files changed, 70 insertions, 2 deletions
diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index cee96e9a..4940c344 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_CAMERA_H__ #define __LIBCAMERA_CAMERA_H__ +#include <map> #include <memory> #include <string> @@ -16,6 +17,7 @@ namespace libcamera { class PipelineHandler; class Stream; +class StreamConfiguration; class Camera final { @@ -35,6 +37,9 @@ public: void release(); const std::vector<Stream *> &streams() const; + std::map<Stream *, StreamConfiguration> + streamConfiguration(std::vector<Stream *> &streams); + int configureStreams(std::map<Stream *, StreamConfiguration> &config); private: Camera(PipelineHandler *pipe, const std::string &name); @@ -48,6 +53,7 @@ private: std::vector<Stream *> streams_; bool acquired_; + bool disconnected_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 49f49fb7..b8c6c8b2 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -110,7 +110,8 @@ const std::string &Camera::name() const */ Camera::Camera(PipelineHandler *pipe, const std::string &name) - : pipe_(pipe->shared_from_this()), name_(name), acquired_(false) + : pipe_(pipe->shared_from_this()), name_(name), acquired_(false), + disconnected_(false) { } @@ -133,7 +134,7 @@ void Camera::disconnect() { LOG(Camera, Debug) << "Disconnecting camera " << name_; - /** \todo Block API calls when they will be implemented. */ + disconnected_ = true; disconnected.emit(this); } @@ -186,4 +187,65 @@ const std::vector<Stream *> &Camera::streams() const return streams_; } +/** + * \brief Retrieve a group of stream configurations + * \param[in] streams A map of stream IDs and configurations to setup + * + * Retrieve the camera's configuration for a specified group of streams. The + * caller can specifies which of the camera's streams to retrieve configuration + * from by populating \a streams. + * + * The easiest way to populate the array of streams to fetch configuration from + * is to first retrieve the camera's full array of stream with streams() and + * then potentially trim it down to only contain the streams the caller + * are interested in. + * + * \return A map of successfully retrieved stream IDs and configurations or an + * empty list on error. + */ +std::map<Stream *, StreamConfiguration> +Camera::streamConfiguration(std::vector<Stream *> &streams) +{ + if (disconnected_ || !streams.size()) + std::map<unsigned int, StreamConfiguration> {}; + + return pipe_->streamConfiguration(this, streams); +} + +/** + * \brief Configure the camera's streams prior to capture + * \param[in] config A map of stream IDs and configurations to setup + * + * Prior to starting capture, the camera must be configured to select a + * group of streams to be involved in the capture and their configuration. + * The caller specifies which streams are to be involved and their configuration + * by populating \a config. + * + * The easiest way to populate the array of config is to fetch an initial + * configuration from the camera with streamConfiguration() and then change the + * parameters to fit the caller's need and once all the streams parameters are + * configured hand that over to configureStreams() to actually setup the camera. + * + * Exclusive access to the camera shall be ensured by a call to acquire() prior + * to calling this function, otherwise an -EACCES error will be returned. + * + * \return 0 on success or a negative error code on error. + * \retval -ENODEV The camera is not connected to any hardware + * \retval -EACCES The user has not acquired exclusive access to the camera + * \retval -EINVAL The configuration is not valid + */ +int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config) +{ + if (disconnected_) + return -ENODEV; + + if (!acquired_) + return -EACCES; + + if (!config.size()) + return -EINVAL; + + return pipe_->configureStreams(this, config); +} + } /* namespace libcamera */ |