[{"id":3177,"web_url":"https://patchwork.libcamera.org/comment/3177/","msgid":"<20191204160506.GE7811@pendragon.ideasonboard.com>","date":"2019-12-04T16:05:06","subject":"Re: [libcamera-devel] [PATCH 06/10] libcamera: camera_sensor: Parse\n\tcamera properties","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Dec 04, 2019 at 02:21:02PM +0100, Jacopo Mondi wrote:\n> Parse and collect camera sensor properties by inspecting the associated\n> v4l2 controls.\n> \n> Augment the CameraSensor class with an operation to retrieve the\n> collected properties.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/camera_sensor.cpp       | 46 ++++++++++++++++++++++++++-\n>  src/libcamera/include/camera_sensor.h |  6 +++-\n>  2 files changed, 50 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 86f0c772861b..af1e218fbd27 100644\n> --- a/src/libcamera/camera_sensor.cpp\n> +++ b/src/libcamera/camera_sensor.cpp\n> @@ -13,6 +13,8 @@\n>  #include <limits.h>\n>  #include <math.h>\n>  \n> +#include <libcamera/property_ids.h>\n> +\n>  #include \"formats.h\"\n>  #include \"utils.h\"\n>  #include \"v4l2_subdevice.h\"\n> @@ -47,7 +49,7 @@ LOG_DEFINE_CATEGORY(CameraSensor);\n>   * Once constructed the instance must be initialized with init().\n>   */\n>  CameraSensor::CameraSensor(const MediaEntity *entity)\n> -\t: entity_(entity)\n> +\t: entity_(entity), properties_(properties::properties)\n>  {\n>  \tsubdev_ = new V4L2Subdevice(entity);\n>  }\n> @@ -89,6 +91,42 @@ 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.defaultValue().get<int32_t>();\n> +\t\tswitch (v4l2Location) {\n> +\t\tcase V4L2_LOCATION_EXTERNAL:\n> +\t\t\tpropertyValue = CAMERA_LOCATION_EXTERNAL;\n> +\t\t\tbreak;\n> +\t\tcase V4L2_LOCATION_FRONT:\n> +\t\t\tpropertyValue = CAMERA_LOCATION_FRONT;\n> +\t\t\tbreak;\n> +\t\tcase V4L2_LOCATION_BACK:\n> +\t\t\tpropertyValue = CAMERA_LOCATION_BACK;\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 = CAMERA_LOCATION_FRONT;\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.defaultValue().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> @@ -284,6 +322,12 @@ int CameraSensor::getControls(ControlList *ctrls)\n>  \treturn subdev_->getControls(ctrls);\n>  }\n>  \n> +/**\n> + * \\fn CameraSensor::properties()\n> + * \\brief Retrieve the camera sensor properties\n> + * \\return The list of camera sensor properties\n\nMaybe we'll want to expand this later, but for now this should be fine.\n\n> + */\n> +\n>  /**\n>   * \\brief Write controls to the sensor\n>   * \\param[in] ctrls The list of controls to write\n> diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> index 1fb36a4f4951..68bfd1a4b8d6 100644\n> --- a/src/libcamera/include/camera_sensor.h\n> +++ b/src/libcamera/include/camera_sensor.h\n> @@ -10,6 +10,7 @@\n>  #include <string>\n>  #include <vector>\n>  \n> +#include <libcamera/controls.h>\n>  #include <libcamera/geometry.h>\n>  \n>  #include \"log.h\"\n> @@ -17,7 +18,6 @@\n>  namespace libcamera {\n>  \n>  class ControlInfoMap;\n\nYou can remove this line too.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> -class ControlList;\n>  class MediaEntity;\n>  class V4L2Subdevice;\n>  \n> @@ -47,6 +47,8 @@ public:\n>  \tint getControls(ControlList *ctrls);\n>  \tint setControls(ControlList *ctrls);\n>  \n> +\tconst ControlList &properties() const { return properties_; }\n> +\n>  protected:\n>  \tstd::string logPrefix() const;\n>  \n> @@ -56,6 +58,8 @@ private:\n>  \n>  \tstd::vector<unsigned int> mbusCodes_;\n>  \tstd::vector<Size> sizes_;\n> +\n> +\tControlList properties_;\n>  };\n>  \n>  } /* namespace libcamera */","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0863560BFF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  4 Dec 2019 17:05:14 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5B3AD2E5;\n\tWed,  4 Dec 2019 17:05:13 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1575475513;\n\tbh=ObIziOyzQ0jlhZ7CKwyZoBANZjk1auwjMZjC4OSyBXk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=v8tfhSrwjB5rCSGFaY13Mr0c2qvB0X3osv3uD1zB4gGsnS2KNPCRtDpcikmrE487A\n\thtnUWZlKJ6hQ/E/Us45AlyNvpAZWaMWMO8IrSBON9NDVxZluW00X9fxeCUzQCcuC2U\n\tIQVsrJaBqUyZGLpkRsK2iBCsismk4CcIPvKzobRk=","Date":"Wed, 4 Dec 2019 18:05:06 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191204160506.GE7811@pendragon.ideasonboard.com>","References":"<20191204132106.21582-1-jacopo@jmondi.org>\n\t<20191204132106.21582-7-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191204132106.21582-7-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 06/10] libcamera: camera_sensor: Parse\n\tcamera properties","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, 04 Dec 2019 16:05:14 -0000"}}]