Patch Detail
Show a patch.
GET /api/1.1/patches/3129/?format=api
{ "id": 3129, "url": "https://patchwork.libcamera.org/api/1.1/patches/3129/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3129/", "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": "<20200316234649.2545-2-laurent.pinchart@ideasonboard.com>", "date": "2020-03-16T23:46:48", "name": "[libcamera-devel,1/2] libcamera: v4l2_videodevice: Add V4L2PixelFormat class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "5add627b2d71b7e0c76171fe8fee7ed594f1c8eb", "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/3129/mbox/", "series": [ { "id": 725, "url": "https://patchwork.libcamera.org/api/1.1/series/725/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=725", "date": "2020-03-16T23:46:47", "name": "Add a V4L2PixelFormat class", "version": 1, "mbox": "https://patchwork.libcamera.org/series/725/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3129/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3129/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 7A77B6041B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Mar 2020 00:46:59 +0100 (CET)", "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 15165AD8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Mar 2020 00:46:59 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584402419;\n\tbh=NNyN4PsNupZGNC4EHASMr7acjMvvlGUy6cywJ99oXrQ=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=icjhKZRz3j/HjRUA8bh4s3KmOtlSWic/6eW4tNmHtn1DQwDOXk/wAFpzXsqfHZlV4\n\tqV6rTucCMBB/SlBpNKQhcXsKlekjouzvwOtR6JfNFQ3XTn0i1zfTzO49wjqEtZnlbz\n\tRfQ+dBwc4gGeebk3w0eHSH/I+z2dFWJoSBPCN8wM=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 17 Mar 2020 01:46:48 +0200", "Message-Id": "<20200316234649.2545-2-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200316234649.2545-1-laurent.pinchart@ideasonboard.com>", "References": "<20200316234649.2545-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 1/2] libcamera: v4l2_videodevice: Add\n\tV4L2PixelFormat class", "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, 16 Mar 2020 23:46:59 -0000" }, "content": "The V4L2PixelFormat class describes the pixel format of a V4L2 buffer.\nIt wraps the V4L2 numerical FourCC, and shall be used in all APIs that\ndeal with V4L2 pixel formats. Its purpose is to prevent unintentional\nconfusion of V4L2 and DRM FourCCs in code by catching implicit\nconversion attempts at compile time.\n\nThe constructor taking a V4L2 FourCC integer value will be made explicit\nin a further commit to minimize the size of this change and keep it\nreviewable.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/v4l2_videodevice.h | 35 ++++++++++---\n src/libcamera/v4l2_videodevice.cpp | 62 +++++++++++++++++++-----\n 2 files changed, 79 insertions(+), 18 deletions(-)", "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex b3000f3c5133..49d2ca357efa 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -149,10 +149,31 @@ 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+\tV4L2PixelFormat(uint32_t fourcc)\n+\t\t: fourcc_(fourcc)\n+\t{\n+\t}\n+\n+\tbool isValid() const { return fourcc_ != 0; }\n+\tuint32_t value() const { return fourcc_; }\n+\toperator uint32_t() const { return fourcc_; }\n+\n+private:\n+\tuint32_t fourcc_;\n+};\n+\n class V4L2DeviceFormat\n {\n public:\n-\tuint32_t fourcc;\n+\tV4L2PixelFormat fourcc;\n \tSize size;\n \n \tstruct {\n@@ -184,7 +205,7 @@ public:\n \n \tint getFormat(V4L2DeviceFormat *format);\n \tint setFormat(V4L2DeviceFormat *format);\n-\tstd::map<unsigned int, std::vector<SizeRange>> formats();\n+\tstd::map<V4L2PixelFormat, std::vector<SizeRange>> formats();\n \n \tint setCrop(Rectangle *rect);\n \tint setCompose(Rectangle *rect);\n@@ -203,9 +224,9 @@ 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+\tstatic PixelFormat toPixelFormat(V4L2PixelFormat v4l2Fourcc);\n+\tV4L2PixelFormat toV4L2Fourcc(PixelFormat pixelFormat);\n+\tstatic V4L2PixelFormat toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar);\n \n protected:\n \tstd::string logPrefix() const;\n@@ -220,8 +241,8 @@ private:\n \tint getFormatSingleplane(V4L2DeviceFormat *format);\n \tint setFormatSingleplane(V4L2DeviceFormat *format);\n \n-\tstd::vector<unsigned int> enumPixelformats();\n-\tstd::vector<SizeRange> enumSizes(unsigned int pixelFormat);\n+\tstd::vector<V4L2PixelFormat> enumPixelformats();\n+\tstd::vector<SizeRange> enumSizes(V4L2PixelFormat pixelFormat);\n \n \tint setSelection(unsigned int target, Rectangle *rect);\n \ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 81911e764fde..40396c22aa45 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -277,6 +277,46 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n \treturn true;\n }\n \n+/**\n+ * \\class V4L2PixelFormat\n+ * \\brief V4L2 pixel format 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+\n+/**\n+ * \\fn V4L2PixelFormat::V4L2PixelFormat()\n+ * \\brief Construct an invalid V4L2 pixel format with a numerical value of 0\n+ */\n+\n+/**\n+ * \\fn V4L2PixelFormat::V4L2PixelFormat(uint32_t fourcc)\n+ * \\brief Construct a V4L2 pixel format from a FourCC value\n+ * \\param[in] fourcc The pixel format numerical value\n+ */\n+\n+/**\n+ * \\fn bool V4L2PixelFormat::isValid() const\n+ * \\brief Check if the pixel format is valid\n+ * \\return True if the pixel format has a non-zero value, false otherwise\n+ */\n+\n+/**\n+ * \\fn uint32_t V4L2PixelFormat::value() const\n+ * \\brief Retrieve the pixel format numerical value\n+ * \\return The pixel format numerical value\n+ */\n+\n+/**\n+ * \\fn V4L2PixelFormat::operator uint32_t() const\n+ * \\brief Convert the the pixel format numerical value\n+ * \\return The pixel format numerical value\n+ */\n+\n /**\n * \\class V4L2DeviceFormat\n * \\brief The V4L2 video device image format and sizes\n@@ -385,7 +425,7 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n const std::string V4L2DeviceFormat::toString() const\n {\n \tstd::stringstream ss;\n-\tss << size.toString() << \"-\" << utils::hex(fourcc);\n+\tss << size.toString() << \"-\" << utils::hex(fourcc.value());\n \treturn ss.str();\n }\n \n@@ -844,11 +884,11 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n *\n * \\return A list of the supported video device formats\n */\n-std::map<unsigned int, std::vector<SizeRange>> V4L2VideoDevice::formats()\n+std::map<V4L2PixelFormat, std::vector<SizeRange>> V4L2VideoDevice::formats()\n {\n-\tstd::map<unsigned int, std::vector<SizeRange>> formats;\n+\tstd::map<V4L2PixelFormat, std::vector<SizeRange>> formats;\n \n-\tfor (unsigned int pixelformat : enumPixelformats()) {\n+\tfor (V4L2PixelFormat pixelformat : enumPixelformats()) {\n \t\tstd::vector<SizeRange> sizes = enumSizes(pixelformat);\n \t\tif (sizes.empty())\n \t\t\treturn {};\n@@ -859,9 +899,9 @@ std::map<unsigned int, std::vector<SizeRange>> V4L2VideoDevice::formats()\n \treturn formats;\n }\n \n-std::vector<unsigned int> V4L2VideoDevice::enumPixelformats()\n+std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats()\n {\n-\tstd::vector<unsigned int> formats;\n+\tstd::vector<V4L2PixelFormat> formats;\n \tint ret;\n \n \tfor (unsigned int index = 0; ; index++) {\n@@ -886,7 +926,7 @@ std::vector<unsigned int> V4L2VideoDevice::enumPixelformats()\n \treturn formats;\n }\n \n-std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat)\n+std::vector<SizeRange> V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat)\n {\n \tstd::vector<SizeRange> sizes;\n \tint ret;\n@@ -1417,7 +1457,7 @@ V4L2VideoDevice *V4L2VideoDevice::fromEntityName(const MediaDevice *media,\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+PixelFormat V4L2VideoDevice::toPixelFormat(V4L2PixelFormat v4l2Fourcc)\n {\n \tswitch (v4l2Fourcc) {\n \t/* RGB formats. */\n@@ -1466,7 +1506,7 @@ PixelFormat V4L2VideoDevice::toPixelFormat(uint32_t v4l2Fourcc)\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\t\t<< utils::hex(v4l2Fourcc.value());\n \t\treturn PixelFormat();\n \t}\n }\n@@ -1482,7 +1522,7 @@ PixelFormat V4L2VideoDevice::toPixelFormat(uint32_t v4l2Fourcc)\n *\n * \\return The V4L2_PIX_FMT_* pixel format code corresponding to \\a pixelFormat\n */\n-uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat)\n+V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat)\n {\n \treturn V4L2VideoDevice::toV4L2Fourcc(pixelFormat, caps_.isMultiplanar());\n }\n@@ -1500,7 +1540,7 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat)\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+V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar)\n {\n \tswitch (pixelFormat.fourcc()) {\n \t/* RGB formats. */\n", "prefixes": [ "libcamera-devel", "1/2" ] }