Show a patch.

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

{
    "id": 21745,
    "url": "https://patchwork.libcamera.org/api/patches/21745/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21745/",
    "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": "<20241023111124.124090-5-jacopo.mondi@ideasonboard.com>",
    "date": "2024-10-23T11:11:23",
    "name": "[4/4] libcamera: v4l2_videodevice: Update to the new kernel metadata API",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "043a2633835d0dd71cb559a3cd94f2205300dfc8",
    "submitter": {
        "id": 143,
        "url": "https://patchwork.libcamera.org/api/people/143/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo.mondi@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21745/mbox/",
    "series": [
        {
            "id": 4738,
            "url": "https://patchwork.libcamera.org/api/series/4738/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4738",
            "date": "2024-10-23T11:11:19",
            "name": "libcamera: Initial support for generic line based metadata",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4738/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21745/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21745/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 5238AC327C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Oct 2024 11:11:47 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 01ABA6539A;\n\tWed, 23 Oct 2024 13:11:46 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B8606537E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Oct 2024 13:11:36 +0200 (CEST)",
            "from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 36D708A9;\n\tWed, 23 Oct 2024 13:09:49 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"HIDIUiyT\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729681789;\n\tbh=NCs455XX6EzBU+WSb2tMkGGAPwuimKMiTnFWFbyeYEQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=HIDIUiyTLgCOo5X2Ki5ppoExr89XRwRxVNTKe6aRsC883PA/ase7Um/F0rLAr4PQG\n\t6QoPtuh2LJBNwxDyWYfLYwpp/47ZEkq0xFGM1r/JWs82dRShFg/RvFYr3vi749LpzR\n\tIEEc74aUJb73QBVCCceK0R0JxczqfJhJBg0VRJqw=",
        "From": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Subject": "[PATCH 4/4] libcamera: v4l2_videodevice: Update to the new kernel\n\tmetadata API",
        "Date": "Wed, 23 Oct 2024 13:11:23 +0200",
        "Message-ID": "<20241023111124.124090-5-jacopo.mondi@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.47.0",
        "In-Reply-To": "<20241023111124.124090-1-jacopo.mondi@ideasonboard.com>",
        "References": "<20241023111124.124090-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>\n\n---\nCompared to Larent's first version, this one sets width, height and\nbytesperline only if the device isMetaCap() and the V4L2 pixel format\nis one of the generic line based ones.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@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 14eba0561d6a..87cdbc3edf52 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": [
        "4/4"
    ]
}