From patchwork Wed Feb 8 09:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18270 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 A7A69C324D for ; Wed, 8 Feb 2023 09:59:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5B28D62601; Wed, 8 Feb 2023 10:59:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1675850376; bh=HbRSjQ39da2Lgx0fziaXvG6iGKLteMFYspzo4RV1DgM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=MktP4IWHnzUJg2IFF1shtxWVE3R9r4FtNXcHTUMgsLVccUuHRACLdLJj7RSqiInbj L/D7uYXzclWSponHeLPCk76oON5hK+6S1WwaMl5gIFSFKLr85pf9vmdpU/uAYTDfV6 jGoNBDz+epaPITxszmJMd1s+9rK/kSRzUH4kaJvMMNBjp5hLpW52XDnzf+Qsw2hCFx HNztDMvWztvxhcj33n8iK1AR8Au4Y6T0MOKfBDe16C2wmRqPA0WftwyiTGaq33NpKD SlpDC1aYV0JdTG8AGhlbA+6sYYfzbfcOppJ66cyhvK9HIEysulUhD3RoWD3UGbwem4 CXGXuiCPa3Ecw== Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CEE2D625F4 for ; Wed, 8 Feb 2023 10:59:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="R8nQ306n"; dkim-atps=neutral Received: by mail-pj1-x102a.google.com with SMTP id c10-20020a17090a1d0a00b0022e63a94799so1863003pjd.2 for ; Wed, 08 Feb 2023 01:59:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=72Bs66NZMpVyTD6wUic29MKfkfKk43ErfuKBDYJ1n2I=; b=R8nQ306nRNqUxDooZMdPxTDhUiTWaCJqdCX93xiD+2GI793fB4kaJufPudkJ8e57n7 FYvBRD/Y54qw/c1xmNMIO4ChU6kt7swNGYtkM+N+OTwZJn2Gcvnmloq9HIY/4rSbSTgO x1q246nKpl5YwukkNJ+a8SQ3Ar+z/Lxr5Lthg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=72Bs66NZMpVyTD6wUic29MKfkfKk43ErfuKBDYJ1n2I=; b=ns9VKc+IWdqjgVY7qsa+uYXsWTUOiq7xQvhvaBBkQEUnBrGaLMsr0fN6hKIZEcL728 qm/3q3wOGJ1YeQzL8FA3OKFXvbFwwYKZie26kVclJMeO2wLMHktXAcddxt95uKosrSFK NwxddW+rlqfX6JScaOc04s06UlialHVR4cWv9Z+j/i5+EPzeKXv2kHtAc66r3oJyLsrJ h2Hbd2YRZ5jLIbbEN12ezk+i1WD8GXSBDiAp/EhgnCQNn9NdHeg8+QhvpMyVSJD8PQp+ lr4PoU3yKQ7MvuVFT/f6DmaTDuDmtalLHcg1x067I19J89JH5OszLN/yka2d3T5e/oxk laBg== X-Gm-Message-State: AO0yUKU5h9oirSSzKQF/bGp7StIntXl7s0aypp74hhpJJ+hEBPwpKpfn G+cEgA6jYhP65q6zGvp9QDHiaBKycY6HLitH X-Google-Smtp-Source: AK7set+ChTKXoN1BUUyo/IF1H536ZKJXpWIlTVmuYZhROSazcGWk6y09jz44wBnJ89f6SdAxRdVoJw== X-Received: by 2002:a17:90b:3508:b0:230:ac45:b4a with SMTP id ls8-20020a17090b350800b00230ac450b4amr7860986pjb.21.1675850371909; Wed, 08 Feb 2023 01:59:31 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id m2-20020a17090a4d8200b00230b8402760sm1077773pjh.38.2023.02.08.01.59.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 01:59:31 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Feb 2023 09:59:22 +0000 Message-Id: <20230208095922.1471175-4-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog In-Reply-To: <20230208095922.1471175-1-chenghaoyang@google.com> References: <20230208095922.1471175-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 3/3] libcamera: Add exportFrameBuffers in HeapAllocator 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-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a helper function exportFrameBuffers in HeapAllocator to make it easier to use. Signed-off-by: Harvey Yang --- include/libcamera/heap_allocator.h | 10 +++++++ src/libcamera/heap_allocator.cpp | 44 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/libcamera/heap_allocator.h b/include/libcamera/heap_allocator.h index cd7ed1a3..138596de 100644 --- a/include/libcamera/heap_allocator.h +++ b/include/libcamera/heap_allocator.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include @@ -15,6 +16,10 @@ namespace libcamera { +class Camera; +class Stream; +class FrameBuffer; + class HeapAllocator { public: @@ -23,7 +28,12 @@ public: bool isValid() const { return heap_->isValid(); } UniqueFD alloc(const char *name, std::size_t size); + int exportFrameBuffers(Camera *camera, Stream *stream, + std::vector> *buffers); + private: + std::unique_ptr createBuffer(std::size_t size); + std::unique_ptr heap_; }; diff --git a/src/libcamera/heap_allocator.cpp b/src/libcamera/heap_allocator.cpp index 179c2c21..1faa5585 100644 --- a/src/libcamera/heap_allocator.cpp +++ b/src/libcamera/heap_allocator.cpp @@ -17,7 +17,10 @@ #include +#include #include +#include +#include #include namespace libcamera { @@ -43,4 +46,45 @@ UniqueFD HeapAllocator::alloc(const char *name, std::size_t size) return heap_->alloc(name, size); } +int HeapAllocator::exportFrameBuffers([[maybe_unused]] Camera *camera, Stream *stream, + std::vector> *buffers) +{ + unsigned int count = stream->configuration().bufferCount; + + /** \todo: Support multiplanar allocations */ + size_t size = stream->configuration().frameSize; + + for (unsigned i = 0; i < count; ++i) { + std::unique_ptr buffer = createBuffer(size); + if (!buffer) { + LOG(HeapAllocator, Error) << "Unable to create buffer"; + + buffers->clear(); + return -EINVAL; + } + + buffers->push_back(std::move(buffer)); + } + + return count; +} + +std::unique_ptr HeapAllocator::createBuffer(std::size_t size) +{ + std::vector planes; + + UniqueFD fd = alloc("Buffer", size); + if (!fd.isValid()) + return nullptr; + + FrameBuffer::Plane plane; + plane.fd = SharedFD(std::move(fd)); + plane.offset = 0; + plane.length = size; + + planes.push_back(std::move(plane)); + + return std::make_unique(planes); +} + } /* namespace libcamera */