From patchwork Tue Jan 22 18:12:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 326 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A277460B23 for ; Tue, 22 Jan 2019 19:12:23 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 38E3B10000B; Tue, 22 Jan 2019 18:12:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Jan 2019 19:12:24 +0100 Message-Id: <20190122181225.12922-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190122181225.12922-1-jacopo@jmondi.org> References: <20190122181225.12922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/2] libcamera: camera: 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: Tue, 22 Jan 2019 18:12:23 -0000 Add abstract base class CameraData for pipeline handlers to store pipeline specific data in Camera class instances. Signed-off-by: Jacopo Mondi --- include/libcamera/camera.h | 13 ++++++++++ src/libcamera/camera.cpp | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 2ea1a68..50041f1 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -12,6 +12,15 @@ namespace libcamera { +class CameraData +{ +public: + virtual ~CameraData() { } +protected: + CameraData() { } + CameraData(CameraData &) = delete; +}; + class Camera final { public: @@ -22,11 +31,15 @@ public: const std::string &name() const; + CameraData *cameraData() const { return data_.get(); } + void setCameraData(CameraData *data); + private: explicit Camera(const std::string &name); ~Camera(); std::string name_; + std::unique_ptr data_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index acf912b..1e2c858 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -33,6 +33,26 @@ namespace libcamera { +/** + * \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 Camera::setCameraData() method, and access them at a later time + * with Camera::cameraData(). + * + * Once associated with a camera, lifetime of derived classes instances will + * be tied to the one of the Camera instance itself. + * + * \sa Camera::setCameraData() + * \sa Camera::cameraData() + */ + /** * \class Camera * \brief Camera device @@ -83,6 +103,36 @@ const std::string &Camera::name() const return name_; } +/** + * \fn CameraData *Camera::cameraData() + * \brief Retrieve the pipeline specific data + * + * Borrow a reference to the platform specific data, associated to a camera + * by pipeline handlers using the setCameraData() method. + */ + +/** + * \brief Set pipeline specific data in the camera + * + * Pipeline handlers might need to associate platform-specific informations to + * camera instances, this method allows them to do so while also transferring + * ownership of the \a cameraData to the Camera instance. + * + * Pipeline specific data are stored as unique_ptr<> to guarantee its + * destruction at Camera deletion time. + * + * Pipeline specific data can be accessed again by pipeline handlers by + * borrowing a (mutable) reference using the cameraData() method. + * + * \sa Camera::cameraData() + * \sa CameraData + */ +void Camera::setCameraData(CameraData *data) +{ + data_ = std::unique_ptr(data); + +} + Camera::Camera(const std::string &name) : name_(name) { From patchwork Tue Jan 22 18:12:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 327 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4539B60C65 for ; Tue, 22 Jan 2019 19:12:24 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id CE9F8100008; Tue, 22 Jan 2019 18:12:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Jan 2019 19:12:25 +0100 Message-Id: <20190122181225.12922-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190122181225.12922-1-jacopo@jmondi.org> References: <20190122181225.12922-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 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: Tue, 22 Jan 2019 18:12:24 -0000 Create V4L2 devices for the CIO2 capture video nodes. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 8cbc10a..58053ea 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -15,11 +15,25 @@ #include "log.h" #include "media_device.h" #include "pipeline_handler.h" +#include "v4l2_device.h" namespace libcamera { LOG_DEFINE_CATEGORY(IPU3) +class IPU3CameraData : public CameraData +{ +public: + IPU3CameraData() : dev_(nullptr) { } + ~IPU3CameraData() { delete dev_; } + + void setV4L2Device(V4L2Device *dev) { dev_ = dev; } + V4L2Device *device() const { return dev_; } + +private: + V4L2Device *dev_; +}; + class PipelineHandlerIPU3 : public PipelineHandler { public: @@ -32,6 +46,7 @@ private: MediaDevice *cio2_; MediaDevice *imgu_; + V4L2Device *createVideoDevice(unsigned int id); void registerCameras(CameraManager *manager); }; @@ -122,6 +137,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 +205,15 @@ void PipelineHandlerIPU3::registerCameras(CameraManager *manager) std::string cameraName = sensor->name() + " " + std::to_string(id); std::shared_ptr camera = Camera::create(cameraName); + + /* Store pipeline private data in the Camera object. */ + V4L2Device *videoDev = createVideoDevice(id); + if (videoDev) { + IPU3CameraData *ipu3Data = new IPU3CameraData(); + ipu3Data->setV4L2Device(videoDev); + camera->setCameraData(ipu3Data); + } + manager->addCamera(std::move(camera)); LOG(IPU3, Info)