From patchwork Tue Feb 28 14:15:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 18320 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 CC0A8BE080 for ; Tue, 28 Feb 2023 14:15:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 512886269B; Tue, 28 Feb 2023 15:15:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1677593754; bh=sH2oboiKC3GZs1NqkSGOTYXrPWvyQopl0ozF0QBoQsg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Bkv6rcM1ztl606YPiVyAfDs9NfYjLY5rP57bbsxpLpqJ4McbKcxXDW7A+5Jk6A+EJ h+0xZaqwAuTMgrQv5knGNgmkKM90y20h6muW0dDOWDQDk4IbfmpoBgCDLh+UoXpB19 jkYvlIcIA3NKEf7YuuVVg15PdbJ1/FIfppaUa+qdCexaqJt4TCaQE9fTmUxz4d89Ba 8pCMGb1cUCCwGn+mndwkbQmfRYPa5CuIQd8B3c3KuRNB+j6iQ4JVjqvOuZTj3Fg5GB 6XFNwqOrEDOwqCLDC8+teMmnoaAael9WXUYDdI9hhxV+pRzveI6DFQxlYRWFGtzJN8 RbQIBi5gqLkdg== Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5A3A962691 for ; Tue, 28 Feb 2023 15:15:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="NYZvhrbe"; dkim-atps=neutral Received: by mail-wm1-x32a.google.com with SMTP id bg16-20020a05600c3c9000b003eb34e21bdfso6206164wmb.0 for ; Tue, 28 Feb 2023 06:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=xfrgrBwq986v9yu5KBszNOyOzUhzZe5srlbJGY80N64=; b=NYZvhrbeoOSdnWxAXhylzOTXdCGOoMd4weM5WvfyJoD6yIBWLQPV1F94bYnpdyHWZv gTar8Z8/pfsCygp6cIjNnXTGCxkr4ARLJapCunuGhDhtufXa28Q4XHSy7GbUF5rojv1w LdQcodG/vHVRv7hhL/NjOc20wo2L/ke8UNXHCJvf/noAKQdmZYTdWa20ceqycab2ZNp7 RLc1jfZI60bcn1/3XexVNFHFcustvIga+7xt0/KUrdJPqnu35sPqydIvwXNwzQAJfXdz R8aSawAR/C+5u00pkd9THPFERxmMlj79Vze1dMsh6IkY3jj/aefZsUiKexC4uohuL5Kz ZWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xfrgrBwq986v9yu5KBszNOyOzUhzZe5srlbJGY80N64=; b=VIPsBPlxlAwdzVXBcJoOwcgInE88gJdI4Aq4Hb0Qe4VSH6Y84qfY7Iu5QIFLsJWzg0 bydufQDhIaSjPvkTg73QdIL4ewXQHnoNqPgVcRQY86PP9eXQvuwl58lP/+qMfYsBdcSZ N4vhBBIFIttDrHhramUN50M6R/T0gNHHFgFytGFmt96SDmbPfCBrW1K6hPL9jloE7I8m zU6LBRJaz7/dUiW22RIqGB8Ym0kWWGlmZJRJcNZT/d/HGBAA7hGWOv3GGfsNmAc7lkwK xEVb9qozQJNwHks+UXuMSKHaVrDIfIX2ivk2dTtAWme2nfXo4tuIY3DtvaKRIKct8HTG aLgw== X-Gm-Message-State: AO0yUKWMy7wE8zJT9/vJYSIgKVUdyHmRwaD/NeKoMJBnunFutL/sJgYP /5cElp6DGt3I9gbL8r5agFu30X1IJDEsOCTd X-Google-Smtp-Source: AK7set93jtgbMj4NSQLINVwZEnf/ffjSlDs3sTtMelvY7dRp49au4GRtZjqPtU6OsQFH4ruIbZ0WjA== X-Received: by 2002:a05:600c:1c96:b0:3eb:38b0:e757 with SMTP id k22-20020a05600c1c9600b003eb38b0e757mr2358787wms.10.1677593751860; Tue, 28 Feb 2023 06:15:51 -0800 (PST) Received: from mkorpershoek-xps13.local ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id n4-20020a7bcbc4000000b003dc3f3d77e3sm11872464wmi.7.2023.02.28.06.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 06:15:51 -0800 (PST) Date: Tue, 28 Feb 2023 15:15:46 +0100 MIME-Version: 1.0 Message-Id: <20230227-android-gralloc-v2-1-029b4d2a0c4d@baylibre.com> X-B4-Tracking: v=1; b=H4sIAJEM/mMC/3WNywqDMBBFf0WybkoerZau+h/FxSQZdUCTMhGpi P/e6L7Lcy+Hs4mMTJjFs9oE40KZUixgLpXwA8QeJYXCwihjlTGNhBg4UZA9wzgmL9UNrQ53DL5 +iGI5yCgdQ/TD4U2QZ+Tj+DB29D1T77bwQHlOvJ7lRR/r/8iipZbW1qrzHTRehZeDdSTHePVpE u2+7z+o3XHwygAAAA== To: libcamera-devel@lists.libcamera.org X-Mailer: b4 0.12.1 Subject: [libcamera-devel] [PATCH v2] android: mm: generic: use GRALLOC_HARDWARE_MODULE_ID 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: , X-Patchwork-Original-From: Mattijs Korpershoek via libcamera-devel From: Mattijs Korpershoek Reply-To: Mattijs Korpershoek Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" PlatformFrameBufferAllocator is an abstraction over gralloc. Right now hardwareModule_ points towards a CAMERA_HARDWARE_MODULE_ID. When gralloc_open() is called we observe: libcamera: DEBUG HAL camera3_hal.cpp:75 Open camera gpu0 libcamera: ERROR Camera camera.cpp:524 Camera in Configured state trying acquire() requiring state Available 01-23 14:14:04.742 370 416 E libcamera: FATAL HAL generic_frame_buffer_allocator.cpp:105 gralloc_open() failed: -87 Which is wrong, gralloc_open() is attempting to re-open the camera HAL, instead of the gralloc HAL. Point to a GRALLOC_HARDWARE_MODULE_ID instead so that we can request buffers from gralloc in android. Note: this add a new dependency on android's libhardware [1] [1] https://android.googlesource.com/platform/hardware/libhardware Fixes: c58662c5770e ("android: Introduce PlatformFrameBufferAllocator") Signed-off-by: Mattijs Korpershoek --- * Tested on an integration branch in Android 12 (Using android.bp) * Build tested with meson. --- Changes in v2: - Add dlclose() in PlatformFrameBufferAllocator destructor (Laurent) - Removed RFC, as linking against an AOSP lib for android is OK. - Link to v1: https://lists.libcamera.org/pipermail/libcamera-devel/2023-February/036857.html --- src/android/mm/generic_frame_buffer_allocator.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- base-commit: 58e0b6e18c425072a47594f42fc0b61801403aca change-id: 20230227-android-gralloc-04e31d5edc68 Best regards, diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp index 3750e1bf52a9..7ecef2c669df 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -5,6 +5,7 @@ * generic_camera_buffer.cpp - Allocate FrameBuffer using gralloc API */ +#include #include #include @@ -72,9 +73,10 @@ class PlatformFrameBufferAllocator::Private : public Extensible::Private public: Private(CameraDevice *const cameraDevice) : cameraDevice_(cameraDevice), - hardwareModule_(cameraDevice->camera3Device()->common.module), + hardwareModule_(nullptr), allocDevice_(nullptr) { + hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hardwareModule_); ASSERT(hardwareModule_); } @@ -85,7 +87,7 @@ public: private: const CameraDevice *const cameraDevice_; - struct hw_module_t *const hardwareModule_; + const struct hw_module_t *hardwareModule_; struct alloc_device_t *allocDevice_; }; @@ -93,6 +95,7 @@ PlatformFrameBufferAllocator::Private::~Private() { if (allocDevice_) gralloc_close(allocDevice_); + dlclose(hardwareModule_->dso); } std::unique_ptr