Show a patch.

GET /api/patches/690/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 690,
    "url": "https://patchwork.libcamera.org/api/patches/690/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/690/",
    "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": "<20190301115139.11060-2-jacopo@jmondi.org>",
    "date": "2019-03-01T11:51:35",
    "name": "[libcamera-devel,v6,1/5] libcamera: v4l2_subdevice: Implement ENUM_FRAME_SIZES",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f49909462063c93659c86c641d726542164f2092",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/690/mbox/",
    "series": [
        {
            "id": 200,
            "url": "https://patchwork.libcamera.org/api/series/200/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=200",
            "date": "2019-03-01T11:51:34",
            "name": "v4l2_(sub)dev: improvements and tests",
            "version": 6,
            "mbox": "https://patchwork.libcamera.org/series/200/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/690/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/690/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AC010610BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 Mar 2019 12:52:44 +0100 (CET)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 2F57EC0011;\n\tFri,  1 Mar 2019 11:52:42 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  1 Mar 2019 12:51:35 +0100",
        "Message-Id": "<20190301115139.11060-2-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190301115139.11060-1-jacopo@jmondi.org>",
        "References": "<20190301115139.11060-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v6 1/5] libcamera: v4l2_subdevice:\n\tImplement ENUM_FRAME_SIZES",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.23",
        "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": "Fri, 01 Mar 2019 11:52:44 -0000"
    },
    "content": "Implement format and size enumeration methods to list all the available\nsubdevice image resolutions and formats.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/geometry.cpp             | 34 +++++++++++\n src/libcamera/include/geometry.h       | 12 ++++\n src/libcamera/include/v4l2_subdevice.h | 11 +++-\n src/libcamera/v4l2_subdevice.cpp       | 84 ++++++++++++++++++++++++++\n 4 files changed, 139 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex 57f4fc7716d9..b6b6592bdfec 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -46,4 +46,38 @@ namespace libcamera {\n  * \\brief The distance between the top and bottom sides\n  */\n \n+/**\n+ * \\struct SizeRange\n+ * \\brief Describe a range of image sizes\n+ *\n+ * SizeRange describes a range of image sizes included in the (minWidth,\n+ * minHeight) - (maxWidth, maxHeight) interval. If the minimum and\n+ * maximum sizes are identical it represents a single image resolution.\n+ */\n+\n+/**\n+ * \\fn SizeRange::SizeRange()\n+ * \\brief Construct a size range\n+ */\n+\n+/**\n+ * \\var SizeRange::minWidth\n+ * \\brief The minimum image width\n+ */\n+\n+/**\n+ * \\var SizeRange::minHeight\n+ * \\brief The minimum image height\n+ */\n+\n+/**\n+ * \\var SizeRange::maxWidth\n+ * \\brief The maximum image width\n+ */\n+\n+/**\n+ * \\var SizeRange::maxHeight\n+ * \\brief The maximum image height\n+ */\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/geometry.h b/src/libcamera/include/geometry.h\nindex cc146da7cb0d..eadc4ed4f9cb 100644\n--- a/src/libcamera/include/geometry.h\n+++ b/src/libcamera/include/geometry.h\n@@ -17,6 +17,18 @@ struct Rectangle {\n \tunsigned int h;\n };\n \n+struct SizeRange {\n+\tSizeRange(unsigned int minW, unsigned int minH,\n+\t\t  unsigned int maxW, unsigned int maxH)\n+\t\t: minWidth(minW), minHeight(minH), maxWidth(maxW),\n+\t\t  maxHeight(maxH) {}\n+\n+\tunsigned int minWidth;\n+\tunsigned int minHeight;\n+\tunsigned int maxWidth;\n+\tunsigned int maxHeight;\n+};\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_GEOMETRY_H__ */\ndiff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex 669e79f9a9fd..aa7451e86962 100644\n--- a/src/libcamera/include/v4l2_subdevice.h\n+++ b/src/libcamera/include/v4l2_subdevice.h\n@@ -7,15 +7,16 @@\n #ifndef __LIBCAMERA_V4L2_SUBDEVICE_H__\n #define __LIBCAMERA_V4L2_SUBDEVICE_H__\n \n+#include <map>\n #include <string>\n+#include <vector>\n \n+#include \"geometry.h\"\n #include \"log.h\"\n #include \"media_object.h\"\n \n namespace libcamera {\n \n-struct Rectangle;\n-\n struct V4L2SubdeviceFormat {\n \tuint32_t mbus_code;\n \tuint32_t width;\n@@ -39,6 +40,9 @@ public:\n \tint setCrop(unsigned int pad, Rectangle *rect);\n \tint setCompose(unsigned int pad, Rectangle *rect);\n \n+\tconst std::map<unsigned int, std::vector<SizeRange>>\n+\t\t\t\t\t\tformats(unsigned int pad);\n+\n \tint getFormat(unsigned int pad, V4L2SubdeviceFormat *format);\n \tint setFormat(unsigned int pad, V4L2SubdeviceFormat *format);\n \n@@ -46,6 +50,9 @@ protected:\n \tstd::string logPrefix() const;\n \n private:\n+\tstd::vector<SizeRange> enumPadSizes(unsigned int pad,\n+\t\t\t\t\t    unsigned int code);\n+\n \tint setSelection(unsigned int pad, unsigned int target,\n \t\t\t Rectangle *rect);\n \ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 87377762664d..07035886c766 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -183,6 +183,57 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect)\n \treturn setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect);\n }\n \n+/**\n+ * \\brief List the sub-device image resolutions and formats on \\a pad\n+ * \\param[in] pad The 0-indexed pad number to enumerate formats on\n+ *\n+ * Retrieve a list of image formats and sizes on the \\a pad of a video\n+ * subdevice. Subdevices can report either a list of discrete sizes they\n+ * support or a list of intervals expressed as a [min-max] sizes range.\n+ *\n+ * Each image size list is associated with a media bus pixel code for which\n+ * the reported resolutions are supported.\n+ *\n+ * \\return A map of image formats associated with a list of image sizes, or\n+ * an empty map on error or if the pad does not exist\n+ */\n+const std::map<unsigned int, std::vector<SizeRange>>\n+V4L2Subdevice::formats(unsigned int pad)\n+{\n+\tstd::map<unsigned int, std::vector<SizeRange>> formatMap = {};\n+\tstruct v4l2_subdev_mbus_code_enum mbusEnum = {};\n+\tint ret;\n+\n+\tif (pad >= entity_->pads().size()) {\n+\t\tLOG(V4L2Subdev, Error)\n+\t\t\t<< \"Invalid pad: \" << pad;\n+\t\treturn formatMap;\n+\t}\n+\n+\tmbusEnum.pad = pad;\n+\tmbusEnum.index = 0;\n+\tmbusEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n+\twhile (true) {\n+\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n+\t\tif (ret)\n+\t\t\tbreak;\n+\n+\t\tformatMap[mbusEnum.code] = enumPadSizes(pad, mbusEnum.code);\n+\n+\t\tmbusEnum.index++;\n+\t}\n+\n+\tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2Subdev, Error)\n+\t\t\t<< \"Unable to enumerate formats on pad \" << pad\n+\t\t\t<< \": \" << strerror(-ret);\n+\t\tformatMap.clear();\n+\t}\n+\n+\treturn formatMap;\n+}\n+\n /**\n  * \\brief Retrieve the image format set on one of the V4L2 subdevice pads\n  * \\param[in] pad The 0-indexed pad number the format is to be retrieved from\n@@ -248,6 +299,39 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n \treturn 0;\n }\n \n+std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,\n+\t\t\t\t\t\t   unsigned int code)\n+{\n+\tstruct v4l2_subdev_frame_size_enum sizeEnum = {};\n+\tstd::vector<SizeRange> sizes = {};\n+\tint ret;\n+\n+\tsizeEnum.index = 0;\n+\tsizeEnum.pad = pad;\n+\tsizeEnum.code = code;\n+\tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n+\twhile (true) {\n+\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n+\t\tif (ret)\n+\t\t\tbreak;\n+\n+\t\tsizes.emplace_back(sizeEnum.min_width, sizeEnum.min_height,\n+\t\t\t\t   sizeEnum.max_width, sizeEnum.max_height);\n+\n+\t\tsizeEnum.index++;\n+\t}\n+\n+\tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2Subdev, Error)\n+\t\t\t<< \"Unable to enumerate sizes on pad \" << pad\n+\t\t\t<< \": \" << strerror(-ret);\n+\t\tsizes.clear();\n+\t}\n+\n+\treturn sizes;\n+}\n+\n int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n \t\t\t\tRectangle *rect)\n {\n",
    "prefixes": [
        "libcamera-devel",
        "v6",
        "1/5"
    ]
}