{"id":17807,"url":"https://patchwork.libcamera.org/api/1.1/patches/17807/?format=json","web_url":"https://patchwork.libcamera.org/patch/17807/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20221116001724.3938045-2-kieran.bingham@ideasonboard.com>","date":"2022-11-16T00:17:23","name":"[libcamera-devel,1/2] libcamera: pipeline: Add an acquireDevice method","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"380a5edaeadd21be5c55b743aa3bc297bfd541b6","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17807/mbox/","series":[{"id":3614,"url":"https://patchwork.libcamera.org/api/1.1/series/3614/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3614","date":"2022-11-16T00:17:22","name":"Support resource acquisition at 'acquire()'","version":1,"mbox":"https://patchwork.libcamera.org/series/3614/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17807/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17807/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9E5F1C3285\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 16 Nov 2022 00:17:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6EB786309B;\n\tWed, 16 Nov 2022 01:17:30 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 577A563087\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 16 Nov 2022 01:17:29 +0100 (CET)","from Monstersaurus.local\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D5AFFAF4;\n\tWed, 16 Nov 2022 01:17:28 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1668557850;\n\tbh=9WogkLEpfbW6noMfaI5JtIgQ8SHgfPUEVfe9+Nv+/cs=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=QwgW6wQ/AiF4cU9qUHU4hCW4MQbMLuqdUYiFHJXUXpkjdJuBN68fy3IBcAF3nkaPa\n\tN3SRyIDyJHJTMXZTkMePY2dBOmulCARy/4hYqBNjj1E7q3DkzK7gLKBDH4MSn5n/4Q\n\tzuTy5PJdnxUknFXpLy5rWaRznO+8IksoVrN043C2IfTI/SGK1obA2UrPAt1kUDXGY3\n\t8XV5lYZBuXrT+7asj3+lp0dVaHS5HDJaPvqtE8UXTyfBrE9JyPVf2mr3MjaySfTO7m\n\tPT6oRe0Q0f0DQ7k0y1+t8G0WoNPlWP5Pgswy7KBty2hTzuI2rlPKfYKdXnvRps1FRF\n\t12tZlCOqoWx1A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1668557849;\n\tbh=9WogkLEpfbW6noMfaI5JtIgQ8SHgfPUEVfe9+Nv+/cs=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Ub88ZsVoU3WqaezXQxalSdbgMuZZvwBAkv+bCUGX6Pl6NArCSKkXN4t4hEin3GgFr\n\t7uPhiaAVUwog687Y3WUkoJdAzm3MdkVgoJJDw4s16q8IsRK0dhE3pYAWboQCr4SVo/\n\trVlu1KnLoT8qjZNe8w73PLu+msg7w8Hlt9tgpIgc="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Ub88ZsVo\"; dkim-atps=neutral","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Wed, 16 Nov 2022 00:17:23 +0000","Message-Id":"<20221116001724.3938045-2-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20221116001724.3938045-1-kieran.bingham@ideasonboard.com>","References":"<20221116001724.3938045-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/2] libcamera: pipeline: Add an\n\tacquireDevice method","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Cameras may need to acquire resources such as video device nodes before\nthey can be configured. Acquisition of these resources can prevent power\nsaving operations from being handled for instance in the event that a\ncamera daemon such as Pipewire keeps unacquired devices held at runtime.\n\nProvide a method to allow pipeline handlers to implement resource\nacquisition operations during the acquire phase of the Camera state\nmachine.\n\nAny resources acquired during acquireDevice() must be released as part\nof the corresponding releaseDevice() implementation.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/pipeline_handler.h |  3 ++-\n src/libcamera/camera.cpp                      |  2 +-\n src/libcamera/pipeline_handler.cpp            | 23 ++++++++++++++++++-\n 3 files changed, 25 insertions(+), 3 deletions(-)","diff":"diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex ec4f662d7399..483553b0d027 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -45,7 +45,7 @@ public:\n \tMediaDevice *acquireMediaDevice(DeviceEnumerator *enumerator,\n \t\t\t\t\tconst DeviceMatch &dm);\n \n-\tbool acquire();\n+\tbool acquire(Camera *camera);\n \tvoid release(Camera *camera);\n \n \tvirtual std::unique_ptr<CameraConfiguration> generateConfiguration(Camera *camera,\n@@ -74,6 +74,7 @@ protected:\n \tvirtual int queueRequestDevice(Camera *camera, Request *request) = 0;\n \tvirtual void stopDevice(Camera *camera) = 0;\n \n+\tvirtual bool acquireDevice(Camera *camera);\n \tvirtual void releaseDevice(Camera *camera);\n \n \tCameraManager *manager_;\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 2d947a442bff..4e0a6584a673 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -835,7 +835,7 @@ int Camera::acquire()\n \tif (ret < 0)\n \t\treturn ret == -EACCES ? -EBUSY : ret;\n \n-\tif (!d->pipe_->acquire()) {\n+\tif (!d->pipe_->acquire(this)) {\n \t\tLOG(Camera, Info)\n \t\t\t<< \"Pipeline handler in use by another process\";\n \t\treturn -EBUSY;\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex cfade4908118..4303a5893a4d 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -143,6 +143,7 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,\n \n /**\n  * \\brief Acquire exclusive access to the pipeline handler for the process\n+ * \\param[in] camera The camera which is being acquired\n  *\n  * This function locks all the media devices used by the pipeline to ensure\n  * that no other process can access them concurrently.\n@@ -155,13 +156,16 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,\n  * Pipeline handlers shall not call this function directly as the Camera class\n  * handles access internally.\n  *\n+ * Any resources acquired during an overridden acquireDevice() must be released\n+ * by a corresponding override of releaseDevice().\n+ *\n  * \\context This function is \\threadsafe.\n  *\n  * \\return True if the pipeline handler was acquired, false if another process\n  * has already acquired it\n  * \\sa release()\n  */\n-bool PipelineHandler::acquire()\n+bool PipelineHandler::acquire(Camera *camera)\n {\n \tMutexLocker locker(lock_);\n \n@@ -177,10 +181,27 @@ bool PipelineHandler::acquire()\n \t\t}\n \t}\n \n+\tif (!acquireDevice(camera)) {\n+\t\tunlockMediaDevices();\n+\t\treturn false;\n+\t}\n+\n \t++useCount_;\n \treturn true;\n }\n \n+/**\n+ * \\brief Acquire resources associated with this camera\n+ * \\param[in] camera The camera for which to acquire resources\n+ *\n+ * Pipeline handlers may override this in order to perform resource acquisition\n+ * operations when a camera is acquired, such as opening device nodes.\n+ */\n+bool PipelineHandler::acquireDevice([[maybe_unused]] Camera *camera)\n+{\n+\treturn true;\n+}\n+\n /**\n  * \\brief Release exclusive access to the pipeline handler\n  * \\param[in] camera The camera for which to release data\n","prefixes":["libcamera-devel","1/2"]}