Patch Detail
Show a patch.
GET /api/patches/19722/?format=api
{ "id": 19722, "url": "https://patchwork.libcamera.org/api/patches/19722/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19722/", "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": "<20240315001613.2033-4-laurent.pinchart@ideasonboard.com>", "date": "2024-03-15T00:16:02", "name": "[v2,03/14] libcamera: v4l2_subdevice: Expose media bus format info as internal API", "commit_ref": "d60fb232588efe9f9aee001faaab35bf5f46bec1", "pull_url": null, "state": "accepted", "archived": false, "hash": "e5ea86d9f2d82559f1f4d94b6aa9c151fc1dd50e", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19722/mbox/", "series": [ { "id": 4226, "url": "https://patchwork.libcamera.org/api/series/4226/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4226", "date": "2024-03-15T00:15:59", "name": "libcamera: Prepare for new camera sensor class", "version": 2, "mbox": "https://patchwork.libcamera.org/series/4226/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19722/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19722/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 0D138BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Mar 2024 00:16:27 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8D8CB62C9E;\n\tFri, 15 Mar 2024 01:16:26 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EA9F62C94\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Mar 2024 01:16:20 +0100 (CET)", "from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9BDBF667\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Mar 2024 01:15:56 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"TdUqXDJM\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710461756;\n\tbh=X7huh+woFiV06sZwTs3RKrbSgRRFY5NTwl60CrvcKNs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=TdUqXDJM1RpuxEraVxoj/jNYPXd57KWk0vbb+PfDmJOImdc8h81tRhDgPBi6g5VIJ\n\tOiUTR980+lssSEOpqWGhA0Kkx9QaIwJXtQrTeagCfg44xekv0yjLPcdGpN1v7gOjv9\n\tGwnhn9QDO18aU+jyCT/xarTfkMGugwEfCGGZHngY=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH v2 03/14] libcamera: v4l2_subdevice: Expose media bus format\n\tinfo as internal API", "Date": "Fri, 15 Mar 2024 02:16:02 +0200", "Message-ID": "<20240315001613.2033-4-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.2", "In-Reply-To": "<20240315001613.2033-1-laurent.pinchart@ideasonboard.com>", "References": "<20240315001613.2033-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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": "The V4L2SubdeviceFormatInfo structure, internal to the\nv4l2_subdevice.cpp compilation unit, contains information about media\nbus formats that will be useful in other parts of libcamera. To prepare\nfor this, expose the structure in the v4l2_subdevice.h header and turn\nit into a class with a similar design as PixelFormatInfo.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\nChanges since v1:\n\n- Improve MediaBusFormatInfo::code documentation\n---\n include/libcamera/internal/v4l2_subdevice.h | 13 +++\n src/libcamera/v4l2_subdevice.cpp | 94 ++++++++++++++-------\n 2 files changed, 76 insertions(+), 31 deletions(-)", "diff": "diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\nindex 17db311bcfb3..a4df9ddfd322 100644\n--- a/include/libcamera/internal/v4l2_subdevice.h\n+++ b/include/libcamera/internal/v4l2_subdevice.h\n@@ -29,6 +29,19 @@ namespace libcamera {\n \n class MediaDevice;\n \n+class MediaBusFormatInfo\n+{\n+public:\n+\tbool isValid() const { return code != 0; }\n+\n+\tstatic const MediaBusFormatInfo &info(uint32_t code);\n+\n+\tconst char *name;\n+\tuint32_t code;\n+\tunsigned int bitsPerPixel;\n+\tPixelFormatInfo::ColourEncoding colourEncoding;\n+};\n+\n struct V4L2SubdeviceCapability final : v4l2_subdev_capability {\n \tbool isReadOnly() const\n \t{\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 1286e7c385c4..4918e28e5f18 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -36,28 +36,40 @@ namespace libcamera {\n \n LOG_DECLARE_CATEGORY(V4L2)\n \n+/**\n+ * \\class MediaBusFormatInfo\n+ * \\brief Information about media bus formats\n+ *\n+ * The MediaBusFormatInfo class groups together information describing a media\n+ * bus format. It facilitates handling of media bus formats by providing data\n+ * commonly used in pipeline handlers.\n+ *\n+ * \\var MediaBusFormatInfo::name\n+ * \\brief The format name as a human-readable string, used as the text\n+ * representation of the format\n+ *\n+ * \\var MediaBusFormatInfo::code\n+ * \\brief The media bus format code described by this instance (MEDIA_BUS_FMT_*)\n+ *\n+ * \\var MediaBusFormatInfo::bitsPerPixel\n+ * \\brief The average number of bits per pixel\n+ *\n+ * The number of bits per pixel averages the total number of bits for all\n+ * colour components over the whole image, excluding any padding bits or\n+ * padding pixels.\n+ *\n+ * For formats that transmit multiple or fractional pixels per sample, the\n+ * value will differ from the bus width.\n+ *\n+ * Formats that don't have a fixed number of bits per pixel, such as compressed\n+ * formats, report 0 in this field.\n+ *\n+ * \\var MediaBusFormatInfo::colourEncoding\n+ * \\brief The colour encoding type\n+ */\n+\n namespace {\n \n-/*\n- * \\struct MediaBusFormatInfo\n- * \\brief Information about media bus formats\n- * \\param name Name of MBUS format\n- * \\param code The media bus format code\n- * \\param bitsPerPixel Bits per pixel\n- * \\param colourEncoding Type of colour encoding\n- */\n-struct MediaBusFormatInfo {\n-\tconst char *name;\n-\tuint32_t code;\n-\tunsigned int bitsPerPixel;\n-\tPixelFormatInfo::ColourEncoding colourEncoding;\n-};\n-\n-/*\n- * \\var mediaBusFormatInfo\n- * \\brief A map that associates MediaBusFormatInfo struct to V4L2 media\n- * bus codes\n- */\n const std::map<uint32_t, MediaBusFormatInfo> mediaBusFormatInfo{\n \t/* This table is sorted to match the order in linux/media-bus-format.h */\n \t{ MEDIA_BUS_FMT_RGB444_2X8_PADHI_BE, {\n@@ -557,6 +569,33 @@ const std::map<uint32_t, MediaBusFormatInfo> mediaBusFormatInfo{\n \n } /* namespace */\n \n+/**\n+ * \\fn bool MediaBusFormatInfo::isValid() const\n+ * \\brief Check if the media bus format info is valid\n+ * \\return True if the media bus format info is valid, false otherwise\n+ */\n+\n+/**\n+ * \\brief Retrieve information about a media bus format\n+ * \\param[in] code The media bus format code\n+ * \\return The MediaBusFormatInfo describing the \\a code if known, or an invalid\n+ * MediaBusFormatInfo otherwise\n+ */\n+const MediaBusFormatInfo &MediaBusFormatInfo::info(uint32_t code)\n+{\n+\tstatic const MediaBusFormatInfo invalid{};\n+\n+\tconst auto it = mediaBusFormatInfo.find(code);\n+\tif (it == mediaBusFormatInfo.end()) {\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Unsupported media bus format \"\n+\t\t\t<< utils::hex(code, 4);\n+\t\treturn invalid;\n+\t}\n+\n+\treturn it->second;\n+}\n+\n /**\n * \\struct V4L2SubdeviceCapability\n * \\brief struct v4l2_subdev_capability object wrapper and helpers\n@@ -653,14 +692,7 @@ const std::string V4L2SubdeviceFormat::toString() const\n */\n uint8_t V4L2SubdeviceFormat::bitsPerPixel() const\n {\n-\tconst auto it = mediaBusFormatInfo.find(mbus_code);\n-\tif (it == mediaBusFormatInfo.end()) {\n-\t\tLOG(V4L2, Error) << \"No information available for format '\"\n-\t\t\t\t << *this << \"'\";\n-\t\treturn 0;\n-\t}\n-\n-\treturn it->second.bitsPerPixel;\n+\treturn MediaBusFormatInfo::info(mbus_code).bitsPerPixel;\n }\n \n /**\n@@ -927,9 +959,9 @@ std::optional<ColorSpace> V4L2Subdevice::toColorSpace(const v4l2_mbus_framefmt &\n \t\treturn std::nullopt;\n \n \tPixelFormatInfo::ColourEncoding colourEncoding;\n-\tauto iter = mediaBusFormatInfo.find(format.code);\n-\tif (iter != mediaBusFormatInfo.end()) {\n-\t\tcolourEncoding = iter->second.colourEncoding;\n+\tconst MediaBusFormatInfo &info = MediaBusFormatInfo::info(format.code);\n+\tif (info.isValid()) {\n+\t\tcolourEncoding = info.colourEncoding;\n \t} else {\n \t\tLOG(V4L2, Warning)\n \t\t\t<< \"Unknown subdev format \"\n", "prefixes": [ "v2", "03/14" ] }