{"id":616,"url":"https://patchwork.libcamera.org/api/1.1/patches/616/?format=json","web_url":"https://patchwork.libcamera.org/patch/616/","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":"<20190225121037.11415-3-jacopo@jmondi.org>","date":"2019-02-25T12:10:33","name":"[libcamera-devel,v2,2/6] libcamera: v4l2_subdevice: Implement ENUM_FRAME_SIZES","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d0b71a45605062d182b56b17c966f8ac64041826","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/616/mbox/","series":[{"id":191,"url":"https://patchwork.libcamera.org/api/1.1/series/191/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=191","date":"2019-02-25T12:10:31","name":"v4l2_(sub)dev: improvements and tests","version":2,"mbox":"https://patchwork.libcamera.org/series/191/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/616/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/616/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 5E978610B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Feb 2019 13:10:19 +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 DD105100008;\n\tMon, 25 Feb 2019 12:10:18 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 25 Feb 2019 13:10:33 +0100","Message-Id":"<20190225121037.11415-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190225121037.11415-1-jacopo@jmondi.org>","References":"<20190225121037.11415-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 2/6] 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":"Mon, 25 Feb 2019 12:10:19 -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 |  8 +++\n src/libcamera/v4l2_subdevice.cpp       | 93 ++++++++++++++++++++++++++\n 2 files changed, 101 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex fcfbee5af106..cb033a76933c 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 \"media_object.h\"\n \n@@ -38,16 +40,22 @@ 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 private:\n+\tint listPadFormats(unsigned int pad,\n+\t\t\t   std::vector<V4L2SubdeviceFormat> *formats);\n+\tvoid listFormats();\n \tint setSelection(unsigned int pad, unsigned int target,\n \t\t\t Rectangle *rect);\n \n \tconst MediaEntity *entity_;\n \tstd::string deviceNode_;\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 ebf87f0124cb..0e9c654579dc 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,8 @@ int V4L2Subdevice::open()\n \t}\n \tfd_ = ret;\n \n+\tlistFormats();\n+\n \treturn 0;\n }\n \n@@ -178,6 +184,17 @@ 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 on error\n+ */\n+std::vector<V4L2SubdeviceFormat> &V4L2Subdevice::formats(unsigned int pad)\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@@ -242,6 +259,82 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n \treturn 0;\n }\n \n+int V4L2Subdevice::listPadFormats(unsigned int pad,\n+\t\t\t\t  std::vector<V4L2SubdeviceFormat> *formats)\n+{\n+\tstruct v4l2_subdev_frame_size_enum sizeEnum = {};\n+\tstruct v4l2_subdev_mbus_code_enum mbusEnum = {};\n+\tint ret;\n+\n+\tmbusEnum.index = 0;\n+\tmbusEnum.pad = pad;\n+\tmbusEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n+\n+\twhile (!(ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum))) {\n+\t\tsizeEnum.index = 0;\n+\t\tsizeEnum.code = mbusEnum.code;\n+\t\tsizeEnum.pad = pad;\n+\t\tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n+\n+\t\twhile (!(ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE,\n+\t\t\t\t     &sizeEnum))) {\n+\n+\t\t\t/* Store the minimum and maximum reported sizes. */\n+\t\t\tV4L2SubdeviceFormat minFormat = {\n+\t\t\t\t.mbus_code = mbusEnum.code,\n+\t\t\t\t.width = sizeEnum.min_width,\n+\t\t\t\t.height = sizeEnum.min_height,\n+\t\t\t};\n+\t\t\tformats->push_back(minFormat);\n+\n+\t\t\tV4L2SubdeviceFormat maxFormat = {\n+\t\t\t\t.mbus_code = mbusEnum.code,\n+\t\t\t\t.width = sizeEnum.max_width,\n+\t\t\t\t.height = sizeEnum.max_height,\n+\t\t\t};\n+\t\t\tformats->push_back(maxFormat);\n+\n+\t\t\tsizeEnum.index++;\n+\t\t}\n+\n+\t\tif (-errno != -EINVAL) {\n+\t\t\tLOG(V4L2Subdev, Error)\n+\t\t\t\t<< \"Unable to enumerate format on pad \" << pad\n+\t\t\t\t<< \" of \" << deviceNode_ << \": \"\n+\t\t\t\t<< strerror(-ret);\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\tmbusEnum.index++;\n+\t}\n+\n+\tif (-errno != -EINVAL) {\n+\t\tLOG(V4L2Subdev, Error)\n+\t\t\t<< \"Unable to enumerate format on pad \" << pad\n+\t\t\t<< \" of \" << deviceNode_ << \": \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void V4L2Subdevice::listFormats()\n+{\n+\tint ret;\n+\n+\tfor (MediaPad *pad : entity_->pads()) {\n+\t\tstd::vector<V4L2SubdeviceFormat> formats = {};\n+\t\tret = listPadFormats(pad->index(), &formats);\n+\t\tif (ret) {\n+\t\t\tformats = {};\n+\t\t\tformats_[pad->index()] = formats;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tformats_[pad->index()] = formats;\n+\t}\n+}\n+\n int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n \t\t\t\tRectangle *rect)\n {\n","prefixes":["libcamera-devel","v2","2/6"]}