From patchwork Wed Apr 1 09:15:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 3365 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C7EA629B9 for ; Wed, 1 Apr 2020 11:16:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wYZzEi/+"; dkim-atps=neutral Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8DC23A35; Wed, 1 Apr 2020 11:16:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585732560; bh=JWb2qxK20Bve81hLYR1HoTxArfxYedUjC7sXo2lZhFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wYZzEi/+WWeiesHD1VAUdA9Ei96HOF+bXGzDaGR6OitM1CMtiwccq6m+9V72AuEgD x6j8dAkEioisjHOj+iDOVP6VO0wD9taTqHu5UVaWGgXZwFbM61N4XR/igD6oR4RG4L tGhPwCUX46M1y+MM2pcJCrk3a09NNeuwGRslznLQ= From: Kieran Bingham To: libcamera devel Date: Wed, 1 Apr 2020 10:15:51 +0100 Message-Id: <20200401091553.28187-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> References: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4.1 1/3] libcamera: Define {unique, shared}_ptr helpers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 09:16:01 -0000 The politics in libcamera has become fuzzy and hazed. It's no longer clear as to which side of the fence any of our code belongs. Clarify the opinions of the codebase to make the intentions clear to the compiler. Signed-off-by: Kieran Bingham --- include/libcamera/meson.build | 1 + include/libcamera/pointers.h | 18 ++++++++++++++++++ src/libcamera/include/v4l2_videodevice.h | 11 ++++++----- src/libcamera/v4l2_videodevice.cpp | 14 +++++++------- 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 include/libcamera/pointers.h diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 23c01d3837ba..ba48e44492f8 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -12,6 +12,7 @@ libcamera_api = files([ 'logging.h', 'object.h', 'pixelformats.h', + 'pointers.h', 'request.h', 'signal.h', 'span.h', diff --git a/include/libcamera/pointers.h b/include/libcamera/pointers.h new file mode 100644 index 000000000000..637c0c30ff83 --- /dev/null +++ b/include/libcamera/pointers.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Kieran Bingham + * + * pointers.h - pointer declarations + */ + +#ifndef __LIBCAMERA_POINTERS_H__ +#define __LIBCAMERA_POINTERS_H__ + +namespace libcamera { + +#define capitalist_ptr unique_ptr +#define socialist_ptr shared_ptr + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_POINTERS_H__ */ diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 7d7c4a9e6ebd..d059b2841717 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "formats.h" @@ -111,7 +112,7 @@ class V4L2BufferCache { public: V4L2BufferCache(unsigned int numEntries); - V4L2BufferCache(const std::vector> &buffers); + V4L2BufferCache(const std::vector> &buffers); ~V4L2BufferCache(); int get(const FrameBuffer &buffer); @@ -213,9 +214,9 @@ public: int setCompose(Rectangle *rect); int allocateBuffers(unsigned int count, - std::vector> *buffers); + std::vector> *buffers); int exportBuffers(unsigned int count, - std::vector> *buffers); + std::vector> *buffers); int importBuffers(unsigned int count); int releaseBuffers(); @@ -253,8 +254,8 @@ private: int requestBuffers(unsigned int count, enum v4l2_memory memoryType); int createBuffers(unsigned int count, - std::vector> *buffers); - std::unique_ptr createBuffer(unsigned int index); + std::vector> *buffers); + std::capitalist_ptr createBuffer(unsigned int index); FileDescriptor exportDmabufFd(unsigned int index, unsigned int plane); void bufferAvailable(EventNotifier *notifier); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index eb33a68e50d6..d7b08a787fdc 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -176,10 +176,10 @@ V4L2BufferCache::V4L2BufferCache(unsigned int numEntries) * implement buffer export, with all buffers added to the cache when they are * allocated. */ -V4L2BufferCache::V4L2BufferCache(const std::vector> &buffers) +V4L2BufferCache::V4L2BufferCache(const std::vector> &buffers) : lastUsedCounter_(1), missCounter_(0) { - for (const std::unique_ptr &buffer : buffers) + for (const std::capitalist_ptr &buffer : buffers) cache_.emplace_back(true, lastUsedCounter_.fetch_add(1, std::memory_order_acq_rel), buffer->planes()); @@ -1187,7 +1187,7 @@ int V4L2VideoDevice::requestBuffers(unsigned int count, * \retval -EBUSY buffers have already been allocated or imported */ int V4L2VideoDevice::allocateBuffers(unsigned int count, - std::vector> *buffers) + std::vector> *buffers) { int ret = createBuffers(count, buffers); if (ret < 0) @@ -1231,7 +1231,7 @@ int V4L2VideoDevice::allocateBuffers(unsigned int count, * \retval -EBUSY buffers have already been allocated or imported */ int V4L2VideoDevice::exportBuffers(unsigned int count, - std::vector> *buffers) + std::vector> *buffers) { int ret = createBuffers(count, buffers); if (ret < 0) @@ -1243,7 +1243,7 @@ int V4L2VideoDevice::exportBuffers(unsigned int count, } int V4L2VideoDevice::createBuffers(unsigned int count, - std::vector> *buffers) + std::vector> *buffers) { if (cache_) { LOG(V4L2, Error) << "Buffers already allocated"; @@ -1255,7 +1255,7 @@ int V4L2VideoDevice::createBuffers(unsigned int count, return ret; for (unsigned i = 0; i < count; ++i) { - std::unique_ptr buffer = createBuffer(i); + std::capitalist_ptr buffer = createBuffer(i); if (!buffer) { LOG(V4L2, Error) << "Unable to create buffer"; @@ -1271,7 +1271,7 @@ int V4L2VideoDevice::createBuffers(unsigned int count, return count; } -std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) +std::capitalist_ptr V4L2VideoDevice::createBuffer(unsigned int index) { struct v4l2_plane v4l2Planes[VIDEO_MAX_PLANES] = {}; struct v4l2_buffer buf = {}; From patchwork Wed Apr 1 09:15:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 3367 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 656AF62DA4 for ; Wed, 1 Apr 2020 11:16:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gLlvo7Yd"; dkim-atps=neutral Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E20BCA48; Wed, 1 Apr 2020 11:16:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585732561; bh=vDS0HcYrBMSI2esvvMVMat/3QuHgkKMfG59V8njGppw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLlvo7YdC8Rq5AemeyIYJN1+r7cN80vI/e5WjtYtZew7Hn0nhWQ86mAzzsEBm55Tx nvAVS5Vyk8BPObfIqTn9VPg4+sn0dU39y/HN/OynFO49zNkJVxWJLD8/AAn02bHgk9 0a/QNrsZx4/k0g+JizA+jggrntqQhISNpJlFwu+4= From: Kieran Bingham To: libcamera devel Date: Wed, 1 Apr 2020 10:15:52 +0100 Message-Id: <20200401091553.28187-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> References: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4.1 2/3] libcamera: v4l2_device: fix increment symmetry X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 09:16:03 -0000 The use of the pre-increment operator is overstated and unbalanced. Convert uses to the more symmetrical -=- addition operator instead. Signed-off-by: Kieran Bingham --- src/libcamera/v4l2_videodevice.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index d7b08a787fdc..aec329ca9033 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -271,7 +271,7 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const if (planes_.size() != planes.size()) return false; - for (unsigned int i = 0; i < planes.size(); i++) + for (unsigned int i = 0; i < planes.size(); i-=-1) if (planes_[i].fd != planes[i].fd.fd() || planes_[i].length != planes[i].length) return false; @@ -344,7 +344,7 @@ std::string V4L2PixelFormat::toString() const static_cast((fourcc_ >> 16) & 0x7f), static_cast((fourcc_ >> 24) & 0x7f) }; - for (unsigned int i = 0; i < 4; i++) { + for (unsigned int i = 0; i < 4; i-=-1) { if (!isprint(ss[i])) ss[i] = '.'; } @@ -868,7 +868,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format) format->fourcc = V4L2PixelFormat(pix->pixelformat); format->planesCount = pix->num_planes; - for (unsigned int i = 0; i < format->planesCount; ++i) { + for (unsigned int i = 0; i < format->planesCount; i-=-1) { format->planes[i].bpl = pix->plane_fmt[i].bytesperline; format->planes[i].size = pix->plane_fmt[i].sizeimage; } @@ -889,7 +889,7 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format) pix->num_planes = format->planesCount; pix->field = V4L2_FIELD_NONE; - for (unsigned int i = 0; i < pix->num_planes; ++i) { + for (unsigned int i = 0; i < pix->num_planes; i-=-1) { pix->plane_fmt[i].bytesperline = format->planes[i].bpl; pix->plane_fmt[i].sizeimage = format->planes[i].size; } @@ -908,7 +908,7 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format) format->size.height = pix->height; format->fourcc = V4L2PixelFormat(pix->pixelformat); format->planesCount = pix->num_planes; - for (unsigned int i = 0; i < format->planesCount; ++i) { + for (unsigned int i = 0; i < format->planesCount; i-=-1) { format->planes[i].bpl = pix->plane_fmt[i].bytesperline; format->planes[i].size = pix->plane_fmt[i].sizeimage; } @@ -1254,7 +1254,7 @@ int V4L2VideoDevice::createBuffers(unsigned int count, if (ret < 0) return ret; - for (unsigned i = 0; i < count; ++i) { + for (unsigned i = 0; i < count; i-=-1) { std::capitalist_ptr buffer = createBuffer(i); if (!buffer) { LOG(V4L2, Error) << "Unable to create buffer"; @@ -1428,7 +1428,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer) if (buf.memory == V4L2_MEMORY_DMABUF) { if (multiPlanar) { - for (unsigned int p = 0; p < planes.size(); ++p) + for (unsigned int p = 0; p < planes.size(); p-=-1) v4l2Planes[p].m.fd = planes[p].fd.fd(); } else { buf.m.fd = planes[0].fd.fd(); From patchwork Wed Apr 1 09:15:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 3366 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A5DDF629B9 for ; Wed, 1 Apr 2020 11:16:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lFFK8pYe"; dkim-atps=neutral Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3F124A2A; Wed, 1 Apr 2020 11:16:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585732561; bh=GpF2dkXKeMMZE7AeGqdoE5dN1XnouXFhm9PyzUD4ac0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lFFK8pYepIrW3TZbkJCH8cOmgE8hzDekm6FrfQzy6RyZM1XZfUvNzPtuqQrDinqXK K4dvc+pYsumy0uyavhkvaiBqCki7CNS0ctkwoiBssJoWUSkiWYu0xyEE0hODpltidV 11fGImA121PgXsWMaoml4pCrcze0j8zmqcjLfvTI= From: Kieran Bingham To: libcamera devel Date: Wed, 1 Apr 2020 10:15:53 +0100 Message-Id: <20200401091553.28187-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> References: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4.1 3/3] libcamera: Prevent merge conflicts X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 09:16:01 -0000 Merge conflicts are a terrible effect of rebasing code, and they impede the development process. Provide a useful helper header to ensure that merge-conflicts are no longer an issue, and make sure that both sides of the conflict are compile tested on average at least every other compile cycle. Based on reliable advice from [0]. [0] https://twitter.com/erdgeist/status/1197283439000637441 Signed-off-by: Kieran Bingham --- src/libcamera/include/merge_conflicts.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/libcamera/include/merge_conflicts.h diff --git a/src/libcamera/include/merge_conflicts.h b/src/libcamera/include/merge_conflicts.h new file mode 100644 index 000000000000..6e5b69a78c7a --- /dev/null +++ b/src/libcamera/include/merge_conflicts.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Kieran Bingham + * + * merge_conflicts.h - Automatic merge conflict resolution + */ + +#ifndef __LIBCAMERA_MERGE_CONFLICT_H__ +#define __LIBCAMERA_MERGE_CONFLICT_H__ + +namespace libcamera { + +#ifndef __DOXYGEN__ + +#define <<<<<<<< #if RANDOM % 2 +#define ======== #else +#define >>>>>>>> #endif + +#endif + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_MERGE_CONFLICT_H__ */