From patchwork Thu Jan 24 10:16:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 356 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6424360C78 for ; Thu, 24 Jan 2019 11:16:57 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D02B72F6; Thu, 24 Jan 2019 11:16:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1548325017; bh=assAIgFS7yxI5tahqSAH/spUZDdGW1KgSnrmxsr4QNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HfOyU+Ol4vF6mcQ96Lp0dQr+WXo7hzWs1f0if5SuINkbtsoE6mJ1FYZ53fmRJpelH YFgmA6f/3Drr79s+BAPx6crwfYLLWA3Ix4z2KDag9ojCkzNr3tC5TdrqeMtl4p5EuP YhJrmPKNoR0cXswSrAR2gAMCI6XL36mtWL5Yoc9c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Jan 2019 12:16:42 +0200 Message-Id: <20190124101651.9993-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190124101651.9993-1-laurent.pinchart@ideasonboard.com> References: <20190124101651.9993-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/10] libcamera: pipeline_handler: Store the camera manager pointer 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 10:16:57 -0000 Instead of passing the camera manager pointer to the match() function, and later to more PipelineHandler functions, store it in the PipelineHandler::manager_ member variable at construction time and access it from there. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/camera_manager.cpp | 4 +-- src/libcamera/include/pipeline_handler.h | 20 ++++++++----- src/libcamera/pipeline/ipu3/ipu3.cpp | 18 ++++++------ src/libcamera/pipeline/uvcvideo.cpp | 12 ++++---- src/libcamera/pipeline/vimc.cpp | 12 ++++---- src/libcamera/pipeline_handler.cpp | 36 ++++++++++++++++++++---- 6 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 4ea7ed44cc31..14410d4dcda7 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -98,8 +98,8 @@ int CameraManager::start() * all pipelines it can provide. */ while (1) { - PipelineHandler *pipe = factory->create(); - if (!pipe->match(this, enumerator_.get())) { + PipelineHandler *pipe = factory->create(this); + if (!pipe->match(enumerator_.get())) { delete pipe; break; } diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index b03217d5bff8..7bb07d1ec5c7 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -19,9 +19,13 @@ class DeviceEnumerator; class PipelineHandler { public: - virtual ~PipelineHandler() { }; + PipelineHandler(CameraManager *manager); + virtual ~PipelineHandler(); - virtual bool match(CameraManager *manager, DeviceEnumerator *enumerator) = 0; + virtual bool match(DeviceEnumerator *enumerator) = 0; + +protected: + CameraManager *manager_; }; class PipelineHandlerFactory @@ -30,7 +34,7 @@ public: PipelineHandlerFactory(const char *name); virtual ~PipelineHandlerFactory() { }; - virtual PipelineHandler *create() = 0; + virtual PipelineHandler *create(CameraManager *manager) = 0; const std::string &name() const { return name_; } @@ -42,11 +46,13 @@ private: }; #define REGISTER_PIPELINE_HANDLER(handler) \ -class handler##Factory : public PipelineHandlerFactory { \ +class handler##Factory : public PipelineHandlerFactory \ +{ \ public: \ - handler##Factory() : PipelineHandlerFactory(#handler) { } \ - PipelineHandler *create() final { \ - return new handler(); \ + handler##Factory() : PipelineHandlerFactory(#handler) {} \ + PipelineHandler *create(CameraManager *manager) final \ + { \ + return new handler(manager); \ } \ }; \ static handler##Factory global_##handler##Factory; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 8cbc10acfbb5..589b3078f301 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -23,20 +23,20 @@ LOG_DEFINE_CATEGORY(IPU3) class PipelineHandlerIPU3 : public PipelineHandler { public: - PipelineHandlerIPU3(); + PipelineHandlerIPU3(CameraManager *manager); ~PipelineHandlerIPU3(); - bool match(CameraManager *manager, DeviceEnumerator *enumerator); + bool match(DeviceEnumerator *enumerator); private: MediaDevice *cio2_; MediaDevice *imgu_; - void registerCameras(CameraManager *manager); + void registerCameras(); }; -PipelineHandlerIPU3::PipelineHandlerIPU3() - : cio2_(nullptr), imgu_(nullptr) +PipelineHandlerIPU3::PipelineHandlerIPU3(CameraManager *manager) + : PipelineHandler(manager), cio2_(nullptr), imgu_(nullptr) { } @@ -52,7 +52,7 @@ PipelineHandlerIPU3::~PipelineHandlerIPU3() imgu_ = nullptr; } -bool PipelineHandlerIPU3::match(CameraManager *manager, DeviceEnumerator *enumerator) +bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) { DeviceMatch cio2_dm("ipu3-cio2"); cio2_dm.add("ipu3-csi2 0"); @@ -106,7 +106,7 @@ bool PipelineHandlerIPU3::match(CameraManager *manager, DeviceEnumerator *enumer if (cio2_->disableLinks()) goto error_close_cio2; - registerCameras(manager); + registerCameras(); cio2_->close(); @@ -127,7 +127,7 @@ error_release_mdev: * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four * CIO2 CSI-2 receivers. */ -void PipelineHandlerIPU3::registerCameras(CameraManager *manager) +void PipelineHandlerIPU3::registerCameras() { /* * For each CSI-2 receiver on the IPU3, create a Camera if an @@ -172,7 +172,7 @@ void PipelineHandlerIPU3::registerCameras(CameraManager *manager) std::string cameraName = sensor->name() + " " + std::to_string(id); std::shared_ptr camera = Camera::create(cameraName); - manager->addCamera(std::move(camera)); + manager_->addCamera(std::move(camera)); LOG(IPU3, Info) << "Registered Camera[" << numCameras << "] \"" diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 3ba69da8b775..92b23da73901 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -17,17 +17,17 @@ namespace libcamera { class PipelineHandlerUVC : public PipelineHandler { public: - PipelineHandlerUVC(); + PipelineHandlerUVC(CameraManager *manager); ~PipelineHandlerUVC(); - bool match(CameraManager *manager, DeviceEnumerator *enumerator); + bool match(DeviceEnumerator *enumerator); private: MediaDevice *dev_; }; -PipelineHandlerUVC::PipelineHandlerUVC() - : dev_(nullptr) +PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager) + : PipelineHandler(manager), dev_(nullptr) { } @@ -37,7 +37,7 @@ PipelineHandlerUVC::~PipelineHandlerUVC() dev_->release(); } -bool PipelineHandlerUVC::match(CameraManager *manager, DeviceEnumerator *enumerator) +bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) { DeviceMatch dm("uvcvideo"); @@ -49,7 +49,7 @@ bool PipelineHandlerUVC::match(CameraManager *manager, DeviceEnumerator *enumera dev_->acquire(); std::shared_ptr camera = Camera::create(dev_->model()); - manager->addCamera(std::move(camera)); + manager_->addCamera(std::move(camera)); return true; } diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 82b9237a3d7d..f12d007cd956 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -17,17 +17,17 @@ namespace libcamera { class PipeHandlerVimc : public PipelineHandler { public: - PipeHandlerVimc(); + PipeHandlerVimc(CameraManager *manager); ~PipeHandlerVimc(); - bool match(CameraManager *manager, DeviceEnumerator *enumerator); + bool match(DeviceEnumerator *enumerator); private: MediaDevice *dev_; }; -PipeHandlerVimc::PipeHandlerVimc() - : dev_(nullptr) +PipeHandlerVimc::PipeHandlerVimc(CameraManager *manager) + : PipelineHandler(manager), dev_(nullptr) { } @@ -37,7 +37,7 @@ PipeHandlerVimc::~PipeHandlerVimc() dev_->release(); } -bool PipeHandlerVimc::match(CameraManager *manager, DeviceEnumerator *enumerator) +bool PipeHandlerVimc::match(DeviceEnumerator *enumerator) { DeviceMatch dm("vimc"); @@ -65,7 +65,7 @@ bool PipeHandlerVimc::match(CameraManager *manager, DeviceEnumerator *enumerator * object is modeled. */ std::shared_ptr camera = Camera::create("Dummy VIMC Camera"); - manager->addCamera(std::move(camera)); + manager_->addCamera(std::move(camera)); return true; } diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index c24feeafc503..45788487b5c0 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -34,18 +34,30 @@ LOG_DEFINE_CATEGORY(Pipeline) * with the pipelines it supports and creates corresponding Camera devices. */ +/** + * \brief Construct a PipelineHandler instance + * \param[in] manager The camera manager + */ +PipelineHandler::PipelineHandler(CameraManager *manager) + : manager_(manager) +{ +} + +PipelineHandler::~PipelineHandler() +{ +} + /** * \fn PipelineHandler::match(DeviceEnumerator *enumerator) * \brief Match media devices and create camera instances - * \param manager The camera manager * \param enumerator The enumerator providing all media devices found in the * system * * This function is the main entry point of the pipeline handler. It is called - * by the camera manager with the \a manager and \a enumerator passed as - * arguments. It shall acquire from the \a enumerator all the media devices it - * needs for a single pipeline, create one or multiple Camera instances and - * register them with the \a manager. + * by the camera manager with the \a enumerator passed as an argument. It shall + * acquire from the \a enumerator all the media devices it needs for a single + * pipeline, create one or multiple Camera instances and register them with the + * camera manager. * * If all media devices needed by the pipeline handler are found, they must all * be acquired by a call to MediaDevice::acquire(). This function shall then @@ -66,6 +78,15 @@ LOG_DEFINE_CATEGORY(Pipeline) * created, or false otherwise */ +/** + * \var PipelineHandler::manager_ + * \brief The Camera manager associated with the pipeline handler + * + * The camera manager pointer is stored in the pipeline handler for the + * convenience of pipeline handler implementations. It remains valid and + * constant for the whole lifetime of the pipeline handler. + */ + /** * \class PipelineHandlerFactory * \brief Registration of PipelineHandler classes and creation of instances @@ -96,8 +117,11 @@ PipelineHandlerFactory::PipelineHandlerFactory(const char *name) /** * \fn PipelineHandlerFactory::create() * \brief Create an instance of the PipelineHandler corresponding to the factory + * \param[in] manager The camera manager * - * This virtual function is implemented by the REGISTER_PIPELINE_HANDLER() macro. + * This virtual function is implemented by the REGISTER_PIPELINE_HANDLER() + * macro. It creates a pipeline handler instance associated with the camera + * \a manager. * * \return a pointer to a newly constructed instance of the PipelineHandler * subclass corresponding to the factory