[PATCH v2 11/20] libcamera: v4l2: Formatting improvements

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sat Aug 31 02:16:51 CEST 2024


On Fri, Aug 30, 2024 at 05:27:08PM +0200, Milan Zamazal wrote:
> The LSP autoformatter doesn't like some of the current formatting, let's
> make it happy.
> 
> Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
> ---
>  src/libcamera/v4l2_device.cpp      | 17 ++++++------
>  src/libcamera/v4l2_subdevice.cpp   |  4 +--
>  src/libcamera/v4l2_videodevice.cpp | 36 ++++++++++++-------------
>  src/v4l2/v4l2_camera_proxy.cpp     | 43 ++++++++++++++----------------
>  src/v4l2/v4l2_compat.cpp           | 19 +++++++------
>  src/v4l2/v4l2_compat_manager.cpp   |  4 +--
>  6 files changed, 60 insertions(+), 63 deletions(-)
> 
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 68add4f2..0da1c5ae 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -424,11 +424,12 @@ int V4L2Device::setFrameStartEnabled(bool enable)
>  	if (frameStartEnabled_ == enable)
>  		return 0;
>  
> -	struct v4l2_event_subscription event{};
> +	struct v4l2_event_subscription event {
> +	};
>  	event.type = V4L2_EVENT_FRAME_SYNC;
>  
>  	unsigned long request = enable ? VIDIOC_SUBSCRIBE_EVENT
> -			      : VIDIOC_UNSUBSCRIBE_EVENT;
> +				       : VIDIOC_UNSUBSCRIBE_EVENT;
>  	int ret = ioctl(request, &event);
>  	if (enable && ret)
>  		return ret;
> @@ -744,7 +745,8 @@ void V4L2Device::updateControls(ControlList *ctrls,
>   */
>  void V4L2Device::eventAvailable()
>  {
> -	struct v4l2_event event{};
> +	struct v4l2_event event {
> +	};
>  	int ret = ioctl(VIDIOC_DQEVENT, &event);
>  	if (ret < 0) {
>  		LOG(V4L2, Error)
> @@ -766,11 +768,10 @@ void V4L2Device::eventAvailable()
>  
>  static const std::map<uint32_t, ColorSpace> v4l2ToColorSpace = {
>  	{ V4L2_COLORSPACE_RAW, ColorSpace::Raw },
> -	{ V4L2_COLORSPACE_SRGB, {
> -		ColorSpace::Primaries::Rec709,
> -		ColorSpace::TransferFunction::Srgb,
> -		ColorSpace::YcbcrEncoding::Rec601,
> -		ColorSpace::Range::Limited } },
> +	{ V4L2_COLORSPACE_SRGB,
> +	  { ColorSpace::Primaries::Rec709,
> +	    ColorSpace::TransferFunction::Srgb,
> +	    ColorSpace::YcbcrEncoding::Rec601, ColorSpace::Range::Limited } },
>  	{ V4L2_COLORSPACE_JPEG, ColorSpace::Sycc },
>  	{ V4L2_COLORSPACE_SMPTE170M, ColorSpace::Smpte170m },
>  	{ V4L2_COLORSPACE_REC709, ColorSpace::Rec709 },
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 6eaa8f01..9f2ec479 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -17,11 +17,11 @@
>  #include <linux/media-bus-format.h>
>  #include <linux/v4l2-subdev.h>
>  
> -#include <libcamera/geometry.h>
> -
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>  
> +#include <libcamera/geometry.h>
> +

This is the only change in this patch that I think we should keep.

>  #include "libcamera/internal/formats.h"
>  #include "libcamera/internal/media_device.h"
>  #include "libcamera/internal/media_object.h"
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 76742e18..1e913c88 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -606,13 +606,13 @@ int V4L2VideoDevice::open()
>  	if (caps_.isVideoCapture()) {
>  		notifierType = EventNotifier::Read;
>  		bufferType_ = caps_.isMultiplanar()
> -			    ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
> -			    : V4L2_BUF_TYPE_VIDEO_CAPTURE;
> +				      ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
> +				      : V4L2_BUF_TYPE_VIDEO_CAPTURE;
>  	} else if (caps_.isVideoOutput()) {
>  		notifierType = EventNotifier::Write;
>  		bufferType_ = caps_.isMultiplanar()
> -			    ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
> -			    : V4L2_BUF_TYPE_VIDEO_OUTPUT;
> +				      ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
> +				      : V4L2_BUF_TYPE_VIDEO_OUTPUT;
>  	} else if (caps_.isMetaCapture()) {
>  		notifierType = EventNotifier::Read;
>  		bufferType_ = V4L2_BUF_TYPE_META_CAPTURE;
> @@ -699,14 +699,14 @@ int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type)
>  	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
>  		notifierType = EventNotifier::Write;
>  		bufferType_ = caps_.isMultiplanar()
> -			    ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
> -			    : V4L2_BUF_TYPE_VIDEO_OUTPUT;
> +				      ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
> +				      : V4L2_BUF_TYPE_VIDEO_OUTPUT;
>  		break;
>  	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
>  		notifierType = EventNotifier::Read;
>  		bufferType_ = caps_.isMultiplanar()
> -			    ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
> -			    : V4L2_BUF_TYPE_VIDEO_CAPTURE;
> +				      ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
> +				      : V4L2_BUF_TYPE_VIDEO_CAPTURE;
>  		break;
>  	default:
>  		LOG(V4L2, Error) << "Unsupported buffer type";
> @@ -792,7 +792,7 @@ void V4L2VideoDevice::close()
>  std::string V4L2VideoDevice::logPrefix() const
>  {
>  	return deviceNode() + "[" + std::to_string(fd()) +
> -		(V4L2_TYPE_IS_OUTPUT(bufferType_) ? ":out]" : ":cap]");
> +	       (V4L2_TYPE_IS_OUTPUT(bufferType_) ? ":out]" : ":cap]");
>  }
>  
>  /**
> @@ -1133,7 +1133,7 @@ std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats(uint32_t code)
>  		return {};
>  	}
>  
> -	for (unsigned int index = 0; ; index++) {
> +	for (unsigned int index = 0;; index++) {
>  		struct v4l2_fmtdesc pixelformatEnum = {};
>  		pixelformatEnum.index = index;
>  		pixelformatEnum.type = bufferType_;
> @@ -1472,9 +1472,9 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)
>  			 * account, which is equal to the bytesPerGroup ratio of
>  			 * the planes.
>  			 */
> -			unsigned int stride = format_.planes[0].bpl
> -					    * formatInfo_->planes[i].bytesPerGroup
> -					    / formatInfo_->planes[0].bytesPerGroup;
> +			unsigned int stride =
> +				format_.planes[0].bpl * formatInfo_->planes[i].bytesPerGroup /
> +				formatInfo_->planes[0].bytesPerGroup;
>  
>  			plane.fd = fd;
>  			plane.offset = offset;
> @@ -1827,11 +1827,11 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()
>  	FrameMetadata &metadata = buffer->_d()->metadata();
>  
>  	metadata.status = buf.flags & V4L2_BUF_FLAG_ERROR
> -			? FrameMetadata::FrameError
> -			: FrameMetadata::FrameSuccess;
> +				  ? FrameMetadata::FrameError
> +				  : FrameMetadata::FrameSuccess;
>  	metadata.sequence = buf.sequence;
> -	metadata.timestamp = buf.timestamp.tv_sec * 1000000000ULL
> -			   + buf.timestamp.tv_usec * 1000ULL;
> +	metadata.timestamp =
> +		buf.timestamp.tv_sec * 1000000000ULL + buf.timestamp.tv_usec * 1000ULL;
>  
>  	if (V4L2_TYPE_IS_OUTPUT(buf.type))
>  		return buffer;
> @@ -1875,7 +1875,7 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()
>  		 * API.
>  		 */
>  		unsigned int bytesused = multiPlanar ? planes[0].bytesused
> -				       : buf.bytesused;
> +						     : buf.bytesused;
>  		unsigned int remaining = bytesused;
>  
>  		for (auto [i, plane] : utils::enumerate(buffer->planes())) {
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index a020a2b0..56c557b5 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -179,17 +179,17 @@ void V4L2CameraProxy::setFmtFromConfig(const StreamConfiguration &streamConfig)
>  {
>  	const Size &size = streamConfig.size;
>  
> -	v4l2PixFormat_.width        = size.width;
> -	v4l2PixFormat_.height       = size.height;
> -	v4l2PixFormat_.pixelformat  = V4L2PixelFormat::fromPixelFormat(streamConfig.pixelFormat)[0];
> -	v4l2PixFormat_.field        = V4L2_FIELD_NONE;
> +	v4l2PixFormat_.width = size.width;
> +	v4l2PixFormat_.height = size.height;
> +	v4l2PixFormat_.pixelformat = V4L2PixelFormat::fromPixelFormat(streamConfig.pixelFormat)[0];
> +	v4l2PixFormat_.field = V4L2_FIELD_NONE;
>  	v4l2PixFormat_.bytesperline = streamConfig.stride;
> -	v4l2PixFormat_.sizeimage    = streamConfig.frameSize;
> -	v4l2PixFormat_.colorspace   = V4L2_COLORSPACE_SRGB;
> -	v4l2PixFormat_.priv         = V4L2_PIX_FMT_PRIV_MAGIC;
> -	v4l2PixFormat_.ycbcr_enc    = V4L2_YCBCR_ENC_DEFAULT;
> +	v4l2PixFormat_.sizeimage = streamConfig.frameSize;
> +	v4l2PixFormat_.colorspace = V4L2_COLORSPACE_SRGB;
> +	v4l2PixFormat_.priv = V4L2_PIX_FMT_PRIV_MAGIC;
> +	v4l2PixFormat_.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
>  	v4l2PixFormat_.quantization = V4L2_QUANTIZATION_DEFAULT;
> -	v4l2PixFormat_.xfer_func    = V4L2_XFER_FUNC_DEFAULT;
> +	v4l2PixFormat_.xfer_func = V4L2_XFER_FUNC_DEFAULT;
>  
>  	sizeimage_ = streamConfig.frameSize;
>  }
> @@ -207,11 +207,8 @@ void V4L2CameraProxy::querycap(std::shared_ptr<Camera> camera)
>  		       sizeof(capabilities_.bus_info));
>  	/* \todo Put this in a header/config somewhere. */
>  	capabilities_.version = KERNEL_VERSION(5, 2, 0);
> -	capabilities_.device_caps = V4L2_CAP_VIDEO_CAPTURE
> -				  | V4L2_CAP_STREAMING
> -				  | V4L2_CAP_EXT_PIX_FORMAT;
> -	capabilities_.capabilities = capabilities_.device_caps
> -				   | V4L2_CAP_DEVICE_CAPS;
> +	capabilities_.device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | V4L2_CAP_EXT_PIX_FORMAT;
> +	capabilities_.capabilities = capabilities_.device_caps | V4L2_CAP_DEVICE_CAPS;
>  	memset(capabilities_.reserved, 0, sizeof(capabilities_.reserved));
>  }
>  
> @@ -330,17 +327,17 @@ int V4L2CameraProxy::tryFormat(struct v4l2_format *arg)
>  		return -EINVAL;
>  	}
>  
> -	arg->fmt.pix.width        = config.size.width;
> -	arg->fmt.pix.height       = config.size.height;
> -	arg->fmt.pix.pixelformat  = V4L2PixelFormat::fromPixelFormat(config.pixelFormat)[0];
> -	arg->fmt.pix.field        = V4L2_FIELD_NONE;
> +	arg->fmt.pix.width = config.size.width;
> +	arg->fmt.pix.height = config.size.height;
> +	arg->fmt.pix.pixelformat = V4L2PixelFormat::fromPixelFormat(config.pixelFormat)[0];
> +	arg->fmt.pix.field = V4L2_FIELD_NONE;
>  	arg->fmt.pix.bytesperline = config.stride;
> -	arg->fmt.pix.sizeimage    = config.frameSize;
> -	arg->fmt.pix.colorspace   = V4L2_COLORSPACE_SRGB;
> -	arg->fmt.pix.priv         = V4L2_PIX_FMT_PRIV_MAGIC;
> -	arg->fmt.pix.ycbcr_enc    = V4L2_YCBCR_ENC_DEFAULT;
> +	arg->fmt.pix.sizeimage = config.frameSize;
> +	arg->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
> +	arg->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
> +	arg->fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
>  	arg->fmt.pix.quantization = V4L2_QUANTIZATION_DEFAULT;
> -	arg->fmt.pix.xfer_func    = V4L2_XFER_FUNC_DEFAULT;
> +	arg->fmt.pix.xfer_func = V4L2_XFER_FUNC_DEFAULT;
>  
>  	return 0;
>  }
> diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp
> index ff833f57..a18d6cc9 100644
> --- a/src/v4l2/v4l2_compat.cpp
> +++ b/src/v4l2/v4l2_compat.cpp
> @@ -5,8 +5,6 @@
>   * V4L2 compatibility layer
>   */
>  
> -#include "v4l2_compat_manager.h"
> -
>  #include <assert.h>
>  #include <fcntl.h>
>  #include <stdarg.h>
> @@ -18,17 +16,19 @@
>  
>  #include <libcamera/base/utils.h>
>  
> +#include "v4l2_compat_manager.h"
> +
>  #define LIBCAMERA_PUBLIC __attribute__((visibility("default")))
>  
>  using namespace libcamera;
>  
> -#define extract_va_arg(type, arg, last)	\
> -{					\
> -	va_list ap;			\
> -	va_start(ap, last);		\
> -	arg = va_arg(ap, type);		\
> -	va_end(ap);			\
> -}
> +#define extract_va_arg(type, arg, last) \
> +	{                               \
> +		va_list ap;             \
> +		va_start(ap, last);     \
> +		arg = va_arg(ap, type); \
> +		va_end(ap);             \
> +	}
>  
>  namespace {
>  
> @@ -164,5 +164,4 @@ LIBCAMERA_PUBLIC int ioctl(int fd, unsigned long request, ...)
>  
>  	return V4L2CompatManager::instance()->ioctl(fd, request, arg);
>  }
> -
>  }
> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp
> index f53fb300..54aba540 100644
> --- a/src/v4l2/v4l2_compat_manager.cpp
> +++ b/src/v4l2/v4l2_compat_manager.cpp
> @@ -171,8 +171,8 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod
>  	fops_.close(fd);
>  
>  	int efd = eventfd(0, EFD_SEMAPHORE |
> -			     ((oflag & O_CLOEXEC) ? EFD_CLOEXEC : 0) |
> -			     ((oflag & O_NONBLOCK) ? EFD_NONBLOCK : 0));
> +				     ((oflag & O_CLOEXEC) ? EFD_CLOEXEC : 0) |
> +				     ((oflag & O_NONBLOCK) ? EFD_NONBLOCK : 0));
>  	if (efd < 0)
>  		return efd;
>  

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list