Show a patch.

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

{
    "id": 13681,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13681/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13681/",
    "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": "<20210906225636.14683-14-laurent.pinchart@ideasonboard.com>",
    "date": "2021-09-06T22:56:20",
    "name": "[libcamera-devel,v3,14/30] libcamera: v4l2_videodevice: Split planes when dequeuing buffer",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "48e31fad63d88bdf24ed1e52c756a35b6ff3967d",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13681/mbox/",
    "series": [
        {
            "id": 2482,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2482/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2482",
            "date": "2021-09-06T22:54:20",
            "name": "libcamera: Handle fallout of FrameBuffer offset support",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/2482/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13681/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13681/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 4E308BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Sep 2021 22:57:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 319AF69171;\n\tTue,  7 Sep 2021 00:57:30 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A114B6916B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 00:57:04 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 39FA6891;\n\tTue,  7 Sep 2021 00:57:04 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"aStOT6hq\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630969024;\n\tbh=ri+vEUSyTxOTaM1OW0ENfWYzF390moPZsaFA9314zvQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=aStOT6hqzNWOeCklJ3ZMe5QdOz/u/aA9WFp3RwGbswKwSzeuYzMfmkidkVA5dzCNY\n\tYe/rzISOqvaFzec63Ok71+IYdf8DB5VWHMCRbuqeD9mxWcyOCn3e58w6gp5KG88yWL\n\tlM+LNEWqtn7p//TKBXXp5d6By2K3JaIdc/gWKi8c=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue,  7 Sep 2021 01:56:20 +0300",
        "Message-Id": "<20210906225636.14683-14-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 14/30] libcamera: v4l2_videodevice:\n\tSplit planes when dequeuing buffer",
        "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": "When dequeueing a buffer from a V4L2VideoDevice, the number of planes in\nthe FrameBuffer may not match the number of V4L2 buffer planes if the\nPixelFormat is multi-planar (has multiple colour planes) and the V4L2\nformat is single-planar (has a single buffer plane). In this case, we\nneed to split the single V4L2 buffer plane into FrameBuffer planes. Do\nso, and add checks to reject invalid V4L2 buffers in case of a driver\nissue.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v1:\n\n- Reduce indentation\n---\n src/libcamera/v4l2_videodevice.cpp | 53 +++++++++++++++++++++++++++---\n 1 file changed, 48 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 6c1ca9bb0a5c..2e458fcc22e0 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -7,6 +7,7 @@\n \n #include \"libcamera/internal/v4l2_videodevice.h\"\n \n+#include <algorithm>\n #include <array>\n #include <fcntl.h>\n #include <iomanip>\n@@ -1669,12 +1670,54 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \tbuffer->metadata_.timestamp = buf.timestamp.tv_sec * 1000000000ULL\n \t\t\t\t    + buf.timestamp.tv_usec * 1000ULL;\n \n-\tbuffer->metadata_.planes.clear();\n-\tif (multiPlanar) {\n-\t\tfor (unsigned int nplane = 0; nplane < buf.length; nplane++)\n-\t\t\tbuffer->metadata_.planes.push_back({ planes[nplane].bytesused });\n+\tif (V4L2_TYPE_IS_OUTPUT(buf.type))\n+\t\treturn buffer;\n+\n+\tunsigned int numV4l2Planes = multiPlanar ? buf.length : 1;\n+\tFrameMetadata &metadata = buffer->metadata_;\n+\tmetadata.planes.clear();\n+\n+\tif (numV4l2Planes != buffer->planes().size()) {\n+\t\t/*\n+\t\t * If we have a multi-planar buffer with a V4L2\n+\t\t * single-planar format, split the V4L2 buffer across\n+\t\t * the buffer planes. Only the last plane may have less\n+\t\t * bytes used than its length.\n+\t\t */\n+\t\tif (numV4l2Planes != 1) {\n+\t\t\tLOG(V4L2, Error)\n+\t\t\t\t<< \"Invalid number of planes (\" << numV4l2Planes\n+\t\t\t\t<< \" != \" << buffer->planes().size() << \")\";\n+\n+\t\t\tmetadata.status = FrameMetadata::FrameError;\n+\t\t\treturn buffer;\n+\t\t}\n+\n+\t\tunsigned int bytesused = multiPlanar ? planes[0].bytesused\n+\t\t\t\t       : buf.bytesused;\n+\n+\t\tfor (auto [i, plane] : utils::enumerate(buffer->planes())) {\n+\t\t\tif (!bytesused) {\n+\t\t\t\tLOG(V4L2, Error)\n+\t\t\t\t\t<< \"Dequeued buffer is too small\";\n+\n+\t\t\t\tmetadata.status = FrameMetadata::FrameError;\n+\t\t\t\treturn buffer;\n+\t\t\t}\n+\n+\t\t\tmetadata.planes.push_back({ std::min(plane.length, bytesused) });\n+\t\t\tbytesused -= metadata.planes.back().bytesused;\n+\t\t}\n+\t} else if (multiPlanar) {\n+\t\t/*\n+\t\t * If we use the multi-planar API, fill in the planes.\n+\t\t * The number of planes in the frame buffer and in the\n+\t\t * V4L2 buffer is guaranteed to be equal at this point.\n+\t\t */\n+\t\tfor (unsigned int i = 0; i < numV4l2Planes; ++i)\n+\t\t\tmetadata.planes.push_back({ planes[i].bytesused });\n \t} else {\n-\t\tbuffer->metadata_.planes.push_back({ buf.bytesused });\n+\t\tmetadata.planes.push_back({ buf.bytesused });\n \t}\n \n \treturn buffer;\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "14/30"
    ]
}