[{"id":18599,"web_url":"https://patchwork.libcamera.org/comment/18599/","msgid":"<59ec5f69-64d7-8c66-9e13-f28373e146eb@ideasonboard.com>","date":"2021-08-06T13:23:59","subject":"Re: [libcamera-devel] [PATCH 01/10] libcamera: media_object: Expose\n\tentity type","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 05/08/2021 23:24, Laurent Pinchart wrote:\n> Add a new field to the MediaEntity class to tell the type of interface\n\ns/tell/identify/\n\n> it exposes to userspace. The MediaEntity constructor is changed to take\n> a media_v2_interface pointer instead of just the device node major and\n> minor to have access to the interface type.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/media_object.h | 11 ++++-\n>  src/libcamera/media_device.cpp            |  9 +---\n>  src/libcamera/media_object.cpp            | 50 +++++++++++++++++++++--\n>  3 files changed, 57 insertions(+), 13 deletions(-)\n> \n> diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h\n> index 2f5d33e1903e..6ae22c679cc5 100644\n> --- a/include/libcamera/internal/media_object.h\n> +++ b/include/libcamera/internal/media_object.h\n> @@ -88,9 +88,17 @@ private:\n>  class MediaEntity : public MediaObject\n>  {\n>  public:\n> +\tenum class Type {\n> +\t\tInvalid,\n> +\t\tMediaEntity,\n> +\t\tV4L2Subdevice,\n> +\t\tV4L2VideoDevice,\n> +\t};\n> +\n>  \tconst std::string &name() const { return name_; }\n>  \tunsigned int function() const { return function_; }\n>  \tunsigned int flags() const { return flags_; }\n> +\tType type() const { return type_; }\n>  \tconst std::string &deviceNode() const { return deviceNode_; }\n>  \tunsigned int deviceMajor() const { return major_; }\n>  \tunsigned int deviceMinor() const { return minor_; }\n> @@ -108,13 +116,14 @@ private:\n>  \tfriend class MediaDevice;\n>  \n>  \tMediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,\n> -\t\t    unsigned int major = 0, unsigned int minor = 0);\n> +\t\t    const struct media_v2_interface *iface);\n>  \n>  \tvoid addPad(MediaPad *pad);\n>  \n>  \tstd::string name_;\n>  \tunsigned int function_;\n>  \tunsigned int flags_;\n> +\tType type_;\n>  \tstd::string deviceNode_;\n>  \tunsigned int major_;\n>  \tunsigned int minor_;\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index fa50264fa253..4d7cb1f566c4 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -652,14 +652,7 @@ bool MediaDevice::populateEntities(const struct media_v2_topology &topology)\n>  \t\t */\n>  \t\tstruct media_v2_interface *iface =\n>  \t\t\tfindInterface(topology, ent->id);\n> -\n> -\t\tMediaEntity *entity;\n> -\t\tif (iface)\n> -\t\t\tentity = new MediaEntity(this, ent,\n> -\t\t\t\t\t\t iface->devnode.major,\n> -\t\t\t\t\t\t iface->devnode.minor);\n> -\t\telse\n> -\t\t\tentity = new MediaEntity(this, ent);\n> +\t\tMediaEntity *entity = new MediaEntity(this, ent, iface);\n>  \n>  \t\tif (!addObject(entity)) {\n>  \t\t\tdelete entity;\n> diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp\n> index 815edc8e3b2d..f425d0447241 100644\n> --- a/src/libcamera/media_object.cpp\n> +++ b/src/libcamera/media_object.cpp\n> @@ -247,6 +247,23 @@ void MediaPad::addLink(MediaLink *link)\n>   * may expose a deviceNode().\n>   */\n>  \n> +/**\n> + * \\enum MediaEntity::Type\n> + * \\brief The type of the interface exposed by the entity to userspace\n> + *\n> + * \\var MediaEntity::Type::Invalid\n> + * \\brief Invalid or unsupported entity type\n> + *\n> + * \\var MediaEntity::Type::MediaEntity\n> + * \\brief Plain media entity with no userspace interface\n> + *\n> + * \\var MediaEntity::Type::V4L2VideoDevice\n> + * \\brief V4L2 video device with a V4L2 video device node\n> + *\n> + * \\var MediaEntity::Type::V4L2Subdevice\n> + * \\brief V4L2 subdevice with a V4L2 subdev device node\n> + */\n> +\n>  /**\n>   * \\fn MediaEntity::name()\n>   * \\brief Retrieve the entity name\n> @@ -273,6 +290,15 @@ void MediaPad::addLink(MediaLink *link)\n>   * \\return The entity's flags\n>   */\n>  \n> +/**\n> + * \\fn MediaEntity::type()\n> + * \\brief Retrieve the entity's type\n> + *\n> + * The entity type identifies the type of interface exposed to userspace.\n> + *\n> + * \\return The entity's type\n> + */\n> +\n>  /**\n>   * \\fn MediaEntity::deviceNode()\n>   * \\brief Retrieve the entity's device node path, if any\n> @@ -356,16 +382,32 @@ int MediaEntity::setDeviceNode(const std::string &deviceNode)\n>   * \\brief Construct a MediaEntity\n>   * \\param[in] dev The media device this entity belongs to\n>   * \\param[in] entity The media entity kernel data\n> - * \\param[in] major The major number of the entity associated interface\n> - * \\param[in] minor The minor number of the entity associated interface\n> + * \\param[in] iface The entity interface data (may be null)\n>   */\n>  MediaEntity::MediaEntity(MediaDevice *dev,\n>  \t\t\t const struct media_v2_entity *entity,\n> -\t\t\t unsigned int major, unsigned int minor)\n> +\t\t\t const struct media_v2_interface *iface)\n>  \t: MediaObject(dev, entity->id), name_(entity->name),\n>  \t  function_(entity->function), flags_(entity->flags),\n> -\t  major_(major), minor_(minor)\n> +\t  type_(Type::MediaEntity), major_(0), minor_(0)\n>  {\n> +\tif (!iface)\n> +\t\treturn;\n> +\n> +\tswitch (iface->intf_type) {\n> +\tcase MEDIA_INTF_T_V4L_VIDEO:\n> +\t\ttype_ = Type::V4L2VideoDevice;\n> +\t\tbreak;\n> +\tcase MEDIA_INTF_T_V4L_SUBDEV:\n> +\t\ttype_ = Type::V4L2Subdevice;\n> +\t\tbreak;\n> +\tdefault:\n> +\t\ttype_ = Type::Invalid;\n> +\t\treturn;\n> +\t}\n> +\n> +\tmajor_ = iface->devnode.major;\n> +\tminor_ = iface->devnode.minor;\n>  }\n>  \n>  /**\n>","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 0E7ADC3235\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Aug 2021 13:24:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 57F9668815;\n\tFri,  6 Aug 2021 15:24:03 +0200 (CEST)","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 738CB60266\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Aug 2021 15:24:02 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E658B4FB;\n\tFri,  6 Aug 2021 15:24:01 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"hHdcfPsb\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628256242;\n\tbh=PETZc5qYQ4SBg/nBfMCY74CvL9YL6ZhhpQOhHqI2I5I=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=hHdcfPsbkOi1Mj5v2OyCkz7+YZIwd6CrcFcu5giHlLFBlGkiBBh2yt4ZxQujN6JAA\n\t89Cn0X1BlTZ6Cg0rX3tHDvTZnnDj/HLx34oO/28/MBsqJa5e6Bk77uRDe7HaDRJ+sG\n\tjEYo+Uo3Lf6JFGnJZIyZ97zIXK9IGKRxURNsEQ+g=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210805222436.6263-1-laurent.pinchart@ideasonboard.com>\n\t<20210805222436.6263-2-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<59ec5f69-64d7-8c66-9e13-f28373e146eb@ideasonboard.com>","Date":"Fri, 6 Aug 2021 14:23:59 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210805222436.6263-2-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 01/10] libcamera: media_object: Expose\n\tentity type","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]