{"id":11837,"url":"https://patchwork.libcamera.org/api/1.1/patches/11837/?format=json","web_url":"https://patchwork.libcamera.org/patch/11837/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20210405040424.1929737-2-hiroh@chromium.org>","date":"2021-04-05T04:04:23","name":"[libcamera-devel,1/2] android: CameraBuffer: Add option of not mapping a buffer","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c7eb76c9b5abf8973655f7178782a4644a81c8fa","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11837/mbox/","series":[{"id":1892,"url":"https://patchwork.libcamera.org/api/1.1/series/1892/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1892","date":"2021-04-05T04:04:22","name":"Check a buffer validness by CameraBuffer::IsValid()","version":1,"mbox":"https://patchwork.libcamera.org/series/1892/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11837/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11837/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 7D181BD695\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  5 Apr 2021 04:04:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1F3E56879D;\n\tMon,  5 Apr 2021 06:04:37 +0200 (CEST)","from mail-pf1-x434.google.com (mail-pf1-x434.google.com\n\t[IPv6:2607:f8b0:4864:20::434])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 86D8C68783\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Apr 2021 06:04:35 +0200 (CEST)","by mail-pf1-x434.google.com with SMTP id c204so3624745pfc.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 04 Apr 2021 21:04:35 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:2581:afba:2075:466f])\n\tby smtp.gmail.com with ESMTPSA id\n\tbb16sm7543783pjb.17.2021.04.04.21.04.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 04 Apr 2021 21:04: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=\"YQgT3mq7\"; 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=noIbd6m9dlc6MOMIGxny9qo6+n7hZZiKAguuGar6Bm0=;\n\tb=YQgT3mq7QnC6EtwwaoAZeIaOnb0Zs4IdQpX2bvYnsJyWMy9D4FvAsdpEBoYpJ+ew22\n\tRgZqDi9T3dwBI9UpL+wIMtsJ4dqb4heATdFN80M6MOnCRtf09+KLj6lvaxSS/TI9WtmE\n\tmRTHbhuAKgjgjLjZBk8FR58R32dlweUnwpPNY=","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=noIbd6m9dlc6MOMIGxny9qo6+n7hZZiKAguuGar6Bm0=;\n\tb=dZia9xZ0BBexg4MTAUTBl+hp70ETFRvUONtoauOP902H4hM/SYF1G+L8iwuIJIIIMS\n\tQP/uXCH1GB7cPakc/LdZfBwScVzkUBpi9m2Db7cb41cLZeQxmQ7wE3HVswKAHPKYBwO8\n\tDUGwKwzSUOc0u9NdNDiRzff2rXOO+fu+93h/94cJjgemBuDS0sziBDFNMGJ4aEnc0yvc\n\tQySYkD599QEgnMXc+y6k+JvHh5GwGCjjeeS004LQIvyKUK0tuLL5W6u5G/rd5Akn8CrZ\n\t55HGXsA0DlwX/U8jS+T1tYnw/H5mZDPQpH7bD75Z9vFiJJZ+K6YPO+93pQ5br1ScnFjS\n\txgnQ==","X-Gm-Message-State":"AOAM531vmsH892N0ni5ydhf1XVt0+kCqYvLANXtrjKPIEU/Jg/d410zk\n\tZdAsJw99lVRmZN6qIgaPZcCkfqZ98rXjMA==","X-Google-Smtp-Source":"ABdhPJy4ssVN+inr35A8GWVBFMnAHVpZOh6omvt9PutG0vqyioYyHILW2qZSXSsjevUrPHIBCVueyQ==","X-Received":"by 2002:a62:e812:0:b029:1fa:e965:5564 with SMTP id\n\tc18-20020a62e8120000b02901fae9655564mr21506416pfi.68.1617595473977; \n\tSun, 04 Apr 2021 21:04:33 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  5 Apr 2021 13:04:23 +0900","Message-Id":"<20210405040424.1929737-2-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.0.208.g409f899ff0-goog","In-Reply-To":"<20210405040424.1929737-1-hiroh@chromium.org>","References":"<20210405040424.1929737-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 1/2] android: CameraBuffer: Add option of\n\tnot mapping a buffer","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>","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":"CameraBuffer always maps a buffer in constructor. This adds an\noption to not map a buffer within CameraBuffer. The option is\nuseful for a caller to only validate a buffer and not have to\nmap the buffer.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/camera_buffer.h              |  7 ++++---\n src/android/mm/cros_camera_buffer.cpp    | 17 +++++++++++++----\n src/android/mm/generic_camera_buffer.cpp | 20 ++++++++++++--------\n 3 files changed, 29 insertions(+), 15 deletions(-)","diff":"diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h\nindex 7e8970b4..1fdb76a6 100644\n--- a/src/android/camera_buffer.h\n+++ b/src/android/camera_buffer.h\n@@ -17,7 +17,7 @@ class CameraBuffer final : public libcamera::Extensible\n \tLIBCAMERA_DECLARE_PRIVATE(CameraBuffer)\n \n public:\n-\tCameraBuffer(buffer_handle_t camera3Buffer, int flags);\n+\tCameraBuffer(buffer_handle_t camera3Buffer, int flags, bool map = true);\n \t~CameraBuffer();\n \n \tbool isValid() const;\n@@ -31,8 +31,9 @@ public:\n };\n \n #define PUBLIC_CAMERA_BUFFER_IMPLEMENTATION\t\t\t\t\\\n-CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags)\t\\\n-\t: Extensible(new Private(this, camera3Buffer, flags))\t\t\\\n+\tCameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags, \\\n+\t\t\t\t   bool map)\t\t\t\t\\\n+\t\t: Extensible(new Private(this, camera3Buffer, flags, map))\\\n {\t\t\t\t\t\t\t\t\t\\\n }\t\t\t\t\t\t\t\t\t\\\n CameraBuffer::~CameraBuffer()\t\t\t\t\t\t\\\ndiff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp\nindex 1a4fd5d1..71e03766 100644\n--- a/src/android/mm/cros_camera_buffer.cpp\n+++ b/src/android/mm/cros_camera_buffer.cpp\n@@ -21,7 +21,7 @@ class CameraBuffer::Private : public Extensible::Private\n \n public:\n \tPrivate(CameraBuffer *cameraBuffer,\n-\t\tbuffer_handle_t camera3Buffer, int flags);\n+\t\tbuffer_handle_t camera3Buffer, int flags, bool map);\n \t~Private();\n \n \tbool isValid() const { return valid_; }\n@@ -38,6 +38,7 @@ private:\n \tunsigned int numPlanes_;\n \tbool valid_;\n \tbool registered_;\n+\tbool map_;\n \tunion {\n \t\tvoid *addr;\n \t\tandroid_ycbcr ycbcr;\n@@ -48,9 +49,10 @@ private:\n };\n \n CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,\n-\t\t\t       buffer_handle_t camera3Buffer, int flags)\n+\t\t\t       buffer_handle_t camera3Buffer, int flags,\n+\t\t\t       bool map)\n \t: Extensible::Private(cameraBuffer), handle_(camera3Buffer),\n-\t  numPlanes_(0), valid_(false), registered_(false)\n+\t  numPlanes_(0), valid_(false), registered_(false), map_(map)\n {\n \tbufferManager_ = cros::CameraBufferManager::GetInstance();\n \n@@ -62,6 +64,13 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,\n \n \tregistered_ = true;\n \tnumPlanes_ = bufferManager_->GetNumPlanes(camera3Buffer);\n+\n+\tmemset(&mem, 0, sizeof(mem));\n+\tif (!map_) {\n+\t\tvalid_ = true;\n+\t\treturn;\n+\t}\n+\n \tswitch (numPlanes_) {\n \tcase 1: {\n \t\tret = bufferManager_->Lock(handle_, 0, 0, 0, 0, 0, &mem.addr);\n@@ -91,7 +100,7 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,\n \n CameraBuffer::Private::~Private()\n {\n-\tif (valid_)\n+\tif (map_ && valid_)\n \t\tbufferManager_->Unlock(handle_);\n \tif (registered_)\n \t\tbufferManager_->Deregister(handle_);\ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nindex 929e078a..8fa79889 100644\n--- a/src/android/mm/generic_camera_buffer.cpp\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -21,7 +21,7 @@ class CameraBuffer::Private : public Extensible::Private,\n \n public:\n \tPrivate(CameraBuffer *cameraBuffer,\n-\t\tbuffer_handle_t camera3Buffer, int flags);\n+\t\tbuffer_handle_t camera3Buffer, int flags, bool map);\n \t~Private();\n \n \tunsigned int numPlanes() const;\n@@ -32,7 +32,8 @@ public:\n };\n \n CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,\n-\t\t\t       buffer_handle_t camera3Buffer, int flags)\n+\t\t\t       buffer_handle_t camera3Buffer,\n+\t\t\t       int flags, bool map)\n \t: Extensible::Private(cameraBuffer)\n {\n \tmaps_.reserve(camera3Buffer->numFds);\n@@ -49,12 +50,15 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer,\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\tvoid *address = nullptr;\n+\t\tif (map) {\n+\t\t\tmmap(nullptr, length, flags, MAP_SHARED,\n+\t\t\t     camera3Buffer->data[i], 0);\n+\t\t\tif (address == MAP_FAILED) {\n+\t\t\t\terror_ = -errno;\n+\t\t\t\tLOG(HAL, Error) << \"Failed to mmap plane\";\n+\t\t\t\tbreak;\n+\t\t\t}\n \t\t}\n \n \t\tmaps_.emplace_back(static_cast<uint8_t *>(address),\n","prefixes":["libcamera-devel","1/2"]}