From patchwork Thu Mar 2 08:27:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 18327 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 98A8BBF415 for ; Thu, 2 Mar 2023 08:27:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0BDEA626C5; Thu, 2 Mar 2023 09:27:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1677745667; bh=6+pjW13oltCtROF2IVRJffgTr9KVfE/2DAmq3nHKMh8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FMsXuMz+3kT00ZBhUIWe9OXgECMBichapIitAfzMZ0X7L9EzmTYlBVcM6aPzAORnm Z59CE21doapWWLpt1JVh/8Eo51iJw8MDAkrSo4lr57ZJXVHFtM7sXOTq9WkudRcXEU rlmkR0h+q3DIjJlTCL19bXT3uQdv7qprbf+gOZl+lZnuC8IetityWzYNySVMJHTKya QjoU7s1GwXHBwp2iT21tk7dySnDcsA3ooPNI0xGIWqGjbyVmNAszpVQWvT8cGlFY9m fQZ55NZpFIP1lV0P3wfDcwHoF+RaNV63FQXLDERhGFcLngpZ1NIPOxH3im5DACFNiB dgnlC8v+Upl+g== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C3846265E for ; Thu, 2 Mar 2023 09:27:45 +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="pm91A6Uu"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id o38-20020a05600c512600b003e8320d1c11so1653182wms.1 for ; Thu, 02 Mar 2023 00:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1677745665; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=EvYTol28kVRNmd8znfjquRAfwKGtksg+QahfMbqU5AA=; b=pm91A6UuhUNATqtKOQWwQtpQ8SYFlUUlb8GXEok7Ofqfxk6qQFS+A3XfVhkgeyXNfv JhUkM2Ng3mLKNapEpcDO7g4/rNAQGuPmJSgK2FYzGyD2kPsawIqQ190kI9hN+WY3M1Ac xsTP01/uPiDtMCMAY6tmez6pSBfUVNc6RK2RfwdHMrM9btYcCLX5NMla8rQ7MSsMLkNk pq9XX6TzsSM21RdyGNuChxEmigBV0zLgOWeTcFuGT9kZRQz2rkTpu5uk+Gbm8/gW5vCr hFcEQdlpAvOCJeAHCOD9OR/urihwfRkAlz7Ozh8VSUSNAaYmOTPlZ1Bk2mcA+0ulAOpL AVIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677745665; 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=EvYTol28kVRNmd8znfjquRAfwKGtksg+QahfMbqU5AA=; b=7iqF8+41R+FE++jq/pQ4oMGazlhs0rk60cr8mwJJoKsDFMElfZPrV7NEQW7VxrkngA rJuz8LNDJ7BJRANh4gw7L7CudjApR1abxF26B1GPNK4xdgCL3IdhwnOazQsJ/eAQ/bj/ zwAjUb5XACTttI9bRc3PifPPNrXAm93rlaIgEUBw0rLoo1UFLjV38JqAg/CBt9o7hmOa FHVPgaKQY6jwIr1LgT02YdepfL7lx0ev7tjkMlmQ2tmsHB5hEuy2y0HDGoS5A7ZDozbx iQuo8GCbJYCJijVLM6h+DYvckeCVK4GfEyReS3WmZMT+m5u/826iTBWP7m3iSLYiINsS q6uQ== X-Gm-Message-State: AO0yUKWQ0PsCtmEX+dZyZMZv23I/D5K0yzxoL7HTUqoB+/dsCcOwRuMj unRjdVdQuucFXSHGV+7seZhfy+YkSe4bEQtX X-Google-Smtp-Source: AK7set++LZe0ztunu3s3xsx1+JQo8ct1SpXm3Rxp7fCqhSC+atm7RxsbaKbJ0gQojZvvPo/1FJXEog== X-Received: by 2002:a05:600c:3d8e:b0:3eb:4cb5:e13 with SMTP id bi14-20020a05600c3d8e00b003eb4cb50e13mr7412218wmb.31.1677745664958; Thu, 02 Mar 2023 00:27:44 -0800 (PST) Received: from mkorpershoek-xps13.local ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id r8-20020a05600c458800b003df5be8987esm2253756wmo.20.2023.03.02.00.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 00:27:44 -0800 (PST) Date: Thu, 02 Mar 2023 09:27:43 +0100 MIME-Version: 1.0 Message-Id: <20230227-android-gralloc-v3-1-d3e0a4f4a60f@baylibre.com> X-B4-Tracking: v=1; b=H4sIAP5dAGQC/4WNzQ6CMBAGX4X0bE1/ENST72E8bNsFmiA1W9JIC O9uy9HEeJzdfDMri0geI7tWKyNMPvowZdCHitkBph65d5mZEkoLpVoOk6PgHe8JxjFYLmrU0p3 Q2ebM8spARG4IJjuU3RPijFQeL8LOv/fU/ZF58HEOtOzlJMv1dyRJLrnWjehsB60V7mZgGb0hP NrwZEWX1B+FygqhLqZ2CoStvxXbtn0An+ewrg0BAAA= To: libcamera-devel@lists.libcamera.org X-Mailer: b4 0.12.1 Subject: [libcamera-devel] [PATCH v3] 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 setup build -Dandroid=enabled -Dandroid_platform=generic --- Changes in v3: - Add missing meson.build change to define libhardware dependency - Link to v2: https://lists.libcamera.org/pipermail/libcamera-devel/2023-February/036884.html 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 +++++-- src/android/mm/meson.build | 1 + 2 files changed, 6 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 diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build index d40a3b0ba2eb..42eeab3bcfa9 100644 --- a/src/android/mm/meson.build +++ b/src/android/mm/meson.build @@ -4,6 +4,7 @@ platform = get_option('android_platform') if platform == 'generic' android_hal_sources += files(['generic_camera_buffer.cpp', 'generic_frame_buffer_allocator.cpp']) + android_deps += [dependency('libhardware')] elif platform == 'cros' android_hal_sources += files(['cros_camera_buffer.cpp', 'cros_frame_buffer_allocator.cpp'])