From patchwork Thu Mar 2 08:13:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18326 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 5F009BF415 for ; Thu, 2 Mar 2023 08:14:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0F3A2626C1; Thu, 2 Mar 2023 09:14:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1677744843; bh=jCT2KScZi8M2XeTWcjx/iXTqRwnAWGbb85nr7/PM9qQ=; 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=Sppshb7rv5PkdkNOVw2cfq7Qhea86owt3BxzWFmpRGq41B2R4mkkwjDlA6sQdauqc 4BZZFINV2e3y8yd9142TYJiT13ELI9et5lIuTVZNna+YfV3MMmxg+ZVEhskWGuOTT8 zrlyRyQUecqQ6cv6YVNRngSvMbgtlv0hCMdmQ4DIBdgbPubCBd3DZgm7JtUtq2CZDB Nn7iuzjXjiJdcsFO9rWY7z7TDPNNeMPwSyu7u3k0SI5EAjrBtNKfAnDgM93cZHopzP CfZrFP8vw95P0jgTW1LJZ7OHKc/mlDGFduHCUptQ7Q1OGrTHP0peCSXqX9COA9PPlI E96vTR1R6/w5Q== 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 98300626CB for ; Thu, 2 Mar 2023 09:14:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="X6tEmFvb"; dkim-atps=neutral Received: by mail-pl1-x62c.google.com with SMTP id a9so6610453plh.11 for ; Thu, 02 Mar 2023 00:14:00 -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=XXgeleZza/lqecvBHGW2tNMDFrYD9w7jlc3eZUNxb4M=; b=X6tEmFvb+RtuR9bEWdyV9wPffL6InSDJ637kr3lfgVLbVun5ASPopFVI+dtwTr9GwJ H2Zl6M6nsNmRe2sT/+4dLzUTSLH01/lRy5CbKD4KLxZyKJKlgJaIaJo2QKRQyiDYneUa QJY3TOzACzYWK2nnQbQRX0d58TCYaq5+qdnhg= 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=XXgeleZza/lqecvBHGW2tNMDFrYD9w7jlc3eZUNxb4M=; b=5qeJK8uXm2GIQ7JJhP/jC7F/+ITvBktYs17gYbAhBKnlxxebmevsFhMOGGKGMkb82P oSThVvC4nVFbDkygAre5QFYxWynEeOP2CozmAz15IYZsNoJybU3jEUlL0ZZ04diGOLA2 SdFhwXuWVT7H4marhcSe6kuxPVTNbXr5rjVHs4QmwbcHj5/9cZgG9U/GBFv3Tibs2zPa Xo7Ff78B7ebV6WlPMDHP+OKRnIVGw/ylEgsu5WCvh8In3UBp5zduRd2NVGeRRDyjDpVk YBxPzcuW5aD5v0rHobk7CQ+TNBn1aZmIulp3zWmgpHgebfdtva+Tgh7zC3w6T/gWxvU0 CTOg== X-Gm-Message-State: AO0yUKUyt95FfsuOcx1Eae9cKHCR+T6fskitdQWJZYOMDO5OuP7OzXLw Kd1KDTjkxNipz4WQT5ls6+gn+Dbn0tZ2jZuX3Ss= X-Google-Smtp-Source: AK7set8RpU+BIuurIpLtTKRwMZ++S7YmXwyJsyppXcdb6AHdQeVWorDRxkURVnvAlhhe0/JQVW88ZA== X-Received: by 2002:a05:6a20:549e:b0:bc:a257:5b2a with SMTP id i30-20020a056a20549e00b000bca2575b2amr10408486pzk.31.1677744838867; Thu, 02 Mar 2023 00:13:58 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (112.157.221.35.bc.googleusercontent.com. [35.221.157.112]) by smtp.gmail.com with ESMTPSA id p9-20020aa78609000000b005a8bdc18453sm9179755pfn.35.2023.03.02.00.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 00:13:58 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Mar 2023 08:13:49 +0000 Message-Id: <20230302081349.3334290-4-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog In-Reply-To: <20230302081349.3334290-1-chenghaoyang@google.com> References: <20230302081349.3334290-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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: Cheng-Hao 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 */