From patchwork Wed Jan 30 11:56:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 452 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E45560B2D for ; Wed, 30 Jan 2019 12:57:05 +0100 (CET) X-Halon-ID: 26407874-2486-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from wyvern.c.hoisthospitality.com (unknown [217.64.245.162]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 26407874-2486-11e9-911a-0050569116f7; Wed, 30 Jan 2019 12:57:03 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 30 Jan 2019 12:56:15 +0100 Message-Id: <20190130115615.17362-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130115615.17362-1-niklas.soderlund@ragnatech.se> References: <20190130115615.17362-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 6/6] libcamera: camera: extend camera object to support configuration of streams X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jan 2019 11:57:05 -0000 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 --- include/libcamera/camera.h | 4 +++ src/libcamera/camera.cpp | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 01498935ae4aab58..b21d116edc0f3a57 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_CAMERA_H__ #define __LIBCAMERA_CAMERA_H__ +#include #include #include @@ -16,6 +17,7 @@ namespace libcamera { class PipelineHandler; class Stream; +class StreamConfiguration; class Camera final { @@ -35,6 +37,8 @@ public: void release(); const std::vector streams() const; + std::map streamConfiguration(std::vector &streams); + int configureStreams(std::map &config); private: Camera(PipelineHandler *pipe, const std::string &name); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 986b74407aed6bd2..a293350f731e18df 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -190,4 +190,65 @@ const std::vector 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 by 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 +Camera::streamConfiguration(std::vector &streams) +{ + if (disconnected_ || !streams.size()) + std::map{}; + + 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 is 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 have not acquired exclusive access to the camera + * \retval -EINVAL The configuration is not valid + */ +int Camera::configureStreams(std::map &config) +{ + if (disconnected_) + return -ENODEV; + + if (!acquired_) + return -EACCES; + + if (!config.size()) + return -EINVAL; + + return pipe_->configureStreams(this, config); +} + } /* namespace libcamera */