{"id":3627,"url":"https://patchwork.libcamera.org/api/1.1/patches/3627/?format=json","web_url":"https://patchwork.libcamera.org/patch/3627/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200430030723.8908-2-laurent.pinchart@ideasonboard.com>","date":"2020-04-30T03:07:18","name":"[libcamera-devel,v2,1/6] libcamera: v4l2_pixelformat: Move V4L2PixelFormat to a new file","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9acbcbf612bcd608db8359d16b873bc276d3f506","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3627/mbox/","series":[{"id":858,"url":"https://patchwork.libcamera.org/api/1.1/series/858/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=858","date":"2020-04-30T03:07:17","name":"libcamera: Improve conversion between DRM and V4L2 formats","version":2,"mbox":"https://patchwork.libcamera.org/series/858/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3627/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3627/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 47655613F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 05:07:28 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C911072C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 05:07:27 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"b+DeUSBe\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588216047;\n\tbh=2078x2Dxc4mWcYrGEoswjkiES9YjkZaknzyImmycANE=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=b+DeUSBeo9RMIEFuleREAf95RaOiqBmVkisuDZT71h39wg/doJ7W5bvtKPNIpzJrR\n\t5lgyXt/iaNHDsD8HuBy2jLYqDB3J1+HZ2FAPRCsK7ccPEiamkDd6c2WgqqXlcWypBA\n\tAxCps0MBftdp/9R+8M6hpQhcyQsW54T5WcdXNlak=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 30 Apr 2020 06:07:18 +0300","Message-Id":"<20200430030723.8908-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.25.3","In-Reply-To":"<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>","References":"<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/6] libcamera: v4l2_pixelformat: Move\n\tV4L2PixelFormat to a new file","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":"Thu, 30 Apr 2020 03:07:28 -0000"},"content":"Move the V4L2PixelFormat class to a new file to prepare for additional\nchanges that will make it grow. No functional modification is included.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/meson.build        |   1 +\n src/libcamera/include/v4l2_pixelformat.h |  45 ++++++++++\n src/libcamera/include/v4l2_videodevice.h |  24 +----\n src/libcamera/meson.build                |   1 +\n src/libcamera/v4l2_pixelformat.cpp       | 106 +++++++++++++++++++++++\n src/libcamera/v4l2_videodevice.cpp       |  77 ----------------\n 6 files changed, 154 insertions(+), 100 deletions(-)\n create mode 100644 src/libcamera/include/v4l2_pixelformat.h\n create mode 100644 src/libcamera/v4l2_pixelformat.cpp","diff":"diff --git a/src/libcamera/include/meson.build b/src/libcamera/include/meson.build\nindex 5aaa99472e4a..683d06133741 100644\n--- a/src/libcamera/include/meson.build\n+++ b/src/libcamera/include/meson.build\n@@ -27,6 +27,7 @@ libcamera_headers = files([\n     'utils.h',\n     'v4l2_controls.h',\n     'v4l2_device.h',\n+    'v4l2_pixelformat.h',\n     'v4l2_subdevice.h',\n     'v4l2_videodevice.h',\n ])\ndiff --git a/src/libcamera/include/v4l2_pixelformat.h b/src/libcamera/include/v4l2_pixelformat.h\nnew file mode 100644\nindex 000000000000..4d277569cb8c\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_pixelformat.h\n@@ -0,0 +1,45 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n+ *\n+ * v4l2_pixelformat.h - V4L2 Pixel Format\n+ */\n+#ifndef __LIBCAMERA_V4L2_PIXELFORMAT_H__\n+#define __LIBCAMERA_V4L2_PIXELFORMAT_H__\n+\n+#include <stdint.h>\n+#include <string>\n+\n+#include <linux/videodev2.h>\n+\n+#include <libcamera/pixelformats.h>\n+\n+namespace libcamera {\n+\n+class V4L2PixelFormat\n+{\n+public:\n+\tV4L2PixelFormat()\n+\t\t: fourcc_(0)\n+\t{\n+\t}\n+\n+\texplicit V4L2PixelFormat(uint32_t fourcc)\n+\t\t: fourcc_(fourcc)\n+\t{\n+\t}\n+\n+\tbool isValid() const { return fourcc_ != 0; }\n+\tuint32_t fourcc() const { return fourcc_; }\n+\toperator uint32_t() const { return fourcc_; }\n+\n+\tstd::string toString() const;\n+\n+private:\n+\tuint32_t fourcc_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_V4L2_PIXELFORMAT_H__ */\ndiff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex 976ef9b6dc50..ff64bb357c7e 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -23,6 +23,7 @@\n #include \"formats.h\"\n #include \"log.h\"\n #include \"v4l2_device.h\"\n+#include \"v4l2_pixelformat.h\"\n \n namespace libcamera {\n \n@@ -149,29 +150,6 @@ private:\n \tunsigned int missCounter_;\n };\n \n-class V4L2PixelFormat\n-{\n-public:\n-\tV4L2PixelFormat()\n-\t\t: fourcc_(0)\n-\t{\n-\t}\n-\n-\texplicit V4L2PixelFormat(uint32_t fourcc)\n-\t\t: fourcc_(fourcc)\n-\t{\n-\t}\n-\n-\tbool isValid() const { return fourcc_ != 0; }\n-\tuint32_t fourcc() const { return fourcc_; }\n-\toperator uint32_t() const { return fourcc_; }\n-\n-\tstd::string toString() const;\n-\n-private:\n-\tuint32_t fourcc_;\n-};\n-\n class V4L2DeviceFormat\n {\n public:\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 874d25904693..d8b4d7206aba 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -44,6 +44,7 @@ libcamera_sources = files([\n     'utils.cpp',\n     'v4l2_controls.cpp',\n     'v4l2_device.cpp',\n+    'v4l2_pixelformat.cpp',\n     'v4l2_subdevice.cpp',\n     'v4l2_videodevice.cpp',\n ])\ndiff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\nnew file mode 100644\nindex 000000000000..57d65c380b0d\n--- /dev/null\n+++ b/src/libcamera/v4l2_pixelformat.cpp\n@@ -0,0 +1,106 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n+ *\n+ * v4l2_pixelformat.cpp - V4L2 Pixel Format\n+ */\n+\n+#include \"v4l2_pixelformat.h\"\n+\n+#include <ctype.h>\n+#include <map>\n+#include <string.h>\n+\n+#include <linux/drm_fourcc.h>\n+\n+#include <libcamera/pixelformats.h>\n+\n+#include \"log.h\"\n+\n+/**\n+ * \\file v4l2_pixelformat.h\n+ * \\brief V4L2 Pixel Format\n+ */\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(V4L2)\n+\n+/**\n+ * \\class V4L2PixelFormat\n+ * \\brief V4L2 pixel format FourCC wrapper\n+ *\n+ * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It\n+ * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with\n+ * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n+ * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n+ * compile time.\n+ *\n+ * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n+ * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n+ * explicit value() and implicit uint32_t conversion operators may be used.\n+ */\n+\n+/**\n+ * \\fn V4L2PixelFormat::V4L2PixelFormat()\n+ * \\brief Construct a V4L2PixelFormat with an invalid format\n+ *\n+ * V4L2PixelFormat instances constructed with the default constructor are\n+ * invalid, calling the isValid() function returns false.\n+ */\n+\n+/**\n+ * \\fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc)\n+ * \\brief Construct a V4L2PixelFormat from a FourCC value\n+ * \\param[in] fourcc The pixel format FourCC numerical value\n+ */\n+\n+/**\n+ * \\fn bool V4L2PixelFormat::isValid() const\n+ * \\brief Check if the pixel format is valid\n+ *\n+ * V4L2PixelFormat instances constructed with the default constructor are\n+ * invalid. Instances constructed with a FourCC defined in the V4L2 API are\n+ * valid. The behaviour is undefined otherwise.\n+ *\n+ * \\return True if the pixel format is valid, false otherwise\n+ */\n+\n+/**\n+ * \\fn uint32_t V4L2PixelFormat::fourcc() const\n+ * \\brief Retrieve the pixel format FourCC numerical value\n+ * \\return The pixel format FourCC numerical value\n+ */\n+\n+/**\n+ * \\fn V4L2PixelFormat::operator uint32_t() const\n+ * \\brief Convert to the pixel format FourCC numerical value\n+ * \\return The pixel format FourCC numerical value\n+ */\n+\n+/**\n+ * \\brief Assemble and return a string describing the pixel format\n+ * \\return A string describing the pixel format\n+ */\n+std::string V4L2PixelFormat::toString() const\n+{\n+\tif (fourcc_ == 0)\n+\t\treturn \"<INVALID>\";\n+\n+\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n+\n+\tfor (unsigned int i = 0; i < 4; i++) {\n+\t\tif (!isprint(ss[i]))\n+\t\t\tss[i] = '.';\n+\t}\n+\n+\tif (fourcc_ & (1 << 31))\n+\t\tstrcat(ss, \"-BE\");\n+\n+\treturn ss;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex e8d4f17dfdf1..21df4f524212 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -278,83 +278,6 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n \treturn true;\n }\n \n-/**\n- * \\class V4L2PixelFormat\n- * \\brief V4L2 pixel format FourCC wrapper\n- *\n- * The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It\n- * wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with\n- * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n- * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n- * compile time.\n- *\n- * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n- * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n- * explicit value() and implicit uint32_t conversion operators may be used.\n- */\n-\n-/**\n- * \\fn V4L2PixelFormat::V4L2PixelFormat()\n- * \\brief Construct a V4L2PixelFormat with an invalid format\n- *\n- * V4L2PixelFormat instances constructed with the default constructor are\n- * invalid, calling the isValid() function returns false.\n- */\n-\n-/**\n- * \\fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc)\n- * \\brief Construct a V4L2PixelFormat from a FourCC value\n- * \\param[in] fourcc The pixel format FourCC numerical value\n- */\n-\n-/**\n- * \\fn bool V4L2PixelFormat::isValid() const\n- * \\brief Check if the pixel format is valid\n- *\n- * V4L2PixelFormat instances constructed with the default constructor are\n- * invalid. Instances constructed with a FourCC defined in the V4L2 API are\n- * valid. The behaviour is undefined otherwise.\n- *\n- * \\return True if the pixel format is valid, false otherwise\n- */\n-\n-/**\n- * \\fn uint32_t V4L2PixelFormat::fourcc() const\n- * \\brief Retrieve the pixel format FourCC numerical value\n- * \\return The pixel format FourCC numerical value\n- */\n-\n-/**\n- * \\fn V4L2PixelFormat::operator uint32_t() const\n- * \\brief Convert to the pixel format FourCC numerical value\n- * \\return The pixel format FourCC numerical value\n- */\n-\n-/**\n- * \\brief Assemble and return a string describing the pixel format\n- * \\return A string describing the pixel format\n- */\n-std::string V4L2PixelFormat::toString() const\n-{\n-\tif (fourcc_ == 0)\n-\t\treturn \"<INVALID>\";\n-\n-\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n-\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n-\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n-\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n-\n-\tfor (unsigned int i = 0; i < 4; i++) {\n-\t\tif (!isprint(ss[i]))\n-\t\t\tss[i] = '.';\n-\t}\n-\n-\tif (fourcc_ & (1 << 31))\n-\t\tstrcat(ss, \"-BE\");\n-\n-\treturn ss;\n-}\n-\n /**\n  * \\class V4L2DeviceFormat\n  * \\brief The V4L2 video device image format and sizes\n","prefixes":["libcamera-devel","v2","1/6"]}