Show a patch.

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

{
    "id": 13434,
    "url": "https://patchwork.libcamera.org/api/patches/13434/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13434/",
    "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-4-hiroh@chromium.org>",
    "date": "2021-08-23T12:43:21",
    "name": "[libcamera-devel,RFC,3/3] android: camera_buffer: Add stride/offset/size function",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "d6d6b3407166c80a0e0939b5eac53091186670de",
    "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/13434/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/13434/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13434/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 39009C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 12:43:37 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E7C316890E;\n\tMon, 23 Aug 2021 14:43:36 +0200 (CEST)",
            "from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com\n\t[IPv6:2607:f8b0:4864:20::42f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F06D6025B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 14:43:35 +0200 (CEST)",
            "by mail-pf1-x42f.google.com with SMTP id y190so15286762pfg.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 05:43:35 -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.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 23 Aug 2021 05:43:33 -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=\"VdAQcMMY\"; 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=bFCbYAuFJwWL8413qwL1JI4tS02tPRRVoLn2/nC3Hec=;\n\tb=VdAQcMMYjTxiGmQwhK6MrB0K5HslBCp69n7O1FdEcS5axywWAqzgGg0tK62QyvdBoJ\n\tKjtBCkeLU2u/aM1XuQkZf/IuAmsWOpxPQKT/te7nu1NocXuev2Re+0DlULYn1hySIkY9\n\tkFr9lydwOjePO1l8qOn5OxT1oZE6iahx3G66E=",
        "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=bFCbYAuFJwWL8413qwL1JI4tS02tPRRVoLn2/nC3Hec=;\n\tb=BCj9B0sfAy4bKvO44R87XmhscxpKXvfsTdxOtdUlDZJyUqTRET5jPrGIOeTljmLUix\n\toDPUbZAJmRsAj2+ywWlaJiqtNDnDMIXVmR1m9KvjNtOLHKbW0uPcxcqdmRI5AGe1PiAW\n\tn6sdThGwapFbBzU3K9gPSVFjV7ELNj3vEtKhyK9KLZPNvl0OcNjP5ysEWp/dxi20qDz7\n\tRx3Iz1ub77vUn5z6Gj74y+/0PYlNxnTE41n9UlWEDCqNwxGb8b5WYXa7yHUXsByqcVa7\n\te0AZrl2aN4vCUNi1qWy94ASDzZnfyqICUO8GuFxr8eWyHWdYx03mY5valOt+723GfXdy\n\tA3oQ==",
        "X-Gm-Message-State": "AOAM532CwEkAbX3k1s1Sp7IuFSAHKJzOdStUuvn1BBlLttNq4pDXwHwR\n\trp3oU+OSRvZeCYQpwMo+QJ+sMlS1hI2a6w==",
        "X-Google-Smtp-Source": "ABdhPJyd2jwFNhySd+duRoEGJzMm9NrPh2jKYBqeUBChMgN5xLOb1xguY/4dJzZedSreghY1pN1DWg==",
        "X-Received": "by 2002:aa7:8c19:0:b0:3e1:4b9e:cf89 with SMTP id\n\tc25-20020aa78c19000000b003e14b9ecf89mr34049582pfd.58.1629722613647; \n\tMon, 23 Aug 2021 05:43:33 -0700 (PDT)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 23 Aug 2021 21:43:21 +0900",
        "Message-Id": "<20210823124321.980847-4-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 3/3] android: camera_buffer: Add\n\tstride/offset/size function",
        "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": "This adds getter functions of stride, offset and size to CameraBuffer\ninterface.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/camera_buffer.h              | 16 +++++\n src/android/mm/cros_camera_buffer.cpp    | 19 ++++++\n src/android/mm/generic_camera_buffer.cpp | 78 ++++++++++++++++++------\n 3 files changed, 94 insertions(+), 19 deletions(-)",
    "diff": "diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h\nindex 87df2570..226a8f5c 100644\n--- a/src/android/camera_buffer.h\n+++ b/src/android/camera_buffer.h\n@@ -31,6 +31,10 @@ public:\n \tlibcamera::Span<const uint8_t> plane(unsigned int plane) const;\n \tlibcamera::Span<uint8_t> plane(unsigned int plane);\n \n+\tunsigned int stride(unsigned int plane) const;\n+\tunsigned int offset(unsigned int plane) const;\n+\tunsigned int size(unsigned int plane) const;\n+\n \tsize_t jpegBufferSize(size_t maxJpegBufferSize) const;\n };\n \n@@ -62,6 +66,18 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane)\t\t\t\\\n {\t\t\t\t\t\t\t\t\t\\\n \treturn _d()->plane(plane);\t\t\t\t\t\\\n }\t\t\t\t\t\t\t\t\t\\\n+unsigned int CameraBuffer::stride(unsigned int plane) const\t\t\\\n+{\t\t\t\t\t\t\t\t\t\\\n+\treturn _d()->stride(plane);\t\t\t\t\t\\\n+}\t\t\t\t\t\t\t\t\t\\\n+unsigned int CameraBuffer::offset(unsigned int plane) const\t\t\\\n+{\t\t\t\t\t\t\t\t\t\\\n+\treturn _d()->offset(plane);\t\t\t\t\t\\\n+}\t\t\t\t\t\t\t\t\t\\\n+unsigned int CameraBuffer::size(unsigned int plane) const\t\t\\\n+{\t\t\t\t\t\t\t\t\t\\\n+\treturn _d()->size(plane);\t\t\t\t\t\\\n+}\t\t\t\t\t\t\t\t\t\\\n size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const\t\\\n {\t\t\t\t\t\t\t\t\t\\\n \treturn _d()->jpegBufferSize(maxJpegBufferSize);\t\t\t\\\ndiff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp\nindex 85ef6480..4ba24f79 100644\n--- a/src/android/mm/cros_camera_buffer.cpp\n+++ b/src/android/mm/cros_camera_buffer.cpp\n@@ -31,6 +31,10 @@ public:\n \n \tSpan<uint8_t> plane(unsigned int plane);\n \n+\tunsigned int stride(unsigned int plane) const;\n+\tunsigned int offset(unsigned int plane) const;\n+\tunsigned int size(unsigned int plane) const;\n+\n \tsize_t jpegBufferSize(size_t maxJpegBufferSize) const;\n \n private:\n@@ -112,6 +116,21 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n \t\t bufferManager_->GetPlaneSize(handle_, plane) };\n }\n \n+unsigned int CameraBuffer::Private::stride(unsigned int plane) const\n+{\n+\treturn cros::CameraBufferManager::GetPlaneStride(handle_, plane);\n+}\n+\n+unsigned int CameraBuffer::Private::offset(unsigned int plane) const\n+{\n+\treturn cros::CameraBufferManager::GetPlaneOffset(handle_, plane);\n+}\n+\n+unsigned int CameraBuffer::Private::size(unsigned int plane) const\n+{\n+\treturn cros::CameraBufferManager::GetPlaneSize(handle_, plane);\n+}\n+\n size_t CameraBuffer::Private::jpegBufferSize([[maybe_unused]] size_t maxJpegBufferSize) const\n {\n \treturn bufferManager_->GetPlaneSize(handle_, 0);\ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nindex 6c1e4611..b296b3e3 100644\n--- a/src/android/mm/generic_camera_buffer.cpp\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -34,15 +34,24 @@ public:\n \n \tSpan<uint8_t> plane(unsigned int plane);\n \n+\tunsigned int stride(unsigned int plane) const;\n+\tunsigned int offset(unsigned int plane) const;\n+\tunsigned int size(unsigned int plane) const;\n+\n \tsize_t jpegBufferSize(size_t maxJpegBufferSize) const;\n \n private:\n+\tstruct PlaneInfo {\n+\t\tunsigned int stride;\n+\t\tunsigned int offset;\n+\t\tunsigned int size;\n+\t};\n+\n \tbool Map();\n \n \tint fd_;\n \tint flags_;\n-\tlibcamera::Size size_;\n-\tlibcamera::PixelFormatInfo info_;\n+\tstd::vector<PlaneInfo> planeInfo_;\n \t/* \\todo remove planes_ is added to MappedBuffer. */\n \tstd::vector<Span<uint8_t>> planes_;\n };\n@@ -51,7 +60,7 @@ 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+\t: fd_(-1), flags_(flags)\n {\n \terror_ = 0;\n \n@@ -68,13 +77,29 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,\n \t\treturn;\n \t}\n \n-\tinfo_ = libcamera::PixelFormatInfo::info(pixelFormat);\n-\tif (!info_.isValid()) {\n+\tconst auto &info = 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+\tconst unsigned int numPlanes = info.numPlanes();\n+\tplaneInfo_.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 planeSize =\n+\t\t\tstride * ((size.height + vertSubSample - 1) / vertSubSample);\n+\n+\t\tplaneInfo_[i].stride = stride;\n+\t\tplaneInfo_[i].offset = offset;\n+\t\tplaneInfo_[i].size = planeSize;\n+\n+\t\toffset += planeSize;\n+\t}\n }\n \n CameraBuffer::Private::~Private()\n@@ -83,7 +108,7 @@ CameraBuffer::Private::~Private()\n \n unsigned int CameraBuffer::Private::numPlanes() const\n {\n-\treturn info_.numPlanes();\n+\treturn planeInfo_.size();\n }\n \n Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n@@ -97,6 +122,30 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)\n \treturn planes_[plane];\n }\n \n+unsigned int CameraBuffer::Private::stride(unsigned int plane) const\n+{\n+\tif (plane >= planeInfo_.size())\n+\t\treturn 0;\n+\n+\treturn planeInfo_[plane].stride;\n+}\n+\n+unsigned int CameraBuffer::Private::offset(unsigned int plane) const\n+{\n+\tif (plane >= planeInfo_.size())\n+\t\treturn 0;\n+\n+\treturn planeInfo_[plane].offset;\n+}\n+\n+unsigned int CameraBuffer::Private::size(unsigned int plane) const\n+{\n+\tif (plane >= planeInfo_.size())\n+\t\treturn 0;\n+\n+\treturn planeInfo_[plane].size;\n+}\n+\n size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const\n {\n \tif (maps_.empty()) {\n@@ -129,19 +178,10 @@ bool CameraBuffer::Private::Map()\n \t}\n \tmaps_.emplace_back(static_cast<uint8_t *>(address), bufferLength);\n \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 planeSize =\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+\tplanes_.reserve(planeInfo_.size());\n+\tfor (const auto &info : planeInfo_) {\n+\t\tplanes_.emplace_back(\n+\t\t\tstatic_cast<uint8_t *>(address) + info.offset, info.size);\n \t}\n \n \treturn true;\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "3/3"
    ]
}