[{"id":2898,"web_url":"https://patchwork.libcamera.org/comment/2898/","msgid":"<20191015001733.GD5976@bigcity.dyn.berto.se>","date":"2019-10-15T00:17:33","subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your patch.\n\nOn 2019-10-14 02:27:50 +0300, Laurent Pinchart wrote:\n> To bring the libcamera and V4L2 control info maps closer, index the\n> latter by ControlId * like the former. As V4L2ControlInfoMap is widely\n> indexed by V4L2 numerical IDs, add accessors based on numerical IDs.\n> \n> This allows complete removal of the ControId pointer from the\n> V4L2ControlInfo, as the ControId is accessible as the key when iterating\n> over the map. A handful of users have to be modified to adapt to the\n> change.\n> \n> The controlInfo argument from V4L2Device::updateControls() can also be\n> removed as it itsn't used anymore.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/include/v4l2_controls.h | 40 +++++++++------\n>  src/libcamera/include/v4l2_device.h   |  1 -\n>  src/libcamera/pipeline/uvcvideo.cpp   |  2 +-\n>  src/libcamera/pipeline/vimc.cpp       |  2 +-\n>  src/libcamera/v4l2_controls.cpp       | 71 +++++++++++++++++++++------\n>  src/libcamera/v4l2_device.cpp         | 25 +++-------\n>  6 files changed, 92 insertions(+), 49 deletions(-)\n> \n> diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h\n> index 4d7ac1a133c7..ca7217501256 100644\n> --- a/src/libcamera/include/v4l2_controls.h\n> +++ b/src/libcamera/include/v4l2_controls.h\n> @@ -28,31 +28,41 @@ public:\n>  class V4L2ControlInfo\n>  {\n>  public:\n> -\tV4L2ControlInfo(const V4L2ControlId &id,\n> -\t\t\tconst struct v4l2_query_ext_ctrl &ctrl);\n> +\tV4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl);\n>  \n> -\tconst ControlId &id() const { return *id_; }\n>  \tconst ControlRange &range() const { return range_; }\n>  \n>  private:\n> -\tconst V4L2ControlId *id_;\n>  \tControlRange range_;\n>  };\n>  \n> -class V4L2ControlInfoMap : private std::map<unsigned int, V4L2ControlInfo>\n> +class V4L2ControlInfoMap : private std::map<const ControlId *, V4L2ControlInfo>\n>  {\n>  public:\n> -\tV4L2ControlInfoMap &operator=(std::map<unsigned int, V4L2ControlInfo> &&info);\n> +\tV4L2ControlInfoMap &operator=(std::map<const ControlId *, V4L2ControlInfo> &&info);\n>  \n> -\tusing std::map<unsigned int, V4L2ControlInfo>::begin;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::cbegin;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::end;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::cend;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::at;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::empty;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::size;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::count;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::find;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::key_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::mapped_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::value_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::size_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::iterator;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::const_iterator;\n> +\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::begin;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::cbegin;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::end;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::cend;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::at;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::empty;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::size;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::count;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::find;\n> +\n> +\tmapped_type &at(unsigned int key);\n> +\tconst mapped_type &at(unsigned int key) const;\n> +\tsize_type count(unsigned int key) const;\n> +\titerator find(unsigned int key);\n> +\tconst_iterator find(unsigned int key) const;\n>  \n>  \tconst ControlIdMap &idmap() const { return idmap_; }\n>  \n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index 5a5b85827f23..f30b1c2cde34 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -45,7 +45,6 @@ protected:\n>  private:\n>  \tvoid listControls();\n>  \tvoid updateControls(ControlList *ctrls,\n> -\t\t\t    const V4L2ControlInfo **controlInfo,\n>  \t\t\t    const struct v4l2_ext_control *v4l2Ctrls,\n>  \t\t\t    unsigned int count);\n>  \n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index 547ad5ca4e55..4d76b5fd9347 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -340,7 +340,7 @@ int UVCCameraData::init(MediaEntity *entity)\n>  \t\tconst V4L2ControlInfo &info = ctrl.second;\n>  \t\tconst ControlId *id;\n>  \n> -\t\tswitch (info.id().id()) {\n> +\t\tswitch (ctrl.first->id()) {\n>  \t\tcase V4L2_CID_BRIGHTNESS:\n>  \t\t\tid = &controls::Brightness;\n>  \t\t\tbreak;\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index 53d00360eb6e..78c0fe5ae509 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -416,7 +416,7 @@ int VimcCameraData::init(MediaDevice *media)\n>  \t\tconst V4L2ControlInfo &info = ctrl.second;\n>  \t\tconst ControlId *id;\n>  \n> -\t\tswitch (info.id().id()) {\n> +\t\tswitch (ctrl.first->id()) {\n>  \t\tcase V4L2_CID_BRIGHTNESS:\n>  \t\t\tid = &controls::Brightness;\n>  \t\t\tbreak;\n> diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\n> index 12c4fb271ba5..9a5e4830db91 100644\n> --- a/src/libcamera/v4l2_controls.cpp\n> +++ b/src/libcamera/v4l2_controls.cpp\n> @@ -122,12 +122,9 @@ V4L2ControlId::V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl)\n>  \n>  /**\n>   * \\brief Construct a V4L2ControlInfo from a struct v4l2_query_ext_ctrl\n> - * \\param[in] id The V4L2 control ID\n>   * \\param[in] ctrl The struct v4l2_query_ext_ctrl as returned by the kernel\n>   */\n> -V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n> -\t\t\t\t const struct v4l2_query_ext_ctrl &ctrl)\n> -\t: id_(&id)\n> +V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n>  {\n>  \tif (ctrl.type == V4L2_CTRL_TYPE_INTEGER64)\n>  \t\trange_ = ControlRange(static_cast<int64_t>(ctrl.minimum),\n> @@ -137,12 +134,6 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n>  \t\t\t\t      static_cast<int32_t>(ctrl.maximum));\n>  }\n>  \n> -/**\n> - * \\fn V4L2ControlInfo::id()\n> - * \\brief Retrieve the control ID\n> - * \\return The V4L2 control ID\n> - */\n> -\n>  /**\n>   * \\fn V4L2ControlInfo::range()\n>   * \\brief Retrieve the control value range\n> @@ -151,7 +142,7 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n>  \n>  /**\n>   * \\class V4L2ControlInfoMap\n> - * \\brief A map of control ID to V4L2ControlInfo\n> + * \\brief A map of controlID to V4L2ControlInfo\n>   */\n>  \n>  /**\n> @@ -165,17 +156,69 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n>   *\n>   * \\return The populated V4L2ControlInfoMap\n>   */\n> -V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<unsigned int, V4L2ControlInfo> &&info)\n> +V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<const ControlId *, V4L2ControlInfo> &&info)\n>  {\n> -\tstd::map<unsigned int, V4L2ControlInfo>::operator=(std::move(info));\n> +\tstd::map<const ControlId *, V4L2ControlInfo>::operator=(std::move(info));\n>  \n>  \tidmap_.clear();\n>  \tfor (const auto &ctrl : *this)\n> -\t\tidmap_[ctrl.first] = &ctrl.second.id();\n> +\t\tidmap_[ctrl.first->id()] = ctrl.first;\n>  \n>  \treturn *this;\n>  }\n>  \n> +/**\n> + * \\brief Access specified element by numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return A reference to the element whose ID is equal to \\a id\n> + */\n> +V4L2ControlInfoMap::mapped_type &V4L2ControlInfoMap::at(unsigned int id)\n> +{\n> +\treturn at(idmap_.at(id));\n> +}\n> +\n> +/**\n> + * \\brief Access specified element by numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return A const reference to the element whose ID is equal to \\a id\n> + */\n> +const V4L2ControlInfoMap::mapped_type &V4L2ControlInfoMap::at(unsigned int id) const\n> +{\n> +\treturn at(idmap_.at(id));\n> +}\n> +\n> +/**\n> + * \\brief Count the number of elements matching a numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return The number of elements matching the numerical \\a id\n> + */\n> +V4L2ControlInfoMap::size_type V4L2ControlInfoMap::count(unsigned int id) const\n> +{\n> +\treturn count(idmap_.at(id));\n> +}\n> +\n> +/**\n> + * \\brief Find the element matching a numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return An iterator pointing to the element matching the numerical \\a id, or\n> + * end() if no such element exists\n> + */\n> +V4L2ControlInfoMap::iterator V4L2ControlInfoMap::find(unsigned int id)\n> +{\n> +\treturn find(idmap_.at(id));\n> +}\n> +\n> +/**\n> + * \\brief Find the element matching a numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return A const iterator pointing to the element matching the numerical\n> + * \\a id, or end() if no such element exists\n> + */\n> +V4L2ControlInfoMap::const_iterator V4L2ControlInfoMap::find(unsigned int id) const\n> +{\n> +\treturn find(idmap_.at(id));\n> +}\n> +\n>  /**\n>   * \\fn const ControlIdMap &V4L2ControlInfoMap::idmap() const\n>   * \\brief Retrieve the ControlId map\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 144a60b4fe93..4bb7d5950f3a 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -171,7 +171,6 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \tif (count == 0)\n>  \t\treturn 0;\n>  \n> -\tconst V4L2ControlInfo *controlInfo[count];\n>  \tstruct v4l2_ext_control v4l2Ctrls[count];\n>  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n>  \n> @@ -185,10 +184,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \t\t\treturn -EINVAL;\n>  \t\t}\n>  \n> -\t\tconst V4L2ControlInfo *info = &iter->second;\n> -\t\tcontrolInfo[i] = info;\n>  \t\tv4l2Ctrls[i].id = id->id();\n> -\n>  \t\ti++;\n>  \t}\n>  \n> @@ -215,7 +211,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \t\tret = errorIdx;\n>  \t}\n>  \n> -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> +\tupdateControls(ctrls, v4l2Ctrls, count);\n>  \n>  \treturn ret;\n>  }\n> @@ -249,7 +245,6 @@ int V4L2Device::setControls(ControlList *ctrls)\n>  \tif (count == 0)\n>  \t\treturn 0;\n>  \n> -\tconst V4L2ControlInfo *controlInfo[count];\n>  \tstruct v4l2_ext_control v4l2Ctrls[count];\n>  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n>  \n> @@ -263,13 +258,11 @@ int V4L2Device::setControls(ControlList *ctrls)\n>  \t\t\treturn -EINVAL;\n>  \t\t}\n>  \n> -\t\tconst V4L2ControlInfo *info = &iter->second;\n> -\t\tcontrolInfo[i] = info;\n>  \t\tv4l2Ctrls[i].id = id->id();\n>  \n>  \t\t/* Set the v4l2_ext_control value for the write operation. */\n>  \t\tconst ControlValue &value = ctrl.second;\n> -\t\tswitch (info->id().type()) {\n> +\t\tswitch (id->type()) {\n>  \t\tcase ControlTypeInteger64:\n>  \t\t\tv4l2Ctrls[i].value64 = value.get<int64_t>();\n>  \t\t\tbreak;\n> @@ -308,7 +301,7 @@ int V4L2Device::setControls(ControlList *ctrls)\n>  \t\tret = errorIdx;\n>  \t}\n>  \n> -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> +\tupdateControls(ctrls, v4l2Ctrls, count);\n>  \n>  \treturn ret;\n>  }\n> @@ -349,7 +342,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n>   */\n>  void V4L2Device::listControls()\n>  {\n> -\tstd::map<unsigned int, V4L2ControlInfo> ctrls;\n> +\tstd::map<const ControlId *, V4L2ControlInfo> ctrls;\n>  \tstruct v4l2_query_ext_ctrl ctrl = {};\n>  \n>  \t/* \\todo Add support for menu and compound controls. */\n> @@ -388,8 +381,8 @@ void V4L2Device::listControls()\n>  \n>  \t\tcontrolIds_.emplace_back(utils::make_unique<V4L2ControlId>(ctrl));\n>  \t\tctrls.emplace(std::piecewise_construct,\n> -\t\t\t      std::forward_as_tuple(ctrl.id),\n> -\t\t\t      std::forward_as_tuple(*controlIds_.back().get(), ctrl));\n> +\t\t\t      std::forward_as_tuple(controlIds_.back().get()),\n> +\t\t\t      std::forward_as_tuple(ctrl));\n>  \t}\n>  \n>  \tcontrols_ = std::move(ctrls);\n> @@ -399,12 +392,10 @@ void V4L2Device::listControls()\n>   * \\brief Update the value of the first \\a count V4L2 controls in \\a ctrls using\n>   * values in \\a v4l2Ctrls\n>   * \\param[inout] ctrls List of V4L2 controls to update\n> - * \\param[in] controlInfo List of V4L2 control information\n>   * \\param[in] v4l2Ctrls List of V4L2 extended controls as returned by the driver\n>   * \\param[in] count The number of controls to update\n>   */\n>  void V4L2Device::updateControls(ControlList *ctrls,\n> -\t\t\t\tconst V4L2ControlInfo **controlInfo,\n>  \t\t\t\tconst struct v4l2_ext_control *v4l2Ctrls,\n>  \t\t\t\tunsigned int count)\n>  {\n> @@ -414,10 +405,10 @@ void V4L2Device::updateControls(ControlList *ctrls,\n>  \t\t\tbreak;\n>  \n>  \t\tconst struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n> -\t\tconst V4L2ControlInfo *info = controlInfo[i];\n> +\t\tconst ControlId *id = ctrl.first;\n>  \t\tControlValue &value = ctrl.second;\n>  \n> -\t\tswitch (info->id().type()) {\n> +\t\tswitch (id->type()) {\n>  \t\tcase ControlTypeInteger64:\n>  \t\t\tvalue.set<int64_t>(v4l2Ctrl->value64);\n>  \t\t\tbreak;\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D4BB1600F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Oct 2019 02:17:35 +0200 (CEST)","by mail-lj1-x243.google.com with SMTP id m7so18338207lji.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 14 Oct 2019 17:17:35 -0700 (PDT)","from localhost (h-93-159.A463.priv.bahnhof.se. [46.59.93.159])\n\tby smtp.gmail.com with ESMTPSA id\n\ta23sm4549217lfl.66.2019.10.14.17.17.34\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 14 Oct 2019 17:17:34 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=WY6JKTbZTFyk59vmXpBpLsBHd+ZqXPn5ioYITR4N4qU=;\n\tb=SHzEx2hRKXwcaglPUTnSBqApwD+KQWYl3Mj6cBC0Xvf5+dh221iKyFjEgyGMetTwgi\n\tV66YQLtGrxr7dZ9NurmZlJDVqBH6b+8hgmhOFuBvHoz85hl3RULhfIMMw0EmZe6PK8mA\n\th7fOHWTlmzOq4n9adJm/oZyx/jziCukcKBJqVpZdwPrOkznsRp9FDm3GjLNz32gkEjDV\n\tPWyd4lc+MhtQfYdxt2KmUlq88avFYuYm88wnXE6/vN5txD3klXdrx3QIsW9L/jhmbQjE\n\tvoioL+LwIGXygXFif1u5ES5eh77oeaYc97HD2sKeXemzhJCJrx0NtQ5BMBbn28bN+y/R\n\tz56g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=WY6JKTbZTFyk59vmXpBpLsBHd+ZqXPn5ioYITR4N4qU=;\n\tb=fR65BOkY1602vBcPMVKo4uD/dR+nfxDG/gZLCc7S54r7F4RtkeCSMiSrSW5v7J3X7r\n\tummeREzrVnyeYcVQNl12BigJECcSTnUiax4Xv8d6nJGpMRJyg07YoZzFAwjQbOh5OnWG\n\tAtBaHBQyP2BbDKFPWVqd2sv+by/c6nUSAkYk2g4uWQqYJQiolPhDF9PjUQzdKWqu0+gM\n\tq0w7xSRg4nECLu8bg0pQMqoMxHGlzrQdYvMDl8fXE1Ig29IxaPD7kKWDu1H/kbihhQOt\n\tCgfJoXu88mCw40otnQYFtH/tPLzu0cHbl85MR6cJd+Z7UXoxpjpRYRy0MwKD28QoiDIx\n\tnhzg==","X-Gm-Message-State":"APjAAAUZrw9plqxDfGBcdNYt+oOAaPcpOE4GzXXSibkCeUnKmdFQX3Vd\n\t+rHBgXLtssmmG03sJJkdqI+UNg==","X-Google-Smtp-Source":"APXvYqxnmnaqTID8uy68612h+0ZtBXtXcS1W4dZyboVnJinMvg4S75onWJouD5jyMBNbl5D2fv8Nyg==","X-Received":"by 2002:a2e:5354:: with SMTP id\n\tt20mr18175108ljd.44.1571098654955; \n\tMon, 14 Oct 2019 17:17:34 -0700 (PDT)","Date":"Tue, 15 Oct 2019 02:17:33 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191015001733.GD5976@bigcity.dyn.berto.se>","References":"<20191013232755.3292-1-laurent.pinchart@ideasonboard.com>\n\t<20191013232755.3292-5-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20191013232755.3292-5-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","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":"Tue, 15 Oct 2019 00:17:36 -0000"}},{"id":2915,"web_url":"https://patchwork.libcamera.org/comment/2915/","msgid":"<20191015151606.krqqw4ure5pcxopc@uno.localdomain>","date":"2019-10-15T15:16:06","subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Mon, Oct 14, 2019 at 02:27:50AM +0300, Laurent Pinchart wrote:\n> To bring the libcamera and V4L2 control info maps closer, index the\n> latter by ControlId * like the former. As V4L2ControlInfoMap is widely\n> indexed by V4L2 numerical IDs, add accessors based on numerical IDs.\n>\n> This allows complete removal of the ControId pointer from the\n> V4L2ControlInfo, as the ControId is accessible as the key when iterating\n> over the map. A handful of users have to be modified to adapt to the\n> change.\n>\n> The controlInfo argument from V4L2Device::updateControls() can also be\n> removed as it itsn't used anymore.\n\nGreat! I had this in my early serialization work and I really wanted\nto see the v4l2_device control handling simplified\n\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/include/v4l2_controls.h | 40 +++++++++------\n>  src/libcamera/include/v4l2_device.h   |  1 -\n>  src/libcamera/pipeline/uvcvideo.cpp   |  2 +-\n>  src/libcamera/pipeline/vimc.cpp       |  2 +-\n>  src/libcamera/v4l2_controls.cpp       | 71 +++++++++++++++++++++------\n>  src/libcamera/v4l2_device.cpp         | 25 +++-------\n>  6 files changed, 92 insertions(+), 49 deletions(-)\n>\n> diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h\n> index 4d7ac1a133c7..ca7217501256 100644\n> --- a/src/libcamera/include/v4l2_controls.h\n> +++ b/src/libcamera/include/v4l2_controls.h\n> @@ -28,31 +28,41 @@ public:\n>  class V4L2ControlInfo\n>  {\n>  public:\n> -\tV4L2ControlInfo(const V4L2ControlId &id,\n> -\t\t\tconst struct v4l2_query_ext_ctrl &ctrl);\n> +\tV4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl);\n>\n> -\tconst ControlId &id() const { return *id_; }\n>  \tconst ControlRange &range() const { return range_; }\n>\n>  private:\n> -\tconst V4L2ControlId *id_;\n>  \tControlRange range_;\n>  };\n>\n> -class V4L2ControlInfoMap : private std::map<unsigned int, V4L2ControlInfo>\n> +class V4L2ControlInfoMap : private std::map<const ControlId *, V4L2ControlInfo>\n>  {\n>  public:\n> -\tV4L2ControlInfoMap &operator=(std::map<unsigned int, V4L2ControlInfo> &&info);\n> +\tV4L2ControlInfoMap &operator=(std::map<const ControlId *, V4L2ControlInfo> &&info);\n>\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::begin;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::cbegin;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::end;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::cend;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::at;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::empty;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::size;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::count;\n> -\tusing std::map<unsigned int, V4L2ControlInfo>::find;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::key_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::mapped_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::value_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::size_type;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::iterator;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::const_iterator;\n> +\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::begin;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::cbegin;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::end;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::cend;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::at;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::empty;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::size;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::count;\n> +\tusing std::map<const ControlId *, V4L2ControlInfo>::find;\n> +\n> +\tmapped_type &at(unsigned int key);\n> +\tconst mapped_type &at(unsigned int key) const;\n> +\tsize_type count(unsigned int key) const;\n> +\titerator find(unsigned int key);\n> +\tconst_iterator find(unsigned int key) const;\n>\n>  \tconst ControlIdMap &idmap() const { return idmap_; }\n>\n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index 5a5b85827f23..f30b1c2cde34 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -45,7 +45,6 @@ protected:\n>  private:\n>  \tvoid listControls();\n>  \tvoid updateControls(ControlList *ctrls,\n> -\t\t\t    const V4L2ControlInfo **controlInfo,\n>  \t\t\t    const struct v4l2_ext_control *v4l2Ctrls,\n>  \t\t\t    unsigned int count);\n>\n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index 547ad5ca4e55..4d76b5fd9347 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -340,7 +340,7 @@ int UVCCameraData::init(MediaEntity *entity)\n>  \t\tconst V4L2ControlInfo &info = ctrl.second;\n>  \t\tconst ControlId *id;\n>\n> -\t\tswitch (info.id().id()) {\n> +\t\tswitch (ctrl.first->id()) {\n>  \t\tcase V4L2_CID_BRIGHTNESS:\n>  \t\t\tid = &controls::Brightness;\n>  \t\t\tbreak;\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index 53d00360eb6e..78c0fe5ae509 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -416,7 +416,7 @@ int VimcCameraData::init(MediaDevice *media)\n>  \t\tconst V4L2ControlInfo &info = ctrl.second;\n>  \t\tconst ControlId *id;\n>\n> -\t\tswitch (info.id().id()) {\n> +\t\tswitch (ctrl.first->id()) {\n>  \t\tcase V4L2_CID_BRIGHTNESS:\n>  \t\t\tid = &controls::Brightness;\n>  \t\t\tbreak;\n> diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\n> index 12c4fb271ba5..9a5e4830db91 100644\n> --- a/src/libcamera/v4l2_controls.cpp\n> +++ b/src/libcamera/v4l2_controls.cpp\n> @@ -122,12 +122,9 @@ V4L2ControlId::V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl)\n>\n>  /**\n>   * \\brief Construct a V4L2ControlInfo from a struct v4l2_query_ext_ctrl\n> - * \\param[in] id The V4L2 control ID\n>   * \\param[in] ctrl The struct v4l2_query_ext_ctrl as returned by the kernel\n>   */\n> -V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n> -\t\t\t\t const struct v4l2_query_ext_ctrl &ctrl)\n> -\t: id_(&id)\n> +V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n>  {\n>  \tif (ctrl.type == V4L2_CTRL_TYPE_INTEGER64)\n>  \t\trange_ = ControlRange(static_cast<int64_t>(ctrl.minimum),\n> @@ -137,12 +134,6 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n>  \t\t\t\t      static_cast<int32_t>(ctrl.maximum));\n>  }\n>\n> -/**\n> - * \\fn V4L2ControlInfo::id()\n> - * \\brief Retrieve the control ID\n> - * \\return The V4L2 control ID\n> - */\n> -\n>  /**\n>   * \\fn V4L2ControlInfo::range()\n>   * \\brief Retrieve the control value range\n> @@ -151,7 +142,7 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n>\n>  /**\n>   * \\class V4L2ControlInfoMap\n> - * \\brief A map of control ID to V4L2ControlInfo\n> + * \\brief A map of controlID to V4L2ControlInfo\n>   */\n>\n>  /**\n> @@ -165,17 +156,69 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n>   *\n>   * \\return The populated V4L2ControlInfoMap\n>   */\n> -V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<unsigned int, V4L2ControlInfo> &&info)\n> +V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<const ControlId *, V4L2ControlInfo> &&info)\n>  {\n> -\tstd::map<unsigned int, V4L2ControlInfo>::operator=(std::move(info));\n> +\tstd::map<const ControlId *, V4L2ControlInfo>::operator=(std::move(info));\n>\n>  \tidmap_.clear();\n>  \tfor (const auto &ctrl : *this)\n> -\t\tidmap_[ctrl.first] = &ctrl.second.id();\n> +\t\tidmap_[ctrl.first->id()] = ctrl.first;\n>\n>  \treturn *this;\n>  }\n>\n> +/**\n> + * \\brief Access specified element by numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return A reference to the element whose ID is equal to \\a id\n> + */\n> +V4L2ControlInfoMap::mapped_type &V4L2ControlInfoMap::at(unsigned int id)\n> +{\n> +\treturn at(idmap_.at(id));\n> +}\n> +\n> +/**\n> + * \\brief Access specified element by numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return A const reference to the element whose ID is equal to \\a id\n> + */\n> +const V4L2ControlInfoMap::mapped_type &V4L2ControlInfoMap::at(unsigned int id) const\n> +{\n> +\treturn at(idmap_.at(id));\n> +}\n> +\n> +/**\n> + * \\brief Count the number of elements matching a numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return The number of elements matching the numerical \\a id\n> + */\n> +V4L2ControlInfoMap::size_type V4L2ControlInfoMap::count(unsigned int id) const\n> +{\n> +\treturn count(idmap_.at(id));\n> +}\n\nCan we have multiple elements indexed by the same id ?\n\n> +\n> +/**\n> + * \\brief Find the element matching a numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return An iterator pointing to the element matching the numerical \\a id, or\n> + * end() if no such element exists\n> + */\n> +V4L2ControlInfoMap::iterator V4L2ControlInfoMap::find(unsigned int id)\n> +{\n> +\treturn find(idmap_.at(id));\n> +}\n> +\n> +/**\n> + * \\brief Find the element matching a numerical ID\n> + * \\param[in] id The numerical ID\n> + * \\return A const iterator pointing to the element matching the numerical\n> + * \\a id, or end() if no such element exists\n> + */\n> +V4L2ControlInfoMap::const_iterator V4L2ControlInfoMap::find(unsigned int id) const\n> +{\n> +\treturn find(idmap_.at(id));\n> +}\n> +\n>  /**\n>   * \\fn const ControlIdMap &V4L2ControlInfoMap::idmap() const\n>   * \\brief Retrieve the ControlId map\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 144a60b4fe93..4bb7d5950f3a 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -171,7 +171,6 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \tif (count == 0)\n>  \t\treturn 0;\n>\n> -\tconst V4L2ControlInfo *controlInfo[count];\n>  \tstruct v4l2_ext_control v4l2Ctrls[count];\n>  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n>\n> @@ -185,10 +184,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \t\t\treturn -EINVAL;\n>  \t\t}\n>\n> -\t\tconst V4L2ControlInfo *info = &iter->second;\n> -\t\tcontrolInfo[i] = info;\n>  \t\tv4l2Ctrls[i].id = id->id();\n> -\n>  \t\ti++;\n>  \t}\n>\n> @@ -215,7 +211,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \t\tret = errorIdx;\n>  \t}\n>\n> -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> +\tupdateControls(ctrls, v4l2Ctrls, count);\n>\n>  \treturn ret;\n>  }\n> @@ -249,7 +245,6 @@ int V4L2Device::setControls(ControlList *ctrls)\n>  \tif (count == 0)\n>  \t\treturn 0;\n>\n> -\tconst V4L2ControlInfo *controlInfo[count];\n>  \tstruct v4l2_ext_control v4l2Ctrls[count];\n>  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n>\n> @@ -263,13 +258,11 @@ int V4L2Device::setControls(ControlList *ctrls)\n>  \t\t\treturn -EINVAL;\n>  \t\t}\n>\n> -\t\tconst V4L2ControlInfo *info = &iter->second;\n> -\t\tcontrolInfo[i] = info;\n>  \t\tv4l2Ctrls[i].id = id->id();\n>\n>  \t\t/* Set the v4l2_ext_control value for the write operation. */\n>  \t\tconst ControlValue &value = ctrl.second;\n> -\t\tswitch (info->id().type()) {\n> +\t\tswitch (id->type()) {\n>  \t\tcase ControlTypeInteger64:\n>  \t\t\tv4l2Ctrls[i].value64 = value.get<int64_t>();\n>  \t\t\tbreak;\n> @@ -308,7 +301,7 @@ int V4L2Device::setControls(ControlList *ctrls)\n>  \t\tret = errorIdx;\n>  \t}\n>\n> -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> +\tupdateControls(ctrls, v4l2Ctrls, count);\n>\n>  \treturn ret;\n>  }\n> @@ -349,7 +342,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n>   */\n>  void V4L2Device::listControls()\n>  {\n> -\tstd::map<unsigned int, V4L2ControlInfo> ctrls;\n> +\tstd::map<const ControlId *, V4L2ControlInfo> ctrls;\n>  \tstruct v4l2_query_ext_ctrl ctrl = {};\n>\n>  \t/* \\todo Add support for menu and compound controls. */\n> @@ -388,8 +381,8 @@ void V4L2Device::listControls()\n>\n>  \t\tcontrolIds_.emplace_back(utils::make_unique<V4L2ControlId>(ctrl));\n\nNot in this patch but I just noticed: doesn't this create a\nV4L2ControlId while we should instead forward the argument to its\nconstructor ? Well, I think the unique_ptr<> here plays a role, and I\ncannot suggest a way around it...\n\nAnyway, the change is good and desirable:\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n   j\n\n>  \t\tctrls.emplace(std::piecewise_construct,\n> -\t\t\t      std::forward_as_tuple(ctrl.id),\n> -\t\t\t      std::forward_as_tuple(*controlIds_.back().get(), ctrl));\n> +\t\t\t      std::forward_as_tuple(controlIds_.back().get()),\n> +\t\t\t      std::forward_as_tuple(ctrl));\n>  \t}\n>\n>  \tcontrols_ = std::move(ctrls);\n> @@ -399,12 +392,10 @@ void V4L2Device::listControls()\n>   * \\brief Update the value of the first \\a count V4L2 controls in \\a ctrls using\n>   * values in \\a v4l2Ctrls\n>   * \\param[inout] ctrls List of V4L2 controls to update\n> - * \\param[in] controlInfo List of V4L2 control information\n>   * \\param[in] v4l2Ctrls List of V4L2 extended controls as returned by the driver\n>   * \\param[in] count The number of controls to update\n>   */\n>  void V4L2Device::updateControls(ControlList *ctrls,\n> -\t\t\t\tconst V4L2ControlInfo **controlInfo,\n>  \t\t\t\tconst struct v4l2_ext_control *v4l2Ctrls,\n>  \t\t\t\tunsigned int count)\n>  {\n> @@ -414,10 +405,10 @@ void V4L2Device::updateControls(ControlList *ctrls,\n>  \t\t\tbreak;\n>\n>  \t\tconst struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n> -\t\tconst V4L2ControlInfo *info = controlInfo[i];\n> +\t\tconst ControlId *id = ctrl.first;\n>  \t\tControlValue &value = ctrl.second;\n>\n> -\t\tswitch (info->id().type()) {\n> +\t\tswitch (id->type()) {\n>  \t\tcase ControlTypeInteger64:\n>  \t\t\tvalue.set<int64_t>(v4l2Ctrl->value64);\n>  \t\t\tbreak;\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 856B261562\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Oct 2019 17:14:18 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 1BAFE40003;\n\tTue, 15 Oct 2019 15:14:17 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Tue, 15 Oct 2019 17:16:06 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191015151606.krqqw4ure5pcxopc@uno.localdomain>","References":"<20191013232755.3292-1-laurent.pinchart@ideasonboard.com>\n\t<20191013232755.3292-5-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"govslwzxwwumqyyp\"","Content-Disposition":"inline","In-Reply-To":"<20191013232755.3292-5-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","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":"Tue, 15 Oct 2019 15:14:18 -0000"}},{"id":2917,"web_url":"https://patchwork.libcamera.org/comment/2917/","msgid":"<20191015153118.GE4875@pendragon.ideasonboard.com>","date":"2019-10-15T15:31:18","subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Tue, Oct 15, 2019 at 05:16:06PM +0200, Jacopo Mondi wrote:\n> On Mon, Oct 14, 2019 at 02:27:50AM +0300, Laurent Pinchart wrote:\n> > To bring the libcamera and V4L2 control info maps closer, index the\n> > latter by ControlId * like the former. As V4L2ControlInfoMap is widely\n> > indexed by V4L2 numerical IDs, add accessors based on numerical IDs.\n> >\n> > This allows complete removal of the ControId pointer from the\n> > V4L2ControlInfo, as the ControId is accessible as the key when iterating\n> > over the map. A handful of users have to be modified to adapt to the\n> > change.\n> >\n> > The controlInfo argument from V4L2Device::updateControls() can also be\n> > removed as it itsn't used anymore.\n> \n> Great! I had this in my early serialization work and I really wanted\n> to see the v4l2_device control handling simplified\n> \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/libcamera/include/v4l2_controls.h | 40 +++++++++------\n> >  src/libcamera/include/v4l2_device.h   |  1 -\n> >  src/libcamera/pipeline/uvcvideo.cpp   |  2 +-\n> >  src/libcamera/pipeline/vimc.cpp       |  2 +-\n> >  src/libcamera/v4l2_controls.cpp       | 71 +++++++++++++++++++++------\n> >  src/libcamera/v4l2_device.cpp         | 25 +++-------\n> >  6 files changed, 92 insertions(+), 49 deletions(-)\n> >\n> > diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h\n> > index 4d7ac1a133c7..ca7217501256 100644\n> > --- a/src/libcamera/include/v4l2_controls.h\n> > +++ b/src/libcamera/include/v4l2_controls.h\n> > @@ -28,31 +28,41 @@ public:\n> >  class V4L2ControlInfo\n> >  {\n> >  public:\n> > -\tV4L2ControlInfo(const V4L2ControlId &id,\n> > -\t\t\tconst struct v4l2_query_ext_ctrl &ctrl);\n> > +\tV4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl);\n> >\n> > -\tconst ControlId &id() const { return *id_; }\n> >  \tconst ControlRange &range() const { return range_; }\n> >\n> >  private:\n> > -\tconst V4L2ControlId *id_;\n> >  \tControlRange range_;\n> >  };\n> >\n> > -class V4L2ControlInfoMap : private std::map<unsigned int, V4L2ControlInfo>\n> > +class V4L2ControlInfoMap : private std::map<const ControlId *, V4L2ControlInfo>\n> >  {\n> >  public:\n> > -\tV4L2ControlInfoMap &operator=(std::map<unsigned int, V4L2ControlInfo> &&info);\n> > +\tV4L2ControlInfoMap &operator=(std::map<const ControlId *, V4L2ControlInfo> &&info);\n> >\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::begin;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::cbegin;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::end;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::cend;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::at;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::empty;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::size;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::count;\n> > -\tusing std::map<unsigned int, V4L2ControlInfo>::find;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::key_type;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::mapped_type;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::value_type;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::size_type;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::iterator;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::const_iterator;\n> > +\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::begin;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::cbegin;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::end;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::cend;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::at;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::empty;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::size;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::count;\n> > +\tusing std::map<const ControlId *, V4L2ControlInfo>::find;\n> > +\n> > +\tmapped_type &at(unsigned int key);\n> > +\tconst mapped_type &at(unsigned int key) const;\n> > +\tsize_type count(unsigned int key) const;\n> > +\titerator find(unsigned int key);\n> > +\tconst_iterator find(unsigned int key) const;\n> >\n> >  \tconst ControlIdMap &idmap() const { return idmap_; }\n> >\n> > diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> > index 5a5b85827f23..f30b1c2cde34 100644\n> > --- a/src/libcamera/include/v4l2_device.h\n> > +++ b/src/libcamera/include/v4l2_device.h\n> > @@ -45,7 +45,6 @@ protected:\n> >  private:\n> >  \tvoid listControls();\n> >  \tvoid updateControls(ControlList *ctrls,\n> > -\t\t\t    const V4L2ControlInfo **controlInfo,\n> >  \t\t\t    const struct v4l2_ext_control *v4l2Ctrls,\n> >  \t\t\t    unsigned int count);\n> >\n> > diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> > index 547ad5ca4e55..4d76b5fd9347 100644\n> > --- a/src/libcamera/pipeline/uvcvideo.cpp\n> > +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> > @@ -340,7 +340,7 @@ int UVCCameraData::init(MediaEntity *entity)\n> >  \t\tconst V4L2ControlInfo &info = ctrl.second;\n> >  \t\tconst ControlId *id;\n> >\n> > -\t\tswitch (info.id().id()) {\n> > +\t\tswitch (ctrl.first->id()) {\n> >  \t\tcase V4L2_CID_BRIGHTNESS:\n> >  \t\t\tid = &controls::Brightness;\n> >  \t\t\tbreak;\n> > diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> > index 53d00360eb6e..78c0fe5ae509 100644\n> > --- a/src/libcamera/pipeline/vimc.cpp\n> > +++ b/src/libcamera/pipeline/vimc.cpp\n> > @@ -416,7 +416,7 @@ int VimcCameraData::init(MediaDevice *media)\n> >  \t\tconst V4L2ControlInfo &info = ctrl.second;\n> >  \t\tconst ControlId *id;\n> >\n> > -\t\tswitch (info.id().id()) {\n> > +\t\tswitch (ctrl.first->id()) {\n> >  \t\tcase V4L2_CID_BRIGHTNESS:\n> >  \t\t\tid = &controls::Brightness;\n> >  \t\t\tbreak;\n> > diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\n> > index 12c4fb271ba5..9a5e4830db91 100644\n> > --- a/src/libcamera/v4l2_controls.cpp\n> > +++ b/src/libcamera/v4l2_controls.cpp\n> > @@ -122,12 +122,9 @@ V4L2ControlId::V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl)\n> >\n> >  /**\n> >   * \\brief Construct a V4L2ControlInfo from a struct v4l2_query_ext_ctrl\n> > - * \\param[in] id The V4L2 control ID\n> >   * \\param[in] ctrl The struct v4l2_query_ext_ctrl as returned by the kernel\n> >   */\n> > -V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n> > -\t\t\t\t const struct v4l2_query_ext_ctrl &ctrl)\n> > -\t: id_(&id)\n> > +V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n> >  {\n> >  \tif (ctrl.type == V4L2_CTRL_TYPE_INTEGER64)\n> >  \t\trange_ = ControlRange(static_cast<int64_t>(ctrl.minimum),\n> > @@ -137,12 +134,6 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n> >  \t\t\t\t      static_cast<int32_t>(ctrl.maximum));\n> >  }\n> >\n> > -/**\n> > - * \\fn V4L2ControlInfo::id()\n> > - * \\brief Retrieve the control ID\n> > - * \\return The V4L2 control ID\n> > - */\n> > -\n> >  /**\n> >   * \\fn V4L2ControlInfo::range()\n> >   * \\brief Retrieve the control value range\n> > @@ -151,7 +142,7 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n> >\n> >  /**\n> >   * \\class V4L2ControlInfoMap\n> > - * \\brief A map of control ID to V4L2ControlInfo\n> > + * \\brief A map of controlID to V4L2ControlInfo\n> >   */\n> >\n> >  /**\n> > @@ -165,17 +156,69 @@ V4L2ControlInfo::V4L2ControlInfo(const V4L2ControlId &id,\n> >   *\n> >   * \\return The populated V4L2ControlInfoMap\n> >   */\n> > -V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<unsigned int, V4L2ControlInfo> &&info)\n> > +V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<const ControlId *, V4L2ControlInfo> &&info)\n> >  {\n> > -\tstd::map<unsigned int, V4L2ControlInfo>::operator=(std::move(info));\n> > +\tstd::map<const ControlId *, V4L2ControlInfo>::operator=(std::move(info));\n> >\n> >  \tidmap_.clear();\n> >  \tfor (const auto &ctrl : *this)\n> > -\t\tidmap_[ctrl.first] = &ctrl.second.id();\n> > +\t\tidmap_[ctrl.first->id()] = ctrl.first;\n> >\n> >  \treturn *this;\n> >  }\n> >\n> > +/**\n> > + * \\brief Access specified element by numerical ID\n> > + * \\param[in] id The numerical ID\n> > + * \\return A reference to the element whose ID is equal to \\a id\n> > + */\n> > +V4L2ControlInfoMap::mapped_type &V4L2ControlInfoMap::at(unsigned int id)\n> > +{\n> > +\treturn at(idmap_.at(id));\n> > +}\n> > +\n> > +/**\n> > + * \\brief Access specified element by numerical ID\n> > + * \\param[in] id The numerical ID\n> > + * \\return A const reference to the element whose ID is equal to \\a id\n> > + */\n> > +const V4L2ControlInfoMap::mapped_type &V4L2ControlInfoMap::at(unsigned int id) const\n> > +{\n> > +\treturn at(idmap_.at(id));\n> > +}\n> > +\n> > +/**\n> > + * \\brief Count the number of elements matching a numerical ID\n> > + * \\param[in] id The numerical ID\n> > + * \\return The number of elements matching the numerical \\a id\n> > + */\n> > +V4L2ControlInfoMap::size_type V4L2ControlInfoMap::count(unsigned int id) const\n> > +{\n> > +\treturn count(idmap_.at(id));\n> > +}\n> \n> Can we have multiple elements indexed by the same id ?\n\nThat would require a V4L2 device to expose multiple controls with the\nsame ID. Highly unlikely given that the kernel API won't support this\n:-)\n\n> > +\n> > +/**\n> > + * \\brief Find the element matching a numerical ID\n> > + * \\param[in] id The numerical ID\n> > + * \\return An iterator pointing to the element matching the numerical \\a id, or\n> > + * end() if no such element exists\n> > + */\n> > +V4L2ControlInfoMap::iterator V4L2ControlInfoMap::find(unsigned int id)\n> > +{\n> > +\treturn find(idmap_.at(id));\n> > +}\n> > +\n> > +/**\n> > + * \\brief Find the element matching a numerical ID\n> > + * \\param[in] id The numerical ID\n> > + * \\return A const iterator pointing to the element matching the numerical\n> > + * \\a id, or end() if no such element exists\n> > + */\n> > +V4L2ControlInfoMap::const_iterator V4L2ControlInfoMap::find(unsigned int id) const\n> > +{\n> > +\treturn find(idmap_.at(id));\n> > +}\n> > +\n> >  /**\n> >   * \\fn const ControlIdMap &V4L2ControlInfoMap::idmap() const\n> >   * \\brief Retrieve the ControlId map\n> > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> > index 144a60b4fe93..4bb7d5950f3a 100644\n> > --- a/src/libcamera/v4l2_device.cpp\n> > +++ b/src/libcamera/v4l2_device.cpp\n> > @@ -171,7 +171,6 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >  \tif (count == 0)\n> >  \t\treturn 0;\n> >\n> > -\tconst V4L2ControlInfo *controlInfo[count];\n> >  \tstruct v4l2_ext_control v4l2Ctrls[count];\n> >  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> >\n> > @@ -185,10 +184,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >  \t\t\treturn -EINVAL;\n> >  \t\t}\n> >\n> > -\t\tconst V4L2ControlInfo *info = &iter->second;\n> > -\t\tcontrolInfo[i] = info;\n> >  \t\tv4l2Ctrls[i].id = id->id();\n> > -\n> >  \t\ti++;\n> >  \t}\n> >\n> > @@ -215,7 +211,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >  \t\tret = errorIdx;\n> >  \t}\n> >\n> > -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> > +\tupdateControls(ctrls, v4l2Ctrls, count);\n> >\n> >  \treturn ret;\n> >  }\n> > @@ -249,7 +245,6 @@ int V4L2Device::setControls(ControlList *ctrls)\n> >  \tif (count == 0)\n> >  \t\treturn 0;\n> >\n> > -\tconst V4L2ControlInfo *controlInfo[count];\n> >  \tstruct v4l2_ext_control v4l2Ctrls[count];\n> >  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> >\n> > @@ -263,13 +258,11 @@ int V4L2Device::setControls(ControlList *ctrls)\n> >  \t\t\treturn -EINVAL;\n> >  \t\t}\n> >\n> > -\t\tconst V4L2ControlInfo *info = &iter->second;\n> > -\t\tcontrolInfo[i] = info;\n> >  \t\tv4l2Ctrls[i].id = id->id();\n> >\n> >  \t\t/* Set the v4l2_ext_control value for the write operation. */\n> >  \t\tconst ControlValue &value = ctrl.second;\n> > -\t\tswitch (info->id().type()) {\n> > +\t\tswitch (id->type()) {\n> >  \t\tcase ControlTypeInteger64:\n> >  \t\t\tv4l2Ctrls[i].value64 = value.get<int64_t>();\n> >  \t\t\tbreak;\n> > @@ -308,7 +301,7 @@ int V4L2Device::setControls(ControlList *ctrls)\n> >  \t\tret = errorIdx;\n> >  \t}\n> >\n> > -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> > +\tupdateControls(ctrls, v4l2Ctrls, count);\n> >\n> >  \treturn ret;\n> >  }\n> > @@ -349,7 +342,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n> >   */\n> >  void V4L2Device::listControls()\n> >  {\n> > -\tstd::map<unsigned int, V4L2ControlInfo> ctrls;\n> > +\tstd::map<const ControlId *, V4L2ControlInfo> ctrls;\n> >  \tstruct v4l2_query_ext_ctrl ctrl = {};\n> >\n> >  \t/* \\todo Add support for menu and compound controls. */\n> > @@ -388,8 +381,8 @@ void V4L2Device::listControls()\n> >\n> >  \t\tcontrolIds_.emplace_back(utils::make_unique<V4L2ControlId>(ctrl));\n> \n> Not in this patch but I just noticed: doesn't this create a\n> V4L2ControlId while we should instead forward the argument to its\n> constructor ? Well, I think the unique_ptr<> here plays a role, and I\n> cannot suggest a way around it...\n\ncontrolIds_ store instance of std::unique_ptr<>, so it doesn't construct\nV4L2ControlId instances. This should, as far as I can tell, create a\nsingle V4L2ControlId. The fact that ControlId copies are now impossible\nis also a hint that no copy is taking place.\n\n> Anyway, the change is good and desirable:\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> >  \t\tctrls.emplace(std::piecewise_construct,\n> > -\t\t\t      std::forward_as_tuple(ctrl.id),\n> > -\t\t\t      std::forward_as_tuple(*controlIds_.back().get(), ctrl));\n> > +\t\t\t      std::forward_as_tuple(controlIds_.back().get()),\n> > +\t\t\t      std::forward_as_tuple(ctrl));\n> >  \t}\n> >\n> >  \tcontrols_ = std::move(ctrls);\n> > @@ -399,12 +392,10 @@ void V4L2Device::listControls()\n> >   * \\brief Update the value of the first \\a count V4L2 controls in \\a ctrls using\n> >   * values in \\a v4l2Ctrls\n> >   * \\param[inout] ctrls List of V4L2 controls to update\n> > - * \\param[in] controlInfo List of V4L2 control information\n> >   * \\param[in] v4l2Ctrls List of V4L2 extended controls as returned by the driver\n> >   * \\param[in] count The number of controls to update\n> >   */\n> >  void V4L2Device::updateControls(ControlList *ctrls,\n> > -\t\t\t\tconst V4L2ControlInfo **controlInfo,\n> >  \t\t\t\tconst struct v4l2_ext_control *v4l2Ctrls,\n> >  \t\t\t\tunsigned int count)\n> >  {\n> > @@ -414,10 +405,10 @@ void V4L2Device::updateControls(ControlList *ctrls,\n> >  \t\t\tbreak;\n> >\n> >  \t\tconst struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n> > -\t\tconst V4L2ControlInfo *info = controlInfo[i];\n> > +\t\tconst ControlId *id = ctrl.first;\n> >  \t\tControlValue &value = ctrl.second;\n> >\n> > -\t\tswitch (info->id().type()) {\n> > +\t\tswitch (id->type()) {\n> >  \t\tcase ControlTypeInteger64:\n> >  \t\t\tvalue.set<int64_t>(v4l2Ctrl->value64);\n> >  \t\t\tbreak;","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E53B61562\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Oct 2019 17:31:21 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B5132324;\n\tTue, 15 Oct 2019 17:31:20 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1571153480;\n\tbh=KxwwsAnG8rUMdvPajNEJedeXreRqRCug47uvtIw3dRY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gGmTIAzLpPMui6yBC38u36E8DR0Xe/aoamSr5sLGCCgeJRuu4Twd63oo4WGJxhPiC\n\tlWFJG8cOOvFTIWlZNaomYOffLBh3J95z3rk2zEvGksaHCY+dI0B3sBeCMFcN580eFU\n\t11H7Xw1V4fPNJppwv3c0OTEidNCUPkmHrwAal8lU=","Date":"Tue, 15 Oct 2019 18:31:18 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191015153118.GE4875@pendragon.ideasonboard.com>","References":"<20191013232755.3292-1-laurent.pinchart@ideasonboard.com>\n\t<20191013232755.3292-5-laurent.pinchart@ideasonboard.com>\n\t<20191015151606.krqqw4ure5pcxopc@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191015151606.krqqw4ure5pcxopc@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","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":"Tue, 15 Oct 2019 15:31:21 -0000"}},{"id":2918,"web_url":"https://patchwork.libcamera.org/comment/2918/","msgid":"<20191015173727.onnzllkqli6bldhd@uno.localdomain>","date":"2019-10-15T17:37:27","subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Tue, Oct 15, 2019 at 06:31:18PM +0300, Laurent Pinchart wrote:\n> Hi Jacopo,\n>\n> > > +/**\n> > > + * \\brief Count the number of elements matching a numerical ID\n> > > + * \\param[in] id The numerical ID\n> > > + * \\return The number of elements matching the numerical \\a id\n> > > + */\n> > > +V4L2ControlInfoMap::size_type V4L2ControlInfoMap::count(unsigned int id) const\n> > > +{\n> > > +\treturn count(idmap_.at(id));\n> > > +}\n> >\n> > Can we have multiple elements indexed by the same id ?\n>\n> That would require a V4L2 device to expose multiple controls with the\n> same ID. Highly unlikely given that the kernel API won't support this\n> :-)\n>\n\nThat's why I asked :) What does a count() operation does then if not\nmaking sure the control is present or not ?\n\nThanks\n   j\n\n> > > +\n> > > +/**\n> > > + * \\brief Find the element matching a numerical ID\n> > > + * \\param[in] id The numerical ID\n> > > + * \\return An iterator pointing to the element matching the numerical \\a id, or\n> > > + * end() if no such element exists\n> > > + */\n> > > +V4L2ControlInfoMap::iterator V4L2ControlInfoMap::find(unsigned int id)\n> > > +{\n> > > +\treturn find(idmap_.at(id));\n> > > +}\n> > > +\n> > > +/**\n> > > + * \\brief Find the element matching a numerical ID\n> > > + * \\param[in] id The numerical ID\n> > > + * \\return A const iterator pointing to the element matching the numerical\n> > > + * \\a id, or end() if no such element exists\n> > > + */\n> > > +V4L2ControlInfoMap::const_iterator V4L2ControlInfoMap::find(unsigned int id) const\n> > > +{\n> > > +\treturn find(idmap_.at(id));\n> > > +}\n> > > +\n> > >  /**\n> > >   * \\fn const ControlIdMap &V4L2ControlInfoMap::idmap() const\n> > >   * \\brief Retrieve the ControlId map\n> > > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> > > index 144a60b4fe93..4bb7d5950f3a 100644\n> > > --- a/src/libcamera/v4l2_device.cpp\n> > > +++ b/src/libcamera/v4l2_device.cpp\n> > > @@ -171,7 +171,6 @@ int V4L2Device::getControls(ControlList *ctrls)\n> > >  \tif (count == 0)\n> > >  \t\treturn 0;\n> > >\n> > > -\tconst V4L2ControlInfo *controlInfo[count];\n> > >  \tstruct v4l2_ext_control v4l2Ctrls[count];\n> > >  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> > >\n> > > @@ -185,10 +184,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> > >  \t\t\treturn -EINVAL;\n> > >  \t\t}\n> > >\n> > > -\t\tconst V4L2ControlInfo *info = &iter->second;\n> > > -\t\tcontrolInfo[i] = info;\n> > >  \t\tv4l2Ctrls[i].id = id->id();\n> > > -\n> > >  \t\ti++;\n> > >  \t}\n> > >\n> > > @@ -215,7 +211,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> > >  \t\tret = errorIdx;\n> > >  \t}\n> > >\n> > > -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> > > +\tupdateControls(ctrls, v4l2Ctrls, count);\n> > >\n> > >  \treturn ret;\n> > >  }\n> > > @@ -249,7 +245,6 @@ int V4L2Device::setControls(ControlList *ctrls)\n> > >  \tif (count == 0)\n> > >  \t\treturn 0;\n> > >\n> > > -\tconst V4L2ControlInfo *controlInfo[count];\n> > >  \tstruct v4l2_ext_control v4l2Ctrls[count];\n> > >  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> > >\n> > > @@ -263,13 +258,11 @@ int V4L2Device::setControls(ControlList *ctrls)\n> > >  \t\t\treturn -EINVAL;\n> > >  \t\t}\n> > >\n> > > -\t\tconst V4L2ControlInfo *info = &iter->second;\n> > > -\t\tcontrolInfo[i] = info;\n> > >  \t\tv4l2Ctrls[i].id = id->id();\n> > >\n> > >  \t\t/* Set the v4l2_ext_control value for the write operation. */\n> > >  \t\tconst ControlValue &value = ctrl.second;\n> > > -\t\tswitch (info->id().type()) {\n> > > +\t\tswitch (id->type()) {\n> > >  \t\tcase ControlTypeInteger64:\n> > >  \t\t\tv4l2Ctrls[i].value64 = value.get<int64_t>();\n> > >  \t\t\tbreak;\n> > > @@ -308,7 +301,7 @@ int V4L2Device::setControls(ControlList *ctrls)\n> > >  \t\tret = errorIdx;\n> > >  \t}\n> > >\n> > > -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> > > +\tupdateControls(ctrls, v4l2Ctrls, count);\n> > >\n> > >  \treturn ret;\n> > >  }\n> > > @@ -349,7 +342,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n> > >   */\n> > >  void V4L2Device::listControls()\n> > >  {\n> > > -\tstd::map<unsigned int, V4L2ControlInfo> ctrls;\n> > > +\tstd::map<const ControlId *, V4L2ControlInfo> ctrls;\n> > >  \tstruct v4l2_query_ext_ctrl ctrl = {};\n> > >\n> > >  \t/* \\todo Add support for menu and compound controls. */\n> > > @@ -388,8 +381,8 @@ void V4L2Device::listControls()\n> > >\n> > >  \t\tcontrolIds_.emplace_back(utils::make_unique<V4L2ControlId>(ctrl));\n> >\n> > Not in this patch but I just noticed: doesn't this create a\n> > V4L2ControlId while we should instead forward the argument to its\n> > constructor ? Well, I think the unique_ptr<> here plays a role, and I\n> > cannot suggest a way around it...\n>\n> controlIds_ store instance of std::unique_ptr<>, so it doesn't construct\n> V4L2ControlId instances. This should, as far as I can tell, create a\n> single V4L2ControlId. The fact that ControlId copies are now impossible\n> is also a hint that no copy is taking place.\n>\n> > Anyway, the change is good and desirable:\n> > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> >\n> > >  \t\tctrls.emplace(std::piecewise_construct,\n> > > -\t\t\t      std::forward_as_tuple(ctrl.id),\n> > > -\t\t\t      std::forward_as_tuple(*controlIds_.back().get(), ctrl));\n> > > +\t\t\t      std::forward_as_tuple(controlIds_.back().get()),\n> > > +\t\t\t      std::forward_as_tuple(ctrl));\n> > >  \t}\n> > >\n> > >  \tcontrols_ = std::move(ctrls);\n> > > @@ -399,12 +392,10 @@ void V4L2Device::listControls()\n> > >   * \\brief Update the value of the first \\a count V4L2 controls in \\a ctrls using\n> > >   * values in \\a v4l2Ctrls\n> > >   * \\param[inout] ctrls List of V4L2 controls to update\n> > > - * \\param[in] controlInfo List of V4L2 control information\n> > >   * \\param[in] v4l2Ctrls List of V4L2 extended controls as returned by the driver\n> > >   * \\param[in] count The number of controls to update\n> > >   */\n> > >  void V4L2Device::updateControls(ControlList *ctrls,\n> > > -\t\t\t\tconst V4L2ControlInfo **controlInfo,\n> > >  \t\t\t\tconst struct v4l2_ext_control *v4l2Ctrls,\n> > >  \t\t\t\tunsigned int count)\n> > >  {\n> > > @@ -414,10 +405,10 @@ void V4L2Device::updateControls(ControlList *ctrls,\n> > >  \t\t\tbreak;\n> > >\n> > >  \t\tconst struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n> > > -\t\tconst V4L2ControlInfo *info = controlInfo[i];\n> > > +\t\tconst ControlId *id = ctrl.first;\n> > >  \t\tControlValue &value = ctrl.second;\n> > >\n> > > -\t\tswitch (info->id().type()) {\n> > > +\t\tswitch (id->type()) {\n> > >  \t\tcase ControlTypeInteger64:\n> > >  \t\t\tvalue.set<int64_t>(v4l2Ctrl->value64);\n> > >  \t\t\tbreak;\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2600161562\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Oct 2019 19:35:39 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id A73AC240006;\n\tTue, 15 Oct 2019 17:35:38 +0000 (UTC)"],"Date":"Tue, 15 Oct 2019 19:37:27 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191015173727.onnzllkqli6bldhd@uno.localdomain>","References":"<20191013232755.3292-1-laurent.pinchart@ideasonboard.com>\n\t<20191013232755.3292-5-laurent.pinchart@ideasonboard.com>\n\t<20191015151606.krqqw4ure5pcxopc@uno.localdomain>\n\t<20191015153118.GE4875@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"c5nkxcb4iawcsxer\"","Content-Disposition":"inline","In-Reply-To":"<20191015153118.GE4875@pendragon.ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","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":"Tue, 15 Oct 2019 17:35:39 -0000"}},{"id":2922,"web_url":"https://patchwork.libcamera.org/comment/2922/","msgid":"<20191015180827.GP4875@pendragon.ideasonboard.com>","date":"2019-10-15T18:08:27","subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Tue, Oct 15, 2019 at 07:37:27PM +0200, Jacopo Mondi wrote:\n> On Tue, Oct 15, 2019 at 06:31:18PM +0300, Laurent Pinchart wrote:\n> >>> +/**\n> >>> + * \\brief Count the number of elements matching a numerical ID\n> >>> + * \\param[in] id The numerical ID\n> >>> + * \\return The number of elements matching the numerical \\a id\n> >>> + */\n> >>> +V4L2ControlInfoMap::size_type V4L2ControlInfoMap::count(unsigned int id) const\n> >>> +{\n> >>> +\treturn count(idmap_.at(id));\n> >>> +}\n> >>\n> >> Can we have multiple elements indexed by the same id ?\n> >\n> > That would require a V4L2 device to expose multiple controls with the\n> > same ID. Highly unlikely given that the kernel API won't support this\n> > :-)\n> \n> That's why I asked :) What does a count() operation does then if not\n> making sure the control is present or not ?\n\nOn a std::map(), count() always returns 0 or 1.\n\n> >>> +\n> >>> +/**\n> >>> + * \\brief Find the element matching a numerical ID\n> >>> + * \\param[in] id The numerical ID\n> >>> + * \\return An iterator pointing to the element matching the numerical \\a id, or\n> >>> + * end() if no such element exists\n> >>> + */\n> >>> +V4L2ControlInfoMap::iterator V4L2ControlInfoMap::find(unsigned int id)\n> >>> +{\n> >>> +\treturn find(idmap_.at(id));\n> >>> +}\n> >>> +\n> >>> +/**\n> >>> + * \\brief Find the element matching a numerical ID\n> >>> + * \\param[in] id The numerical ID\n> >>> + * \\return A const iterator pointing to the element matching the numerical\n> >>> + * \\a id, or end() if no such element exists\n> >>> + */\n> >>> +V4L2ControlInfoMap::const_iterator V4L2ControlInfoMap::find(unsigned int id) const\n> >>> +{\n> >>> +\treturn find(idmap_.at(id));\n> >>> +}\n> >>> +\n> >>>  /**\n> >>>   * \\fn const ControlIdMap &V4L2ControlInfoMap::idmap() const\n> >>>   * \\brief Retrieve the ControlId map\n> >>> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> >>> index 144a60b4fe93..4bb7d5950f3a 100644\n> >>> --- a/src/libcamera/v4l2_device.cpp\n> >>> +++ b/src/libcamera/v4l2_device.cpp\n> >>> @@ -171,7 +171,6 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >>>  \tif (count == 0)\n> >>>  \t\treturn 0;\n> >>>\n> >>> -\tconst V4L2ControlInfo *controlInfo[count];\n> >>>  \tstruct v4l2_ext_control v4l2Ctrls[count];\n> >>>  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> >>>\n> >>> @@ -185,10 +184,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >>>  \t\t\treturn -EINVAL;\n> >>>  \t\t}\n> >>>\n> >>> -\t\tconst V4L2ControlInfo *info = &iter->second;\n> >>> -\t\tcontrolInfo[i] = info;\n> >>>  \t\tv4l2Ctrls[i].id = id->id();\n> >>> -\n> >>>  \t\ti++;\n> >>>  \t}\n> >>>\n> >>> @@ -215,7 +211,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >>>  \t\tret = errorIdx;\n> >>>  \t}\n> >>>\n> >>> -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> >>> +\tupdateControls(ctrls, v4l2Ctrls, count);\n> >>>\n> >>>  \treturn ret;\n> >>>  }\n> >>> @@ -249,7 +245,6 @@ int V4L2Device::setControls(ControlList *ctrls)\n> >>>  \tif (count == 0)\n> >>>  \t\treturn 0;\n> >>>\n> >>> -\tconst V4L2ControlInfo *controlInfo[count];\n> >>>  \tstruct v4l2_ext_control v4l2Ctrls[count];\n> >>>  \tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> >>>\n> >>> @@ -263,13 +258,11 @@ int V4L2Device::setControls(ControlList *ctrls)\n> >>>  \t\t\treturn -EINVAL;\n> >>>  \t\t}\n> >>>\n> >>> -\t\tconst V4L2ControlInfo *info = &iter->second;\n> >>> -\t\tcontrolInfo[i] = info;\n> >>>  \t\tv4l2Ctrls[i].id = id->id();\n> >>>\n> >>>  \t\t/* Set the v4l2_ext_control value for the write operation. */\n> >>>  \t\tconst ControlValue &value = ctrl.second;\n> >>> -\t\tswitch (info->id().type()) {\n> >>> +\t\tswitch (id->type()) {\n> >>>  \t\tcase ControlTypeInteger64:\n> >>>  \t\t\tv4l2Ctrls[i].value64 = value.get<int64_t>();\n> >>>  \t\t\tbreak;\n> >>> @@ -308,7 +301,7 @@ int V4L2Device::setControls(ControlList *ctrls)\n> >>>  \t\tret = errorIdx;\n> >>>  \t}\n> >>>\n> >>> -\tupdateControls(ctrls, controlInfo, v4l2Ctrls, count);\n> >>> +\tupdateControls(ctrls, v4l2Ctrls, count);\n> >>>\n> >>>  \treturn ret;\n> >>>  }\n> >>> @@ -349,7 +342,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n> >>>   */\n> >>>  void V4L2Device::listControls()\n> >>>  {\n> >>> -\tstd::map<unsigned int, V4L2ControlInfo> ctrls;\n> >>> +\tstd::map<const ControlId *, V4L2ControlInfo> ctrls;\n> >>>  \tstruct v4l2_query_ext_ctrl ctrl = {};\n> >>>\n> >>>  \t/* \\todo Add support for menu and compound controls. */\n> >>> @@ -388,8 +381,8 @@ void V4L2Device::listControls()\n> >>>\n> >>>  \t\tcontrolIds_.emplace_back(utils::make_unique<V4L2ControlId>(ctrl));\n> >>\n> >> Not in this patch but I just noticed: doesn't this create a\n> >> V4L2ControlId while we should instead forward the argument to its\n> >> constructor ? Well, I think the unique_ptr<> here plays a role, and I\n> >> cannot suggest a way around it...\n> >\n> > controlIds_ store instance of std::unique_ptr<>, so it doesn't construct\n> > V4L2ControlId instances. This should, as far as I can tell, create a\n> > single V4L2ControlId. The fact that ControlId copies are now impossible\n> > is also a hint that no copy is taking place.\n> >\n> >> Anyway, the change is good and desirable:\n> >> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> >>\n> >>>  \t\tctrls.emplace(std::piecewise_construct,\n> >>> -\t\t\t      std::forward_as_tuple(ctrl.id),\n> >>> -\t\t\t      std::forward_as_tuple(*controlIds_.back().get(), ctrl));\n> >>> +\t\t\t      std::forward_as_tuple(controlIds_.back().get()),\n> >>> +\t\t\t      std::forward_as_tuple(ctrl));\n> >>>  \t}\n> >>>\n> >>>  \tcontrols_ = std::move(ctrls);\n> >>> @@ -399,12 +392,10 @@ void V4L2Device::listControls()\n> >>>   * \\brief Update the value of the first \\a count V4L2 controls in \\a ctrls using\n> >>>   * values in \\a v4l2Ctrls\n> >>>   * \\param[inout] ctrls List of V4L2 controls to update\n> >>> - * \\param[in] controlInfo List of V4L2 control information\n> >>>   * \\param[in] v4l2Ctrls List of V4L2 extended controls as returned by the driver\n> >>>   * \\param[in] count The number of controls to update\n> >>>   */\n> >>>  void V4L2Device::updateControls(ControlList *ctrls,\n> >>> -\t\t\t\tconst V4L2ControlInfo **controlInfo,\n> >>>  \t\t\t\tconst struct v4l2_ext_control *v4l2Ctrls,\n> >>>  \t\t\t\tunsigned int count)\n> >>>  {\n> >>> @@ -414,10 +405,10 @@ void V4L2Device::updateControls(ControlList *ctrls,\n> >>>  \t\t\tbreak;\n> >>>\n> >>>  \t\tconst struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n> >>> -\t\tconst V4L2ControlInfo *info = controlInfo[i];\n> >>> +\t\tconst ControlId *id = ctrl.first;\n> >>>  \t\tControlValue &value = ctrl.second;\n> >>>\n> >>> -\t\tswitch (info->id().type()) {\n> >>> +\t\tswitch (id->type()) {\n> >>>  \t\tcase ControlTypeInteger64:\n> >>>  \t\t\tvalue.set<int64_t>(v4l2Ctrl->value64);\n> >>>  \t\t\tbreak;","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ABCA661562\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Oct 2019 20:08:30 +0200 (CEST)","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 E3093324;\n\tTue, 15 Oct 2019 20:08:29 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1571162910;\n\tbh=kCr+V8lgbTo6n1vw38qxd4N35f2Tt6iurMLJiN0IbI4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=GiZNtqlnq8ceSC9tKwdJhS8MKaZqCkkRbPjJQAXENtW4XJU2z7ai9yev5lUiaLZzY\n\twdQFz/Sj8t2X5gPYhl98DHVQYVIXjVCfYoKzQHr1JgR3bqw5V5B3y4sRmpnMWb1zOc\n\tGo83pgQ/XQKnmKGy9of+6uf6yHUgo+2hALUaGHcI=","Date":"Tue, 15 Oct 2019 21:08:27 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191015180827.GP4875@pendragon.ideasonboard.com>","References":"<20191013232755.3292-1-laurent.pinchart@ideasonboard.com>\n\t<20191013232755.3292-5-laurent.pinchart@ideasonboard.com>\n\t<20191015151606.krqqw4ure5pcxopc@uno.localdomain>\n\t<20191015153118.GE4875@pendragon.ideasonboard.com>\n\t<20191015173727.onnzllkqli6bldhd@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191015173727.onnzllkqli6bldhd@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 04/10] libcamera: v4l2_controls: Index\n\tV4L2ControlInfoMap by ControlId *","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":"Tue, 15 Oct 2019 18:08:30 -0000"}}]