Patch Detail
Show a patch.
GET /api/1.1/patches/11915/?format=api
{ "id": 11915, "url": "https://patchwork.libcamera.org/api/1.1/patches/11915/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11915/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210413145042.48185-5-jacopo@jmondi.org>", "date": "2021-04-13T14:50:41", "name": "[libcamera-devel,4/5] android: camera_device: Get properties from configuration", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "f5fb1b52064ce14dbc04e738a23ac97d5aca4274", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11915/mbox/", "series": [ { "id": 1919, "url": "https://patchwork.libcamera.org/api/1.1/series/1919/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1919", "date": "2021-04-13T14:50:37", "name": "android: Introduce Configuration file", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1919/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11915/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11915/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 56CFCBD22F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Apr 2021 14:50:14 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 17E6A602D1;\n\tTue, 13 Apr 2021 16:50:14 +0200 (CEST)", "from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EDD3F602D1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 16:50:11 +0200 (CEST)", "from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 83C172000F;\n\tTue, 13 Apr 2021 14:50:11 +0000 (UTC)" ], "X-Originating-IP": "93.34.118.233", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 13 Apr 2021 16:50:41 +0200", "Message-Id": "<20210413145042.48185-5-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.31.1", "In-Reply-To": "<20210413145042.48185-1-jacopo@jmondi.org>", "References": "<20210413145042.48185-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 4/5] android: camera_device: Get\n\tproperties from configuration", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Open the HAL configuration file in the Camera HAL manager and get\nthe camera properties for each created CameraDevice and initialize it\nwith them.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp | 56 +++++++++++++++++++++++++-----\n src/android/camera_device.h | 3 +-\n src/android/camera_hal_manager.cpp | 37 +++++++++++++++++++-\n src/android/camera_hal_manager.h | 3 ++\n 4 files changed, 89 insertions(+), 10 deletions(-)", "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 89044efa7ebe..2e93936fdb4b 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -6,6 +6,7 @@\n */\n \n #include \"camera_device.h\"\n+#include \"camera_hal_config.h\"\n #include \"camera_ops.h\"\n #include \"post_processor.h\"\n \n@@ -443,12 +444,25 @@ std::unique_ptr<CameraDevice> CameraDevice::create(unsigned int id,\n }\n \n /*\n- * Initialize the camera static information.\n+ * Initialize the camera static information retrieved from the\n+ * Camera::properties or from the cameraPros.\n+ *\n+ * cameraProps is optional for external camera devices and is defaulted to\n+ * nullptr.\n+ *\n * This method is called before the camera device is opened.\n */\n-int CameraDevice::initialize()\n+int CameraDevice::initialize(const CameraProps *cameraProps)\n {\n-\t/* Initialize orientation and facing side of the camera. */\n+\t/*\n+\t * Initialize orientation and facing side of the camera.\n+\t *\n+\t * If the libcamera::Camera provides those information as retrieved\n+\t * from firmware use them, otherwise fallback to values parsed from\n+\t * the configuration file. If the configuration file is not available\n+\t * the camera is external so its location and rotation can be safely\n+\t * defaulted.\n+\t */\n \tconst ControlList &properties = camera_->properties();\n \n \tif (properties.contains(properties::Location)) {\n@@ -464,12 +478,22 @@ int CameraDevice::initialize()\n \t\t\tfacing_ = CAMERA_FACING_EXTERNAL;\n \t\t\tbreak;\n \t\t}\n+\n+\t\tif (cameraProps && cameraProps->facing != -1 &&\n+\t\t facing_ != cameraProps->facing) {\n+\t\t\tLOG(HAL, Warning)\n+\t\t\t\t<< \"Camera location does not match\"\n+\t\t\t\t<< \" configuration file. Using \" << facing_;\n+\t\t}\n+\t} else if (cameraProps) {\n+\t\tif (cameraProps->facing == -1) {\n+\t\t\tLOG(HAL, Error)\n+\t\t\t\t<< \"Camera facing not in configuration file\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t\tfacing_ = cameraProps->facing;\n \t} else {\n-\t\t/*\n-\t\t * \\todo Retrieve the camera location from configuration file\n-\t\t * if not available from the library.\n-\t\t */\n-\t\tfacing_ = CAMERA_FACING_FRONT;\n+\t\tfacing_ = CAMERA_FACING_EXTERNAL;\n \t}\n \n \t/*\n@@ -483,8 +507,24 @@ int CameraDevice::initialize()\n \tif (properties.contains(properties::Rotation)) {\n \t\tint rotation = properties.get(properties::Rotation);\n \t\torientation_ = (360 - rotation) % 360;\n+\t\tif (cameraProps && cameraProps->rotation != -1 &&\n+\t\t orientation_ != cameraProps->rotation) {\n+\t\t\tLOG(HAL, Warning)\n+\t\t\t\t<< \"Camera orientation does not match\"\n+\t\t\t\t<< \" configuration file. Using \" << orientation_;\n+\t\t}\n+\t} else if (cameraProps) {\n+\t\tif (cameraProps->rotation == -1) {\n+\t\t\tLOG(HAL, Error)\n+\t\t\t\t<< \"Camera rotation not in configuration file\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t\torientation_ = cameraProps->rotation;\n+\t} else {\n+\t\torientation_ = 0;\n \t}\n \n+\t/* Acquire the camera and initialize available stream configurations. */\n \tint ret = camera_->acquire();\n \tif (ret) {\n \t\tLOG(HAL, Error) << \"Failed to temporarily acquire the camera\";\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 11bdfec8d587..598d89f1cff0 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -29,6 +29,7 @@\n #include \"camera_worker.h\"\n #include \"jpeg/encoder.h\"\n \n+class CameraProps;\n class CameraDevice : protected libcamera::Loggable\n {\n public:\n@@ -36,7 +37,7 @@ public:\n \t\t\t\t\t\t std::shared_ptr<libcamera::Camera> cam);\n \t~CameraDevice();\n \n-\tint initialize();\n+\tint initialize(const CameraProps *cameraProps = nullptr);\n \n \tint open(const hw_module_t *hardwareModule);\n \tvoid close();\ndiff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp\nindex bf3fcda75237..1defc3f9c5bd 100644\n--- a/src/android/camera_hal_manager.cpp\n+++ b/src/android/camera_hal_manager.cpp\n@@ -41,6 +41,16 @@ int CameraHalManager::init()\n {\n \tcameraManager_ = std::make_unique<CameraManager>();\n \n+\t/*\n+\t * Open and parse configuration file.\n+\t *\n+\t * If the configuration file is not available the HAL only supports\n+\t * external cameras. If it exists but it's not valid then error out.\n+\t */\n+\thalConfig_.open();\n+\tif (halConfig_.exists() && !halConfig_.valid())\n+\t\treturn -EINVAL;\n+\n \t/* Support camera hotplug. */\n \tcameraManager_->cameraAdded.connect(this, &CameraHalManager::cameraAdded);\n \tcameraManager_->cameraRemoved.connect(this, &CameraHalManager::cameraRemoved);\n@@ -100,6 +110,8 @@ void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam)\n \tauto iter = cameraIdsMap_.find(cam->id());\n \tif (iter != cameraIdsMap_.end()) {\n \t\tid = iter->second;\n+\t\tif (id >= firstExternalCameraId_)\n+\t\t\tisCameraExternal = true;\n \t} else {\n \t\tisCameraNew = true;\n \n@@ -117,7 +129,30 @@ void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam)\n \n \t/* Create a CameraDevice instance to wrap the libcamera Camera. */\n \tstd::unique_ptr<CameraDevice> camera = CameraDevice::create(id, cam);\n-\tint ret = camera->initialize();\n+\n+\t/*\n+\t * The configuration file must be valid for internal cameras.\n+\t * External cameras can be initialized without configuration file.\n+\t */\n+\tint ret = -EINVAL;\n+\tif (!halConfig_.exists()) {\n+\t\tif (isCameraExternal)\n+\t\t\tret = camera->initialize();\n+\t} else {\n+\t\t/*\n+\t\t * Get camera properties from the configuration file which\n+\t\t * exists and is valid.\n+\t\t *\n+\t\t * Internal cameras are required to have a corresponding entry\n+\t\t * in the configuration file. External cameras are not required\n+\t\t * to.\n+\t\t */\n+\t\tconst CameraProps *cameraProps = &halConfig_.cameraProps(cam->id());\n+\t\tif (cameraProps->valid)\n+\t\t\tret = camera->initialize(cameraProps);\n+\t\telse if (isCameraExternal)\n+\t\t\tret = camera->initialize();\n+\t}\n \tif (ret) {\n \t\tLOG(HAL, Error) << \"Failed to initialize camera: \" << cam->id();\n \t\treturn;\ndiff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h\nindex d9bf27989965..af1581da6579 100644\n--- a/src/android/camera_hal_manager.h\n+++ b/src/android/camera_hal_manager.h\n@@ -19,6 +19,8 @@\n \n #include <libcamera/camera_manager.h>\n \n+#include \"camera_hal_config.h\"\n+\n class CameraDevice;\n \n class CameraHalManager\n@@ -50,6 +52,7 @@ private:\n \tCameraDevice *cameraDeviceFromHalId(unsigned int id);\n \n \tstd::unique_ptr<libcamera::CameraManager> cameraManager_;\n+\tCameraHalConfig halConfig_;\n \n \tconst camera_module_callbacks_t *callbacks_;\n \tstd::vector<std::unique_ptr<CameraDevice>> cameras_;\n", "prefixes": [ "libcamera-devel", "4/5" ] }