Show a patch.

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

{
    "id": 21047,
    "url": "https://patchwork.libcamera.org/api/patches/21047/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21047/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20240827164255.314432-4-hdegoede@redhat.com>",
    "date": "2024-08-27T16:42:55",
    "name": "[v2,3/3] uvcvideo: Implement acquireDevice() + releaseDevice()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "df9997898b4610e042c1c369efe1e33c9ef68cf2",
    "submitter": {
        "id": 102,
        "url": "https://patchwork.libcamera.org/api/people/102/?format=api",
        "name": "Hans de Goede",
        "email": "hdegoede@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21047/mbox/",
    "series": [
        {
            "id": 4546,
            "url": "https://patchwork.libcamera.org/api/series/4546/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4546",
            "date": "2024-08-27T16:42:52",
            "name": "Fix uvcvideo pipelinehandler keeping /dev/video# open",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4546/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21047/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21047/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 D3FA6C32C2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Aug 2024 16:43:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6EA3163460;\n\tTue, 27 Aug 2024 18:43:20 +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 1F4726345F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Aug 2024 18:43:14 +0200 (CEST)",
            "from mx-prod-mc-05.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-124-9NqRetDGPji5s5HEa27-xA-1;\n\tTue, 27 Aug 2024 12:43:11 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid E32191955BE7 for <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Aug 2024 16:43:10 +0000 (UTC)",
            "from localhost.localdomain (unknown [10.39.192.136])\n\tby mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 5D2691955D8B; Tue, 27 Aug 2024 16:43:09 +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=\"aTtXNIaK\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1724776993;\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=xk3NH8Mo97mDm9v1otdkRM2eP3Jyn3uw2XyLBc9Unqs=;\n\tb=aTtXNIaKXdt+PriHo7z8vM7UTZmuSl00KkURcyuA8HQkj1twC7HhKULZKsis4hdbf/gA9A\n\t4hFOa5q505/QJ7emXR6xONtj+Ao+20/4HzeLpOcl8FchHYbQpcpcSci4ESYeiV+twID3si\n\tHTiX0MZ+b8V6O4DclTFL0A4GrO8mfos=",
        "X-MC-Unique": "9NqRetDGPji5s5HEa27-xA-1",
        "From": "Hans de Goede <hdegoede@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Milan Zamazal <mzamazal@redhat.com>, Maxime Ripard <mripard@redhat.com>, \n\tHans de Goede <hdegoede@redhat.com>",
        "Subject": "[PATCH v2 3/3] uvcvideo: Implement acquireDevice() + releaseDevice()",
        "Date": "Tue, 27 Aug 2024 18:42:55 +0200",
        "Message-ID": "<20240827164255.314432-4-hdegoede@redhat.com>",
        "In-Reply-To": "<20240827164255.314432-1-hdegoede@redhat.com>",
        "References": "<20240827164255.314432-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": "The uvcvideo pipeline handler always keeps the uvcvideo /dev/video# node\nfor a pipeline open after enumerating the camera.\n\nThis is a problem for uvcvideo, as keeping the /dev/video# node open stops\nthe underlying USB device and the USB bus controller from being able to\nenter runtime-suspend causing significant unnecessary power-usage.\n\nImplement acquireDevice() + releaseDevice(), openening /dev/video# on\nacquire and closing it on release to fix this.\n\nAnd make validate do a local video_->open() + close() around validate()\nwhen not open yet. To keep validate() working on unacquired cameras.\n\nLink: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2669\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\nChanges in v2:\n- Minor commit msg + code improvements\n---\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 45 ++++++++++++++++++++\n 1 file changed, 45 insertions(+)",
    "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 8a7409fc..584f5230 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -13,6 +13,7 @@\n #include <tuple>\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/mutex.h>\n #include <libcamera/base/utils.h>\n \n #include <libcamera/camera.h>\n@@ -48,6 +49,7 @@ public:\n \n \tconst std::string &id() const { return id_; }\n \n+\tMutex openLock_;\n \tstd::unique_ptr<V4L2VideoDevice> video_;\n \tStream stream_;\n \tstd::map<PixelFormat, std::vector<SizeRange>> formats_;\n@@ -93,6 +95,9 @@ private:\n \t\t\t   const ControlValue &value);\n \tint processControls(UVCCameraData *data, Request *request);\n \n+\tbool acquireDevice(Camera *camera) override;\n+\tvoid releaseDevice(Camera *camera) override;\n+\n \tUVCCameraData *cameraData(Camera *camera)\n \t{\n \t\treturn static_cast<UVCCameraData *>(camera->_d());\n@@ -107,6 +112,7 @@ UVCCameraConfiguration::UVCCameraConfiguration(UVCCameraData *data)\n CameraConfiguration::Status UVCCameraConfiguration::validate()\n {\n \tStatus status = Valid;\n+\tbool opened = false;\n \n \tif (config_.empty())\n \t\treturn Invalid;\n@@ -158,7 +164,23 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()\n \tformat.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat);\n \tformat.size = cfg.size;\n \n+\t/*\n+\t * For power-consumption reasons video_ is closed when the camera\n+\t * is not acquired. Open it here if necessary.\n+\t */\n+\tMutexLocker locker(data_->openLock_);\n+\n+\tif (!data_->video_->isOpen()) {\n+\t\tint ret = data_->video_->open();\n+\t\tif (ret)\n+\t\t\treturn Invalid;\n+\n+\t\topened = true;\n+\t}\n+\n \tint ret = data_->video_->tryFormat(&format);\n+\tif (opened)\n+\t\tdata_->video_->close();\n \tif (ret)\n \t\treturn Invalid;\n \n@@ -411,6 +433,23 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n \treturn true;\n }\n \n+bool PipelineHandlerUVC::acquireDevice(Camera *camera)\n+{\n+\tUVCCameraData *data = cameraData(camera);\n+\n+\tMutexLocker locker(data->openLock_);\n+\n+\treturn data->video_->open() == 0;\n+}\n+\n+void PipelineHandlerUVC::releaseDevice(Camera *camera)\n+{\n+\tUVCCameraData *data = cameraData(camera);\n+\n+\tMutexLocker locker(data->openLock_);\n+\tdata->video_->close();\n+}\n+\n int UVCCameraData::init(MediaDevice *media)\n {\n \tint ret;\n@@ -512,6 +551,12 @@ int UVCCameraData::init(MediaDevice *media)\n \n \tcontrolInfo_ = ControlInfoMap(std::move(ctrls), controls::controls);\n \n+\t/*\n+\t * Close to allow camera to go into runtime-suspend, video_\n+\t * will be re-opened from acquireDevice() and validate().\n+\t */\n+\tvideo_->close();\n+\n \treturn 0;\n }\n \n",
    "prefixes": [
        "v2",
        "3/3"
    ]
}