{"id":671,"url":"https://patchwork.libcamera.org/api/1.1/patches/671/?format=json","web_url":"https://patchwork.libcamera.org/patch/671/","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":"<20190228200151.2948-4-jacopo@jmondi.org>","date":"2019-02-28T20:01:45","name":"[libcamera-devel,v5,3/9] libcamera: v4l2_subdevice: Implement ENUM_FRAME_SIZES","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e1126998b9526d64e5150fc91d2c78a06c5a1a9a","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/671/mbox/","series":[{"id":198,"url":"https://patchwork.libcamera.org/api/1.1/series/198/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=198","date":"2019-02-28T20:01:42","name":"v4l2_(sub)dev: improvements and tests","version":4,"mbox":"https://patchwork.libcamera.org/series/198/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/671/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/671/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8017E610B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Feb 2019 21:01:32 +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 relay11.mail.gandi.net (Postfix) with ESMTPSA id 089B3100006;\n\tThu, 28 Feb 2019 20:01:31 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 28 Feb 2019 21:01:45 +0100","Message-Id":"<20190228200151.2948-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190228200151.2948-1-jacopo@jmondi.org>","References":"<20190228200151.2948-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 3/9] 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":"Thu, 28 Feb 2019 20:01:32 -0000"},"content":"Implement enumFormat() methods to enumerate the available image\nresolutions on the subdevice.\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..f41f6975d4ce 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 (maxWidth,\n+ * maxHeight) - (minWidth, minHeight) 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 4fe59c45f000..7f191e072c61 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -183,6 +183,58 @@ 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 are free to report a list of discrete sizes they\n+ * support, or a single size interval 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 exists\n+ * \\sa SizeRange\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<< \"Format enumeration required on a non-existing pad: \"\n+\t\t\t<< 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\tLOG(V4L2Subdev, Error)\n+\t\t\t<< \"Unable to enumerate format on pad \" << pad\n+\t\t\t<< \": \" << strerror(errno);\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 +300,38 @@ 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\tLOG(V4L2Subdev, Error)\n+\t\t\t<< \"Unable to enumerate sizes on pad \" << pad\n+\t\t\t<< \": \" << strerror(errno);\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","v5","3/9"]}