{"id":1419,"url":"https://patchwork.libcamera.org/api/patches/1419/?format=json","web_url":"https://patchwork.libcamera.org/patch/1419/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190612163604.10037-3-jacopo@jmondi.org>","date":"2019-06-12T16:36:04","name":"[libcamera-devel,v3,2/2] libcamera: Introduce V4L2Device base class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"deda99e4dbf8b98ace7da067e2f041cd184f01c3","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1419/mbox/","series":[{"id":354,"url":"https://patchwork.libcamera.org/api/series/354/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=354","date":"2019-06-12T16:36:02","name":"libcamera: Introduce V4L2Device base class","version":3,"mbox":"https://patchwork.libcamera.org/series/354/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1419/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1419/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9FD5061DE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 12 Jun 2019 18:35:01 +0200 (CEST)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay5-d.mail.gandi.net (Postfix) with ESMTPSA id D56631C0011;\n\tWed, 12 Jun 2019 16:35:00 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 12 Jun 2019 18:36:04 +0200","Message-Id":"<20190612163604.10037-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190612163604.10037-1-jacopo@jmondi.org>","References":"<20190612163604.10037-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 2/2] libcamera: Introduce V4L2Device\n\tbase class","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":"Wed, 12 Jun 2019 16:35:02 -0000"},"content":"he V4L2 devices and subdevices share a few common operations,like\nopening and closing a device node, and perform IOCTLs on the device.\n\nWith the forthcoming introduction of support for V4L2 controls, the\nquantity of shared code will drastically increase, as the control\nimplementation is identical for the two.\n\nTo maximize code re-use and avoid duplications, provide a V4L2Device\nbase class which groups the common operations and members.\n\nThe newly introduced base class provides methods to open/close a device\nnode, access the file descriptor, and perform IOCTLs on the device.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/v4l2_device.h      |  36 ++++++\n src/libcamera/include/v4l2_subdevice.h   |   6 +-\n src/libcamera/include/v4l2_videodevice.h |   5 +-\n src/libcamera/meson.build                |   2 +\n src/libcamera/v4l2_device.cpp            | 148 +++++++++++++++++++++++\n src/libcamera/v4l2_subdevice.cpp         |  69 +++--------\n src/libcamera/v4l2_videodevice.cpp       |  82 ++++---------\n 7 files changed, 227 insertions(+), 121 deletions(-)\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..584a570a4703\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -0,0 +1,36 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_device.h - Common base for V4L2 video devices and subdevices\n+ */\n+#ifndef __LIBCAMERA_V4L2_DEVICE_H__\n+#define __LIBCAMERA_V4L2_DEVICE_H__\n+\n+#include <string>\n+\n+namespace libcamera {\n+\n+class V4L2Device\n+{\n+public:\n+\tvirtual ~V4L2Device() { close(); }\n+\n+protected:\n+\tV4L2Device();\n+\n+\tint fd() { return fd_; }\n+\n+\tint open(const std::string &pathname, unsigned int flags);\n+\tint close();\n+\tbool isOpen() const;\n+\n+\tint ioctl(unsigned long request, void *argp);\n+\n+private:\n+\tint fd_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_V4L2_DEVICE_H__ */\ndiff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex 3e4e5107aebe..a34b719f8c52 100644\n--- a/src/libcamera/include/v4l2_subdevice.h\n+++ b/src/libcamera/include/v4l2_subdevice.h\n@@ -16,6 +16,7 @@\n #include \"formats.h\"\n #include \"log.h\"\n #include \"media_object.h\"\n+#include \"v4l2_device.h\"\n \n namespace libcamera {\n \n@@ -28,7 +29,7 @@ struct V4L2SubdeviceFormat {\n \tconst std::string toString() const;\n };\n \n-class V4L2Subdevice : protected Loggable\n+class V4L2Subdevice : public V4L2Device, protected Loggable\n {\n public:\n \texplicit V4L2Subdevice(const MediaEntity *entity);\n@@ -37,8 +38,6 @@ public:\n \t~V4L2Subdevice();\n \n \tint open();\n-\tbool isOpen() const;\n-\tvoid close();\n \n \tconst MediaEntity *entity() const { return entity_; }\n \n@@ -64,7 +63,6 @@ private:\n \t\t\t Rectangle *rect);\n \n \tconst MediaEntity *entity_;\n-\tint fd_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex 6ecdb64e5f3c..15a83635b9bf 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -17,6 +17,7 @@\n #include <libcamera/signal.h>\n \n #include \"log.h\"\n+#include \"v4l2_device.h\"\n \n namespace libcamera {\n \n@@ -111,7 +112,7 @@ public:\n \tconst std::string toString() const;\n };\n \n-class V4L2VideoDevice : protected Loggable\n+class V4L2VideoDevice : public V4L2Device, protected Loggable\n {\n public:\n \texplicit V4L2VideoDevice(const std::string &deviceNode);\n@@ -122,7 +123,6 @@ public:\n \tV4L2VideoDevice &operator=(const V4L2VideoDevice &) = delete;\n \n \tint open();\n-\tbool isOpen() const;\n \tvoid close();\n \n \tconst char *driverName() const { return caps_.driver(); }\n@@ -167,7 +167,6 @@ private:\n \tvoid bufferAvailable(EventNotifier *notifier);\n \n \tstd::string deviceNode_;\n-\tint fd_;\n \tV4L2Capability caps_;\n \n \tenum v4l2_buf_type bufferType_;\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 15ab53b1abbe..f26ad5b2dc57 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -23,6 +23,7 @@ libcamera_sources = files([\n     'stream.cpp',\n     'timer.cpp',\n     'utils.cpp',\n+    'v4l2_device.cpp',\n     'v4l2_subdevice.cpp',\n     'v4l2_videodevice.cpp',\n ])\n@@ -41,6 +42,7 @@ libcamera_headers = files([\n     'include/media_object.h',\n     'include/pipeline_handler.h',\n     'include/utils.h',\n+    'include/v4l2_device.h',\n     'include/v4l2_subdevice.h',\n     'include/v4l2_videodevice.h',\n ])\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nnew file mode 100644\nindex 000000000000..bddd10e6f83c\n--- /dev/null\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -0,0 +1,148 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_device.cpp - Common base for V4L2 devices and subdevices\n+ */\n+\n+#include \"v4l2_device.h\"\n+\n+#include <fcntl.h>\n+#include <string.h>\n+#include <sys/ioctl.h>\n+#include <unistd.h>\n+\n+#include \"log.h\"\n+\n+/**\n+ * \\file v4l2_device.h\n+ * \\brief Common base for V4L2 devices and subdevices\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(V4L2)\n+\n+/**\n+ * \\class V4L2Device\n+ * \\brief Base class for V4L2Videodev and V4L2Subdev\n+ *\n+ * The V4L2Device class groups together the methods and fields common to\n+ * both V4L2Videodev and V4L2Subdev, and provide a base class which\n+ * provides methods to open and close the device node associated with the\n+ * device and to perform IOCTL system calls on it.\n+ *\n+ * The V4L2Device class cannot be instantiated directly, as its constructor\n+ * is protected. Users should use instead one the derived classes to model\n+ * either a V4L2 video device or a V4L2 subdevice.\n+ */\n+\n+/**\n+ * \\brief Construct a V4L2Device\n+ *\n+ * The V4L2Device constructor is protected and can only be accessed by the\n+ * V4L2Videodev and V4L2Subdev derived classes.\n+ *\n+ * Initialize the file descriptor to -1.\n+ */\n+V4L2Device::V4L2Device()\n+\t: fd_(-1)\n+{\n+}\n+\n+/**\n+ * \\fn V4L2Device::fd()\n+ * \\brief Retrieve the V4L2 device file descriptor\n+ * \\return The V4L2 device file descriptor, -1 if the device node is not open\n+ */\n+\n+/**\n+ * \\brief Open a V4L2 device node\n+ * \\param pathname The filesystem path of the device node to open\n+ * \\param flags Access mode flags\n+ *\n+ * Initialize the file descriptor, which was initially set to -1.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Device::open(const std::string &pathname, unsigned int flags)\n+{\n+\tif (isOpen()) {\n+\t\tLOG(V4L2, Error) << \"Device already open\";\n+\t\treturn -EBUSY;\n+\t}\n+\n+\tint ret = ::open(pathname.c_str(), flags);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2, Error) << \"Failed to open V4L2 device: \"\n+\t\t\t\t << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tfd_ = ret;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Close the device node\n+ *\n+ * Reset the file descriptor to -1\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Device::close()\n+{\n+\tif (fd_ < 0)\n+\t\treturn 0;\n+\n+\tint ret = ::close(fd_);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(V4L2, Error) << \"Failed to close V4L2 device: \"\n+\t\t\t\t << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tfd_ = -1;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Check if the V4L2 device node is open\n+ * \\return True if the V4L2 device node is open, false otherwise\n+ */\n+bool V4L2Device::isOpen() const\n+{\n+\treturn fd_ != -1;\n+}\n+\n+/**\n+ * \\brief Perform an IOCTL system call on the device node\n+ * \\param request The IOCTL request code\n+ * \\param argp A pointer to the IOCTL argument\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Device::ioctl(unsigned long request, void *argp)\n+{\n+\t/*\n+\t * Printing out an error message is usually better performed\n+\t * in the caller, which can provide more context.\n+\t */\n+\tif (::ioctl(fd_, request, argp) < 0)\n+\t\treturn -errno;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\var V4L2Device::fd_\n+ * \\brief The V4L2 device node file descriptor\n+ *\n+ * The file descriptor is initialized to -1 and reset to this value once\n+ * the device node gets closed.\n+ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 6681c1920065..52244d2ac3e1 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -29,7 +29,7 @@\n \n namespace libcamera {\n \n-LOG_DEFINE_CATEGORY(V4L2Subdev)\n+LOG_DECLARE_CATEGORY(V4L2)\n \n /**\n  * \\struct V4L2SubdeviceFormat\n@@ -102,7 +102,7 @@ const std::string V4L2SubdeviceFormat::toString() const\n  * path\n  */\n V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)\n-\t: entity_(entity), fd_(-1)\n+\t: V4L2Device(), entity_(entity)\n {\n }\n \n@@ -117,45 +117,7 @@ V4L2Subdevice::~V4L2Subdevice()\n  */\n int V4L2Subdevice::open()\n {\n-\tint ret;\n-\n-\tif (isOpen()) {\n-\t\tLOG(V4L2Subdev, Error) << \"Device already open\";\n-\t\treturn -EBUSY;\n-\t}\n-\n-\tret = ::open(entity_->deviceNode().c_str(), O_RDWR);\n-\tif (ret < 0) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2Subdev, Error)\n-\t\t\t<< \"Failed to open V4L2 subdevice '\"\n-\t\t\t<< entity_->deviceNode() << \"': \" << strerror(-ret);\n-\t\treturn ret;\n-\t}\n-\tfd_ = ret;\n-\n-\treturn 0;\n-}\n-\n-/**\n- * \\brief Check if the subdevice is open\n- * \\return True if the subdevice is open, false otherwise\n- */\n-bool V4L2Subdevice::isOpen() const\n-{\n-\treturn fd_ != -1;\n-}\n-\n-/**\n- * \\brief Close the subdevice, releasing any resources acquired by open()\n- */\n-void V4L2Subdevice::close()\n-{\n-\tif (!isOpen())\n-\t\treturn;\n-\n-\t::close(fd_);\n-\tfd_ = -1;\n+\treturn V4L2Device::open(entity_->deviceNode(), O_RDWR);\n }\n \n /**\n@@ -207,7 +169,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n \tint ret;\n \n \tif (pad >= entity_->pads().size()) {\n-\t\tLOG(V4L2Subdev, Error) << \"Invalid pad: \" << pad;\n+\t\tLOG(V4L2, Error) << \"Invalid pad: \" << pad;\n \t\treturn formatMap;\n \t}\n \n@@ -215,7 +177,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n \tmbusEnum.index = 0;\n \tmbusEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n \twhile (true) {\n-\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n+\t\tret = ioctl(VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n \t\tif (ret)\n \t\t\tbreak;\n \n@@ -229,7 +191,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n \n \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n \t\tret = -errno;\n-\t\tLOG(V4L2Subdev, Error)\n+\t\tLOG(V4L2, Error)\n \t\t\t<< \"Unable to enumerate formats on pad \" << pad\n \t\t\t<< \": \" << strerror(-ret);\n \t\tformatMap.clear();\n@@ -250,10 +212,9 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n \tsubdevFmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n \tsubdevFmt.pad = pad;\n \n-\tint ret = ioctl(fd_, VIDIOC_SUBDEV_G_FMT, &subdevFmt);\n+\tint ret = ioctl(VIDIOC_SUBDEV_G_FMT, &subdevFmt);\n \tif (ret) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2Subdev, Error)\n+\t\tLOG(V4L2, Error)\n \t\t\t<< \"Unable to get format on pad \" << pad\n \t\t\t<< \": \" << strerror(-ret);\n \t\treturn ret;\n@@ -286,10 +247,9 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n \tsubdevFmt.format.height = format->size.height;\n \tsubdevFmt.format.code = format->mbus_code;\n \n-\tint ret = ioctl(fd_, VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n+\tint ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n \tif (ret) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2Subdev, Error)\n+\t\tLOG(V4L2, Error)\n \t\t\t<< \"Unable to set format on pad \" << pad\n \t\t\t<< \": \" << strerror(-ret);\n \t\treturn ret;\n@@ -339,7 +299,7 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n \tsizeEnum.code = code;\n \tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n \twhile (true) {\n-\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n+\t\tret = ioctl(VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n \t\tif (ret)\n \t\t\tbreak;\n \n@@ -351,7 +311,7 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n \n \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n \t\tret = -errno;\n-\t\tLOG(V4L2Subdev, Error)\n+\t\tLOG(V4L2, Error)\n \t\t\t<< \"Unable to enumerate sizes on pad \" << pad\n \t\t\t<< \": \" << strerror(-ret);\n \t\tsizes->clear();\n@@ -377,10 +337,9 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n \tsel.r.width = rect->w;\n \tsel.r.height = rect->h;\n \n-\tint ret = ioctl(fd_, VIDIOC_SUBDEV_S_SELECTION, &sel);\n+\tint ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);\n \tif (ret < 0) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2Subdev, Error)\n+\t\tLOG(V4L2, Error)\n \t\t\t<< \"Unable to set rectangle \" << target << \" on pad \"\n \t\t\t<< pad << \": \" << strerror(-ret);\n \t\treturn ret;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 8957cf8f97d3..bc5b306e5ca3 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -30,7 +30,7 @@\n  */\n namespace libcamera {\n \n-LOG_DEFINE_CATEGORY(V4L2)\n+LOG_DECLARE_CATEGORY(V4L2)\n \n /**\n  * \\struct V4L2Capability\n@@ -270,7 +270,7 @@ const std::string V4L2DeviceFormat::toString() const\n  * \\param[in] deviceNode The file-system path to the video device node\n  */\n V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n-\t: deviceNode_(deviceNode), fd_(-1), bufferPool_(nullptr),\n+\t: V4L2Device(), deviceNode_(deviceNode), bufferPool_(nullptr),\n \t  queuedBuffersCount_(0), fdEvent_(nullptr)\n {\n \t/*\n@@ -305,23 +305,12 @@ int V4L2VideoDevice::open()\n {\n \tint ret;\n \n-\tif (isOpen()) {\n-\t\tLOG(V4L2, Error) << \"Device already open\";\n-\t\treturn -EBUSY;\n-\t}\n-\n-\tret = ::open(deviceNode_.c_str(), O_RDWR | O_NONBLOCK);\n-\tif (ret < 0) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2, Error)\n-\t\t\t<< \"Failed to open V4L2 device: \" << strerror(-ret);\n+\tret = V4L2Device::open(deviceNode_, O_RDWR | O_NONBLOCK);\n+\tif (ret < 0)\n \t\treturn ret;\n-\t}\n-\tfd_ = ret;\n \n-\tret = ioctl(fd_, VIDIOC_QUERYCAP, &caps_);\n+\tret = ioctl(VIDIOC_QUERYCAP, &caps_);\n \tif (ret < 0) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to query device capabilities: \"\n \t\t\t<< strerror(-ret);\n@@ -342,20 +331,20 @@ int V4L2VideoDevice::open()\n \t * (POLLIN), and write notifications for OUTPUT devices (POLLOUT).\n \t */\n \tif (caps_.isVideoCapture()) {\n-\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Read);\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\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\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\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@@ -368,28 +357,16 @@ int V4L2VideoDevice::open()\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 V4L2VideoDevice::isOpen() const\n-{\n-\treturn fd_ != -1;\n-}\n-\n /**\n  * \\brief Close the device, releasing any resources acquired by open()\n  */\n void V4L2VideoDevice::close()\n {\n-\tif (fd_ < 0)\n+\tif (fd() < 0)\n \t\treturn;\n \n \treleaseBuffers();\n \tdelete fdEvent_;\n-\n-\t::close(fd_);\n-\tfd_ = -1;\n }\n \n /**\n@@ -462,9 +439,8 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n \tint ret;\n \n \tv4l2Format.type = bufferType_;\n-\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n+\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n@@ -488,9 +464,8 @@ int V4L2VideoDevice::setFormatMeta(V4L2DeviceFormat *format)\n \tv4l2Format.type = bufferType_;\n \tpix->dataformat = format->fourcc;\n \tpix->buffersize = format->planes[0].size;\n-\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n+\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n@@ -516,9 +491,8 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n \tint ret;\n \n \tv4l2Format.type = bufferType_;\n-\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n+\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n@@ -554,9 +528,8 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format)\n \t\tpix->plane_fmt[i].sizeimage = format->planes[i].size;\n \t}\n \n-\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n+\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n@@ -584,9 +557,8 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n \tint ret;\n \n \tv4l2Format.type = bufferType_;\n-\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n+\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n@@ -613,9 +585,8 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n \tpix->pixelformat = format->fourcc;\n \tpix->bytesperline = format->planes[0].bpl;\n \tpix->field = V4L2_FIELD_NONE;\n-\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n+\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n \tif (ret) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n@@ -643,9 +614,8 @@ int V4L2VideoDevice::requestBuffers(unsigned int count)\n \trb.type = bufferType_;\n \trb.memory = memoryType_;\n \n-\tret = ioctl(fd_, VIDIOC_REQBUFS, &rb);\n+\tret = ioctl(VIDIOC_REQBUFS, &rb);\n \tif (ret < 0) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Unable to request \" << count << \" buffers: \"\n \t\t\t<< strerror(-ret);\n@@ -695,9 +665,8 @@ int V4L2VideoDevice::exportBuffers(BufferPool *pool)\n \t\tbuf.length = VIDEO_MAX_PLANES;\n \t\tbuf.m.planes = planes;\n \n-\t\tret = ioctl(fd_, VIDIOC_QUERYBUF, &buf);\n+\t\tret = ioctl(VIDIOC_QUERYBUF, &buf);\n \t\tif (ret < 0) {\n-\t\t\tret = -errno;\n \t\t\tLOG(V4L2, Error)\n \t\t\t\t<< \"Unable to query buffer \" << i << \": \"\n \t\t\t\t<< strerror(-ret);\n@@ -748,9 +717,8 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex,\n \texpbuf.plane = planeIndex;\n \texpbuf.flags = O_RDWR;\n \n-\tret = ioctl(fd_, VIDIOC_EXPBUF, &expbuf);\n+\tret = ioctl(VIDIOC_EXPBUF, &expbuf);\n \tif (ret < 0) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n \t\treturn ret;\n@@ -855,9 +823,8 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer)\n \n \tLOG(V4L2, Debug) << \"Queueing buffer \" << buf.index;\n \n-\tret = ioctl(fd_, VIDIOC_QBUF, &buf);\n+\tret = ioctl(VIDIOC_QBUF, &buf);\n \tif (ret < 0) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to queue buffer \" << buf.index << \": \"\n \t\t\t<< strerror(-ret);\n@@ -892,9 +859,8 @@ Buffer *V4L2VideoDevice::dequeueBuffer()\n \t\tbuf.m.planes = planes;\n \t}\n \n-\tret = ioctl(fd_, VIDIOC_DQBUF, &buf);\n+\tret = ioctl(VIDIOC_DQBUF, &buf);\n \tif (ret < 0) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to dequeue buffer: \" << strerror(-ret);\n \t\treturn nullptr;\n@@ -952,9 +918,8 @@ int V4L2VideoDevice::streamOn()\n {\n \tint ret;\n \n-\tret = ioctl(fd_, VIDIOC_STREAMON, &bufferType_);\n+\tret = ioctl(VIDIOC_STREAMON, &bufferType_);\n \tif (ret < 0) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to start streaming: \" << strerror(-ret);\n \t\treturn ret;\n@@ -975,9 +940,8 @@ int V4L2VideoDevice::streamOff()\n {\n \tint ret;\n \n-\tret = ioctl(fd_, VIDIOC_STREAMOFF, &bufferType_);\n+\tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n \tif (ret < 0) {\n-\t\tret = -errno;\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Failed to stop streaming: \" << strerror(-ret);\n \t\treturn ret;\n","prefixes":["libcamera-devel","v3","2/2"]}