Show a patch.

GET /api/patches/13944/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13944,
    "url": "https://patchwork.libcamera.org/api/patches/13944/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13944/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20210927104821.2526508-2-hiroh@chromium.org>",
    "date": "2021-09-27T10:48:20",
    "name": "[libcamera-devel,RFC,1/2] android: Introduce PlatformFrameBufferAllocator",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "640d8d77177b71ce8d479cd28190d0540bcf094f",
    "submitter": {
        "id": 63,
        "url": "https://patchwork.libcamera.org/api/people/63/?format=api",
        "name": "Hirokazu Honda",
        "email": "hiroh@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13944/mbox/",
    "series": [
        {
            "id": 2572,
            "url": "https://patchwork.libcamera.org/api/series/2572/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2572",
            "date": "2021-09-27T10:48:19",
            "name": "android: Fix the issue with Type::Mapped only request",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2572/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13944/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13944/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 A8CA9C3243\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Sep 2021 10:48:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7901869193;\n\tMon, 27 Sep 2021 12:48:33 +0200 (CEST)",
            "from mail-pl1-x631.google.com (mail-pl1-x631.google.com\n\t[IPv6:2607:f8b0:4864:20::631])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 520EF69189\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 12:48:31 +0200 (CEST)",
            "by mail-pl1-x631.google.com with SMTP id bb10so11507554plb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 03:48:31 -0700 (PDT)",
            "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:7cac:9967:6683:8845])\n\tby smtp.gmail.com with ESMTPSA id\n\tb11sm18694452pge.57.2021.09.27.03.48.27\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 27 Sep 2021 03:48:28 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"avuZCksG\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=HPdtTWeFNk194YiGMW//3NWvGklNDVDINr9fGXGmR9M=;\n\tb=avuZCksGq7EG5SiZja88QL5B3QllorLJLZ3z83ryPbE/dbnZfXNaoQhdOh5OmGWhTM\n\tn6xoB39+0DzOZBKGAFBC+SnweEcRSJAUC2/S+xKzf1s2Uxhb1cOHqoYWfZNNaXT9NOrJ\n\tuDinq6WeCbM601QoBsb4SWdXHkvn5pV2ZQUK0=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=HPdtTWeFNk194YiGMW//3NWvGklNDVDINr9fGXGmR9M=;\n\tb=SV+s6MFPhZeFcBr2OejgrCep51wGrmktNyzmH/un0fhWKZfUJnGCuZfLgEdgZjqE3Q\n\tEL3xiO4tChhGfZ+po6KkAxUPeVkPGXK8+oIQ4E6dwQuHr2Na+MaFHfN5jGKSFDJ9E3PE\n\tcsRG5S3Be7dKhxIhNLu3C9s+py4WCa6j2y/NnVPUSmBtgI/7UkjltZiEySsvJmcJneGn\n\taVGj9TUPXRE2O1El9pVkjjMNDk/pvIkSkKDPrKNXmQV0DjBP6OzggpPYe1RnN44v2Ri/\n\tqeT7keg/sfMr58vuK+8+0o10BGol52FgZyQSmalx6j3rJvfublSwvuPTsDhhrjeTKz1R\n\ttEVg==",
        "X-Gm-Message-State": "AOAM531Gxu50FG4b5NG/hBcUSVVOak2x7ZmoqLnyvXwJhOGEvNzwVnr1\n\tFl9oT9jOXVdt9yLORCCyMOrM9/wJ9fUtvg==",
        "X-Google-Smtp-Source": "ABdhPJw8Dk2G2Z1G2So1QLWwIwkK8mPoxr5ha+Dt2SB6arjyBtU8WaIAmgNSjkEErNGYIZ2eqQzSvA==",
        "X-Received": "by 2002:a17:90b:3a8a:: with SMTP id\n\tom10mr18629898pjb.223.1632739709308; \n\tMon, 27 Sep 2021 03:48:29 -0700 (PDT)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 27 Sep 2021 19:48:20 +0900",
        "Message-Id": "<20210927104821.2526508-2-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.33.0.685.g46640cef36-goog",
        "In-Reply-To": "<20210927104821.2526508-1-hiroh@chromium.org>",
        "References": "<20210927104821.2526508-1-hiroh@chromium.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [RFC PATCH 1/2] android: Introduce\n\tPlatformFrameBufferAllocator",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "PlatformFrameBufferAllocator allocates FrameBuffer(s) using\ncros::CameraBufferManager on ChromeOS and gralloc on non\nChromeOS platform. The allocated FrameBuffer(s) are owned by\nPlatformFrameBufferAllocator an destroyed when\nPlatformFrameBufferAllocator is destroyed.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/frame_buffer.h              |  53 +++++++++++\n src/android/mm/cros_frame_buffer.cpp    |  85 +++++++++++++++++\n src/android/mm/generic_frame_buffer.cpp | 116 ++++++++++++++++++++++++\n src/android/mm/meson.build              |   6 +-\n 4 files changed, 258 insertions(+), 2 deletions(-)\n create mode 100644 src/android/frame_buffer.h\n create mode 100644 src/android/mm/cros_frame_buffer.cpp\n create mode 100644 src/android/mm/generic_frame_buffer.cpp",
    "diff": "diff --git a/src/android/frame_buffer.h b/src/android/frame_buffer.h\nnew file mode 100644\nindex 00000000..6aafeaf3\n--- /dev/null\n+++ b/src/android/frame_buffer.h\n@@ -0,0 +1,53 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * frame_buffer.h - Frame buffer allocating interface definition\n+ */\n+#ifndef __ANDROID_FRAME_BUFFER_H__\n+#define __ANDROID_FRAME_BUFFER_H__\n+\n+#include <memory>\n+#include <vector>\n+\n+#include <libcamera/base/class.h>\n+#include <libcamera/camera.h>\n+#include <libcamera/framebuffer.h>\n+#include <libcamera/geometry.h>\n+\n+class CameraDevice;\n+\n+class PlatformFrameBufferAllocator : libcamera::Extensible\n+{\n+\tLIBCAMERA_DECLARE_PRIVATE()\n+\n+public:\n+\texplicit PlatformFrameBufferAllocator(CameraDevice *const cameraDevice);\n+\t~PlatformFrameBufferAllocator();\n+\n+\tconst std::vector<std::unique_ptr<libcamera::FrameBuffer>> &\n+\tallocate(int halPixelFormat,\n+\t\t const libcamera::Size &size,\n+\t\t uint32_t usage,\n+\t\t size_t numBuffers);\n+};\n+\n+#define PUBLIC_FRAME_BUFFER_IMPLEMENTATION\t\t\t\t\\\n+PlatformFrameBufferAllocator::PlatformFrameBufferAllocator(\t\t\\\n+\tCameraDevice *const cameraDevice)\t\t\t\t\\\n+\t: Extensible(std::make_unique<Private>(this, cameraDevice))\t\\\n+{\t\t\t\t\t\t\t\t\t\\\n+}\t\t\t\t\t\t\t\t\t\\\n+PlatformFrameBufferAllocator::~PlatformFrameBufferAllocator()\t\t\\\n+{\t\t\t\t\t\t\t\t\t\\\n+}\t\t\t\t\t\t\t\t\t\\\n+const std::vector<std::unique_ptr<libcamera::FrameBuffer>>&\t\t\\\n+PlatformFrameBufferAllocator::allocate(int halPixelFormat,\t\t\\\n+\t\t\t\t       const libcamera::Size& size,\t\\\n+\t\t\t\t       uint32_t usage,\t\t\t\\\n+\t\t\t\t       size_t numBuffers)\t\t\\\n+{\t\t\t\t\t\t\t\t\t\\\n+\treturn _d()->allocate(halPixelFormat, size, usage, numBuffers);\t\\\n+}\n+\n+#endif /* __ANDROID_FRAME_BUFFER_H__ */\ndiff --git a/src/android/mm/cros_frame_buffer.cpp b/src/android/mm/cros_frame_buffer.cpp\nnew file mode 100644\nindex 00000000..114c739b\n--- /dev/null\n+++ b/src/android/mm/cros_frame_buffer.cpp\n@@ -0,0 +1,85 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * cros_frame_buffer.cpp - allocate FrameBuffer for Chromium OS buffer backend\n+ * using CameraBufferManager\n+ */\n+\n+#include \"../frame_buffer.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+#include \"cros-camera/camera_buffer_manager.h\"\n+\n+#include \"../camera_device.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DECLARE_CATEGORY(HAL)\n+\n+class PlatformFrameBufferAllocator::Private : public Extensible::Private\n+{\n+\tLIBCAMERA_DECLARE_PUBLIC(PlatformFrameBufferAllocator)\n+\n+public:\n+\tPrivate([[maybe_unused]] PlatformFrameBufferAllocator *allocator,\n+\t\t[[maybe_unused]] CameraDevice *const cameraDevice)\n+\t{\n+\t}\n+\n+\t~Private() = default;\n+\n+\tconst std::vector<std::unique_ptr<libcamera::FrameBuffer>> &\n+\tallocate(int halPixelFormat,\n+\t\t const libcamera::Size &size,\n+\t\t uint32_t usage,\n+\t\t size_t numBuffers);\n+\n+private:\n+\tstd::vector<std::unique_ptr<libcamera::FrameBuffer>> allocatedBuffers_;\n+\tstd::vector<cros::ScopedBufferHandle> allocatedHandles_;\n+};\n+\n+const std::vector<std::unique_ptr<libcamera::FrameBuffer>> &\n+PlatformFrameBufferAllocator::Private::allocate(\n+\tint halPixelFormat, const libcamera::Size &size, uint32_t usage,\n+\tsize_t numBuffers)\n+{\n+\tASSERT(allocatedBuffers_.empty());\n+\n+\tstd::vector<std::unique_ptr<libcamera::FrameBuffer>> buffers;\n+\tfor (size_t i = 0; i < numBuffers; ++i) {\n+\t\tcros::ScopedBufferHandle handle =\n+\t\t\tcros::CameraBufferManager::AllocateScopedBuffer(\n+\t\t\t\tsize.width, size.height, halPixelFormat, usage);\n+\t\tif (!handle) {\n+\t\t\tLOG(HAL, Error) << \"Failed allocate buffer_handle\";\n+\t\t\treturn allocatedBuffers_;\n+\t\t}\n+\n+\t\tconst size_t numPlanes = cros::CameraBufferManager::GetNumPlanes(*handle);\n+\t\tstd::vector<FrameBuffer::Plane> planes(numPlanes);\n+\t\tfor (size_t j = 0; j < numPlanes; ++j) {\n+\t\t\tFileDescriptor fd{ (*handle)->data[0] };\n+\t\t\tif (!fd.isValid()) {\n+\t\t\t\tLOG(HAL, Fatal) << \"Invalid fd\";\n+\t\t\t\treturn allocatedBuffers_;\n+\t\t\t}\n+\n+\t\t\tplanes[j].fd = fd;\n+\t\t\tplanes[j].offset =\n+\t\t\t\tcros::CameraBufferManager::GetPlaneOffset(*handle, j);\n+\t\t\tplanes[j].length =\n+\t\t\t\tcros::CameraBufferManager::GetPlaneSize(*handle, j);\n+\t\t}\n+\n+\t\tbuffers.push_back(std::make_unique<FrameBuffer>(planes));\n+\t\tallocatedHandles_.push_back(std::move(handle));\n+\t}\n+\n+\tallocatedBuffers_ = std::move(buffers);\n+\treturn allocatedBuffers_;\n+}\n+\n+PUBLIC_FRAME_BUFFER_IMPLEMENTATION\ndiff --git a/src/android/mm/generic_frame_buffer.cpp b/src/android/mm/generic_frame_buffer.cpp\nnew file mode 100644\nindex 00000000..b387d5a2\n--- /dev/null\n+++ b/src/android/mm/generic_frame_buffer.cpp\n@@ -0,0 +1,116 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * generic_camera_buffer.cpp - allocate FrameBuffer for Generic Android frame\n+ * buffer backend\n+ */\n+\n+#include \"../frame_buffer.h\"\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/internal/formats.h>\n+\n+#include <hardware/camera3.h>\n+#include <hardware/gralloc.h>\n+#include <hardware/hardware.h>\n+\n+#include \"../camera_device.h\"\n+\n+using namespace libcamera;\n+\n+LOG_DECLARE_CATEGORY(HAL)\n+\n+class PlatformFrameBufferAllocator::Private : public Extensible::Private\n+{\n+\tLIBCAMERA_DECLARE_PUBLIC(PlatformFrameBufferAllocator)\n+\n+public:\n+\tPrivate([[maybe_unused]] PlatformFrameBufferAllocator *allocator,\n+\t\tCameraDevice *const cameraDevice)\n+\t\t: cameraDevice_(cameraDevice),\n+\t\t  hardwareModule_(cameraDevice->camera3Device()->common.module)\n+\t{\n+\t\tASSERT(!!hardwareModule_);\n+\t}\n+\n+\t~Private() override;\n+\n+\tconst std::vector<std::unique_ptr<libcamera::FrameBuffer>> &\n+\tallocate(int halPixelFormat,\n+\t\t const libcamera::Size &size,\n+\t\t uint32_t usage,\n+\t\t size_t numBuffers);\n+\n+private:\n+\tconst CameraDevice *const cameraDevice_;\n+\tstruct hw_module_t *const hardwareModule_;\n+\tstruct alloc_device_t *allocDevice_;\n+\n+\tstd::vector<std::unique_ptr<libcamera::FrameBuffer>> allocatedBuffers_;\n+\tstd::vector<buffer_handle_t> bufferHandles_;\n+};\n+\n+PlatformFrameBufferAllocator::Private::~Private()\n+{\n+\tfor (buffer_handle_t &handle : bufferHandles_) {\n+\t\tASSERT(allocDevice_);\n+\t\tallocDevice_->free(allocDevice_, handle);\n+\t}\n+\tif (allocDevice_)\n+\t\tgralloc_close(allocDevice_);\n+}\n+\n+const std::vector<std::unique_ptr<libcamera::FrameBuffer>> &\n+PlatformFrameBufferAllocator::Private::allocate(\n+\tint halPixelFormat, const libcamera::Size &size, uint32_t usage,\n+\tsize_t numBuffers)\n+{\n+\tASSERT(allocatedBuffers_.empty());\n+\tASSERT(bufferHandles_.empty());\n+\tASSERT(!allocDevice_);\n+\n+\tint ret = gralloc_open(hardwareModule_, &allocDevice_);\n+\tif (ret) {\n+\t\tLOG(HAL, Error) << \"gralloc_open() failed: \" << ret;\n+\t\treturn allocatedBuffers_;\n+\t}\n+\n+\tint stride = 0;\n+\tfor (size_t i = 0; i < numBuffers; ++i) {\n+\t\tbuffer_handle_t handle{};\n+\t\tret = allocDevice_->alloc(allocDevice_, size.width, size.height,\n+\t\t\t\t\t  halPixelFormat, usage, &handle, &stride);\n+\t\tif (ret) {\n+\t\t\tLOG(HAL, Error) << \"failed buffer allocating: \" << ret;\n+\t\t\treturn allocatedBuffers_;\n+\t\t}\n+\n+\t\tbufferHandles_.push_back(handle);\n+\t}\n+\n+\tconst libcamera::PixelFormat pixelFormat =\n+\t\tcameraDevice_->capabilities()->toPixelFormat(halPixelFormat);\n+\tconst auto &info = PixelFormatInfo::info(pixelFormat);\n+\tconst unsigned int numPlanes = info.numPlanes();\n+\n+\tallocatedBuffers_.reserve(numBuffers);\n+\tfor (const buffer_handle_t &handle : bufferHandles_) {\n+\t\tstd::vector<FrameBuffer::Plane> planes(numPlanes);\n+\t\tsize_t offset = 0;\n+\t\tfor (size_t i = 0; i < numPlanes; ++i) {\n+\t\t\tplanes[i].fd = FileDescriptor(handle->data[i]);\n+\t\t\tsize_t planeSize = info.planeSize(size.height, i, stride);\n+\n+\t\t\tplanes[i].offset = offset;\n+\t\t\tplanes[i].length = planeSize;\n+\t\t\toffset += planeSize;\n+\t\t}\n+\n+\t\tallocatedBuffers_.push_back(std::make_unique<FrameBuffer>(planes));\n+\t}\n+\n+\treturn allocatedBuffers_;\n+}\n+\n+PUBLIC_FRAME_BUFFER_IMPLEMENTATION\ndiff --git a/src/android/mm/meson.build b/src/android/mm/meson.build\nindex eeb5cc2e..d1ad64d9 100644\n--- a/src/android/mm/meson.build\n+++ b/src/android/mm/meson.build\n@@ -2,8 +2,10 @@\n \n platform = get_option('android_platform')\n if platform == 'generic'\n-    android_hal_sources += files(['generic_camera_buffer.cpp'])\n+    android_hal_sources += files(['generic_camera_buffer.cpp',\n+                                  'generic_frame_buffer.cpp'])\n elif platform == 'cros'\n-    android_hal_sources += files(['cros_camera_buffer.cpp'])\n+    android_hal_sources += files(['cros_camera_buffer.cpp',\n+                                  'cros_frame_buffer.cpp'])\n     android_deps += [dependency('libcros_camera')]\n endif\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "1/2"
    ]
}