Show a patch.

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

{
    "id": 1752,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1752/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1752/",
    "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": "<20190808151221.24254-4-kieran.bingham@ideasonboard.com>",
    "date": "2019-08-08T15:12:18",
    "name": "[libcamera-devel,3/6] libcamera: v4l2_videodevice: Support M2M devices",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "895551b671e43912b8d4943f0a0972e3885ea84b",
    "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/1752/mbox/",
    "series": [
        {
            "id": 449,
            "url": "https://patchwork.libcamera.org/api/1.1/series/449/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=449",
            "date": "2019-08-08T15:12:15",
            "name": "V4L2 M2M Support (+RPi PoC)",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/449/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1752/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1752/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 30B46615FF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  8 Aug 2019 17:12:27 +0200 (CEST)",
            "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 90F76B7D;\n\tThu,  8 Aug 2019 17:12:26 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565277146;\n\tbh=HE+2iIf2jmH9xq9Ah+w8FOfgMN3VSOatszIlY4aDOxI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=BVMYsW5XvrSEA1zhfcTSzMPKrRdvR7ifqiFilymo2xIrm7IWeF0cHJLKdvNCNMWMQ\n\te+kBm/kMDeJvPYePAUd9Czja86IxgqtjF/VjaaoE29QJwyw+rhYmlqBkAR929ogPwe\n\tPX8uX+oJMCExJdcXa43P/NSlUBnHuHXjiNqv7pFg=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Thu,  8 Aug 2019 16:12:18 +0100",
        "Message-Id": "<20190808151221.24254-4-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190808151221.24254-1-kieran.bingham@ideasonboard.com>",
        "References": "<20190808151221.24254-1-kieran.bingham@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/6] libcamera: v4l2_videodevice: Support\n\tM2M devices",
        "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, 08 Aug 2019 15:12:27 -0000"
    },
    "content": "V4L2 M2M devices represent a V4L2Device with two queues. One output, and\none capture on a single device node.\n\nRepresent this by instantiating a V4L2VideoDevice for each queue type,\nand preparing each device for its queue.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/v4l2_videodevice.h |  26 ++-\n src/libcamera/v4l2_videodevice.cpp       | 200 ++++++++++++++++++++---\n 2 files changed, 201 insertions(+), 25 deletions(-)",
    "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex f5c8da93fcb5..24c58d787fde 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -71,6 +71,11 @@ struct V4L2Capability final : v4l2_capability {\n \t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT |\n \t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT_MPLANE);\n \t}\n+\tbool isM2M() const\n+\t{\n+\t\treturn device_caps() & (V4L2_CAP_VIDEO_M2M |\n+\t\t\t\t\tV4L2_CAP_VIDEO_M2M_MPLANE);\n+\t}\n \tbool isMeta() const\n \t{\n \t\treturn device_caps() & (V4L2_CAP_META_CAPTURE |\n@@ -123,7 +128,7 @@ public:\n \n \tV4L2VideoDevice &operator=(const V4L2VideoDevice &) = delete;\n \n-\tint open();\n+\tint open(int fd = -1, enum v4l2_buf_type type = V4L2_BUF_TYPE_PRIVATE);\n \tvoid close();\n \n \tconst char *driverName() const { return caps_.driver(); }\n@@ -152,6 +157,9 @@ protected:\n \tstd::string logPrefix() const;\n \n private:\n+\tint queryBufferType();\n+\tint queryBufferType(enum v4l2_buf_type type);\n+\n \tint getFormatMeta(V4L2DeviceFormat *format);\n \tint setFormatMeta(V4L2DeviceFormat *format);\n \n@@ -182,6 +190,22 @@ private:\n \tEventNotifier *fdEvent_;\n };\n \n+class V4L2M2MDevice\n+{\n+public:\n+\tV4L2M2MDevice(const std::string &deviceNode);\n+\t~V4L2M2MDevice();\n+\n+\tV4L2VideoDevice *output() { return output_; }\n+\tV4L2VideoDevice *capture() { return capture_; }\n+\tunsigned int status() { return status_; }\n+\n+private:\n+\tV4L2VideoDevice *output_;\n+\tV4L2VideoDevice *capture_;\n+\tunsigned int status_;\n+};\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_V4L2_VIDEODEVICE_H__ */\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 81098dd70190..4bd33af5f3de 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -89,6 +89,12 @@ LOG_DECLARE_CATEGORY(V4L2)\n  * \\return True if the video device can capture or output images\n  */\n \n+/**\n+ * \\fn V4L2Capability::isM2M()\n+ * \\brief Identify if the device is an M2M device\n+ * \\return True if the device can capture and output images using the M2M API\n+ */\n+\n /**\n  * \\fn V4L2Capability::isMeta()\n  * \\brief Identify if the video device captures or outputs image meta-data\n@@ -294,17 +300,80 @@ V4L2VideoDevice::~V4L2VideoDevice()\n \tclose();\n }\n \n+int V4L2VideoDevice::queryBufferType()\n+{\n+\tif (caps_.isVideoCapture()) {\n+\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\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+\t} else if (caps_.isVideoOutput()) {\n+\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\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+\t} else if (caps_.isMetaCapture()) {\n+\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\n+\t\tbufferType_ = V4L2_BUF_TYPE_META_CAPTURE;\n+\t} else if (caps_.isMetaOutput()) {\n+\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\n+\t\tbufferType_ = V4L2_BUF_TYPE_META_OUTPUT;\n+\t} else {\n+\t\tLOG(V4L2, Error) << \"Device is not a supported type\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int V4L2VideoDevice::queryBufferType(enum v4l2_buf_type type)\n+{\n+\tswitch (type) {\n+\tcase V4L2_BUF_TYPE_VIDEO_OUTPUT:\n+\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\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+\t\tbreak;\n+\tcase V4L2_BUF_TYPE_VIDEO_CAPTURE:\n+\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\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+\t\tbreak;\n+\tdefault:\n+\t\tLOG(V4L2, Error) << \"Unsupported buffer type\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Open a V4L2 video device and query its capabilities\n+ *\n+ * \\param[in] fd The file descriptor to set (optional)\n+ * \\param[in] type The device type to operate on (optional)\n+ *\n+ * Opens a device or sets the file descriptor if provided, and then queries the\n+ * capabilities of the device and establishes the buffer types and device events\n+ * accordingly.\n+ *\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2VideoDevice::open()\n+int V4L2VideoDevice::open(int fd, enum v4l2_buf_type type)\n {\n \tint ret;\n \n-\tret = V4L2Device::open(O_RDWR | O_NONBLOCK);\n-\tif (ret < 0)\n-\t\treturn ret;\n+\tif (fd != -1) {\n+\t\tret = V4L2Device::setFd(fd);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t} else {\n+\t\tret = V4L2Device::open(O_RDWR | O_NONBLOCK);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t}\n \n \tret = ioctl(VIDIOC_QUERYCAP, &caps_);\n \tif (ret < 0) {\n@@ -324,26 +393,10 @@ int V4L2VideoDevice::open()\n \t * devices (POLLIN), and write notifications for OUTPUT video devices\n \t * (POLLOUT).\n \t */\n-\tif (caps_.isVideoCapture()) {\n-\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\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-\t} else if (caps_.isVideoOutput()) {\n-\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\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-\t} else if (caps_.isMetaCapture()) {\n-\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\n-\t\tbufferType_ = V4L2_BUF_TYPE_META_CAPTURE;\n-\t} else if (caps_.isMetaOutput()) {\n-\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\n-\t\tbufferType_ = V4L2_BUF_TYPE_META_OUTPUT;\n-\t} else {\n-\t\tLOG(V4L2, Error) << \"Device is not a supported type\";\n-\t\treturn -EINVAL;\n-\t}\n+\tif (type != V4L2_BUF_TYPE_PRIVATE)\n+\t\tqueryBufferType(type);\n+\telse\n+\t\tqueryBufferType();\n \n \tfdEvent_->activated.connect(this, &V4L2VideoDevice::bufferAvailable);\n \tfdEvent_->setEnabled(false);\n@@ -1143,4 +1196,103 @@ V4L2VideoDevice *V4L2VideoDevice::fromEntityName(const MediaDevice *media,\n \treturn new V4L2VideoDevice(mediaEntity);\n }\n \n+/**\n+ * \\class V4L2M2MDevice\n+ * \\brief Memory2Memory device container\n+ *\n+ * The V4L2M2MDevice manages two V4L2Device instances on the same\n+ * deviceNode which operate together using two queues to implement the V4L2\n+ * Memory to Memory API.\n+ *\n+ * V4L2M2MDevices are opened at the point they are created, and will return\n+ * both a capture and an output device or neither in the event of failure.\n+ *\n+ * The two devices should be configured and started as normal V4L2Device\n+ * instances. Closing either of the devices will require recreating a new\n+ * V4L2M2MDevice.\n+ *\n+ * The two V4L2Device instances share a single device node which is opened at\n+ * the point the V4L2M2MDevice is created.\n+ */\n+\n+/**\n+ * \\fn V4L2M2MDevice::output\n+ * \\return The output V4L2Device instance\n+ */\n+\n+/**\n+ * \\fn V4L2M2MDevice::capture\n+ * \\return The capture V4L2Device instance\n+ */\n+\n+/**\n+ * \\fn V4L2M2MDevice::status\n+ * \\return The construction status of the V4L2M2MDevice\n+ */\n+\n+/**\n+ * \\brief Create a new V4L2M2MDevice from the \\a deviceNode\n+ *\n+ * The deviceNode will be opened and shared across two V4L2VideoDevice\n+ * instances. One to control the output stream, and one to control the capture\n+ * stream.\n+ *\n+ * After construction, the status() must be checked to validate the instance.\n+ */\n+V4L2M2MDevice::V4L2M2MDevice(const std::string &deviceNode)\n+\t: status_(0)\n+{\n+\tint fd[2] = { -1, -1 };\n+\tint ret;\n+\n+\toutput_ = new V4L2VideoDevice(deviceNode);\n+\tcapture_ = new V4L2VideoDevice(deviceNode);\n+\n+\t/* Both V4L2Devices will have the same deviceNode. */\n+\tfd[0] = ::open(deviceNode.c_str(), O_RDWR | O_NONBLOCK);\n+\tif (fd[0] < 0) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Failed to open V4L2 M2M device: \" << strerror(-ret);\n+\t\tgoto err;\n+\t}\n+\n+\tfd[1] = dup(fd[0]);\n+\tif (fd[1] < 0) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Failed to duplicate M2M device: \" << strerror(-ret);\n+\n+\t\tgoto err;\n+\t}\n+\n+\tret = output_->open(fd[0], V4L2_BUF_TYPE_VIDEO_OUTPUT);\n+\tif (ret)\n+\t\tgoto err;\n+\n+\tret = capture_->open(fd[1], V4L2_BUF_TYPE_VIDEO_CAPTURE);\n+\tif (ret)\n+\t\tgoto err;\n+\n+\treturn;\n+\n+err:\n+\tdelete capture_;\n+\tdelete output_;\n+\n+\tcapture_ = nullptr;\n+\toutput_ = nullptr;\n+\n+\tstatus_ = ret;\n+\n+\tclose(fd[1]);\n+\tclose(fd[0]);\n+}\n+\n+V4L2M2MDevice::~V4L2M2MDevice()\n+{\n+\tdelete capture_;\n+\tdelete output_;\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "3/6"
    ]
}