{"id":11435,"url":"https://patchwork.libcamera.org/api/patches/11435/?format=json","web_url":"https://patchwork.libcamera.org/patch/11435/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210302115108.103328-3-jacopo@jmondi.org>","date":"2021-03-02T11:51:00","name":"[libcamera-devel,v3,02/10] android: Introduce CameraBuffer interface","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"91a538459982d171a3795af7a3939498fb0c80a9","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11435/mbox/","series":[{"id":1738,"url":"https://patchwork.libcamera.org/api/series/1738/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1738","date":"2021-03-02T11:50:58","name":"android: Supports memory backends","version":3,"mbox":"https://patchwork.libcamera.org/series/1738/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11435/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11435/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 56A7EBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Mar 2021 11:50:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 323E068AA5;\n\tTue,  2 Mar 2021 12:50:48 +0100 (CET)","from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 02CF968A93\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Mar 2021 12:50:47 +0100 (CET)","from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id 9E978200009;\n\tTue,  2 Mar 2021 11:50:45 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  2 Mar 2021 12:51:00 +0100","Message-Id":"<20210302115108.103328-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.30.0","In-Reply-To":"<20210302115108.103328-1-jacopo@jmondi.org>","References":"<20210302115108.103328-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 02/10] android: Introduce CameraBuffer\n\tinterface","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"Han-lin Chen <hanlinchen@chromium.org>,\n\tDaniel Hung-yu Wu <hywu@google.com>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"In order to provide support for different memory backends,\nmove the MappedCamera3Buffer class definition outside of the\nCameraDevice class to its own file and rename it in CameraBuffer.\n\nThe interface defined in camera_buffer.h will be implemented by\ndifferent backends that will be placed in the src/android/mm\nsubdirectory.\n\nProvide a first implementation for the 'generic android' backend\nwhich matches the existing one.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_buffer.h              | 21 +++++++++++\n src/android/camera_device.cpp            | 34 +----------------\n src/android/camera_device.h              |  7 +---\n src/android/meson.build                  |  2 +\n src/android/mm/generic_camera_buffer.cpp | 47 ++++++++++++++++++++++++\n src/android/mm/meson.build               |  6 +++\n 6 files changed, 79 insertions(+), 38 deletions(-)\n create mode 100644 src/android/camera_buffer.h\n create mode 100644 src/android/mm/generic_camera_buffer.cpp\n create mode 100644 src/android/mm/meson.build","diff":"diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h\nnew file mode 100644\nindex 000000000000..00b061502d6e\n--- /dev/null\n+++ b/src/android/camera_buffer.h\n@@ -0,0 +1,21 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * camera_buffer.h - Frame buffer handling interface definition\n+ */\n+#ifndef __ANDROID_CAMERA_BUFFER_H__\n+#define __ANDROID_CAMERA_BUFFER_H__\n+\n+#include <hardware/camera3.h>\n+\n+#include <libcamera/internal/buffer.h>\n+\n+class CameraBuffer : public libcamera::MappedBuffer\n+{\n+public:\n+\tCameraBuffer(const buffer_handle_t camera3buffer, int flags);\n+\t~CameraBuffer();\n+};\n+\n+#endif /* __ANDROID_CAMERA_BUFFER_H__ */\ndiff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 16cb8c6d2b84..f47f28b8c7ee 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -257,36 +257,6 @@ void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs,\n \n } /* namespace */\n \n-MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,\n-\t\t\t\t\t int flags)\n-{\n-\tmaps_.reserve(camera3buffer->numFds);\n-\terror_ = 0;\n-\n-\tfor (int i = 0; i < camera3buffer->numFds; i++) {\n-\t\tif (camera3buffer->data[i] == -1)\n-\t\t\tcontinue;\n-\n-\t\toff_t length = lseek(camera3buffer->data[i], 0, SEEK_END);\n-\t\tif (length < 0) {\n-\t\t\terror_ = -errno;\n-\t\t\tLOG(HAL, Error) << \"Failed to query plane length\";\n-\t\t\tbreak;\n-\t\t}\n-\n-\t\tvoid *address = mmap(nullptr, length, flags, MAP_SHARED,\n-\t\t\t\t     camera3buffer->data[i], 0);\n-\t\tif (address == MAP_FAILED) {\n-\t\t\terror_ = -errno;\n-\t\t\tLOG(HAL, Error) << \"Failed to mmap plane\";\n-\t\t\tbreak;\n-\t\t}\n-\n-\t\tmaps_.emplace_back(static_cast<uint8_t *>(address),\n-\t\t\t\t   static_cast<size_t>(length));\n-\t}\n-}\n-\n /*\n  * \\struct Camera3RequestDescriptor\n  *\n@@ -1892,8 +1862,8 @@ void CameraDevice::requestComplete(Request *request)\n \t\t * separate thread.\n \t\t */\n \n-\t\tMappedCamera3Buffer mapped(*descriptor->buffers_[i].buffer,\n-\t\t\t\t\t   PROT_READ | PROT_WRITE);\n+\t\tCameraBuffer mapped(*descriptor->buffers_[i].buffer,\n+\t\t\t\t    PROT_READ | PROT_WRITE);\n \t\tif (!mapped.isValid()) {\n \t\t\tLOG(HAL, Error) << \"Failed to mmap android blob buffer\";\n \t\t\tcontinue;\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 9cbfcad38433..e6c192c2100b 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -24,17 +24,12 @@\n #include \"libcamera/internal/log.h\"\n #include \"libcamera/internal/message.h\"\n \n+#include \"camera_buffer.h\"\n #include \"camera_metadata.h\"\n #include \"camera_stream.h\"\n #include \"camera_worker.h\"\n #include \"jpeg/encoder.h\"\n \n-class MappedCamera3Buffer : public libcamera::MappedBuffer\n-{\n-public:\n-\tMappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags);\n-};\n-\n class CameraDevice : protected libcamera::Loggable\n {\n public:\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex 9719c42b65c6..7004d32d4b23 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -52,6 +52,8 @@ android_hal_sources = files([\n     'yuv/post_processor_yuv.cpp'\n ])\n \n+subdir('mm')\n+\n android_camera_metadata_sources = files([\n     'metadata/camera_metadata.c',\n ])\ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nnew file mode 100644\nindex 000000000000..bd9152cf9a16\n--- /dev/null\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -0,0 +1,47 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * generic_camera_buffer.cpp - Generic Android frame buffer backend\n+ */\n+\n+#include \"../camera_buffer.h\"\n+\n+#include \"libcamera/internal/log.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DECLARE_CATEGORY(HAL)\n+\n+CameraBuffer::CameraBuffer(const buffer_handle_t camera3buffer, int flags)\n+{\n+\tmaps_.reserve(camera3buffer->numFds);\n+\terror_ = 0;\n+\n+\tfor (int i = 0; i < camera3buffer->numFds; i++) {\n+\t\tif (camera3buffer->data[i] == -1)\n+\t\t\tcontinue;\n+\n+\t\toff_t length = lseek(camera3buffer->data[i], 0, SEEK_END);\n+\t\tif (length < 0) {\n+\t\t\terror_ = -errno;\n+\t\t\tLOG(HAL, Error) << \"Failed to query plane length\";\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tvoid *address = mmap(nullptr, length, flags, MAP_SHARED,\n+\t\t\t\t     camera3buffer->data[i], 0);\n+\t\tif (address == MAP_FAILED) {\n+\t\t\terror_ = -errno;\n+\t\t\tLOG(HAL, Error) << \"Failed to mmap plane\";\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tmaps_.emplace_back(static_cast<uint8_t *>(address),\n+\t\t\t\t   static_cast<size_t>(length));\n+\t}\n+}\n+\n+CameraBuffer::~CameraBuffer()\n+{\n+}\ndiff --git a/src/android/mm/meson.build b/src/android/mm/meson.build\nnew file mode 100644\nindex 000000000000..97f83f2a7380\n--- /dev/null\n+++ b/src/android/mm/meson.build\n@@ -0,0 +1,6 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+platform = get_option('android_platform')\n+if platform == 'generic'\n+    android_hal_sources += files(['generic_camera_buffer.cpp'])\n+endif\n","prefixes":["libcamera-devel","v3","02/10"]}