From patchwork Mon Apr 5 04:04:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11837 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7D181BD695 for ; Mon, 5 Apr 2021 04:04:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1F3E56879D; Mon, 5 Apr 2021 06:04:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="YQgT3mq7"; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 86D8C68783 for ; Mon, 5 Apr 2021 06:04:35 +0200 (CEST) Received: by mail-pf1-x434.google.com with SMTP id c204so3624745pfc.4 for ; Sun, 04 Apr 2021 21:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=noIbd6m9dlc6MOMIGxny9qo6+n7hZZiKAguuGar6Bm0=; b=YQgT3mq7QnC6EtwwaoAZeIaOnb0Zs4IdQpX2bvYnsJyWMy9D4FvAsdpEBoYpJ+ew22 RgZqDi9T3dwBI9UpL+wIMtsJ4dqb4heATdFN80M6MOnCRtf09+KLj6lvaxSS/TI9WtmE mRTHbhuAKgjgjLjZBk8FR58R32dlweUnwpPNY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=noIbd6m9dlc6MOMIGxny9qo6+n7hZZiKAguuGar6Bm0=; b=dZia9xZ0BBexg4MTAUTBl+hp70ETFRvUONtoauOP902H4hM/SYF1G+L8iwuIJIIIMS QP/uXCH1GB7cPakc/LdZfBwScVzkUBpi9m2Db7cb41cLZeQxmQ7wE3HVswKAHPKYBwO8 DUGwKwzSUOc0u9NdNDiRzff2rXOO+fu+93h/94cJjgemBuDS0sziBDFNMGJ4aEnc0yvc QySYkD599QEgnMXc+y6k+JvHh5GwGCjjeeS004LQIvyKUK0tuLL5W6u5G/rd5Akn8CrZ 55HGXsA0DlwX/U8jS+T1tYnw/H5mZDPQpH7bD75Z9vFiJJZ+K6YPO+93pQ5br1ScnFjS xgnQ== X-Gm-Message-State: AOAM531vmsH892N0ni5ydhf1XVt0+kCqYvLANXtrjKPIEU/Jg/d410zk ZdAsJw99lVRmZN6qIgaPZcCkfqZ98rXjMA== X-Google-Smtp-Source: ABdhPJy4ssVN+inr35A8GWVBFMnAHVpZOh6omvt9PutG0vqyioYyHILW2qZSXSsjevUrPHIBCVueyQ== X-Received: by 2002:a62:e812:0:b029:1fa:e965:5564 with SMTP id c18-20020a62e8120000b02901fae9655564mr21506416pfi.68.1617595473977; Sun, 04 Apr 2021 21:04:33 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:2581:afba:2075:466f]) by smtp.gmail.com with ESMTPSA id bb16sm7543783pjb.17.2021.04.04.21.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Apr 2021 21:04:33 -0700 (PDT) From: Hirokazu Honda 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 not mapping a buffer X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" CameraBuffer always maps a buffer in constructor. This adds an option to not map a buffer within CameraBuffer. The option is useful for a caller to only validate a buffer and not have to map the buffer. Signed-off-by: Hirokazu Honda --- src/android/camera_buffer.h | 7 ++++--- src/android/mm/cros_camera_buffer.cpp | 17 +++++++++++++---- src/android/mm/generic_camera_buffer.cpp | 20 ++++++++++++-------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 7e8970b4..1fdb76a6 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -17,7 +17,7 @@ class CameraBuffer final : public libcamera::Extensible LIBCAMERA_DECLARE_PRIVATE(CameraBuffer) public: - CameraBuffer(buffer_handle_t camera3Buffer, int flags); + CameraBuffer(buffer_handle_t camera3Buffer, int flags, bool map = true); ~CameraBuffer(); bool isValid() const; @@ -31,8 +31,9 @@ public: }; #define PUBLIC_CAMERA_BUFFER_IMPLEMENTATION \ -CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) \ - : Extensible(new Private(this, camera3Buffer, flags)) \ + CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags, \ + bool map) \ + : Extensible(new Private(this, camera3Buffer, flags, map))\ { \ } \ CameraBuffer::~CameraBuffer() \ diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp index 1a4fd5d1..71e03766 100644 --- a/src/android/mm/cros_camera_buffer.cpp +++ b/src/android/mm/cros_camera_buffer.cpp @@ -21,7 +21,7 @@ class CameraBuffer::Private : public Extensible::Private public: Private(CameraBuffer *cameraBuffer, - buffer_handle_t camera3Buffer, int flags); + buffer_handle_t camera3Buffer, int flags, bool map); ~Private(); bool isValid() const { return valid_; } @@ -38,6 +38,7 @@ private: unsigned int numPlanes_; bool valid_; bool registered_; + bool map_; union { void *addr; android_ycbcr ycbcr; @@ -48,9 +49,10 @@ private: }; CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, - buffer_handle_t camera3Buffer, int flags) + buffer_handle_t camera3Buffer, int flags, + bool map) : Extensible::Private(cameraBuffer), handle_(camera3Buffer), - numPlanes_(0), valid_(false), registered_(false) + numPlanes_(0), valid_(false), registered_(false), map_(map) { bufferManager_ = cros::CameraBufferManager::GetInstance(); @@ -62,6 +64,13 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, registered_ = true; numPlanes_ = bufferManager_->GetNumPlanes(camera3Buffer); + + memset(&mem, 0, sizeof(mem)); + if (!map_) { + valid_ = true; + return; + } + switch (numPlanes_) { case 1: { ret = bufferManager_->Lock(handle_, 0, 0, 0, 0, 0, &mem.addr); @@ -91,7 +100,7 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, CameraBuffer::Private::~Private() { - if (valid_) + if (map_ && valid_) bufferManager_->Unlock(handle_); if (registered_) bufferManager_->Deregister(handle_); diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index 929e078a..8fa79889 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -21,7 +21,7 @@ class CameraBuffer::Private : public Extensible::Private, public: Private(CameraBuffer *cameraBuffer, - buffer_handle_t camera3Buffer, int flags); + buffer_handle_t camera3Buffer, int flags, bool map); ~Private(); unsigned int numPlanes() const; @@ -32,7 +32,8 @@ public: }; CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, - buffer_handle_t camera3Buffer, int flags) + buffer_handle_t camera3Buffer, + int flags, bool map) : Extensible::Private(cameraBuffer) { maps_.reserve(camera3Buffer->numFds); @@ -49,12 +50,15 @@ CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, break; } - void *address = mmap(nullptr, length, flags, MAP_SHARED, - camera3Buffer->data[i], 0); - if (address == MAP_FAILED) { - error_ = -errno; - LOG(HAL, Error) << "Failed to mmap plane"; - break; + void *address = nullptr; + if (map) { + mmap(nullptr, length, flags, MAP_SHARED, + camera3Buffer->data[i], 0); + if (address == MAP_FAILED) { + error_ = -errno; + LOG(HAL, Error) << "Failed to mmap plane"; + break; + } } maps_.emplace_back(static_cast(address),