[{"id":21389,"web_url":"https://patchwork.libcamera.org/comment/21389/","msgid":"<YaWg0wk8bHTEmj7V@pendragon.ideasonboard.com>","date":"2021-11-30T03:56:03","subject":"Re: [libcamera-devel] [PATCH v5 2/4] libcamera: add model() for\n\tretriving model name in V4L2Subdevice","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Han-lin,\n\nThank you for the patch.\n\nOn Fri, Nov 26, 2021 at 07:29:01PM +0800, Han-Lin Chen wrote:\n> CameraSensor retrives model name from media entity. Move the heuristics\n> method into V4L2Subdevice, so CameraLens can reuse the function.\n> \n> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n> ---\n>  include/libcamera/internal/v4l2_subdevice.h |  5 +++\n>  src/libcamera/camera_sensor.cpp             | 13 ++-----\n>  src/libcamera/v4l2_subdevice.cpp            | 40 +++++++++++++++++++++\n>  3 files changed, 47 insertions(+), 11 deletions(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 97b89fb9..794c80c6 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -61,6 +61,8 @@ public:\n>  \tint setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n>  \t\t      Whence whence = ActiveFormat);\n>  \n> +\tstd::string model() { return model_; }\n> +\n>  \tstatic std::unique_ptr<V4L2Subdevice>\n>  \tfromEntityName(const MediaDevice *media, const std::string &entity);\n>  \n> @@ -73,8 +75,11 @@ private:\n>  \tstd::vector<unsigned int> enumPadCodes(unsigned int pad);\n>  \tstd::vector<SizeRange> enumPadSizes(unsigned int pad,\n>  \t\t\t\t\t    unsigned int code);\n> +\tvoid generateModel();\n>  \n>  \tconst MediaEntity *entity_;\n> +\n> +\tstd::string model_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 9fdb8c09..3659ff2d 100644\n> --- a/src/libcamera/camera_sensor.cpp\n> +++ b/src/libcamera/camera_sensor.cpp\n> @@ -13,7 +13,6 @@\n>  #include <iomanip>\n>  #include <limits.h>\n>  #include <math.h>\n> -#include <regex>\n>  #include <string.h>\n>  \n>  #include <libcamera/property_ids.h>\n> @@ -366,15 +365,7 @@ int CameraSensor::initProperties()\n>  \t * part of the entity name before the first space if the name contains\n>  \t * an I2C address, and use the full entity name otherwise.\n>  \t */\n\nShouldn't the comment be removed too ?\n\n> -\tstd::string entityName = entity_->name();\n> -\tstd::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n> -\tstd::smatch match;\n> -\n> -\tif (std::regex_search(entityName, match, i2cRegex))\n> -\t\tmodel_ = entityName.substr(0, entityName.find(' '));\n> -\telse\n> -\t\tmodel_ = entityName;\n> -\n> +\tmodel_ = subdev_->model();\n>  \tproperties_.set(properties::Model, utils::toAscii(model_));\n>  \n>  \t/* Generate a unique ID for the sensor. */\n> @@ -832,7 +823,7 @@ int CameraSensor::generateId()\n>  \t/*\n>  \t * Virtual sensors not described in firmware\n>  \t *\n> -\t * Verify it's a platform device and construct ID from the deive path\n> +\t * Verify it's a platform device and construct ID from the device path\n>  \t * and model of sensor.\n>  \t */\n>  \tif (devPath.find(\"/sys/devices/platform/\", 0) == 0) {\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 023e2328..0e194081 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -9,6 +9,7 @@\n>  \n>  #include <fcntl.h>\n>  #include <iomanip>\n> +#include <regex>\n>  #include <sstream>\n>  #include <string.h>\n>  #include <sys/ioctl.h>\n> @@ -239,6 +240,7 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const\n>  V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)\n>  \t: V4L2Device(entity->deviceNode()), entity_(entity)\n>  {\n> +\tgenerateModel();\n\nHow about doing this the first time model() is called, so that we won't\ntry to generate a model for every single subdev when only a few of them\nwill need it ?\n\n>  }\n>  \n>  V4L2Subdevice::~V4L2Subdevice()\n> @@ -442,6 +444,12 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n>  \treturn 0;\n>  }\n>  \n> +/**\n> + * \\fn V4L2Subdevice::model()\n> + * \\brief Retrieve the model name\n> + * \\return The model name of the device\n> + */\n> +\n>  /**\n>   * \\brief Create a new video subdevice instance from \\a entity in media device\n>   * \\a media\n> @@ -525,4 +533,36 @@ std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,\n>  \treturn sizes;\n>  }\n>  \n> +void V4L2Subdevice::generateModel()\n> +{\n> +\t/*\n> +\t * Extract model name from the media entity name.\n> +\t *\n> +\t * There is no standardized naming scheme for sensor entities in the\n> +\t * Linux kernel at the moment.\n> +\t *\n> +\t * - The most common rule, used by I2C sensors, associates the model\n> +\t *   name with the I2C bus number and address (e.g. 'imx219 0-0010').\n> +\t *\n> +\t * - When the sensor exposes multiple subdevs, the model name is\n> +\t *   usually followed by a function name, as in the smiapp driver (e.g.\n> +\t *   'jt8ew9 pixel_array 0-0010').\n> +\t *\n> +\t * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.\n> +\t *\n> +\t * Other schemes probably exist. As a best effort heuristic, use the\n> +\t * part of the entity name before the first space if the name contains\n> +\t * an I2C address, and use the full entity name otherwise.\n> +\t */\n> +\tstd::string entityName = entity_->name();\n> +\tstd::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n> +\tstd::smatch match;\n> +\n> +\tstd::string model;\n> +\tif (std::regex_search(entityName, match, i2cRegex))\n> +\t\tmodel_ = entityName.substr(0, entityName.find(' '));\n> +\telse\n> +\t\tmodel_ = entityName;\n> +}\n> +\n>  } /* namespace libcamera */","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 32048BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 03:56:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7E20C605B4;\n\tTue, 30 Nov 2021 04:56:29 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DBD10604FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 04:56:27 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 59A748F0;\n\tTue, 30 Nov 2021 04:56:27 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"mu/Dr8yY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638244587;\n\tbh=I7OT3ZHPmg0Pc0WTsydlhH1GpUPe+/DgvPImrFAQbNY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=mu/Dr8yYkPqtF3ZeBA7i2xOsQBXg7/Pzqjwo+58OXeSTVsC3rKSSzrMhLrllvGk3Q\n\tzfbykZWAKUoek4g2kXZP7FanL36C2XJG30BwzZBbUnXTuhfwHh8IMQe9oLRTKGzND+\n\tZ/2pbA9Vt73ES/o0VyQMLCvRIQlbVjZP6xbrTQXw=","Date":"Tue, 30 Nov 2021 05:56:03 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Han-Lin Chen <hanlinchen@chromium.org>","Message-ID":"<YaWg0wk8bHTEmj7V@pendragon.ideasonboard.com>","References":"<20211126112903.3276056-1-hanlinchen@chromium.org>\n\t<20211126112903.3276056-3-hanlinchen@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211126112903.3276056-3-hanlinchen@chromium.org>","Subject":"Re: [libcamera-devel] [PATCH v5 2/4] libcamera: add model() for\n\tretriving model name in V4L2Subdevice","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]