From patchwork Mon May 24 11:56:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12387 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 9F8B3C3201 for ; Mon, 24 May 2021 11:56:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 414A968921; Mon, 24 May 2021 13:56:50 +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="j5eVjBnC"; dkim-atps=neutral Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 883DD602B0 for ; Mon, 24 May 2021 13:56:48 +0200 (CEST) Received: by mail-pl1-x62e.google.com with SMTP id t21so14524313plo.2 for ; Mon, 24 May 2021 04:56:48 -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=lXE2YWM6EqATPCpKWMrkx6hm6hxJy4BMvVLRSweXb9o=; b=j5eVjBnCQb14Cytpe/XgP/ZmoYymRWR1CUVMl95DijWhxHjoez+6gp6M1z6qcbEy2u XSydt+468EVB/CIkNqQjgpq38hi2OW1MxK+iS3Cx4ter4bkUmw4yoCZm85q1qz+pnj7S sYno2dPIowQUZHHBvhD6CO0YLlxdrxRqYS/2k= 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=lXE2YWM6EqATPCpKWMrkx6hm6hxJy4BMvVLRSweXb9o=; b=Xey0HrEaot4zHnuCjygPWuDVd8Q55gjFBYx2zQ5CVF3dqv0gmDVIXeSY5uNSB19Eo8 OncE40+u8kk9xZ8BmsPoT+YRPlX6+V3stpIDeTcnnOq8MWAYu2fDzyRuaLhOEuuvH+Cl OdNFkEr0IU4k76ea/lzwr99lcOuUDLdMcFckeRHIJseHRIMNTD3agsm7SFVivoTRc8oU eE2uuVbzCEPcyVOGlrCaSOtQYbrGUlb1CDdNElP/f3yC/RsWYzRjY9RgjqhJR8OkPYTE FBzAu3kHL1YnN6MhfZN9876Fromo0pLKbeRFSSAfoCkeohEMpl3RN+WwAdV3sQoGPgth LAvA== X-Gm-Message-State: AOAM530wRzlT3xbio3aCrHqDAisr60iHIyMc/bHTPWc2EFuwyYj1lQ9i ZNv6eNXvCooKguyBjm7ODbd5i0FnLCk34w== X-Google-Smtp-Source: ABdhPJyVWqS/SKXQEo4ihXnWUHM5h65bP/4PhkGMsZTitf7bFSsWa+duaoQzwa4ik52Z+V12E7p4Iw== X-Received: by 2002:a17:90a:17a6:: with SMTP id q35mr24552485pja.118.1621857406933; Mon, 24 May 2021 04:56:46 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:7208:465c:c4e:2dc3]) by smtp.gmail.com with ESMTPSA id t19sm11149980pfg.70.2021.05.24.04.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 04:56:46 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 24 May 2021 20:56:39 +0900 Message-Id: <20210524115640.2334778-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog In-Reply-To: <20210524115640.2334778-1-hiroh@chromium.org> References: <20210524115640.2334778-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH RFC 1/2] android: Move ChromeOS specific Camera HAL calls to camera3_hal.cpp 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" ChromeOS specific Camera HAL calls are in android/cros directory. Moves them to android/camera3_hal.cpp by enclosing them with OS_CHROMEOS macro. Signed-off-by: Hirokazu Honda --- Found LOG macro conflict issues in libchrome and libcamera. See the error message. https://paste.debian.net/1198594/ I ask for comments, while I hack the conflict by undefining LOG of libcamera. --- src/android/camera3_hal.cpp | 27 +++++++++++++++++++++++++++ src/android/cros/camera3_hal.cpp | 21 --------------------- src/android/cros/meson.build | 17 ----------------- src/android/meson.build | 3 +-- 4 files changed, 28 insertions(+), 40 deletions(-) delete mode 100644 src/android/cros/camera3_hal.cpp delete mode 100644 src/android/cros/meson.build -- 2.31.1.818.g46aad6cb9e-goog diff --git a/src/android/camera3_hal.cpp b/src/android/camera3_hal.cpp index 08773d33..f2d4799f 100644 --- a/src/android/camera3_hal.cpp +++ b/src/android/camera3_hal.cpp @@ -5,6 +5,14 @@ * camera3_hal.cpp - Android Camera HALv3 module */ +#if defined(OS_CHROMEOS) +#include +/* HACK. LOG is defined in logging.h in chrome. It conflicts LOG macro in + * libcamera. + */ +#undef LOG +#endif + #include #include "libcamera/internal/log.h" @@ -115,3 +123,22 @@ camera_module_t HAL_MODULE_INFO_SYM = { .init = hal_init, .reserved = {}, }; + +#if defined(OS_CHROMEOS) +/*------------------------------------------------------------------------------ + * ChromeOS specific Camera HAL callbacks + */ + +static void set_up(cros::CameraMojoChannelManagerToken *token) +{ +} + +static void tear_down() +{ +} + +cros::cros_camera_hal_t CROS_CAMERA_EXPORT CROS_CAMERA_HAL_INFO_SYM = { + .set_up = set_up, + .tear_down = tear_down +}; +#endif diff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp deleted file mode 100644 index 31ad36ac..00000000 --- a/src/android/cros/camera3_hal.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2021, Google Inc. - * - * camera3_hal.cpp - cros-specific components of Android Camera HALv3 module - */ - -#include - -static void set_up(cros::CameraMojoChannelManagerToken *token) -{ -} - -static void tear_down() -{ -} - -cros::cros_camera_hal_t CROS_CAMERA_EXPORT CROS_CAMERA_HAL_INFO_SYM = { - .set_up = set_up, - .tear_down = tear_down -}; diff --git a/src/android/cros/meson.build b/src/android/cros/meson.build deleted file mode 100644 index 4aab0f20..00000000 --- a/src/android/cros/meson.build +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: CC0-1.0 - -if get_option('android_platform') != 'cros' - subdir_done() -endif - -cros_hal_info_sources = files([ - 'camera3_hal.cpp', -]) - -cros_hal_info = static_library('cros_hal_info', - cros_hal_info_sources, - dependencies : dependency('libcros_camera'), - c_args : '-Wno-shadow', - include_directories : android_includes) - -libcamera_objects += cros_hal_info.extract_objects('camera3_hal.cpp') diff --git a/src/android/meson.build b/src/android/meson.build index 2be20c97..84144f33 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -37,10 +37,9 @@ android_deps += [libyuv_dep] if get_option('android_platform') == 'cros' libcamera_cpp_args += [ '-DOS_CHROMEOS'] + android_deps += [dependency('libcros_camera')] endif -subdir('cros') - android_hal_sources = files([ 'camera3_hal.cpp', 'camera_hal_manager.cpp', From patchwork Mon May 24 11:56:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12388 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 D0564C3201 for ; Mon, 24 May 2021 11:56:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8EFC368919; Mon, 24 May 2021 13:56:52 +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="ClDA3GBt"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6596668923 for ; Mon, 24 May 2021 13:56:50 +0200 (CEST) Received: by mail-pj1-x1034.google.com with SMTP id gb21-20020a17090b0615b029015d1a863a91so11113156pjb.2 for ; Mon, 24 May 2021 04:56:50 -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=0s2Nd4Ix/jMmEzfVpR+RpQh2atUP4LM4KsrXuCpddx4=; b=ClDA3GBt6uY5U8J8Y4z7uLJ0Pbq41rWHtNQfD0JygsS8+ECc+SqB7J6hvt4kyX+iEu s1fLTW4eBNP+HynyNH8vfpPQitvSqK038LEbNG1T1jszpjTF9hKr7eXi0+Gwc7EmlkAO wWrHKE5udmlC/ZcBZ6si+9HqfFriOsEUC689I= 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=0s2Nd4Ix/jMmEzfVpR+RpQh2atUP4LM4KsrXuCpddx4=; b=AKf2CiLXtWyysPXHggWR29vGKJrNr/USd7hzbhw05UwSQdc6bryPDTnEw+kVaLUZXh 0sTQYyK1AU2dEDRGWvVP4OgNPE1gLFPyTRH3v0o8OEkDEoPtJE3LTv0n5OWULNv/fXTe xgca7+IUs9aQ1NdsT+D5tlL75llNNAKa+5oOadTmpAwvWWbPudSRTW4mY0uWb5tNiLoS JpQlm0qIQHvAN0SDHH7GD1+biDTCEIgFKWfZIGKVKQuZvpPD+qkfp7msGEL0OASLGzxa lA43x4NE4oKOea5pcmq1qDiQL7fIOsENgMUb1XL3A9PKnhxYbMutSEvM63qX4Ybt6Yv2 mZTw== X-Gm-Message-State: AOAM531LVAncMI1x/yGSgmvHS3W+UBY8JiI5uG4Hh19P/L/c9jZybdsc nLBOe4UH7ZmdSWdai+IXdWCfzrfKMcB8rA== X-Google-Smtp-Source: ABdhPJyhSTCw6V8erjvA5ciEXQys7IFBbEe5qAKXDKpVxr051RN1LX/6qjwgE0jjrnFPhwufcHxgjA== X-Received: by 2002:a17:90b:3b92:: with SMTP id pc18mr24335478pjb.218.1621857408594; Mon, 24 May 2021 04:56:48 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:7208:465c:c4e:2dc3]) by smtp.gmail.com with ESMTPSA id t19sm11149980pfg.70.2021.05.24.04.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 04:56:48 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 24 May 2021 20:56:40 +0900 Message-Id: <20210524115640.2334778-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog In-Reply-To: <20210524115640.2334778-1-hiroh@chromium.org> References: <20210524115640.2334778-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH RFC 2/2] android: CameraHalManager: Create a static object dynamically 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" Originally CameraHalManager is created in the libcamera start up and destroyed in the libcamera termination. However, CameraHalManager destructor can access other static objects that has been destroyed. Avoid this issue by destroying CameraHalManager when tear_down() is called in ChromeOS or leaking it in other platforms. Signed-off-by: Hirokazu Honda --- src/android/camera3_hal.cpp | 14 +++++++------- src/android/camera_hal_manager.cpp | 7 +++++++ src/android/camera_hal_manager.h | 5 ++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/android/camera3_hal.cpp b/src/android/camera3_hal.cpp index f2d4799f..59d51ed5 100644 --- a/src/android/camera3_hal.cpp +++ b/src/android/camera3_hal.cpp @@ -24,25 +24,23 @@ using namespace libcamera; LOG_DEFINE_CATEGORY(HAL) -static CameraHalManager cameraManager; - /*------------------------------------------------------------------------------ * Android Camera HAL callbacks */ static int hal_get_number_of_cameras() { - return cameraManager.numCameras(); + return CameraHalManager::instance()->numCameras(); } static int hal_get_camera_info(int id, struct camera_info *info) { - return cameraManager.getCameraInfo(id, info); + return CameraHalManager::instance()->getCameraInfo(id, info); } static int hal_set_callbacks(const camera_module_callbacks_t *callbacks) { - cameraManager.setCallbacks(callbacks); + CameraHalManager::instance()->setCallbacks(callbacks); return 0; } @@ -70,7 +68,7 @@ static int hal_init() { LOG(HAL, Info) << "Initialising Android camera HAL"; - cameraManager.init(); + CameraHalManager::instance()->init(); return 0; } @@ -85,7 +83,8 @@ static int hal_dev_open(const hw_module_t *module, const char *name, LOG(HAL, Debug) << "Open camera " << name; int id = atoi(name); - auto [camera, ret] = cameraManager.open(id, module); + + auto [camera, ret] = CameraHalManager::instance()->open(id, module); if (!camera) { LOG(HAL, Error) << "Failed to open camera module '" << id << "'"; @@ -135,6 +134,7 @@ static void set_up(cros::CameraMojoChannelManagerToken *token) static void tear_down() { + delete CameraHalManager::instance(); } cros::cros_camera_hal_t CROS_CAMERA_EXPORT CROS_CAMERA_HAL_INFO_SYM = { diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index bf3fcda7..387b600d 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -37,6 +37,13 @@ CameraHalManager::CameraHalManager() /* CameraManager calls stop() in the destructor. */ CameraHalManager::~CameraHalManager() = default; +/* static */ +CameraHalManager *CameraHalManager::instance() +{ + static CameraHalManager *cameraHalManager = new CameraHalManager; + return cameraHalManager; +} + int CameraHalManager::init() { cameraManager_ = std::make_unique(); diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index d9bf2798..9b43afc4 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -24,9 +24,10 @@ class CameraDevice; class CameraHalManager { public: - CameraHalManager(); ~CameraHalManager(); + static CameraHalManager *instance(); + int init(); std::tuple @@ -42,6 +43,8 @@ private: static constexpr unsigned int firstExternalCameraId_ = 1000; + CameraHalManager(); + static int32_t cameraLocation(const libcamera::Camera *cam); void cameraAdded(std::shared_ptr cam);