[{"id":31006,"web_url":"https://patchwork.libcamera.org/comment/31006/","msgid":"<20240831001651.GI3811@pendragon.ideasonboard.com>","date":"2024-08-31T00:16:51","subject":"Re: [PATCH v2 11/20] libcamera: v4l2: Formatting improvements","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, Aug 30, 2024 at 05:27:08PM +0200, Milan Zamazal wrote:\n> The LSP autoformatter doesn't like some of the current formatting, let's\n> make it happy.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/libcamera/v4l2_device.cpp      | 17 ++++++------\n>  src/libcamera/v4l2_subdevice.cpp   |  4 +--\n>  src/libcamera/v4l2_videodevice.cpp | 36 ++++++++++++-------------\n>  src/v4l2/v4l2_camera_proxy.cpp     | 43 ++++++++++++++----------------\n>  src/v4l2/v4l2_compat.cpp           | 19 +++++++------\n>  src/v4l2/v4l2_compat_manager.cpp   |  4 +--\n>  6 files changed, 60 insertions(+), 63 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 68add4f2..0da1c5ae 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -424,11 +424,12 @@ int V4L2Device::setFrameStartEnabled(bool enable)\n>  \tif (frameStartEnabled_ == enable)\n>  \t\treturn 0;\n>  \n> -\tstruct v4l2_event_subscription event{};\n> +\tstruct v4l2_event_subscription event {\n> +\t};\n>  \tevent.type = V4L2_EVENT_FRAME_SYNC;\n>  \n>  \tunsigned long request = enable ? VIDIOC_SUBSCRIBE_EVENT\n> -\t\t\t      : VIDIOC_UNSUBSCRIBE_EVENT;\n> +\t\t\t\t       : VIDIOC_UNSUBSCRIBE_EVENT;\n>  \tint ret = ioctl(request, &event);\n>  \tif (enable && ret)\n>  \t\treturn ret;\n> @@ -744,7 +745,8 @@ void V4L2Device::updateControls(ControlList *ctrls,\n>   */\n>  void V4L2Device::eventAvailable()\n>  {\n> -\tstruct v4l2_event event{};\n> +\tstruct v4l2_event event {\n> +\t};\n>  \tint ret = ioctl(VIDIOC_DQEVENT, &event);\n>  \tif (ret < 0) {\n>  \t\tLOG(V4L2, Error)\n> @@ -766,11 +768,10 @@ void V4L2Device::eventAvailable()\n>  \n>  static const std::map<uint32_t, ColorSpace> v4l2ToColorSpace = {\n>  \t{ V4L2_COLORSPACE_RAW, ColorSpace::Raw },\n> -\t{ V4L2_COLORSPACE_SRGB, {\n> -\t\tColorSpace::Primaries::Rec709,\n> -\t\tColorSpace::TransferFunction::Srgb,\n> -\t\tColorSpace::YcbcrEncoding::Rec601,\n> -\t\tColorSpace::Range::Limited } },\n> +\t{ V4L2_COLORSPACE_SRGB,\n> +\t  { ColorSpace::Primaries::Rec709,\n> +\t    ColorSpace::TransferFunction::Srgb,\n> +\t    ColorSpace::YcbcrEncoding::Rec601, ColorSpace::Range::Limited } },\n>  \t{ V4L2_COLORSPACE_JPEG, ColorSpace::Sycc },\n>  \t{ V4L2_COLORSPACE_SMPTE170M, ColorSpace::Smpte170m },\n>  \t{ V4L2_COLORSPACE_REC709, ColorSpace::Rec709 },\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 6eaa8f01..9f2ec479 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -17,11 +17,11 @@\n>  #include <linux/media-bus-format.h>\n>  #include <linux/v4l2-subdev.h>\n>  \n> -#include <libcamera/geometry.h>\n> -\n>  #include <libcamera/base/log.h>\n>  #include <libcamera/base/utils.h>\n>  \n> +#include <libcamera/geometry.h>\n> +\n\nThis is the only change in this patch that I think we should keep.\n\n>  #include \"libcamera/internal/formats.h\"\n>  #include \"libcamera/internal/media_device.h\"\n>  #include \"libcamera/internal/media_object.h\"\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 76742e18..1e913c88 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -606,13 +606,13 @@ int V4L2VideoDevice::open()\n>  \tif (caps_.isVideoCapture()) {\n>  \t\tnotifierType = 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\t\t\t      ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE\n> +\t\t\t\t      : V4L2_BUF_TYPE_VIDEO_CAPTURE;\n>  \t} else if (caps_.isVideoOutput()) {\n>  \t\tnotifierType = 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\t\t\t      ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE\n> +\t\t\t\t      : V4L2_BUF_TYPE_VIDEO_OUTPUT;\n>  \t} else if (caps_.isMetaCapture()) {\n>  \t\tnotifierType = EventNotifier::Read;\n>  \t\tbufferType_ = V4L2_BUF_TYPE_META_CAPTURE;\n> @@ -699,14 +699,14 @@ int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type)\n>  \tcase V4L2_BUF_TYPE_VIDEO_OUTPUT:\n>  \t\tnotifierType = 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\t\t\t      ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE\n> +\t\t\t\t      : V4L2_BUF_TYPE_VIDEO_OUTPUT;\n>  \t\tbreak;\n>  \tcase V4L2_BUF_TYPE_VIDEO_CAPTURE:\n>  \t\tnotifierType = 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\t\t\t      ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE\n> +\t\t\t\t      : V4L2_BUF_TYPE_VIDEO_CAPTURE;\n>  \t\tbreak;\n>  \tdefault:\n>  \t\tLOG(V4L2, Error) << \"Unsupported buffer type\";\n> @@ -792,7 +792,7 @@ void V4L2VideoDevice::close()\n>  std::string V4L2VideoDevice::logPrefix() const\n>  {\n>  \treturn deviceNode() + \"[\" + std::to_string(fd()) +\n> -\t\t(V4L2_TYPE_IS_OUTPUT(bufferType_) ? \":out]\" : \":cap]\");\n> +\t       (V4L2_TYPE_IS_OUTPUT(bufferType_) ? \":out]\" : \":cap]\");\n>  }\n>  \n>  /**\n> @@ -1133,7 +1133,7 @@ std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats(uint32_t code)\n>  \t\treturn {};\n>  \t}\n>  \n> -\tfor (unsigned int index = 0; ; index++) {\n> +\tfor (unsigned int index = 0;; index++) {\n>  \t\tstruct v4l2_fmtdesc pixelformatEnum = {};\n>  \t\tpixelformatEnum.index = index;\n>  \t\tpixelformatEnum.type = bufferType_;\n> @@ -1472,9 +1472,9 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n>  \t\t\t * account, which is equal to the bytesPerGroup ratio of\n>  \t\t\t * the planes.\n>  \t\t\t */\n> -\t\t\tunsigned int stride = format_.planes[0].bpl\n> -\t\t\t\t\t    * formatInfo_->planes[i].bytesPerGroup\n> -\t\t\t\t\t    / formatInfo_->planes[0].bytesPerGroup;\n> +\t\t\tunsigned int stride =\n> +\t\t\t\tformat_.planes[0].bpl * formatInfo_->planes[i].bytesPerGroup /\n> +\t\t\t\tformatInfo_->planes[0].bytesPerGroup;\n>  \n>  \t\t\tplane.fd = fd;\n>  \t\t\tplane.offset = offset;\n> @@ -1827,11 +1827,11 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n>  \tFrameMetadata &metadata = buffer->_d()->metadata();\n>  \n>  \tmetadata.status = buf.flags & V4L2_BUF_FLAG_ERROR\n> -\t\t\t? FrameMetadata::FrameError\n> -\t\t\t: FrameMetadata::FrameSuccess;\n> +\t\t\t\t  ? FrameMetadata::FrameError\n> +\t\t\t\t  : FrameMetadata::FrameSuccess;\n>  \tmetadata.sequence = buf.sequence;\n> -\tmetadata.timestamp = buf.timestamp.tv_sec * 1000000000ULL\n> -\t\t\t   + buf.timestamp.tv_usec * 1000ULL;\n> +\tmetadata.timestamp =\n> +\t\tbuf.timestamp.tv_sec * 1000000000ULL + buf.timestamp.tv_usec * 1000ULL;\n>  \n>  \tif (V4L2_TYPE_IS_OUTPUT(buf.type))\n>  \t\treturn buffer;\n> @@ -1875,7 +1875,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n>  \t\t * API.\n>  \t\t */\n>  \t\tunsigned int bytesused = multiPlanar ? planes[0].bytesused\n> -\t\t\t\t       : buf.bytesused;\n> +\t\t\t\t\t\t     : buf.bytesused;\n>  \t\tunsigned int remaining = bytesused;\n>  \n>  \t\tfor (auto [i, plane] : utils::enumerate(buffer->planes())) {\n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index a020a2b0..56c557b5 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -179,17 +179,17 @@ void V4L2CameraProxy::setFmtFromConfig(const StreamConfiguration &streamConfig)\n>  {\n>  \tconst Size &size = streamConfig.size;\n>  \n> -\tv4l2PixFormat_.width        = size.width;\n> -\tv4l2PixFormat_.height       = size.height;\n> -\tv4l2PixFormat_.pixelformat  = V4L2PixelFormat::fromPixelFormat(streamConfig.pixelFormat)[0];\n> -\tv4l2PixFormat_.field        = V4L2_FIELD_NONE;\n> +\tv4l2PixFormat_.width = size.width;\n> +\tv4l2PixFormat_.height = size.height;\n> +\tv4l2PixFormat_.pixelformat = V4L2PixelFormat::fromPixelFormat(streamConfig.pixelFormat)[0];\n> +\tv4l2PixFormat_.field = V4L2_FIELD_NONE;\n>  \tv4l2PixFormat_.bytesperline = streamConfig.stride;\n> -\tv4l2PixFormat_.sizeimage    = streamConfig.frameSize;\n> -\tv4l2PixFormat_.colorspace   = V4L2_COLORSPACE_SRGB;\n> -\tv4l2PixFormat_.priv         = V4L2_PIX_FMT_PRIV_MAGIC;\n> -\tv4l2PixFormat_.ycbcr_enc    = V4L2_YCBCR_ENC_DEFAULT;\n> +\tv4l2PixFormat_.sizeimage = streamConfig.frameSize;\n> +\tv4l2PixFormat_.colorspace = V4L2_COLORSPACE_SRGB;\n> +\tv4l2PixFormat_.priv = V4L2_PIX_FMT_PRIV_MAGIC;\n> +\tv4l2PixFormat_.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;\n>  \tv4l2PixFormat_.quantization = V4L2_QUANTIZATION_DEFAULT;\n> -\tv4l2PixFormat_.xfer_func    = V4L2_XFER_FUNC_DEFAULT;\n> +\tv4l2PixFormat_.xfer_func = V4L2_XFER_FUNC_DEFAULT;\n>  \n>  \tsizeimage_ = streamConfig.frameSize;\n>  }\n> @@ -207,11 +207,8 @@ void V4L2CameraProxy::querycap(std::shared_ptr<Camera> camera)\n>  \t\t       sizeof(capabilities_.bus_info));\n>  \t/* \\todo Put this in a header/config somewhere. */\n>  \tcapabilities_.version = KERNEL_VERSION(5, 2, 0);\n> -\tcapabilities_.device_caps = V4L2_CAP_VIDEO_CAPTURE\n> -\t\t\t\t  | V4L2_CAP_STREAMING\n> -\t\t\t\t  | V4L2_CAP_EXT_PIX_FORMAT;\n> -\tcapabilities_.capabilities = capabilities_.device_caps\n> -\t\t\t\t   | V4L2_CAP_DEVICE_CAPS;\n> +\tcapabilities_.device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | V4L2_CAP_EXT_PIX_FORMAT;\n> +\tcapabilities_.capabilities = capabilities_.device_caps | V4L2_CAP_DEVICE_CAPS;\n>  \tmemset(capabilities_.reserved, 0, sizeof(capabilities_.reserved));\n>  }\n>  \n> @@ -330,17 +327,17 @@ int V4L2CameraProxy::tryFormat(struct v4l2_format *arg)\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> -\targ->fmt.pix.width        = config.size.width;\n> -\targ->fmt.pix.height       = config.size.height;\n> -\targ->fmt.pix.pixelformat  = V4L2PixelFormat::fromPixelFormat(config.pixelFormat)[0];\n> -\targ->fmt.pix.field        = V4L2_FIELD_NONE;\n> +\targ->fmt.pix.width = config.size.width;\n> +\targ->fmt.pix.height = config.size.height;\n> +\targ->fmt.pix.pixelformat = V4L2PixelFormat::fromPixelFormat(config.pixelFormat)[0];\n> +\targ->fmt.pix.field = V4L2_FIELD_NONE;\n>  \targ->fmt.pix.bytesperline = config.stride;\n> -\targ->fmt.pix.sizeimage    = config.frameSize;\n> -\targ->fmt.pix.colorspace   = V4L2_COLORSPACE_SRGB;\n> -\targ->fmt.pix.priv         = V4L2_PIX_FMT_PRIV_MAGIC;\n> -\targ->fmt.pix.ycbcr_enc    = V4L2_YCBCR_ENC_DEFAULT;\n> +\targ->fmt.pix.sizeimage = config.frameSize;\n> +\targ->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;\n> +\targ->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;\n> +\targ->fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;\n>  \targ->fmt.pix.quantization = V4L2_QUANTIZATION_DEFAULT;\n> -\targ->fmt.pix.xfer_func    = V4L2_XFER_FUNC_DEFAULT;\n> +\targ->fmt.pix.xfer_func = V4L2_XFER_FUNC_DEFAULT;\n>  \n>  \treturn 0;\n>  }\n> diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\n> index ff833f57..a18d6cc9 100644\n> --- a/src/v4l2/v4l2_compat.cpp\n> +++ b/src/v4l2/v4l2_compat.cpp\n> @@ -5,8 +5,6 @@\n>   * V4L2 compatibility layer\n>   */\n>  \n> -#include \"v4l2_compat_manager.h\"\n> -\n>  #include <assert.h>\n>  #include <fcntl.h>\n>  #include <stdarg.h>\n> @@ -18,17 +16,19 @@\n>  \n>  #include <libcamera/base/utils.h>\n>  \n> +#include \"v4l2_compat_manager.h\"\n> +\n>  #define LIBCAMERA_PUBLIC __attribute__((visibility(\"default\")))\n>  \n>  using namespace libcamera;\n>  \n> -#define extract_va_arg(type, arg, last)\t\\\n> -{\t\t\t\t\t\\\n> -\tva_list ap;\t\t\t\\\n> -\tva_start(ap, last);\t\t\\\n> -\targ = va_arg(ap, type);\t\t\\\n> -\tva_end(ap);\t\t\t\\\n> -}\n> +#define extract_va_arg(type, arg, last) \\\n> +\t{                               \\\n> +\t\tva_list ap;             \\\n> +\t\tva_start(ap, last);     \\\n> +\t\targ = va_arg(ap, type); \\\n> +\t\tva_end(ap);             \\\n> +\t}\n>  \n>  namespace {\n>  \n> @@ -164,5 +164,4 @@ LIBCAMERA_PUBLIC int ioctl(int fd, unsigned long request, ...)\n>  \n>  \treturn V4L2CompatManager::instance()->ioctl(fd, request, arg);\n>  }\n> -\n>  }\n> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp\n> index f53fb300..54aba540 100644\n> --- a/src/v4l2/v4l2_compat_manager.cpp\n> +++ b/src/v4l2/v4l2_compat_manager.cpp\n> @@ -171,8 +171,8 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod\n>  \tfops_.close(fd);\n>  \n>  \tint efd = eventfd(0, EFD_SEMAPHORE |\n> -\t\t\t     ((oflag & O_CLOEXEC) ? EFD_CLOEXEC : 0) |\n> -\t\t\t     ((oflag & O_NONBLOCK) ? EFD_NONBLOCK : 0));\n> +\t\t\t\t     ((oflag & O_CLOEXEC) ? EFD_CLOEXEC : 0) |\n> +\t\t\t\t     ((oflag & O_NONBLOCK) ? EFD_NONBLOCK : 0));\n>  \tif (efd < 0)\n>  \t\treturn efd;\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B37E5C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 31 Aug 2024 00:17:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D1DC363469;\n\tSat, 31 Aug 2024 02:17:24 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 713DD63456\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 31 Aug 2024 02:17:23 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ADB0974C;\n\tSat, 31 Aug 2024 02:16:13 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"U5ZV7/Zq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1725063374;\n\tbh=xkE3/ioQvCOYDulGaCOjm2+btYmBab2DuzQBSRZnwaY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=U5ZV7/ZqANwUg4V7EUhw2erbV4jEsHIbUsVHfEdvkuV9jX1emwBb7CxcUr5GyxmKQ\n\tabQ1dmea1AUvhxxNxr7/EAbxOIlOI+n5BniQLf1xp+X/Ve79ElNt4UThty24DXBQ/Z\n\tOUV0dw8D5wK7JC6wjlGnZ9eKzTJ6utNY6wwNuJak=","Date":"Sat, 31 Aug 2024 03:16:51 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 11/20] libcamera: v4l2: Formatting improvements","Message-ID":"<20240831001651.GI3811@pendragon.ideasonboard.com>","References":"<20240830152721.1420313-1-mzamazal@redhat.com>\n\t<20240830152721.1420313-12-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240830152721.1420313-12-mzamazal@redhat.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]