From patchwork Thu Jan 24 11:30:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 370 Return-Path: Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 53E2C60C80 for ; Thu, 24 Jan 2019 12:30:13 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id DCBBFE0018; Thu, 24 Jan 2019 11:30:12 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Jan 2019 12:30:19 +0100 Message-Id: <20190124113020.7203-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124113020.7203-1-jacopo@jmondi.org> References: <20190124113020.7203-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: pipeline_handler: Add CameraData 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: Thu, 24 Jan 2019 11:30:13 -0000 Add class definition and methods to associate a Camera with specific data in the pipeline_handler base class. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/include/pipeline_handler.h | 24 +++++++- src/libcamera/pipeline_handler.cpp | 73 ++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index b03217d..41699a5 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -11,17 +11,39 @@ #include #include +#include + namespace libcamera { class CameraManager; class DeviceEnumerator; +class CameraData +{ +public: + virtual ~CameraData() {} + +protected: + CameraData() {} + +private: + CameraData(const CameraData &) = delete; + void operator=(const CameraData &) = delete; +}; + class PipelineHandler { public: - virtual ~PipelineHandler() { }; + virtual ~PipelineHandler(); virtual bool match(CameraManager *manager, DeviceEnumerator *enumerator) = 0; + +protected: + CameraData *cameraData(const Camera *camera); + void setCameraData(const Camera *camera, std::unique_ptr data); + +private: + std::map> cameraData_; }; class PipelineHandlerFactory diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index c24feea..fb49fde 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -8,6 +8,8 @@ #include "log.h" #include "pipeline_handler.h" +#include + /** * \file pipeline_handler.h * \brief Create pipelines and cameras from a set of media devices @@ -26,6 +28,20 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Pipeline) +/** + * \class CameraData + * \brief Base class for platform-specific data associated with a camera + * + * The CameraData base abstract class represents platform specific-data + * a pipeline handler might want to associate with a Camera to access them + * at a later time. + * + * Pipeline handlers are expected to extend this base class with platform + * specific implementation, associate instances of the derived classes + * using the setCameraData() method, and access them at a later time + * with cameraData(). + */ + /** * \class PipelineHandler * \brief Create and manage cameras based on a set of media devices @@ -66,6 +82,63 @@ LOG_DEFINE_CATEGORY(Pipeline) * created, or false otherwise */ +/** + * \brief Delete the pipeline handler + * + * Release the cameraData_ map, causing all data there referenced to be + * deleted, as they are stored as unique_ptr + */ +PipelineHandler::~PipelineHandler() +{ + cameraData_.clear(); +}; + +/** + * \brief Retrieve the pipeline-specific data associated with a Camera + * \param camera The camera data is associate with + * + * \return A pointer to the pipeline-specific data set with setCameraData(). + * The returned pointer lifetime is associated with the one of the pipeline + * handler, and caller of this function shall never release it manually. + */ +CameraData *PipelineHandler::cameraData(const Camera *camera) +{ + if (!cameraData_.count(camera)) { + LOG(Pipeline, Error) + << "Cannot get data associated with camera " + << camera->name(); + return nullptr; + } + + return cameraData_[camera].get(); +} + +/** + * \brief Set pipeline-specific data in the camera + * \param camera The camera to associate data to + * \param data The pipeline-specific data + * + * This method allows pipeline handlers to associate pipeline-specific + * information with \a camera. The \a data lifetime gets associated with + * the pipeline handler one, and gets released at deletion time. + * + * If pipeline-specific data has already been associated with the camera by a + * previous call to this method, is it replaced by \a data and the previous data + * are deleted, rendering all references to them invalid. + * + * The data can be retrieved by pipeline handlers using the cameraData() method. + */ +void PipelineHandler::setCameraData(const Camera *camera, + std::unique_ptr data) +{ + if (cameraData_.count(camera)) + LOG(Pipeline, Debug) + << "Replacing data associated with " + << camera->name(); + + cameraData_[camera] = std::move(data); +} + /** * \class PipelineHandlerFactory * \brief Registration of PipelineHandler classes and creation of instances From patchwork Thu Jan 24 11:30:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 371 Return-Path: Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ECD9160C82 for ; Thu, 24 Jan 2019 12:30:13 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 7E855E0007; Thu, 24 Jan 2019 11:30:13 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Jan 2019 12:30:20 +0100 Message-Id: <20190124113020.7203-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124113020.7203-1-jacopo@jmondi.org> References: <20190124113020.7203-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: ipu3: Create CIO2 V4L2 devices 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: Thu, 24 Jan 2019 11:30:14 -0000 Create V4L2 devices for the CIO2 capture video nodes and associate them with the camera they are part of. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 8cbc10a..9f5a40f 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -15,6 +15,8 @@ #include "log.h" #include "media_device.h" #include "pipeline_handler.h" +#include "utils.h" +#include "v4l2_device.h" namespace libcamera { @@ -29,9 +31,19 @@ public: bool match(CameraManager *manager, DeviceEnumerator *enumerator); private: + class IPU3CameraData : public CameraData + { + public: + IPU3CameraData() + : dev_(nullptr) { } + ~IPU3CameraData() { delete dev_; } + V4L2Device *dev_; + }; + MediaDevice *cio2_; MediaDevice *imgu_; + V4L2Device *createVideoDevice(unsigned int id); void registerCameras(CameraManager *manager); }; @@ -122,6 +134,24 @@ error_release_mdev: return false; } +/* Create video devices for the CIO2 unit associated with a camera. */ +V4L2Device *PipelineHandlerIPU3::createVideoDevice(unsigned int id) +{ + std::string cio2Name = "ipu3-cio2 " + std::to_string(id); + MediaEntity *cio2 = cio2_->getEntityByName(cio2Name); + if (!cio2) + return nullptr; + + V4L2Device *dev = new V4L2Device(*cio2); + if (dev->open()) { + delete dev; + return nullptr; + } + dev->close(); + + return dev; +} + /* * Cameras are created associating an image sensor (represented by a * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four @@ -172,6 +202,26 @@ void PipelineHandlerIPU3::registerCameras(CameraManager *manager) std::string cameraName = sensor->name() + " " + std::to_string(id); std::shared_ptr camera = Camera::create(cameraName); + + setCameraData(camera.get(), + std::move(utils::make_unique())); + IPU3CameraData *data = + reinterpret_cast(cameraData(camera.get())); + + /* + * If V4L2 device creation fails, the Camera instance won't be + * registered. The 'camera' shared pointer goes out of scope + * and deletes the Camera it manages. + */ + V4L2Device *videoDev = createVideoDevice(id); + if (!videoDev) { + LOG(IPU3, Error) + << "Failed to register camera[" + << numCameras << "] \"" << cameraName << "\""; + continue; + } + + data->dev_ = videoDev; manager->addCamera(std::move(camera)); LOG(IPU3, Info)