From patchwork Tue Jan 22 23:29:54 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: 332 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F9C460C81 for ; Wed, 23 Jan 2019 00:30:44 +0100 (CET) X-Halon-ID: bb2411cb-1e9d-11e9-874f-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id bb2411cb-1e9d-11e9-874f-005056917f90; Wed, 23 Jan 2019 00:30:41 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Jan 2019 00:29:54 +0100 Message-Id: <20190122232955.31783-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190122232955.31783-1-niklas.soderlund@ragnatech.se> References: <20190122232955.31783-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: pipelines: keep reference to cameras created 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 23:30:44 -0000 The pipeline handlers needs to keep a reference to the cameras it creates in order to notify it when it's being disconnected. When hot-unplug support is added the pipeline handler would be deleted when the hardware is removed from under it. After the deletion of pipeline handler all the Camera objects created by the pipeline handler might still be around as they might be in use by a application. At this point the pipeline handler should inform the camera that it's disconnected. Signed-off-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 7 ++++++- src/libcamera/pipeline/uvcvideo.cpp | 10 +++++++--- src/libcamera/pipeline/vimc.cpp | 11 +++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 48d028f7e6cd9b4d..19f73011f8b75438 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -32,6 +32,8 @@ private: MediaDevice *cio2_; MediaDevice *imgu_; + std::vector> cameras_; + void registerCameras(CameraManager *manager); }; @@ -42,6 +44,8 @@ PipelineHandlerIPU3::PipelineHandlerIPU3() PipelineHandlerIPU3::~PipelineHandlerIPU3() { + cameras_.clear(); + if (cio2_) cio2_->release(); @@ -173,7 +177,8 @@ void PipelineHandlerIPU3::registerCameras(CameraManager *manager) std::string cameraName = sensor->name() + " " + std::to_string(id); std::shared_ptr camera = Camera::create(cameraName, this); - manager->addCamera(std::move(camera)); + cameras_.push_back(camera); + manager->addCamera(camera); LOG(IPU3, Info) << "Registered Camera[" << numCameras << "] \"" diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 3651250b683e7810..2162824eb571fba7 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -24,15 +24,19 @@ public: private: MediaDevice *dev_; + std::shared_ptr camera_; }; PipelineHandlerUVC::PipelineHandlerUVC() - : dev_(nullptr) + : dev_(nullptr), camera_(nullptr) { } PipelineHandlerUVC::~PipelineHandlerUVC() { + if (camera_) + camera_ = nullptr; + if (dev_) dev_->release(); } @@ -48,8 +52,8 @@ bool PipelineHandlerUVC::match(CameraManager *manager, DeviceEnumerator *enumera dev_->acquire(); - std::shared_ptr camera = Camera::create(dev_->model(), this); - manager->addCamera(std::move(camera)); + camera_ = Camera::create(dev_->model(), this); + manager->addCamera(camera_); return true; } diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 81d8319eb88e06d2..373fc0ee5339f9ae 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -24,15 +24,19 @@ public: private: MediaDevice *dev_; + std::shared_ptr camera_; }; PipeHandlerVimc::PipeHandlerVimc() - : dev_(nullptr) + : dev_(nullptr), camera_(nullptr) { } PipeHandlerVimc::~PipeHandlerVimc() { + if (camera_) + camera_ = nullptr; + if (dev_) dev_->release(); } @@ -57,9 +61,8 @@ bool PipeHandlerVimc::match(CameraManager *manager, DeviceEnumerator *enumerator dev_->acquire(); - std::shared_ptr camera = Camera::create("Dummy VIMC Camera", - this); - manager->addCamera(std::move(camera)); + camera_ = Camera::create("Dummy VIMC Camera", this); + manager->addCamera(camera_); return true; }