From patchwork Mon Nov 23 16:43:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10479 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 B3CC1BE08A for ; Mon, 23 Nov 2020 16:45:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F9E8633FF; Mon, 23 Nov 2020 17:45:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qgs43ZrY"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5510A633FA for ; Mon, 23 Nov 2020 17:45:00 +0100 (CET) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0115A102C; Mon, 23 Nov 2020 17:44:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1606149900; bh=YvzN9h1fhb+XlVT8Bx6Fp1ABG07k7SDvCkVDUIkrufg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qgs43ZrYUmJuVK6t+q6CuW9TycqGZa5ZAzNODChy13yw7uA3QfAjd1tVTgxi2nBhg 20WTFhosDzQmrej5XX4AswQAqid5lPJoPl/yJKt9MVeCQdapJzkH6VJq5z+4rEPppI Yw0laY5EBJ67kVpcZcR4Qiy4dTDxxa2XI4loSXBo= From: Kieran Bingham To: libcamera devel Date: Mon, 23 Nov 2020 16:43:19 +0000 Message-Id: <20201123164319.152742-9-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123164319.152742-1-kieran.bingham@ideasonboard.com> References: <20201123164319.152742-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 8/8] libcamera: camera_sensor: Parse configuration properties 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" Search for a camera_sensor.json configuration file specific to libcamera and parse it to see if any properties specific to this CameraSensor are applicable. Signed-off-by: Kieran Bingham --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 50 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index b9eba89f00fb..646f24a966bd 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -69,6 +69,7 @@ protected: private: int generateId(); + int parseConfigurationFile(); const MediaEntity *entity_; std::unique_ptr subdev_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 935de528c496..5a1bda483b9d 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -17,6 +17,7 @@ #include +#include "libcamera/internal/configuration.h" #include "libcamera/internal/formats.h" #include "libcamera/internal/sysfs.h" #include "libcamera/internal/utils.h" @@ -251,6 +252,12 @@ int CameraSensor::init() propertyValue = 0; properties_.set(properties::Rotation, propertyValue); + /* + * Properties are pulled from a configuration file on a best effort. + * If the file doesn't exist, or has no properties there is no failure. + */ + parseConfigurationFile(); + /* Enumerate, sort and cache media bus codes and sizes. */ formats_ = subdev_->formats(pad_); if (formats_.empty()) { @@ -584,4 +591,47 @@ int CameraSensor::generateId() return -EINVAL; } +int CameraSensor::parseConfigurationFile() +{ + Configuration c; + + int ret = c.open("camera_sensor.json"); + if (ret) { + LOG(CameraSensor, Debug) << "No configuration file available"; + return -ENODATA; + } + + /* Find properties based on the Camera model_ */ + /* Todo: Spilt parsing out for multiple paths. */ + + /* Find properties based around the Camera Sensor ID */ + json::iterator it = c.data().find(id_); + if (it == c.data().end()) + return -ENOENT; + + json j = *it; + it = j.find("properties"); + if (it == j.end()) + return -ENOENT; + + json deviceProperties = *it; + + for (auto &[key, value] : deviceProperties.items()) { + LOG(CameraSensor, Debug) << "Key: " << key << " Value: " << value; + + if (!value.is_number()) { + LOG(CameraSensor, Debug) << "Not a number: " << value; + continue; + } + + if (key == "Rotation") + properties_.set(properties::Rotation, value); + + if (key == "Location") + properties_.set(properties::Location, value); + } + + return 0; +} + } /* namespace libcamera */