From patchwork Mon May 29 13:30:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 18655 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 4C6A5C31E9 for ; Mon, 29 May 2023 13:30:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0FD83626F8; Mon, 29 May 2023 15:30:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1685367038; bh=8YHBaKjcZvwuirnItvvTdE8XwUSArdlfjIpU2Wun2jY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MFo3vM+bPZ/DgQP/dKg2jAs1aQyCRWPjOXLTvrD+80VszBLE+UlKMXgk1WuGV+MRs kVBYbh5ZyucBPLVDc9B4sDMj1PDm0Cm7EptgvpptFhIqMq+Os6Tgt43f07sfYI/4JY MCMWpcSL70y9QlV75+084hWR5Js/UnCXCVZCpy1gtmf3AYDZ6N4IUpcil6Ccac2ny1 3iZ30LsGULs2lCgufJlEmQ81Y2HP2pNg2ofwQGqoYxXpEIZSnkxzX6m03R35EwGW46 JlhcxuKnBePFaJQ0BmztdIa0mvHNfVX/abQ7+wsa5iLzICN9bQLFHc+65IbohYKVMT 8Lid5m7TdQK7w== Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 21F56626F5 for ; Mon, 29 May 2023 15:30:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20221208.gappssmtp.com header.i=@baylibre-com.20221208.gappssmtp.com header.b="KMck49G3"; dkim-atps=neutral Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5149aafef44so1933593a12.0 for ; Mon, 29 May 2023 06:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1685367035; x=1687959035; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=ym3UGKNp6yp5lkLkUD7+AV7dH+RffFgtYALuXpjaC/U=; b=KMck49G3gCn5dlpR7GvJZ7K5BhCCgWpFfyKyrcWUX8X+p/+jCxqgO/1l8jG/scqy7K sLMwqmD6J60GR1V1gsKJ1HIy6mBD6yffAMZq1myCNqz48oOnRgZbW0zO9d1CvcGHnd5V OGue23hSU+GlgTdLdax9w7Q8qtsgPKVN8qRmjLfXJ7mdPYHfknYPFAJ0NfJpupJ9S0jA X6ZOgJOB4O7uY89RHfKwLwV5FztXvWCx6/WRASbp/K/kEVLiGq+KOI9ZZ4KsFdzqpXya 3EKzx0GJIRKvBgOFZk0rLBcZKYAsRJqrmKxaoacg+MllAt5b1EMU/PEKsGKz3quNNt6P qavw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685367035; x=1687959035; 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=ym3UGKNp6yp5lkLkUD7+AV7dH+RffFgtYALuXpjaC/U=; b=aArGg3uQpdrXtb6Y6uhpmxMQUty8eeAbjYs7TjpmGKJlu/+IJdZGqSuCAB5M1HFHqp Nt/OISklnVZIgjjMS3XK/dlVP2mJ33BGdB4POPVLBUaOJShRpJvXjL/F3EXgjLf6hwRv 5ptRBT2tl6NUpmNuPaeTkiKD/CdahPzZIy3IxPDhbnASaj98iZRxopS6xt77XrmI2nbr JFNke/l9EsUPaib7Ew1YZDeGG8RT0ATRvJ60I8qMmTLeeycGZalvDDbKDi0mx0xM5Dim VeJHuZ5X+dTxLQuuV+LJGH1m5mp4rt+FhG94JeFH49vwPqMQdQ32FpxTlAZZn83sIIPz r/XQ== X-Gm-Message-State: AC+VfDwFv1ORRHWLHy6AwaPMYq/JC8tD39z0BQIbitYTKIXwHH4g7Zl/ vDvqAONH/t95mFH8rweJmkMrCQ== X-Google-Smtp-Source: ACHHUZ7UB6ugqHtO8n9JLRRfocEafvU2vAmdi4iyiNONcgHLWK55zXdK3kIF5B5OUFxWIJcS058FdQ== X-Received: by 2002:a50:fa8b:0:b0:514:7f39:aa80 with SMTP id w11-20020a50fa8b000000b005147f39aa80mr7540969edr.18.1685367035667; Mon, 29 May 2023 06:30:35 -0700 (PDT) Received: from [10.2.5.100] (abordeaux-655-1-129-86.w90-5.abo.wanadoo.fr. [90.5.10.86]) by smtp.gmail.com with ESMTPSA id u4-20020a05640207c400b00514a6d05de9sm156015edy.88.2023.05.29.06.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 06:30:35 -0700 (PDT) Date: Mon, 29 May 2023 15:30:17 +0200 MIME-Version: 1.0 Message-Id: <20230227-android-gralloc-v4-1-8cd3a44c5b70@baylibre.com> X-B4-Tracking: v=1; b=H4sIAOiodGQC/4XOwQ6CMAwG4FchOzsztgnqyfcwHrqtwBJkpiOLh PDuDo5Gw/Fv0+/vzCKSx8iuxcwIk48+DDnoQ8FsB0OL3LucmRRSCSlrDoOj4B1vCfo+WC40qtK d0NnqzPKVgYjcEAy2W++eEEekdfEibPx7q7o/cu58HANNW3Mq1+n/klTykitVicY2UFvhbgam3 hvCow1PtnJJ7hAyE0JejHYShNW/CLVDqEw4hQJ0oyE/80Usy/IB7xQBZFABAAA= To: libcamera-devel@lists.libcamera.org X-Mailer: b4 0.12.2 Subject: [libcamera-devel] [PATCH v4] 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 adds new dependencies on android's libhardware [1] and on libdl. [1] https://android.googlesource.com/platform/hardware/libhardware Fixes: c58662c5770e ("android: Introduce PlatformFrameBufferAllocator") Signed-off-by: Mattijs Korpershoek Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- * Tested on an integration branch in Android 12 (Using android.bp) * Build tested with meson setup build -Dandroid=enabled -Dandroid_platform=generic (Laurent, I dropped your reviewed-by since there are additional changes) --- Changes in v4: - Add missing meson.build change to link against libdl - Link to v3: https://lists.libcamera.org/pipermail/libcamera-devel/2023-May/037926.html 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: 76e1cb9f7176b4e7a935295d4e633ee24a0fef67 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..c92416bd3a6f 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 += [libdl, dependency('libhardware')] elif platform == 'cros' android_hal_sources += files(['cros_camera_buffer.cpp', 'cros_frame_buffer_allocator.cpp'])