Patch Detail
Show a patch.
GET /api/patches/13530/?format=api
{ "id": 13530, "url": "https://patchwork.libcamera.org/api/patches/13530/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13530/", "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": "<20210827064439.879308-1-hiroh@chromium.org>", "date": "2021-08-27T06:44:39", "name": "[libcamera-devel,v4,7/9] libcamera: v4l2_videodevice: Create color-format planes in createBuffer()", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "059cf8bb4c851f3df8cd66e6f762b999ca41b574", "submitter": { "id": 63, "url": "https://patchwork.libcamera.org/api/people/63/?format=api", "name": "Hirokazu Honda", "email": "hiroh@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13530/mbox/", "series": [ { "id": 2404, "url": "https://patchwork.libcamera.org/api/series/2404/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2404", "date": "2021-08-27T06:44:39", "name": null, "version": 4, "mbox": "https://patchwork.libcamera.org/series/2404/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13530/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13530/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 071A9BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Aug 2021 06:44:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4703D68932;\n\tFri, 27 Aug 2021 08:44:47 +0200 (CEST)", "from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com\n\t[IPv6:2607:f8b0:4864:20::42c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 96B7160288\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Aug 2021 08:44:46 +0200 (CEST)", "by mail-pf1-x42c.google.com with SMTP id s29so54823pfw.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 23:44:46 -0700 (PDT)", "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:e14c:e27b:81d2:aa99])\n\tby smtp.gmail.com with ESMTPSA id\n\tu20sm5499885pgm.4.2021.08.26.23.44.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 26 Aug 2021 23:44:44 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"ZmD0BJo+\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; h=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=+DtX14Bn2/Cfefny+vTtcaYWQ1ERk0zFfOXH+PSH7gc=;\n\tb=ZmD0BJo+WbQAd5Mwx+rbc9QG2Hip/KugDnBNohEdB0dJIN6X3rzc7BGOqgnNO1PjTw\n\tpCehCvYfeGUwezy2uHO9h8JqM9DOiTyvSjHpoNl4Mkk+wj6r/3+R/VLHu9IUxcwc1zt2\n\tTFHNBpwPHPl2gZihEeuUh/kPz8f1f2vgdD8Wk=", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=+DtX14Bn2/Cfefny+vTtcaYWQ1ERk0zFfOXH+PSH7gc=;\n\tb=A/fp/V4YXLT+mlZTg+W24mWJ4ybp2MqpRhKerfkBrWyLreWFu0LuBcFZ1h9Fce+fkM\n\tujj7UObq8CdY1yVuAPJTwSSdLf3Ahb+XjWNe+Oq6cdNqeitdfPsMwf8vpsyWfymp/DBL\n\t74AHDV8iRjiRv8XGi6c5U7pWokIclcRfFtm9HV4iI94tdn2YNVXjNhbKt9YwtWGHrKzq\n\tt7BxQOJ14+H79snUCLY6xtPLjfVOgyGXW/F5MVHagFAM8M9tDqLInYVMmjqrtuotuDdz\n\tU1SSJJ/4ea8rTD9fnjy1l0CDkEo3rI3xbL/EWOoYURq+1p+YBXsL19uE6eSOWaqGyoY5\n\tfsCQ==", "X-Gm-Message-State": "AOAM530pzBtocORI1Y/O2qvo5MGAhvJKa7qCAGxfNWo4ssTVaYRy6/f3\n\t9+QCKxZQtKdzU/myjxww8TvJXQmK1jYQ4w==", "X-Google-Smtp-Source": "ABdhPJxDrO5cCqqBq8qvsIkfJukSTIFElf1j+65YtsNKQKQonQSc4grkpKuBs+4mXjDVDCyXZsAVtw==", "X-Received": "by 2002:a62:ab01:0:b0:3f2:89dc:aa8d with SMTP id\n\tp1-20020a62ab01000000b003f289dcaa8dmr2597772pff.20.1630046684530; \n\tThu, 26 Aug 2021 23:44:44 -0700 (PDT)", "From": "Hirokazu Honda <hiroh@chromium.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 27 Aug 2021 15:44:39 +0900", "Message-Id": "<20210827064439.879308-1-hiroh@chromium.org>", "X-Mailer": "git-send-email 2.33.0.259.gc128427fd7-goog", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 7/9] libcamera: v4l2_videodevice:\n\tCreate color-format planes in createBuffer()", "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": "V4L2VideDevice::createBuffer() creates the same number of\nFrameBuffer::Planes as V4L2 format planes. Therefore, if the v4l2\nformat single is single-planar format, the created number of\nFrameBuffer::Planes is 1.\nIt should rather create the same number of FrameBuffer::Planes as the\ncolor format planes.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n\n---\n\nLet me send this patch only in v4.\n\n---\n include/libcamera/internal/v4l2_videodevice.h | 1 +\n src/libcamera/v4l2_videodevice.cpp | 69 ++++++++++++++++---\n 2 files changed, 61 insertions(+), 9 deletions(-)\n\n--\n2.33.0.259.gc128427fd7-goog", "diff": "diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex e767ec84..4a5d2cad 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -242,6 +242,7 @@ private:\n \tFrameBuffer *dequeueBuffer();\n\n \tV4L2Capability caps_;\n+\tV4L2DeviceFormat format_;\n\n \tenum v4l2_buf_type bufferType_;\n \tenum v4l2_memory memoryType_;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 2ff25af2..9d35618d 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -25,6 +25,7 @@\n\n #include <libcamera/file_descriptor.h>\n\n+#include \"libcamera/internal/formats.h\"\n #include \"libcamera/internal/media_device.h\"\n #include \"libcamera/internal/media_object.h\"\n\n@@ -579,6 +580,12 @@ int V4L2VideoDevice::open()\n \t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n \t\t<< caps_.driver() << \": \" << caps_.card();\n\n+\tret = getFormat(&format_);\n+\tif (ret) {\n+\t\tLOG(V4L2, Error) << \"Failed to get format\";\n+\t\treturn ret;\n+\t}\n+\n \treturn 0;\n }\n\n@@ -668,6 +675,12 @@ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type)\n \t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n \t\t<< caps_.driver() << \": \" << caps_.card();\n\n+\tret = getFormat(&format_);\n+\tif (ret) {\n+\t\tLOG(V4L2, Error) << \"Failed to get format\";\n+\t\treturn ret;\n+\t}\n+\n \treturn 0;\n }\n\n@@ -761,12 +774,20 @@ int V4L2VideoDevice::tryFormat(V4L2DeviceFormat *format)\n */\n int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format)\n {\n+\tint ret = 0;\n \tif (caps_.isMeta())\n-\t\treturn trySetFormatMeta(format, true);\n+\t\tret = trySetFormatMeta(format, true);\n \telse if (caps_.isMultiplanar())\n-\t\treturn trySetFormatMultiplane(format, true);\n+\t\tret = trySetFormatMultiplane(format, true);\n \telse\n-\t\treturn trySetFormatSingleplane(format, true);\n+\t\tret = trySetFormatSingleplane(format, true);\n+\n+\t/* Cache the set format on success. */\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tformat_ = *format;\n+\treturn 0;\n }\n\n int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n@@ -1152,8 +1173,13 @@ int V4L2VideoDevice::requestBuffers(unsigned int count,\n * successful return the driver's internal buffer management is initialized in\n * MMAP mode, and the video device is ready to accept queueBuffer() calls.\n *\n- * The number of planes and the plane sizes for the allocation are determined\n- * by the currently active format on the device as set by setFormat().\n+ * The number of planes and their offsets and sizes are determined by the\n+ * currently active format on the device as set by setFormat(). They do not map\n+ * to the V4L2 buffer planes, but to colour planes of the pixel format. For\n+ * instance, if the active format is formats::NV12, the allocated FrameBuffer\n+ * instances will have two planes, for the luma and chroma components,\n+ * regardless of whether the device uses V4L2_PIX_FMT_NV12 or\n+ * V4L2_PIX_FMT_NV12M.\n *\n * Buffers allocated with this function shall later be free with\n * releaseBuffers(). If buffers have already been allocated with\n@@ -1190,8 +1216,13 @@ int V4L2VideoDevice::allocateBuffers(unsigned int count,\n * usable with any V4L2 video device in DMABUF mode, or with other dmabuf\n * importers.\n *\n- * The number of planes and the plane sizes for the allocation are determined\n- * by the currently active format on the device as set by setFormat().\n+ * The number of planes and their offsets and sizes are determined by the\n+ * currently active format on the device as set by setFormat(). They do not map\n+ * to the V4L2 buffer planes, but to colour planes of the pixel format. For\n+ * instance, if the active format is formats::NV12, the allocated FrameBuffer\n+ * instances will have two planes, for the luma and chroma components,\n+ * regardless of whether the device uses V4L2_PIX_FMT_NV12 or\n+ * V4L2_PIX_FMT_NV12M.\n *\n * Multiple independent sets of buffers can be allocated with multiple calls to\n * this function. Device-specific limitations may apply regarding the minimum\n@@ -1289,12 +1320,32 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n \t\t * \\todo Set the right offset once V4L2 API provides a way.\n \t\t */\n \t\tplane.offset = 0;\n-\t\tplane.length = multiPlanar ?\n-\t\t\tbuf.m.planes[nplane].length : buf.length;\n+\t\tplane.length = multiPlanar ? buf.m.planes[nplane].length : buf.length;\n\n \t\tplanes.push_back(std::move(plane));\n \t}\n\n+\tconst auto &info = PixelFormatInfo::info(format_.fourcc);\n+\tif (info.isValid() && info.numPlanes() != numPlanes) {\n+\t\tASSERT(numPlanes == 1u);\n+\t\tconst size_t numColorPlanes = info.numPlanes();\n+\t\tplanes.resize(numColorPlanes);\n+\t\tconst FileDescriptor &fd = planes[0].fd;\n+\t\tsize_t offset = 0;\n+\t\tfor (size_t i = 0; i < numColorPlanes; ++i) {\n+\t\t\tplanes[i].fd = fd;\n+\t\t\tplanes[i].offset = offset;\n+\n+\t\t\t/* \\todo Take the V4L2 stride into account */\n+\t\t\tconst unsigned int vertSubSample =\n+\t\t\t\tinfo.planes[i].verticalSubSampling;\n+\t\t\tplanes[i].length =\n+\t\t\t\tinfo.stride(format_.size.width, i, 1u) *\n+\t\t\t\t((format_.size.height + vertSubSample - 1) / vertSubSample);\n+\t\t\toffset += planes[i].length;\n+\t\t}\n+\t}\n+\n \treturn std::make_unique<FrameBuffer>(std::move(planes));\n }\n\n", "prefixes": [ "libcamera-devel", "v4", "7/9" ] }