{"id":11428,"url":"https://patchwork.libcamera.org/api/patches/11428/?format=json","web_url":"https://patchwork.libcamera.org/patch/11428/","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":"<20210301150111.61791-11-jacopo@jmondi.org>","date":"2021-03-01T15:01:11","name":"[libcamera-devel,10/10] android: Introduce Chromium OS buffer manager","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"548a564682f27dbaa4a841101c7a3819c91cd358","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/11428/mbox/","series":[{"id":1735,"url":"https://patchwork.libcamera.org/api/series/1735/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1735","date":"2021-03-01T15:01:01","name":"Support memory backends","version":1,"mbox":"https://patchwork.libcamera.org/series/1735/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11428/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11428/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 A7106BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  1 Mar 2021 15:01:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 811BF68A7D;\n\tMon,  1 Mar 2021 16:01:10 +0100 (CET)","from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A418F68A94\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Mar 2021 16:01:08 +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 relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 5F0D440010;\n\tMon,  1 Mar 2021 15:01:07 +0000 (UTC)"],"X-Originating-IP":"93.61.96.190","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  1 Mar 2021 16:01:11 +0100","Message-Id":"<20210301150111.61791-11-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.30.0","In-Reply-To":"<20210301150111.61791-1-jacopo@jmondi.org>","References":"<20210301150111.61791-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 10/10] android: Introduce Chromium OS\n\tbuffer manager","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":"Introduce the CameraBuffer backend for the Chromium OS operating system\nand the associated meson option.\n\nThe Chromium OS CameraBuffer implementation uses the\ncros::CameraBufferManager class to perform mapping of 1 plane and multiplane\nbuffers and to retrieve size information.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n meson_options.txt                     |   2 +-\n src/android/mm/cros_camera_buffer.cpp | 141 ++++++++++++++++++++++++++\n src/android/mm/meson.build            |   3 +\n 3 files changed, 145 insertions(+), 1 deletion(-)\n create mode 100644 src/android/mm/cros_camera_buffer.cpp","diff":"diff --git a/meson_options.txt b/meson_options.txt\nindex d840543b01f5..870914662f3e 100644\n--- a/meson_options.txt\n+++ b/meson_options.txt\n@@ -7,7 +7,7 @@ option('android',\n \n option('android_platform',\n         type : 'combo',\n-        choices : ['generic'],\n+        choices : ['generic', 'cros'],\n         value : 'generic',\n         description : 'Select the Android platform to compile for')\n \ndiff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp\nnew file mode 100644\nindex 000000000000..1103f4423c2f\n--- /dev/null\n+++ b/src/android/mm/cros_camera_buffer.cpp\n@@ -0,0 +1,141 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * cros_camera_buffer.cpp - Chromium OS buffer backend using CameraBufferManager\n+ */\n+\n+#include \"../camera_buffer.h\"\n+\n+#include \"libcamera/internal/log.h\"\n+#include <libcamera/span.h>\n+\n+#include \"cros-camera/camera_buffer_manager.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DECLARE_CATEGORY(HAL)\n+\n+class CameraBuffer::Private : public Extensible::Private\n+{\n+\tLIBCAMERA_DECLARE_PUBLIC(CameraBuffer)\n+\n+public:\n+\tPrivate(CameraBuffer *cameraBuffer,\n+\t\tbuffer_handle_t camera3Buffer, int flags);\n+\t~Private();\n+\n+\tbool isValid() const { return valid_; }\n+\n+\tunsigned int numPlanes() const;\n+\n+\tSpan<const uint8_t> plane(unsigned int plane) const;\n+\tSpan<uint8_t> plane(unsigned int plane);\n+\n+private:\n+\tcros::CameraBufferManager *bufferManager_;\n+\tbuffer_handle_t handle_;\n+\tunsigned int numPlanes_;\n+\tbool valid_;\n+\tunion {\n+\t\tvoid *addr;\n+\t\tandroid_ycbcr ycbcr;\n+\t} mem;\n+\n+\tconst uint8_t *planeAddr(unsigned int plane) const;\n+\tuint8_t *planeAddr(unsigned int plane);\n+};\n+\n+CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,\n+\t\t\t       buffer_handle_t camera3Buffer, int flags)\n+\t: Extensible::Private(cameraBuffer), handle_(camera3Buffer),\n+\t  numPlanes_(0), valid_(false)\n+{\n+\tbufferManager_ = cros::CameraBufferManager::GetInstance();\n+\n+\tbufferManager_->Register(camera3Buffer);\n+\n+\tnumPlanes_ = bufferManager_->GetNumPlanes(camera3Buffer);\n+\tswitch (numPlanes_) {\n+\tcase 1: {\n+\t\tint ret = bufferManager_->Lock(handle_, 0, 0, 0, 0, 0, &mem.addr);\n+\t\tif (ret) {\n+\t\t\tLOG(HAL, Error) << \"Single plane buffer mapping failed\";\n+\t\t\treturn;\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tcase 2:\n+\tcase 3: {\n+\t\tint ret = bufferManager_->LockYCbCr(handle_, 0, 0, 0, 0, 0,\n+\t\t\t\t\t\t    &mem.ycbcr);\n+\t\tif (ret) {\n+\t\t\tLOG(HAL, Error) << \"YCbCr buffer mapping failed\";\n+\t\t\treturn;\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tdefault:\n+\t\tLOG(HAL, Error) << \"Invalid number of planes: \" << numPlanes_;\n+\t\treturn;\n+\t}\n+\n+\tvalid_ = true;\n+}\n+\n+CameraBuffer::Private::~Private()\n+{\n+\tbufferManager_->Unlock(handle_);\n+\tbufferManager_->Deregister(handle_);\n+}\n+\n+unsigned int CameraBuffer::Private::numPlanes() const\n+{\n+\treturn bufferManager_->GetNumPlanes(handle_);\n+}\n+\n+Span<const uint8_t> CameraBuffer::Private::plane(unsigned int plane) const\n+{\n+\tconst uint8_t *addr = planeAddr(plane);\n+\treturn { addr, bufferManager_->GetPlaneSize(handle_, plane) };\n+}\n+\n+Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n+{\n+\tuint8_t *addr = planeAddr(plane);\n+\treturn { addr, bufferManager_->GetPlaneSize(handle_, plane) };\n+}\n+\n+const uint8_t *CameraBuffer::Private::planeAddr(unsigned int plane) const\n+{\n+\tconst void *addr;\n+\n+\tswitch (numPlanes()) {\n+\tcase 1:\n+\t\taddr = mem.addr;\n+\t\tbreak;\n+\tdefault:\n+\t\tswitch (plane) {\n+\t\tcase 1:\n+\t\t\taddr = mem.ycbcr.y;\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\taddr = mem.ycbcr.cb;\n+\t\t\tbreak;\n+\t\tcase 3:\n+\t\t\taddr = mem.ycbcr.cr;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn static_cast<const uint8_t *>(addr);\n+}\n+\n+uint8_t *CameraBuffer::Private::planeAddr(unsigned int plane)\n+{\n+\tconst CameraBuffer::Private *self =\n+\t\tconst_cast<const CameraBuffer::Private *>(this);\n+\treturn const_cast<uint8_t *>(self->planeAddr(plane));\n+}\n+\n+PUBLIC_CAMERA_BUFFER\ndiff --git a/src/android/mm/meson.build b/src/android/mm/meson.build\nindex 97f83f2a7380..eeb5cc2e6a31 100644\n--- a/src/android/mm/meson.build\n+++ b/src/android/mm/meson.build\n@@ -3,4 +3,7 @@\n platform = get_option('android_platform')\n if platform == 'generic'\n     android_hal_sources += files(['generic_camera_buffer.cpp'])\n+elif platform == 'cros'\n+    android_hal_sources += files(['cros_camera_buffer.cpp'])\n+    android_deps += [dependency('libcros_camera')]\n endif\n","prefixes":["libcamera-devel","10/10"]}