{"id":333,"url":"https://patchwork.libcamera.org/api/patches/333/?format=json","web_url":"https://patchwork.libcamera.org/patch/333/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190122232955.31783-4-niklas.soderlund@ragnatech.se>","date":"2019-01-22T23:29:55","name":"[libcamera-devel,3/3] libcamera: camera: add method to disconnect camera","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2261623c7ab4a02c2318b4ee8e40f48e31693d31","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/333/mbox/","series":[{"id":117,"url":"https://patchwork.libcamera.org/api/series/117/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=117","date":"2019-01-22T23:29:52","name":"libcamera: add association between Camera and PipelineHandlers","version":1,"mbox":"https://patchwork.libcamera.org/series/117/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/333/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/333/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A625D60C82\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Jan 2019 00:30:45 +0100 (CET)","from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid bb9fda7e-1e9d-11e9-874f-005056917f90;\n\tWed, 23 Jan 2019 00:30:41 +0100 (CET)"],"X-Halon-ID":"bb9fda7e-1e9d-11e9-874f-005056917f90","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 23 Jan 2019 00:29:55 +0100","Message-Id":"<20190122232955.31783-4-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","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 3/3] libcamera: camera: add method to\n\tdisconnect camera","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 22 Jan 2019 23:30:45 -0000"},"content":"As camera object have the potential to outlive the hardware they\nrepresent there is a need to inform the camera it's disconnected from\nthe hardware.\n\nAt this point it is enough to sever the reference to the pipeline\nhandler which created the camera as that is the only resource the Camera\nobject holds which represents hardware. As we move forward maybe a more\nelaborate flag is needed to flag that hardware is being removed.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/camera.h           |  2 ++\n src/libcamera/camera.cpp             | 16 ++++++++++++++++\n src/libcamera/pipeline/ipu3/ipu3.cpp |  3 +++\n src/libcamera/pipeline/uvcvideo.cpp  |  4 +++-\n src/libcamera/pipeline/vimc.cpp      |  4 +++-\n 5 files changed, 27 insertions(+), 2 deletions(-)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex d3bae4cbee1e0cea..b5d4dfe4b1f6a586 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -25,6 +25,8 @@ public:\n \n \tconst std::string &name() const;\n \n+\tvoid disconnect();\n+\n private:\n \texplicit Camera(const std::string &name, class PipelineHandler *pipe);\n \t~Camera();\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex f198eb4978b12239..496fb1021c4fccf0 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -33,6 +33,8 @@\n \n namespace libcamera {\n \n+LOG_DECLARE_CATEGORY(Camera)\n+\n /**\n  * \\class Camera\n  * \\brief Camera device\n@@ -86,6 +88,20 @@ const std::string &Camera::name() const\n \treturn name_;\n }\n \n+/**\n+ * \\brief Disconnect the camera from the hardware\n+ *\n+ * When the underlying PipelineHandler is deleted as a result of the hardware\n+ * being removed or un-pluged the Camera needs to be disconnected. The pipeline\n+ * handler should when it detects that it's being removed notify all cameras it\n+ * have created that they are now longer backed by any hardware.\n+ */\n+void Camera::disconnect()\n+{\n+\tLOG(Camera, Debug) << \"Disconnecting camera\" << name_;\n+\tpipe_ = nullptr;\n+}\n+\n Camera::Camera(const std::string &name, class PipelineHandler *pipe)\n \t: name_(name), pipe_(pipe)\n {\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 19f73011f8b75438..c6106c538f071058 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -44,6 +44,9 @@ PipelineHandlerIPU3::PipelineHandlerIPU3()\n \n PipelineHandlerIPU3::~PipelineHandlerIPU3()\n {\n+\tfor (const std::shared_ptr<Camera> &camera : cameras_)\n+\t\tcamera->disconnect();\n+\n \tcameras_.clear();\n \n \tif (cio2_)\ndiff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\nindex 2162824eb571fba7..a02f3671d22c5f79 100644\n--- a/src/libcamera/pipeline/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo.cpp\n@@ -34,8 +34,10 @@ PipelineHandlerUVC::PipelineHandlerUVC()\n \n PipelineHandlerUVC::~PipelineHandlerUVC()\n {\n-\tif (camera_)\n+\tif (camera_) {\n+\t\tcamera_->disconnect();\n \t\tcamera_ = nullptr;\n+\t}\n \n \tif (dev_)\n \t\tdev_->release();\ndiff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex 373fc0ee5339f9ae..d732ac21cae1a84b 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -34,8 +34,10 @@ PipeHandlerVimc::PipeHandlerVimc()\n \n PipeHandlerVimc::~PipeHandlerVimc()\n {\n-\tif (camera_)\n+\tif (camera_) {\n+\t\tcamera_->disconnect();\n \t\tcamera_ = nullptr;\n+\t}\n \n \tif (dev_)\n \t\tdev_->release();\n","prefixes":["libcamera-devel","3/3"]}