From patchwork Mon Jul 20 22:42:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8900 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 816D4C0109 for ; Mon, 20 Jul 2020 22:42:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4A1BD605C6; Tue, 21 Jul 2020 00:42:46 +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="RlrB1Mpp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C9F7460868 for ; Tue, 21 Jul 2020 00:42:39 +0200 (CEST) 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 66A8F2A4; Tue, 21 Jul 2020 00:42:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1595284959; bh=b+RJdw7AB5+v7lD8xvW9oNeJ88FYZV30jIahUr+L2/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RlrB1MppXjoINy8Oic1BAU82SCRU3ZjsmLoYksFyTO02cIRtbmsHbi0EC7YP/iYzh 4P+ea9Ot5OeyAtSMdaQqC1cvcgXwehZJdHOl1Temq9XgXhyjCJMEDtU0UhGuzXEMkJ 9fSB2EXD2gGuvkAfEzY/kwMe4HPRGg9QuFZ8qpfU= From: Kieran Bingham To: libcamera devel Date: Mon, 20 Jul 2020 23:42:32 +0100 Message-Id: <20200720224232.153717-9-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200720224232.153717-1-kieran.bingham@ideasonboard.com> References: <20200720224232.153717-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 8/8] RFC-Only: android: camera_device: Provide a MappedCamera3Buffer 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" Utilise the MappedBuffer interface to map each of the planes provided in the Camera3 buffer to facilitate use in software streams. The buffers will be automatically unmapped when the object goes out of scope or is deleted. Signed-off-by: Kieran Bingham --- This patch shows an addition of a new MappedBuffer type constructed from a camera3buffer. The base class deals with the move-constructors and destructor, and gives us a common interface to pass a set of mapped dmabufs around. I had hoped to use this to pass in the camera3buffer for writing jpeg buffers to, giving the same interface for both the source and destination buffer - but for JPEG, I do also need to return the number of bytes actually consumed, so this ended up potentially not adding the benefits I hoped for. Still, it might still provide some benefits, so I've included it here as something to talk about. -- Kieran src/android/camera_device.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 6212ccdd61ec..f78486117e9f 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -86,6 +86,39 @@ const std::map camera3FormatsMap = { LOG_DECLARE_CATEGORY(HAL); +class MappedCamera3Buffer : public MappedBuffer { +public: + MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags) + { + maps_.reserve(camera3buffer->numFds); + error_ = 0; + + for (int i = 0; i < camera3buffer->numFds; i++) { + if (camera3buffer->data[i] == -1) + continue; + + off_t length = lseek(camera3buffer->data[i], 0, SEEK_END); + if (length < 0) { + error_ = errno; + LOG(HAL, Error) << "Failed to query plane length"; + break; + } + + void *address = mmap(nullptr, length, flags, MAP_SHARED, + camera3buffer->data[i], 0); + if (address == MAP_FAILED) { + error_ = errno; + LOG(HAL, Error) << "Failed to mmap plane"; + break; + } + + maps_.push_back({address, static_cast(length)}); + } + + valid_ = error_ == 0; + } +}; + /* * \struct Camera3RequestDescriptor *