Show a patch.

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

{
    "id": 22464,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/22464/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22464/",
    "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": "<20250108104924.163077-5-jacopo.mondi@ideasonboard.com>",
    "date": "2025-01-08T10:49:21",
    "name": "[v3,4/6] libcamera: v4l2_videodevice: Update to the new kernel metadata API",
    "commit_ref": "99b54c2c55a899769652a67d532850adecc67d8d",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "043a2633835d0dd71cb559a3cd94f2205300dfc8",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22464/mbox/",
    "series": [
        {
            "id": 4933,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4933/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4933",
            "date": "2025-01-08T10:49:17",
            "name": "libcamera: Initial support for generic line based metadata",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/4933/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22464/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22464/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 7080DC32F0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Jan 2025 10:49:47 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EC39E68509;\n\tWed,  8 Jan 2025 11:49:46 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D9EBF684E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Jan 2025 11:49:38 +0100 (CET)",
            "from ideasonboard.com (mob-5-90-140-184.net.vodafone.it\n\t[5.90.140.184])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8E49389A;\n\tWed,  8 Jan 2025 11:48:45 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"csUNlZkI\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736333326;\n\tbh=MDWopgsLalwu+GNnKMJEPeXukXK7HLLL+GwsNF/tq/U=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=csUNlZkIBj+L4sh9pZqjbutfWeqSXTPE3y/TWp3xP0kqeYeZ0MpID0gwO4spmns7M\n\tRMSolr2azw3j0r/8K2M7wFipxfvOhBjpdO9I9lg4erNHIlRndKb5Gic8hVDKhV/eJy\n\tPZ/P8FT3Akc543c5J1uGZV09XjeHr0JYGCDxi1ng=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>, naush@raspberrypi.com,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>",
        "Subject": "[PATCH v3 4/6] libcamera: v4l2_videodevice: Update to the new kernel\n\tmetadata API",
        "Date": "Wed,  8 Jan 2025 11:49:21 +0100",
        "Message-ID": "<20250108104924.163077-5-jacopo.mondi@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.47.1",
        "In-Reply-To": "<20250108104924.163077-1-jacopo.mondi@ideasonboard.com>",
        "References": "<20250108104924.163077-1-jacopo.mondi@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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": "From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nWith support for metadata in the streams API, the v4l2_meta_format\nstructure has been extended with width, height and bytesperline fields.\n\nSupport them in the V4L2VideoDevice getFormat() and setFormat()\nfunctions is the video device is meta capture device and if the\npixel format is one of the generic line-based metadata formats.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_pixelformat.h |  2 +\n src/libcamera/v4l2_pixelformat.cpp            | 34 +++++++++++++\n src/libcamera/v4l2_videodevice.cpp            | 51 ++++++++++++++-----\n 3 files changed, 73 insertions(+), 14 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h\nindex c836346bdc04..543eb21b3c07 100644\n--- a/include/libcamera/internal/v4l2_pixelformat.h\n+++ b/include/libcamera/internal/v4l2_pixelformat.h\n@@ -49,6 +49,8 @@ public:\n \tstatic const std::vector<V4L2PixelFormat> &\n \tfromPixelFormat(const PixelFormat &pixelFormat);\n \n+\tbool isGenericLineBasedMetadata() const;\n+\n private:\n \tuint32_t fourcc_;\n };\ndiff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\nindex eb9ac2224fd1..e8b3eb9c1394 100644\n--- a/src/libcamera/v4l2_pixelformat.cpp\n+++ b/src/libcamera/v4l2_pixelformat.cpp\n@@ -372,6 +372,40 @@ V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat)\n \treturn info.v4l2Formats;\n }\n \n+/**\n+ * \\brief Test if a V4L2PixelFormat is one of the line based generic metadata\n+ * formats\n+ *\n+ * A limited number of metadata formats, the ones that represents generic\n+ * line-based metadata buffers, need to have their width, height and\n+ * bytesperline set by userspace.\n+ *\n+ * This function tests if the current V4L2PixelFormat is one of those.\n+ *\n+ * Note: It would have been nicer to store this information in a\n+ * V4L2PixelFormat::Info instance, but as metadata format are not exposed to\n+ * applications, there are no PixelFormat and DRM fourcc codes associated to\n+ * them.\n+ *\n+ * \\return True if the V4L2PixelFormat() is a generic line based format, false\n+ * otherwise\n+ */\n+bool V4L2PixelFormat::isGenericLineBasedMetadata() const\n+{\n+\tswitch (fourcc_) {\n+\tcase V4L2_META_FMT_GENERIC_8:\n+\tcase V4L2_META_FMT_GENERIC_CSI2_10:\n+\tcase V4L2_META_FMT_GENERIC_CSI2_12:\n+\tcase V4L2_META_FMT_GENERIC_CSI2_14:\n+\tcase V4L2_META_FMT_GENERIC_CSI2_16:\n+\tcase V4L2_META_FMT_GENERIC_CSI2_20:\n+\tcase V4L2_META_FMT_GENERIC_CSI2_24:\n+\t\treturn true;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+}\n+\n /**\n  * \\brief Insert a text representation of a V4L2PixelFormat into an output\n  * stream\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex a5cf67845ce3..e241eb47b75d 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -888,7 +888,7 @@ int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format)\n int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n {\n \tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n+\tstruct v4l2_meta_format *meta = &v4l2Format.fmt.meta;\n \tint ret;\n \n \tv4l2Format.type = bufferType_;\n@@ -898,25 +898,42 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n \t\treturn ret;\n \t}\n \n-\tformat->size.width = 0;\n-\tformat->size.height = 0;\n-\tformat->fourcc = V4L2PixelFormat(pix->dataformat);\n+\tformat->fourcc = V4L2PixelFormat(meta->dataformat);\n+\tformat->planes[0].size = meta->buffersize;\n \tformat->planesCount = 1;\n-\tformat->planes[0].bpl = pix->buffersize;\n-\tformat->planes[0].size = pix->buffersize;\n+\n+\tbool genericLineBased = caps_.isMetaCapture() &&\n+\t\t\t\tformat->fourcc.isGenericLineBasedMetadata();\n+\n+\tif (genericLineBased) {\n+\t\tformat->size.width = meta->width;\n+\t\tformat->size.height = meta->height;\n+\t\tformat->planes[0].bpl = meta->bytesperline;\n+\t} else {\n+\t\tformat->size.width = 0;\n+\t\tformat->size.height = 0;\n+\t\tformat->planes[0].bpl = meta->buffersize;\n+\t}\n \n \treturn 0;\n }\n \n int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set)\n {\n+\tbool genericLineBased = caps_.isMetaCapture() &&\n+\t\t\t\tformat->fourcc.isGenericLineBasedMetadata();\n \tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n+\tstruct v4l2_meta_format *meta = &v4l2Format.fmt.meta;\n \tint ret;\n \n \tv4l2Format.type = bufferType_;\n-\tpix->dataformat = format->fourcc;\n-\tpix->buffersize = format->planes[0].size;\n+\tmeta->dataformat = format->fourcc;\n+\tmeta->buffersize = format->planes[0].size;\n+\tif (genericLineBased) {\n+\t\tmeta->width = format->size.width;\n+\t\tmeta->height = format->size.height;\n+\t\tmeta->bytesperline = format->planes[0].bpl;\n+\t}\n \tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n \tif (ret) {\n \t\tLOG(V4L2, Error)\n@@ -929,12 +946,18 @@ int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set)\n \t * Return to caller the format actually applied on the video device,\n \t * which might differ from the requested one.\n \t */\n-\tformat->size.width = 0;\n-\tformat->size.height = 0;\n-\tformat->fourcc = V4L2PixelFormat(pix->dataformat);\n+\tformat->fourcc = V4L2PixelFormat(meta->dataformat);\n \tformat->planesCount = 1;\n-\tformat->planes[0].bpl = pix->buffersize;\n-\tformat->planes[0].size = pix->buffersize;\n+\tformat->planes[0].size = meta->buffersize;\n+\tif (genericLineBased) {\n+\t\tformat->size.width = meta->width;\n+\t\tformat->size.height = meta->height;\n+\t\tformat->planes[0].bpl = meta->bytesperline;\n+\t} else {\n+\t\tformat->size.width = 0;\n+\t\tformat->size.height = 0;\n+\t\tformat->planes[0].bpl = meta->buffersize;\n+\t}\n \n \treturn 0;\n }\n",
    "prefixes": [
        "v3",
        "4/6"
    ]
}