From patchwork Wed Dec 4 13:20:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2385 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 30CE661364 for ; Wed, 4 Dec 2019 14:21:20 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id C1549240012; Wed, 4 Dec 2019 13:21:19 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:20:57 +0100 Message-Id: <20191204132106.21582-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/10] [TEMP] include: linux: Update v4l2-controls.h 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-List-Received-Date: Wed, 04 Dec 2019 13:21:20 -0000 Import a temporary version of the v4l2-controls.h with the newly added definition of V4L2_CID_CAMERA_SENSOR_LOCATION control. This patch should be temporary applied waiting for the newly added control to land in the mainline kernel version. Signed-off-by: Jacopo Mondi --- include/linux/v4l2-controls.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/v4l2-controls.h b/include/linux/v4l2-controls.h index ef2ee5b796b4..d18a7749d3f1 100644 --- a/include/linux/v4l2-controls.h +++ b/include/linux/v4l2-controls.h @@ -910,6 +910,13 @@ enum v4l2_auto_focus_range { #define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32) #define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33) +#define V4L2_CID_CAMERA_SENSOR_LOCATION (V4L2_CID_CAMERA_CLASS_BASE+34) +#define V4L2_LOCATION_FRONT 0 +#define V4L2_LOCATION_BACK 1 +#define V4L2_LOCATION_EXTERNAL 2 + +#define V4L2_CID_CAMERA_SENSOR_ROTATION (V4L2_CID_CAMERA_CLASS_BASE+35) + /* FM Modulator class control IDs */ #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900) From patchwork Wed Dec 4 13:20:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2386 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C743961CC6 for ; Wed, 4 Dec 2019 14:21:20 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 5A6B524000F; Wed, 4 Dec 2019 13:21:20 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:20:58 +0100 Message-Id: <20191204132106.21582-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/10] libcamera: controls: Parse 'values' in gen-controls.py 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-List-Received-Date: Wed, 04 Dec 2019 13:21:21 -0000 In preparation to add libcamera Camera definition by re-using the control generation framework, augment the gen_controls.py script to support parsing the 'values' yaml tag and generate documentation and definition of possible values associated with a Control or a Property. Signed-off-by: Jacopo Mondi --- src/libcamera/gen-controls.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py index 940386cc68c8..ca843cb9b538 100755 --- a/src/libcamera/gen-controls.py +++ b/src/libcamera/gen-controls.py @@ -11,6 +11,24 @@ import string import sys import yaml +class ValueGenerator: + doc_template = string.Template('''/** + * \\def ${name} + * \\brief ${description} */''') + def_template = string.Template('''#define ${name} ${value}''') + + def __init__(self, value): + self.info = { + 'name': value['name'], + 'value': value['value'], + 'description': value['description'] + } + + def generate_doc(self): + return self.doc_template.substitute(self.info) + + def generate_def(self): + return self.def_template.substitute(self.info) def snake_case(s): return ''.join([c.isupper() and ('_' + c) or c for c in s]).strip('_') @@ -35,14 +53,23 @@ ${description} description[0] = '\\brief ' + description[0] description = '\n'.join([(line and ' * ' or ' *') + line for line in description]) + try: + values = ctrl['values'] + except KeyError: + values = "" + info = { 'name': name, 'type': ctrl['type'], 'description': description, 'id_name': id_name, + 'values' : values, } + for v in values: + ctrls_doc.append(ValueGenerator(v).generate_doc()) ctrls_doc.append(doc_template.substitute(info)) + ctrls_def.append(def_template.substitute(info)) ctrls_map.append('\t{ ' + id_name + ', &' + name + ' },') @@ -66,11 +93,19 @@ def generate_h(controls): ids.append('\t' + id_name + ' = ' + str(id_value) + ',') + try: + values = ctrl['values'] + except KeyError: + values = "" + info = { 'name': name, 'type': ctrl['type'], + 'values' : values, } + for v in values: + ctrls.append(ValueGenerator(v).generate_def()) ctrls.append(template.substitute(info)) id_value += 1 From patchwork Wed Dec 4 13:20:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2387 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 69E2261CC6 for ; Wed, 4 Dec 2019 14:21:21 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id F3B4724000F; Wed, 4 Dec 2019 13:21:20 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:20:59 +0100 Message-Id: <20191204132106.21582-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 03/10] libcamera: properties: Generate libcamera 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: , X-List-Received-Date: Wed, 04 Dec 2019 13:21:21 -0000 Re-use the Control generation infrastructure to generate libcamera properties. Introduce three additional files, one that enumerates the properties ids (include/libcamera/property_ids.h) and one the defines Control<> instances, one for each property (src/libcamera/property_ids.cpp) and provide properties definitions in src/libcamera/property_ids.yaml Signed-off-by: Jacopo Mondi --- include/libcamera/meson.build | 9 ++++++ include/libcamera/property_ids.h.in | 33 ++++++++++++++++++++++ src/libcamera/meson.build | 6 ++++ src/libcamera/property_ids.cpp.in | 43 +++++++++++++++++++++++++++++ src/libcamera/property_ids.yaml | 34 +++++++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 include/libcamera/property_ids.h.in create mode 100644 src/libcamera/property_ids.cpp.in create mode 100644 src/libcamera/property_ids.yaml diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 99abf0609940..0ec32ad84c96 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -31,7 +31,16 @@ control_ids_h = custom_target('control_ids_h', install : true, install_dir : join_paths('include', include_dir)) +property_ids_h = custom_target('property_ids_h', + input : files('../../src/libcamera/property_ids.yaml', 'property_ids.h.in'), + output : 'property_ids.h', + depend_files : gen_controls, + command : [gen_controls, '-o', '@OUTPUT@', '@INPUT@'], + install : true, + install_dir : join_paths('include', include_dir)) + libcamera_api += control_ids_h +libcamera_api += property_ids_h gen_header = files('gen-header.sh') diff --git a/include/libcamera/property_ids.h.in b/include/libcamera/property_ids.h.in new file mode 100644 index 000000000000..62799b3e8c54 --- /dev/null +++ b/include/libcamera/property_ids.h.in @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * property_ids.h : Property ID list + * + * This file is auto-generated. Do not edit. + */ + +#ifndef __LIBCAMERA_PROPERTY_IDS_H__ +#define __LIBCAMERA_PROPERTY_IDS_H__ + +#include + +#include + +namespace libcamera { + +namespace properties { + +enum { +${ids} +}; + +${controls} + +extern const ControlIdMap properties; + +} /* namespace propertiess */ + +} /* namespace libcamera */ + +#endif // __LIBCAMERA_PROPERTY_IDS_H__ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index c4f965bd7413..abd7046bd95d 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -73,7 +73,13 @@ control_ids_cpp = custom_target('control_ids_cpp', depend_files : gen_controls, command : [gen_controls, '-o', '@OUTPUT@', '@INPUT@']) +property_ids_cpp = custom_target('property_ids_cpp', + input : files('property_ids.yaml', 'property_ids.cpp.in'), + output : 'property_ids.cpp', + depend_files : gen_controls, + command : [gen_controls, '-o', '@OUTPUT@', '@INPUT@']) libcamera_sources += control_ids_cpp +libcamera_sources += property_ids_cpp libcamera_sources += control_ids_h gen_version = join_paths(meson.source_root(), 'utils', 'gen-version.sh') diff --git a/src/libcamera/property_ids.cpp.in b/src/libcamera/property_ids.cpp.in new file mode 100644 index 000000000000..635a56f7d647 --- /dev/null +++ b/src/libcamera/property_ids.cpp.in @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * property_ids.cpp : Property ID list + * + * This file is auto-generated. Do not edit. + */ + +#include + +/** + * \file property_ids.h + * \brief Camera property identifiers + */ + +namespace libcamera { + +/** + * \brief Namespace for libcamera controls + */ +namespace properties { + +${controls_doc} + +#ifndef __DOXYGEN__ +/* + * Keep the properties definitions hidden from doxygen as it incorrectly parses + * them as functions. + */ +${controls_def} +#endif + +/** + * \brief List of all supported libcamera properties + */ +extern const ControlIdMap properties { +${controls_map} +}; + +} /* namespace properties */ + +} /* namespace libcamera */ diff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml new file mode 100644 index 000000000000..61be2ab5298c --- /dev/null +++ b/src/libcamera/property_ids.yaml @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# Copyright (C) 2019, Google Inc. +# +%YAML 1.2 +--- +controls: + - Location: + type: int32_t + description: | + Camera mounting location + values: + - name: "CAMERA_LOCATION_FRONT" + value: 0 + description: | + The camera is mounted on the front side of the device, facing the + user + - name: "CAMERA_LOCATION_BACK" + value: 1 + description: | + The camera is mounted on the back facing side of the device + - name: "CAMERA_LOCATION_EXTERNAL" + value: 2 + description: | + The camera is attached to the device in a way that allows it to + move freely + + - Rotation: + type: int32_t + description: | + Camera mounting rotation expressed as counterclockwise rotation degrees + towards the axis perpendicular to the sensor surface and directed away + from it +... From patchwork Wed Dec 4 13:21:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2388 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0AFA061CE6 for ; Wed, 4 Dec 2019 14:21:22 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 8ADD7240008; Wed, 4 Dec 2019 13:21:21 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:21:00 +0100 Message-Id: <20191204132106.21582-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/10] libcamera: controls: Add default to ControlRange 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-List-Received-Date: Wed, 04 Dec 2019 13:21:22 -0000 Augment the the ControlRange class to store the control default value. This is particularly relevant for v4l2 controls used to create Camera properties, which are constructed using immutable video device properties, whose value won't change at runtime. Signed-off-by: Jacopo Mondi --- include/libcamera/controls.h | 7 ++++++- src/libcamera/controls.cpp | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index b1b73367e874..1e2f284eafeb 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -114,10 +114,12 @@ class ControlRange { public: explicit ControlRange(const ControlValue &min = 0, - const ControlValue &max = 0); + const ControlValue &max = 0, + const ControlValue &defaultValue = 0); const ControlValue &min() const { return min_; } const ControlValue &max() const { return max_; } + const ControlValue &defaultValue() const { return defaultValue_; } std::string toString() const; @@ -131,6 +133,9 @@ public: return !(*this == other); } +protected: + ControlValue defaultValue_; + private: ControlValue min_; ControlValue max_; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 7d8a0e97ee3a..bacba0fbf68a 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -353,14 +353,21 @@ Control::Control(unsigned int id, const char *name) * pipeline handlers to describe the controls they support. */ +/** + * \var ControlRange::defaultValue_ + * \brief The control default value + */ + /** * \brief Construct a ControlRange with minimum and maximum range parameters * \param[in] min The control minimum value * \param[in] max The control maximum value + * \param[in] defaultValue The control default value */ ControlRange::ControlRange(const ControlValue &min, - const ControlValue &max) - : min_(min), max_(max) + const ControlValue &max, + const ControlValue &defaultValue) + : defaultValue_(defaultValue), min_(min), max_(max) { } @@ -376,6 +383,12 @@ ControlRange::ControlRange(const ControlValue &min, * \return A ControlValue with the maximum value for the control */ +/** + * \fn ControlRange::defaultValue() + * \brief Retrieve the default value of the control + * \return A ControlValue with the default value for the control + */ + /** * \brief Provide a string representation of the ControlRange */ From patchwork Wed Dec 4 13:21:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2389 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A173F61CF3 for ; Wed, 4 Dec 2019 14:21:22 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 32D72240008; Wed, 4 Dec 2019 13:21:22 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:21:01 +0100 Message-Id: <20191204132106.21582-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/10] libcamera: v4l2_controls: Store default value 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-List-Received-Date: Wed, 04 Dec 2019 13:21:23 -0000 Store the default value for V4L2 controls as reported by the kernel when creating ControlRange instances using information coming from v4l2_query_ext_ctrl. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_controls.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index b6547a7c627c..7446c3880330 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -121,17 +121,20 @@ V4L2ControlRange::V4L2ControlRange(const struct v4l2_query_ext_ctrl &ctrl) switch (ctrl.type) { case V4L2_CTRL_TYPE_BOOLEAN: ControlRange::operator=(ControlRange(static_cast(ctrl.minimum), - static_cast(ctrl.maximum))); + static_cast(ctrl.maximum), + static_cast(ctrl.default_value))); break; case V4L2_CTRL_TYPE_INTEGER64: ControlRange::operator=(ControlRange(static_cast(ctrl.minimum), - static_cast(ctrl.maximum))); + static_cast(ctrl.maximum), + static_cast(ctrl.default_value))); break; default: ControlRange::operator=(ControlRange(static_cast(ctrl.minimum), - static_cast(ctrl.maximum))); + static_cast(ctrl.maximum), + static_cast(ctrl.default_value))); break; } } From patchwork Wed Dec 4 13:21:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2390 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A02161D00 for ; Wed, 4 Dec 2019 14:21:23 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id C3F90240008; Wed, 4 Dec 2019 13:21:22 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:21:02 +0100 Message-Id: <20191204132106.21582-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/10] libcamera: camera_sensor: Parse camera 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: , X-List-Received-Date: Wed, 04 Dec 2019 13:21:23 -0000 Parse and collect camera sensor properties by inspecting the associated v4l2 controls. Augment the CameraSensor class with an operation to retrieve the collected properties. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 46 ++++++++++++++++++++++++++- src/libcamera/include/camera_sensor.h | 6 +++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 86f0c772861b..af1e218fbd27 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -13,6 +13,8 @@ #include #include +#include + #include "formats.h" #include "utils.h" #include "v4l2_subdevice.h" @@ -47,7 +49,7 @@ LOG_DEFINE_CATEGORY(CameraSensor); * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity) + : entity_(entity), properties_(properties::properties) { subdev_ = new V4L2Subdevice(entity); } @@ -89,6 +91,42 @@ int CameraSensor::init() if (ret < 0) return ret; + /* Retrieve and store the camera sensor properties. */ + const ControlInfoMap &controls = subdev_->controls(); + int32_t propertyValue; + + /* Camera Location: default is front location. */ + const auto &locationControl = controls.find(V4L2_CID_CAMERA_SENSOR_LOCATION); + if (locationControl != controls.end()) { + int32_t v4l2Location = + locationControl->second.defaultValue().get(); + switch (v4l2Location) { + case V4L2_LOCATION_EXTERNAL: + propertyValue = CAMERA_LOCATION_EXTERNAL; + break; + case V4L2_LOCATION_FRONT: + propertyValue = CAMERA_LOCATION_FRONT; + break; + case V4L2_LOCATION_BACK: + propertyValue = CAMERA_LOCATION_BACK; + break; + default: + LOG(CameraSensor, Error) + << "Unsupported camera location: " << v4l2Location; + return -EINVAL; + } + } else { + propertyValue = CAMERA_LOCATION_FRONT; + } + properties_.set(properties::Location, propertyValue); + + /* Camera Rotation: default is 0 degrees. */ + propertyValue = 0; + const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); + if (rotationControl != controls.end()) + propertyValue = rotationControl->second.defaultValue().get(); + properties_.set(properties::Rotation, propertyValue); + /* Enumerate and cache media bus codes and sizes. */ const ImageFormats formats = subdev_->formats(0); if (formats.isEmpty()) { @@ -284,6 +322,12 @@ int CameraSensor::getControls(ControlList *ctrls) return subdev_->getControls(ctrls); } +/** + * \fn CameraSensor::properties() + * \brief Retrieve the camera sensor properties + * \return The list of camera sensor properties + */ + /** * \brief Write controls to the sensor * \param[in] ctrls The list of controls to write diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 1fb36a4f4951..68bfd1a4b8d6 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -10,6 +10,7 @@ #include #include +#include #include #include "log.h" @@ -17,7 +18,6 @@ namespace libcamera { class ControlInfoMap; -class ControlList; class MediaEntity; class V4L2Subdevice; @@ -47,6 +47,8 @@ public: int getControls(ControlList *ctrls); int setControls(ControlList *ctrls); + const ControlList &properties() const { return properties_; } + protected: std::string logPrefix() const; @@ -56,6 +58,8 @@ private: std::vector mbusCodes_; std::vector sizes_; + + ControlList properties_; }; } /* namespace libcamera */ From patchwork Wed Dec 4 13:21:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2391 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C03E661CF3 for ; Wed, 4 Dec 2019 14:21:23 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 4CBB7240002; Wed, 4 Dec 2019 13:21:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:21:03 +0100 Message-Id: <20191204132106.21582-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/10] libcamera: pipeline_handler: Add Camera 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: , X-List-Received-Date: Wed, 04 Dec 2019 13:21:24 -0000 Associate to each Camera a ControlList which contains the Camera properties as created by pipeline handlers in the pipeline handler's CameraData and provide an operation to retrieve them. Collect properties from the camera sensor in all pipeline handlers that support one (IPU3, RKISP1 and VIMC). Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/include/pipeline_handler.h | 2 ++ src/libcamera/pipeline/ipu3/ipu3.cpp | 3 +++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 3 +++ src/libcamera/pipeline/vimc.cpp | 4 ++++ src/libcamera/pipeline_handler.cpp | 19 +++++++++++++++++++ 5 files changed, 31 insertions(+) diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index a02e6e77dc9c..68761cc473c4 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -43,6 +43,7 @@ public: PipelineHandler *pipe_; std::list queuedRequests_; ControlInfoMap controlInfo_; + ControlList properties_; std::unique_ptr ipa_; private: @@ -64,6 +65,7 @@ public: void unlock(); const ControlInfoMap &controls(Camera *camera); + const ControlList &properties(Camera *camera); virtual CameraConfiguration *generateConfiguration(Camera *camera, const StreamRoles &roles) = 0; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 1c5fccf69428..536a63a30018 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -867,6 +867,9 @@ int PipelineHandlerIPU3::registerCameras() if (ret) continue; + /* Initialize the camera properties. */ + data->properties_ = cio2->sensor_->properties(); + /** * \todo Dynamically assign ImgU and output devices to each * stream and camera; as of now, limit support to two cameras diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 4a583a7a1d7e..e9a70755f4c5 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -888,6 +888,9 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) if (ret) return ret; + /* Initialize the camera properties. */ + data->properties_ = data->sensor_->properties(); + ret = data->loadIPA(); if (ret) return ret; diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 06664fed42e7..f043cf55889e 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -454,6 +454,10 @@ int VimcCameraData::init(MediaDevice *media) } controlInfo_ = std::move(ctrls); + + /* Initialize the camera properties. */ + properties_ = sensor_->properties(); + return 0; } diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 4349ca8957e4..a023fa1001f5 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -96,6 +96,14 @@ LOG_DEFINE_CATEGORY(Pipeline) * creating the camera, and shall not be modified afterwards. */ +/** + * \var CameraData::properties_ + * \brief The list of properties supported by the camera + * + * The list of camera properties shall be initialised by the pipeline handler + * when creating the camera, and shall not be modified afterwards. + */ + /** * \var CameraData::ipa_ * \brief The IPA module used by the camera @@ -244,6 +252,17 @@ const ControlInfoMap &PipelineHandler::controls(Camera *camera) return data->controlInfo_; } +/** + * \brief Retrieve the list of properties for a camera + * \param[in] camera The camera + * \return A ControlList of properties supported by \a camera + */ +const ControlList &PipelineHandler::properties(Camera *camera) +{ + CameraData *data = cameraData(camera); + return data->properties_; +} + /** * \fn PipelineHandler::generateConfiguration() * \brief Generate a camera configuration for a specified camera From patchwork Wed Dec 4 13:21:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2392 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 63D0E61CF3 for ; Wed, 4 Dec 2019 14:21:24 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id EAD40240002; Wed, 4 Dec 2019 13:21:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:21:04 +0100 Message-Id: <20191204132106.21582-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/10] libcamera: camera: Add Camera 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: , X-List-Received-Date: Wed, 04 Dec 2019 13:21:24 -0000 Add an operation to the Camera class to retrive the Camera properties registered by the pipeline handler. While at it, rewords the Camera::controls() operation documentation to specify that the camera control information are constant during the camera lifetime not their value, while the camera properties value are the actually static information. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/camera.h | 1 + src/libcamera/camera.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index ef6a37bb142c..72d5d62cc902 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -85,6 +85,7 @@ public: int release(); const ControlInfoMap &controls(); + const ControlList &properties(); const std::set &streams() const; std::unique_ptr generateConfiguration(const StreamRoles &roles); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index e810fb725d81..44031ffdb4b3 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -551,7 +551,8 @@ int Camera::release() /** * \brief Retrieve the list of controls supported by the camera * - * Camera controls remain constant through the lifetime of the camera. + * The list of controls supported by the camera and their associated + * constraints remain constant through the lifetime of the camera. * * \return A ControlInfoMap listing the controls supported by the camera */ @@ -560,6 +561,19 @@ const ControlInfoMap &Camera::controls() return pipe_->controls(this); } +/** + * \brief Retrieve the list of properties of the camera + * + * Camera properties are static information that remain constant through the + * lifetime of the camera. + * + * \return A ControlList of properties supported by the camera + */ +const ControlList &Camera::properties() +{ + return pipe_->properties(this); +} + /** * \brief Retrieve all the camera's stream information * From patchwork Wed Dec 4 13:21:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2393 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E0A8E61D19 for ; Wed, 4 Dec 2019 14:21:24 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 89A92240002; Wed, 4 Dec 2019 13:21:24 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:21:05 +0100 Message-Id: <20191204132106.21582-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/10] android: camera_device: Use Camera properties for static Metadata 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-List-Received-Date: Wed, 04 Dec 2019 13:21:25 -0000 Construct two example static metadata to be reported to the Android framework using the properties reported by the Camera. Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 065e0292e186..674867d313ac 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -7,6 +7,9 @@ #include "camera_device.h" +#include +#include + #include "log.h" #include "utils.h" @@ -97,6 +100,8 @@ camera_metadata_t *CameraDevice::getStaticMetadata() if (staticMetadata_) return staticMetadata_->get(); + const ControlList &properties = camera_->properties(); + /* * The here reported metadata are enough to implement a basic capture * example application, but a real camera implementation will require @@ -261,9 +266,15 @@ camera_metadata_t *CameraDevice::getStaticMetadata() staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE, &exposureTimeRange, 2); + /* + * Android reports orientation as clockwise correction, while Linux + * uses counter-clockwise. + */ int32_t orientation = 0; - staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, - &orientation, 1); + if (properties.contains(properties::Rotation)) + orientation = (360 - properties.get(properties::Rotation)) + % 360; + staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation, 1); std::vector testPatterModes = { ANDROID_SENSOR_TEST_PATTERN_MODE_OFF, @@ -310,6 +321,20 @@ camera_metadata_t *CameraDevice::getStaticMetadata() lensApertures.size()); uint8_t lensFacing = ANDROID_LENS_FACING_FRONT; + if (properties.contains(properties::Location)) { + int32_t location = properties.get(properties::Location); + switch (location) { + case CAMERA_LOCATION_FRONT: + lensFacing = ANDROID_LENS_FACING_FRONT; + break; + case CAMERA_LOCATION_BACK: + lensFacing = ANDROID_LENS_FACING_BACK; + break; + case CAMERA_LOCATION_EXTERNAL: + lensFacing = ANDROID_LENS_FACING_EXTERNAL; + break; + } + } staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1); std::vector lensFocalLenghts = { From patchwork Wed Dec 4 13:21:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2394 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 752B361D27 for ; Wed, 4 Dec 2019 14:21:25 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 1902124000E; Wed, 4 Dec 2019 13:21:24 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:21:06 +0100 Message-Id: <20191204132106.21582-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 10/10] DO NOT MERGE: Reports camera properties in cam 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-List-Received-Date: Wed, 04 Dec 2019 13:21:25 -0000 Running cam -l lists the camera properties registered by the pipeline handler. In example, for the VIMC pipelinehandler: Available cameras: 1: Integrated Camera: Integrated C 2: VIMC Sensor B Rotation: 0 Location: 0 Signed-off-by: Jacopo Mondi --- src/cam/main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index a38cca959aca..8d37754773af 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "capture.h" #include "event_loop.h" @@ -309,6 +310,16 @@ int CamApp::run() for (const std::shared_ptr &cam : cm_->cameras()) { std::cout << index << ": " << cam->name() << std::endl; index++; + + const ControlList &properties = cam->properties(); + for (const auto &prop : properties) { + auto it = properties::properties.find(prop.first); + if (it == properties::properties.end()) + continue; + + std::cout << it->second->name() << ": " << + prop.second.get() << "\n"; + } } }