Show a patch.

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

{
    "id": 263,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/263/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/263/",
    "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": "<20190117212703.24047-2-kieran.bingham@ideasonboard.com>",
    "date": "2019-01-17T21:27:02",
    "name": "[libcamera-devel,v4,1/2] libcamera: Add V4L2 Device object",
    "commit_ref": "e74f3eebb498634f438a005b2ad5b7f1778091e8",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "9e69bae29a82953159abe78738d484089b28468d",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/1.1/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/263/mbox/",
    "series": [
        {
            "id": 88,
            "url": "https://patchwork.libcamera.org/api/1.1/series/88/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=88",
            "date": "2019-01-17T21:27:01",
            "name": "V4L2Device: Add basic V4L2 support class",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/88/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/263/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/263/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<kieran.bingham@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 378E460B2D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Jan 2019 22:27:13 +0100 (CET)",
            "from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C05C558;\n\tThu, 17 Jan 2019 22:27:12 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1547760432;\n\tbh=A8JNgNUlYnLyREN59ZNVcnvf24lef7ofOfejK95ChjU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=XbbONCZV2UOVl8ChzWm6Fa/sExznugzIF9buTCIC+JyAKc0Z8gi9GR2WfwpURhxy4\n\tZbYm1mVhwA78e/ILqXyQEUt8d1DIWwOb3nce/D8QyKXi4dYho21Wn7hVSSl6Bwvj16\n\txkItOLnhjxUzoCerA4/ad2WJnaFxi0uxfwkMQX1s=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Thu, 17 Jan 2019 21:27:02 +0000",
        "Message-Id": "<20190117212703.24047-2-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20190117212703.24047-1-kieran.bingham@ideasonboard.com>",
        "References": "<20190117212703.24047-1-kieran.bingham@ideasonboard.com>",
        "Subject": "[libcamera-devel] [PATCH v4 1/2] libcamera: Add V4L2 Device object",
        "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": "Thu, 17 Jan 2019 21:27:13 -0000"
    },
    "content": "Provide a helper V4L2 device object capable of interacting with the\nV4L2 Linux Kernel APIs.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/v4l2_device.h |  60 +++++++++\n src/libcamera/meson.build           |   2 +\n src/libcamera/v4l2_device.cpp       | 186 ++++++++++++++++++++++++++++\n 3 files changed, 248 insertions(+)\n create mode 100644 src/libcamera/include/v4l2_device.h\n create mode 100644 src/libcamera/v4l2_device.cpp",
    "diff": "diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nnew file mode 100644\nindex 000000000000..474c05b58cef\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -0,0 +1,60 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_device.h - V4L2 Device\n+ */\n+#ifndef __LIBCAMERA_V4L2_DEVICE_H__\n+#define __LIBCAMERA_V4L2_DEVICE_H__\n+\n+#include <string>\n+\n+#include <linux/videodev2.h>\n+\n+namespace libcamera {\n+\n+struct V4L2Capability final : v4l2_capability {\n+\tconst char *driver() const\n+\t{\n+\t\treturn reinterpret_cast<const char *>(v4l2_capability::driver);\n+\t}\n+\tconst char *card() const\n+\t{\n+\t\treturn reinterpret_cast<const char *>(v4l2_capability::card);\n+\t}\n+\tconst char *bus_info() const\n+\t{\n+\t\treturn reinterpret_cast<const char *>(v4l2_capability::bus_info);\n+\t}\n+\n+\tbool isCapture() const { return capabilities & V4L2_CAP_VIDEO_CAPTURE; }\n+\tbool isOutput() const { return capabilities & V4L2_CAP_VIDEO_OUTPUT; }\n+\tbool hasStreaming() const { return capabilities & V4L2_CAP_STREAMING; }\n+};\n+\n+class V4L2Device\n+{\n+public:\n+\tV4L2Device(const std::string &devnode);\n+\tV4L2Device(const V4L2Device &) = delete;\n+\t~V4L2Device();\n+\n+\tvoid operator=(const V4L2Device &) = delete;\n+\n+\tint open();\n+\tbool isOpen() const;\n+\tvoid close();\n+\n+\tconst char *driverName() const { return caps_.driver(); }\n+\tconst char *deviceName() const { return caps_.card(); }\n+\tconst char *busName() const { return caps_.bus_info(); }\n+\n+private:\n+\tstd::string devnode_;\n+\tint fd_;\n+\tV4L2Capability caps_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_V4L2_DEVICE_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex abf9a71d4172..f9f25c0ecf15 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -11,6 +11,7 @@ libcamera_sources = files([\n     'pipeline_handler.cpp',\n     'signal.cpp',\n     'timer.cpp',\n+    'v4l2_device.cpp',\n ])\n \n libcamera_headers = files([\n@@ -21,6 +22,7 @@ libcamera_headers = files([\n     'include/media_object.h',\n     'include/pipeline_handler.h',\n     'include/utils.h',\n+    'include/v4l2_device.h',\n ])\n \n libcamera_internal_includes =  include_directories('include')\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nnew file mode 100644\nindex 000000000000..54b53de37510\n--- /dev/null\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -0,0 +1,186 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_device.cpp - V4L2 Device\n+ */\n+\n+#include <fcntl.h>\n+#include <string.h>\n+#include <sys/ioctl.h>\n+#include <sys/mman.h>\n+#include <unistd.h>\n+\n+#include \"log.h\"\n+#include \"v4l2_device.h\"\n+\n+/**\n+ * \\file v4l2_device.h\n+ * \\brief V4L2 Device API\n+ */\n+namespace libcamera {\n+\n+/**\n+ * \\struct V4L2Capability\n+ * \\brief struct v4l2_capability object wrapper and helpers\n+ *\n+ * The V4L2Capability structure manages the information returned by the\n+ * VIDIOC_QUERYCAP ioctl.\n+ */\n+\n+/**\n+ * \\fn const char *V4L2Capability::driver()\n+ * \\brief Retrieve the driver module name\n+ * \\return The string containing the name of the driver module\n+ */\n+\n+/**\n+ * \\fn const char *V4L2Capability::card()\n+ * \\brief Retrieve the device card name\n+ * \\return The string containing the device name\n+ */\n+\n+/**\n+ * \\fn const char *V4L2Capability::bus_info()\n+ * \\brief Retrieve the location of the device in the system\n+ * \\return The string containing the device location\n+ */\n+\n+/**\n+ * \\fn bool V4L2Capability::isCapture()\n+ * \\brief Identify if the device is capable of capturing video\n+ * \\return True if the device can capture video frames\n+ */\n+\n+/**\n+ * \\fn bool V4L2Capability::isOutput()\n+ * \\brief Identify if the device is capable of outputting video\n+ * \\return True if the device can output video frames\n+ */\n+\n+/**\n+ * \\fn bool V4L2Capability::hasStreaming()\n+ * \\brief Determine if the device can perform Streaming I/O\n+ * \\return True if the device provides Streaming I/O IOCTLs\n+ */\n+\n+/**\n+ * \\class V4L2Device\n+ * \\brief V4L2Device object and API\n+ *\n+ * The V4L2 Device API class models an instance of a V4L2 device node.\n+ * It is constructed with the path to a V4L2 video device node. The device node\n+ * is only opened upon a call to open() which must be checked for success.\n+ *\n+ * The device capabilities are validated when the device is opened and the\n+ * device is rejected if it is not a suitable V4L2 capture or output device, or\n+ * if the device does not support streaming I/O.\n+ *\n+ * No API call other than open(), isOpen() and close() shall be called on an\n+ * unopened device instance.\n+ *\n+ * Upon destruction any device left open will be closed, and any resources\n+ * released.\n+ */\n+\n+/**\n+ * \\brief Construct a V4L2Device\n+ * \\param devnode The file-system path to the video device node\n+ */\n+V4L2Device::V4L2Device(const std::string &devnode)\n+\t: devnode_(devnode), fd_(-1)\n+{\n+}\n+\n+V4L2Device::~V4L2Device()\n+{\n+\tclose();\n+}\n+\n+/**\n+ * \\brief Open a V4L2 device and query its capabilities\n+ * \\return 0 on success, or a negative error code otherwise\n+ */\n+int V4L2Device::open()\n+{\n+\tint ret;\n+\n+\tif (isOpen()) {\n+\t\tLOG(Error) << \"Device already open\";\n+\t\treturn -EBUSY;\n+\t}\n+\n+\tret = ::open(devnode_.c_str(), O_RDWR);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Failed to open V4L2 device '\" << devnode_\n+\t\t\t   << \"': \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\tfd_ = ret;\n+\n+\tret = ioctl(fd_, VIDIOC_QUERYCAP, &caps_);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(Error) << \"Failed to query device capabilities: \"\n+\t\t\t   << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tLOG(Debug) << \"Opened '\" << devnode_ << \"' \"\n+\t\t   << caps_.bus_info() << \": \" << caps_.driver()\n+\t\t   << \": \" << caps_.card();\n+\n+\tif (!caps_.isCapture() && !caps_.isOutput()) {\n+\t\tLOG(Debug) << \"Device is not a supported type\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!caps_.hasStreaming()) {\n+\t\tLOG(Error) << \"Device does not support streaming I/O\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Check if device is successfully opened\n+ * \\return True if the device is open, false otherwise\n+ */\n+bool V4L2Device::isOpen() const\n+{\n+\treturn fd_ != -1;\n+}\n+\n+/**\n+ * \\brief Close the device, releasing any resources acquired by open()\n+ */\n+void V4L2Device::close()\n+{\n+\tif (fd_ < 0)\n+\t\treturn;\n+\n+\t::close(fd_);\n+\tfd_ = -1;\n+}\n+\n+/**\n+ * \\fn const char *V4L2Device::driverName()\n+ * \\brief Retrieve the name of the V4L2 device driver\n+ * \\return The string containing the driver name\n+ */\n+\n+/**\n+ * \\fn const char *V4L2Device::deviceName()\n+ * \\brief Retrieve the name of the V4L2 device\n+ * \\return The string containing the device name\n+ */\n+\n+/**\n+ * \\fn const char *V4L2Device::busName()\n+ * \\brief Retrieve the location of the device in the system\n+ * \\return The string containing the device location\n+ */\n+\n+} /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "1/2"
    ]
}