Show a patch.

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

{
    "id": 1301,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1301/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1301/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20190527001543.13593-10-niklas.soderlund@ragnatech.se>",
    "date": "2019-05-27T00:15:35",
    "name": "[libcamera-devel,09/17] libcamera: v4l2_device: Add enumeration of pixelformats and frame sizes",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "4e08069e14412e9749f0cd983fd46303f85c8941",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1301/mbox/",
    "series": [
        {
            "id": 328,
            "url": "https://patchwork.libcamera.org/api/1.1/series/328/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=328",
            "date": "2019-05-27T00:15:28",
            "name": "libcamera: Add support for format information and validation",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/328/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1301/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1301/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<niklas.soderlund@ragnatech.se>",
        "Received": [
            "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 988EC61903\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 May 2019 02:16:10 +0200 (CEST)",
            "from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 9ee85045-8014-11e9-8ab4-005056917a89;\n\tMon, 27 May 2019 02:16:06 +0200 (CEST)"
        ],
        "X-Halon-ID": "9ee85045-8014-11e9-8ab4-005056917a89",
        "Authorized-sender": "niklas@soderlund.pp.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 27 May 2019 02:15:35 +0200",
        "Message-Id": "<20190527001543.13593-10-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190527001543.13593-1-niklas.soderlund@ragnatech.se>",
        "References": "<20190527001543.13593-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 09/17] libcamera: v4l2_device: Add\n\tenumeration of pixelformats and 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, 27 May 2019 00:16:13 -0000"
    },
    "content": "Add methods to enumerate pixelformats and frame sizes from a v4l2\ndevice. The interface is similar to how V4L2Subdevice enumerates mbus\ncodes and frame sizes.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/include/v4l2_device.h |   5 ++\n src/libcamera/v4l2_device.cpp       | 104 ++++++++++++++++++++++++++++\n 2 files changed, 109 insertions(+)",
    "diff": "diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 2e7bd1e7f4cce276..db2d12757c6f564a 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -16,6 +16,7 @@\n #include <libcamera/geometry.h>\n #include <libcamera/signal.h>\n \n+#include \"formats.h\"\n #include \"log.h\"\n \n namespace libcamera {\n@@ -126,6 +127,7 @@ public:\n \n \tint getFormat(V4L2DeviceFormat *format);\n \tint setFormat(V4L2DeviceFormat *format);\n+\tV4L2DeviceFormats formats();\n \n \tint exportBuffers(BufferPool *pool);\n \tint importBuffers(BufferPool *pool);\n@@ -154,6 +156,9 @@ private:\n \tint createPlane(Buffer *buffer, unsigned int plane,\n \t\t\tunsigned int length);\n \n+\tstd::vector<unsigned int> enumPixelformats();\n+\tstd::vector<SizeRange> enumSizes(unsigned int pixelformat);\n+\n \tBuffer *dequeueBuffer();\n \tvoid bufferAvailable(EventNotifier *notifier);\n \ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 8366ffc4db559520..a9667092a20505d9 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -564,6 +564,23 @@ int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *format)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Enumerate all pixelformats and frame sizes\n+ *\n+ * Enumerate all pixelformats and frame sizes reported by the video device.\n+ *\n+ * \\return All pixelformats and frame sizes\n+ */\n+V4L2DeviceFormats V4L2Device::formats()\n+{\n+\tstd::map<unsigned int, std::vector<SizeRange>> formatMap = {};\n+\n+\tfor (unsigned int pixelformat : enumPixelformats())\n+\t\tformatMap[pixelformat] = enumSizes(pixelformat);\n+\n+\treturn V4L2DeviceFormats(formatMap);\n+}\n+\n int V4L2Device::requestBuffers(unsigned int count)\n {\n \tstruct v4l2_requestbuffers rb = {};\n@@ -692,6 +709,93 @@ int V4L2Device::createPlane(Buffer *buffer, unsigned int planeIndex,\n \n \treturn 0;\n }\n+std::vector<unsigned int> V4L2Device::enumPixelformats()\n+{\n+\tstd::vector<unsigned int> pixelformats;\n+\tint ret;\n+\n+\tfor (unsigned int index = 0;; index++) {\n+\t\tstruct v4l2_fmtdesc pixelformatEnum = {\n+\t\t\t.index = index,\n+\t\t\t.type = bufferType_,\n+\t\t};\n+\n+\t\tret = ioctl(fd_, VIDIOC_ENUM_FMT, &pixelformatEnum);\n+\t\tif (ret)\n+\t\t\tbreak;\n+\n+\t\tpixelformats.push_back(pixelformatEnum.pixelformat);\n+\t}\n+\n+\tif (ret && errno != EINVAL) {\n+\t\tret = errno;\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Unable to enumerate pixelformats: \"\n+\t\t\t<< strerror(ret);\n+\t\treturn {};\n+\t}\n+\n+\treturn pixelformats;\n+}\n+\n+std::vector<SizeRange> V4L2Device::enumSizes(unsigned int pixelformat)\n+{\n+\tstd::vector<SizeRange> sizes;\n+\tint ret;\n+\n+\tfor (unsigned int index = 0;; index++) {\n+\t\tstruct v4l2_frmsizeenum frameSize = {\n+\t\t\t.index = index,\n+\t\t\t.pixel_format = pixelformat,\n+\t\t};\n+\n+\t\tret = ioctl(fd_, VIDIOC_ENUM_FRAMESIZES, &frameSize);\n+\t\tif (ret)\n+\t\t\tbreak;\n+\n+\t\tif (index != 0 &&\n+\t\t    frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) {\n+\t\t\tLOG(V4L2, Error)\n+\t\t\t\t<< \"None 0 index for none discrete type\";\n+\t\t\treturn {};\n+\t\t}\n+\n+\t\tswitch (frameSize.type) {\n+\t\tcase V4L2_FRMSIZE_TYPE_DISCRETE:\n+\t\t\tsizes.emplace_back(frameSize.discrete.width,\n+\t\t\t\t\t   frameSize.discrete.height);\n+\t\t\tbreak;\n+\t\tcase V4L2_FRMSIZE_TYPE_CONTINUOUS:\n+\t\t\tsizes.emplace_back(frameSize.stepwise.min_width,\n+\t\t\t\t\t   frameSize.stepwise.min_height,\n+\t\t\t\t\t   frameSize.stepwise.max_width,\n+\t\t\t\t\t   frameSize.stepwise.max_height);\n+\t\t\tbreak;\n+\t\tcase V4L2_FRMSIZE_TYPE_STEPWISE:\n+\t\t\tsizes.emplace_back(frameSize.stepwise.min_width,\n+\t\t\t\t\t   frameSize.stepwise.min_height,\n+\t\t\t\t\t   frameSize.stepwise.max_width,\n+\t\t\t\t\t   frameSize.stepwise.max_height,\n+\t\t\t\t\t   frameSize.stepwise.step_width,\n+\t\t\t\t\t   frameSize.stepwise.step_height);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tLOG(V4L2, Error)\n+\t\t\t\t<< \"Unkown VIDIOC_ENUM_FRAMESIZES type \"\n+\t\t\t\t<< frameSize.type;\n+\t\t\treturn {};\n+\t\t}\n+\t}\n+\n+\tif (ret && errno != EINVAL) {\n+\t\tret = errno;\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Unable to enumerate frame sizes: \" << strerror(ret);\n+\t\treturn {};\n+\t}\n+\n+\treturn sizes;\n+}\n \n /**\n  * \\brief Import the externally allocated \\a pool of buffers\n",
    "prefixes": [
        "libcamera-devel",
        "09/17"
    ]
}