Show a patch.

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

{
    "id": 11177,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/11177/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11177/",
    "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": "<20210205131044.512128-4-helen.koike@collabora.com>",
    "date": "2021-02-05T13:10:44",
    "name": "[libcamera-devel,RFC,3/3] libcamera: Use VIDIOC_EXT_(D)QBUF for buffer handling",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "93d9bb35495dd728da52c444773014c6e1106fcf",
    "submitter": {
        "id": 20,
        "url": "https://patchwork.libcamera.org/api/1.1/people/20/?format=api",
        "name": "Helen Koike",
        "email": "helen.koike@collabora.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11177/mbox/",
    "series": [
        {
            "id": 1657,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1657/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1657",
            "date": "2021-02-05T13:10:41",
            "name": "libcamera: Use extended fmt and buffer ioctls API",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1657/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11177/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11177/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 A3BADBD162\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 Feb 2021 13:11:07 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7E8F1614BA;\n\tFri,  5 Feb 2021 14:11:07 +0100 (CET)",
            "from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 33D69614B0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Feb 2021 14:11:06 +0100 (CET)",
            "from [127.0.0.1] (localhost [127.0.0.1])\n\t(Authenticated sender: koike) with ESMTPSA id 88BF21F466AD"
        ],
        "From": "Helen Koike <helen.koike@collabora.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  5 Feb 2021 10:10:44 -0300",
        "Message-Id": "<20210205131044.512128-4-helen.koike@collabora.com>",
        "X-Mailer": "git-send-email 2.30.0",
        "In-Reply-To": "<20210205131044.512128-1-helen.koike@collabora.com>",
        "References": "<20210205131044.512128-1-helen.koike@collabora.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [RFC PATCH 3/3] libcamera: Use VIDIOC_EXT_(D)QBUF\n\tfor buffer handling",
        "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>",
        "Cc": "kieran.bingham+renesas@ideasonboard.com, frkoenig@chromium.org,\n\tkernel@collabora.com",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Use Ext API for buffer handling.\nAllow memory buffers to be defined per color component.\n\nSigned-off-by: Helen Koike <helen.koike@collabora.com>\n---\n src/libcamera/v4l2_videodevice.cpp | 75 ++++++++++++------------------\n src/v4l2/v4l2_camera_proxy.cpp     | 20 ++++----\n 2 files changed, 41 insertions(+), 54 deletions(-)",
    "diff": "diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex fab3ba4c..0a724266 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -141,7 +141,7 @@ LOG_DECLARE_CATEGORY(V4L2)\n  * \\brief Hot cache of associations between V4L2 buffer indexes and FrameBuffer\n  *\n  * When importing buffers, V4L2 performs lazy mapping of dmabuf instances at\n- * VIDIOC_QBUF (or VIDIOC_PREPARE_BUF) time and keeps the mapping associated\n+ * VIDIOC_EXT_QBUF (or VIDIOC_PREPARE_BUF) time and keeps the mapping associated\n  * with the V4L2 buffer, as identified by its index. If the same V4L2 buffer is\n  * then reused and queued with different dmabufs, the old dmabufs will be\n  * unmapped and the new ones mapped. To keep this process efficient, it is\n@@ -1315,8 +1315,8 @@ int V4L2VideoDevice::releaseBuffers()\n  */\n int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n {\n-\tstruct v4l2_plane v4l2Planes[VIDEO_MAX_PLANES] = {};\n-\tstruct v4l2_buffer buf = {};\n+\tV4L2DeviceFormat format;\n+\tstruct v4l2_ext_buffer buf = {};\n \tint ret;\n \n \tret = cache_->get(*buffer);\n@@ -1328,46 +1328,46 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)\n \tbuf.memory = memoryType_;\n \tbuf.field = V4L2_FIELD_NONE;\n \n-\tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\n \tconst std::vector<FrameBuffer::Plane> &planes = buffer->planes();\n \n+\tret = getFormat(&format);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n \tif (buf.memory == V4L2_MEMORY_DMABUF) {\n-\t\tif (multiPlanar) {\n-\t\t\tfor (unsigned int p = 0; p < planes.size(); ++p)\n-\t\t\t\tv4l2Planes[p].m.fd = planes[p].fd.fd();\n+\t\t/*\n+\t\t * If there is a single memory plane, fill color planes with\n+\t\t * the same dmabuf fd but on a different offset\n+\t\t */\n+\t\tif (planes.size() == 1) {\n+\t\t\tbuf.planes[0].m.dmabuf_fd = planes[0].fd.fd();\n+\t\t\tfor (unsigned int p = 1;\n+\t\t\t     p < format.planes.size() && format.planes[p].size; ++p) {\n+\t\t\t\tbuf.planes[p].m.dmabuf_fd = planes[0].fd.fd();\n+\t\t\t\tbuf.planes[p].offset = format.planes[p - 1].size;\n+\t\t\t}\n \t\t} else {\n-\t\t\tbuf.m.fd = planes[0].fd.fd();\n+\t\t\tfor (unsigned int p = 0; p < planes.size(); ++p)\n+\t\t\t\tbuf.planes[p].m.dmabuf_fd = planes[p].fd.fd();\n \t\t}\n \t}\n \n-\tif (multiPlanar) {\n-\t\tbuf.length = planes.size();\n-\t\tbuf.m.planes = v4l2Planes;\n-\t}\n-\n \tif (V4L2_TYPE_IS_OUTPUT(buf.type)) {\n \t\tconst FrameMetadata &metadata = buffer->metadata();\n+\t\tunsigned int nplane = 0;\n \n-\t\tif (multiPlanar) {\n-\t\t\tunsigned int nplane = 0;\n-\t\t\tfor (const FrameMetadata::Plane &plane : metadata.planes) {\n-\t\t\t\tv4l2Planes[nplane].bytesused = plane.bytesused;\n-\t\t\t\tv4l2Planes[nplane].length = buffer->planes()[nplane].length;\n-\t\t\t\tnplane++;\n-\t\t\t}\n-\t\t} else {\n-\t\t\tif (metadata.planes.size())\n-\t\t\t\tbuf.bytesused = metadata.planes[0].bytesused;\n+\t\tfor (const FrameMetadata::Plane &plane : metadata.planes) {\n+\t\t\tbuf.planes[nplane].bytesused = plane.bytesused;\n+\t\t\tnplane++;\n \t\t}\n \n \t\tbuf.sequence = metadata.sequence;\n-\t\tbuf.timestamp.tv_sec = metadata.timestamp / 1000000000;\n-\t\tbuf.timestamp.tv_usec = (metadata.timestamp / 1000) % 1000000;\n+\t\tbuf.timestamp = metadata.timestamp;\n \t}\n \n \tLOG(V4L2, Debug) << \"Queueing buffer \" << buf.index;\n \n-\tret = ioctl(VIDIOC_QBUF, &buf);\n+\tret = ioctl(VIDIOC_EXT_QBUF, &buf);\n \tif (ret < 0) {\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to queue buffer \" << buf.index << \": \"\n@@ -1413,21 +1413,13 @@ void V4L2VideoDevice::bufferAvailable([[maybe_unused]] EventNotifier *notifier)\n  */\n FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n {\n-\tstruct v4l2_buffer buf = {};\n-\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n+\tstruct v4l2_ext_buffer buf = {};\n \tint ret;\n \n \tbuf.type = bufferType_;\n \tbuf.memory = memoryType_;\n \n-\tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\n-\n-\tif (multiPlanar) {\n-\t\tbuf.length = VIDEO_MAX_PLANES;\n-\t\tbuf.m.planes = planes;\n-\t}\n-\n-\tret = ioctl(VIDIOC_DQBUF, &buf);\n+\tret = ioctl(VIDIOC_EXT_DQBUF, &buf);\n \tif (ret < 0) {\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to dequeue buffer: \" << strerror(-ret);\n@@ -1449,16 +1441,11 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \t\t\t\t ? FrameMetadata::FrameError\n \t\t\t\t : FrameMetadata::FrameSuccess;\n \tbuffer->metadata_.sequence = buf.sequence;\n-\tbuffer->metadata_.timestamp = buf.timestamp.tv_sec * 1000000000ULL\n-\t\t\t\t    + buf.timestamp.tv_usec * 1000ULL;\n+\tbuffer->metadata_.timestamp = buf.timestamp;\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-\t} else {\n-\t\tbuffer->metadata_.planes.push_back({ buf.bytesused });\n-\t}\n+\tfor (unsigned int nplane = 0; buf.planes[nplane].bytesused; nplane++)\n+\t\tbuffer->metadata_.planes.push_back({ buf.planes[nplane].bytesused });\n \n \treturn buffer;\n }\ndiff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex f8bfe595..32fed4b8 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -544,9 +544,9 @@ int V4L2CameraProxy::vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *a\n \treturn 0;\n }\n \n-int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg)\n+int V4L2CameraProxy::vidioc_ext_qbuf(V4L2CameraFile *file, struct v4l2_ext_buffer *arg)\n {\n-\tLOG(V4L2Compat, Debug) << \"Servicing vidioc_qbuf, index = \"\n+\tLOG(V4L2Compat, Debug) << \"Servicing vidioc_ext_qbuf, index = \"\n \t\t\t       << arg->index << \" fd = \" << file->efd();\n \n \tif (arg->index >= bufferCount_)\n@@ -574,8 +574,8 @@ int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg)\n \treturn ret;\n }\n \n-int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg,\n-\t\t\t\t  MutexLocker *locker)\n+int V4L2CameraProxy::vidioc_ext_dqbuf(V4L2CameraFile *file, struct v4l2_ext_buffer *arg,\n+\t\t\t\t      MutexLocker *locker)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing vidioc_dqbuf fd = \" << file->efd();\n \n@@ -683,8 +683,8 @@ const std::set<unsigned long> V4L2CameraProxy::supportedIoctls_ = {\n \tVIDIOC_S_INPUT,\n \tVIDIOC_REQBUFS,\n \tVIDIOC_QUERYBUF,\n-\tVIDIOC_QBUF,\n-\tVIDIOC_DQBUF,\n+\tVIDIOC_EXT_QBUF,\n+\tVIDIOC_EXT_DQBUF,\n \tVIDIOC_STREAMON,\n \tVIDIOC_STREAMOFF,\n };\n@@ -749,11 +749,11 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar\n \tcase VIDIOC_QUERYBUF:\n \t\tret = vidioc_querybuf(file, static_cast<struct v4l2_buffer *>(arg));\n \t\tbreak;\n-\tcase VIDIOC_QBUF:\n-\t\tret = vidioc_qbuf(file, static_cast<struct v4l2_buffer *>(arg));\n+\tcase VIDIOC_EXT_QBUF:\n+\t\tret = vidioc_ext_qbuf(file, static_cast<struct v4l2_ext_buffer *>(arg));\n \t\tbreak;\n-\tcase VIDIOC_DQBUF:\n-\t\tret = vidioc_dqbuf(file, static_cast<struct v4l2_buffer *>(arg), &locker);\n+\tcase VIDIOC_EXT_DQBUF:\n+\t\tret = vidioc_ext_dqbuf(file, static_cast<struct v4l2_ext_buffer *>(arg), &locker);\n \t\tbreak;\n \tcase VIDIOC_STREAMON:\n \t\tret = vidioc_streamon(file, static_cast<int *>(arg));\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "3/3"
    ]
}