Show a patch.

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

{
    "id": 13433,
    "url": "https://patchwork.libcamera.org/api/patches/13433/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13433/",
    "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": "<20210823124321.980847-3-hiroh@chromium.org>",
    "date": "2021-08-23T12:43:20",
    "name": "[libcamera-devel,RFC,2/3] android: camera_buffer: Map buffer in the first plane() call",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "d6d8b2d512b61457fc540ac972e016e7f94c367c",
    "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/13433/mbox/",
    "series": [
        {
            "id": 2384,
            "url": "https://patchwork.libcamera.org/api/series/2384/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2384",
            "date": "2021-08-23T12:43:18",
            "name": "Improve CameraBuffer implementation",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2384/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13433/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13433/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 C7133BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 12:43:36 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 87FBF688A3;\n\tMon, 23 Aug 2021 14:43:36 +0200 (CEST)",
            "from mail-pl1-x630.google.com (mail-pl1-x630.google.com\n\t[IPv6:2607:f8b0:4864:20::630])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D755A688AC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 14:43:33 +0200 (CEST)",
            "by mail-pl1-x630.google.com with SMTP id a5so10085005plh.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 05:43:33 -0700 (PDT)",
            "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:184e:5d20:8fcb:dfcd])\n\tby smtp.gmail.com with ESMTPSA id\n\to2sm12103107pgu.76.2021.08.23.05.43.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 23 Aug 2021 05:43:31 -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=\"OHAzmt/9\"; 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=PLLR3hebxfmwGxx8ycAFSj/gcCJJAYskwcHt/K1rz+A=;\n\tb=OHAzmt/9FHPLTq89oNoqLxdsXBgShcs6e1R1Qmgp2eVO5hPI3EjOFzUBELLgj1qWXR\n\th9GK26OaI/cveEhEdkwzs0eF7z4vTvylfj/Id5qez7AcDLtUScgI2p8z7wHZzTQgTlha\n\t7HatFI0Ti8AQiXfKYEIhzTuow+5efueukjAYk=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\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=PLLR3hebxfmwGxx8ycAFSj/gcCJJAYskwcHt/K1rz+A=;\n\tb=dkb/G7cAYD9nS94vm/aeDtqzTJipA6rAG8tmBGcwwi84b3WBHu823g9HPhx7cAFAHn\n\tTbldywr7z3ihW+3JVCuu8Fsz1Ipcnm74YHN/twy2VFgVDaIst4rZuaMov1GWBmoYzJ9M\n\tN8zP2BYtMmotR70l0gO86osqTC4FZhZJKjMwuPi8dj2CjoKCsJz+aGW3yJSJmA8/U3Y4\n\tyJzsNoeXrQSXiFokRt9xdJBGgi4AuMbqHy5QuiVL3tzxLJBzsrJU64IfyrTL9kKuClRl\n\tHDoOsCkmdkN8XTth6Lh42ZPFjh/AfpMdOCw9exgn2YSHw2LrfL74IOrmYVDlSHARaNqj\n\twOeg==",
        "X-Gm-Message-State": "AOAM530Sk17bdPQFpD56ePkT4EAmKXjiIT0p2OO6OvkslUBuPmMHhFIt\n\t25CkdaFSjxhIcQwDlBEzQqvZURybqgbZdA==",
        "X-Google-Smtp-Source": "ABdhPJxXAw+hyvYmzO2L8DGJ0B1h6tu1k5q0Xiesq2C5/qugtXoXjze6x/UHhhPGWINdum45FNitPA==",
        "X-Received": "by 2002:a17:902:8346:b0:131:bb78:7a9e with SMTP id\n\tz6-20020a170902834600b00131bb787a9emr12404997pln.28.1629722611831; \n\tMon, 23 Aug 2021 05:43:31 -0700 (PDT)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 23 Aug 2021 21:43:20 +0900",
        "Message-Id": "<20210823124321.980847-3-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.33.0.rc2.250.ged5fa647cd-goog",
        "In-Reply-To": "<20210823124321.980847-1-hiroh@chromium.org>",
        "References": "<20210823124321.980847-1-hiroh@chromium.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [RFC PATCH 2/3] android: camera_buffer: Map\n\tbuffer in the first plane() call",
        "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": "CameraBuffer implementation maps a given buffer_handle_t in\nconstructor. Mapping is redundant to only know the plane info like\nstride and offset. Mapping should be executed rater in the first\nplane() call.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/mm/cros_camera_buffer.cpp    | 71 ++++++++++--------\n src/android/mm/generic_camera_buffer.cpp | 93 +++++++++++++++---------\n 2 files changed, 100 insertions(+), 64 deletions(-)",
    "diff": "diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp\nindex 50732637..85ef6480 100644\n--- a/src/android/mm/cros_camera_buffer.cpp\n+++ b/src/android/mm/cros_camera_buffer.cpp\n@@ -25,7 +25,7 @@ public:\n \t\tint flags);\n \t~Private();\n \n-\tbool isValid() const { return valid_; }\n+\tbool isValid() const { return registered_; }\n \n \tunsigned int numPlanes() const;\n \n@@ -34,10 +34,12 @@ public:\n \tsize_t jpegBufferSize(size_t maxJpegBufferSize) const;\n \n private:\n+\tbool Map();\n+\n \tcros::CameraBufferManager *bufferManager_;\n \tbuffer_handle_t handle_;\n \tunsigned int numPlanes_;\n-\tbool valid_;\n+\tbool mapped_;\n \tbool registered_;\n \tunion {\n \t\tvoid *addr;\n@@ -50,7 +52,7 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,\n \t\t\t       [[maybe_unused]] libcamera::PixelFormat pixelFormat,\n \t\t\t       [[maybe_unused]] const libcamera::Size &size,\n \t\t\t       [[maybe_unused]] int flags)\n-\t: handle_(camera3Buffer), numPlanes_(0), valid_(false),\n+\t: handle_(camera3Buffer), numPlanes_(0), mapped_(false),\n \t  registered_(false)\n {\n \tbufferManager_ = cros::CameraBufferManager::GetInstance();\n@@ -63,36 +65,11 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,\n \n \tregistered_ = true;\n \tnumPlanes_ = bufferManager_->GetNumPlanes(camera3Buffer);\n-\tswitch (numPlanes_) {\n-\tcase 1: {\n-\t\tret = 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\tret = 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-\tif (valid_)\n+\tif (mapped_)\n \t\tbufferManager_->Unlock(handle_);\n \tif (registered_)\n \t\tbufferManager_->Deregister(handle_);\n@@ -105,6 +82,12 @@ unsigned int CameraBuffer::Private::numPlanes() const\n \n Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n {\n+\tif (!mapped_) {\n+\t\tmapped_ = Map();\n+\t\tif (!mapped_)\n+\t\t\treturn {};\n+\t}\n+\n \tvoid *addr;\n \n \tswitch (numPlanes()) {\n@@ -134,4 +117,34 @@ size_t CameraBuffer::Private::jpegBufferSize([[maybe_unused]] size_t maxJpegBuff\n \treturn bufferManager_->GetPlaneSize(handle_, 0);\n }\n \n+bool CameraBuffer::Private::Map()\n+{\n+\tint ret;\n+\tswitch (numPlanes_) {\n+\tcase 1: {\n+\t\tret = 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 false;\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tcase 2:\n+\tcase 3: {\n+\t\tret = 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 false;\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tdefault:\n+\t\tLOG(HAL, Error) << \"Invalid number of planes: \" << numPlanes_;\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n PUBLIC_CAMERA_BUFFER_IMPLEMENTATION\ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nindex 3127069f..6c1e4611 100644\n--- a/src/android/mm/generic_camera_buffer.cpp\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -37,6 +37,12 @@ public:\n \tsize_t jpegBufferSize(size_t maxJpegBufferSize) const;\n \n private:\n+\tbool Map();\n+\n+\tint fd_;\n+\tint flags_;\n+\tlibcamera::Size size_;\n+\tlibcamera::PixelFormatInfo info_;\n \t/* \\todo remove planes_ is added to MappedBuffer. */\n \tstd::vector<Span<uint8_t>> planes_;\n };\n@@ -45,83 +51,100 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,\n \t\t\t       buffer_handle_t camera3Buffer,\n \t\t\t       libcamera::PixelFormat pixelFormat,\n \t\t\t       const libcamera::Size &size, int flags)\n+\t: fd_(-1), flags_(flags), size_(size)\n {\n \terror_ = 0;\n \n-\tint fd = -1;\n \tfor (int i = 0; i < camera3Buffer->numFds; i++) {\n \t\tif (camera3Buffer->data[i] != -1) {\n-\t\t\tfd = camera3Buffer->data[i];\n+\t\t\tfd_ = camera3Buffer->data[i];\n \t\t\tbreak;\n \t\t}\n \t}\n \n-\tif (fd != -1) {\n+\tif (fd_ != -1) {\n \t\terror_ = EINVAL;\n \t\tLOG(HAL, Error) << \"No valid file descriptor\";\n \t\treturn;\n \t}\n \n-\tconst auto &info = libcamera::PixelFormatInfo::info(pixelFormat);\n-\tif (!info.isValid()) {\n+\tinfo_ = libcamera::PixelFormatInfo::info(pixelFormat);\n+\tif (!info_.isValid()) {\n \t\terror_ = EINVAL;\n \t\tLOG(HAL, Error) << \"Invalid pixel format: \"\n \t\t\t\t<< pixelFormat.toString();\n \t\treturn;\n \t}\n+}\n+\n+CameraBuffer::Private::~Private()\n+{\n+}\n+\n+unsigned int CameraBuffer::Private::numPlanes() const\n+{\n+\treturn info_.numPlanes();\n+}\n+\n+Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n+{\n+\tif (planes_.empty() && !Map())\n+\t\treturn {};\n \n-\tsize_t bufferLength = lseek(fd, 0, SEEK_END);\n+\tif (plane >= planes_.size())\n+\t\treturn {};\n+\n+\treturn planes_[plane];\n+}\n+\n+size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const\n+{\n+\tif (maps_.empty()) {\n+\t\tsize_t bufferLength = lseek(fd_, 0, SEEK_END);\n+\t\tif (bufferLength < 0)\n+\t\t\tLOG(HAL, Error) << \"Failed to get buffer length\";\n+\t\treturn 0;\n+\t}\n+\n+\treturn std::min<unsigned int>(maps_[0].size(),\n+\t\t\t\t      maxJpegBufferSize);\n+}\n+\n+bool CameraBuffer::Private::Map()\n+{\n+\tASSERT(fd_ != -1);\n+\n+\tsize_t bufferLength = lseek(fd_, 0, SEEK_END);\n \tif (bufferLength < 0) {\n \t\terror_ = -errno;\n \t\tLOG(HAL, Error) << \"Failed to get buffer length\";\n-\t\treturn;\n+\t\treturn false;\n \t}\n \n-\tvoid *address = mmap(nullptr, bufferLength, flags, MAP_SHARED, fd, 0);\n+\tvoid *address = mmap(nullptr, bufferLength, flags_, MAP_SHARED, fd_, 0);\n \tif (address == MAP_FAILED) {\n \t\terror_ = -errno;\n \t\tLOG(HAL, Error) << \"Failed to mmap plane\";\n-\t\treturn;\n+\t\treturn false;\n \t}\n \tmaps_.emplace_back(static_cast<uint8_t *>(address), bufferLength);\n \n-\tconst unsigned int numPlanes = info.numPlanes();\n+\tconst unsigned int numPlanes = info_.numPlanes();\n \tplanes_.resize(numPlanes);\n \tunsigned int offset = 0;\n \tfor (unsigned int i = 0; i < numPlanes; ++i) {\n-\t\tconst unsigned int vertSubSample = info.planes[i].verticalSubSampling;\n-\t\tconst unsigned int stride = info.stride(size.width, i, 1u);\n+\t\tconst unsigned int vertSubSample = info_.planes[i].verticalSubSampling;\n+\t\tconst unsigned int stride = info_.stride(size_.width, i, 1u);\n \t\tconst unsigned int planeSize =\n-\t\t\tstride * ((size.height + vertSubSample - 1) / vertSubSample);\n+\t\t\tstride * ((size_.height + vertSubSample - 1) / vertSubSample);\n \n \t\tplanes_[i] = libcamera::Span<uint8_t>(\n \t\t\tstatic_cast<uint8_t *>(address) + offset, planeSize);\n \n \t\toffset += planeSize;\n \t}\n-}\n-\n-CameraBuffer::Private::~Private()\n-{\n-}\n-\n-unsigned int CameraBuffer::Private::numPlanes() const\n-{\n-\treturn planes_.size();\n-}\n \n-Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n-{\n-\tif (plane >= planes_.size())\n-\t\treturn {};\n-\n-\treturn planes_[plane];\n-}\n-\n-size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const\n-{\n-\treturn std::min<unsigned int>(maps_[0].size(),\n-\t\t\t\t      maxJpegBufferSize);\n+\treturn true;\n }\n \n PUBLIC_CAMERA_BUFFER_IMPLEMENTATION\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "2/3"
    ]
}