Patch Detail
Show a patch.
GET /api/1.1/patches/2289/?format=api
{ "id": 2289, "url": "https://patchwork.libcamera.org/api/1.1/patches/2289/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2289/", "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": "<20191028110208.15751-7-laurent.pinchart@ideasonboard.com>", "date": "2019-10-28T11:02:07", "name": "[libcamera-devel,v2,6/7] libcamera: v4l2_videodevice: Add PixelFormat conversion", "commit_ref": "2a8bf04227811b29bc94b942e78f1567afd8874b", "pull_url": null, "state": "accepted", "archived": false, "hash": "3c8087053454892a5b9266b9e855d834a54b3179", "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/2289/mbox/", "series": [ { "id": 564, "url": "https://patchwork.libcamera.org/api/1.1/series/564/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=564", "date": "2019-10-28T11:02:01", "name": "libcamera: Introduce a PixelFormat type", "version": 2, "mbox": "https://patchwork.libcamera.org/series/564/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2289/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2289/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F23F361508\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Oct 2019 12:02:20 +0100 (CET)", "from pendragon.ideasonboard.com (unknown [91.217.168.176])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 83BBB9C2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Oct 2019 12:02:20 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1572260540;\n\tbh=d95E9L3Zcoo5XYlEyewaY0SpoiMkYACyDbXH41Mkz+0=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=ToXVQvMFkBdVekUKjrX9THzbiX7sjdFgTVc9sk0Xygc858PTfhEVsnebtlQpb6XFG\n\tMsagE6gFFiht6OU8JN7uWm4kpNCnsi63+M0s/IgGgR3CG3GkEEWeFjZcB/UO4g69Ii\n\t+Egb+sp3j26GUphk/zI8o4+TZYiIcfN9o9VavWhM=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 28 Oct 2019 13:02:07 +0200", "Message-Id": "<20191028110208.15751-7-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.23.0", "In-Reply-To": "<20191028110208.15751-1-laurent.pinchart@ideasonboard.com>", "References": "<20191028110208.15751-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 6/7] libcamera: v4l2_videodevice: Add\n\tPixelFormat conversion", "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>", "X-List-Received-Date": "Mon, 28 Oct 2019 11:02:22 -0000" }, "content": "From: Jacopo Mondi <jacopo@jmondi.org>\n\nIn preparation for switching PixelFormat to DRM pixel formats, add\nhelper methods to the V4L2VideoDevice class to translate between DRM\npixel formats and V4L2 pixel formats.\n\nMore work is needed to properly suppor the V4L2 multi-planar (NV[0-9]*M)\nformats.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/v4l2_videodevice.h | 5 +\n src/libcamera/v4l2_videodevice.cpp | 141 +++++++++++++++++++++++\n 2 files changed, 146 insertions(+)", "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex 4b8cf9394eb9..fdf11b3a6ec9 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -13,6 +13,7 @@\n #include <linux/videodev2.h>\n \n #include <libcamera/geometry.h>\n+#include <libcamera/pixelformats.h>\n #include <libcamera/signal.h>\n \n #include \"formats.h\"\n@@ -155,6 +156,10 @@ public:\n \tstatic V4L2VideoDevice *fromEntityName(const MediaDevice *media,\n \t\t\t\t\t const std::string &entity);\n \n+\tstatic PixelFormat toPixelFormat(uint32_t v4l2Fourcc);\n+\tuint32_t toV4L2Fourcc(PixelFormat pixelFormat);\n+\tstatic uint32_t toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar);\n+\n protected:\n \tstd::string logPrefix() const;\n \ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 208ab54199b1..3f2dc2799796 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -17,6 +17,8 @@\n #include <unistd.h>\n #include <vector>\n \n+#include <linux/drm_fourcc.h>\n+\n #include <libcamera/buffer.h>\n #include <libcamera/event_notifier.h>\n \n@@ -1234,6 +1236,145 @@ V4L2VideoDevice *V4L2VideoDevice::fromEntityName(const MediaDevice *media,\n \treturn new V4L2VideoDevice(mediaEntity);\n }\n \n+/**\n+ * \\brief Convert a \\a v4l2Fourcc to the corresponding PixelFormat\n+ * \\param[in] v4l2Fourcc The V4L2 pixel format (V4L2_PIX_FORMAT_*)\n+ * \\return The PixelFormat corresponding to \\a v4l2Fourcc\n+ */\n+PixelFormat V4L2VideoDevice::toPixelFormat(uint32_t v4l2Fourcc)\n+{\n+\tswitch (v4l2Fourcc) {\n+\t/* RGB formats. */\n+\tcase V4L2_PIX_FMT_RGB24:\n+\t\treturn DRM_FORMAT_BGR888;\n+\tcase V4L2_PIX_FMT_BGR24:\n+\t\treturn DRM_FORMAT_RGB888;\n+\tcase V4L2_PIX_FMT_ARGB32:\n+\t\treturn DRM_FORMAT_BGRA8888;\n+\n+\t/* YUV packed formats. */\n+\tcase V4L2_PIX_FMT_YUYV:\n+\t\treturn DRM_FORMAT_YUYV;\n+\tcase V4L2_PIX_FMT_YVYU:\n+\t\treturn DRM_FORMAT_YVYU;\n+\tcase V4L2_PIX_FMT_UYVY:\n+\t\treturn DRM_FORMAT_UYVY;\n+\tcase V4L2_PIX_FMT_VYUY:\n+\t\treturn DRM_FORMAT_VYUY;\n+\n+\t/* YUY planar formats. */\n+\tcase V4L2_PIX_FMT_NV16:\n+\tcase V4L2_PIX_FMT_NV16M:\n+\t\treturn DRM_FORMAT_NV16;\n+\tcase V4L2_PIX_FMT_NV61:\n+\tcase V4L2_PIX_FMT_NV61M:\n+\t\treturn DRM_FORMAT_NV61;\n+\tcase V4L2_PIX_FMT_NV12:\n+\tcase V4L2_PIX_FMT_NV12M:\n+\t\treturn DRM_FORMAT_NV12;\n+\tcase V4L2_PIX_FMT_NV21:\n+\tcase V4L2_PIX_FMT_NV21M:\n+\t\treturn DRM_FORMAT_NV21;\n+\n+\t/* Compressed formats. */\n+\tcase V4L2_PIX_FMT_MJPEG:\n+\t\treturn DRM_FORMAT_MJPEG;\n+\n+\t/* V4L2 formats not yet supported by DRM. */\n+\tcase V4L2_PIX_FMT_GREY:\n+\tdefault:\n+\t\t/*\n+\t\t * \\todo We can't use LOG() in a static method of a Loggable\n+\t\t * class. Until we fix the logger, work around it.\n+\t\t */\n+\t\tlibcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(),\n+\t\t\t\tLogError).stream()\n+\t\t\t<< \"Unsupported V4L2 pixel format \"\n+\t\t\t<< utils::hex(v4l2Fourcc);\n+\t\treturn 0;\n+\t}\n+}\n+\n+/**\n+ * \\brief Convert \\a PixelFormat to its corresponding V4L2 FourCC\n+ * \\param[in] pixelFormat The PixelFormat to convert\n+ *\n+ * For multiplanar formats, the V4L2 format variant (contiguous or\n+ * non-contiguous planes) is selected automatically based on the capabilities\n+ * of the video device. If the video device supports the V4L2 multiplanar API,\n+ * non-contiguous formats are preferred.\n+ *\n+ * \\return The V4L2_PIX_FMT_* pixel format code corresponding to \\a pixelFormat\n+ */\n+uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat)\n+{\n+\treturn V4L2VideoDevice::toV4L2Fourcc(pixelFormat, caps_.isMultiplanar());\n+}\n+\n+/**\n+ * \\brief Convert \\a pixelFormat to its corresponding V4L2 FourCC\n+ * \\param[in] pixelFormat The PixelFormat to convert\n+ * \\param[in] multiplanar V4L2 Multiplanar API support flag\n+ *\n+ * Multiple V4L2 formats may exist for one PixelFormat when the format uses\n+ * multiple planes, as V4L2 defines separate 4CCs for contiguous and separate\n+ * planes formats. Set the \\a multiplanar parameter to false to select a format\n+ * with contiguous planes, or to true to select a format with non-contiguous\n+ * planes.\n+ *\n+ * \\return The V4L2_PIX_FMT_* pixel format code corresponding to \\a pixelFormat\n+ */\n+uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar)\n+{\n+\tswitch (pixelFormat) {\n+\t/* RGB formats. */\n+\tcase DRM_FORMAT_BGR888:\n+\t\treturn V4L2_PIX_FMT_RGB24;\n+\tcase DRM_FORMAT_RGB888:\n+\t\treturn V4L2_PIX_FMT_BGR24;\n+\tcase DRM_FORMAT_BGRA8888:\n+\t\treturn V4L2_PIX_FMT_ARGB32;\n+\n+\t/* YUV packed formats. */\n+\tcase DRM_FORMAT_YUYV:\n+\t\treturn V4L2_PIX_FMT_YUYV;\n+\tcase DRM_FORMAT_YVYU:\n+\t\treturn V4L2_PIX_FMT_YVYU;\n+\tcase DRM_FORMAT_UYVY:\n+\t\treturn V4L2_PIX_FMT_UYVY;\n+\tcase DRM_FORMAT_VYUY:\n+\t\treturn V4L2_PIX_FMT_VYUY;\n+\n+\t/*\n+\t * YUY planar formats.\n+\t * \\todo Add support for non-contiguous memory planes\n+\t * \\todo Select the format variant not only based on \\a multiplanar but\n+\t * also take into account the formats supported by the device.\n+\t */\n+\tcase DRM_FORMAT_NV16:\n+\t\treturn V4L2_PIX_FMT_NV16;\n+\tcase DRM_FORMAT_NV61:\n+\t\treturn V4L2_PIX_FMT_NV61;\n+\tcase DRM_FORMAT_NV12:\n+\t\treturn V4L2_PIX_FMT_NV12;\n+\tcase DRM_FORMAT_NV21:\n+\t\treturn V4L2_PIX_FMT_NV21;\n+\n+\t/* Compressed formats. */\n+\tcase DRM_FORMAT_MJPEG:\n+\t\treturn V4L2_PIX_FMT_MJPEG;\n+\t}\n+\n+\t/*\n+\t * \\todo We can't use LOG() in a static method of a Loggable\n+\t * class. Until we fix the logger, work around it.\n+\t */\n+\tlibcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(), LogError).stream()\n+\t\t<< \"Unsupported V4L2 pixel format \"\n+\t\t<< utils::hex(pixelFormat);\n+\treturn 0;\n+}\n+\n /**\n * \\class V4L2M2MDevice\n * \\brief Memory-to-Memory video device\n", "prefixes": [ "libcamera-devel", "v2", "6/7" ] }