Show a patch.

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

{
    "id": 632,
    "url": "https://patchwork.libcamera.org/api/patches/632/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/632/",
    "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": "<20190226162641.12116-3-jacopo@jmondi.org>",
    "date": "2019-02-26T16:26:35",
    "name": "[libcamera-devel,v3,2/8] libcamera: v4l2_subdevice: Implement ENUM_FRAME_SIZES",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "065271f3fd9c8444226d6c19bb190031126a5a85",
    "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/632/mbox/",
    "series": [
        {
            "id": 193,
            "url": "https://patchwork.libcamera.org/api/series/193/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=193",
            "date": "2019-02-26T16:26:33",
            "name": "v4l2_(sub)dev: improvements and tests",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/193/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/632/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/632/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 86E4C610B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Feb 2019 17:26: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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 1CB1960008;\n\tTue, 26 Feb 2019 16:26:18 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 26 Feb 2019 17:26:35 +0100",
        "Message-Id": "<20190226162641.12116-3-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190226162641.12116-1-jacopo@jmondi.org>",
        "References": "<20190226162641.12116-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 2/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": "Tue, 26 Feb 2019 16:26: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 |   9 ++\n src/libcamera/v4l2_subdevice.cpp       | 118 +++++++++++++++++++++++++\n 2 files changed, 127 insertions(+)",
    "diff": "diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex eac699a06109..6b21308d2087 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,15 +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 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 56ecf3851cb0..f81a521f9e2a 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@@ -242,6 +268,98 @@ 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<< \" of \" << deviceName() << \": \"\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+\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<< \" of \" << deviceName() << \": \" << strerror(-ret);\n+\t\treturn formats;\n+\t}\n+\n+\tif (mbusEnum.index == 0 && ret && errno == EINVAL) {\n+\t\t/*\n+\t\t * The subdevice might not support ENUM_MBUS_CODE but\n+\t\t * might support ENUM_FRAME_SIZES.\n+\t\t */\n+\t\tstruct V4L2SubdeviceFormat subdevFormat;\n+\t\tret = getFormat(pad, &subdevFormat);\n+\t\tif (ret)\n+\t\t\treturn formats;\n+\n+\t\tlistPadSizes(pad, subdevFormat.mbus_code, &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",
        "v3",
        "2/8"
    ]
}