{"id":2438,"url":"https://patchwork.libcamera.org/api/1.1/patches/2438/?format=json","web_url":"https://patchwork.libcamera.org/patch/2438/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20191218145001.22283-4-jacopo@jmondi.org>","date":"2019-12-18T14:49:57","name":"[libcamera-devel,RFC,3/7] libcamera: camera_sensor: Factorize out properties","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"a1d25c4bc5e08e4492e55a4fa85570f81642be22","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/1.1/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/2438/mbox/","series":[{"id":591,"url":"https://patchwork.libcamera.org/api/1.1/series/591/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=591","date":"2019-12-18T14:49:54","name":"Define and register 'sensor' and 'lens' properties","version":1,"mbox":"https://patchwork.libcamera.org/series/591/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2438/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2438/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DEB01605D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Dec 2019 15:47:53 +0100 (CET)","from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 6EF4160003;\n\tWed, 18 Dec 2019 14:47:53 +0000 (UTC)"],"X-Originating-IP":"93.34.114.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 18 Dec 2019 15:49:57 +0100","Message-Id":"<20191218145001.22283-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.24.0","In-Reply-To":"<20191218145001.22283-1-jacopo@jmondi.org>","References":"<20191218145001.22283-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC 3/7] libcamera: camera_sensor: Factorize out\n\tproperties","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>","X-List-Received-Date":"Wed, 18 Dec 2019 14:47:54 -0000"},"content":"Factorize CameraSensor properties initialization to a dedicated virtual\nfunction that dervied classes could subclass to register sensor-specific\nproperties.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/camera_sensor.cpp       | 94 ++++++++++++++++-----------\n src/libcamera/include/camera_sensor.h |  5 +-\n 2 files changed, 60 insertions(+), 39 deletions(-)","diff":"diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex d1c9c9bcd58f..9692895d9b7b 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -77,7 +77,7 @@ CameraSensor *CameraSensorFactory::create(const MediaEntity *entity)\n  * Once constructed the instance must be initialized with init().\n  */\n CameraSensor::CameraSensor(const MediaEntity *entity)\n-\t: entity_(entity), properties_(properties::properties)\n+\t: properties_(properties::properties), entity_(entity)\n {\n \tsubdev_ = new V4L2Subdevice(entity);\n }\n@@ -119,42 +119,6 @@ int CameraSensor::init()\n \tif (ret < 0)\n \t\treturn ret;\n \n-\t/* Retrieve and store the camera sensor properties. */\n-\tconst ControlInfoMap &controls = subdev_->controls();\n-\tint32_t propertyValue;\n-\n-\t/* Camera Location: default is front location. */\n-\tconst auto &locationControl = controls.find(V4L2_CID_CAMERA_SENSOR_LOCATION);\n-\tif (locationControl != controls.end()) {\n-\t\tint32_t v4l2Location =\n-\t\t\tlocationControl->second.def().get<int32_t>();\n-\t\tswitch (v4l2Location) {\n-\t\tcase V4L2_LOCATION_EXTERNAL:\n-\t\t\tpropertyValue = properties::CameraLocationExternal;\n-\t\t\tbreak;\n-\t\tcase V4L2_LOCATION_FRONT:\n-\t\t\tpropertyValue = properties::CameraLocationFront;\n-\t\t\tbreak;\n-\t\tcase V4L2_LOCATION_BACK:\n-\t\t\tpropertyValue = properties::CameraLocationBack;\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\tLOG(CameraSensor, Error)\n-\t\t\t\t<< \"Unsupported camera location: \" << v4l2Location;\n-\t\t\treturn -EINVAL;\n-\t\t}\n-\t} else {\n-\t\tpropertyValue = properties::CameraLocationFront;\n-\t}\n-\tproperties_.set(properties::Location, propertyValue);\n-\n-\t/* Camera Rotation: default is 0 degrees. */\n-\tpropertyValue = 0;\n-\tconst auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION);\n-\tif (rotationControl != controls.end())\n-\t\tpropertyValue = rotationControl->second.def().get<int32_t>();\n-\tproperties_.set(properties::Rotation, propertyValue);\n-\n \t/* Enumerate and cache media bus codes and sizes. */\n \tconst ImageFormats formats = subdev_->formats(0);\n \tif (formats.isEmpty()) {\n@@ -185,6 +149,62 @@ int CameraSensor::init()\n \tstd::sort(mbusCodes_.begin(), mbusCodes_.end());\n \tstd::sort(sizes_.begin(), sizes_.end());\n \n+\treturn initProperties(subdev_->controls());\n+}\n+\n+/**\n+ * \\brief Initialize the camera sensor properties\n+ * \\param[in] controlMap The map of control information provided by the sensor\n+ *\n+ * This method initializes the camera sensor properties, by inspecting the\n+ * control information reported by the sensor media entity in \\a controlMap.\n+ * For each supported standard V4L2 control reported by the sensor, a libcamera\n+ * property is created and registered in the list of properties supported by the\n+ * sensor.\n+ *\n+ * Derived classes are free to override this method to register sensor specific\n+ * properties as they like, by inspecting custom controls or by adding\n+ * properties with pre-defined values, and eventually call this base class\n+ * implementation to register standard ones.\n+ *\n+ * \\return 0 on success, a negative error code otherwise\n+ */\n+int CameraSensor::initProperties(const ControlInfoMap &controlMap)\n+{\n+\tint32_t propertyValue;\n+\n+\t/* Camera Location: default is front location. */\n+\tconst auto &locationControl = controlMap.find(V4L2_CID_CAMERA_SENSOR_LOCATION);\n+\tif (locationControl != controlMap.end()) {\n+\t\tint32_t v4l2Location =\n+\t\t\tlocationControl->second.def().get<int32_t>();\n+\t\tswitch (v4l2Location) {\n+\t\tcase V4L2_LOCATION_EXTERNAL:\n+\t\t\tpropertyValue = properties::CameraLocationExternal;\n+\t\t\tbreak;\n+\t\tcase V4L2_LOCATION_FRONT:\n+\t\t\tpropertyValue = properties::CameraLocationFront;\n+\t\t\tbreak;\n+\t\tcase V4L2_LOCATION_BACK:\n+\t\t\tpropertyValue = properties::CameraLocationBack;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tLOG(CameraSensor, Error)\n+\t\t\t\t<< \"Unsupported camera location: \" << v4l2Location;\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t} else {\n+\t\tpropertyValue = properties::CameraLocationFront;\n+\t}\n+\tproperties_.set(properties::Location, propertyValue);\n+\n+\t/* Camera Rotation: default is 0 degrees. */\n+\tpropertyValue = 0;\n+\tconst auto &rotationControl = controlMap.find(V4L2_CID_CAMERA_SENSOR_ROTATION);\n+\tif (rotationControl != controlMap.end())\n+\t\tpropertyValue = rotationControl->second.def().get<int32_t>();\n+\tproperties_.set(properties::Rotation, propertyValue);\n+\n \treturn 0;\n }\n \ndiff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\nindex 2c09b1bdb61b..43748a6c8535 100644\n--- a/src/libcamera/include/camera_sensor.h\n+++ b/src/libcamera/include/camera_sensor.h\n@@ -38,6 +38,7 @@ public:\n \tCameraSensor &operator=(const CameraSensor &) = delete;\n \n \tint init();\n+\tvirtual int initProperties(const ControlInfoMap &controlMap);\n \n \tconst MediaEntity *entity() const { return entity_; }\n \tconst std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }\n@@ -55,6 +56,8 @@ public:\n \tconst ControlList &properties() const { return properties_; }\n \n protected:\n+\tControlList properties_;\n+\n \tfriend class CameraSensorFactory;\n \texplicit CameraSensor(const MediaEntity *entity);\n \tstd::string logPrefix() const;\n@@ -65,8 +68,6 @@ private:\n \n \tstd::vector<unsigned int> mbusCodes_;\n \tstd::vector<Size> sizes_;\n-\n-\tControlList properties_;\n };\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","RFC","3/7"]}