From patchwork Thu Sep 2 04:22:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13597 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7C0C9BDC71 for ; Thu, 2 Sep 2021 04:23:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8E2A169175; Thu, 2 Sep 2021 06:23:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YZICMoc8"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9047560503 for ; Thu, 2 Sep 2021 06:23:23 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2818C532; Thu, 2 Sep 2021 06:23:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630556603; bh=EGsuCz46CfqF9csFzUwa9z0WWFrn+8UXa9jBXTTFsZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YZICMoc8mrNzQSWPbA00PmHymUy6ibz14pN0rVyiYRd7jL+n4YpjhmCCLSSdB5wCX 8qJgGzYWBSaHW4PrB2/0iknPjd8nDYq4Cge8CsqMxple3y3nhlD0MbW5aTGLtRvLGf 99Af1vX/R5KlmmlxtTfdUqE24tWL3LJRzIu1HFcc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Sep 2021 07:22:52 +0300 Message-Id: <20210902042303.2254-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> References: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v1 01/12] libcamera: base: utils: Use size_t for index in utils::enumerate() 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The index generated by utils::enumerate() is an iteration counter, which should thus be positive. Use std::size_t instead of the different_type of the container. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Hirokazu Honda --- include/libcamera/base/utils.h | 4 ++-- test/utils.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 52301254c2eb..2b761436a99f 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -246,7 +246,7 @@ private: public: using difference_type = typename std::iterator_traits::difference_type; - using value_type = std::pair; + using value_type = std::pair; using pointer = value_type *; using reference = value_type &; using iterator_category = std::input_iterator_tag; @@ -275,7 +275,7 @@ public: private: Base current_; - difference_type pos_; + std::size_t pos_; }; template diff --git a/test/utils.cpp b/test/utils.cpp index d7f810e95e7a..d65467b5102c 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -77,8 +77,8 @@ protected: int testEnumerate() { - std::vector integers{ 1, 2, 3, 4, 5 }; - int i = 0; + std::vector integers{ 1, 2, 3, 4, 5 }; + unsigned int i = 0; for (auto [index, value] : utils::enumerate(integers)) { if (index != i || value != i + 1) { @@ -93,12 +93,12 @@ protected: ++i; } - if (integers != std::vector{ 0, 1, 2, 3, 4 }) { + if (integers != std::vector{ 0, 1, 2, 3, 4 }) { cerr << "Failed to modify container in enumerated range loop" << endl; return TestFail; } - Span span{ integers }; + Span span{ integers }; i = 0; for (auto [index, value] : utils::enumerate(span)) { @@ -112,7 +112,7 @@ protected: ++i; } - const int array[] = { 0, 2, 4, 6, 8 }; + const unsigned int array[] = { 0, 2, 4, 6, 8 }; i = 0; for (auto [index, value] : utils::enumerate(array)) { From patchwork Thu Sep 2 04:22:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13598 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 96FE9C3241 for ; Thu, 2 Sep 2021 04:23:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D4AC069178; Thu, 2 Sep 2021 06:23:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="slGFA+kL"; dkim-atps=neutral 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 EE9B369165 for ; Thu, 2 Sep 2021 06:23:23 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 836A01516; Thu, 2 Sep 2021 06:23:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630556603; bh=xlimUmJ5zsZKLiB/zii3QqC3WblIuvqwIrzvJQEqS8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=slGFA+kLNpOyfVRNgFC15eS1fQQcsqnxkOyUjKFduw2I/y5JXK5VkCCjcHz3hzfXk B/lhxUtW6/ApSYrVUUQCeiocRFwxmqYpmV5DoDoiIOXDix9hucoM2sGiglVSUmGEyV 6s0LZ3ABLFCc1J4qCVZvBzwM+hQoZrOnSJ7N9R8I= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Sep 2021 07:22:53 +0300 Message-Id: <20210902042303.2254-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> References: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v1 02/12] libcamera: file_descriptor: Add a function to retrieve the inode 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The inode is useful to check if two file descriptors refer to the same file. Add a function to retrieve it. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/file_descriptor.h | 3 +++ src/libcamera/file_descriptor.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/libcamera/file_descriptor.h b/include/libcamera/file_descriptor.h index d514aac7697b..988f9b7a3d25 100644 --- a/include/libcamera/file_descriptor.h +++ b/include/libcamera/file_descriptor.h @@ -8,6 +8,7 @@ #define __LIBCAMERA_FILE_DESCRIPTOR_H__ #include +#include namespace libcamera { @@ -27,6 +28,8 @@ public: int fd() const { return fd_ ? fd_->fd() : -1; } FileDescriptor dup() const; + ino_t inode() const; + private: class Descriptor { diff --git a/src/libcamera/file_descriptor.cpp b/src/libcamera/file_descriptor.cpp index 9f9ebc81f738..d55e2b100b6d 100644 --- a/src/libcamera/file_descriptor.cpp +++ b/src/libcamera/file_descriptor.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include @@ -221,6 +223,26 @@ FileDescriptor FileDescriptor::dup() const return FileDescriptor(fd()); } +/** + * \brief Retrieve the file descriptor inode + * + * \todo Should this move to the File class ? + * + * \return The file descriptor inode on success, or 0 on error + */ +ino_t FileDescriptor::inode() const +{ + if (!fd_ || fd_->fd() == -1) + return 0; + + struct stat st; + int ret = fstat(fd_->fd(), &st); + if (ret < 0) + return 0; + + return st.st_ino; +} + FileDescriptor::Descriptor::Descriptor(int fd, bool duplicate) { if (!duplicate) { From patchwork Thu Sep 2 04:22:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13599 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1F111C3243 for ; Thu, 2 Sep 2021 04:23:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D12CA69180; Thu, 2 Sep 2021 06:23:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="o1OcaqG1"; dkim-atps=neutral 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 2069869167 for ; Thu, 2 Sep 2021 06:23:25 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A611745E; Thu, 2 Sep 2021 06:23:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630556604; bh=p+5LZdOtA9bp4navCtHQ0fcbILuRsaD5UZbhHGPVtBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o1OcaqG1INo32oE/ffmnbSL9BCfP0393krZ2CYhjaSgzFPYGdj8cVHIgp4rLSDFFT 41UY926VapdAyqcn54RQQA9qtp/b/7pqv0Cq97dWz7jDqmaCrS70k6DtUHB1Dl6ksY hNvMyUUnSWxtR9XDYsESt2mA7bMlWNeGPgyaX1r0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Sep 2021 07:22:56 +0300 Message-Id: <20210902042303.2254-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> References: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v1 05/12] libcamera: framebuffer: Move planes check to constructor 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The FrameBuffer::planes() function checks that planes are correctly initialized with an offset. This can be done at construction time instead, as the planes are constant. The runtime overhead is reduced, and the backtrace generated by the assertion will show where the faulty frame buffer is created instead of where it is used, easing debugging. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Hirokazu Honda --- include/libcamera/framebuffer.h | 9 +-------- src/libcamera/framebuffer.cpp | 3 +++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index d5aeff00387b..fd68ed0a139d 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -51,14 +51,7 @@ public: FrameBuffer(const std::vector &planes, unsigned int cookie = 0); - const std::vector &planes() const - { - /* \todo Remove the assertions after sufficient testing */ - for (const auto &plane : planes_) - assert(plane.offset != Plane::kInvalidOffset); - return planes_; - } - + const std::vector &planes() const { return planes_; } Request *request() const; const FrameMetadata &metadata() const { return metadata_; } diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index c99f5b15e6ff..53ef89bf458f 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -199,6 +199,9 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) : Extensible(std::make_unique()), planes_(planes), cookie_(cookie) { + /* \todo Remove the assertions after sufficient testing */ + for (const auto &plane : planes_) + ASSERT(plane.offset != Plane::kInvalidOffset); } /** From patchwork Thu Sep 2 04:23:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13600 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 32725C324A for ; Thu, 2 Sep 2021 04:23:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 98BA469173; Thu, 2 Sep 2021 06:23:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DWjuTxzx"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AE5F269167 for ; Thu, 2 Sep 2021 06:23:27 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5317D45E; Thu, 2 Sep 2021 06:23:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630556607; bh=lQuIPtySiPaYQ3lohbAWNwQ8tei909kkgfLYGjUF/Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DWjuTxzxXQH5REDGGm0AQ1EYeORXzPKqfzTMwvQ5iF68t6gazwo0NG9MzIyXz+1BH 9kD7uk/tEHn3R5FISCjR1+qbQHI4fmau3249gDYyvN4wUQfGLWfh7aykHB5Jzutlu4 +A/8ojKCIPbqVuA1fz4vhqh1s1C19n64etDgSzT4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Sep 2021 07:23:03 +0300 Message-Id: <20210902042303.2254-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> References: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v1 12/12] libcamera: v4l2_videodevice: Use utils::enumerate() 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace a manual counter with the utils::enumerate() utility function. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Hirokazu Honda --- src/libcamera/v4l2_videodevice.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index b80b9038a914..8a7d847c060e 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1338,13 +1338,12 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) planes.resize(formatInfo_->numPlanes()); const FileDescriptor &fd = planes[0].fd; size_t offset = 0; - for (size_t i = 0; i < planes.size(); ++i) { - planes[i].fd = fd; - planes[i].offset = offset; - + for (auto [i, plane] : utils::enumerate(planes)) { + plane.fd = fd; + plane.offset = offset; /* \todo Take the V4L2 stride into account */ - planes[i].length = formatInfo_->planeSize(format_.size, i); - offset += planes[i].length; + plane.length = formatInfo_->planeSize(format_.size, i); + offset += plane.length; } }