[{"id":24338,"web_url":"https://patchwork.libcamera.org/comment/24338/","msgid":"<165952790955.3981176.6465551183543967239@Monstersaurus>","date":"2022-08-03T11:58:29","subject":"Re: [libcamera-devel] [PATCH 07/13] libcamera: v4l2_subdevice:\n\tCollect subdev capabilities","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart via libcamera-devel (2022-08-01 01:05:37)\n> From: Jacopo Mondi <jacopo@jmondi.org>\n> \n> Collect subdev capabilities at open() time.\n> \n> Model the V4L2SubdevCapabilties as V4L2Capability from the video\n> device class.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> Changes on top of Jacopo's initial work:\n> \n> - Rename V4L2SubdevCapabilities to V4L2SubdeviceCapability and make it\n>   final, to match the V4L2VideoDevice class\n> - Add V4L2Subdevice::caps()\n> ---\n>  include/libcamera/internal/v4l2_subdevice.h | 13 ++++++\n>  src/libcamera/v4l2_subdevice.cpp            | 50 ++++++++++++++++++++-\n>  2 files changed, 62 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 2db392d5e37a..a1d3144c6a7f 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -29,6 +29,17 @@ namespace libcamera {\n>  \n>  class MediaDevice;\n>  \n> +struct V4L2SubdeviceCapability final : v4l2_subdev_capability {\n> +       bool isReadOnly() const\n> +       {\n> +               return capabilities & V4L2_SUBDEV_CAP_RO_SUBDEV;\n> +       }\n> +       bool hasStreams() const\n> +       {\n> +               return capabilities & V4L2_SUBDEV_CAP_MPLEXED;\n> +       }\n> +};\n> +\n>  struct V4L2SubdeviceFormat {\n>         uint32_t mbus_code;\n>         Size size;\n> @@ -70,6 +81,7 @@ public:\n>                       Whence whence = ActiveFormat);\n>  \n>         const std::string &model();\n> +       const V4L2SubdeviceCapability &caps() const { return caps_; }\n>  \n>         static std::unique_ptr<V4L2Subdevice>\n>         fromEntityName(const MediaDevice *media, const std::string &entity);\n> @@ -87,6 +99,7 @@ private:\n>         const MediaEntity *entity_;\n>  \n>         std::string model_;\n> +       struct V4L2SubdeviceCapability caps_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 37960b76a044..a1672b2365f2 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -133,6 +133,30 @@ const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {\n>  \n>  } /* namespace */\n>  \n> +/**\n> + * \\struct V4L2SubdeviceCapability\n> + * \\brief struct v4l2_subdev_capability object wrapper and helpers\n> + *\n> + * The V4L2SubdeviceCapability structure manages the information returned by the\n> + * VIDIOC_SUBDEV_QUERYCAP ioctl.\n> + */\n> +\n> +/**\n> + * \\fn V4L2SubdeviceCapability::isReadOnly()\n> + * \\brief Retrieve if a subdevice is registered as read-only\n> + *\n> + * A V4L2 subdevice is registered as read-only if V4L2_SUBDEV_CAP_RO_SUBDEV\n> + * is listed as part of its capabilities.\n> + *\n> + * \\return True if the subdevice is registered as read-only, false otherwise\n> + */\n> +\n> +/**\n> + * \\fn V4L2SubdeviceCapability::hasStreams()\n> + * \\brief Retrieve if a subdevice supports the V4L2 streams API\n> + * \\return True if the subdevice supports the streams API, false otherwise\n> + */\n> +\n>  /**\n>   * \\struct V4L2SubdeviceFormat\n>   * \\brief The V4L2 sub-device image format and sizes\n> @@ -284,7 +308,25 @@ V4L2Subdevice::~V4L2Subdevice()\n>   */\n>  int V4L2Subdevice::open()\n>  {\n> -       return V4L2Device::open(O_RDWR);\n> +       int ret = V4L2Device::open(O_RDWR);\n> +       if (ret)\n> +               return ret;\n> +\n> +       /*\n> +        * Try to query the subdev capabilities. The VIDIOC_SUBDEV_QUERYCAP API\n> +        * was introduced in kernel v5.8, ENOTTY errors must be ignored to\n> +        * support older kernels.\n> +        */\n> +       caps_ = {};\n> +       ret = ioctl(VIDIOC_SUBDEV_QUERYCAP, &caps_);\n> +       if (ret < 0 && errno != ENOTTY) {\n> +               ret = -errno;\n> +               LOG(V4L2, Error)\n> +                       << \"Unable to query capabilities: \" << strerror(-ret);\n> +               return ret;\n> +       }\n\nI wonder if we should report ENOTTY errors through a Debug level print,\nbut perhaps we could do that generically in our ioctl call (in a\nseparate patch) to report that an attempt was made on an unsupported\ncall?\n\nOtherwise, I like this.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> +\n> +       return 0;\n>  }\n>  \n>  /**\n> @@ -527,6 +569,12 @@ const std::string &V4L2Subdevice::model()\n>         return model_;\n>  }\n>  \n> +/**\n> + * \\fn V4L2Subdevice::caps()\n> + * \\brief Retrieve the subdevice V4L2 capabilities\n> + * \\return The subdevice V4L2 capabilities\n> + */\n> +\n>  /**\n>   * \\brief Create a new video subdevice instance from \\a entity in media device\n>   * \\a media\n> -- \n> Regards,\n> \n> Laurent Pinchart\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 772CABE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Aug 2022 11:58:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BADDD63310;\n\tWed,  3 Aug 2022 13:58:33 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F01F603E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Aug 2022 13:58:32 +0200 (CEST)","from pendragon.ideasonboard.com\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 1F76F8B;\n\tWed,  3 Aug 2022 13:58:32 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659527913;\n\tbh=enfFJZc1D0haemAd8z1hoy/DBTMYEdcNglwZoLcBNa0=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=nAKllMAx2jmeREPDZHo24f9TXTKogjhpbWZzt60VCvmXtsP2ZlCgYT0H+qqm8Pwsc\n\t/VEzD7MK2VzH2evHuYE3PKa9Fkn7pPP9PlYmmL2curf7lw5Th6pThXxp7L2f5f4Zzw\n\teTTHVQroG8OkH7U5VtuxNBQ7PoOryNAp+ew72IrM8TBCPKHCQeOWKAASF8oAyJ4GyX\n\t6fv4qbpM/rUQNCK0yR/NMPR/zd7nKqyJEIOq08H0rlIZ40/68/VhhCB2Lbo2aYwo4E\n\tBXTNdEeueu3ooNkfkKLOg7sBru38NTSsacItX8jTCPt4FTOHdlW4wX5QHdEdGiMy4n\n\trlr1Xwlfey1Pw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659527912;\n\tbh=enfFJZc1D0haemAd8z1hoy/DBTMYEdcNglwZoLcBNa0=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=d9JhAw2hpg7X6zgkir/Rppwf1Dvc/HpmWUFXcQSPKEtFKth0AmyZMXHU7tMFOcuoz\n\t2LkTksAsBLOCXvEKe6EvA1qt/rmwR2Qpfg6jB6/KB/LYGQMS19TeDla4JMS02CZc5z\n\tyZNR3bpK2wpyVFL3s/yEvnKNf3x1eDzn923UyXeM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"d9JhAw2h\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220801000543.3501-8-laurent.pinchart@ideasonboard.com>","References":"<20220801000543.3501-1-laurent.pinchart@ideasonboard.com>\n\t<20220801000543.3501-8-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 03 Aug 2022 12:58:29 +0100","Message-ID":"<165952790955.3981176.6465551183543967239@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH 07/13] libcamera: v4l2_subdevice:\n\tCollect subdev capabilities","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24346,"web_url":"https://patchwork.libcamera.org/comment/24346/","msgid":"<20220803132714.GE311202@pyrite.rasen.tech>","date":"2022-08-03T13:27:14","subject":"Re: [libcamera-devel] [PATCH 07/13] libcamera: v4l2_subdevice:\n\tCollect subdev capabilities","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"On Mon, Aug 01, 2022 at 03:05:37AM +0300, Laurent Pinchart via libcamera-devel wrote:\n> From: Jacopo Mondi <jacopo@jmondi.org>\n> \n> Collect subdev capabilities at open() time.\n> \n> Model the V4L2SubdevCapabilties as V4L2Capability from the video\n> device class.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n> Changes on top of Jacopo's initial work:\n> \n> - Rename V4L2SubdevCapabilities to V4L2SubdeviceCapability and make it\n>   final, to match the V4L2VideoDevice class\n> - Add V4L2Subdevice::caps()\n> ---\n>  include/libcamera/internal/v4l2_subdevice.h | 13 ++++++\n>  src/libcamera/v4l2_subdevice.cpp            | 50 ++++++++++++++++++++-\n>  2 files changed, 62 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 2db392d5e37a..a1d3144c6a7f 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -29,6 +29,17 @@ namespace libcamera {\n>  \n>  class MediaDevice;\n>  \n> +struct V4L2SubdeviceCapability final : v4l2_subdev_capability {\n> +\tbool isReadOnly() const\n> +\t{\n> +\t\treturn capabilities & V4L2_SUBDEV_CAP_RO_SUBDEV;\n> +\t}\n> +\tbool hasStreams() const\n> +\t{\n> +\t\treturn capabilities & V4L2_SUBDEV_CAP_MPLEXED;\n> +\t}\n> +};\n> +\n>  struct V4L2SubdeviceFormat {\n>  \tuint32_t mbus_code;\n>  \tSize size;\n> @@ -70,6 +81,7 @@ public:\n>  \t\t      Whence whence = ActiveFormat);\n>  \n>  \tconst std::string &model();\n> +\tconst V4L2SubdeviceCapability &caps() const { return caps_; }\n>  \n>  \tstatic std::unique_ptr<V4L2Subdevice>\n>  \tfromEntityName(const MediaDevice *media, const std::string &entity);\n> @@ -87,6 +99,7 @@ private:\n>  \tconst MediaEntity *entity_;\n>  \n>  \tstd::string model_;\n> +\tstruct V4L2SubdeviceCapability caps_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 37960b76a044..a1672b2365f2 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -133,6 +133,30 @@ const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {\n>  \n>  } /* namespace */\n>  \n> +/**\n> + * \\struct V4L2SubdeviceCapability\n> + * \\brief struct v4l2_subdev_capability object wrapper and helpers\n> + *\n> + * The V4L2SubdeviceCapability structure manages the information returned by the\n> + * VIDIOC_SUBDEV_QUERYCAP ioctl.\n> + */\n> +\n> +/**\n> + * \\fn V4L2SubdeviceCapability::isReadOnly()\n> + * \\brief Retrieve if a subdevice is registered as read-only\n> + *\n> + * A V4L2 subdevice is registered as read-only if V4L2_SUBDEV_CAP_RO_SUBDEV\n> + * is listed as part of its capabilities.\n> + *\n> + * \\return True if the subdevice is registered as read-only, false otherwise\n> + */\n> +\n> +/**\n> + * \\fn V4L2SubdeviceCapability::hasStreams()\n> + * \\brief Retrieve if a subdevice supports the V4L2 streams API\n> + * \\return True if the subdevice supports the streams API, false otherwise\n> + */\n> +\n>  /**\n>   * \\struct V4L2SubdeviceFormat\n>   * \\brief The V4L2 sub-device image format and sizes\n> @@ -284,7 +308,25 @@ V4L2Subdevice::~V4L2Subdevice()\n>   */\n>  int V4L2Subdevice::open()\n>  {\n> -\treturn V4L2Device::open(O_RDWR);\n> +\tint ret = V4L2Device::open(O_RDWR);\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\t/*\n> +\t * Try to query the subdev capabilities. The VIDIOC_SUBDEV_QUERYCAP API\n> +\t * was introduced in kernel v5.8, ENOTTY errors must be ignored to\n> +\t * support older kernels.\n> +\t */\n> +\tcaps_ = {};\n> +\tret = ioctl(VIDIOC_SUBDEV_QUERYCAP, &caps_);\n> +\tif (ret < 0 && errno != ENOTTY) {\n> +\t\tret = -errno;\n> +\t\tLOG(V4L2, Error)\n> +\t\t\t<< \"Unable to query capabilities: \" << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\treturn 0;\n>  }\n>  \n>  /**\n> @@ -527,6 +569,12 @@ const std::string &V4L2Subdevice::model()\n>  \treturn model_;\n>  }\n>  \n> +/**\n> + * \\fn V4L2Subdevice::caps()\n> + * \\brief Retrieve the subdevice V4L2 capabilities\n> + * \\return The subdevice V4L2 capabilities\n> + */\n> +\n>  /**\n>   * \\brief Create a new video subdevice instance from \\a entity in media device\n>   * \\a media\n> -- \n> Regards,\n> \n> Laurent Pinchart\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 EC2EAC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Aug 2022 13:27:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42F6A63310;\n\tWed,  3 Aug 2022 15:27:23 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 129EE603E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Aug 2022 15:27:22 +0200 (CEST)","from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B8A638B;\n\tWed,  3 Aug 2022 15:27:20 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659533243;\n\tbh=FYBieaJcQALHJjVuNjRa9Uz1cu0d6izUt1i6UFdDZh8=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=yIbEEtSR9xGDMjklpNfKfuG+8OxVKssvwOtUZ+VIqzL0CKqDdvE0GnXGxDxAcP/81\n\tu5QfDfBJ7XVftcgYajJe4Ik/876oNr+I1G31sN9DNkXU+uHXC1N1WuaM2dKA+0H0Cd\n\tbMhUpnPaN+Zfkja/dguavHLXViGfFSaYC/btzUjCaYoVE2WK+zYdSRZsZQuKpE4eF1\n\tS551eNOY/rDz1vP9BQHcnIb607sF5EbLvLYtScDsLNuxlsucoywBC/WwNwV2o07FI5\n\tzCIGEKAgR/5U5WblPmmj+3iwPBXp2BNwiHo6Vb/Ivc3aT5JDzCDAoJqE9p5RqahOiG\n\tfKE7LKzQvLanw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659533241;\n\tbh=FYBieaJcQALHJjVuNjRa9Uz1cu0d6izUt1i6UFdDZh8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=fqKqSb4gaOTxuA/z87KcWeJdl7AAbNLN/3hKg8ypKCA4BVo2f60f1++3TSLTyUdJt\n\t5toN4Tx0QPfhaCbVkIux9mT+JqMOOo3jSJbfJE24ReD97DV7t/nyWZQ712lRehLZvc\n\tdovjlhhyTSBe1xe7ASqZvHFI9jKF9WdXXw7IqGho="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"fqKqSb4g\"; dkim-atps=neutral","Date":"Wed, 3 Aug 2022 22:27:14 +0900","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20220803132714.GE311202@pyrite.rasen.tech>","References":"<20220801000543.3501-1-laurent.pinchart@ideasonboard.com>\n\t<20220801000543.3501-8-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20220801000543.3501-8-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 07/13] libcamera: v4l2_subdevice:\n\tCollect subdev capabilities","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>","From":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@ideasonboard.com","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24347,"web_url":"https://patchwork.libcamera.org/comment/24347/","msgid":"<Yup6DmIvthcuWq5P@pendragon.ideasonboard.com>","date":"2022-08-03T13:37:18","subject":"Re: [libcamera-devel] [PATCH 07/13] libcamera: v4l2_subdevice:\n\tCollect subdev capabilities","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Wed, Aug 03, 2022 at 12:58:29PM +0100, Kieran Bingham wrote:\n> Quoting Laurent Pinchart via libcamera-devel (2022-08-01 01:05:37)\n> > From: Jacopo Mondi <jacopo@jmondi.org>\n> > \n> > Collect subdev capabilities at open() time.\n> > \n> > Model the V4L2SubdevCapabilties as V4L2Capability from the video\n> > device class.\n> > \n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> > Changes on top of Jacopo's initial work:\n> > \n> > - Rename V4L2SubdevCapabilities to V4L2SubdeviceCapability and make it\n> >   final, to match the V4L2VideoDevice class\n> > - Add V4L2Subdevice::caps()\n> > ---\n> >  include/libcamera/internal/v4l2_subdevice.h | 13 ++++++\n> >  src/libcamera/v4l2_subdevice.cpp            | 50 ++++++++++++++++++++-\n> >  2 files changed, 62 insertions(+), 1 deletion(-)\n> > \n> > diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> > index 2db392d5e37a..a1d3144c6a7f 100644\n> > --- a/include/libcamera/internal/v4l2_subdevice.h\n> > +++ b/include/libcamera/internal/v4l2_subdevice.h\n> > @@ -29,6 +29,17 @@ namespace libcamera {\n> >  \n> >  class MediaDevice;\n> >  \n> > +struct V4L2SubdeviceCapability final : v4l2_subdev_capability {\n> > +       bool isReadOnly() const\n> > +       {\n> > +               return capabilities & V4L2_SUBDEV_CAP_RO_SUBDEV;\n> > +       }\n> > +       bool hasStreams() const\n> > +       {\n> > +               return capabilities & V4L2_SUBDEV_CAP_MPLEXED;\n> > +       }\n> > +};\n> > +\n> >  struct V4L2SubdeviceFormat {\n> >         uint32_t mbus_code;\n> >         Size size;\n> > @@ -70,6 +81,7 @@ public:\n> >                       Whence whence = ActiveFormat);\n> >  \n> >         const std::string &model();\n> > +       const V4L2SubdeviceCapability &caps() const { return caps_; }\n> >  \n> >         static std::unique_ptr<V4L2Subdevice>\n> >         fromEntityName(const MediaDevice *media, const std::string &entity);\n> > @@ -87,6 +99,7 @@ private:\n> >         const MediaEntity *entity_;\n> >  \n> >         std::string model_;\n> > +       struct V4L2SubdeviceCapability caps_;\n> >  };\n> >  \n> >  } /* namespace libcamera */\n> > diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> > index 37960b76a044..a1672b2365f2 100644\n> > --- a/src/libcamera/v4l2_subdevice.cpp\n> > +++ b/src/libcamera/v4l2_subdevice.cpp\n> > @@ -133,6 +133,30 @@ const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {\n> >  \n> >  } /* namespace */\n> >  \n> > +/**\n> > + * \\struct V4L2SubdeviceCapability\n> > + * \\brief struct v4l2_subdev_capability object wrapper and helpers\n> > + *\n> > + * The V4L2SubdeviceCapability structure manages the information returned by the\n> > + * VIDIOC_SUBDEV_QUERYCAP ioctl.\n> > + */\n> > +\n> > +/**\n> > + * \\fn V4L2SubdeviceCapability::isReadOnly()\n> > + * \\brief Retrieve if a subdevice is registered as read-only\n> > + *\n> > + * A V4L2 subdevice is registered as read-only if V4L2_SUBDEV_CAP_RO_SUBDEV\n> > + * is listed as part of its capabilities.\n> > + *\n> > + * \\return True if the subdevice is registered as read-only, false otherwise\n> > + */\n> > +\n> > +/**\n> > + * \\fn V4L2SubdeviceCapability::hasStreams()\n> > + * \\brief Retrieve if a subdevice supports the V4L2 streams API\n> > + * \\return True if the subdevice supports the streams API, false otherwise\n> > + */\n> > +\n> >  /**\n> >   * \\struct V4L2SubdeviceFormat\n> >   * \\brief The V4L2 sub-device image format and sizes\n> > @@ -284,7 +308,25 @@ V4L2Subdevice::~V4L2Subdevice()\n> >   */\n> >  int V4L2Subdevice::open()\n> >  {\n> > -       return V4L2Device::open(O_RDWR);\n> > +       int ret = V4L2Device::open(O_RDWR);\n> > +       if (ret)\n> > +               return ret;\n> > +\n> > +       /*\n> > +        * Try to query the subdev capabilities. The VIDIOC_SUBDEV_QUERYCAP API\n> > +        * was introduced in kernel v5.8, ENOTTY errors must be ignored to\n> > +        * support older kernels.\n> > +        */\n> > +       caps_ = {};\n> > +       ret = ioctl(VIDIOC_SUBDEV_QUERYCAP, &caps_);\n> > +       if (ret < 0 && errno != ENOTTY) {\n> > +               ret = -errno;\n> > +               LOG(V4L2, Error)\n> > +                       << \"Unable to query capabilities: \" << strerror(-ret);\n> > +               return ret;\n> > +       }\n> \n> I wonder if we should report ENOTTY errors through a Debug level print,\n> but perhaps we could do that generically in our ioctl call (in a\n> separate patch) to report that an attempt was made on an unsupported\n> call?\n\nI've thought about it, but even as a debug message, I fear it may be too\nverbose if it ends up being triggered by ioctls we call constantly. I\nsuppose that may be more of a risk on video nodes than on subdevs, so\nmaybe that could be a middle ground ? I'm tempted to delay it until we\nfind a need during debugging though.\n\n> Otherwise, I like this.\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > +\n> > +       return 0;\n> >  }\n> >  \n> >  /**\n> > @@ -527,6 +569,12 @@ const std::string &V4L2Subdevice::model()\n> >         return model_;\n> >  }\n> >  \n> > +/**\n> > + * \\fn V4L2Subdevice::caps()\n> > + * \\brief Retrieve the subdevice V4L2 capabilities\n> > + * \\return The subdevice V4L2 capabilities\n> > + */\n> > +\n> >  /**\n> >   * \\brief Create a new video subdevice instance from \\a entity in media device\n> >   * \\a media","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 ED3A1BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Aug 2022 13:37:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6305B63310;\n\tWed,  3 Aug 2022 15:37:27 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A3593603E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Aug 2022 15:37:25 +0200 (CEST)","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 0B6668B;\n\tWed,  3 Aug 2022 15:37:24 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1659533847;\n\tbh=P0Rvcc5iHKQNUxlkGg3ce8FvXdlUc/4HJY1zoDOUANI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=0Nipd2Jw0oqsXxqtS1N2s+WO+rP+ElKC6zmfEhdcJHpFE9ruwTw2Tp4XBfDHyMfqJ\n\tCE2N300EHbvxP1QOPqaLTpqcEjHBaXy7+9icjgTf4Uy9oEoWoVuhf9VTTXppEFhyBS\n\te1ZZSiOXCIjZB32NZV4ewgTkhh36mB7r4rAgX4t+1REhMSwe0CCKWxx9QICFVu4QLy\n\tyJ7np6SrJbLCCvcz6YYH1KxVJeRpj5QxiiuiM171bVh5JKOjSk4G2tSxXvrR60+Zmx\n\taVRo1qObbFLIdRv0/oJKJJZtSCd8OrAgLytrXfzxEqP1VYQdJTsfPB7tVZ7PDVWBTN\n\tOxxyhmdBoaveA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1659533845;\n\tbh=P0Rvcc5iHKQNUxlkGg3ce8FvXdlUc/4HJY1zoDOUANI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DYNU+Ygs9IhjW8XjMdlvR+fXxSAFQs744k4J6syUEeYOytIjcbs90nQ0axknpcJbE\n\t3SnBlnPlnrXRRpWylzOuIA+SkkP2LJkQuOdNqj0RSW2OhVSlDaLeGOS78/9RvfoXvX\n\tEjf4ojliBEbDdNiwAPQgxsGW5Tjj7i7vbx1W8C70="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"DYNU+Ygs\"; dkim-atps=neutral","Date":"Wed, 3 Aug 2022 16:37:18 +0300","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<Yup6DmIvthcuWq5P@pendragon.ideasonboard.com>","References":"<20220801000543.3501-1-laurent.pinchart@ideasonboard.com>\n\t<20220801000543.3501-8-laurent.pinchart@ideasonboard.com>\n\t<165952790955.3981176.6465551183543967239@Monstersaurus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<165952790955.3981176.6465551183543967239@Monstersaurus>","Subject":"Re: [libcamera-devel] [PATCH 07/13] libcamera: v4l2_subdevice:\n\tCollect subdev capabilities","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]