Show a patch.

GET /api/1.1/patches/20979/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 20979,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20979/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20979/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240820195016.16028-4-hdegoede@redhat.com>",
    "date": "2024-08-20T19:50:14",
    "name": "[3/5] pipeline_handler: Add acquireDevice() method to mirror existing releaseDevice()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "bb717ef817cd9246b542c5175c055d036f93192b",
    "submitter": {
        "id": 102,
        "url": "https://patchwork.libcamera.org/api/1.1/people/102/?format=api",
        "name": "Hans de Goede",
        "email": "hdegoede@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20979/mbox/",
    "series": [
        {
            "id": 4530,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4530/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4530",
            "date": "2024-08-20T19:50:11",
            "name": "Fix uvcvideo pipelinehandler keeping /dev/video# open",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4530/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20979/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20979/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 84097C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Aug 2024 19:50:34 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2F3B9633CC;\n\tTue, 20 Aug 2024 21:50:34 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BB326633CE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Aug 2024 21:50:30 +0200 (CEST)",
            "from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-480-fgjgkCGoOvmhUpX8d272Gw-1;\n\tTue, 20 Aug 2024 15:50:28 -0400",
            "from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.12])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid 816FF1955D50 for <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Aug 2024 19:50:27 +0000 (UTC)",
            "from x1.localdomain.com (unknown [10.39.192.41])\n\tby mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 8007419560AA; Tue, 20 Aug 2024 19:50:25 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"C6he7EkT\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1724183429;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=yv03rFPwncxEXqXKc75XE90oiiULTRtFAXKnU/3UDfE=;\n\tb=C6he7EkTlcQODQmIVqOnp6vTMxF1Rmb24eyvv3gkgoOeUqEfwfhbu1Y81uy0OiXYpuM9FD\n\tn/1UFQeDTH12UeBenD3g0bSdnBAYLHAoihc5XqrhEDJd38RNLutbMfeAm1K1rqhO8NnSuB\n\tRNidJlkC8no5e2vNInxNRV5VeqUdkqU=",
        "X-MC-Unique": "fgjgkCGoOvmhUpX8d272Gw-1",
        "From": "Hans de Goede <hdegoede@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Maxime Ripard <mripard@redhat.com>, Milan Zamazal <mzamazal@redhat.com>, \n\tHans de Goede <hdegoede@redhat.com>",
        "Subject": "[PATCH 3/5] pipeline_handler: Add acquireDevice() method to mirror\n\texisting releaseDevice()",
        "Date": "Tue, 20 Aug 2024 21:50:14 +0200",
        "Message-ID": "<20240820195016.16028-4-hdegoede@redhat.com>",
        "In-Reply-To": "<20240820195016.16028-1-hdegoede@redhat.com>",
        "References": "<20240820195016.16028-1-hdegoede@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.0 on 10.30.177.12",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "ATM libcamera always keeps all /dev/video# and /dev/v4l2_subdev# nodes\nfor a pipeline open after enumerating the camera.\n\nThis is a problem for uvcvideo and atomisp /dev/video# nodes as well as\nfor VCM /dev/v4l2_subdev# nodes. Keeping these open stops the underlying\nhw-devices from being able to enter runtime-suspend causing significant\nunnecessary power-usage.\n\nAdd a stub acquireDevice() method to the PipelineHandler class which\npipeline handlers can override to delay opening /dev nodes until\nthe camera is acquired.\n\nNote pipeline handlers typically also will need access to /dev nodes\nfor their CameraConfig::validate() implementation for tryFormat() calls.\nMaking sure that /dev nodes are opened as necessary from validate() is\nleft up to the pipeline handler implementation.\n\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n include/libcamera/internal/pipeline_handler.h |  3 +-\n src/libcamera/camera.cpp                      |  2 +-\n src/libcamera/pipeline_handler.cpp            | 43 +++++++++++++++----\n 3 files changed, 37 insertions(+), 11 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex cad5812f..597f7c3e 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@@ -79,6 +79,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 382a68f7..4e393f89 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -995,7 +995,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 1fc22d6a..e1342306 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -163,20 +163,22 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,\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-\tif (useCount_) {\n-\t\t++useCount_;\n-\t\treturn true;\n+\tif (useCount_ == 0) {\n+\t\tfor (std::shared_ptr<MediaDevice> &media : mediaDevices_) {\n+\t\t\tif (!media->lock()) {\n+\t\t\t\tunlockMediaDevices();\n+\t\t\t\treturn false;\n+\t\t\t}\n+\t\t}\n \t}\n \n-\tfor (std::shared_ptr<MediaDevice> &media : mediaDevices_) {\n-\t\tif (!media->lock()) {\n-\t\t\tunlockMediaDevices();\n-\t\t\treturn false;\n-\t\t}\n+\tif (!acquireDevice(camera)) {\n+\t\tunlockMediaDevices();\n+\t\treturn false;\n \t}\n \n \t++useCount_;\n@@ -213,12 +215,35 @@ void PipelineHandler::release(Camera *camera)\n \t--useCount_;\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 get resources\n+ * such as open /dev nodes are allocate buffers when a camera is\n+ * acquired.\n+ *\n+ * Note this is called once for every camera which is acquired,\n+ * so if there are shared resources the pipeline handler must take\n+ * care to not release them until releaseDevice() has been called for\n+ * all previously acquired cameras.\n+ *\n+ * \\return True on success, false on failure.\n+ * \\sa releaseDevice()\n+ */\n+bool PipelineHandler::acquireDevice([[maybe_unused]] Camera *camera)\n+{\n+\treturn true;\n+}\n+\n /**\n  * \\brief Release resources associated with this camera\n  * \\param[in] camera The camera for which to release resources\n  *\n  * Pipeline handlers may override this in order to perform cleanup operations\n  * when a camera is released, such as freeing memory.\n+ *\n+ * \\sa acquireDevice()\n  */\n void PipelineHandler::releaseDevice([[maybe_unused]] Camera *camera)\n {\n",
    "prefixes": [
        "3/5"
    ]
}