Show a patch.

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

{
    "id": 432,
    "url": "https://patchwork.libcamera.org/api/patches/432/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/432/",
    "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": "<20190128151137.31075-3-jacopo@jmondi.org>",
    "date": "2019-01-28T15:11:37",
    "name": "[libcamera-devel,2/2] libcamera: v4l2_device: Add methods to get/set format",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "b22bf3b2d3b6f90588d5febb5eed4e9c72e4e6a9",
    "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/432/mbox/",
    "series": [
        {
            "id": 152,
            "url": "https://patchwork.libcamera.org/api/series/152/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=152",
            "date": "2019-01-28T15:11:35",
            "name": "V4L2Device: Add get/set format support",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/152/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/432/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/432/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7361560DB8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Jan 2019 16:11:31 +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 relay10.mail.gandi.net (Postfix) with ESMTPSA id E3FD5240010;\n\tMon, 28 Jan 2019 15:11:30 +0000 (UTC)"
        ],
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 28 Jan 2019 16:11:37 +0100",
        "Message-Id": "<20190128151137.31075-3-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190128151137.31075-1-jacopo@jmondi.org>",
        "References": "<20190128151137.31075-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 2/2] libcamera: v4l2_device: Add methods\n\tto get/set format",
        "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, 28 Jan 2019 15:11:31 -0000"
    },
    "content": "Add methods to set and get the image format programmed on a V4L2Device\nfor both the single and multi planar use case.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_device.h |  10 +++\n src/libcamera/v4l2_device.cpp       | 128 ++++++++++++++++++++++++++++\n 2 files changed, 138 insertions(+)",
    "diff": "diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex c70959e..fe54220 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -86,10 +86,20 @@ public:\n \tconst char *deviceName() const { return caps_.card(); }\n \tconst char *busName() const { return caps_.bus_info(); }\n \n+\tint format(V4L2DeviceFormat *fmt);\n+\tint setFormat(V4L2DeviceFormat *fmt);\n+\n private:\n \tstd::string deviceNode_;\n \tint fd_;\n \tV4L2Capability caps_;\n+\tenum v4l2_buf_type bufferType_;\n+\n+\tint getFormatSingleplane(V4L2DeviceFormat *fmt);\n+\tint setFormatSingleplane(V4L2DeviceFormat *fmt);\n+\n+\tint getFormatMultiplane(V4L2DeviceFormat *fmt);\n+\tint setFormatMultiplane(V4L2DeviceFormat *fmt);\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex d6143f2..5c415d0 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -227,6 +227,15 @@ int V4L2Device::open()\n \t\treturn -EINVAL;\n \t}\n \n+\tif (caps_.isCapture())\n+\t\tbufferType_ = caps_.isMultiplanar()\n+\t\t\t    ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE\n+\t\t\t    : V4L2_BUF_TYPE_VIDEO_CAPTURE;\n+\telse\n+\t\tbufferType_ = caps_.isMultiplanar()\n+\t\t\t    ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE\n+\t\t\t    : V4L2_BUF_TYPE_VIDEO_OUTPUT;\n+\n \treturn 0;\n }\n \n@@ -269,4 +278,123 @@ void V4L2Device::close()\n  * \\return The string containing the device location\n  */\n \n+/**\n+ * \\brief Retrieve the image format set on the V4L2 device\n+ * \\return 0 for success, a negative error code otherwise\n+ */\n+int V4L2Device::format(V4L2DeviceFormat *fmt)\n+{\n+\treturn caps_.isMultiplanar() ? getFormatMultiplane(fmt) :\n+\t\t\t\t       getFormatSingleplane(fmt);\n+}\n+\n+/**\n+ * \\brief Configure an image format on the V4L2 device\n+ * \\return 0 for success, a negative error code otherwise\n+ */\n+int V4L2Device::setFormat(V4L2DeviceFormat *fmt)\n+{\n+\treturn caps_.isMultiplanar() ? setFormatMultiplane(fmt) :\n+\t\t\t\t       setFormatSingleplane(fmt);\n+}\n+\n+int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *fmt)\n+{\n+\tstruct v4l2_format v4l2Fmt;\n+\tstruct v4l2_pix_format *pix = &v4l2Fmt.fmt.pix;\n+\tint ret;\n+\n+\tv4l2Fmt.type = bufferType_;\n+\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Fmt);\n+\tif (ret) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Unable to get format: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tfmt->width = pix->width;\n+\tfmt->height = pix->height;\n+\tfmt->fourcc = pix->pixelformat;\n+\tfmt->planes = 1;\n+\tfmt->planesFmt[0].bpl = pix->bytesperline;\n+\tfmt->planesFmt[0].size = pix->sizeimage;\n+\n+\treturn 0;\n+}\n+\n+int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *fmt)\n+{\n+\tstruct v4l2_format v4l2Fmt;\n+\tstruct v4l2_pix_format *pix = &v4l2Fmt.fmt.pix;\n+\tint ret;\n+\n+\tv4l2Fmt.type = bufferType_;\n+\tpix->width = fmt->width;\n+\tpix->height = fmt->height;\n+\tpix->pixelformat = fmt->fourcc;\n+\n+\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Fmt);\n+\tif (ret) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Unable to set format: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int V4L2Device::getFormatMultiplane(V4L2DeviceFormat *fmt)\n+{\n+\tstruct v4l2_format v4l2Fmt;\n+\tstruct v4l2_pix_format_mplane *pix = &v4l2Fmt.fmt.pix_mp;\n+\tint ret;\n+\n+\tv4l2Fmt.type = bufferType_;\n+\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Fmt);\n+\tif (ret) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Unable to get format: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tfmt->width = pix->width;\n+\tfmt->height = pix->height;\n+\tfmt->fourcc = pix->pixelformat;\n+\tfmt->planes = pix->num_planes;\n+\n+\tfor (unsigned int i = 0; i < fmt->planes; ++i) {\n+\t\tfmt->planesFmt[i].bpl = pix->plane_fmt[i].bytesperline;\n+\t\tfmt->planesFmt[i].size = pix->plane_fmt[i].sizeimage;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *fmt)\n+{\n+\tstruct v4l2_format v4l2Fmt;\n+\tstruct v4l2_pix_format_mplane *pix = &v4l2Fmt.fmt.pix_mp;\n+\tint ret;\n+\n+\tv4l2Fmt.type = bufferType_;\n+\tpix->width = fmt->width;\n+\tpix->height = fmt->height;\n+\tpix->pixelformat = fmt->fourcc;\n+\tpix->num_planes = fmt->planes;\n+\n+\tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n+\t\tpix->plane_fmt[i].bytesperline = fmt->planesFmt[i].bpl;\n+\t\tpix->plane_fmt[i].sizeimage = fmt->planesFmt[i].size;\n+\t}\n+\n+\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Fmt);\n+\tif (ret) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Unable to set format: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "2/2"
    ]
}