{"id":642,"url":"https://patchwork.libcamera.org/api/patches/642/?format=json","web_url":"https://patchwork.libcamera.org/patch/642/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190227173837.6902-4-jacopo@jmondi.org>","date":"2019-02-27T17:38:32","name":"[libcamera-devel,v4,3/8] libcamera: v4l2_subdevice: Implement ENUM_FRAME_SIZES","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"b2b0c7ec282f03798e7b9d5a43d5e06b0c011dd2","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/642/mbox/","series":[{"id":194,"url":"https://patchwork.libcamera.org/api/series/194/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=194","date":"2019-02-27T17:38:29","name":"v4l2_(sub)dev: improvements and tests","version":4,"mbox":"https://patchwork.libcamera.org/series/194/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/642/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/642/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 AF1FA610B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Feb 2019 18:38:15 +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 46779100005;\n\tWed, 27 Feb 2019 17:38:15 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 27 Feb 2019 18:38:32 +0100","Message-Id":"<20190227173837.6902-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190227173837.6902-1-jacopo@jmondi.org>","References":"<20190227173837.6902-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 3/8] 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":"Wed, 27 Feb 2019 17:38:15 -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/include/v4l2_subdevice.h |   9 ++\n src/libcamera/v4l2_subdevice.cpp       | 122 +++++++++++++++++++++++++\n 2 files changed, 131 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex dc311034a8ee..827068ec563c 100644\n--- a/src/libcamera/include/v4l2_subdevice.h\n+++ b/src/libcamera/include/v4l2_subdevice.h\n@@ -7,7 +7,9 @@\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 \"log.h\"\n #include \"media_object.h\"\n@@ -39,6 +41,7 @@ public:\n \tint setCrop(unsigned int pad, Rectangle *rect);\n \tint setCompose(unsigned int pad, Rectangle *rect);\n \n+\tstd::vector<V4L2SubdeviceFormat> &formats(unsigned int pad);\n \tint getFormat(unsigned int pad, V4L2SubdeviceFormat *format);\n \tint setFormat(unsigned int pad, V4L2SubdeviceFormat *format);\n \n@@ -46,11 +49,17 @@ protected:\n \tstd::string logPrefix() const { return \"'\" + deviceName() + \"'\"; }\n \n private:\n+\tint listPadSizes(unsigned int pad, unsigned int mbus_code,\n+\t\t\t std::vector<V4L2SubdeviceFormat> *formats);\n+\tstd::vector<V4L2SubdeviceFormat> listPadFormats(unsigned int pad);\n+\n \tint setSelection(unsigned int pad, unsigned int target,\n \t\t\t Rectangle *rect);\n \n \tconst MediaEntity *entity_;\n \tint fd_;\n+\n+\tstd::map<unsigned int, std::vector<V4L2SubdeviceFormat>> formats_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex dbb54506ee41..b3a5d7a37413 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -5,6 +5,10 @@\n  * v4l2_subdevice.cpp - V4L2 Subdevice\n  */\n \n+#include <map>\n+#include <string>\n+#include <vector>\n+\n #include <fcntl.h>\n #include <string.h>\n #include <sys/ioctl.h>\n@@ -116,6 +120,9 @@ int V4L2Subdevice::open()\n \t}\n \tfd_ = ret;\n \n+\tfor (MediaPad *pad : entity_->pads())\n+\t\tformats_[pad->index()] = listPadFormats(pad->index());\n+\n \treturn 0;\n }\n \n@@ -178,6 +185,25 @@ 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+ * \\return A vector of image formats, or an empty vector if the pad does not\n+ * exist\n+ */\n+std::vector<V4L2SubdeviceFormat> &V4L2Subdevice::formats(unsigned int pad)\n+{\n+\t/*\n+\t * If pad does not exist, return an empty vector at position\n+\t * pads().size()\n+\t */\n+\tif (pad > entity_->pads().size())\n+\t\tpad = entity_->pads().size();\n+\n+\treturn formats_[pad];\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@@ -243,6 +269,102 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n \treturn 0;\n }\n \n+int V4L2Subdevice::listPadSizes(unsigned int pad, unsigned int mbus_code,\n+\t\t\t\tstd::vector<V4L2SubdeviceFormat> *formats)\n+{\n+\tstruct v4l2_subdev_frame_size_enum sizeEnum = {};\n+\tint ret;\n+\n+\tsizeEnum.index = 0;\n+\tsizeEnum.pad = pad;\n+\tsizeEnum.code = mbus_code;\n+\tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n+\n+\twhile (!(ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum))) {\n+\t\tV4L2SubdeviceFormat minFormat = {\n+\t\t\t.mbus_code = mbus_code,\n+\t\t\t.width = sizeEnum.min_width,\n+\t\t\t.height = sizeEnum.min_height,\n+\t\t};\n+\t\tformats->push_back(minFormat);\n+\n+\t\t/*\n+\t\t * Most subdevices report discrete frame resolutions, where\n+\t\t * min and max sizes are identical. For continue frame\n+\t\t * resolutions, store the min and max sizes interval.\n+\t\t */\n+\t\tif (sizeEnum.min_width == sizeEnum.max_width &&\n+\t\t    sizeEnum.min_height == sizeEnum.max_height) {\n+\t\t\tsizeEnum.index++;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tV4L2SubdeviceFormat maxFormat = {\n+\t\t\t.mbus_code = mbus_code,\n+\t\t\t.width = sizeEnum.max_width,\n+\t\t\t.height = sizeEnum.max_height,\n+\t\t};\n+\t\tformats->push_back(maxFormat);\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 format on pad \" << pad\n+\t\t\t<< \": \" << strerror(errno);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+std::vector<V4L2SubdeviceFormat> V4L2Subdevice::listPadFormats(unsigned int pad)\n+{\n+\tstruct v4l2_subdev_mbus_code_enum mbusEnum = {};\n+\tstd::vector<V4L2SubdeviceFormat> formats = {};\n+\tint ret;\n+\n+\tmbusEnum.pad = pad;\n+\tmbusEnum.index = 0;\n+\tmbusEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n+\n+\twhile (!(ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum))) {\n+\t\tret = listPadSizes(pad, mbusEnum.code, &formats);\n+\t\tif (ret)\n+\t\t\treturn formats;\n+\n+\t\tmbusEnum.index++;\n+\t}\n+\n+\t/*\n+\t * The subdevice might not support ENUM_MBUS_CODE but might support\n+\t * ENUM_FRAME_SIZES. Try with the currently applied format.\n+\t */\n+\tif (ret && errno == ENOTTY) {\n+\t\tstruct V4L2SubdeviceFormat subdevFormat;\n+\t\tif (getFormat(pad, &subdevFormat)) {\n+\t\t\tLOG(V4L2Subdev, Error)\n+\t\t\t\t<< \"Unable to get format on pad \" << pad\n+\t\t\t\t<< \": \" << strerror(errno);\n+\t\t\treturn formats;\n+\t\t}\n+\n+\t\tret = listPadSizes(pad, subdevFormat.mbus_code, &formats);\n+\t\tif (ret)\n+\t\t\treturn formats;\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\treturn formats;\n+\t}\n+\n+\treturn formats;\n+}\n+\n int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n \t\t\t\tRectangle *rect)\n {\n","prefixes":["libcamera-devel","v4","3/8"]}