[{"id":1881,"web_url":"https://patchwork.libcamera.org/comment/1881/","msgid":"<20190612205643.GA4778@bigcity.dyn.berto.se>","date":"2019-06-12T20:56:43","subject":"Re: [libcamera-devel] [PATCH v3 2/2] libcamera: Introduce\n\tV4L2Device base class","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2019-06-12 18:36:04 +0200, Jacopo Mondi wrote:\n> he V4L2 devices and subdevices share a few common operations,like\n\ns/^he/The/\n\n> opening and closing a device node, and perform IOCTLs on the device.\n> \n> With the forthcoming introduction of support for V4L2 controls, the\n> quantity of shared code will drastically increase, as the control\n> implementation is identical for the two.\n> \n> To maximize code re-use and avoid duplications, provide a V4L2Device\n> base class which groups the common operations and members.\n> \n> The newly introduced base class provides methods to open/close a device\n> node, access the file descriptor, and perform IOCTLs on the device.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/libcamera/include/v4l2_device.h      |  36 ++++++\n>  src/libcamera/include/v4l2_subdevice.h   |   6 +-\n>  src/libcamera/include/v4l2_videodevice.h |   5 +-\n>  src/libcamera/meson.build                |   2 +\n>  src/libcamera/v4l2_device.cpp            | 148 +++++++++++++++++++++++\n>  src/libcamera/v4l2_subdevice.cpp         |  69 +++--------\n>  src/libcamera/v4l2_videodevice.cpp       |  82 ++++---------\n>  7 files changed, 227 insertions(+), 121 deletions(-)\n>  create mode 100644 src/libcamera/include/v4l2_device.h\n>  create mode 100644 src/libcamera/v4l2_device.cpp\n> \n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> new file mode 100644\n> index 000000000000..584a570a4703\n> --- /dev/null\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -0,0 +1,36 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * v4l2_device.h - Common base for V4L2 video devices and subdevices\n> + */\n> +#ifndef __LIBCAMERA_V4L2_DEVICE_H__\n> +#define __LIBCAMERA_V4L2_DEVICE_H__\n> +\n> +#include <string>\n> +\n> +namespace libcamera {\n> +\n> +class V4L2Device\n> +{\n> +public:\n> +\tvirtual ~V4L2Device() { close(); }\n> +\n> +protected:\n> +\tV4L2Device();\n> +\n> +\tint fd() { return fd_; }\n> +\n> +\tint open(const std::string &pathname, unsigned int flags);\n> +\tint close();\n> +\tbool isOpen() const;\n> +\n> +\tint ioctl(unsigned long request, void *argp);\n> +\n> +private:\n> +\tint fd_;\n> +};\n> +\n> +} /* namespace libcamera */\n> +\n> +#endif /* __LIBCAMERA_V4L2_DEVICE_H__ */\n> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\n> index 3e4e5107aebe..a34b719f8c52 100644\n> --- a/src/libcamera/include/v4l2_subdevice.h\n> +++ b/src/libcamera/include/v4l2_subdevice.h\n> @@ -16,6 +16,7 @@\n>  #include \"formats.h\"\n>  #include \"log.h\"\n>  #include \"media_object.h\"\n> +#include \"v4l2_device.h\"\n>  \n>  namespace libcamera {\n>  \n> @@ -28,7 +29,7 @@ struct V4L2SubdeviceFormat {\n>  \tconst std::string toString() const;\n>  };\n>  \n> -class V4L2Subdevice : protected Loggable\n> +class V4L2Subdevice : public V4L2Device, protected Loggable\n>  {\n>  public:\n>  \texplicit V4L2Subdevice(const MediaEntity *entity);\n> @@ -37,8 +38,6 @@ public:\n>  \t~V4L2Subdevice();\n>  \n>  \tint open();\n> -\tbool isOpen() const;\n> -\tvoid close();\n>  \n>  \tconst MediaEntity *entity() const { return entity_; }\n>  \n> @@ -64,7 +63,6 @@ private:\n>  \t\t\t Rectangle *rect);\n>  \n>  \tconst MediaEntity *entity_;\n> -\tint fd_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index 6ecdb64e5f3c..15a83635b9bf 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -17,6 +17,7 @@\n>  #include <libcamera/signal.h>\n>  \n>  #include \"log.h\"\n> +#include \"v4l2_device.h\"\n>  \n>  namespace libcamera {\n>  \n> @@ -111,7 +112,7 @@ public:\n>  \tconst std::string toString() const;\n>  };\n>  \n> -class V4L2VideoDevice : protected Loggable\n> +class V4L2VideoDevice : public V4L2Device, protected Loggable\n>  {\n>  public:\n>  \texplicit V4L2VideoDevice(const std::string &deviceNode);\n> @@ -122,7 +123,6 @@ public:\n>  \tV4L2VideoDevice &operator=(const V4L2VideoDevice &) = delete;\n>  \n>  \tint open();\n> -\tbool isOpen() const;\n>  \tvoid close();\n>  \n>  \tconst char *driverName() const { return caps_.driver(); }\n> @@ -167,7 +167,6 @@ private:\n>  \tvoid bufferAvailable(EventNotifier *notifier);\n>  \n>  \tstd::string deviceNode_;\n> -\tint fd_;\n>  \tV4L2Capability caps_;\n>  \n>  \tenum v4l2_buf_type bufferType_;\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 15ab53b1abbe..f26ad5b2dc57 100644\n> --- a/src/libcamera/meson.build\n> +++ b/src/libcamera/meson.build\n> @@ -23,6 +23,7 @@ libcamera_sources = files([\n>      'stream.cpp',\n>      'timer.cpp',\n>      'utils.cpp',\n> +    'v4l2_device.cpp',\n>      'v4l2_subdevice.cpp',\n>      'v4l2_videodevice.cpp',\n>  ])\n> @@ -41,6 +42,7 @@ libcamera_headers = files([\n>      'include/media_object.h',\n>      'include/pipeline_handler.h',\n>      'include/utils.h',\n> +    'include/v4l2_device.h',\n>      'include/v4l2_subdevice.h',\n>      'include/v4l2_videodevice.h',\n>  ])\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> new file mode 100644\n> index 000000000000..bddd10e6f83c\n> --- /dev/null\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -0,0 +1,148 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * v4l2_device.cpp - Common base for V4L2 devices and subdevices\n\nOne line summary is different form the .h file.\n\n    v4l2_device.h - Common base for V4L2 video devices and subdevices\n\n> + */\n> +\n> +#include \"v4l2_device.h\"\n> +\n> +#include <fcntl.h>\n> +#include <string.h>\n> +#include <sys/ioctl.h>\n> +#include <unistd.h>\n> +\n> +#include \"log.h\"\n> +\n> +/**\n> + * \\file v4l2_device.h\n> + * \\brief Common base for V4L2 devices and subdevices\n> + */\n> +\n> +namespace libcamera {\n> +\n> +LOG_DEFINE_CATEGORY(V4L2)\n> +\n> +/**\n> + * \\class V4L2Device\n> + * \\brief Base class for V4L2Videodev and V4L2Subdev\n> + *\n> + * The V4L2Device class groups together the methods and fields common to\n> + * both V4L2Videodev and V4L2Subdev, and provide a base class which\n> + * provides methods to open and close the device node associated with the\n> + * device and to perform IOCTL system calls on it.\n> + *\n> + * The V4L2Device class cannot be instantiated directly, as its constructor\n> + * is protected. Users should use instead one the derived classes to model\n> + * either a V4L2 video device or a V4L2 subdevice.\n> + */\n> +\n> +/**\n> + * \\brief Construct a V4L2Device\n> + *\n> + * The V4L2Device constructor is protected and can only be accessed by the\n> + * V4L2Videodev and V4L2Subdev derived classes.\n> + *\n> + * Initialize the file descriptor to -1.\n> + */\n> +V4L2Device::V4L2Device()\n> +\t: fd_(-1)\n> +{\n> +}\n> +\n> +/**\n> + * \\fn V4L2Device::fd()\n> + * \\brief Retrieve the V4L2 device file descriptor\n> + * \\return The V4L2 device file descriptor, -1 if the device node is not open\n> + */\n> +\n> +/**\n> + * \\brief Open a V4L2 device node\n> + * \\param pathname The filesystem path of the device node to open\n> + * \\param flags Access mode flags\n> + *\n> + * Initialize the file descriptor, which was initially set to -1.\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2Device::open(const std::string &pathname, unsigned int flags)\n> +{\n> +\tif (isOpen()) {\n> +\t\tLOG(V4L2, Error) << \"Device already open\";\n> +\t\treturn -EBUSY;\n> +\t}\n> +\n> +\tint ret = ::open(pathname.c_str(), flags);\n> +\tif (ret < 0) {\n> +\t\tret = -errno;\n> +\t\tLOG(V4L2, Error) << \"Failed to open V4L2 device: \"\n> +\t\t\t\t << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tfd_ = ret;\n> +\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * \\brief Close the device node\n> + *\n> + * Reset the file descriptor to -1\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2Device::close()\n> +{\n> +\tif (fd_ < 0)\n> +\t\treturn 0;\n> +\n> +\tint ret = ::close(fd_);\n> +\tif (ret < 0) {\n> +\t\tret = -errno;\n> +\t\tLOG(V4L2, Error) << \"Failed to close V4L2 device: \"\n> +\t\t\t\t << strerror(-ret);\n> +\t\treturn ret;\n\nIs it really a good idea to return the error here and not set fd_ to -1 \n? I wonder if we should not keep the same signature as before the \nintroduction of the base class and V4L2Device::close() return a void.\n\nLooking in our code base not a single call site checks the return of any \nclose() call. And I'm not sure how we would recover if a close would \nfail. Either we make turn the Error into Fatal or we reset the fd anyhow \nand potentially leak it.\n\n> +\t}\n> +\n> +\tfd_ = -1;\n> +\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * \\brief Check if the V4L2 device node is open\n> + * \\return True if the V4L2 device node is open, false otherwise\n> + */\n> +bool V4L2Device::isOpen() const\n> +{\n> +\treturn fd_ != -1;\n> +}\n> +\n> +/**\n> + * \\brief Perform an IOCTL system call on the device node\n> + * \\param request The IOCTL request code\n> + * \\param argp A pointer to the IOCTL argument\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2Device::ioctl(unsigned long request, void *argp)\n> +{\n> +\t/*\n> +\t * Printing out an error message is usually better performed\n> +\t * in the caller, which can provide more context.\n> +\t */\n> +\tif (::ioctl(fd_, request, argp) < 0)\n> +\t\treturn -errno;\n> +\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * \\var V4L2Device::fd_\n> + * \\brief The V4L2 device node file descriptor\n\nnit: This is a private member of V4L2Device, I'm not sure it really \nneeds to be documented.\n\n> + *\n> + * The file descriptor is initialized to -1 and reset to this value once\n> + * the device node gets closed.\n> + */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 6681c1920065..52244d2ac3e1 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -29,7 +29,7 @@\n>  \n>  namespace libcamera {\n>  \n> -LOG_DEFINE_CATEGORY(V4L2Subdev)\n> +LOG_DECLARE_CATEGORY(V4L2)\n\nI'm not sure what I think about using the same log category for the base \nand the specific implementation. What is the upside of only having the \none?\n\n>  \n>  /**\n>   * \\struct V4L2SubdeviceFormat\n> @@ -102,7 +102,7 @@ const std::string V4L2SubdeviceFormat::toString() const\n>   * path\n>   */\n>  V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)\n> -\t: entity_(entity), fd_(-1)\n> +\t: V4L2Device(), entity_(entity)\n>  {\n>  }\n>  \n> @@ -117,45 +117,7 @@ V4L2Subdevice::~V4L2Subdevice()\n>   */\n>  int V4L2Subdevice::open()\n>  {\n> -\tint ret;\n> -\n> -\tif (isOpen()) {\n> -\t\tLOG(V4L2Subdev, Error) << \"Device already open\";\n> -\t\treturn -EBUSY;\n> -\t}\n> -\n> -\tret = ::open(entity_->deviceNode().c_str(), O_RDWR);\n> -\tif (ret < 0) {\n> -\t\tret = -errno;\n> -\t\tLOG(V4L2Subdev, Error)\n> -\t\t\t<< \"Failed to open V4L2 subdevice '\"\n> -\t\t\t<< entity_->deviceNode() << \"': \" << strerror(-ret);\n> -\t\treturn ret;\n> -\t}\n> -\tfd_ = ret;\n> -\n> -\treturn 0;\n> -}\n> -\n> -/**\n> - * \\brief Check if the subdevice is open\n> - * \\return True if the subdevice is open, false otherwise\n> - */\n> -bool V4L2Subdevice::isOpen() const\n> -{\n> -\treturn fd_ != -1;\n> -}\n> -\n> -/**\n> - * \\brief Close the subdevice, releasing any resources acquired by open()\n> - */\n> -void V4L2Subdevice::close()\n> -{\n> -\tif (!isOpen())\n> -\t\treturn;\n> -\n> -\t::close(fd_);\n> -\tfd_ = -1;\n> +\treturn V4L2Device::open(entity_->deviceNode(), O_RDWR);\n>  }\n>  \n>  /**\n> @@ -207,7 +169,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n>  \tint ret;\n>  \n>  \tif (pad >= entity_->pads().size()) {\n> -\t\tLOG(V4L2Subdev, Error) << \"Invalid pad: \" << pad;\n> +\t\tLOG(V4L2, Error) << \"Invalid pad: \" << pad;\n>  \t\treturn formatMap;\n>  \t}\n>  \n> @@ -215,7 +177,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n>  \tmbusEnum.index = 0;\n>  \tmbusEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n>  \twhile (true) {\n> -\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n> +\t\tret = ioctl(VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n>  \t\tif (ret)\n>  \t\t\tbreak;\n>  \n> @@ -229,7 +191,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n>  \n>  \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n>  \t\tret = -errno;\n> -\t\tLOG(V4L2Subdev, Error)\n> +\t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Unable to enumerate formats on pad \" << pad\n>  \t\t\t<< \": \" << strerror(-ret);\n>  \t\tformatMap.clear();\n> @@ -250,10 +212,9 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n>  \tsubdevFmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n>  \tsubdevFmt.pad = pad;\n>  \n> -\tint ret = ioctl(fd_, VIDIOC_SUBDEV_G_FMT, &subdevFmt);\n> +\tint ret = ioctl(VIDIOC_SUBDEV_G_FMT, &subdevFmt);\n>  \tif (ret) {\n> -\t\tret = -errno;\n> -\t\tLOG(V4L2Subdev, Error)\n> +\t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Unable to get format on pad \" << pad\n>  \t\t\t<< \": \" << strerror(-ret);\n>  \t\treturn ret;\n> @@ -286,10 +247,9 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n>  \tsubdevFmt.format.height = format->size.height;\n>  \tsubdevFmt.format.code = format->mbus_code;\n>  \n> -\tint ret = ioctl(fd_, VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n> +\tint ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n>  \tif (ret) {\n> -\t\tret = -errno;\n> -\t\tLOG(V4L2Subdev, Error)\n> +\t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Unable to set format on pad \" << pad\n>  \t\t\t<< \": \" << strerror(-ret);\n>  \t\treturn ret;\n> @@ -339,7 +299,7 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n>  \tsizeEnum.code = code;\n>  \tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n>  \twhile (true) {\n> -\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n> +\t\tret = ioctl(VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n>  \t\tif (ret)\n>  \t\t\tbreak;\n>  \n> @@ -351,7 +311,7 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n>  \n>  \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n>  \t\tret = -errno;\n> -\t\tLOG(V4L2Subdev, Error)\n> +\t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Unable to enumerate sizes on pad \" << pad\n>  \t\t\t<< \": \" << strerror(-ret);\n>  \t\tsizes->clear();\n> @@ -377,10 +337,9 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n>  \tsel.r.width = rect->w;\n>  \tsel.r.height = rect->h;\n>  \n> -\tint ret = ioctl(fd_, VIDIOC_SUBDEV_S_SELECTION, &sel);\n> +\tint ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n> -\t\tLOG(V4L2Subdev, Error)\n> +\t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Unable to set rectangle \" << target << \" on pad \"\n>  \t\t\t<< pad << \": \" << strerror(-ret);\n>  \t\treturn ret;\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 8957cf8f97d3..bc5b306e5ca3 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -30,7 +30,7 @@\n>   */\n>  namespace libcamera {\n>  \n> -LOG_DEFINE_CATEGORY(V4L2)\n> +LOG_DECLARE_CATEGORY(V4L2)\n>  \n>  /**\n>   * \\struct V4L2Capability\n> @@ -270,7 +270,7 @@ const std::string V4L2DeviceFormat::toString() const\n>   * \\param[in] deviceNode The file-system path to the video device node\n>   */\n>  V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n> -\t: deviceNode_(deviceNode), fd_(-1), bufferPool_(nullptr),\n> +\t: V4L2Device(), deviceNode_(deviceNode), bufferPool_(nullptr),\n>  \t  queuedBuffersCount_(0), fdEvent_(nullptr)\n>  {\n>  \t/*\n> @@ -305,23 +305,12 @@ int V4L2VideoDevice::open()\n>  {\n>  \tint ret;\n>  \n> -\tif (isOpen()) {\n> -\t\tLOG(V4L2, Error) << \"Device already open\";\n> -\t\treturn -EBUSY;\n> -\t}\n> -\n> -\tret = ::open(deviceNode_.c_str(), O_RDWR | O_NONBLOCK);\n> -\tif (ret < 0) {\n> -\t\tret = -errno;\n> -\t\tLOG(V4L2, Error)\n> -\t\t\t<< \"Failed to open V4L2 device: \" << strerror(-ret);\n> +\tret = V4L2Device::open(deviceNode_, O_RDWR | O_NONBLOCK);\n> +\tif (ret < 0)\n>  \t\treturn ret;\n> -\t}\n> -\tfd_ = ret;\n>  \n> -\tret = ioctl(fd_, VIDIOC_QUERYCAP, &caps_);\n> +\tret = ioctl(VIDIOC_QUERYCAP, &caps_);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Failed to query device capabilities: \"\n>  \t\t\t<< strerror(-ret);\n> @@ -342,20 +331,20 @@ int V4L2VideoDevice::open()\n>  \t * (POLLIN), and write notifications for OUTPUT devices (POLLOUT).\n>  \t */\n>  \tif (caps_.isVideoCapture()) {\n> -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Read);\n> +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\n>  \t\tbufferType_ = caps_.isMultiplanar()\n>  \t\t\t    ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE\n>  \t\t\t    : V4L2_BUF_TYPE_VIDEO_CAPTURE;\n>  \t} else if (caps_.isVideoOutput()) {\n> -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Write);\n> +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\n>  \t\tbufferType_ = caps_.isMultiplanar()\n>  \t\t\t    ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE\n>  \t\t\t    : V4L2_BUF_TYPE_VIDEO_OUTPUT;\n>  \t} else if (caps_.isMetaCapture()) {\n> -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Read);\n> +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\n>  \t\tbufferType_ = V4L2_BUF_TYPE_META_CAPTURE;\n>  \t} else if (caps_.isMetaOutput()) {\n> -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Write);\n> +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\n>  \t\tbufferType_ = V4L2_BUF_TYPE_META_OUTPUT;\n>  \t} else {\n>  \t\tLOG(V4L2, Error) << \"Device is not a supported type\";\n> @@ -368,28 +357,16 @@ int V4L2VideoDevice::open()\n>  \treturn 0;\n>  }\n>  \n> -/**\n> - * \\brief Check if device is successfully opened\n> - * \\return True if the device is open, false otherwise\n> - */\n> -bool V4L2VideoDevice::isOpen() const\n> -{\n> -\treturn fd_ != -1;\n> -}\n> -\n>  /**\n>   * \\brief Close the device, releasing any resources acquired by open()\n>   */\n>  void V4L2VideoDevice::close()\n>  {\n> -\tif (fd_ < 0)\n> +\tif (fd() < 0)\n>  \t\treturn;\n>  \n>  \treleaseBuffers();\n>  \tdelete fdEvent_;\n> -\n> -\t::close(fd_);\n> -\tfd_ = -1;\n\nShould you not call V4L2Device::close() here?\n\n>  }\n>  \n>  /**\n> @@ -462,9 +439,8 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n>  \tint ret;\n>  \n>  \tv4l2Format.type = bufferType_;\n> -\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n> +\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n>  \tif (ret) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n>  \t\treturn ret;\n>  \t}\n> @@ -488,9 +464,8 @@ int V4L2VideoDevice::setFormatMeta(V4L2DeviceFormat *format)\n>  \tv4l2Format.type = bufferType_;\n>  \tpix->dataformat = format->fourcc;\n>  \tpix->buffersize = format->planes[0].size;\n> -\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n> +\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n>  \tif (ret) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n>  \t\treturn ret;\n>  \t}\n> @@ -516,9 +491,8 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n>  \tint ret;\n>  \n>  \tv4l2Format.type = bufferType_;\n> -\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n> +\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n>  \tif (ret) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n>  \t\treturn ret;\n>  \t}\n> @@ -554,9 +528,8 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format)\n>  \t\tpix->plane_fmt[i].sizeimage = format->planes[i].size;\n>  \t}\n>  \n> -\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n> +\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n>  \tif (ret) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n>  \t\treturn ret;\n>  \t}\n> @@ -584,9 +557,8 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n>  \tint ret;\n>  \n>  \tv4l2Format.type = bufferType_;\n> -\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n> +\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n>  \tif (ret) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n>  \t\treturn ret;\n>  \t}\n> @@ -613,9 +585,8 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n>  \tpix->pixelformat = format->fourcc;\n>  \tpix->bytesperline = format->planes[0].bpl;\n>  \tpix->field = V4L2_FIELD_NONE;\n> -\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n> +\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n>  \tif (ret) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n>  \t\treturn ret;\n>  \t}\n> @@ -643,9 +614,8 @@ int V4L2VideoDevice::requestBuffers(unsigned int count)\n>  \trb.type = bufferType_;\n>  \trb.memory = memoryType_;\n>  \n> -\tret = ioctl(fd_, VIDIOC_REQBUFS, &rb);\n> +\tret = ioctl(VIDIOC_REQBUFS, &rb);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Unable to request \" << count << \" buffers: \"\n>  \t\t\t<< strerror(-ret);\n> @@ -695,9 +665,8 @@ int V4L2VideoDevice::exportBuffers(BufferPool *pool)\n>  \t\tbuf.length = VIDEO_MAX_PLANES;\n>  \t\tbuf.m.planes = planes;\n>  \n> -\t\tret = ioctl(fd_, VIDIOC_QUERYBUF, &buf);\n> +\t\tret = ioctl(VIDIOC_QUERYBUF, &buf);\n>  \t\tif (ret < 0) {\n> -\t\t\tret = -errno;\n>  \t\t\tLOG(V4L2, Error)\n>  \t\t\t\t<< \"Unable to query buffer \" << i << \": \"\n>  \t\t\t\t<< strerror(-ret);\n> @@ -748,9 +717,8 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex,\n>  \texpbuf.plane = planeIndex;\n>  \texpbuf.flags = O_RDWR;\n>  \n> -\tret = ioctl(fd_, VIDIOC_EXPBUF, &expbuf);\n> +\tret = ioctl(VIDIOC_EXPBUF, &expbuf);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n>  \t\treturn ret;\n> @@ -855,9 +823,8 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer)\n>  \n>  \tLOG(V4L2, Debug) << \"Queueing buffer \" << buf.index;\n>  \n> -\tret = ioctl(fd_, VIDIOC_QBUF, &buf);\n> +\tret = ioctl(VIDIOC_QBUF, &buf);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Failed to queue buffer \" << buf.index << \": \"\n>  \t\t\t<< strerror(-ret);\n> @@ -892,9 +859,8 @@ Buffer *V4L2VideoDevice::dequeueBuffer()\n>  \t\tbuf.m.planes = planes;\n>  \t}\n>  \n> -\tret = ioctl(fd_, VIDIOC_DQBUF, &buf);\n> +\tret = ioctl(VIDIOC_DQBUF, &buf);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Failed to dequeue buffer: \" << strerror(-ret);\n>  \t\treturn nullptr;\n> @@ -952,9 +918,8 @@ int V4L2VideoDevice::streamOn()\n>  {\n>  \tint ret;\n>  \n> -\tret = ioctl(fd_, VIDIOC_STREAMON, &bufferType_);\n> +\tret = ioctl(VIDIOC_STREAMON, &bufferType_);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Failed to start streaming: \" << strerror(-ret);\n>  \t\treturn ret;\n> @@ -975,9 +940,8 @@ int V4L2VideoDevice::streamOff()\n>  {\n>  \tint ret;\n>  \n> -\tret = ioctl(fd_, VIDIOC_STREAMOFF, &bufferType_);\n> +\tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n>  \tif (ret < 0) {\n> -\t\tret = -errno;\n>  \t\tLOG(V4L2, Error)\n>  \t\t\t<< \"Failed to stop streaming: \" << strerror(-ret);\n>  \t\treturn ret;\n> -- \n> 2.21.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C68C36336C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 12 Jun 2019 22:56:45 +0200 (CEST)","by mail-lj1-x243.google.com with SMTP id p17so9086280ljg.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 12 Jun 2019 13:56:45 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tr11sm167719ljh.90.2019.06.12.13.56.44\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tWed, 12 Jun 2019 13:56:44 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=N/kYX1rSZoelm1ASad9UmcpsKdiMlAPMkPyg9IemojU=;\n\tb=fGZYROEf1YXKFXOjFfIlrvyjUNx2p/UKU5hX2+o0Jp3w8vTpC5wc8rDEHVCm4IoIpo\n\tRByaIma/YXehI6WOxbGTCqrvEoh6e4A82poRAHHqZQWRddg7UoFveO2GDpRxLhFjQV/7\n\twOIM+fJRJg3OKfvmqRBVAxngENeYrVx/oycvSy8Bjx1yHhK2OJLTA2WBYov7ZJlhajd3\n\ttypkpSvSPCpEnTxmHIR71VzwoDAtFyBpSQXn53E9L68dOR2lQ/BQt1LeBHvtrYQO3Nkk\n\tkYdVXKTu9VIn9hmwaWy6z4Z38AUcYq4ziOJlCmaw5lzs9FBy+urOGEscg4Hs2CiB701r\n\tgjLw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=N/kYX1rSZoelm1ASad9UmcpsKdiMlAPMkPyg9IemojU=;\n\tb=jGxJrjPv39zrp0yBA9LqxRyRdaCX55uLuFGU9NTXFpr4rQDNqV/kpnCn8+FgU9ZmbW\n\tL+4poMSLSqnG6U0NYovA5cpFHgHzM+mNeGBejFMY/g1D3f72fTE5MGvTpIUr8Oj7Fvwx\n\tyscmZTkw1ujNPDbACbNRdUpZo9dCknLGoCbHMNyB/zFhW9xNffdQklGh/kewCkXzcpne\n\tJUaABQmiStq6jEDTa/3Eh3EGnC6ky66VbyJYpsCNilM5Ft3PoUAkadZK8Ju8J3ThJGUn\n\tNPQSYXL+9m2o7DcB7qW7PkfhiLoyzQ9uYjpaiVVaBlt0GkzdEGvthoTxMPfOOBWsbvWx\n\tPUHg==","X-Gm-Message-State":"APjAAAU9hS9w0p+eunAv9yxnJAnxI5WvP2LbwsRYohRFNt07zHwZwLvC\n\tN6H/qCRxbFnip/CTzm1l7Bbgdg==","X-Google-Smtp-Source":"APXvYqx1eXYxN8ESOCeo1wieYcoR5cKm+yHiOArrv9T2v8OWpnuVN7q25h6kNyTMaplq4CdpAwq9rg==","X-Received":"by 2002:a2e:8591:: with SMTP id\n\tb17mr34513153lji.71.1560373005003; \n\tWed, 12 Jun 2019 13:56:45 -0700 (PDT)","Date":"Wed, 12 Jun 2019 22:56:43 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190612205643.GA4778@bigcity.dyn.berto.se>","References":"<20190612163604.10037-1-jacopo@jmondi.org>\n\t<20190612163604.10037-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190612163604.10037-3-jacopo@jmondi.org>","User-Agent":"Mutt/1.12.0 (2019-05-25)","Subject":"Re: [libcamera-devel] [PATCH v3 2/2] libcamera: Introduce\n\tV4L2Device 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 20:56:46 -0000"}},{"id":1882,"web_url":"https://patchwork.libcamera.org/comment/1882/","msgid":"<20190613073755.gobzohbxh5cr3hn3@uno.localdomain>","date":"2019-06-13T07:37:55","subject":"Re: [libcamera-devel] [PATCH v3 2/2] libcamera: Introduce\n\tV4L2Device base class","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Wed, Jun 12, 2019 at 10:56:43PM +0200, Niklas Söderlund wrote:\n> Hi Jacopo,\n>\n> Thanks for your work.\n>\n> On 2019-06-12 18:36:04 +0200, Jacopo Mondi wrote:\n> > he V4L2 devices and subdevices share a few common operations,like\n>\n> s/^he/The/\n>\n\nUps, missed that from Kieran's review.\n\n> > opening and closing a device node, and perform IOCTLs on the device.\n> >\n> > With the forthcoming introduction of support for V4L2 controls, the\n> > quantity of shared code will drastically increase, as the control\n> > implementation is identical for the two.\n> >\n> > To maximize code re-use and avoid duplications, provide a V4L2Device\n> > base class which groups the common operations and members.\n> >\n> > The newly introduced base class provides methods to open/close a device\n> > node, access the file descriptor, and perform IOCTLs on the device.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >  src/libcamera/include/v4l2_device.h      |  36 ++++++\n> >  src/libcamera/include/v4l2_subdevice.h   |   6 +-\n> >  src/libcamera/include/v4l2_videodevice.h |   5 +-\n> >  src/libcamera/meson.build                |   2 +\n> >  src/libcamera/v4l2_device.cpp            | 148 +++++++++++++++++++++++\n> >  src/libcamera/v4l2_subdevice.cpp         |  69 +++--------\n> >  src/libcamera/v4l2_videodevice.cpp       |  82 ++++---------\n> >  7 files changed, 227 insertions(+), 121 deletions(-)\n> >  create mode 100644 src/libcamera/include/v4l2_device.h\n> >  create mode 100644 src/libcamera/v4l2_device.cpp\n> >\n> > diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> > new file mode 100644\n> > index 000000000000..584a570a4703\n> > --- /dev/null\n> > +++ b/src/libcamera/include/v4l2_device.h\n> > @@ -0,0 +1,36 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2019, Google Inc.\n> > + *\n> > + * v4l2_device.h - Common base for V4L2 video devices and subdevices\n> > + */\n> > +#ifndef __LIBCAMERA_V4L2_DEVICE_H__\n> > +#define __LIBCAMERA_V4L2_DEVICE_H__\n> > +\n> > +#include <string>\n> > +\n> > +namespace libcamera {\n> > +\n> > +class V4L2Device\n> > +{\n> > +public:\n> > +\tvirtual ~V4L2Device() { close(); }\n> > +\n> > +protected:\n> > +\tV4L2Device();\n> > +\n> > +\tint fd() { return fd_; }\n> > +\n> > +\tint open(const std::string &pathname, unsigned int flags);\n> > +\tint close();\n> > +\tbool isOpen() const;\n> > +\n> > +\tint ioctl(unsigned long request, void *argp);\n> > +\n> > +private:\n> > +\tint fd_;\n> > +};\n> > +\n> > +} /* namespace libcamera */\n> > +\n> > +#endif /* __LIBCAMERA_V4L2_DEVICE_H__ */\n> > diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\n> > index 3e4e5107aebe..a34b719f8c52 100644\n> > --- a/src/libcamera/include/v4l2_subdevice.h\n> > +++ b/src/libcamera/include/v4l2_subdevice.h\n> > @@ -16,6 +16,7 @@\n> >  #include \"formats.h\"\n> >  #include \"log.h\"\n> >  #include \"media_object.h\"\n> > +#include \"v4l2_device.h\"\n> >\n> >  namespace libcamera {\n> >\n> > @@ -28,7 +29,7 @@ struct V4L2SubdeviceFormat {\n> >  \tconst std::string toString() const;\n> >  };\n> >\n> > -class V4L2Subdevice : protected Loggable\n> > +class V4L2Subdevice : public V4L2Device, protected Loggable\n> >  {\n> >  public:\n> >  \texplicit V4L2Subdevice(const MediaEntity *entity);\n> > @@ -37,8 +38,6 @@ public:\n> >  \t~V4L2Subdevice();\n> >\n> >  \tint open();\n> > -\tbool isOpen() const;\n> > -\tvoid close();\n> >\n> >  \tconst MediaEntity *entity() const { return entity_; }\n> >\n> > @@ -64,7 +63,6 @@ private:\n> >  \t\t\t Rectangle *rect);\n> >\n> >  \tconst MediaEntity *entity_;\n> > -\tint fd_;\n> >  };\n> >\n> >  } /* namespace libcamera */\n> > diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> > index 6ecdb64e5f3c..15a83635b9bf 100644\n> > --- a/src/libcamera/include/v4l2_videodevice.h\n> > +++ b/src/libcamera/include/v4l2_videodevice.h\n> > @@ -17,6 +17,7 @@\n> >  #include <libcamera/signal.h>\n> >\n> >  #include \"log.h\"\n> > +#include \"v4l2_device.h\"\n> >\n> >  namespace libcamera {\n> >\n> > @@ -111,7 +112,7 @@ public:\n> >  \tconst std::string toString() const;\n> >  };\n> >\n> > -class V4L2VideoDevice : protected Loggable\n> > +class V4L2VideoDevice : public V4L2Device, protected Loggable\n> >  {\n> >  public:\n> >  \texplicit V4L2VideoDevice(const std::string &deviceNode);\n> > @@ -122,7 +123,6 @@ public:\n> >  \tV4L2VideoDevice &operator=(const V4L2VideoDevice &) = delete;\n> >\n> >  \tint open();\n> > -\tbool isOpen() const;\n> >  \tvoid close();\n> >\n> >  \tconst char *driverName() const { return caps_.driver(); }\n> > @@ -167,7 +167,6 @@ private:\n> >  \tvoid bufferAvailable(EventNotifier *notifier);\n> >\n> >  \tstd::string deviceNode_;\n> > -\tint fd_;\n> >  \tV4L2Capability caps_;\n> >\n> >  \tenum v4l2_buf_type bufferType_;\n> > diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> > index 15ab53b1abbe..f26ad5b2dc57 100644\n> > --- a/src/libcamera/meson.build\n> > +++ b/src/libcamera/meson.build\n> > @@ -23,6 +23,7 @@ libcamera_sources = files([\n> >      'stream.cpp',\n> >      'timer.cpp',\n> >      'utils.cpp',\n> > +    'v4l2_device.cpp',\n> >      'v4l2_subdevice.cpp',\n> >      'v4l2_videodevice.cpp',\n> >  ])\n> > @@ -41,6 +42,7 @@ libcamera_headers = files([\n> >      'include/media_object.h',\n> >      'include/pipeline_handler.h',\n> >      'include/utils.h',\n> > +    'include/v4l2_device.h',\n> >      'include/v4l2_subdevice.h',\n> >      'include/v4l2_videodevice.h',\n> >  ])\n> > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> > new file mode 100644\n> > index 000000000000..bddd10e6f83c\n> > --- /dev/null\n> > +++ b/src/libcamera/v4l2_device.cpp\n> > @@ -0,0 +1,148 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2019, Google Inc.\n> > + *\n> > + * v4l2_device.cpp - Common base for V4L2 devices and subdevices\n>\n> One line summary is different form the .h file.\n>\n>     v4l2_device.h - Common base for V4L2 video devices and subdevices\n>\n\nThanks! nice catch!\n\n> > + */\n> > +\n> > +#include \"v4l2_device.h\"\n> > +\n> > +#include <fcntl.h>\n> > +#include <string.h>\n> > +#include <sys/ioctl.h>\n> > +#include <unistd.h>\n> > +\n> > +#include \"log.h\"\n> > +\n> > +/**\n> > + * \\file v4l2_device.h\n> > + * \\brief Common base for V4L2 devices and subdevices\n> > + */\n> > +\n> > +namespace libcamera {\n> > +\n> > +LOG_DEFINE_CATEGORY(V4L2)\n> > +\n> > +/**\n> > + * \\class V4L2Device\n> > + * \\brief Base class for V4L2Videodev and V4L2Subdev\n> > + *\n> > + * The V4L2Device class groups together the methods and fields common to\n> > + * both V4L2Videodev and V4L2Subdev, and provide a base class which\n> > + * provides methods to open and close the device node associated with the\n> > + * device and to perform IOCTL system calls on it.\n> > + *\n> > + * The V4L2Device class cannot be instantiated directly, as its constructor\n> > + * is protected. Users should use instead one the derived classes to model\n> > + * either a V4L2 video device or a V4L2 subdevice.\n> > + */\n> > +\n> > +/**\n> > + * \\brief Construct a V4L2Device\n> > + *\n> > + * The V4L2Device constructor is protected and can only be accessed by the\n> > + * V4L2Videodev and V4L2Subdev derived classes.\n> > + *\n> > + * Initialize the file descriptor to -1.\n> > + */\n> > +V4L2Device::V4L2Device()\n> > +\t: fd_(-1)\n> > +{\n> > +}\n> > +\n> > +/**\n> > + * \\fn V4L2Device::fd()\n> > + * \\brief Retrieve the V4L2 device file descriptor\n> > + * \\return The V4L2 device file descriptor, -1 if the device node is not open\n> > + */\n> > +\n> > +/**\n> > + * \\brief Open a V4L2 device node\n> > + * \\param pathname The filesystem path of the device node to open\n> > + * \\param flags Access mode flags\n> > + *\n> > + * Initialize the file descriptor, which was initially set to -1.\n> > + *\n> > + * \\return 0 on success or a negative error code otherwise\n> > + */\n> > +int V4L2Device::open(const std::string &pathname, unsigned int flags)\n> > +{\n> > +\tif (isOpen()) {\n> > +\t\tLOG(V4L2, Error) << \"Device already open\";\n> > +\t\treturn -EBUSY;\n> > +\t}\n> > +\n> > +\tint ret = ::open(pathname.c_str(), flags);\n> > +\tif (ret < 0) {\n> > +\t\tret = -errno;\n> > +\t\tLOG(V4L2, Error) << \"Failed to open V4L2 device: \"\n> > +\t\t\t\t << strerror(-ret);\n> > +\t\treturn ret;\n> > +\t}\n> > +\n> > +\tfd_ = ret;\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> > +/**\n> > + * \\brief Close the device node\n> > + *\n> > + * Reset the file descriptor to -1\n> > + *\n> > + * \\return 0 on success or a negative error code otherwise\n> > + */\n> > +int V4L2Device::close()\n> > +{\n> > +\tif (fd_ < 0)\n> > +\t\treturn 0;\n> > +\n> > +\tint ret = ::close(fd_);\n> > +\tif (ret < 0) {\n> > +\t\tret = -errno;\n> > +\t\tLOG(V4L2, Error) << \"Failed to close V4L2 device: \"\n> > +\t\t\t\t << strerror(-ret);\n> > +\t\treturn ret;\n>\n> Is it really a good idea to return the error here and not set fd_ to -1\n> ? I wonder if we should not keep the same signature as before the\n> introduction of the base class and V4L2Device::close() return a void.\n>\n\nPossibly, yes.\n\n> Looking in our code base not a single call site checks the return of any\n> close() call. And I'm not sure how we would recover if a close would\n> fail. Either we make turn the Error into Fatal or we reset the fd anyhow\n> and potentially leak it.\n\nI should probably just ignore the ::close error and reset the fd to -1\nanyhow. However, I would print out a message in case of error.\n\n>\n> > +\t}\n> > +\n> > +\tfd_ = -1;\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> > +/**\n> > + * \\brief Check if the V4L2 device node is open\n> > + * \\return True if the V4L2 device node is open, false otherwise\n> > + */\n> > +bool V4L2Device::isOpen() const\n> > +{\n> > +\treturn fd_ != -1;\n> > +}\n> > +\n> > +/**\n> > + * \\brief Perform an IOCTL system call on the device node\n> > + * \\param request The IOCTL request code\n> > + * \\param argp A pointer to the IOCTL argument\n> > + * \\return 0 on success or a negative error code otherwise\n> > + */\n> > +int V4L2Device::ioctl(unsigned long request, void *argp)\n> > +{\n> > +\t/*\n> > +\t * Printing out an error message is usually better performed\n> > +\t * in the caller, which can provide more context.\n> > +\t */\n> > +\tif (::ioctl(fd_, request, argp) < 0)\n> > +\t\treturn -errno;\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> > +/**\n> > + * \\var V4L2Device::fd_\n> > + * \\brief The V4L2 device node file descriptor\n>\n> nit: This is a private member of V4L2Device, I'm not sure it really\n> needs to be documented.\n>\n\nNo, it does not, and the comment doesn't tell anything particularly\nuseful.\n\n> > + *\n> > + * The file descriptor is initialized to -1 and reset to this value once\n> > + * the device node gets closed.\n> > + */\n> > +\n> > +} /* namespace libcamera */\n> > diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> > index 6681c1920065..52244d2ac3e1 100644\n> > --- a/src/libcamera/v4l2_subdevice.cpp\n> > +++ b/src/libcamera/v4l2_subdevice.cpp\n> > @@ -29,7 +29,7 @@\n> >\n> >  namespace libcamera {\n> >\n> > -LOG_DEFINE_CATEGORY(V4L2Subdev)\n> > +LOG_DECLARE_CATEGORY(V4L2)\n>\n> I'm not sure what I think about using the same log category for the base\n> and the specific implementation. What is the upside of only having the\n> one?\n>\n\nAs the derived classes call into the base methods, we would end up\nwith the call path to an error printed out with different tags. I\nthink it's better to have the same in all three (the better would be\nfor have the base class use the tag defined by the derived class the\nfailing operation has been called on. I'm not sure it is possible\nthough).\n\n> >\n> >  /**\n> >   * \\struct V4L2SubdeviceFormat\n> > @@ -102,7 +102,7 @@ const std::string V4L2SubdeviceFormat::toString() const\n> >   * path\n> >   */\n> >  V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)\n> > -\t: entity_(entity), fd_(-1)\n> > +\t: V4L2Device(), entity_(entity)\n> >  {\n> >  }\n> >\n> > @@ -117,45 +117,7 @@ V4L2Subdevice::~V4L2Subdevice()\n> >   */\n> >  int V4L2Subdevice::open()\n> >  {\n> > -\tint ret;\n> > -\n> > -\tif (isOpen()) {\n> > -\t\tLOG(V4L2Subdev, Error) << \"Device already open\";\n> > -\t\treturn -EBUSY;\n> > -\t}\n> > -\n> > -\tret = ::open(entity_->deviceNode().c_str(), O_RDWR);\n> > -\tif (ret < 0) {\n> > -\t\tret = -errno;\n> > -\t\tLOG(V4L2Subdev, Error)\n> > -\t\t\t<< \"Failed to open V4L2 subdevice '\"\n> > -\t\t\t<< entity_->deviceNode() << \"': \" << strerror(-ret);\n> > -\t\treturn ret;\n> > -\t}\n> > -\tfd_ = ret;\n> > -\n> > -\treturn 0;\n> > -}\n> > -\n> > -/**\n> > - * \\brief Check if the subdevice is open\n> > - * \\return True if the subdevice is open, false otherwise\n> > - */\n> > -bool V4L2Subdevice::isOpen() const\n> > -{\n> > -\treturn fd_ != -1;\n> > -}\n> > -\n> > -/**\n> > - * \\brief Close the subdevice, releasing any resources acquired by open()\n> > - */\n> > -void V4L2Subdevice::close()\n> > -{\n> > -\tif (!isOpen())\n> > -\t\treturn;\n> > -\n> > -\t::close(fd_);\n> > -\tfd_ = -1;\n> > +\treturn V4L2Device::open(entity_->deviceNode(), O_RDWR);\n> >  }\n> >\n> >  /**\n> > @@ -207,7 +169,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n> >  \tint ret;\n> >\n> >  \tif (pad >= entity_->pads().size()) {\n> > -\t\tLOG(V4L2Subdev, Error) << \"Invalid pad: \" << pad;\n> > +\t\tLOG(V4L2, Error) << \"Invalid pad: \" << pad;\n> >  \t\treturn formatMap;\n> >  \t}\n> >\n> > @@ -215,7 +177,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n> >  \tmbusEnum.index = 0;\n> >  \tmbusEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n> >  \twhile (true) {\n> > -\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n> > +\t\tret = ioctl(VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);\n> >  \t\tif (ret)\n> >  \t\t\tbreak;\n> >\n> > @@ -229,7 +191,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n> >\n> >  \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n> >  \t\tret = -errno;\n> > -\t\tLOG(V4L2Subdev, Error)\n> > +\t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Unable to enumerate formats on pad \" << pad\n> >  \t\t\t<< \": \" << strerror(-ret);\n> >  \t\tformatMap.clear();\n> > @@ -250,10 +212,9 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n> >  \tsubdevFmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n> >  \tsubdevFmt.pad = pad;\n> >\n> > -\tint ret = ioctl(fd_, VIDIOC_SUBDEV_G_FMT, &subdevFmt);\n> > +\tint ret = ioctl(VIDIOC_SUBDEV_G_FMT, &subdevFmt);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> > -\t\tLOG(V4L2Subdev, Error)\n> > +\t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Unable to get format on pad \" << pad\n> >  \t\t\t<< \": \" << strerror(-ret);\n> >  \t\treturn ret;\n> > @@ -286,10 +247,9 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format)\n> >  \tsubdevFmt.format.height = format->size.height;\n> >  \tsubdevFmt.format.code = format->mbus_code;\n> >\n> > -\tint ret = ioctl(fd_, VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n> > +\tint ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> > -\t\tLOG(V4L2Subdev, Error)\n> > +\t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Unable to set format on pad \" << pad\n> >  \t\t\t<< \": \" << strerror(-ret);\n> >  \t\treturn ret;\n> > @@ -339,7 +299,7 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n> >  \tsizeEnum.code = code;\n> >  \tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n> >  \twhile (true) {\n> > -\t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n> > +\t\tret = ioctl(VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n> >  \t\tif (ret)\n> >  \t\t\tbreak;\n> >\n> > @@ -351,7 +311,7 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n> >\n> >  \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n> >  \t\tret = -errno;\n> > -\t\tLOG(V4L2Subdev, Error)\n> > +\t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Unable to enumerate sizes on pad \" << pad\n> >  \t\t\t<< \": \" << strerror(-ret);\n> >  \t\tsizes->clear();\n> > @@ -377,10 +337,9 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n> >  \tsel.r.width = rect->w;\n> >  \tsel.r.height = rect->h;\n> >\n> > -\tint ret = ioctl(fd_, VIDIOC_SUBDEV_S_SELECTION, &sel);\n> > +\tint ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> > -\t\tLOG(V4L2Subdev, Error)\n> > +\t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Unable to set rectangle \" << target << \" on pad \"\n> >  \t\t\t<< pad << \": \" << strerror(-ret);\n> >  \t\treturn ret;\n> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > index 8957cf8f97d3..bc5b306e5ca3 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -30,7 +30,7 @@\n> >   */\n> >  namespace libcamera {\n> >\n> > -LOG_DEFINE_CATEGORY(V4L2)\n> > +LOG_DECLARE_CATEGORY(V4L2)\n> >\n> >  /**\n> >   * \\struct V4L2Capability\n> > @@ -270,7 +270,7 @@ const std::string V4L2DeviceFormat::toString() const\n> >   * \\param[in] deviceNode The file-system path to the video device node\n> >   */\n> >  V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n> > -\t: deviceNode_(deviceNode), fd_(-1), bufferPool_(nullptr),\n> > +\t: V4L2Device(), deviceNode_(deviceNode), bufferPool_(nullptr),\n> >  \t  queuedBuffersCount_(0), fdEvent_(nullptr)\n> >  {\n> >  \t/*\n> > @@ -305,23 +305,12 @@ int V4L2VideoDevice::open()\n> >  {\n> >  \tint ret;\n> >\n> > -\tif (isOpen()) {\n> > -\t\tLOG(V4L2, Error) << \"Device already open\";\n> > -\t\treturn -EBUSY;\n> > -\t}\n> > -\n> > -\tret = ::open(deviceNode_.c_str(), O_RDWR | O_NONBLOCK);\n> > -\tif (ret < 0) {\n> > -\t\tret = -errno;\n> > -\t\tLOG(V4L2, Error)\n> > -\t\t\t<< \"Failed to open V4L2 device: \" << strerror(-ret);\n> > +\tret = V4L2Device::open(deviceNode_, O_RDWR | O_NONBLOCK);\n> > +\tif (ret < 0)\n> >  \t\treturn ret;\n> > -\t}\n> > -\tfd_ = ret;\n> >\n> > -\tret = ioctl(fd_, VIDIOC_QUERYCAP, &caps_);\n> > +\tret = ioctl(VIDIOC_QUERYCAP, &caps_);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Failed to query device capabilities: \"\n> >  \t\t\t<< strerror(-ret);\n> > @@ -342,20 +331,20 @@ int V4L2VideoDevice::open()\n> >  \t * (POLLIN), and write notifications for OUTPUT devices (POLLOUT).\n> >  \t */\n> >  \tif (caps_.isVideoCapture()) {\n> > -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Read);\n> > +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\n> >  \t\tbufferType_ = caps_.isMultiplanar()\n> >  \t\t\t    ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE\n> >  \t\t\t    : V4L2_BUF_TYPE_VIDEO_CAPTURE;\n> >  \t} else if (caps_.isVideoOutput()) {\n> > -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Write);\n> > +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\n> >  \t\tbufferType_ = caps_.isMultiplanar()\n> >  \t\t\t    ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE\n> >  \t\t\t    : V4L2_BUF_TYPE_VIDEO_OUTPUT;\n> >  \t} else if (caps_.isMetaCapture()) {\n> > -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Read);\n> > +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Read);\n> >  \t\tbufferType_ = V4L2_BUF_TYPE_META_CAPTURE;\n> >  \t} else if (caps_.isMetaOutput()) {\n> > -\t\tfdEvent_ = new EventNotifier(fd_, EventNotifier::Write);\n> > +\t\tfdEvent_ = new EventNotifier(fd(), EventNotifier::Write);\n> >  \t\tbufferType_ = V4L2_BUF_TYPE_META_OUTPUT;\n> >  \t} else {\n> >  \t\tLOG(V4L2, Error) << \"Device is not a supported type\";\n> > @@ -368,28 +357,16 @@ int V4L2VideoDevice::open()\n> >  \treturn 0;\n> >  }\n> >\n> > -/**\n> > - * \\brief Check if device is successfully opened\n> > - * \\return True if the device is open, false otherwise\n> > - */\n> > -bool V4L2VideoDevice::isOpen() const\n> > -{\n> > -\treturn fd_ != -1;\n> > -}\n> > -\n> >  /**\n> >   * \\brief Close the device, releasing any resources acquired by open()\n> >   */\n> >  void V4L2VideoDevice::close()\n> >  {\n> > -\tif (fd_ < 0)\n> > +\tif (fd() < 0)\n> >  \t\treturn;\n> >\n> >  \treleaseBuffers();\n> >  \tdelete fdEvent_;\n> > -\n> > -\t::close(fd_);\n> > -\tfd_ = -1;\n>\n> Should you not call V4L2Device::close() here?\n>\n\nIndeed I should! I thought I had it! Nice catch!\n\nThanks\n   j\n\n\n> >  }\n> >\n> >  /**\n> > @@ -462,9 +439,8 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n> >  \tint ret;\n> >\n> >  \tv4l2Format.type = bufferType_;\n> > -\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n> > +\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n> >  \t\treturn ret;\n> >  \t}\n> > @@ -488,9 +464,8 @@ int V4L2VideoDevice::setFormatMeta(V4L2DeviceFormat *format)\n> >  \tv4l2Format.type = bufferType_;\n> >  \tpix->dataformat = format->fourcc;\n> >  \tpix->buffersize = format->planes[0].size;\n> > -\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n> > +\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n> >  \t\treturn ret;\n> >  \t}\n> > @@ -516,9 +491,8 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n> >  \tint ret;\n> >\n> >  \tv4l2Format.type = bufferType_;\n> > -\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n> > +\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n> >  \t\treturn ret;\n> >  \t}\n> > @@ -554,9 +528,8 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format)\n> >  \t\tpix->plane_fmt[i].sizeimage = format->planes[i].size;\n> >  \t}\n> >\n> > -\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n> > +\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n> >  \t\treturn ret;\n> >  \t}\n> > @@ -584,9 +557,8 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n> >  \tint ret;\n> >\n> >  \tv4l2Format.type = bufferType_;\n> > -\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n> > +\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n> >  \t\treturn ret;\n> >  \t}\n> > @@ -613,9 +585,8 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n> >  \tpix->pixelformat = format->fourcc;\n> >  \tpix->bytesperline = format->planes[0].bpl;\n> >  \tpix->field = V4L2_FIELD_NONE;\n> > -\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n> > +\tret = ioctl(VIDIOC_S_FMT, &v4l2Format);\n> >  \tif (ret) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n> >  \t\treturn ret;\n> >  \t}\n> > @@ -643,9 +614,8 @@ int V4L2VideoDevice::requestBuffers(unsigned int count)\n> >  \trb.type = bufferType_;\n> >  \trb.memory = memoryType_;\n> >\n> > -\tret = ioctl(fd_, VIDIOC_REQBUFS, &rb);\n> > +\tret = ioctl(VIDIOC_REQBUFS, &rb);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Unable to request \" << count << \" buffers: \"\n> >  \t\t\t<< strerror(-ret);\n> > @@ -695,9 +665,8 @@ int V4L2VideoDevice::exportBuffers(BufferPool *pool)\n> >  \t\tbuf.length = VIDEO_MAX_PLANES;\n> >  \t\tbuf.m.planes = planes;\n> >\n> > -\t\tret = ioctl(fd_, VIDIOC_QUERYBUF, &buf);\n> > +\t\tret = ioctl(VIDIOC_QUERYBUF, &buf);\n> >  \t\tif (ret < 0) {\n> > -\t\t\tret = -errno;\n> >  \t\t\tLOG(V4L2, Error)\n> >  \t\t\t\t<< \"Unable to query buffer \" << i << \": \"\n> >  \t\t\t\t<< strerror(-ret);\n> > @@ -748,9 +717,8 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex,\n> >  \texpbuf.plane = planeIndex;\n> >  \texpbuf.flags = O_RDWR;\n> >\n> > -\tret = ioctl(fd_, VIDIOC_EXPBUF, &expbuf);\n> > +\tret = ioctl(VIDIOC_EXPBUF, &expbuf);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Failed to export buffer: \" << strerror(-ret);\n> >  \t\treturn ret;\n> > @@ -855,9 +823,8 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer)\n> >\n> >  \tLOG(V4L2, Debug) << \"Queueing buffer \" << buf.index;\n> >\n> > -\tret = ioctl(fd_, VIDIOC_QBUF, &buf);\n> > +\tret = ioctl(VIDIOC_QBUF, &buf);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Failed to queue buffer \" << buf.index << \": \"\n> >  \t\t\t<< strerror(-ret);\n> > @@ -892,9 +859,8 @@ Buffer *V4L2VideoDevice::dequeueBuffer()\n> >  \t\tbuf.m.planes = planes;\n> >  \t}\n> >\n> > -\tret = ioctl(fd_, VIDIOC_DQBUF, &buf);\n> > +\tret = ioctl(VIDIOC_DQBUF, &buf);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Failed to dequeue buffer: \" << strerror(-ret);\n> >  \t\treturn nullptr;\n> > @@ -952,9 +918,8 @@ int V4L2VideoDevice::streamOn()\n> >  {\n> >  \tint ret;\n> >\n> > -\tret = ioctl(fd_, VIDIOC_STREAMON, &bufferType_);\n> > +\tret = ioctl(VIDIOC_STREAMON, &bufferType_);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Failed to start streaming: \" << strerror(-ret);\n> >  \t\treturn ret;\n> > @@ -975,9 +940,8 @@ int V4L2VideoDevice::streamOff()\n> >  {\n> >  \tint ret;\n> >\n> > -\tret = ioctl(fd_, VIDIOC_STREAMOFF, &bufferType_);\n> > +\tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n> >  \tif (ret < 0) {\n> > -\t\tret = -errno;\n> >  \t\tLOG(V4L2, Error)\n> >  \t\t\t<< \"Failed to stop streaming: \" << strerror(-ret);\n> >  \t\treturn ret;\n> > --\n> > 2.21.0\n> >\n> > _______________________________________________\n> > libcamera-devel mailing list\n> > libcamera-devel@lists.libcamera.org\n> > https://lists.libcamera.org/listinfo/libcamera-devel\n>\n> --\n> Regards,\n> Niklas Söderlund","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E3E863587\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2019 09:36:43 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 86CBE1BF210;\n\tThu, 13 Jun 2019 07:36:42 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Thu, 13 Jun 2019 09:37:55 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190613073755.gobzohbxh5cr3hn3@uno.localdomain>","References":"<20190612163604.10037-1-jacopo@jmondi.org>\n\t<20190612163604.10037-3-jacopo@jmondi.org>\n\t<20190612205643.GA4778@bigcity.dyn.berto.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"qwm56mz3ivt3q4lo\"","Content-Disposition":"inline","In-Reply-To":"<20190612205643.GA4778@bigcity.dyn.berto.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH v3 2/2] libcamera: Introduce\n\tV4L2Device 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":"Thu, 13 Jun 2019 07:36:43 -0000"}}]