Show a patch.

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

{
    "id": 246,
    "url": "https://patchwork.libcamera.org/api/patches/246/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/246/",
    "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": "<20190115231909.19893-3-kieran.bingham@ideasonboard.com>",
    "date": "2019-01-15T23:19:08",
    "name": "[libcamera-devel,v3,2/3] libcamera: Add V4L2 Device object",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "e3e19ed80a8936a4067feebe1eefc498166ba552",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/246/mbox/",
    "series": [
        {
            "id": 83,
            "url": "https://patchwork.libcamera.org/api/series/83/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=83",
            "date": "2019-01-15T23:19:06",
            "name": "V4L2Device: Add basic V4L2 support class",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/83/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/246/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/246/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 B833A60C99\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 16 Jan 2019 00:19:14 +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 4BC7459B;\n\tWed, 16 Jan 2019 00:19:14 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1547594354;\n\tbh=FQJYXug8xH804kBrb/lkuYcfnUl9OY4Jsv787CWa7rQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=R/r/mMAe2wjWPYu2+ZddSYVTM5iD6pul9eNq0n5Sb9rPkN5DCI+WJsmr96VAaVeMf\n\twTETCX1kXkaM3ko25CATeiNrxLEzjZxWemwfrUy/TBWaD/AKrbnBaVAUzz1N1yuuil\n\toexk8x10IMacLEMXCm8RVsBFlU/9IFbs6UaqVo6k=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Tue, 15 Jan 2019 23:19:08 +0000",
        "Message-Id": "<20190115231909.19893-3-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20190115231909.19893-1-kieran.bingham@ideasonboard.com>",
        "References": "<20190115231909.19893-1-kieran.bingham@ideasonboard.com>",
        "Subject": "[libcamera-devel] [PATCH v3 2/3] 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": "Tue, 15 Jan 2019 23:19:14 -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 |  45 +++++++++\n src/libcamera/meson.build           |   2 +\n src/libcamera/v4l2_device.cpp       | 150 ++++++++++++++++++++++++++++\n 3 files changed, 197 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..b0f5e9689654\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -0,0 +1,45 @@\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+class V4L2Capability : public v4l2_capability\n+{\n+public:\n+\tstd::string getDriver() const { return std::string((char *)driver); }\n+\tstd::string getCard() const { return std::string((char *)card); }\n+\n+\tbool isCapture() const { return capabilities & V4L2_CAP_VIDEO_CAPTURE; }\n+\tbool hasStreaming() const { return capabilities & V4L2_CAP_STREAMING; }\n+};\n+\n+class V4L2Device\n+{\n+public:\n+\tV4L2Device() = delete;\n+\tV4L2Device(const std::string &devnode);\n+\t~V4L2Device();\n+\n+\tint open();\n+\tbool isOpen() const;\n+\tvoid close();\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..8c49d3ff56e2\n--- /dev/null\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -0,0 +1,150 @@\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+ * \\class V4L2Capability\n+ * \\brief struct v4l2_capability object wrapper and helpers\n+ *\n+ * The V4L2Capability class manages the information returned by the\n+ * VIDIOC_QUERYCAP ioctl.\n+ */\n+\n+/**\n+ * \\fn std::string V4L2Capability::getDriver()\n+ * \\brief Retrieve the driver module name\n+ * \\return The string containing the name of the driver module\n+ */\n+\n+/**\n+ * \\fn std::string V4L2Capability::getCard()\n+ * \\brief Retrieve the device card name\n+ * \\return The string containing the device name\n+ */\n+\n+/**\n+ * \\fn bool V4L2Capability::isCapture()\n+ * \\brief Identify if the device is capable of capturing video\n+ * \\return boolean true if the device provides video frames\n+ */\n+\n+/**\n+ * \\fn bool V4L2Capability::hasStreaming()\n+ * \\brief Determine if the device can perform Streaming IO\n+ * \\return boolean true if the device provides Streaming IO 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 and the device is rejected if it is\n+ * not a suitable capture device.\n+ *\n+ * No API call (except 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 properties from the device.\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\tLOG(Error) << \"Failed to query device capabilities: \" << strerror(errno);\n+\t\treturn -errno;\n+\t}\n+\n+\tLOG(Debug) << \"Opened '\" << devnode_ << \"' \" << caps_.getDriver() << \": \" << caps_.getCard();\n+\n+\tif (!(caps_.isCapture())) {\n+\t\tLOG(Error) << \"Device is not a capture device\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!(caps_.hasStreaming())) {\n+\t\tLOG(Error) << \"Device does not support streaming IO\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Check if device is successfully opened\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+} /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "2/3"
    ]
}