{"id":1413,"url":"https://patchwork.libcamera.org/api/patches/1413/?format=json","web_url":"https://patchwork.libcamera.org/patch/1413/","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":"<20190612104135.21719-1-jacopo@jmondi.org>","date":"2019-06-12T10:41:35","name":"[libcamera-devel] libcamera: Introduce V4L2Device base class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ef13602c143267f9e306d6c7bfc1d407e9a482a3","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/1413/mbox/","series":[{"id":352,"url":"https://patchwork.libcamera.org/api/series/352/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=352","date":"2019-06-12T10:41:35","name":"[libcamera-devel] libcamera: Introduce V4L2Device base class","version":1,"mbox":"https://patchwork.libcamera.org/series/352/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1413/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1413/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4086861E34\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 12 Jun 2019 12:40:31 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 94698240006;\n\tWed, 12 Jun 2019 10:40:29 +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 12:41:35 +0200","Message-Id":"<20190612104135.21719-1-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] libcamera: Introduce V4L2Device base 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 10:40:31 -0000"},"content":"The V4L2 devices and subdevices share a few common operations and fields,\nlike opening and closing a device node, and perform IOCTLs on the\ndevice's file descriptor. With the forthcoming introduction of support\nfor V4L2 controls, the quantity of shared code will drastically increase,\nas the control implementation 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, and perform a\ntree-wide rename of V4L2Device and V4L2Subdevice in V4L2Videodev and\nV4L2Subdev respectively.\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>\n---\nThis patch is big, and will get in the way of many of the currently in-review\nseries. At the same time, having a common base where to implement support for\nV4L2 controls is a requirement, and so I bit the bullet and went on the huge\nrenaming operation you have here implemented.\n\nI renamed V4L2Device->V4L2Videodev and V4L2Subdevice->V4L2Subdev everywhere.\nI intentionally left the V4L2DeviceFormat and V4L2SubdeviceFormat un-touched\nas Niklas' series is going to remove them, so there was not point of making\nthings more complex than necessary here.\n\nI'm sending this one alone, separately from the V4L2 control suppor, to fast\ntrack it and have it merged sooner than later. I know this will cause a lot\nof work in-flight to be rebased, I'm sorry about it, but sooner or later this\nhad to be done.\n\nThanks\n  j\n---\n\n include/libcamera/buffer.h                    |   2 +-\n src/libcamera/camera_sensor.cpp               |   4 +-\n src/libcamera/include/camera_sensor.h         |   4 +-\n src/libcamera/include/v4l2_device.h           | 170 +--\n .../{v4l2_subdevice.h => v4l2_subdev.h}       |  25 +-\n src/libcamera/include/v4l2_videodev.h         | 183 ++++\n src/libcamera/meson.build                     |   6 +-\n src/libcamera/pipeline/ipu3/ipu3.cpp          |  32 +-\n src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  16 +-\n src/libcamera/pipeline/uvcvideo.cpp           |   6 +-\n src/libcamera/pipeline/vimc.cpp               |   6 +-\n src/libcamera/v4l2_device.cpp                 | 983 ++---------------\n .../{v4l2_subdevice.cpp => v4l2_subdev.cpp}   | 100 +-\n src/libcamera/v4l2_videodev.cpp               | 992 ++++++++++++++++++\n test/meson.build                              |   4 +-\n .../list_formats.cpp                          |   6 +-\n .../meson.build                               |   8 +-\n .../test_formats.cpp                          |   6 +-\n .../v4l2_subdev_test.cpp}                     |  12 +-\n .../v4l2_subdev_test.h}                       |  10 +-\n .../buffer_sharing.cpp                        |  18 +-\n .../capture_async.cpp                         |   6 +-\n .../double_open.cpp                           |   8 +-\n .../formats.cpp                               |   8 +-\n .../meson.build                               |   8 +-\n .../request_buffers.cpp                       |   6 +-\n .../stream_on_off.cpp                         |   6 +-\n .../v4l2_videodev_test.cpp}                   |   8 +-\n .../v4l2_videodev_test.h}                     |   8 +-\n 29 files changed, 1397 insertions(+), 1254 deletions(-)\n rename src/libcamera/include/{v4l2_subdevice.h => v4l2_subdev.h} (67%)\n create mode 100644 src/libcamera/include/v4l2_videodev.h\n rename src/libcamera/{v4l2_subdevice.cpp => v4l2_subdev.cpp} (79%)\n create mode 100644 src/libcamera/v4l2_videodev.cpp\n rename test/{v4l2_subdevice => v4l2_subdev}/list_formats.cpp (95%)\n rename test/{v4l2_subdevice => v4l2_subdev}/meson.build (57%)\n rename test/{v4l2_subdevice => v4l2_subdev}/test_formats.cpp (93%)\n rename test/{v4l2_subdevice/v4l2_subdevice_test.cpp => v4l2_subdev/v4l2_subdev_test.cpp} (84%)\n rename test/{v4l2_subdevice/v4l2_subdevice_test.h => v4l2_subdev/v4l2_subdev_test.h} (76%)\n rename test/{v4l2_device => v4l2_videodev}/buffer_sharing.cpp (90%)\n rename test/{v4l2_device => v4l2_videodev}/capture_async.cpp (92%)\n rename test/{v4l2_device => v4l2_videodev}/double_open.cpp (76%)\n rename test/{v4l2_device => v4l2_videodev}/formats.cpp (86%)\n rename test/{v4l2_device => v4l2_videodev}/meson.build (75%)\n rename test/{v4l2_device => v4l2_videodev}/request_buffers.cpp (78%)\n rename test/{v4l2_device => v4l2_videodev}/stream_on_off.cpp (79%)\n rename test/{v4l2_device/v4l2_device_test.cpp => v4l2_videodev/v4l2_videodev_test.cpp} (91%)\n rename test/{v4l2_device/v4l2_device_test.h => v4l2_videodev/v4l2_videodev_test.h} (82%)\n\n--\n2.21.0","diff":"diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\nindex 8f9b42e39339..7da9a4263fd3 100644\n--- a/include/libcamera/buffer.h\n+++ b/include/libcamera/buffer.h\n@@ -59,7 +59,7 @@ private:\n \tfriend class BufferPool;\n \tfriend class PipelineHandler;\n \tfriend class Request;\n-\tfriend class V4L2Device;\n+\tfriend class V4L2Videodev;\n\n \tvoid cancel();\n\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex cb6649efac3f..83f121ec3514 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -14,7 +14,7 @@\n #include <math.h>\n\n #include \"formats.h\"\n-#include \"v4l2_subdevice.h\"\n+#include \"v4l2_subdev.h\"\n\n /**\n  * \\file camera_sensor.h\n@@ -48,7 +48,7 @@ LOG_DEFINE_CATEGORY(CameraSensor);\n CameraSensor::CameraSensor(const MediaEntity *entity)\n \t: entity_(entity)\n {\n-\tsubdev_ = new V4L2Subdevice(entity);\n+\tsubdev_ = new V4L2Subdev(entity);\n }\n\n /**\ndiff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\nindex b823480241a7..2dd311652aa5 100644\n--- a/src/libcamera/include/camera_sensor.h\n+++ b/src/libcamera/include/camera_sensor.h\n@@ -17,7 +17,7 @@\n namespace libcamera {\n\n class MediaEntity;\n-class V4L2Subdevice;\n+class V4L2Subdev;\n\n struct V4L2SubdeviceFormat;\n\n@@ -46,7 +46,7 @@ protected:\n\n private:\n \tconst MediaEntity *entity_;\n-\tV4L2Subdevice *subdev_;\n+\tV4L2Subdev *subdev_;\n\n \tstd::vector<unsigned int> mbusCodes_;\n \tstd::vector<Size> sizes_;\ndiff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex bdecc087fe5a..e3f3ecf235d4 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -2,183 +2,37 @@\n /*\n  * Copyright (C) 2019, Google Inc.\n  *\n- * v4l2_device.h - V4L2 Device\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 <atomic>\n #include <string>\n-#include <vector>\n-\n-#include <linux/videodev2.h>\n-\n-#include <libcamera/geometry.h>\n-#include <libcamera/signal.h>\n-\n-#include \"log.h\"\n\n namespace libcamera {\n\n-class Buffer;\n-class BufferPool;\n-class EventNotifier;\n-class MediaDevice;\n-class MediaEntity;\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-\tunsigned int device_caps() const\n-\t{\n-\t\treturn capabilities & V4L2_CAP_DEVICE_CAPS\n-\t\t\t\t    ? v4l2_capability::device_caps\n-\t\t\t\t    : v4l2_capability::capabilities;\n-\t}\n-\tbool isMultiplanar() const\n-\t{\n-\t\treturn device_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |\n-\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT_MPLANE);\n-\t}\n-\tbool isCapture() const\n-\t{\n-\t\treturn device_caps() & (V4L2_CAP_VIDEO_CAPTURE |\n-\t\t\t\t\tV4L2_CAP_VIDEO_CAPTURE_MPLANE |\n-\t\t\t\t\tV4L2_CAP_META_CAPTURE);\n-\t}\n-\tbool isOutput() const\n-\t{\n-\t\treturn device_caps() & (V4L2_CAP_VIDEO_OUTPUT |\n-\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT_MPLANE |\n-\t\t\t\t\tV4L2_CAP_META_OUTPUT);\n-\t}\n-\tbool isVideo() const\n-\t{\n-\t\treturn device_caps() & (V4L2_CAP_VIDEO_CAPTURE |\n-\t\t\t\t\tV4L2_CAP_VIDEO_CAPTURE_MPLANE |\n-\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT |\n-\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT_MPLANE);\n-\t}\n-\tbool isMeta() const\n-\t{\n-\t\treturn device_caps() & (V4L2_CAP_META_CAPTURE |\n-\t\t\t\t\tV4L2_CAP_META_OUTPUT);\n-\t}\n-\tbool isVideoCapture() const\n-\t{\n-\t\treturn isVideo() && isCapture();\n-\t}\n-\tbool isVideoOutput() const\n-\t{\n-\t\treturn isVideo() && isOutput();\n-\t}\n-\tbool isMetaCapture() const\n-\t{\n-\t\treturn isMeta() && isCapture();\n-\t}\n-\tbool isMetaOutput() const\n-\t{\n-\t\treturn isMeta() && isOutput();\n-\t}\n-\tbool hasStreaming() const\n-\t{\n-\t\treturn device_caps() & V4L2_CAP_STREAMING;\n-\t}\n-};\n-\n-class V4L2DeviceFormat\n+class V4L2Device\n {\n public:\n-\tuint32_t fourcc;\n-\tSize size;\n-\n-\tstruct {\n-\t\tuint32_t size;\n-\t\tuint32_t bpl;\n-\t} planes[3];\n-\tunsigned int planesCount;\n-\n-\tconst std::string toString() const;\n-};\n+\tvirtual ~V4L2Device()\n+\t{\n+\t}\n\n-class V4L2Device : protected Loggable\n-{\n-public:\n-\texplicit V4L2Device(const std::string &deviceNode);\n-\texplicit V4L2Device(const MediaEntity *entity);\n-\tV4L2Device(const V4L2Device &) = delete;\n-\t~V4L2Device();\n+protected:\n+\tV4L2Device();\n\n-\tV4L2Device &operator=(const V4L2Device &) = delete;\n+\tint fd() { return fd_; }\n\n-\tint open();\n+\tint open(const std::string &pathname, unsigned int flags);\n+\tint close();\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-\tconst std::string &deviceNode() const { return deviceNode_; }\n\n-\tint getFormat(V4L2DeviceFormat *format);\n-\tint setFormat(V4L2DeviceFormat *format);\n-\n-\tint exportBuffers(BufferPool *pool);\n-\tint importBuffers(BufferPool *pool);\n-\tint releaseBuffers();\n-\n-\tint queueBuffer(Buffer *buffer);\n-\tSignal<Buffer *> bufferReady;\n-\n-\tint streamOn();\n-\tint streamOff();\n-\n-\tstatic V4L2Device *fromEntityName(const MediaDevice *media,\n-\t\t\t\t\t  const std::string &entity);\n-\n-protected:\n-\tstd::string logPrefix() const;\n+\tint ioctl(unsigned long request, void *argp);\n\n private:\n-\tint getFormatMeta(V4L2DeviceFormat *format);\n-\tint setFormatMeta(V4L2DeviceFormat *format);\n-\n-\tint getFormatMultiplane(V4L2DeviceFormat *format);\n-\tint setFormatMultiplane(V4L2DeviceFormat *format);\n-\n-\tint getFormatSingleplane(V4L2DeviceFormat *format);\n-\tint setFormatSingleplane(V4L2DeviceFormat *format);\n-\n-\tint requestBuffers(unsigned int count);\n-\tint createPlane(Buffer *buffer, unsigned int plane,\n-\t\t\tunsigned int length);\n-\n-\tBuffer *dequeueBuffer();\n-\tvoid bufferAvailable(EventNotifier *notifier);\n-\n-\tstd::string deviceNode_;\n \tint fd_;\n-\tV4L2Capability caps_;\n-\n-\tenum v4l2_buf_type bufferType_;\n-\tenum v4l2_memory memoryType_;\n-\n-\tBufferPool *bufferPool_;\n-\tstd::atomic<unsigned int> queuedBuffersCount_;\n-\n-\tEventNotifier *fdEvent_;\n };\n\n-} /* namespace libcamera */\n+}; /* namespace libcamera */\n\n #endif /* __LIBCAMERA_V4L2_DEVICE_H__ */\ndiff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdev.h\nsimilarity index 67%\nrename from src/libcamera/include/v4l2_subdevice.h\nrename to src/libcamera/include/v4l2_subdev.h\nindex 3e4e5107aebe..9770f05deae4 100644\n--- a/src/libcamera/include/v4l2_subdevice.h\n+++ b/src/libcamera/include/v4l2_subdev.h\n@@ -2,10 +2,10 @@\n /*\n  * Copyright (C) 2019, Google Inc.\n  *\n- * v4l2_subdevice.h - V4L2 Subdevice\n+ * v4l2_subdev.h - V4L2 Subdevice\n  */\n-#ifndef __LIBCAMERA_V4L2_SUBDEVICE_H__\n-#define __LIBCAMERA_V4L2_SUBDEVICE_H__\n+#ifndef __LIBCAMERA_V4L2_SUBDEV_H__\n+#define __LIBCAMERA_V4L2_SUBDEV_H__\n\n #include <map>\n #include <string>\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,16 +29,15 @@ struct V4L2SubdeviceFormat {\n \tconst std::string toString() const;\n };\n\n-class V4L2Subdevice : protected Loggable\n+class V4L2Subdev : public V4L2Device, protected Loggable\n {\n public:\n-\texplicit V4L2Subdevice(const MediaEntity *entity);\n-\tV4L2Subdevice(const V4L2Subdevice &) = delete;\n-\tV4L2Subdevice &operator=(const V4L2Subdevice &) = delete;\n-\t~V4L2Subdevice();\n+\texplicit V4L2Subdev(const MediaEntity *entity);\n+\tV4L2Subdev(const V4L2Subdev &) = delete;\n+\tV4L2Subdev &operator=(const V4L2Subdev &) = delete;\n+\t~V4L2Subdev();\n\n \tint open();\n-\tbool isOpen() const;\n \tvoid close();\n\n \tconst MediaEntity *entity() const { return entity_; }\n@@ -50,8 +50,8 @@ public:\n \tint getFormat(unsigned int pad, V4L2SubdeviceFormat *format);\n \tint setFormat(unsigned int pad, V4L2SubdeviceFormat *format);\n\n-\tstatic V4L2Subdevice *fromEntityName(const MediaDevice *media,\n-\t\t\t\t\t     const std::string &entity);\n+\tstatic V4L2Subdev *fromEntityName(const MediaDevice *media,\n+\t\t\t\t\t  const std::string &entity);\n\n protected:\n \tstd::string logPrefix() const;\n@@ -64,9 +64,8 @@ private:\n \t\t\t Rectangle *rect);\n\n \tconst MediaEntity *entity_;\n-\tint fd_;\n };\n\n } /* namespace libcamera */\n\n-#endif /* __LIBCAMERA_V4L2_SUBDEVICE_H__ */\n+#endif /* __LIBCAMERA_V4L2_SUBDEV_H__ */\ndiff --git a/src/libcamera/include/v4l2_videodev.h b/src/libcamera/include/v4l2_videodev.h\nnew file mode 100644\nindex 000000000000..c072f1fa5449\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_videodev.h\n@@ -0,0 +1,183 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_videodev.h - V4L2 Video Device\n+ */\n+#ifndef __LIBCAMERA_V4L2_VIDEODEV_H__\n+#define __LIBCAMERA_V4L2_VIDEODEV_H__\n+\n+#include <atomic>\n+#include <string>\n+#include <vector>\n+\n+#include <linux/videodev2.h>\n+\n+#include <libcamera/geometry.h>\n+#include <libcamera/signal.h>\n+\n+#include \"log.h\"\n+#include \"v4l2_device.h\"\n+\n+namespace libcamera {\n+\n+class Buffer;\n+class BufferPool;\n+class EventNotifier;\n+class MediaDevice;\n+class MediaEntity;\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+\tunsigned int device_caps() const\n+\t{\n+\t\treturn capabilities & V4L2_CAP_DEVICE_CAPS\n+\t\t\t\t    ? v4l2_capability::device_caps\n+\t\t\t\t    : v4l2_capability::capabilities;\n+\t}\n+\tbool isMultiplanar() const\n+\t{\n+\t\treturn device_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |\n+\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT_MPLANE);\n+\t}\n+\tbool isCapture() const\n+\t{\n+\t\treturn device_caps() & (V4L2_CAP_VIDEO_CAPTURE |\n+\t\t\t\t\tV4L2_CAP_VIDEO_CAPTURE_MPLANE |\n+\t\t\t\t\tV4L2_CAP_META_CAPTURE);\n+\t}\n+\tbool isOutput() const\n+\t{\n+\t\treturn device_caps() & (V4L2_CAP_VIDEO_OUTPUT |\n+\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT_MPLANE |\n+\t\t\t\t\tV4L2_CAP_META_OUTPUT);\n+\t}\n+\tbool isVideo() const\n+\t{\n+\t\treturn device_caps() & (V4L2_CAP_VIDEO_CAPTURE |\n+\t\t\t\t\tV4L2_CAP_VIDEO_CAPTURE_MPLANE |\n+\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT |\n+\t\t\t\t\tV4L2_CAP_VIDEO_OUTPUT_MPLANE);\n+\t}\n+\tbool isMeta() const\n+\t{\n+\t\treturn device_caps() & (V4L2_CAP_META_CAPTURE |\n+\t\t\t\t\tV4L2_CAP_META_OUTPUT);\n+\t}\n+\tbool isVideoCapture() const\n+\t{\n+\t\treturn isVideo() && isCapture();\n+\t}\n+\tbool isVideoOutput() const\n+\t{\n+\t\treturn isVideo() && isOutput();\n+\t}\n+\tbool isMetaCapture() const\n+\t{\n+\t\treturn isMeta() && isCapture();\n+\t}\n+\tbool isMetaOutput() const\n+\t{\n+\t\treturn isMeta() && isOutput();\n+\t}\n+\tbool hasStreaming() const\n+\t{\n+\t\treturn device_caps() & V4L2_CAP_STREAMING;\n+\t}\n+};\n+\n+class V4L2DeviceFormat\n+{\n+public:\n+\tuint32_t fourcc;\n+\tSize size;\n+\n+\tstruct {\n+\t\tuint32_t size;\n+\t\tuint32_t bpl;\n+\t} planes[3];\n+\tunsigned int planesCount;\n+\n+\tconst std::string toString() const;\n+};\n+\n+class V4L2Videodev : public V4L2Device, protected Loggable\n+{\n+public:\n+\texplicit V4L2Videodev(const std::string &deviceNode);\n+\texplicit V4L2Videodev(const MediaEntity *entity);\n+\tV4L2Videodev(const V4L2Videodev &) = delete;\n+\t~V4L2Videodev();\n+\n+\tV4L2Videodev &operator=(const V4L2Videodev &) = delete;\n+\n+\tint open();\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+\tconst std::string &deviceNode() const { return deviceNode_; }\n+\n+\tint getFormat(V4L2DeviceFormat *format);\n+\tint setFormat(V4L2DeviceFormat *format);\n+\n+\tint exportBuffers(BufferPool *pool);\n+\tint importBuffers(BufferPool *pool);\n+\tint releaseBuffers();\n+\n+\tint queueBuffer(Buffer *buffer);\n+\tSignal<Buffer *> bufferReady;\n+\n+\tint streamOn();\n+\tint streamOff();\n+\n+\tstatic V4L2Videodev *fromEntityName(const MediaDevice *media,\n+\t\t\t\t\t    const std::string &entity);\n+\n+protected:\n+\tstd::string logPrefix() const;\n+\n+private:\n+\tint getFormatMeta(V4L2DeviceFormat *format);\n+\tint setFormatMeta(V4L2DeviceFormat *format);\n+\n+\tint getFormatMultiplane(V4L2DeviceFormat *format);\n+\tint setFormatMultiplane(V4L2DeviceFormat *format);\n+\n+\tint getFormatSingleplane(V4L2DeviceFormat *format);\n+\tint setFormatSingleplane(V4L2DeviceFormat *format);\n+\n+\tint requestBuffers(unsigned int count);\n+\tint createPlane(Buffer *buffer, unsigned int plane,\n+\t\t\tunsigned int length);\n+\n+\tBuffer *dequeueBuffer();\n+\tvoid bufferAvailable(EventNotifier *notifier);\n+\n+\tstd::string deviceNode_;\n+\tV4L2Capability caps_;\n+\n+\tenum v4l2_buf_type bufferType_;\n+\tenum v4l2_memory memoryType_;\n+\n+\tBufferPool *bufferPool_;\n+\tstd::atomic<unsigned int> queuedBuffersCount_;\n+\n+\tEventNotifier *fdEvent_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_V4L2_VIDEODEV_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 1ca1083cf5c7..f7a48fcb43df 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -24,7 +24,8 @@ libcamera_sources = files([\n     'timer.cpp',\n     'utils.cpp',\n     'v4l2_device.cpp',\n-    'v4l2_subdevice.cpp',\n+    'v4l2_subdev.cpp',\n+    'v4l2_videodev.cpp',\n ])\n\n libcamera_headers = files([\n@@ -42,7 +43,8 @@ libcamera_headers = files([\n     'include/pipeline_handler.h',\n     'include/utils.h',\n     'include/v4l2_device.h',\n-    'include/v4l2_subdevice.h',\n+    'include/v4l2_subdev.h',\n+    'include/v4l2_videodev.h',\n ])\n\n libcamera_internal_includes =  include_directories('include')\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex f2bdecbac20f..c4229453afe8 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -22,8 +22,8 @@\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n-#include \"v4l2_device.h\"\n-#include \"v4l2_subdevice.h\"\n+#include \"v4l2_subdev.h\"\n+#include \"v4l2_videodev.h\"\n\n namespace libcamera {\n\n@@ -39,7 +39,7 @@ public:\n\n \t/* ImgU output descriptor: group data specific to an ImgU output. */\n \tstruct ImgUOutput {\n-\t\tV4L2Device *dev;\n+\t\tV4L2Videodev *dev;\n \t\tunsigned int pad;\n \t\tstd::string name;\n \t\tBufferPool *pool;\n@@ -84,8 +84,8 @@ public:\n \tstd::string name_;\n \tMediaDevice *media_;\n\n-\tV4L2Subdevice *imgu_;\n-\tV4L2Device *input_;\n+\tV4L2Subdev *imgu_;\n+\tV4L2Videodev *input_;\n \tImgUOutput output_;\n \tImgUOutput viewfinder_;\n \tImgUOutput stat_;\n@@ -125,8 +125,8 @@ public:\n\n \tstatic int mediaBusToFormat(unsigned int code);\n\n-\tV4L2Device *output_;\n-\tV4L2Subdevice *csi2_;\n+\tV4L2Videodev *output_;\n+\tV4L2Subdev *csi2_;\n \tCameraSensor *sensor_;\n\n \tBufferPool pool_;\n@@ -943,7 +943,7 @@ void IPU3CameraData::cio2BufferReady(Buffer *buffer)\n  * Create and open the V4L2 devices and subdevices of the ImgU instance\n  * with \\a index.\n  *\n- * In case of errors the created V4L2Device and V4L2Subdevice instances\n+ * In case of errors the created V4L2Videodev and V4L2Subdev instances\n  * are destroyed at pipeline handler delete time.\n  *\n  * \\return 0 on success or a negative error code otherwise\n@@ -961,17 +961,17 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n \t * by the match() function: no need to check for newly created\n \t * video devices and subdevice validity here.\n \t */\n-\timgu_ = V4L2Subdevice::fromEntityName(media, name_);\n+\timgu_ = V4L2Subdev::fromEntityName(media, name_);\n \tret = imgu_->open();\n \tif (ret)\n \t\treturn ret;\n\n-\tinput_ = V4L2Device::fromEntityName(media, name_ + \" input\");\n+\tinput_ = V4L2Videodev::fromEntityName(media, name_ + \" input\");\n \tret = input_->open();\n \tif (ret)\n \t\treturn ret;\n\n-\toutput_.dev = V4L2Device::fromEntityName(media, name_ + \" output\");\n+\toutput_.dev = V4L2Videodev::fromEntityName(media, name_ + \" output\");\n \tret = output_.dev->open();\n \tif (ret)\n \t\treturn ret;\n@@ -980,7 +980,7 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n \toutput_.name = \"output\";\n \toutput_.pool = &outPool_;\n\n-\tviewfinder_.dev = V4L2Device::fromEntityName(media,\n+\tviewfinder_.dev = V4L2Videodev::fromEntityName(media,\n \t\t\t\t\t\t     name_ + \" viewfinder\");\n \tret = viewfinder_.dev->open();\n \tif (ret)\n@@ -990,7 +990,7 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n \tviewfinder_.name = \"viewfinder\";\n \tviewfinder_.pool = &vfPool_;\n\n-\tstat_.dev = V4L2Device::fromEntityName(media, name_ + \" 3a stat\");\n+\tstat_.dev = V4L2Videodev::fromEntityName(media, name_ + \" 3a stat\");\n \tret = stat_.dev->open();\n \tif (ret)\n \t\treturn ret;\n@@ -1067,7 +1067,7 @@ int ImgUDevice::configureInput(const Size &size,\n int ImgUDevice::configureOutput(ImgUOutput *output,\n \t\t\t\tconst StreamConfiguration &cfg)\n {\n-\tV4L2Device *dev = output->dev;\n+\tV4L2Videodev *dev = output->dev;\n \tunsigned int pad = output->pad;\n\n \tV4L2SubdeviceFormat imguFormat = {};\n@@ -1331,13 +1331,13 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \t * might impact on power consumption.\n \t */\n\n-\tcsi2_ = new V4L2Subdevice(csi2Entity);\n+\tcsi2_ = new V4L2Subdev(csi2Entity);\n \tret = csi2_->open();\n \tif (ret)\n \t\treturn ret;\n\n \tstd::string cio2Name = \"ipu3-cio2 \" + std::to_string(index);\n-\toutput_ = V4L2Device::fromEntityName(media, cio2Name);\n+\toutput_ = V4L2Videodev::fromEntityName(media, cio2Name);\n \tret = output_->open();\n \tif (ret)\n \t\treturn ret;\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 9b3eea2f6dd3..08b640a1bd49 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -23,8 +23,8 @@\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n-#include \"v4l2_device.h\"\n-#include \"v4l2_subdevice.h\"\n+#include \"v4l2_subdev.h\"\n+#include \"v4l2_videodev.h\"\n\n namespace libcamera {\n\n@@ -104,9 +104,9 @@ private:\n \tvoid bufferReady(Buffer *buffer);\n\n \tMediaDevice *media_;\n-\tV4L2Subdevice *dphy_;\n-\tV4L2Subdevice *isp_;\n-\tV4L2Device *video_;\n+\tV4L2Subdev *dphy_;\n+\tV4L2Subdev *isp_;\n+\tV4L2Videodev *video_;\n\n \tCamera *activeCamera_;\n };\n@@ -449,16 +449,16 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator)\n \t\treturn false;\n\n \t/* Create the V4L2 subdevices we will need. */\n-\tdphy_ = V4L2Subdevice::fromEntityName(media_, \"rockchip-sy-mipi-dphy\");\n+\tdphy_ = V4L2Subdev::fromEntityName(media_, \"rockchip-sy-mipi-dphy\");\n \tif (dphy_->open() < 0)\n \t\treturn false;\n\n-\tisp_ = V4L2Subdevice::fromEntityName(media_, \"rkisp1-isp-subdev\");\n+\tisp_ = V4L2Subdev::fromEntityName(media_, \"rkisp1-isp-subdev\");\n \tif (isp_->open() < 0)\n \t\treturn false;\n\n \t/* Locate and open the capture video node. */\n-\tvideo_ = V4L2Device::fromEntityName(media_, \"rkisp1_mainpath\");\n+\tvideo_ = V4L2Videodev::fromEntityName(media_, \"rkisp1_mainpath\");\n \tif (video_->open() < 0)\n \t\treturn false;\n\ndiff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\nindex 45260f34c8f5..fa3c5a2f8374 100644\n--- a/src/libcamera/pipeline/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo.cpp\n@@ -14,7 +14,7 @@\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n-#include \"v4l2_device.h\"\n+#include \"v4l2_videodev.h\"\n\n namespace libcamera {\n\n@@ -35,7 +35,7 @@ public:\n\n \tvoid bufferReady(Buffer *buffer);\n\n-\tV4L2Device *video_;\n+\tV4L2Videodev *video_;\n \tStream stream_;\n };\n\n@@ -229,7 +229,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n \t/* Locate and open the default video node. */\n \tfor (MediaEntity *entity : media->entities()) {\n \t\tif (entity->flags() & MEDIA_ENT_FL_DEFAULT) {\n-\t\t\tdata->video_ = new V4L2Device(entity);\n+\t\t\tdata->video_ = new V4L2Videodev(entity);\n \t\t\tbreak;\n \t\t}\n \t}\ndiff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex ad4577acd9d6..e1fa3eabeae0 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -20,7 +20,7 @@\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n-#include \"v4l2_device.h\"\n+#include \"v4l2_videodev.h\"\n\n namespace libcamera {\n\n@@ -41,7 +41,7 @@ public:\n\n \tvoid bufferReady(Buffer *buffer);\n\n-\tV4L2Device *video_;\n+\tV4L2Videodev *video_;\n \tStream stream_;\n };\n\n@@ -262,7 +262,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \tstd::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);\n\n \t/* Locate and open the capture video node. */\n-\tdata->video_ = new V4L2Device(media->getEntityByName(\"Raw Capture 1\"));\n+\tdata->video_ = new V4L2Videodev(media->getEntityByName(\"Raw Capture 1\"));\n \tif (data->video_->open())\n \t\treturn false;\n\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 0821bd75fb42..c20dc7928fcd 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -2,1011 +2,150 @@\n /*\n  * Copyright (C) 2019, Google Inc.\n  *\n- * v4l2_device.cpp - V4L2 Device\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 <iomanip>\n-#include <sstream>\n #include <string.h>\n #include <sys/ioctl.h>\n-#include <sys/mman.h>\n-#include <sys/time.h>\n #include <unistd.h>\n-#include <vector>\n-\n-#include <libcamera/buffer.h>\n-#include <libcamera/event_notifier.h>\n\n #include \"log.h\"\n-#include \"media_device.h\"\n-#include \"media_object.h\"\n\n /**\n  * \\file v4l2_device.h\n- * \\brief V4L2 Device API\n+ * \\brief Common base for V4L2 devices and subdevices\n  */\n+\n namespace libcamera {\n\n LOG_DEFINE_CATEGORY(V4L2)\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 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 V4L2Capability::card()\n- * \\brief Retrieve the device card name\n- * \\return The string containing the device name\n- */\n-\n-/**\n- * \\fn 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 V4L2Capability::device_caps()\n- * \\brief Retrieve the capabilities of the device\n- * \\return The device specific capabilities if V4L2_CAP_DEVICE_CAPS is set or\n- * \t   driver capabilities otherwise\n- */\n-\n-/**\n- * \\fn V4L2Capability::isMultiplanar()\n- * \\brief Identify if the device implements the V4L2 multiplanar APIs\n- * \\return True if the device supports multiplanar APIs\n- */\n-\n-/**\n- * \\fn V4L2Capability::isCapture()\n- * \\brief Identify if the device captures data\n- * \\return True if the device can capture data\n- */\n-\n-/**\n- * \\fn V4L2Capability::isOutput()\n- * \\brief Identify if the device outputs data\n- * \\return True if the device can output data\n- */\n-\n-/**\n- * \\fn V4L2Capability::isVideo()\n- * \\brief Identify if the device captures or outputs images\n- * \\return True if the device can capture or output images\n- */\n-\n-/**\n- * \\fn V4L2Capability::isMeta()\n- * \\brief Identify if the device captures or outputs image meta-data\n- *\n- * \\todo Add support for META_CAPTURE introduced in Linux v5.0\n- *\n- * \\return True if the device can capture or output image meta-data\n- */\n-\n-/**\n- * \\fn V4L2Capability::isVideoCapture()\n- * \\brief Identify if the device captures images\n- * \\return True if the device can capture images\n- */\n-\n-/**\n- * \\fn V4L2Capability::isVideoOutput()\n- * \\brief Identify if the device outputs images\n- * \\return True if the device can output images\n- */\n-\n-/**\n- * \\fn V4L2Capability::isMetaCapture()\n- * \\brief Identify if the device captures image meta-data\n- * \\return True if the device can capture image meta-data\n- */\n-\n-/**\n- * \\fn V4L2Capability::isMetaOutput()\n- * \\brief Identify if the device outputs image meta-data\n- * \\return True if the device can output image meta-data\n- */\n-\n-/**\n- * \\fn 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 V4L2DeviceFormat\n- * \\brief The V4L2 device image format and sizes\n- *\n- * This class describes the image format and resolution to be programmed on a\n- * V4L2 video device. The image format is defined by a fourcc code (as specified\n- * by the V4L2 API with the V4L2_PIX_FMT_* macros), a resolution (width and\n- * height) and one to three planes with configurable line stride and a total\n- * per-plane size in bytes.\n- *\n- * Image formats, as defined by the V4L2 APIs, are categorised as packed,\n- * semi-planar and planar, and describe the layout of the image pixel components\n- * stored in memory.\n- *\n- * Packed image formats store pixel components one after the other, in a\n- * contiguous memory area. Examples of packed image formats are YUYV\n- * permutations, RGB with different pixel sub-sampling ratios such as RGB565 or\n- * RGB666 or Raw-Bayer formats such as SRGGB8 or SGRBG12.\n- *\n- * Semi-planar and planar image formats store the pixel components in separate\n- * and possibly non-contiguous memory areas, named planes, whose sizes depend on\n- * the pixel components sub-sampling ratios, which are defined by the format.\n- * Semi-planar formats use two planes to store pixel components and notable\n- * examples of such formats are the NV12 and NV16 formats, while planar formats\n- * use three planes to store pixel components and notable examples are YUV422\n- * and YUV420.\n- *\n- * Image formats supported by the V4L2 API are defined and described in Section\n- * number 2 of the \"Part I - Video for Linux API\" chapter of the \"Linux Media\n- * Infrastructure userspace API\", part of the Linux kernel documentation.\n- *\n- * In the context of this document, packed image formats are referred to as\n- * \"packed formats\" and semi-planar and planar image formats are referred to as\n- * \"planar formats\".\n- *\n- * V4L2 also defines two different sets of APIs to work with devices that store\n- * planes in contiguous or separate memory areas. They are named \"Single-plane\n- * APIs\" and \"Multi-plane APIs\" respectively and are documented in Section 2.1\n- * and Section 2.2 of the above mentioned \"Part I - Video for Linux API\"\n- * documentation.\n- *\n- * The single-plane API allows, among other parameters, the configuration of the\n- * image resolution, the pixel format and the stride length. In that case the\n- * stride applies to all planes (possibly sub-sampled). The multi-plane API\n- * allows configuring the resolution, the pixel format and a per-plane stride\n- * length and total size.\n+ * \\class V4L2Device\n+ * \\brief Base class for V4L2Videodev and V4L2Subdev\n  *\n- * Packed image formats, which occupy a single memory area, are easily described\n- * through the single-plane API. When used on a device that implements the\n- * multi-plane API, only the size and stride information contained in the first\n- * plane are taken into account.\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- * Planar image formats, which occupy distinct memory areas, are easily\n- * described through the multi-plane APIs. When used on a device that implements\n- * the single-plane API, all planes are stored one after the other in a\n- * contiguous memory area, and it is not possible to configure per-plane stride\n- * length and size, but only a global stride length which is applied to all\n- * planes.\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- * The V4L2DeviceFormat class describes both packed and planar image formats,\n- * regardless of the API type (single or multi plane) implemented by the device\n- * the format has to be applied to. The total size and bytes per line of images\n- * represented with packed formats are configured using the first entry of the\n- * V4L2DeviceFormat::planes array, while the per-plane size and per-plane stride\n- * length of images represented with planar image formats are configured using\n- * the opportune number of entries of the V4L2DeviceFormat::planes array, as\n- * prescribed by the image format definition (semi-planar formats use 2 entries,\n- * while planar formats use the whole 3 entries). The number of valid entries of\n- * the V4L2DeviceFormat::planes array is defined by the\n- * V4L2DeviceFormat::planesCount value.\n- */\n-\n-/**\n- * \\var V4L2DeviceFormat::size\n- * \\brief The image size in pixels\n+ * Methods common to V4L2Videodev and V4L2Subdev, such as V4L2 controls\n+ * support are implemented in the base class to maximize code re-use.\n  */\n\n /**\n- * \\var V4L2DeviceFormat::fourcc\n- * \\brief The fourcc code describing the pixel encoding scheme\n+ * \\brief Construct a V4L2Device\n  *\n- * The fourcc code, as defined by the V4L2 API with the V4L2_PIX_FMT_* macros,\n- * that identifies the image format pixel encoding scheme.\n- */\n-\n-/**\n- * \\var V4L2DeviceFormat::planes\n- * \\brief The per-plane memory size information\n+ * The V4L2Device constructor is protected and can only be accessed by the\n+ * V4L2Videodev and V4L2Subdev derived classes.\n  *\n- * Images are stored in memory in one or more data planes. Each data plane has a\n- * specific line stride and memory size, which could differ from the image\n- * visible sizes to accommodate padding at the end of lines and end of planes.\n- * Only the first \\ref planesCount entries are considered valid.\n- */\n-\n-/**\n- * \\var V4L2DeviceFormat::planesCount\n- * \\brief The number of valid data planes\n+ * Initialize the file descriptor to -1.\n  */\n-\n-/**\n- * \\brief Assemble and return a string describing the format\n- * \\return A string describing the V4L2DeviceFormat\n- */\n-const std::string V4L2DeviceFormat::toString() const\n+V4L2Device::V4L2Device() :\n+\tfd_(-1)\n {\n-\tstd::stringstream ss;\n-\n-\tss.fill(0);\n-\tss << size.toString() << \"-0x\" << std::hex << std::setw(8) << fourcc;\n-\n-\treturn ss.str();\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- * The V4L2Device class tracks queued buffers and handles buffer events. It\n- * automatically dequeues completed buffers and emits the \\ref bufferReady\n- * signal.\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[in] deviceNode The file-system path to the video device node\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-V4L2Device::V4L2Device(const std::string &deviceNode)\n-\t: deviceNode_(deviceNode), fd_(-1), bufferPool_(nullptr),\n-\t  queuedBuffersCount_(0), fdEvent_(nullptr)\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-\t */\n-\tbufferType_ = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;\n-\tmemoryType_ = V4L2_MEMORY_MMAP;\n-}\n\n /**\n- * \\brief Construct a V4L2Device from a MediaEntity\n- * \\param[in] entity The MediaEntity to build the device from\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- * Construct a V4L2Device from a MediaEntity's device node path.\n- */\n-V4L2Device::V4L2Device(const MediaEntity *entity)\n-\t: V4L2Device(entity->deviceNode())\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+int V4L2Device::open(const std::string &pathname, unsigned int flags)\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+\tint ret = ::open(pathname.c_str(), flags);\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+\t\tLOG(V4L2, Error) << \"Failed to open V4L2 device: \"\n+\t\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(V4L2, Error)\n-\t\t\t<< \"Failed to query device capabilities: \"\n-\t\t\t<< strerror(-ret);\n-\t\treturn ret;\n-\t}\n-\n-\tLOG(V4L2, Debug)\n-\t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n-\t\t<< caps_.driver() << \": \" << caps_.card();\n-\n-\tif (!caps_.hasStreaming()) {\n-\t\tLOG(V4L2, Error) << \"Device does not support streaming I/O\";\n-\t\treturn -EINVAL;\n-\t}\n-\n-\t/*\n-\t * Set buffer type and wait for read notifications on CAPTURE devices\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\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-\tfdEvent_->activated.connect(this, &V4L2Device::bufferAvailable);\n-\tfdEvent_->setEnabled(false);\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-\treleaseBuffers();\n-\tdelete fdEvent_;\n-\n-\t::close(fd_);\n-\tfd_ = -1;\n-}\n-\n-/**\n- * \\fn 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 V4L2Device::deviceName()\n- * \\brief Retrieve the name of the V4L2 device\n- * \\return The string containing the device name\n- */\n-\n-/**\n- * \\fn V4L2Device::busName()\n- * \\brief Retrieve the location of the device in the system\n- * \\return The string containing the device location\n- */\n-\n-/**\n- * \\fn V4L2Device::deviceNode()\n- * \\brief Retrieve the video device node path\n- * \\return The video device device node path\n- */\n-\n-std::string V4L2Device::logPrefix() const\n-{\n-\treturn deviceNode_ + (V4L2_TYPE_IS_OUTPUT(bufferType_) ? \"[out]\" : \"[cap]\");\n-}\n-\n-/**\n- * \\brief Retrieve the image format set on the V4L2 device\n- * \\param[out] format The image format applied on the device\n- * \\return 0 on success or a negative error code otherwise\n- */\n-int V4L2Device::getFormat(V4L2DeviceFormat *format)\n-{\n-\tif (caps_.isMeta())\n-\t\treturn getFormatMeta(format);\n-\telse if (caps_.isMultiplanar())\n-\t\treturn getFormatMultiplane(format);\n-\telse\n-\t\treturn getFormatSingleplane(format);\n-}\n-\n-/**\n- * \\brief Configure an image format on the V4L2 device\n- * \\param[inout] format The image format to apply to the device\n- *\n- * Apply the supplied \\a format to the device, and return the actually\n- * applied format parameters, as \\ref V4L2Device::getFormat would do.\n- *\n- * \\return 0 on success or a negative error code otherwise\n- */\n-int V4L2Device::setFormat(V4L2DeviceFormat *format)\n-{\n-\tif (caps_.isMeta())\n-\t\treturn setFormatMeta(format);\n-\telse if (caps_.isMultiplanar())\n-\t\treturn setFormatMultiplane(format);\n-\telse\n-\t\treturn setFormatSingleplane(format);\n-}\n-\n-int V4L2Device::getFormatMeta(V4L2DeviceFormat *format)\n-{\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n-\tint ret;\n-\n-\tv4l2Format.type = bufferType_;\n-\tret = ioctl(fd_, 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-\n-\tformat->size.width = 0;\n-\tformat->size.height = 0;\n-\tformat->fourcc = pix->dataformat;\n-\tformat->planesCount = 1;\n-\tformat->planes[0].bpl = pix->buffersize;\n-\tformat->planes[0].size = pix->buffersize;\n-\n-\treturn 0;\n-}\n-\n-int V4L2Device::setFormatMeta(V4L2DeviceFormat *format)\n-{\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n-\tint ret;\n-\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-\tif (ret) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n-\t\treturn ret;\n-\t}\n-\n-\t/*\n-\t * Return to caller the format actually applied on the device,\n-\t * which might differ from the requested one.\n-\t */\n-\tformat->size.width = 0;\n-\tformat->size.height = 0;\n-\tformat->fourcc = format->fourcc;\n-\tformat->planesCount = 1;\n-\tformat->planes[0].bpl = pix->buffersize;\n-\tformat->planes[0].size = pix->buffersize;\n-\n-\treturn 0;\n-}\n\n-int V4L2Device::getFormatMultiplane(V4L2DeviceFormat *format)\n-{\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n-\tint ret;\n-\n-\tv4l2Format.type = bufferType_;\n-\tret = ioctl(fd_, 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-\n-\tformat->size.width = pix->width;\n-\tformat->size.height = pix->height;\n-\tformat->fourcc = pix->pixelformat;\n-\tformat->planesCount = pix->num_planes;\n-\n-\tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n-\t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n-\t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n-\t}\n-\n-\treturn 0;\n-}\n-\n-int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *format)\n-{\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n-\tint ret;\n-\n-\tv4l2Format.type = bufferType_;\n-\tpix->width = format->size.width;\n-\tpix->height = format->size.height;\n-\tpix->pixelformat = format->fourcc;\n-\tpix->num_planes = format->planesCount;\n-\tpix->field = V4L2_FIELD_NONE;\n-\n-\tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n-\t\tpix->plane_fmt[i].bytesperline = format->planes[i].bpl;\n-\t\tpix->plane_fmt[i].sizeimage = format->planes[i].size;\n-\t}\n-\n-\tret = ioctl(fd_, 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-\n-\t/*\n-\t * Return to caller the format actually applied on the device,\n-\t * which might differ from the requested one.\n-\t */\n-\tformat->size.width = pix->width;\n-\tformat->size.height = pix->height;\n-\tformat->fourcc = pix->pixelformat;\n-\tformat->planesCount = pix->num_planes;\n-\tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n-\t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n-\t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n-\t}\n-\n-\treturn 0;\n-}\n-\n-int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *format)\n-{\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n-\tint ret;\n-\n-\tv4l2Format.type = bufferType_;\n-\tret = ioctl(fd_, 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-\n-\tformat->size.width = pix->width;\n-\tformat->size.height = pix->height;\n-\tformat->fourcc = pix->pixelformat;\n-\tformat->planesCount = 1;\n-\tformat->planes[0].bpl = pix->bytesperline;\n-\tformat->planes[0].size = pix->sizeimage;\n-\n-\treturn 0;\n-}\n-\n-int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *format)\n-{\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n-\tint ret;\n-\n-\tv4l2Format.type = bufferType_;\n-\tpix->width = format->size.width;\n-\tpix->height = format->size.height;\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-\tif (ret) {\n-\t\tret = -errno;\n-\t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n-\t\treturn ret;\n-\t}\n-\n-\t/*\n-\t * Return to caller the format actually applied on the device,\n-\t * which might differ from the requested one.\n-\t */\n-\tformat->size.width = pix->width;\n-\tformat->size.height = pix->height;\n-\tformat->fourcc = pix->pixelformat;\n-\tformat->planesCount = 1;\n-\tformat->planes[0].bpl = pix->bytesperline;\n-\tformat->planes[0].size = pix->sizeimage;\n-\n-\treturn 0;\n-}\n-\n-int V4L2Device::requestBuffers(unsigned int count)\n-{\n-\tstruct v4l2_requestbuffers rb = {};\n-\tint ret;\n-\n-\trb.count = count;\n-\trb.type = bufferType_;\n-\trb.memory = memoryType_;\n-\n-\tret = ioctl(fd_, 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-\t\treturn ret;\n-\t}\n-\n-\tLOG(V4L2, Debug) << rb.count << \" buffers requested.\";\n-\n-\treturn rb.count;\n-}\n-\n-/**\n- * \\brief Request buffers to be allocated from the device and stored in the\n- *  buffer pool provided.\n- * \\param[out] pool BufferPool to populate with buffers\n- * \\return 0 on success or a negative error code otherwise\n- */\n-int V4L2Device::exportBuffers(BufferPool *pool)\n-{\n-\tunsigned int allocatedBuffers;\n-\tunsigned int i;\n-\tint ret;\n-\n-\tmemoryType_ = V4L2_MEMORY_MMAP;\n-\n-\tret = requestBuffers(pool->count());\n-\tif (ret < 0)\n-\t\treturn ret;\n-\n-\tallocatedBuffers = ret;\n-\tif (allocatedBuffers < pool->count()) {\n-\t\tLOG(V4L2, Error) << \"Not enough buffers provided by V4L2Device\";\n-\t\trequestBuffers(0);\n-\t\treturn -ENOMEM;\n-\t}\n-\n-\t/* Map the buffers. */\n-\tfor (i = 0; i < pool->count(); ++i) {\n-\t\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n-\t\tstruct v4l2_buffer buf = {};\n-\t\tBuffer &buffer = pool->buffers()[i];\n-\n-\t\tbuf.index = i;\n-\t\tbuf.type = bufferType_;\n-\t\tbuf.memory = memoryType_;\n-\t\tbuf.length = VIDEO_MAX_PLANES;\n-\t\tbuf.m.planes = planes;\n-\n-\t\tret = ioctl(fd_, 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-\t\t\tbreak;\n-\t\t}\n-\n-\t\tif (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {\n-\t\t\tfor (unsigned int p = 0; p < buf.length; ++p) {\n-\t\t\t\tret = createPlane(&buffer, p,\n-\t\t\t\t\t\t  buf.m.planes[p].length);\n-\t\t\t\tif (ret)\n-\t\t\t\t\tbreak;\n-\t\t\t}\n-\t\t} else {\n-\t\t\tret = createPlane(&buffer, 0, buf.length);\n-\t\t}\n-\n-\t\tif (ret) {\n-\t\t\tLOG(V4L2, Error) << \"Failed to create plane\";\n-\t\t\tbreak;\n-\t\t}\n-\t}\n-\n-\tif (ret) {\n-\t\trequestBuffers(0);\n-\t\tpool->destroyBuffers();\n-\t\treturn ret;\n-\t}\n-\n-\tbufferPool_ = pool;\n-\n-\treturn 0;\n-}\n-\n-int V4L2Device::createPlane(Buffer *buffer, unsigned int planeIndex,\n-\t\t\t    unsigned int length)\n-{\n-\tstruct v4l2_exportbuffer expbuf = {};\n-\tint ret;\n-\n-\tLOG(V4L2, Debug)\n-\t\t<< \"Buffer \" << buffer->index()\n-\t\t<< \" plane \" << planeIndex\n-\t\t<< \": length=\" << length;\n-\n-\texpbuf.type = bufferType_;\n-\texpbuf.index = buffer->index();\n-\texpbuf.plane = planeIndex;\n-\texpbuf.flags = O_RDWR;\n-\n-\tret = ioctl(fd_, 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-\t}\n-\n-\tbuffer->planes().emplace_back();\n-\tPlane &plane = buffer->planes().back();\n-\tplane.setDmabuf(expbuf.fd, length);\n-\t::close(expbuf.fd);\n-\n-\treturn 0;\n-}\n-\n-/**\n- * \\brief Import the externally allocated \\a pool of buffers\n- * \\param[in] pool BufferPool of buffers to import\n- * \\return 0 on success or a negative error code otherwise\n- */\n-int V4L2Device::importBuffers(BufferPool *pool)\n-{\n-\tunsigned int allocatedBuffers;\n-\tint ret;\n-\n-\tmemoryType_ = V4L2_MEMORY_DMABUF;\n-\n-\tret = requestBuffers(pool->count());\n-\tif (ret < 0)\n-\t\treturn ret;\n-\n-\tallocatedBuffers = ret;\n-\tif (allocatedBuffers < pool->count()) {\n-\t\tLOG(V4L2, Error)\n-\t\t\t<< \"Not enough buffers provided by V4L2Device\";\n-\t\trequestBuffers(0);\n-\t\treturn -ENOMEM;\n-\t}\n-\n-\tLOG(V4L2, Debug) << \"provided pool of \" << pool->count() << \" buffers\";\n-\tbufferPool_ = pool;\n+\tfd_ = ret;\n\n \treturn 0;\n }\n\n /**\n- * \\brief Release all internally allocated buffers\n- */\n-int V4L2Device::releaseBuffers()\n-{\n-\tLOG(V4L2, Debug) << \"Releasing bufferPool\";\n-\n-\tbufferPool_ = nullptr;\n-\n-\treturn requestBuffers(0);\n-}\n-\n-/**\n- * \\brief Queue a buffer into the device\n- * \\param[in] buffer The buffer to be queued\n+ * \\brief Close the device or subdevice\n  *\n- * For capture devices the \\a buffer will be filled with data by the device.\n- * For output devices the \\a buffer shall contain valid data and will be\n- * processed by the device. Once the device has finished processing the buffer,\n- * it will be available for dequeue.\n+ * Reset the file descriptor to -1\n  *\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Device::queueBuffer(Buffer *buffer)\n+int V4L2Device::close()\n {\n-\tstruct v4l2_buffer buf = {};\n-\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n-\tint ret;\n-\n-\tbuf.index = buffer->index();\n-\tbuf.type = bufferType_;\n-\tbuf.memory = memoryType_;\n-\tbuf.field = V4L2_FIELD_NONE;\n-\n-\tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\n-\n-\tif (buf.memory == V4L2_MEMORY_DMABUF) {\n-\t\tif (multiPlanar) {\n-\t\t\tfor (unsigned int p = 0;\n-\t\t\t     p < buffer->planes().size();\n-\t\t\t     p++)\n-\t\t\t\tplanes[p].m.fd = buffer->planes()[p].dmabuf();\n-\t\t} else {\n-\t\t\tbuf.m.fd = buffer->planes()[0].dmabuf();\n-\t\t}\n-\t}\n-\n-\tif (multiPlanar) {\n-\t\tbuf.length = buffer->planes().size();\n-\t\tbuf.m.planes = planes;\n-\t}\n-\n-\tif (V4L2_TYPE_IS_OUTPUT(bufferType_)) {\n-\t\tbuf.bytesused = buffer->bytesused_;\n-\t\tbuf.sequence = buffer->sequence_;\n-\t\tbuf.timestamp.tv_sec = buffer->timestamp_ / 1000000000;\n-\t\tbuf.timestamp.tv_usec = (buffer->timestamp_ / 1000) % 1000000;\n-\t}\n-\n-\tLOG(V4L2, Debug) << \"Queueing buffer \" << buf.index;\n+\tif (fd_ < 0)\n+\t\treturn 0;\n\n-\tret = ioctl(fd_, VIDIOC_QBUF, &buf);\n+\tint ret = ::close(fd_);\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+\t\tLOG(V4L2, Error) << \"Failed to close V4L2 device: \"\n+\t\t\t\t << strerror(-ret);\n \t\treturn ret;\n \t}\n\n-\tif (queuedBuffersCount_++ == 0)\n-\t\tfdEvent_->setEnabled(true);\n+\tfd_ = -1;\n\n \treturn 0;\n }\n\n /**\n- * \\brief Dequeue the next available buffer from the device\n- *\n- * This method dequeues the next available buffer from the device. If no buffer\n- * is available to be dequeued it will return nullptr immediately.\n- *\n- * \\return A pointer to the dequeued buffer on success, or nullptr otherwise\n- */\n-Buffer *V4L2Device::dequeueBuffer()\n-{\n-\tstruct v4l2_buffer buf = {};\n-\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n-\tint ret;\n-\n-\tbuf.type = bufferType_;\n-\tbuf.memory = memoryType_;\n-\n-\tif (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {\n-\t\tbuf.length = VIDEO_MAX_PLANES;\n-\t\tbuf.m.planes = planes;\n-\t}\n-\n-\tret = ioctl(fd_, 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-\t}\n-\n-\tASSERT(buf.index < bufferPool_->count());\n-\n-\tif (--queuedBuffersCount_ == 0)\n-\t\tfdEvent_->setEnabled(false);\n-\n-\tBuffer *buffer = &bufferPool_->buffers()[buf.index];\n-\n-\tbuffer->bytesused_ = buf.bytesused;\n-\tbuffer->timestamp_ = buf.timestamp.tv_sec * 1000000000ULL\n-\t\t\t   + buf.timestamp.tv_usec * 1000ULL;\n-\tbuffer->sequence_ = buf.sequence;\n-\tbuffer->status_ = buf.flags & V4L2_BUF_FLAG_ERROR\n-\t\t\t? Buffer::BufferError : Buffer::BufferSuccess;\n-\n-\treturn buffer;\n-}\n-\n-/**\n- * \\brief Slot to handle completed buffer events from the V4L2 device\n- * \\param[in] notifier The event notifier\n- *\n- * When this slot is called, a Buffer has become available from the device, and\n- * will be emitted through the bufferReady Signal.\n- *\n- * For Capture devices the Buffer will contain valid data.\n- * For Output devices the Buffer can be considered empty.\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-void V4L2Device::bufferAvailable(EventNotifier *notifier)\n-{\n-\tBuffer *buffer = dequeueBuffer();\n-\tif (!buffer)\n-\t\treturn;\n-\n-\tLOG(V4L2, Debug) << \"Buffer \" << buffer->index() << \" is available\";\n-\n-\t/* Notify anyone listening to the device. */\n-\tbufferReady.emit(buffer);\n-}\n-\n-/**\n- * \\var V4L2Device::bufferReady\n- * \\brief A Signal emitted when a buffer completes\n- */\n-\n-/**\n- * \\brief Start the video stream\n- * \\return 0 on success or a negative error code otherwise\n- */\n-int V4L2Device::streamOn()\n+bool V4L2Device::isOpen() const\n {\n-\tint ret;\n-\n-\tret = ioctl(fd_, 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-\t}\n-\n-\treturn 0;\n+\treturn fd_ != -1;\n }\n\n /**\n- * \\brief Stop the video stream\n- *\n- * Buffers that are still queued when the video stream is stopped are\n- * implicitly dequeued, but no bufferReady signal is emitted for them.\n- *\n+ * \\brief Perform an IOCTL system call on the device node\n+ * \\param request The IOCTL request code\n+ * \\param argp A poiunter to the IOCTL argument\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Device::streamOff()\n+int V4L2Device::ioctl(unsigned long request, void *argp)\n {\n-\tint ret;\n-\n-\tret = ioctl(fd_, 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-\t}\n-\n-\tqueuedBuffersCount_ = 0;\n-\tfdEvent_->setEnabled(false);\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- * \\brief Create a new video device instance from \\a entity in media device\n- * \\a media\n- * \\param[in] media The media device where the entity is registered\n- * \\param[in] entity The media entity name\n- *\n- * Releasing memory of the newly created instance is responsibility of the\n- * caller of this function.\n+ * \\var V4L2Device::fd_\n+ * \\brief The V4L2 device or subdevice device node file descriptor\n  *\n- * \\return A newly created V4L2Device on success, nullptr otherwise\n+ * The file descriptor is initialized to -1 and reset to this value once\n+ * the device or subdevice gets closed.\n  */\n-V4L2Device *V4L2Device::fromEntityName(const MediaDevice *media,\n-\t\t\t\t       const std::string &entity)\n-{\n-\tMediaEntity *mediaEntity = media->getEntityByName(entity);\n-\tif (!mediaEntity)\n-\t\treturn nullptr;\n-\n-\treturn new V4L2Device(mediaEntity);\n-}\n\n-} /* namespace libcamera */\n+}; /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdev.cpp\nsimilarity index 79%\nrename from src/libcamera/v4l2_subdevice.cpp\nrename to src/libcamera/v4l2_subdev.cpp\nindex fceee33156e9..60bbd07284ff 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdev.cpp\n@@ -2,10 +2,10 @@\n /*\n  * Copyright (C) 2019, Google Inc.\n  *\n- * v4l2_subdevice.cpp - V4L2 Subdevice\n+ * v4l2_subdev.cpp - V4L2 Subdevice\n  */\n\n-#include \"v4l2_subdevice.h\"\n+#include \"v4l2_subdev.h\"\n\n #include <fcntl.h>\n #include <iomanip>\n@@ -23,7 +23,7 @@\n #include \"media_object.h\"\n\n /**\n- * \\file v4l2_subdevice.h\n+ * \\file v4l2_subdev.h\n  * \\brief V4L2 Subdevice API\n  */\n\n@@ -44,7 +44,7 @@ LOG_DEFINE_CATEGORY(V4L2Subdev)\n  * as the \"media bus format\", and it is identified by a resolution and a pixel\n  * format identification code, known as the \"media bus code\", not to be confused\n  * with the fourcc code that identify the format of images when stored in memory\n- * (see V4L2Device::V4L2DeviceFormat).\n+ * (see V4L2Videodev::V4L2DeviceFormat).\n  *\n  * Media Bus formats supported by the V4L2 APIs are described in Section\n  * 4.15.3.4.1 of the \"Part I - Video for Linux API\" chapter of the \"Linux Media\n@@ -84,14 +84,14 @@ const std::string V4L2SubdeviceFormat::toString() const\n }\n\n /**\n- * \\class V4L2Subdevice\n+ * \\class V4L2Subdev\n  * \\brief A V4L2 subdevice as exposed by the Linux kernel\n  *\n- * The V4L2Subdevice class provides an API to the \"Sub-device interface\" as\n+ * The V4L2Subdev class provides an API to the \"Sub-device interface\" as\n  * described in section 4.15 of the \"Linux Media Infrastructure userspace API\"\n  * chapter of the Linux Kernel documentation.\n  *\n- * A V4L2Subdevice is constructed from a MediaEntity instance, using the system\n+ * A V4L2Subdev is constructed from a MediaEntity instance, using the system\n  * path of the entity's device node. No API call other than open(), isOpen()\n  * and close() shall be called on an unopened device instance. Upon destruction\n  * any device left open will be closed, and any resources released.\n@@ -101,65 +101,39 @@ const std::string V4L2SubdeviceFormat::toString() const\n  * \\brief Create a V4L2 subdevice from a MediaEntity using its device node\n  * path\n  */\n-V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)\n-\t: entity_(entity), fd_(-1)\n+V4L2Subdev::V4L2Subdev(const MediaEntity *entity)\n+\t: V4L2Device(), entity_(entity)\n {\n }\n\n-V4L2Subdevice::~V4L2Subdevice()\n+V4L2Subdev::~V4L2Subdev()\n {\n-\tclose();\n+\tV4L2Device::close();\n }\n\n /**\n  * \\brief Open a V4L2 subdevice\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Subdevice::open()\n+int V4L2Subdev::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+\tint ret = V4L2Device::open(entity_->deviceNode(), O_RDWR);\n+\tif (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+void V4L2Subdev::close()\n {\n-\tif (!isOpen())\n-\t\treturn;\n-\n-\t::close(fd_);\n-\tfd_ = -1;\n+\tV4L2Device::close();\n }\n\n /**\n- * \\fn V4L2Subdevice::entity()\n+ * \\fn V4L2Subdev::entity()\n  * \\brief Retrieve the media entity associated with the subdevice\n  * \\return The subdevice's associated media entity.\n  */\n@@ -170,7 +144,7 @@ void V4L2Subdevice::close()\n  * \\param[inout] rect The rectangle describing crop target area\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Subdevice::setCrop(unsigned int pad, Rectangle *rect)\n+int V4L2Subdev::setCrop(unsigned int pad, Rectangle *rect)\n {\n \treturn setSelection(pad, V4L2_SEL_TGT_CROP, rect);\n }\n@@ -181,7 +155,7 @@ int V4L2Subdevice::setCrop(unsigned int pad, Rectangle *rect)\n  * \\param[inout] rect The rectangle describing the compose target area\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect)\n+int V4L2Subdev::setCompose(unsigned int pad, Rectangle *rect)\n {\n \treturn setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect);\n }\n@@ -200,7 +174,7 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect)\n  * \\return A map of image formats associated with a list of image sizes, or\n  * an empty map on error or if the pad does not exist\n  */\n-FormatEnum V4L2Subdevice::formats(unsigned int pad)\n+FormatEnum V4L2Subdev::formats(unsigned int pad)\n {\n \tFormatEnum formatMap = {};\n \tstruct v4l2_subdev_mbus_code_enum mbusEnum = {};\n@@ -215,7 +189,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 = V4L2Device::ioctl(VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n \t\tif (ret)\n \t\t\tbreak;\n\n@@ -244,13 +218,13 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n  * \\param[out] format The image bus format\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n+int V4L2Subdev::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n {\n \tstruct v4l2_subdev_format subdevFmt = {};\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 = V4L2Device::ioctl(VIDIOC_SUBDEV_G_FMT, &subdevFmt);\n \tif (ret) {\n \t\tret = -errno;\n \t\tLOG(V4L2Subdev, Error)\n@@ -272,12 +246,12 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n  * \\param[inout] format The image bus format to apply to the subdevice's pad\n  *\n  * Apply the requested image format to the desired media pad and return the\n- * actually applied format parameters, as \\ref V4L2Subdevice::getFormat would\n+ * actually applied format parameters, as \\ref V4L2Subdev::getFormat would\n  * do.\n  *\n  * \\return 0 on success or a negative error code otherwise\n  */\n-int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n+int V4L2Subdev::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n {\n \tstruct v4l2_subdev_format subdevFmt = {};\n \tsubdevFmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n@@ -286,7 +260,7 @@ 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 = V4L2Device::ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n \tif (ret) {\n \t\tret = -errno;\n \t\tLOG(V4L2Subdev, Error)\n@@ -311,25 +285,25 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n  * Releasing memory of the newly created instance is responsibility of the\n  * caller of this function.\n  *\n- * \\return A newly created V4L2Subdevice on success, nullptr otherwise\n+ * \\return A newly created V4L2Subdev on success, nullptr otherwise\n  */\n-V4L2Subdevice *V4L2Subdevice::fromEntityName(const MediaDevice *media,\n-\t\t\t\t\t     const std::string &entity)\n+V4L2Subdev *V4L2Subdev::fromEntityName(const MediaDevice *media,\n+\t\t\t\t       const std::string &entity)\n {\n \tMediaEntity *mediaEntity = media->getEntityByName(entity);\n \tif (!mediaEntity)\n \t\treturn nullptr;\n\n-\treturn new V4L2Subdevice(mediaEntity);\n+\treturn new V4L2Subdev(mediaEntity);\n }\n\n-std::string V4L2Subdevice::logPrefix() const\n+std::string V4L2Subdev::logPrefix() const\n {\n \treturn \"'\" + entity_->name() + \"'\";\n }\n\n-int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n-\t\t\t\tstd::vector<SizeRange> *sizes)\n+int V4L2Subdev::enumPadSizes(unsigned int pad,unsigned int code,\n+\t\t\t     std::vector<SizeRange> *sizes)\n {\n \tstruct v4l2_subdev_frame_size_enum sizeEnum = {};\n \tint ret;\n@@ -339,7 +313,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 = V4L2Device::ioctl(VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n \t\tif (ret)\n \t\t\tbreak;\n\n@@ -362,8 +336,8 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n \treturn 0;\n }\n\n-int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n-\t\t\t\tRectangle *rect)\n+int V4L2Subdev::setSelection(unsigned int pad, unsigned int target,\n+\t\t\t     Rectangle *rect)\n {\n \tstruct v4l2_subdev_selection sel = {};\n\n@@ -377,7 +351,7 @@ 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 = V4L2Device::ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);\n \tif (ret < 0) {\n \t\tret = -errno;\n \t\tLOG(V4L2Subdev, Error)\ndiff --git a/src/libcamera/v4l2_videodev.cpp b/src/libcamera/v4l2_videodev.cpp\nnew file mode 100644\nindex 000000000000..6ad3af53a3bd\n--- /dev/null\n+++ b/src/libcamera/v4l2_videodev.cpp\n@@ -0,0 +1,992 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_videodev.cpp - V4L2 Video Device\n+ */\n+\n+#include \"v4l2_videodev.h\"\n+\n+#include <fcntl.h>\n+#include <iomanip>\n+#include <sstream>\n+#include <string.h>\n+#include <sys/ioctl.h>\n+#include <sys/mman.h>\n+#include <sys/time.h>\n+#include <unistd.h>\n+#include <vector>\n+\n+#include <libcamera/buffer.h>\n+#include <libcamera/event_notifier.h>\n+\n+#include \"log.h\"\n+#include \"media_device.h\"\n+#include \"media_object.h\"\n+\n+/**\n+ * \\file v4l2_videodev.h\n+ * \\brief V4L2 Video Device API\n+ */\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(V4L2)\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 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 V4L2Capability::card()\n+ * \\brief Retrieve the device card name\n+ * \\return The string containing the device name\n+ */\n+\n+/**\n+ * \\fn 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 V4L2Capability::device_caps()\n+ * \\brief Retrieve the capabilities of the device\n+ * \\return The device specific capabilities if V4L2_CAP_DEVICE_CAPS is set or\n+ * \t   driver capabilities otherwise\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isMultiplanar()\n+ * \\brief Identify if the device implements the V4L2 multiplanar APIs\n+ * \\return True if the device supports multiplanar APIs\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isCapture()\n+ * \\brief Identify if the device captures data\n+ * \\return True if the device can capture data\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isOutput()\n+ * \\brief Identify if the device outputs data\n+ * \\return True if the device can output data\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isVideo()\n+ * \\brief Identify if the device captures or outputs images\n+ * \\return True if the device can capture or output images\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isMeta()\n+ * \\brief Identify if the device captures or outputs image meta-data\n+ *\n+ * \\todo Add support for META_CAPTURE introduced in Linux v5.0\n+ *\n+ * \\return True if the device can capture or output image meta-data\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isVideoCapture()\n+ * \\brief Identify if the device captures images\n+ * \\return True if the device can capture images\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isVideoOutput()\n+ * \\brief Identify if the device outputs images\n+ * \\return True if the device can output images\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isMetaCapture()\n+ * \\brief Identify if the device captures image meta-data\n+ * \\return True if the device can capture image meta-data\n+ */\n+\n+/**\n+ * \\fn V4L2Capability::isMetaOutput()\n+ * \\brief Identify if the device outputs image meta-data\n+ * \\return True if the device can output image meta-data\n+ */\n+\n+/**\n+ * \\fn 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 V4L2DeviceFormat\n+ * \\brief The V4L2 device image format and sizes\n+ *\n+ * This class describes the image format and resolution to be programmed on a\n+ * V4L2 video device. The image format is defined by a fourcc code (as specified\n+ * by the V4L2 API with the V4L2_PIX_FMT_* macros), a resolution (width and\n+ * height) and one to three planes with configurable line stride and a total\n+ * per-plane size in bytes.\n+ *\n+ * Image formats, as defined by the V4L2 APIs, are categorised as packed,\n+ * semi-planar and planar, and describe the layout of the image pixel components\n+ * stored in memory.\n+ *\n+ * Packed image formats store pixel components one after the other, in a\n+ * contiguous memory area. Examples of packed image formats are YUYV\n+ * permutations, RGB with different pixel sub-sampling ratios such as RGB565 or\n+ * RGB666 or Raw-Bayer formats such as SRGGB8 or SGRBG12.\n+ *\n+ * Semi-planar and planar image formats store the pixel components in separate\n+ * and possibly non-contiguous memory areas, named planes, whose sizes depend on\n+ * the pixel components sub-sampling ratios, which are defined by the format.\n+ * Semi-planar formats use two planes to store pixel components and notable\n+ * examples of such formats are the NV12 and NV16 formats, while planar formats\n+ * use three planes to store pixel components and notable examples are YUV422\n+ * and YUV420.\n+ *\n+ * Image formats supported by the V4L2 API are defined and described in Section\n+ * number 2 of the \"Part I - Video for Linux API\" chapter of the \"Linux Media\n+ * Infrastructure userspace API\", part of the Linux kernel documentation.\n+ *\n+ * In the context of this document, packed image formats are referred to as\n+ * \"packed formats\" and semi-planar and planar image formats are referred to as\n+ * \"planar formats\".\n+ *\n+ * V4L2 also defines two different sets of APIs to work with devices that store\n+ * planes in contiguous or separate memory areas. They are named \"Single-plane\n+ * APIs\" and \"Multi-plane APIs\" respectively and are documented in Section 2.1\n+ * and Section 2.2 of the above mentioned \"Part I - Video for Linux API\"\n+ * documentation.\n+ *\n+ * The single-plane API allows, among other parameters, the configuration of the\n+ * image resolution, the pixel format and the stride length. In that case the\n+ * stride applies to all planes (possibly sub-sampled). The multi-plane API\n+ * allows configuring the resolution, the pixel format and a per-plane stride\n+ * length and total size.\n+ *\n+ * Packed image formats, which occupy a single memory area, are easily described\n+ * through the single-plane API. When used on a device that implements the\n+ * multi-plane API, only the size and stride information contained in the first\n+ * plane are taken into account.\n+ *\n+ * Planar image formats, which occupy distinct memory areas, are easily\n+ * described through the multi-plane APIs. When used on a device that implements\n+ * the single-plane API, all planes are stored one after the other in a\n+ * contiguous memory area, and it is not possible to configure per-plane stride\n+ * length and size, but only a global stride length which is applied to all\n+ * planes.\n+ *\n+ * The V4L2DeviceFormat class describes both packed and planar image formats,\n+ * regardless of the API type (single or multi plane) implemented by the device\n+ * the format has to be applied to. The total size and bytes per line of images\n+ * represented with packed formats are configured using the first entry of the\n+ * V4L2DeviceFormat::planes array, while the per-plane size and per-plane stride\n+ * length of images represented with planar image formats are configured using\n+ * the opportune number of entries of the V4L2DeviceFormat::planes array, as\n+ * prescribed by the image format definition (semi-planar formats use 2 entries,\n+ * while planar formats use the whole 3 entries). The number of valid entries of\n+ * the V4L2DeviceFormat::planes array is defined by the\n+ * V4L2DeviceFormat::planesCount value.\n+ */\n+\n+/**\n+ * \\var V4L2DeviceFormat::size\n+ * \\brief The image size in pixels\n+ */\n+\n+/**\n+ * \\var V4L2DeviceFormat::fourcc\n+ * \\brief The fourcc code describing the pixel encoding scheme\n+ *\n+ * The fourcc code, as defined by the V4L2 API with the V4L2_PIX_FMT_* macros,\n+ * that identifies the image format pixel encoding scheme.\n+ */\n+\n+/**\n+ * \\var V4L2DeviceFormat::planes\n+ * \\brief The per-plane memory size information\n+ *\n+ * Images are stored in memory in one or more data planes. Each data plane has a\n+ * specific line stride and memory size, which could differ from the image\n+ * visible sizes to accommodate padding at the end of lines and end of planes.\n+ * Only the first \\ref planesCount entries are considered valid.\n+ */\n+\n+/**\n+ * \\var V4L2DeviceFormat::planesCount\n+ * \\brief The number of valid data planes\n+ */\n+\n+/**\n+ * \\brief Assemble and return a string describing the format\n+ * \\return A string describing the V4L2DeviceFormat\n+ */\n+const std::string V4L2DeviceFormat::toString() const\n+{\n+\tstd::stringstream ss;\n+\n+\tss.fill(0);\n+\tss << size.toString() << \"-0x\" << std::hex << std::setw(8) << fourcc;\n+\n+\treturn ss.str();\n+}\n+\n+/**\n+ * \\class V4L2Videodev\n+ * \\brief V4L2Videodev 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+ * The V4L2Videodev class tracks queued buffers and handles buffer events. It\n+ * automatically dequeues completed buffers and emits the \\ref bufferReady\n+ * signal.\n+ *\n+ * Upon destruction any device left open will be closed, and any resources\n+ * released.\n+ */\n+\n+/**\n+ * \\brief Construct a V4L2Videodev\n+ * \\param[in] deviceNode The file-system path to the video device node\n+ */\n+V4L2Videodev::V4L2Videodev(const std::string &deviceNode)\n+\t: V4L2Device(), deviceNode_(deviceNode), bufferPool_(nullptr),\n+\t  queuedBuffersCount_(0), fdEvent_(nullptr)\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+\t */\n+\tbufferType_ = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;\n+\tmemoryType_ = V4L2_MEMORY_MMAP;\n+}\n+\n+/**\n+ * \\brief Construct a V4L2Videodev from a MediaEntity\n+ * \\param[in] entity The MediaEntity to build the device from\n+ *\n+ * Construct a V4L2Videodev from a MediaEntity's device node path.\n+ */\n+V4L2Videodev::V4L2Videodev(const MediaEntity *entity)\n+\t: V4L2Videodev(entity->deviceNode())\n+{\n+}\n+\n+V4L2Videodev::~V4L2Videodev()\n+{\n+\tV4L2Device::close();\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 V4L2Videodev::open()\n+{\n+\tint ret;\n+\n+\tret = V4L2Device::open(deviceNode_, O_RDWR | O_NONBLOCK);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tret = V4L2Device::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+\t\treturn ret;\n+\t}\n+\n+\tLOG(V4L2, Debug)\n+\t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n+\t\t<< caps_.driver() << \": \" << caps_.card();\n+\n+\tif (!caps_.hasStreaming()) {\n+\t\tLOG(V4L2, Error) << \"Device does not support streaming I/O\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/*\n+\t * Set buffer type and wait for read notifications on CAPTURE devices\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\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+\tfdEvent_->activated.connect(this, &V4L2Videodev::bufferAvailable);\n+\tfdEvent_->setEnabled(false);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Close the device, releasing any resources acquired by open()\n+ */\n+void V4L2Videodev::close()\n+{\n+\tif (fd() < 0)\n+\t\treturn;\n+\n+\treleaseBuffers();\n+\tdelete fdEvent_;\n+\n+\tV4L2Device::close();\n+}\n+\n+/**\n+ * \\fn V4L2Videodev::driverName()\n+ * \\brief Retrieve the name of the V4L2 device driver\n+ * \\return The string containing the driver name\n+ */\n+\n+/**\n+ * \\fn V4L2Videodev::deviceName()\n+ * \\brief Retrieve the name of the V4L2 device\n+ * \\return The string containing the device name\n+ */\n+\n+/**\n+ * \\fn V4L2Videodev::busName()\n+ * \\brief Retrieve the location of the device in the system\n+ * \\return The string containing the device location\n+ */\n+\n+/**\n+ * \\fn V4L2Videodev::deviceNode()\n+ * \\brief Retrieve the video device node path\n+ * \\return The video device device node path\n+ */\n+\n+std::string V4L2Videodev::logPrefix() const\n+{\n+\treturn deviceNode_ + (V4L2_TYPE_IS_OUTPUT(bufferType_) ? \"[out]\" : \"[cap]\");\n+}\n+\n+/**\n+ * \\brief Retrieve the image format set on the V4L2 device\n+ * \\param[out] format The image format applied on the device\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Videodev::getFormat(V4L2DeviceFormat *format)\n+{\n+\tif (caps_.isMeta())\n+\t\treturn getFormatMeta(format);\n+\telse if (caps_.isMultiplanar())\n+\t\treturn getFormatMultiplane(format);\n+\telse\n+\t\treturn getFormatSingleplane(format);\n+}\n+\n+/**\n+ * \\brief Configure an image format on the V4L2 device\n+ * \\param[inout] format The image format to apply to the device\n+ *\n+ * Apply the supplied \\a format to the device, and return the actually\n+ * applied format parameters, as \\ref V4L2Videodev::getFormat would do.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Videodev::setFormat(V4L2DeviceFormat *format)\n+{\n+\tif (caps_.isMeta())\n+\t\treturn setFormatMeta(format);\n+\telse if (caps_.isMultiplanar())\n+\t\treturn setFormatMultiplane(format);\n+\telse\n+\t\treturn setFormatSingleplane(format);\n+}\n+\n+int V4L2Videodev::getFormatMeta(V4L2DeviceFormat *format)\n+{\n+\tstruct v4l2_format v4l2Format = {};\n+\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n+\tint ret;\n+\n+\tv4l2Format.type = bufferType_;\n+\tret = V4L2Device::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+\n+\tformat->size.width = 0;\n+\tformat->size.height = 0;\n+\tformat->fourcc = pix->dataformat;\n+\tformat->planesCount = 1;\n+\tformat->planes[0].bpl = pix->buffersize;\n+\tformat->planes[0].size = pix->buffersize;\n+\n+\treturn 0;\n+}\n+\n+int V4L2Videodev::setFormatMeta(V4L2DeviceFormat *format)\n+{\n+\tstruct v4l2_format v4l2Format = {};\n+\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n+\tint ret;\n+\n+\tv4l2Format.type = bufferType_;\n+\tpix->dataformat = format->fourcc;\n+\tpix->buffersize = format->planes[0].size;\n+\tret = V4L2Device::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+\n+\t/*\n+\t * Return to caller the format actually applied on the device,\n+\t * which might differ from the requested one.\n+\t */\n+\tformat->size.width = 0;\n+\tformat->size.height = 0;\n+\tformat->fourcc = format->fourcc;\n+\tformat->planesCount = 1;\n+\tformat->planes[0].bpl = pix->buffersize;\n+\tformat->planes[0].size = pix->buffersize;\n+\n+\treturn 0;\n+}\n+\n+int V4L2Videodev::getFormatMultiplane(V4L2DeviceFormat *format)\n+{\n+\tstruct v4l2_format v4l2Format = {};\n+\tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n+\tint ret;\n+\n+\tv4l2Format.type = bufferType_;\n+\tret = V4L2Device::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+\n+\tformat->size.width = pix->width;\n+\tformat->size.height = pix->height;\n+\tformat->fourcc = pix->pixelformat;\n+\tformat->planesCount = pix->num_planes;\n+\n+\tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n+\t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n+\t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int V4L2Videodev::setFormatMultiplane(V4L2DeviceFormat *format)\n+{\n+\tstruct v4l2_format v4l2Format = {};\n+\tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n+\tint ret;\n+\n+\tv4l2Format.type = bufferType_;\n+\tpix->width = format->size.width;\n+\tpix->height = format->size.height;\n+\tpix->pixelformat = format->fourcc;\n+\tpix->num_planes = format->planesCount;\n+\tpix->field = V4L2_FIELD_NONE;\n+\n+\tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n+\t\tpix->plane_fmt[i].bytesperline = format->planes[i].bpl;\n+\t\tpix->plane_fmt[i].sizeimage = format->planes[i].size;\n+\t}\n+\n+\tret = V4L2Device::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+\n+\t/*\n+\t * Return to caller the format actually applied on the device,\n+\t * which might differ from the requested one.\n+\t */\n+\tformat->size.width = pix->width;\n+\tformat->size.height = pix->height;\n+\tformat->fourcc = pix->pixelformat;\n+\tformat->planesCount = pix->num_planes;\n+\tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n+\t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n+\t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int V4L2Videodev::getFormatSingleplane(V4L2DeviceFormat *format)\n+{\n+\tstruct v4l2_format v4l2Format = {};\n+\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n+\tint ret;\n+\n+\tv4l2Format.type = bufferType_;\n+\tret = V4L2Device::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+\n+\tformat->size.width = pix->width;\n+\tformat->size.height = pix->height;\n+\tformat->fourcc = pix->pixelformat;\n+\tformat->planesCount = 1;\n+\tformat->planes[0].bpl = pix->bytesperline;\n+\tformat->planes[0].size = pix->sizeimage;\n+\n+\treturn 0;\n+}\n+\n+int V4L2Videodev::setFormatSingleplane(V4L2DeviceFormat *format)\n+{\n+\tstruct v4l2_format v4l2Format = {};\n+\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n+\tint ret;\n+\n+\tv4l2Format.type = bufferType_;\n+\tpix->width = format->size.width;\n+\tpix->height = format->size.height;\n+\tpix->pixelformat = format->fourcc;\n+\tpix->bytesperline = format->planes[0].bpl;\n+\tpix->field = V4L2_FIELD_NONE;\n+\tret = V4L2Device::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+\n+\t/*\n+\t * Return to caller the format actually applied on the device,\n+\t * which might differ from the requested one.\n+\t */\n+\tformat->size.width = pix->width;\n+\tformat->size.height = pix->height;\n+\tformat->fourcc = pix->pixelformat;\n+\tformat->planesCount = 1;\n+\tformat->planes[0].bpl = pix->bytesperline;\n+\tformat->planes[0].size = pix->sizeimage;\n+\n+\treturn 0;\n+}\n+\n+int V4L2Videodev::requestBuffers(unsigned int count)\n+{\n+\tstruct v4l2_requestbuffers rb = {};\n+\tint ret;\n+\n+\trb.count = count;\n+\trb.type = bufferType_;\n+\trb.memory = memoryType_;\n+\n+\tret = V4L2Device::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+\t\treturn ret;\n+\t}\n+\n+\tLOG(V4L2, Debug) << rb.count << \" buffers requested.\";\n+\n+\treturn rb.count;\n+}\n+\n+/**\n+ * \\brief Request buffers to be allocated from the device and stored in the\n+ *  buffer pool provided.\n+ * \\param[out] pool BufferPool to populate with buffers\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Videodev::exportBuffers(BufferPool *pool)\n+{\n+\tunsigned int allocatedBuffers;\n+\tunsigned int i;\n+\tint ret;\n+\n+\tmemoryType_ = V4L2_MEMORY_MMAP;\n+\n+\tret = requestBuffers(pool->count());\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tallocatedBuffers = ret;\n+\tif (allocatedBuffers < pool->count()) {\n+\t\tLOG(V4L2, Error) << \"Not enough buffers provided by V4L2Videodev\";\n+\t\trequestBuffers(0);\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\t/* Map the buffers. */\n+\tfor (i = 0; i < pool->count(); ++i) {\n+\t\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n+\t\tstruct v4l2_buffer buf = {};\n+\t\tBuffer &buffer = pool->buffers()[i];\n+\n+\t\tbuf.index = i;\n+\t\tbuf.type = bufferType_;\n+\t\tbuf.memory = memoryType_;\n+\t\tbuf.length = VIDEO_MAX_PLANES;\n+\t\tbuf.m.planes = planes;\n+\n+\t\tret = V4L2Device::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+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {\n+\t\t\tfor (unsigned int p = 0; p < buf.length; ++p) {\n+\t\t\t\tret = createPlane(&buffer, p,\n+\t\t\t\t\t\t  buf.m.planes[p].length);\n+\t\t\t\tif (ret)\n+\t\t\t\t\tbreak;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tret = createPlane(&buffer, 0, buf.length);\n+\t\t}\n+\n+\t\tif (ret) {\n+\t\t\tLOG(V4L2, Error) << \"Failed to create plane\";\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (ret) {\n+\t\trequestBuffers(0);\n+\t\tpool->destroyBuffers();\n+\t\treturn ret;\n+\t}\n+\n+\tbufferPool_ = pool;\n+\n+\treturn 0;\n+}\n+\n+int V4L2Videodev::createPlane(Buffer *buffer, unsigned int planeIndex,\n+\t\t\t    unsigned int length)\n+{\n+\tstruct v4l2_exportbuffer expbuf = {};\n+\tint ret;\n+\n+\tLOG(V4L2, Debug)\n+\t\t<< \"Buffer \" << buffer->index()\n+\t\t<< \" plane \" << planeIndex\n+\t\t<< \": length=\" << length;\n+\n+\texpbuf.type = bufferType_;\n+\texpbuf.index = buffer->index();\n+\texpbuf.plane = planeIndex;\n+\texpbuf.flags = O_RDWR;\n+\n+\tret = V4L2Device::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+\t}\n+\n+\tbuffer->planes().emplace_back();\n+\tPlane &plane = buffer->planes().back();\n+\tplane.setDmabuf(expbuf.fd, length);\n+\t::close(expbuf.fd);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Import the externally allocated \\a pool of buffers\n+ * \\param[in] pool BufferPool of buffers to import\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Videodev::importBuffers(BufferPool *pool)\n+{\n+\tunsigned int allocatedBuffers;\n+\tint ret;\n+\n+\tmemoryType_ = V4L2_MEMORY_DMABUF;\n+\n+\tret = requestBuffers(pool->count());\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tallocatedBuffers = ret;\n+\tif (allocatedBuffers < pool->count()) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Not enough buffers provided by V4L2Videodev\";\n+\t\trequestBuffers(0);\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tLOG(V4L2, Debug) << \"provided pool of \" << pool->count() << \" buffers\";\n+\tbufferPool_ = pool;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Release all internally allocated buffers\n+ */\n+int V4L2Videodev::releaseBuffers()\n+{\n+\tLOG(V4L2, Debug) << \"Releasing bufferPool\";\n+\n+\tbufferPool_ = nullptr;\n+\n+\treturn requestBuffers(0);\n+}\n+\n+/**\n+ * \\brief Queue a buffer into the device\n+ * \\param[in] buffer The buffer to be queued\n+ *\n+ * For capture devices the \\a buffer will be filled with data by the device.\n+ * For output devices the \\a buffer shall contain valid data and will be\n+ * processed by the device. Once the device has finished processing the buffer,\n+ * it will be available for dequeue.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Videodev::queueBuffer(Buffer *buffer)\n+{\n+\tstruct v4l2_buffer buf = {};\n+\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n+\tint ret;\n+\n+\tbuf.index = buffer->index();\n+\tbuf.type = bufferType_;\n+\tbuf.memory = memoryType_;\n+\tbuf.field = V4L2_FIELD_NONE;\n+\n+\tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\n+\n+\tif (buf.memory == V4L2_MEMORY_DMABUF) {\n+\t\tif (multiPlanar) {\n+\t\t\tfor (unsigned int p = 0;\n+\t\t\t     p < buffer->planes().size();\n+\t\t\t     p++)\n+\t\t\t\tplanes[p].m.fd = buffer->planes()[p].dmabuf();\n+\t\t} else {\n+\t\t\tbuf.m.fd = buffer->planes()[0].dmabuf();\n+\t\t}\n+\t}\n+\n+\tif (multiPlanar) {\n+\t\tbuf.length = buffer->planes().size();\n+\t\tbuf.m.planes = planes;\n+\t}\n+\n+\tif (V4L2_TYPE_IS_OUTPUT(bufferType_)) {\n+\t\tbuf.bytesused = buffer->bytesused_;\n+\t\tbuf.sequence = buffer->sequence_;\n+\t\tbuf.timestamp.tv_sec = buffer->timestamp_ / 1000000000;\n+\t\tbuf.timestamp.tv_usec = (buffer->timestamp_ / 1000) % 1000000;\n+\t}\n+\n+\tLOG(V4L2, Debug) << \"Queueing buffer \" << buf.index;\n+\n+\tret = V4L2Device::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+\t\treturn ret;\n+\t}\n+\n+\tif (queuedBuffersCount_++ == 0)\n+\t\tfdEvent_->setEnabled(true);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Dequeue the next available buffer from the device\n+ *\n+ * This method dequeues the next available buffer from the device. If no buffer\n+ * is available to be dequeued it will return nullptr immediately.\n+ *\n+ * \\return A pointer to the dequeued buffer on success, or nullptr otherwise\n+ */\n+Buffer *V4L2Videodev::dequeueBuffer()\n+{\n+\tstruct v4l2_buffer buf = {};\n+\tstruct v4l2_plane planes[VIDEO_MAX_PLANES] = {};\n+\tint ret;\n+\n+\tbuf.type = bufferType_;\n+\tbuf.memory = memoryType_;\n+\n+\tif (V4L2_TYPE_IS_MULTIPLANAR(buf.type)) {\n+\t\tbuf.length = VIDEO_MAX_PLANES;\n+\t\tbuf.m.planes = planes;\n+\t}\n+\n+\tret = V4L2Device::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+\t}\n+\n+\tASSERT(buf.index < bufferPool_->count());\n+\n+\tif (--queuedBuffersCount_ == 0)\n+\t\tfdEvent_->setEnabled(false);\n+\n+\tBuffer *buffer = &bufferPool_->buffers()[buf.index];\n+\n+\tbuffer->bytesused_ = buf.bytesused;\n+\tbuffer->timestamp_ = buf.timestamp.tv_sec * 1000000000ULL\n+\t\t\t   + buf.timestamp.tv_usec * 1000ULL;\n+\tbuffer->sequence_ = buf.sequence;\n+\tbuffer->status_ = buf.flags & V4L2_BUF_FLAG_ERROR\n+\t\t\t? Buffer::BufferError : Buffer::BufferSuccess;\n+\n+\treturn buffer;\n+}\n+\n+/**\n+ * \\brief Slot to handle completed buffer events from the V4L2 device\n+ * \\param[in] notifier The event notifier\n+ *\n+ * When this slot is called, a Buffer has become available from the device, and\n+ * will be emitted through the bufferReady Signal.\n+ *\n+ * For Capture devices the Buffer will contain valid data.\n+ * For Output devices the Buffer can be considered empty.\n+ */\n+void V4L2Videodev::bufferAvailable(EventNotifier *notifier)\n+{\n+\tBuffer *buffer = dequeueBuffer();\n+\tif (!buffer)\n+\t\treturn;\n+\n+\tLOG(V4L2, Debug) << \"Buffer \" << buffer->index() << \" is available\";\n+\n+\t/* Notify anyone listening to the device. */\n+\tbufferReady.emit(buffer);\n+}\n+\n+/**\n+ * \\var V4L2Videodev::bufferReady\n+ * \\brief A Signal emitted when a buffer completes\n+ */\n+\n+/**\n+ * \\brief Start the video stream\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Videodev::streamOn()\n+{\n+\tint ret;\n+\n+\tret = V4L2Device::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+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Stop the video stream\n+ *\n+ * Buffers that are still queued when the video stream is stopped are\n+ * implicitly dequeued, but no bufferReady signal is emitted for them.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Videodev::streamOff()\n+{\n+\tint ret;\n+\n+\tret = V4L2Device::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+\t}\n+\n+\tqueuedBuffersCount_ = 0;\n+\tfdEvent_->setEnabled(false);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Create a new video device instance from \\a entity in media device\n+ * \\a media\n+ * \\param[in] media The media device where the entity is registered\n+ * \\param[in] entity The media entity name\n+ *\n+ * Releasing memory of the newly created instance is responsibility of the\n+ * caller of this function.\n+ *\n+ * \\return A newly created V4L2Videodev on success, nullptr otherwise\n+ */\n+V4L2Videodev *V4L2Videodev::fromEntityName(const MediaDevice *media,\n+\t\t\t\t\t   const std::string &entity)\n+{\n+\tMediaEntity *mediaEntity = media->getEntityByName(entity);\n+\tif (!mediaEntity)\n+\t\treturn nullptr;\n+\n+\treturn new V4L2Videodev(mediaEntity);\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/test/meson.build b/test/meson.build\nindex 609aeab80e7d..f23b560afc73 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -4,8 +4,8 @@ subdir('camera')\n subdir('ipa')\n subdir('media_device')\n subdir('pipeline')\n-subdir('v4l2_device')\n-subdir('v4l2_subdevice')\n+subdir('v4l2_videodev')\n+subdir('v4l2_subdev')\n\n public_tests = [\n     ['event',                           'event.cpp'],\ndiff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdev/list_formats.cpp\nsimilarity index 95%\nrename from test/v4l2_subdevice/list_formats.cpp\nrename to test/v4l2_subdev/list_formats.cpp\nindex 3f0edafcdcd7..cd9d8b58850d 100644\n--- a/test/v4l2_subdevice/list_formats.cpp\n+++ b/test/v4l2_subdev/list_formats.cpp\n@@ -11,15 +11,15 @@\n\n #include <libcamera/geometry.h>\n\n-#include \"v4l2_subdevice.h\"\n-#include \"v4l2_subdevice_test.h\"\n+#include \"v4l2_subdev.h\"\n+#include \"v4l2_subdev_test.h\"\n\n using namespace std;\n using namespace libcamera;\n\n /* List image formats on the \"Scaler\" subdevice of vimc media device.  */\n\n-class ListFormatsTest : public V4L2SubdeviceTest\n+class ListFormatsTest : public V4L2SubdevTest\n {\n protected:\n \tint run() override;\ndiff --git a/test/v4l2_subdevice/meson.build b/test/v4l2_subdev/meson.build\nsimilarity index 57%\nrename from test/v4l2_subdevice/meson.build\nrename to test/v4l2_subdev/meson.build\nindex 0521984b2a78..57fbead2170e 100644\n--- a/test/v4l2_subdevice/meson.build\n+++ b/test/v4l2_subdev/meson.build\n@@ -1,12 +1,12 @@\n-v4l2_subdevice_tests = [\n+v4l2_subdev_tests = [\n   [ 'list_formats',             'list_formats.cpp'],\n   [ 'test_formats',             'test_formats.cpp'],\n ]\n\n-foreach t : v4l2_subdevice_tests\n-    exe = executable(t[0], [t[1], 'v4l2_subdevice_test.cpp'],\n+foreach t : v4l2_subdev_tests\n+    exe = executable(t[0], [t[1], 'v4l2_subdev_test.cpp'],\n         dependencies : libcamera_dep,\n         link_with : test_libraries,\n         include_directories : test_includes_internal)\n-    test(t[0], exe, suite : 'v4l2_subdevice', is_parallel : false)\n+    test(t[0], exe, suite : 'v4l2_subdev', is_parallel : false)\n endforeach\ndiff --git a/test/v4l2_subdevice/test_formats.cpp b/test/v4l2_subdev/test_formats.cpp\nsimilarity index 93%\nrename from test/v4l2_subdevice/test_formats.cpp\nrename to test/v4l2_subdev/test_formats.cpp\nindex e90c2c2426da..819264c1a97e 100644\n--- a/test/v4l2_subdevice/test_formats.cpp\n+++ b/test/v4l2_subdev/test_formats.cpp\n@@ -8,15 +8,15 @@\n #include <climits>\n #include <iostream>\n\n-#include \"v4l2_subdevice.h\"\n-#include \"v4l2_subdevice_test.h\"\n+#include \"v4l2_subdev.h\"\n+#include \"v4l2_subdev_test.h\"\n\n using namespace std;\n using namespace libcamera;\n\n /* Test format handling on the \"Scaler\" subdevice of vimc media device.  */\n\n-class FormatHandlingTest : public V4L2SubdeviceTest\n+class FormatHandlingTest : public V4L2SubdevTest\n {\n protected:\n \tint run() override;\ndiff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdev/v4l2_subdev_test.cpp\nsimilarity index 84%\nrename from test/v4l2_subdevice/v4l2_subdevice_test.cpp\nrename to test/v4l2_subdev/v4l2_subdev_test.cpp\nindex 562a638cb28e..c9f26c5f88f4 100644\n--- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n+++ b/test/v4l2_subdev/v4l2_subdev_test.cpp\n@@ -2,7 +2,7 @@\n /*\n  * Copyright (C) 2019, Google Inc.\n  *\n- * v4l2_subdevice_test.cpp - VIMC-based V4L2 subdevice test\n+ * v4l2_subdev_test.cpp - VIMC-based V4L2 subdevice test\n  */\n\n #include <iostream>\n@@ -11,8 +11,8 @@\n\n #include \"device_enumerator.h\"\n #include \"media_device.h\"\n-#include \"v4l2_subdevice.h\"\n-#include \"v4l2_subdevice_test.h\"\n+#include \"v4l2_subdev.h\"\n+#include \"v4l2_subdev_test.h\"\n\n using namespace std;\n using namespace libcamera;\n@@ -25,7 +25,7 @@ using namespace libcamera;\n  * If the vimc module is not loaded, the test gets skipped.\n  */\n\n-int V4L2SubdeviceTest::init()\n+int V4L2SubdevTest::init()\n {\n \tenumerator_ = DeviceEnumerator::create();\n \tif (!enumerator_) {\n@@ -51,7 +51,7 @@ int V4L2SubdeviceTest::init()\n \t\treturn TestFail;\n \t}\n\n-\tscaler_ = new V4L2Subdevice(videoEntity);\n+\tscaler_ = new V4L2Subdev(videoEntity);\n \tif (scaler_->open()) {\n \t\tcerr << \"Unable to open video subdevice \"\n \t\t     << scaler_->entity()->deviceNode() << endl;\n@@ -61,7 +61,7 @@ int V4L2SubdeviceTest::init()\n \treturn 0;\n }\n\n-void V4L2SubdeviceTest::cleanup()\n+void V4L2SubdevTest::cleanup()\n {\n \tdelete scaler_;\n }\ndiff --git a/test/v4l2_subdevice/v4l2_subdevice_test.h b/test/v4l2_subdev/v4l2_subdev_test.h\nsimilarity index 76%\nrename from test/v4l2_subdevice/v4l2_subdevice_test.h\nrename to test/v4l2_subdev/v4l2_subdev_test.h\nindex 96646a155536..9e332daf9aec 100644\n--- a/test/v4l2_subdevice/v4l2_subdevice_test.h\n+++ b/test/v4l2_subdev/v4l2_subdev_test.h\n@@ -2,7 +2,7 @@\n /*\n  * Copyright (C) 2019, Google Inc.\n  *\n- * v4l2_subdevice_test.h - VIMC-based V4L2 subdevice test\n+ * v4l2_subdev_test.h - VIMC-based V4L2 subdevice test\n  */\n\n #ifndef __LIBCAMERA_V4L2_SUBDEVICE_TEST_H__\n@@ -13,14 +13,14 @@\n #include \"device_enumerator.h\"\n #include \"media_device.h\"\n #include \"test.h\"\n-#include \"v4l2_subdevice.h\"\n+#include \"v4l2_subdev.h\"\n\n using namespace libcamera;\n\n-class V4L2SubdeviceTest : public Test\n+class V4L2SubdevTest : public Test\n {\n public:\n-\tV4L2SubdeviceTest()\n+\tV4L2SubdevTest()\n \t\t: scaler_(nullptr){};\n\n protected:\n@@ -29,7 +29,7 @@ protected:\n\n \tstd::unique_ptr<DeviceEnumerator> enumerator_;\n \tstd::shared_ptr<MediaDevice> media_;\n-\tV4L2Subdevice *scaler_;\n+\tV4L2Subdev *scaler_;\n };\n\n #endif /* __LIBCAMERA_V4L2_SUBDEVICE_TEST_H__ */\ndiff --git a/test/v4l2_device/buffer_sharing.cpp b/test/v4l2_videodev/buffer_sharing.cpp\nsimilarity index 90%\nrename from test/v4l2_device/buffer_sharing.cpp\nrename to test/v4l2_videodev/buffer_sharing.cpp\nindex e63ddff85689..a997cd69af5c 100644\n--- a/test/v4l2_device/buffer_sharing.cpp\n+++ b/test/v4l2_videodev/buffer_sharing.cpp\n@@ -4,8 +4,8 @@\n  *\n  * libcamera V4L2 API tests\n  *\n- * Validate the function of exporting buffers from a V4L2Device and\n- * the ability to import them to another V4L2Device instance.\n+ * Validate the function of exporting buffers from a V4L2Videodev and\n+ * the ability to import them to another V4L2Videodev instance.\n  * Ensure that the Buffers can successfully be queued and dequeued\n  * between both devices.\n  */\n@@ -17,19 +17,19 @@\n #include <libcamera/event_dispatcher.h>\n #include <libcamera/timer.h>\n\n-#include \"v4l2_device_test.h\"\n+#include \"v4l2_videodev_test.h\"\n\n-class BufferSharingTest : public V4L2DeviceTest\n+class BufferSharingTest : public V4L2VideodevTest\n {\n public:\n \tBufferSharingTest()\n-\t\t: V4L2DeviceTest(\"vivid\", \"vivid-000-vid-cap\"),\n+\t\t: V4L2VideodevTest(\"vivid\", \"vivid-000-vid-cap\"),\n \t\t  output_(nullptr), framesCaptured_(0), framesOutput_(0) {}\n\n protected:\n \tint init()\n \t{\n-\t\tint ret = V4L2DeviceTest::init();\n+\t\tint ret = V4L2VideodevTest::init();\n \t\tif (ret)\n \t\t\treturn ret;\n\n@@ -38,7 +38,7 @@ protected:\n \t\tif (!entity)\n \t\t\treturn TestSkip;\n\n-\t\toutput_ = new V4L2Device(entity);\n+\t\toutput_ = new V4L2Videodev(entity);\n \t\tif (!output_) {\n \t\t\tstd::cout << \"Failed to create output device\" << std::endl;\n \t\t\treturn TestFail;\n@@ -171,13 +171,13 @@ protected:\n\n \t\tdelete output_;\n\n-\t\tV4L2DeviceTest::cleanup();\n+\t\tV4L2VideodevTest::cleanup();\n \t}\n\n private:\n \tconst unsigned int bufferCount = 4;\n\n-\tV4L2Device *output_;\n+\tV4L2Videodev *output_;\n\n \tunsigned int framesCaptured_;\n \tunsigned int framesOutput_;\ndiff --git a/test/v4l2_device/capture_async.cpp b/test/v4l2_videodev/capture_async.cpp\nsimilarity index 92%\nrename from test/v4l2_device/capture_async.cpp\nrename to test/v4l2_videodev/capture_async.cpp\nindex 69b1d5a13ed8..97b2a9d9f246 100644\n--- a/test/v4l2_device/capture_async.cpp\n+++ b/test/v4l2_videodev/capture_async.cpp\n@@ -12,13 +12,13 @@\n\n #include <iostream>\n\n-#include \"v4l2_device_test.h\"\n+#include \"v4l2_videodev_test.h\"\n\n-class CaptureAsyncTest : public V4L2DeviceTest\n+class CaptureAsyncTest : public V4L2VideodevTest\n {\n public:\n \tCaptureAsyncTest()\n-\t\t: V4L2DeviceTest(\"vimc\", \"Raw Capture 0\"), frames(0) {}\n+\t\t: V4L2VideodevTest(\"vimc\", \"Raw Capture 0\"), frames(0) {}\n\n \tvoid receiveBuffer(Buffer *buffer)\n \t{\ndiff --git a/test/v4l2_device/double_open.cpp b/test/v4l2_videodev/double_open.cpp\nsimilarity index 76%\nrename from test/v4l2_device/double_open.cpp\nrename to test/v4l2_videodev/double_open.cpp\nindex 53850620889b..b679be3b3319 100644\n--- a/test/v4l2_device/double_open.cpp\n+++ b/test/v4l2_videodev/double_open.cpp\n@@ -7,15 +7,15 @@\n\n #include <iostream>\n\n-#include \"v4l2_device_test.h\"\n+#include \"v4l2_videodev_test.h\"\n\n namespace {\n\n-class DoubleOpen : public V4L2DeviceTest\n+class DoubleOpen : public V4L2VideodevTest\n {\n public:\n \tDoubleOpen()\n-\t\t: V4L2DeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideodevTest(\"vimc\", \"Raw Capture 0\") {}\n protected:\n \tint run()\n \t{\n@@ -23,7 +23,7 @@ protected:\n\n \t\t/*\n \t\t * Expect failure: The device has already been opened by the\n-\t\t * V4L2DeviceTest base class\n+\t\t * V4L2VideodevTest base class\n \t\t */\n \t\tret = capture_->open();\n \t\tif (!ret) {\ndiff --git a/test/v4l2_device/formats.cpp b/test/v4l2_videodev/formats.cpp\nsimilarity index 86%\nrename from test/v4l2_device/formats.cpp\nrename to test/v4l2_videodev/formats.cpp\nindex 6be045ff754c..80b92a560c7a 100644\n--- a/test/v4l2_device/formats.cpp\n+++ b/test/v4l2_videodev/formats.cpp\n@@ -8,18 +8,18 @@\n #include <climits>\n #include <iostream>\n\n-#include \"v4l2_device.h\"\n+#include \"v4l2_videodev.h\"\n\n-#include \"v4l2_device_test.h\"\n+#include \"v4l2_videodev_test.h\"\n\n using namespace std;\n using namespace libcamera;\n\n-class Format : public V4L2DeviceTest\n+class Format : public V4L2VideodevTest\n {\n public:\n \tFormat()\n-\t\t: V4L2DeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideodevTest(\"vimc\", \"Raw Capture 0\") {}\n protected:\n \tint run()\n \t{\ndiff --git a/test/v4l2_device/meson.build b/test/v4l2_videodev/meson.build\nsimilarity index 75%\nrename from test/v4l2_device/meson.build\nrename to test/v4l2_videodev/meson.build\nindex de540b1ba6f5..34eb33d1c3ec 100644\n--- a/test/v4l2_device/meson.build\n+++ b/test/v4l2_videodev/meson.build\n@@ -1,6 +1,6 @@\n # Tests are listed in order of complexity.\n # They are not alphabetically sorted.\n-v4l2_device_tests = [\n+v4l2_videodev_tests = [\n     [ 'double_open',        'double_open.cpp' ],\n     [ 'formats',            'formats.cpp' ],\n     [ 'request_buffers',    'request_buffers.cpp' ],\n@@ -9,10 +9,10 @@ v4l2_device_tests = [\n     [ 'buffer_sharing',     'buffer_sharing.cpp' ],\n ]\n\n-foreach t : v4l2_device_tests\n-    exe = executable(t[0], [t[1], 'v4l2_device_test.cpp'],\n+foreach t : v4l2_videodev_tests\n+    exe = executable(t[0], [t[1], 'v4l2_videodev_test.cpp'],\n                      dependencies : libcamera_dep,\n                      link_with : test_libraries,\n                      include_directories : test_includes_internal)\n-    test(t[0], exe, suite : 'v4l2_device', is_parallel : false)\n+    test(t[0], exe, suite : 'v4l2_videodev', is_parallel : false)\n endforeach\ndiff --git a/test/v4l2_device/request_buffers.cpp b/test/v4l2_videodev/request_buffers.cpp\nsimilarity index 78%\nrename from test/v4l2_device/request_buffers.cpp\nrename to test/v4l2_videodev/request_buffers.cpp\nindex 7b7b06b2b409..493605e79746 100644\n--- a/test/v4l2_device/request_buffers.cpp\n+++ b/test/v4l2_videodev/request_buffers.cpp\n@@ -5,13 +5,13 @@\n  * libcamera V4L2 API tests\n  */\n\n-#include \"v4l2_device_test.h\"\n+#include \"v4l2_videodev_test.h\"\n\n-class RequestBuffersTest : public V4L2DeviceTest\n+class RequestBuffersTest : public V4L2VideodevTest\n {\n public:\n \tRequestBuffersTest()\n-\t\t: V4L2DeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideodevTest(\"vimc\", \"Raw Capture 0\") {}\n\n protected:\n \tint run()\ndiff --git a/test/v4l2_device/stream_on_off.cpp b/test/v4l2_videodev/stream_on_off.cpp\nsimilarity index 79%\nrename from test/v4l2_device/stream_on_off.cpp\nrename to test/v4l2_videodev/stream_on_off.cpp\nindex b158b8e402c8..fefe48c7ad39 100644\n--- a/test/v4l2_device/stream_on_off.cpp\n+++ b/test/v4l2_videodev/stream_on_off.cpp\n@@ -5,13 +5,13 @@\n  * libcamera V4L2 API tests\n  */\n\n-#include \"v4l2_device_test.h\"\n+#include \"v4l2_videodev_test.h\"\n\n-class StreamOnStreamOffTest : public V4L2DeviceTest\n+class StreamOnStreamOffTest : public V4L2VideodevTest\n {\n public:\n \tStreamOnStreamOffTest()\n-\t\t: V4L2DeviceTest(\"vimc\", \"Raw Capture 0\") {}\n+\t\t: V4L2VideodevTest(\"vimc\", \"Raw Capture 0\") {}\n protected:\n \tint run()\n \t{\ndiff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_videodev/v4l2_videodev_test.cpp\nsimilarity index 91%\nrename from test/v4l2_device/v4l2_device_test.cpp\nrename to test/v4l2_videodev/v4l2_videodev_test.cpp\nindex baad48f8aa9e..b3ed503567ee 100644\n--- a/test/v4l2_device/v4l2_device_test.cpp\n+++ b/test/v4l2_videodev/v4l2_videodev_test.cpp\n@@ -8,7 +8,7 @@\n #include <iostream>\n #include <sys/stat.h>\n\n-#include \"v4l2_device_test.h\"\n+#include \"v4l2_videodev_test.h\"\n\n #include \"device_enumerator.h\"\n #include \"media_device.h\"\n@@ -26,7 +26,7 @@ bool exists(const std::string &path)\n \treturn false;\n }\n\n-int V4L2DeviceTest::init()\n+int V4L2VideodevTest::init()\n {\n \tenumerator_ = DeviceEnumerator::create();\n \tif (!enumerator_) {\n@@ -50,7 +50,7 @@ int V4L2DeviceTest::init()\n \tif (!entity)\n \t\treturn TestSkip;\n\n-\tcapture_ = new V4L2Device(entity);\n+\tcapture_ = new V4L2Videodev(entity);\n \tif (!capture_)\n \t\treturn TestFail;\n\n@@ -77,7 +77,7 @@ int V4L2DeviceTest::init()\n \treturn TestPass;\n }\n\n-void V4L2DeviceTest::cleanup()\n+void V4L2VideodevTest::cleanup()\n {\n \tcapture_->streamOff();\n \tcapture_->releaseBuffers();\ndiff --git a/test/v4l2_device/v4l2_device_test.h b/test/v4l2_videodev/v4l2_videodev_test.h\nsimilarity index 82%\nrename from test/v4l2_device/v4l2_device_test.h\nrename to test/v4l2_videodev/v4l2_videodev_test.h\nindex 651c005f4e54..6298961b3b15 100644\n--- a/test/v4l2_device/v4l2_device_test.h\n+++ b/test/v4l2_videodev/v4l2_videodev_test.h\n@@ -15,14 +15,14 @@\n\n #include \"device_enumerator.h\"\n #include \"media_device.h\"\n-#include \"v4l2_device.h\"\n+#include \"v4l2_videodev.h\"\n\n using namespace libcamera;\n\n-class V4L2DeviceTest : public Test\n+class V4L2VideodevTest : public Test\n {\n public:\n-\tV4L2DeviceTest(const char *driver, const char *entity)\n+\tV4L2VideodevTest(const char *driver, const char *entity)\n \t\t: driver_(driver), entity_(entity), capture_(nullptr)\n \t{\n \t}\n@@ -35,7 +35,7 @@ protected:\n \tstd::string entity_;\n \tstd::unique_ptr<DeviceEnumerator> enumerator_;\n \tstd::shared_ptr<MediaDevice> media_;\n-\tV4L2Device *capture_;\n+\tV4L2Videodev *capture_;\n \tBufferPool pool_;\n };\n\n","prefixes":["libcamera-devel"]}