From patchwork Mon Aug 16 04:31:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13359 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 533EAC3241 for ; Mon, 16 Aug 2021 04:31:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3834368894; Mon, 16 Aug 2021 06:31:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EafXNiny"; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CFF26888A for ; Mon, 16 Aug 2021 06:31:48 +0200 (CEST) Received: by mail-pl1-x62e.google.com with SMTP id a5so19385681plh.5 for ; Sun, 15 Aug 2021 21:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O8KjuN3pQ3H8El8/lL+5eqPsdn/Esip4kifoaHHNeUs=; b=EafXNinylckofYhe9+3Le9A6tfmOfYTlYt/GM8jXO1FiIfcaFUO2/ka/egUutpZo5f o6grWE/p1/oqcZzm/srRIXgacg31fymXVXYvcnCAUp+DF1ESdD3piQo+r9z+bmPC507q CEE1wRL83FIXA4PxleDd8xbiXsk3NZXs87nIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O8KjuN3pQ3H8El8/lL+5eqPsdn/Esip4kifoaHHNeUs=; b=DcggiVtsRnTVD9T4J9dndKt5CWi1jXTU3HgjlS5iyv7UxPlXcjbHnXIhdqH8lVBOoy 7C49+Jo0lhuqlwDhPd0CFSX635MdiPZ8vAIsktZeUY6oxOhPf1kUPCb83LM6YQ5CXjvP Bvj4jIhweb4opBl2lwGyiE1Q29s+DKlBoPIE37bIVeelQmx78TtzIMMluDjACuI22EkM BXzWx9ECNDtIy4JUzKLijpHoiaFM9WYl2r3iRJrDQlNFDWhs4DCS8xpQHL/86xmKovyd r2L/rMnToUZEeOyuzl0zWF9wyzX6Z3zVlZTaV2z8DS46eRa/TUdV4fJeQsfoSnSdChHt 3llA== X-Gm-Message-State: AOAM531LMLlYNDnTdoXCAGv4D7GEiGfADE51kGxylhV41lO3s0OzsUR9 z+oL6J8lbbPnd6FRiSVg4bcVFZc9eSrIMw== X-Google-Smtp-Source: ABdhPJyuwbWJdc4C2F7LKtm4iSIM3OmJ5c9qXmsMeisqTLDe2G577h11p+gKXXp/yr4NQFRNOgeMRg== X-Received: by 2002:a17:90a:4d8e:: with SMTP id m14mr15153782pjh.106.1629088306426; Sun, 15 Aug 2021 21:31:46 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:46 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:29 +0900 Message-Id: <20210816043138.957984-2-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 01/10] libcamera: framebuffer: Add offset to FrameBuffer::Plane 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" This adds offset to FrameBuffer::Plane. It enables represents V4L2 multi-planar format and mapping with MappedFrameBuffer. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/framebuffer.h | 1 + src/libcamera/framebuffer.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index 28307890..5de3c744 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -42,6 +42,7 @@ class FrameBuffer final : public Extensible public: struct Plane { FileDescriptor fd; + unsigned int offset; unsigned int length; }; diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index 42c73134..1d7d5ea3 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -131,7 +131,7 @@ FrameBuffer::Private::Private() * * The static information describes the memory planes that make a frame. The * planes are specified when creating the FrameBuffer and are expressed as a set - * of dmabuf file descriptors and length. + * of dmabuf file descriptors, offset and length. * * The dynamic information is grouped in a FrameMetadata instance. It is updated * during the processing of a queued capture request, and is valid from the @@ -151,8 +151,8 @@ FrameBuffer::Private::Private() * * Planar pixel formats use multiple memory regions to store the different * colour components of a frame. The Plane structure describes such a memory - * region by a dmabuf file descriptor and a length. A FrameBuffer then - * contains one or multiple planes, depending on the pixel format of the + * region by a dmabuf file descriptor, an offset and a length. A FrameBuffer + * then contains one or multiple planes, depending on the pixel format of the * frames it is meant to store. * * To support DMA access, planes are associated with dmabuf objects represented @@ -170,6 +170,11 @@ FrameBuffer::Private::Private() * \brief The dmabuf file descriptor */ +/** + * \var FrameBuffer::Plane::offset + * \brief The plane offset in bytes +*/ + /** * \var FrameBuffer::Plane::length * \brief The plane length in bytes From patchwork Mon Aug 16 04:31:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13360 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 BE8A6BD87D for ; Mon, 16 Aug 2021 04:31:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7D1BD688A3; Mon, 16 Aug 2021 06:31:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="a7COMVNi"; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED090688A5 for ; Mon, 16 Aug 2021 06:31:49 +0200 (CEST) Received: by mail-pl1-x62e.google.com with SMTP id l11so19403618plk.6 for ; Sun, 15 Aug 2021 21:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MvGbJNKDMTcMJvLM1bMSKiW53fH3DOp/ai6lDpTjr3s=; b=a7COMVNiu3/omF99ctQ4E3/aJRIXBe7fSFSggW3kqDz+aqGE6ewYpo9zKzNTM+XTtd kAbmkXucA35qrix9S+OCb3ErVdKSTHMJ83tvD/6JVM7mqwyDboEgucrRospm6okBsLbN bnoc/g04TJ5Jv5na3eAc6XpORmwDajF5wcjmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MvGbJNKDMTcMJvLM1bMSKiW53fH3DOp/ai6lDpTjr3s=; b=iWA92HlrksY92Wiogdrgxxl7YrmleSDRz5hcUy/mTGdW6PkRi/A0AlzH7+NNCK9XBc bfA67zTl4XD3n9Ukzdc0I3i/i7IJCqgOOVySxfmrUp6BZ6RiqDoDwpW1wZ35GMK5isvh bTih+Wfh/OGnn4Qljiw25RIRb75k8W0wShVzMp5XjfNb7XUaSfjUVqIWqDwv7RphpoJe QTVInlZBjpzpXala/cmncE9+MryXUfyZsv8QE5ULQqQOXaUsoXy6OfEbzyh4q7KqlQga qc3maUHeQL9BgSqftilVlmRoT19PJe/RcqXreadBQU0nakbHs7nYLP3t17/8HQqnjL4f ZHfQ== X-Gm-Message-State: AOAM531nQfnIvhwXP1cJ07ykHPB6zEsVHsIg9EJimh5/ON1zfPqaCcha edTgOm/QWM8JwvIYXjmU3YVA7yLbtMZxbw== X-Google-Smtp-Source: ABdhPJxJLFbn7ckW5Ov2fbY0WDqCvXhIPBjXu09y4N+rS/A+RIbbIJp0PjGOuvBY+6JaUQq3VcyV+w== X-Received: by 2002:a17:90a:4211:: with SMTP id o17mr15290439pjg.176.1629088308238; Sun, 15 Aug 2021 21:31:48 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:47 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:30 +0900 Message-Id: <20210816043138.957984-3-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 02/10] libcamera: ipa_data_serializer: Modify (de)serialization for offset 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 offset variable is added to FrameBuffer::Plane. This modifies the serialization and deserialization code for the offset variable. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/libcamera/ipa_data_serializer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libcamera/ipa_data_serializer.cpp b/src/libcamera/ipa_data_serializer.cpp index fb941e6b..144c3248 100644 --- a/src/libcamera/ipa_data_serializer.cpp +++ b/src/libcamera/ipa_data_serializer.cpp @@ -562,6 +562,7 @@ FileDescriptor IPADataSerializer::deserialize(const std::vector< * FrameBuffer::Plane is serialized as: * * 1 byte - FileDescriptor + * 4 bytes - uint32_t Offset * 4 bytes - uint32_t Length */ template<> @@ -580,6 +581,7 @@ IPADataSerializer::serialize(const FrameBuffer::Plane &data, fdsVec.insert(fdsVec.end(), fdFds.begin(), fdFds.end()); appendPOD(dataVec, data.length); + appendPOD(dataVec, data.offset); return { dataVec, fdsVec }; } @@ -596,7 +598,8 @@ IPADataSerializer::deserialize(std::vector::const_i ret.fd = IPADataSerializer::deserialize(dataBegin, dataBegin + 1, fdsBegin, fdsBegin + 1); - ret.length = readPOD(dataBegin, 1, dataEnd); + ret.offset = readPOD(dataBegin, 1, dataBegin + 2); + ret.length = readPOD(dataBegin + 1, 1, dataEnd); return ret; } From patchwork Mon Aug 16 04:31:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13361 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 2A2F7BD87D for ; Mon, 16 Aug 2021 04:31:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DACAF68894; Mon, 16 Aug 2021 06:31:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Q3jnWge3"; dkim-atps=neutral Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC1FB6888A for ; Mon, 16 Aug 2021 06:31:51 +0200 (CEST) Received: by mail-pl1-x62c.google.com with SMTP id u1so2262175plr.1 for ; Sun, 15 Aug 2021 21:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O5yb3VMefRl6XvYP/u28Ygt231KKcloKZj/dkCFdHeM=; b=Q3jnWge34hWXrcZTv9FdKQ3zT5pvohqi8YOu1nSDkYfg3LHAMPDadycpQ3lhJShfiH nNqpVnywrVCVJHLM+CiZXEfIe/oxPEo97vaUnFy5WuJG4rM/3ZePm4tRhVBjy4pHHZdV vYuQLJKF01nMiFrxEKFdXkHb81MCUxrSVVYpQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O5yb3VMefRl6XvYP/u28Ygt231KKcloKZj/dkCFdHeM=; b=VAPVtvVvMB/pxS3fNQM9+TjRjkhrI6U2JKTeL5MXwAW+nQYwdBUC3lAPamLsF91WEp Q7uuR9GGlDGieLnaRZsWEo+RfQk/OFxhiiPeUulVbUfPcHpcg2wImIjLLY0h6OURSe0e k3aF/13USCID+CKIMXlgkOWm6YMEPP/24Uh7XtJXKjP+1cXy9nhWeYw5WfWnfyauG2RD zezoJ1a0NYSzTIsNQ+M7i7otJ/efurPk9jBdBVWGys0vAQBiIZYN+VogiDV+7brkXx3p f3vx+UzKSYEnN+o52AZPwus7lTFCDVKCLxXxZnxZX1g62kHji7xtzewXVmOQ3cPegMGW nSIg== X-Gm-Message-State: AOAM533sJgclmgBg2hbsfs5gt5CyK1CEMrFEU0mctAEtiY0PDki1sv5e 85w5YtjD/abPspiwHi5KmlMqTwrUx2TxUQ== X-Google-Smtp-Source: ABdhPJy+hTXvL1xXiTTu/xJzzSlB0keO65Ak7wnV1SHrz6UdXpordEfYIbCKcp/6CNLnJg5bC0nnlA== X-Received: by 2002:a17:90a:940e:: with SMTP id r14mr15078550pjo.41.1629088310035; Sun, 15 Aug 2021 21:31:50 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:49 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:31 +0900 Message-Id: <20210816043138.957984-4-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 03/10] libcamera: mapped_framebuffer: Return plane begin address by MappedBuffer::maps() 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" MappedBuffer::maps() returns std::vector. Plane has the address, but the address points the beginning of the buffer containing the plane. This makes the Plane point the beginning of the plane. So MappedBuffer::maps()[i].data() returns the address of i-th plane. Signed-off-by: Hirokazu Honda --- .../libcamera/internal/mapped_framebuffer.h | 4 +- src/libcamera/mapped_framebuffer.cpp | 51 +++++++++++++++---- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h index 3401a9fc..42479541 100644 --- a/include/libcamera/internal/mapped_framebuffer.h +++ b/include/libcamera/internal/mapped_framebuffer.h @@ -30,12 +30,14 @@ public: bool isValid() const { return error_ == 0; } int error() const { return error_; } - const std::vector &maps() const { return maps_; } + /* \todo rename to planes(). */ + const std::vector &maps() const { return planes_; } protected: MappedBuffer(); int error_; + std::vector planes_; std::vector maps_; private: diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp index 2ebe9fdb..b0ba89b0 100644 --- a/src/libcamera/mapped_framebuffer.cpp +++ b/src/libcamera/mapped_framebuffer.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -79,6 +80,7 @@ MappedBuffer::MappedBuffer(MappedBuffer &&other) MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other) { error_ = other.error_; + planes_ = std::move(other.planes_); maps_ = std::move(other.maps_); other.error_ = -ENOENT; @@ -127,10 +129,18 @@ MappedBuffer::~MappedBuffer() */ /** - * \var MappedBuffer::maps_ + * \var MappedBuffer::planes_ * \brief Stores the internal mapped planes * * MappedBuffer derived classes shall store the mappings they create in this + * vector which points the beginning of mapped plane addresses. + */ + +/** + * \var MappedBuffer::maps_ + * \brief Stores the mapped buffer + * + * MappedBuffer derived classes shall store the mappings they create in this * vector which is parsed during destruct to unmap any memory mappings which * completed successfully. */ @@ -167,7 +177,8 @@ MappedBuffer::~MappedBuffer() */ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) { - maps_.reserve(buffer->planes().size()); + ASSERT(!buffer->planes().empty()); + planes_.reserve(buffer->planes().size()); int mmapFlags = 0; @@ -177,18 +188,38 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags) if (flags & MapFlag::Write) mmapFlags |= PROT_WRITE; + int prevFd = -1; for (const FrameBuffer::Plane &plane : buffer->planes()) { - void *address = mmap(nullptr, plane.length, mmapFlags, - MAP_SHARED, plane.fd.fd(), 0); - if (address == MAP_FAILED) { - error_ = -errno; - LOG(Buffer, Error) << "Failed to mmap plane: " - << strerror(-error_); - break; + const int fd = plane.fd.fd(); + if (prevFd != fd) { + const size_t length = lseek(fd, 0, SEEK_END); + void *address = mmap(nullptr, length, mmapFlags, + MAP_SHARED, fd, 0); + if (address == MAP_FAILED) { + error_ = -errno; + LOG(Buffer, Error) << "Failed to mmap plane: " + << strerror(-error_); + return; + } + maps_.emplace_back(static_cast(address), + length); + prevFd = fd; } - maps_.emplace_back(static_cast(address), plane.length); + const size_t length = maps_.back().size(); + if (plane.offset + plane.length > length) { + LOG(Buffer, Fatal) << "plane is out of buffer: " + << "buffer length=" << length + << ", plane offset=" << plane.offset + << ", plane length=" << plane.length; + return; + } + + uint8_t *buf = maps_.back().data(); + planes_.emplace_back(buf + plane.offset, plane.length); } + + ASSERT(maps_.size() == 1u); } } /* namespace libcamera */ From patchwork Mon Aug 16 04:31:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13362 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 82D29BD87D for ; Mon, 16 Aug 2021 04:31:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4B838688C4; Mon, 16 Aug 2021 06:31:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="kFho54l7"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 74AC56888C for ; Mon, 16 Aug 2021 06:31:53 +0200 (CEST) Received: by mail-pl1-x629.google.com with SMTP id q2so19363503plr.11 for ; Sun, 15 Aug 2021 21:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=73f5QDjSVO9zhfCjdBruDhBrJUzuMAxKbVfRDfFAGRI=; b=kFho54l72yWrhKew1OD+0Z+4mRuQLh8R2xWj1e/yTH4AxvzYMKp0Wtete7ZgRNT7QI CMBV/XDux2r0KnofVii3NV1uqJGSbpgYNOfqyARaL0vgRgiXlbGevrZE4s/8Q0t0qx4h UykzEY2jf3gl+KLuY3UBfqYy2ZKVRtBy38mVk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=73f5QDjSVO9zhfCjdBruDhBrJUzuMAxKbVfRDfFAGRI=; b=mCPOPpxEDl2IsIdNdZGROUMTOZG6EaXcjt+fEmx1h1GrAwVzo+7yEAcctyy8R/1JDT U5oQZWm6T9FboJNSKGnsPeUbgj3FtuaaiPBZYJgfB+yycOWFJieOiKM2VInknqSuQh+A hkk7mka0+1sM3kZ7AqIT8Bi2W7qi+0ntgOGeZgD5J4AK+GW3iTiWNQdPEjfX7wg3ewQe +scvkPJ994Hpnl1BnEeH2l2KX1/UyFB1gFbXw8BgUKS5U0S8uJpoYt3EmH60JjAqb8Jc xAi3GcK1h+1TA6P575HST0zXOQIKrUTc6nvFtvHBgH0LEvgy4GpiM5Sh3PEk1UX2b/hR FJPg== X-Gm-Message-State: AOAM532NbYQaxQ9B5TOHSPx+fS0iRtxThTZv1x9ZGevZ+NtzCDzO0NAQ 1MtBNti2dGa5rwjVLY3QhxdHcap//dxlXw== X-Google-Smtp-Source: ABdhPJwdDf18lvQ/3rVXL44IRX8OsSbO8Zq5bEzGFqjLDr6Thp+s0LVoMbzEy8XL4ZVKSlT0p7Z7qQ== X-Received: by 2002:a65:5a0d:: with SMTP id y13mr14047046pgs.22.1629088311783; Sun, 15 Aug 2021 21:31:51 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:51 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:32 +0900 Message-Id: <20210816043138.957984-5-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 04/10] cam: file_sink: Use offset in mapping FrameBuffer 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" This fixes the way of mapping FrameBuffer in FrameSink by using offset. Signed-off-by: Hirokazu Honda --- src/cam/file_sink.cpp | 5 ++++- src/cam/file_sink.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp index 2d30694a..92b2d53d 100644 --- a/src/cam/file_sink.cpp +++ b/src/cam/file_sink.cpp @@ -51,12 +51,15 @@ int FileSink::configure(const libcamera::CameraConfiguration &config) void FileSink::mapBuffer(FrameBuffer *buffer) { + /* \todo use MappedFrameBuffer. */ for (const FrameBuffer::Plane &plane : buffer->planes()) { void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED, plane.fd.fd(), 0); mappedBuffers_[plane.fd.fd()] = std::make_pair(memory, plane.length); + planeData_[plane.fd.fd()] = + static_cast(memory) + plane.offset; } } @@ -102,7 +105,7 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer) const FrameBuffer::Plane &plane = buffer->planes()[i]; const FrameMetadata::Plane &meta = buffer->metadata().planes[i]; - void *data = mappedBuffers_[plane.fd.fd()].first; + void *data = planeData_[plane.fd.fd()]; unsigned int length = std::min(meta.bytesused, plane.length); if (meta.bytesused > plane.length) diff --git a/src/cam/file_sink.h b/src/cam/file_sink.h index c3eb230a..d236d6d8 100644 --- a/src/cam/file_sink.h +++ b/src/cam/file_sink.h @@ -33,6 +33,7 @@ private: std::map streamNames_; std::string pattern_; std::map> mappedBuffers_; + std::map planeData_; }; #endif /* __CAM_FILE_SINK_H__ */ From patchwork Mon Aug 16 04:31:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13363 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 0865EC3241 for ; Mon, 16 Aug 2021 04:31:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BE2806888C; Mon, 16 Aug 2021 06:31:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Me7+xVkU"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 26C5F6888C for ; Mon, 16 Aug 2021 06:31:55 +0200 (CEST) Received: by mail-pj1-x1034.google.com with SMTP id j12-20020a17090aeb0c00b00179530520b3so9957438pjz.0 for ; Sun, 15 Aug 2021 21:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fE1vSWJEgZ6nlMPNgdHPWSi5Hp9OUVVHMgM8F+zZWPs=; b=Me7+xVkUe3b9qvmByrsnzJQPy6N0Bb/v9GMATEEGumulMclHhKBKicxdrgwLG0ULJG uEOdYmNXWcFjoTS9k+4vpZVfHsFZa6NyAoUgcXAxxgJ+IMMAVGoUkVs6LBIuUoElu+tn 6QKt9AUmIAJoQHX6yq9+CmGZH9Ss/QDfNRsWQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fE1vSWJEgZ6nlMPNgdHPWSi5Hp9OUVVHMgM8F+zZWPs=; b=GsadBhlB1GoIXfQRJkVnxygnknzOrH8luSjmTFS2/Fu3xHz9T9I53Imfu29SWSEXTH LL9ZnQkPBpDrdPqpADCmg26S/VGd1/IC41ICr00NdNT7gPfs20dZ9rF0ZBIvbRMYz3Hc ADqwGI3jVtYltmF0LEhdV0qoRDmzVIAOoyRAzhhYIf3yhzDz3DytyPuX9NBLXlqXCjff VhG7Lw3hrJGeoXV1lD1HvRxoBTBW297GtTNC3HuX5uaxGFy0iE1lIAcVH0pc235kpp+i My/+CzzbA0m8PftEFo5neViUGSqelcOLJ9vDsL1YECpg/e94+++RIGCA7yeFaOYMaFm2 zGIg== X-Gm-Message-State: AOAM532QcVTGDcOY7o5BB97dhXMbbxvTtVA56gGLOv/YGDyLbmw24uB/ fe4sFINmPkzzDpgMPtYjEw/V3oIUbwnYSw== X-Google-Smtp-Source: ABdhPJwmSW3Sq62mC1RogThotuMh4eQD/A7KPegPA+QR/5XQxNlJgBAETkyaZch6MRN3oqYRjtVNjQ== X-Received: by 2002:a17:90a:f10:: with SMTP id 16mr14955777pjy.80.1629088313532; Sun, 15 Aug 2021 21:31:53 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:53 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:33 +0900 Message-Id: <20210816043138.957984-6-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 05/10] ipa: rkisp1: Use offset in mapping IPABuffer 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" IPABuffer is represented by FrameBuffer. FrameBuffer::Plane has now an offset. This uses the offset variable to map the IPABuffer. Signed-off-by: Hirokazu Honda --- src/ipa/rkisp1/rkisp1.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 06fb9640..eb7a2705 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -165,7 +165,7 @@ void IPARkISP1::mapBuffers(const std::vector &buffers) * to applications). */ buffersMemory_[buffer.id] = mmap(NULL, - fb.planes()[0].length, + fb.planes()[0].offset + fb.planes()[0].length, PROT_READ | PROT_WRITE, MAP_SHARED, fb.planes()[0].fd.fd(), @@ -186,7 +186,7 @@ void IPARkISP1::unmapBuffers(const std::vector &ids) if (fb == buffers_.end()) continue; - munmap(buffersMemory_[id], fb->second.planes()[0].length); + munmap(buffersMemory_[id], fb->second.planes()[0].offset + fb->second.planes()[0].length); buffersMemory_.erase(id); buffers_.erase(id); } From patchwork Mon Aug 16 04:31:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13364 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 1309FBD87D for ; Mon, 16 Aug 2021 04:31:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C10F9688A2; Mon, 16 Aug 2021 06:31:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="kTaa8Zct"; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE37A688E4 for ; Mon, 16 Aug 2021 06:31:56 +0200 (CEST) Received: by mail-pj1-x1029.google.com with SMTP id cp15-20020a17090afb8fb029017891959dcbso30406266pjb.2 for ; Sun, 15 Aug 2021 21:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pu6I4Bte51NOKNhfGBLmMoWxaLd3FC64fN/DTIH0QsA=; b=kTaa8ZctmPKR/W9VWIgHqvSDzOpALbYFkTgGGcMv39etthYUAHsHpjA1fpMj07NHt0 1GA04kOyJv29IamgSz3X2ab9oa0YmzW3U12lV6mdQm8cQqQH60rUARbLsJs03n+RLPaJ jyT+t4/9CtrhENkNoF7oSUwpzUxJpqnk8FqCc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pu6I4Bte51NOKNhfGBLmMoWxaLd3FC64fN/DTIH0QsA=; b=UQCMtNr05jIvwXESJRvHEbrnGqcWuAWxwCsJ7awSIgIZpkQBsNkbFif291FbaP3dg0 GItd7X1ozVttICDO2008gkK6aM5fpZHd4Bwg8t1JwzBQZBHDBD0L+0Lxd8E2LSV/y2ZR ZQ9KBQzBRAsv6dT6zDzcSzFPERkfmX9ri4+iiqIwmXe9NHjhoG47is8PTHEH9uAOaTnI 6aIVtV3RzHCg9r5c5cvuQKdx1b2UTzkIk7stWw9bT88+Cz9nDjbwvt7ma97B/Adq3twp yb7nl1hMD/G2HRMXa/IQSHMfaGOjSeoIWm/zaKvPX0QDlDjUhPnJxi9QRis7jcb6uMJR RaBQ== X-Gm-Message-State: AOAM5317DYOg3vuF7XxyCGN0ZTSL5vywjGnyarc0oJN9lB61cAVAYooJ YK/mt0Pmvm+m2S1t7WctZrYkiKz1SF/e9Q== X-Google-Smtp-Source: ABdhPJz2C1OXnaPOqwCP9lJ9my4yYnhkAZxHIdtFeIWkoKHIbfePJC5r4FZzWU8FBSj4JIuuNDvQ3g== X-Received: by 2002:a63:e74b:: with SMTP id j11mr5175990pgk.322.1629088315251; Sun, 15 Aug 2021 21:31:55 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:54 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:34 +0900 Message-Id: <20210816043138.957984-7-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 06/10] qcam: main_window: Use offset mapping FrameBuffer 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" FrameBuffer::Plane has offset info now. This uses the offset in mapping FrameBuffer in MainWindow. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/qcam/main_window.cpp | 15 ++++++++++----- src/qcam/main_window.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 39d034de..f815d281 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -472,9 +473,11 @@ int MainWindow::startCapture() for (const std::unique_ptr &buffer : allocator_->buffers(stream)) { /* Map memory buffers and cache the mappings. */ const FrameBuffer::Plane &plane = buffer->planes().front(); - void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED, + size_t length = lseek(plane.fd.fd(), 0, SEEK_END); + void *memory = mmap(NULL, length, PROT_READ, MAP_SHARED, plane.fd.fd(), 0); - mappedBuffers_[buffer.get()] = { memory, plane.length }; + mappedBuffers_[buffer.get()] = { memory, length }; + planeData_[buffer.get()] = { static_cast(memory) + plane.offset, plane.length }; /* Store buffers on the free list. */ freeBuffers_[stream].enqueue(buffer.get()); @@ -541,6 +544,7 @@ error: munmap(buffer.memory, buffer.size); } mappedBuffers_.clear(); + planeData_.clear(); freeBuffers_.clear(); @@ -577,6 +581,7 @@ void MainWindow::stopCapture() munmap(buffer.memory, buffer.size); } mappedBuffers_.clear(); + planeData_.clear(); requests_.clear(); freeQueue_.clear(); @@ -673,10 +678,10 @@ void MainWindow::processRaw(FrameBuffer *buffer, "DNG Files (*.dng)"); if (!filename.isEmpty()) { - const MappedBuffer &mapped = mappedBuffers_[buffer]; + void *memory = planeData_[buffer].memory; DNGWriter::write(filename.toStdString().c_str(), camera_.get(), rawStream_->configuration(), metadata, buffer, - mapped.memory); + memory); } #endif @@ -753,7 +758,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer) << "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps; /* Render the frame on the viewfinder. */ - viewfinder_->render(buffer, &mappedBuffers_[buffer]); + viewfinder_->render(buffer, &planeData_[buffer]); } void MainWindow::queueRequest(FrameBuffer *buffer) diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 85d56ce4..d7ea994c 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -107,6 +107,7 @@ private: std::unique_ptr config_; std::map mappedBuffers_; + std::map planeData_; /* Capture state, buffers queue and statistics */ bool isCapturing_; From patchwork Mon Aug 16 04:31:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13365 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 84987BD87D for ; Mon, 16 Aug 2021 04:32:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1F797688C4; Mon, 16 Aug 2021 06:32:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="YgTTNAX1"; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C06168892 for ; Mon, 16 Aug 2021 06:31:58 +0200 (CEST) Received: by mail-pj1-x1030.google.com with SMTP id w14so24477433pjh.5 for ; Sun, 15 Aug 2021 21:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a4AJqyB/WfqVzb/ZaK2PhCQNUXRUhr1JGmbh6yQPpkY=; b=YgTTNAX1hxb+UReWQCifyV6Cekq7CDqtLKOWb23M+mLTtshi3OWz0IFZTvDQiEieHg AqhzAO56FRlgzLL/h6awhF3uv987cWgjwxmXip9EWPLBq154AtaCtjbjN+JoAiWo07N4 zVZiBikDgoQXSSxkqEw/pnIfh/rdEvPrxzTVA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a4AJqyB/WfqVzb/ZaK2PhCQNUXRUhr1JGmbh6yQPpkY=; b=k6DTYwPCEGe2BYTjbDW9B3+0qCCjyi/DUzit0ivwbFRbS8w/RryXXAQwJSDZ76OE/8 XPQrIGxlzcvcFKIlcRSV5udH/fQW/93tYuXgWo7o4/OLDKTuLBdVYDhjh1zAua/a2CQ/ 5+FrVyr62v/Z3GVl120uma6G9uGTkI/+7MShHxvOVp9+YdoN2OhBP/EuH5KzClfj75pO sAtY60/visFWFExSgC9I2KnJVKDsq1M2Kk8ncy1HTphX7htk7+UD/71zfaQCcPAXmLBJ nCDY3BPU6oWziBCv2fuqjWUDMFhmxi42f0yL4yofRP70svW0t0M3amIyu3afLpSpV84V 2AHw== X-Gm-Message-State: AOAM5322F6ld1eOwuJXqRoxLyFw0hZkd8+DUNUiC4ZJgf45aYt5AOxJC MbqP1q3NvMCZXeawtc6DLOg8dWp/v688Nw== X-Google-Smtp-Source: ABdhPJxCGlbH44hu3nJ47ivynPtb4RAv0t4KQ3gu9835Wn0u4egRMAl2SsR1orPmoL7ggOR/rOSd5g== X-Received: by 2002:a65:608f:: with SMTP id t15mr14128132pgu.452.1629088316973; Sun, 15 Aug 2021 21:31:56 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:56 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:35 +0900 Message-Id: <20210816043138.957984-8-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 07/10] gstreamer: gstlibcameraallocator: Use offset in creating a buffer 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 plane length is the length of the plane size. The buffer length to be allocated for a plane is the offset and the length of FrameBuffer::Plane. Signed-off-by: Hirokazu Honda --- src/gstreamer/gstlibcameraallocator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp index 7bd8ba2d..a3ffec5b 100644 --- a/src/gstreamer/gstlibcameraallocator.cpp +++ b/src/gstreamer/gstlibcameraallocator.cpp @@ -52,7 +52,8 @@ FrameWrap::FrameWrap(GstAllocator *allocator, FrameBuffer *buffer, outstandingPlanes_(0) { for (const FrameBuffer::Plane &plane : buffer->planes()) { - GstMemory *mem = gst_fd_allocator_alloc(allocator, plane.fd.fd(), plane.length, + GstMemory *mem = gst_fd_allocator_alloc(allocator, plane.fd.fd(), + plane.offset + plane.length, GST_FD_MEMORY_FLAG_DONT_CLOSE); gst_mini_object_set_qdata(GST_MINI_OBJECT(mem), getQuark(), this, nullptr); GST_MINI_OBJECT(mem)->dispose = gst_libcamera_allocator_release; From patchwork Mon Aug 16 04:31:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13366 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 1270AC3241 for ; Mon, 16 Aug 2021 04:32:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CFC13688A2; Mon, 16 Aug 2021 06:32:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ai1Ghl5X"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6DA5D6888A for ; Mon, 16 Aug 2021 06:32:00 +0200 (CEST) Received: by mail-pj1-x102d.google.com with SMTP id u21-20020a17090a8915b02901782c36f543so30382725pjn.4 for ; Sun, 15 Aug 2021 21:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FsWpdqKw6TMEtZZ057bMVlcaK+oi5l0g77pu+9nPVwU=; b=Ai1Ghl5XvjCssy3QWXHJOeWM06Eas8kttZenRR+pYIoEjr9JRfsZbB7IM0OzNcRCMz xpg94cTxkyaFWUqthxVR9w6q9UB19LKRGstFZdKFGDrPAG9DlU6ghGDVSjaIbMdK3cM6 PeNOIsaMPjn3FIL9wwkCqF7dIRDYBK8rLeYRQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FsWpdqKw6TMEtZZ057bMVlcaK+oi5l0g77pu+9nPVwU=; b=cNDVOByA/utEBEhXUUQf9NeKs05m/+lskFQyxLbBqbu1t50LLDCjrzWFGEp973hlNy DUwxA0XknN50y29tNMSTL4dQNajemWwKTSIpEU3GTAEc+SMRCwJBltwThAyO8y4Z7oHi 0rK1U499wsxS0GHtSqTTcTMNZFx6rc+lqi42k9XuGfOH0SpnT4q2QIDpmdGHmvCyI+qs 9S3vtxND7hC1nd8Ku6szIXqOEbGOeSmUckQ5F5BwIipiWHRgGgqDEbxsvR7pAkX+dxee V54l3ISgRMmGeiA6ov73JQv5rvJVZNHTENtDvaxk2V+Kgt+KaUDC2qVmllnl7PzSXFPS kZuw== X-Gm-Message-State: AOAM53099oIOgri0HGEShJPAVwELFjaS9If9skW/Xr65LgmROnFa/w6l 9KxQP+RmLd0FhsGU7ypFaIuSoPLb0gx3fQ== X-Google-Smtp-Source: ABdhPJx1c/GOOfJm7hI5owshTMQpqTBNXpoTZ49tcfzYTJBURoM8VRt9fb+FpTIr+wzYv+800wJ9eg== X-Received: by 2002:a17:902:b095:b029:12c:de88:7d3b with SMTP id p21-20020a170902b095b029012cde887d3bmr11629356plr.15.1629088318684; Sun, 15 Aug 2021 21:31:58 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:31:58 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:36 +0900 Message-Id: <20210816043138.957984-9-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 08/10] libcamera: v4l2_videodevice: Create color-format planes in CreateBuffer() 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" V4L2VideDevice::CreateBuffer() creates the same number of FrameBuffer::Planes as V4L2 format planes. Therefore, if the v4l2 format single is single-planar format, the created number of FrameBuffer::Planes is 1. It should rather create the same number of FrameBuffer::Planes as the color format planes. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/v4l2_videodevice.h | 4 ++- src/libcamera/v4l2_videodevice.cpp | 28 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index e767ec84..d0aeb614 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -136,11 +136,13 @@ private: private: struct Plane { Plane(const FrameBuffer::Plane &plane) - : fd(plane.fd.fd()), length(plane.length) + : fd(plane.fd.fd()), offset(plane.offset), + length(plane.length) { } int fd; + unsigned int offset; unsigned int length; }; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index ce60dff6..549418c8 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -25,6 +25,7 @@ #include +#include "libcamera/internal/formats.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/media_object.h" @@ -273,6 +274,7 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const for (unsigned int i = 0; i < planes.size(); i++) if (planes_[i].fd != planes[i].fd.fd() || + planes_[i].offset != planes_[i].offset || planes_[i].length != planes[i].length) return false; return true; @@ -1283,12 +1285,34 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) FrameBuffer::Plane plane; plane.fd = std::move(fd); - plane.length = multiPlanar ? - buf.m.planes[nplane].length : buf.length; + plane.offset = multiPlanar ? buf.m.planes[nplane].data_offset : 0; + plane.length = multiPlanar ? buf.m.planes[nplane].length : buf.length; planes.push_back(std::move(plane)); } + V4L2DeviceFormat format{}; + ret = getFormat(&format); + if (ret < 0) { + LOG(V4L2, Error) + << "Failed to get format: " << strerror(-ret); + return nullptr; + } + + const auto &info = PixelFormatInfo::info(format.fourcc); + if (info.isValid() && info.numPlanes() != numPlanes) { + ASSERT(numPlanes == 1u); + planes.resize(info.numPlanes()); + const FileDescriptor &fd = planes[0].fd; + size_t offset = 0; + for (size_t i = 0; i < info.numPlanes(); ++i) { + planes[i].fd = fd; + planes[i].offset = offset; + planes[i].length = info.frameSize(format.size); + offset += planes[i].length; + } + } + return std::make_unique(std::move(planes)); } From patchwork Mon Aug 16 04:31:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13367 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 D768DC3242 for ; Mon, 16 Aug 2021 04:32:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 40C16688AC; Mon, 16 Aug 2021 06:32:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HwligxSW"; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 091626888C for ; Mon, 16 Aug 2021 06:32:02 +0200 (CEST) Received: by mail-pl1-x62e.google.com with SMTP id e19so19380696pla.10 for ; Sun, 15 Aug 2021 21:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k7D8nd4mpOzgm8wgTT5iNwJlHKvqDfF85/MjYwtrNUU=; b=HwligxSWkJIAd28VBQvWZj3L1h3GvJDmRrehJHaGTooWWZvwPysO3/CNkQ7DcCZhlK BYGvxrvDtYetZKnx2mTwGIXUdPMOxOcIogiCkYJtcyskD0CnME7QR9y9Wb3TtksKJL/5 +lZXUdqnlhPnlzqCaDmAwCG3o0nyC8AB46XoQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k7D8nd4mpOzgm8wgTT5iNwJlHKvqDfF85/MjYwtrNUU=; b=iRS51KWBuOFusFUOCtaMWFFk9Hy7ptSNy7+UcVMLSSfv3NEpxFmNQLEo0QJlV+ebq4 khTNTFGeqNMl1N8FvEWGnKQQwyY4o2gx/JAG4i6w7hoYZYn//XStDMPXUdvM4DurYLoP nIc74UUiytDiREPBqIYXEU6bbVID8pwBlir7UQQ20XC3+bP8l9OmlTQ3JjPK+c2H0HZl GWvUG3EzbWhrjSppTg/+ikVW3SBWecHZg+eoY/Q8VP6jqZhOwB5ffG4kTsKH4kii75s4 v4tO4qNXmGFkatK8NTVnIUctdkMBV5jnQ8io6L0MgTwV86whDQTYrmOjLce/O8w2Wluq Qp5w== X-Gm-Message-State: AOAM533rW19a4DYwcXfWl+IdhB97KZyvvsmU2xJcMrLu7gCDwC39Z4fm yHZOhWLEvRUTy/4QVJbpu96cAOkAMnRA8A== X-Google-Smtp-Source: ABdhPJxEcr1S2Co9CSoFFvGgycT5moyngyr1H2O0cAY98XcmAzSCkhq3SqLY9HsIlAwrfQ57kU8f+g== X-Received: by 2002:a17:90a:9b0b:: with SMTP id f11mr15062593pjp.120.1629088320411; Sun, 15 Aug 2021 21:32:00 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:32:00 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:37 +0900 Message-Id: <20210816043138.957984-10-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 09/10] android: camera_device: Fill offset and right length in CreateFrameBuffer() 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" CameraDevice::CreateFrameBuffer() fills the length of the buffer to each FrameBuffer::Plane::length. It should rather be the length of plane. This also changes CreateFrameBuffer() to fill offset of FrameBuffer::Plane. Signed-off-by: Hirokazu Honda --- src/android/camera_device.cpp | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a69b687a..1ded5cb1 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -746,29 +747,30 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) { - std::vector planes; + FileDescriptor fd; + /* This assumes all the planes are in the same buffer. */ for (int i = 0; i < camera3buffer->numFds; i++) { - /* Skip unused planes. */ - if (camera3buffer->data[i] == -1) + if (camera3buffer->data[i] != -1) { + fd = FileDescriptor(camera3buffer->data[i]); break; - - FrameBuffer::Plane plane; - plane.fd = FileDescriptor(camera3buffer->data[i]); - if (!plane.fd.isValid()) { - LOG(HAL, Error) << "Failed to obtain FileDescriptor (" - << camera3buffer->data[i] << ") " - << " on plane " << i; - return nullptr; } + } + if (!fd.isValid()) { + LOG(HAL, Fatal) << "No valid fd"; + return nullptr; + } - off_t length = lseek(plane.fd.fd(), 0, SEEK_END); - if (length == -1) { - LOG(HAL, Error) << "Failed to query plane length"; - return nullptr; - } + CameraBuffer buf(camera3buffer, PROT_READ); + if (!buf.isValid()) { + LOG(HAL, Fatal) << "Failed mapping buffer"; + return nullptr; + } - plane.length = length; - planes.push_back(std::move(plane)); + std::vector planes(buf.numPlanes()); + for (size_t i = 0; i < buf.numPlanes(); ++i) { + planes[i].fd = fd; + planes[i].offset = buf.plane(i).data() - buf.plane(0).data(); + planes[i].length = buf.plane(i).size(); } return new FrameBuffer(std::move(planes)); From patchwork Mon Aug 16 04:31:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13368 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 14AEDBD87D for ; Mon, 16 Aug 2021 04:32:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BA984688A2; Mon, 16 Aug 2021 06:32:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="n+En1NwB"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BBCCD68894 for ; Mon, 16 Aug 2021 06:32:03 +0200 (CEST) Received: by mail-pj1-x102d.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so30424397pjr.1 for ; Sun, 15 Aug 2021 21:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T0dHkJ+PNUMoZsj2N4CcOXDLrqClbhhh/k1FY/GiBJ4=; b=n+En1NwBdcH4TcPaMwrSbLNjbPZ7eHu5aquTG1xyL87Alq2AyAfq6VIKenL2dRFAQi fujSyt1idViZxifcccws3ejuPsn2x8NiGOTiSjgsg7FWVfyQt10kwHyPXLFuKOI+MZn8 6DLyqH6WK1qyinAXMxm6v0s1y/cp0XizzKuGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T0dHkJ+PNUMoZsj2N4CcOXDLrqClbhhh/k1FY/GiBJ4=; b=tic79EACsHlOI7QsD4WX6LzWU5e7eAWs3a/gmFr/tJavZ9cOF9g3Py1QEvQLUQmZmQ oC/s+jbMiY/C1ocPQxC72u1E3bFpKq0adlE7fNUbK587+5m2y9wguPKZo3cjN6Lgeq+w YuXa9tFmslT8V4nvc+HONmU8BlrbSkbSrQBLFxfj/DOAPGwHhb8zYkuFVyPp5xl0a2kn 8TchJdFkrjyztQP8YX2+DUz45LxVkcR6++q/h3ZQII054s5xdeaaOU4CxWLnseUzb2Zt gMWY7X/BE+5D7oprIhHwjziLaqqbwogk3QVm0R1V6qiuZUF/qS5EgE4L7/QKsVgBiDJK AaAg== X-Gm-Message-State: AOAM533Wpuq8BcSzJ7FshRjzQ+l/t06u7PRWkLlBS7up/BHiHJnZMm1h C5XgMCEHvaMI2N9lCt0ilqtDVIMC1Lyr/Q== X-Google-Smtp-Source: ABdhPJyIbuE9t6aeZQu06o+X2h+vnUq44B/CC7xAWI3oOnHCX7F7G9PmG5tUl2yjnW288PcM/xOXCg== X-Received: by 2002:aa7:8e4e:0:b029:3e0:28db:d73b with SMTP id d14-20020aa78e4e0000b02903e028dbd73bmr14309318pfr.8.1629088322111; Sun, 15 Aug 2021 21:32:02 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6f5f:1479:a6ab:4229]) by smtp.gmail.com with ESMTPSA id u10sm2767417pgj.48.2021.08.15.21.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:32:01 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Aug 2021 13:31:38 +0900 Message-Id: <20210816043138.957984-11-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210816043138.957984-1-hiroh@chromium.org> References: <20210816043138.957984-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 10/10] libcamera: framebuffer: Add assertion to detect offset is unfilled 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 offset variable is introduced to FrameBuffer::Plane. In order to detect that the plane is used while the offset is not set, this adds the assertion to FrameBuffer::planes(). It should be removed in the future. Signed-off-by: Hirokazu Honda --- include/libcamera/framebuffer.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index 5de3c744..79541557 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -7,6 +7,8 @@ #ifndef __LIBCAMERA_FRAMEBUFFER_H__ #define __LIBCAMERA_FRAMEBUFFER_H__ +#include +#include #include #include @@ -41,14 +43,21 @@ class FrameBuffer final : public Extensible public: struct Plane { + static constexpr unsigned int kInvalidOffset = std::numeric_limits::max(); FileDescriptor fd; - unsigned int offset; + unsigned int offset = kInvalidOffset; unsigned int length; }; FrameBuffer(const std::vector &planes, unsigned int cookie = 0); - const std::vector &planes() const { return planes_; } + const std::vector &planes() const + { + /* \todo remove this assert. */ + for (const auto &plane : planes_) + assert(plane.offset != Plane::kInvalidOffset); + return planes_; + } Request *request() const; const FrameMetadata &metadata() const { return metadata_; }