Patch Detail
Show a patch.
GET /api/1.1/patches/1331/?format=api
{ "id": 1331, "url": "https://patchwork.libcamera.org/api/1.1/patches/1331/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1331/", "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": "<20190602130435.18780-3-jacopo@jmondi.org>", "date": "2019-06-02T13:04:31", "name": "[libcamera-devel,2/6] libcamera: Provide a V4L2Base class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "3290afe50c919dca8ea51e2f70e728703fe6f345", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": { "id": 15, "url": "https://patchwork.libcamera.org/api/1.1/users/15/?format=api", "username": "jmondi", "first_name": "Jacopo", "last_name": "Mondi", "email": "jacopo@jmondi.org" }, "mbox": "https://patchwork.libcamera.org/patch/1331/mbox/", "series": [ { "id": 333, "url": "https://patchwork.libcamera.org/api/1.1/series/333/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=333", "date": "2019-06-02T13:04:29", "name": "libcamera: v4l2_controls: Add support for V4L2 controls", "version": 1, "mbox": "https://patchwork.libcamera.org/series/333/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1331/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1331/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BC86360BFA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 2 Jun 2019 15:03:45 +0200 (CEST)", "from uno.homenet.telecomitalia.it (unknown [79.35.79.123])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id E76B6100005;\n\tSun, 2 Jun 2019 13:03:44 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 2 Jun 2019 15:04:31 +0200", "Message-Id": "<20190602130435.18780-3-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190602130435.18780-1-jacopo@jmondi.org>", "References": "<20190602130435.18780-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 2/6] libcamera: Provide a V4L2Base 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": "Sun, 02 Jun 2019 13:03:45 -0000" }, "content": "Provide a base class for V4L2 Devices and Subdevices to group common\nmethods and fields.\n\nAt the moment the code shared between V4L2Device and V4L2Subdevice is\nquite limited, but with the forthcoming introduction of control it will\ngrow consistently.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_base.h | 31 +++++++++++++\n src/libcamera/include/v4l2_device.h | 9 ++--\n src/libcamera/include/v4l2_subdevice.h | 9 ++--\n src/libcamera/meson.build | 2 +\n src/libcamera/v4l2_base.cpp | 64 ++++++++++++++++++++++++++\n src/libcamera/v4l2_device.cpp | 13 ++----\n src/libcamera/v4l2_subdevice.cpp | 12 +----\n 7 files changed, 110 insertions(+), 30 deletions(-)\n create mode 100644 src/libcamera/include/v4l2_base.h\n create mode 100644 src/libcamera/v4l2_base.cpp", "diff": "diff --git a/src/libcamera/include/v4l2_base.h b/src/libcamera/include/v4l2_base.h\nnew file mode 100644\nindex 000000000000..2fda81a960d2\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_base.h\n@@ -0,0 +1,31 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_base.h - Common base for V4L2 devices and subdevices\n+ */\n+#ifndef __LIBCAMERA_V4L2_BASE__\n+#define __LIBCAMERA_V4L2_BASE__\n+\n+#include <vector>\n+\n+namespace libcamera {\n+\n+class V4L2Base\n+{\n+public:\n+\tvirtual ~V4L2Base()\n+\t{\n+\t}\n+\n+\tvirtual int open() = 0;\n+\tvirtual void close() = 0;\n+\tbool isOpen() const;\n+\n+protected:\n+\tint fd_;\n+};\n+\n+}; /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_V4L2_BASE__ */\ndiff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex bdecc087fe5a..d9bcdb921b8c 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -17,6 +17,7 @@\n #include <libcamera/signal.h>\n \n #include \"log.h\"\n+#include \"v4l2_base.h\"\n \n namespace libcamera {\n \n@@ -111,7 +112,7 @@ public:\n \tconst std::string toString() const;\n };\n \n-class V4L2Device : protected Loggable\n+class V4L2Device : public V4L2Base, protected Loggable\n {\n public:\n \texplicit V4L2Device(const std::string &deviceNode);\n@@ -121,9 +122,8 @@ public:\n \n \tV4L2Device &operator=(const V4L2Device &) = delete;\n \n-\tint open();\n-\tbool isOpen() const;\n-\tvoid close();\n+\tint open() override;\n+\tvoid close() override;\n \n \tconst char *driverName() const { return caps_.driver(); }\n \tconst char *deviceName() const { return caps_.card(); }\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/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex 3e4e5107aebe..bdef3e69dd8c 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_base.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 V4L2Base, protected Loggable\n {\n public:\n \texplicit V4L2Subdevice(const MediaEntity *entity);\n@@ -36,9 +37,8 @@ public:\n \tV4L2Subdevice &operator=(const V4L2Subdevice &) = delete;\n \t~V4L2Subdevice();\n \n-\tint open();\n-\tbool isOpen() const;\n-\tvoid close();\n+\tint open() override;\n+\tvoid close() override;\n \n \tconst MediaEntity *entity() const { return entity_; }\n \n@@ -64,7 +64,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/meson.build b/src/libcamera/meson.build\nindex 6a73580d71f5..6d858a22531e 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -21,6 +21,7 @@ libcamera_sources = files([\n 'stream.cpp',\n 'timer.cpp',\n 'utils.cpp',\n+ 'v4l2_base.cpp',\n 'v4l2_device.cpp',\n 'v4l2_subdevice.cpp',\n ])\n@@ -38,6 +39,7 @@ libcamera_headers = files([\n 'include/media_object.h',\n 'include/pipeline_handler.h',\n 'include/utils.h',\n+ 'include/v4l2_base.h',\n 'include/v4l2_device.h',\n 'include/v4l2_subdevice.h',\n ])\ndiff --git a/src/libcamera/v4l2_base.cpp b/src/libcamera/v4l2_base.cpp\nnew file mode 100644\nindex 000000000000..7d05a3c82e4d\n--- /dev/null\n+++ b/src/libcamera/v4l2_base.cpp\n@@ -0,0 +1,64 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_base.cpp - Common base for V4L2 devices and subdevices\n+ */\n+\n+#include \"v4l2_base.h\"\n+\n+/**\n+ * \\file v4l2_base.h\n+ * \\brief Common base for V4L2 devices and subdevices\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class V4L2Base\n+ * \\brief Base class for V4L2Device and V4L2Subdevice\n+ *\n+ * The V4L2Base class groups together the methods and fields common to\n+ * both V4L2Device and V4L2Subdevice, and provide a base abstract class which\n+ * defines a streamlined interface that both the derived class have to implement.\n+ *\n+ * The interface defined by V4L2Base only requires derived classes to implement\n+ * methods that modifies the status of the file descriptor associated with\n+ * the video device or subdevice, such as \\a open() and \\a close().\n+ *\n+ * Methods common to V4L2Device and V4L2Subdevice, such as V4L2 controls\n+ * support are implemented in the base class to maximize code re-use.\n+ */\n+\n+/**\n+ * \\brief Open a V4L2 device or subdevice\n+ *\n+ * Pure virtual method to be implemented by the derived classes.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+\n+/**\n+ * \\brief Close the device or subdevice\n+ *\n+ * Pure virtual method to be implemented by the derived classes.\n+ */\n+\n+/**\n+ * \\brief Check if the V4L2 device or subdevice is open\n+ * \\return True if the V4L2 device or subdevice is open, false otherwise\n+ */\n+bool V4L2Base::isOpen() const\n+{\n+\treturn fd_ != -1;\n+}\n+\n+/**\n+ * \\var V4L2Base::fd_\n+ * \\brief The V4L2 device or subdevice device node file descriptor\n+ *\n+ * The file descriptor is initialized to -1 and reset to this value once\n+ * the device or subdevice gets closed.\n+ */\n+\n+}; /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 0821bd75fb42..64533e88a512 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -270,9 +270,11 @@ const std::string V4L2DeviceFormat::toString() const\n * \\param[in] deviceNode The file-system path to the video device node\n */\n V4L2Device::V4L2Device(const std::string &deviceNode)\n-\t: deviceNode_(deviceNode), fd_(-1), bufferPool_(nullptr),\n+\t: deviceNode_(deviceNode), bufferPool_(nullptr),\n \t queuedBuffersCount_(0), fdEvent_(nullptr)\n {\n+\tfd_ = -1;\n+\n \t/*\n \t * We default to an MMAP based CAPTURE device, however this will be\n \t * updated based upon the device capabilities.\n@@ -368,15 +370,6 @@ int V4L2Device::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 V4L2Device::isOpen() const\n-{\n-\treturn fd_ != -1;\n-}\n-\n /**\n * \\brief Close the device, releasing any resources acquired by open()\n */\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex fceee33156e9..3a053fadb3f6 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -102,8 +102,9 @@ const std::string V4L2SubdeviceFormat::toString() const\n * path\n */\n V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)\n-\t: entity_(entity), fd_(-1)\n+\t: entity_(entity)\n {\n+\tfd_ = -1;\n }\n \n V4L2Subdevice::~V4L2Subdevice()\n@@ -137,15 +138,6 @@ int V4L2Subdevice::open()\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", "prefixes": [ "libcamera-devel", "2/6" ] }