Patch Detail
Show a patch.
GET /api/patches/19554/?format=api
{ "id": 19554, "url": "https://patchwork.libcamera.org/api/patches/19554/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19554/", "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": "<20240227140953.26093-4-laurent.pinchart@ideasonboard.com>", "date": "2024-02-27T14:09:47", "name": "[3/9] libcamera: v4l2_subdevice: Expose media bus format info as internal API", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "5c499c839e04b1e1fe9e582f50e08ee82cae11d6", "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/19554/mbox/", "series": [ { "id": 4189, "url": "https://patchwork.libcamera.org/api/series/4189/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4189", "date": "2024-02-27T14:09:44", "name": "libcamera: v4l2_subdevice: Prepare for embedded data support", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4189/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19554/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19554/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 13B86C3264\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Feb 2024 14:09:58 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC45F62876;\n\tTue, 27 Feb 2024 15:09:57 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 37D0D62865\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Feb 2024 15:09:55 +0100 (CET)", "from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi\n\t[89.27.53.110])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 043FB8C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Feb 2024 15:09:42 +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=\"oFDlEMJh\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1709042983;\n\tbh=K6fWqDxuGYV/zSI4pRxbkeMFJpQtYK8oVtBnCgFpyIE=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=oFDlEMJhEHsJB1p0l5dgwA0DlNAYd+1YAgP/JqC/PLFKxTsiEJfsTqK0/vGrvNUxU\n\tQfjafBz5UbGsnTJrEwR1jISXYCbieDgO0s2n6Sjz0uI18XBTe8ySXX2lhbKw+pnXk0\n\t42Z2VXiofHAKtPzBSuIu1iUqQNYph1JSyHmskRSU=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH 3/9] libcamera: v4l2_subdevice: Expose media bus format info\n\tas internal API", "Date": "Tue, 27 Feb 2024 16:09:47 +0200", "Message-ID": "<20240227140953.26093-4-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20240227140953.26093-1-laurent.pinchart@ideasonboard.com>", "References": "<20240227140953.26093-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>\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 a74b8362b6d1..fd289ae9ae6f 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\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@@ -533,6 +545,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@@ -629,14 +668,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@@ -903,9 +935,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": [ "3/9" ] }