[{"id":4604,"web_url":"https://patchwork.libcamera.org/comment/4604/","msgid":"<20200428021432.GA1208690@oden.dyn.berto.se>","date":"2020-04-28T02:14:32","subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Simplify\n\tusage of getControls()","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 four your work.\n\nOn 2020-04-28 04:21:22 +0300, Laurent Pinchart wrote:\n> The V4L2Device::getControls() function takes a ControlList that needs to\n> be pre-populated with dummy entries for the controls that need to be\n> read. This is a cumbersome API, especially when reading a single\n> control. Make it nicer by passing the list of V4L2 controls as a vector\n> of control IDs, and returning a ControlList.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n> Changes since v1:\n> \n> - Fill the ControlList and v4l2_ext_control arrays separately\n> \n> The patch has no dependency on \"[PATCH 1/2] libcamera: controls: Return\n> ControlValue reference from ControlList::set()\" anymore.\n> ---\n>  src/libcamera/camera_sensor.cpp       | 23 ++++-------\n>  src/libcamera/include/camera_sensor.h |  2 +-\n>  src/libcamera/include/v4l2_device.h   |  2 +-\n>  src/libcamera/v4l2_device.cpp         | 59 +++++++++++++++------------\n>  test/v4l2_videodevice/controls.cpp    | 20 +++++----\n>  5 files changed, 55 insertions(+), 51 deletions(-)\n> \n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 140186b79f6f..55a9fbd71e69 100644\n> --- a/src/libcamera/camera_sensor.cpp\n> +++ b/src/libcamera/camera_sensor.cpp\n> @@ -323,30 +323,25 @@ const ControlInfoMap &CameraSensor::controls() const\n>  \n>  /**\n>   * \\brief Read controls from the sensor\n> - * \\param[inout] ctrls The list of controls to read\n> + * \\param[in] ids The list of control to read, specified by their ID\n>   *\n> - * This method reads the value of all controls contained in \\a ctrls, and stores\n> - * their values in the corresponding \\a ctrls entry.\n> + * This method reads the value of all controls contained in \\a ids, and returns\n> + * their values as a ControlList.\n>   *\n> - * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n> + * If any control in \\a ids is not supported by the device, is disabled (i.e.\n>   * has the V4L2_CTRL_FLAG_DISABLED flag set), is a compound control, or if any\n>   * other error occurs during validation of the requested controls, no control is\n> - * read and this method returns -EINVAL.\n> + * read and this method returns an empty control list.\n>   *\n> - * If an error occurs while reading the controls, the index of the first control\n> - * that couldn't be read is returned. The value of all controls below that index\n> - * are updated in \\a ctrls, while the value of all the other controls are not\n> - * changed.\n> + * If an error occurs while reading the controls, an empty list is returned.\n>   *\n>   * \\sa V4L2Device::getControls()\n>   *\n> - * \\return 0 on success or an error code otherwise\n> - * \\retval -EINVAL One of the control is not supported or not accessible\n> - * \\retval i The index of the control that failed\n> + * \\return The control values in a ControlList\n\nHere and bellow, would it make sens to move the 'an empty list is \nreturned on error' information from above to the \\return statement?  \nWhit or without this addressed,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n>   */\n> -int CameraSensor::getControls(ControlList *ctrls)\n> +ControlList CameraSensor::getControls(const std::vector<uint32_t> &ids)\n>  {\n> -\treturn subdev_->getControls(ctrls);\n> +\treturn subdev_->getControls(ids);\n>  }\n>  \n>  /**\n> diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> index 7dc4ebc79051..e68185370eb2 100644\n> --- a/src/libcamera/include/camera_sensor.h\n> +++ b/src/libcamera/include/camera_sensor.h\n> @@ -44,7 +44,7 @@ public:\n>  \tint setFormat(V4L2SubdeviceFormat *format);\n>  \n>  \tconst ControlInfoMap &controls() const;\n> -\tint getControls(ControlList *ctrls);\n> +\tControlList getControls(const std::vector<uint32_t> &ids);\n>  \tint setControls(ControlList *ctrls);\n>  \n>  \tconst ControlList &properties() const { return properties_; }\n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index ce8edd98a01d..e604a40df4c9 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -26,7 +26,7 @@ public:\n>  \n>  \tconst ControlInfoMap &controls() const { return controls_; }\n>  \n> -\tint getControls(ControlList *ctrls);\n> +\tControlList getControls(const std::vector<uint32_t> &ids);\n>  \tint setControls(ControlList *ctrls);\n>  \n>  \tconst std::string &deviceNode() const { return deviceNode_; }\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index c134266e5fd7..d009fc47c2ef 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -147,46 +147,52 @@ void V4L2Device::close()\n>  \n>  /**\n>   * \\brief Read controls from the device\n> - * \\param[inout] ctrls The list of controls to read\n> + * \\param[in] ids The list of control to read, specified by their ID\n>   *\n> - * This method reads the value of all controls contained in \\a ctrls, and stores\n> - * their values in the corresponding \\a ctrls entry.\n> + * This method reads the value of all controls contained in \\a ids, and returns\n> + * their values as a ControlList.\n>   *\n> - * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n> + * If any control in \\a ids is not supported by the device, is disabled (i.e.\n>   * has the V4L2_CTRL_FLAG_DISABLED flag set), or if any other error occurs\n>   * during validation of the requested controls, no control is read and this\n> - * method returns -EINVAL.\n> + * method returns an empty control list.\n>   *\n> - * If an error occurs while reading the controls, the index of the first control\n> - * that couldn't be read is returned. The value of all controls below that index\n> - * are updated in \\a ctrls, while the value of all the other controls are not\n> - * changed.\n> + * If an error occurs while reading the controls, an empty list is returned.\n>   *\n> - * \\return 0 on success or an error code otherwise\n> - * \\retval -EINVAL One of the control is not supported or not accessible\n> - * \\retval i The index of the control that failed\n> + * \\return The control values in a ControlList\n>   */\n> -int V4L2Device::getControls(ControlList *ctrls)\n> +ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n>  {\n> -\tunsigned int count = ctrls->size();\n> +\tunsigned int count = ids.size();\n>  \tif (count == 0)\n> -\t\treturn 0;\n> +\t\treturn {};\n>  \n> -\tstruct v4l2_ext_control v4l2Ctrls[count];\n> -\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> +\tControlList ctrls{ controls_ };\n>  \n> -\tunsigned int i = 0;\n> -\tfor (auto &ctrl : *ctrls) {\n> -\t\tunsigned int id = ctrl.first;\n> +\t/*\n> +\t * Start by filling the ControlList. This can't be combined with filling\n> +\t * v4l2Ctrls, as updateControls() relies on both containers having the\n> +\t * same order, and the control list is based on a map, which is not\n> +\t * sorted by insertion order.\n> +\t */\n> +\tfor (uint32_t id : ids) {\n>  \t\tconst auto iter = controls_.find(id);\n>  \t\tif (iter == controls_.end()) {\n>  \t\t\tLOG(V4L2, Error)\n>  \t\t\t\t<< \"Control \" << utils::hex(id) << \" not found\";\n> -\t\t\treturn -EINVAL;\n> +\t\t\treturn {};\n>  \t\t}\n>  \n> +\t\tctrls.set(id, {});\n> +\t}\n> +\n> +\tstruct v4l2_ext_control v4l2Ctrls[count];\n> +\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> +\n> +\tunsigned int i = 0;\n> +\tfor (auto &ctrl : ctrls) {\n> +\t\tunsigned int id = ctrl.first;\n>  \t\tconst struct v4l2_query_ext_ctrl &info = controlInfo_[id];\n> -\t\tControlValue &value = ctrl.second;\n>  \n>  \t\tif (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {\n>  \t\t\tControlType type;\n> @@ -200,9 +206,10 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \t\t\t\tLOG(V4L2, Error)\n>  \t\t\t\t\t<< \"Unsupported payload control type \"\n>  \t\t\t\t\t<< info.type;\n> -\t\t\t\treturn -EINVAL;\n> +\t\t\t\treturn {};\n>  \t\t\t}\n>  \n> +\t\t\tControlValue &value = ctrl.second;\n>  \t\t\tvalue.reserve(type, true, info.elems);\n>  \t\t\tSpan<uint8_t> data = value.data();\n>  \n> @@ -227,7 +234,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \t\tif (errorIdx == 0 || errorIdx >= count) {\n>  \t\t\tLOG(V4L2, Error) << \"Unable to read controls: \"\n>  \t\t\t\t\t << strerror(-ret);\n> -\t\t\treturn -EINVAL;\n> +\t\t\treturn {};\n>  \t\t}\n>  \n>  \t\t/* A specific control failed. */\n> @@ -237,9 +244,9 @@ int V4L2Device::getControls(ControlList *ctrls)\n>  \t\tret = errorIdx;\n>  \t}\n>  \n> -\tupdateControls(ctrls, v4l2Ctrls, count);\n> +\tupdateControls(&ctrls, v4l2Ctrls, count);\n>  \n> -\treturn ret;\n> +\treturn ctrls;\n>  }\n>  \n>  /**\n> diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp\n> index da9e0111e221..347af2112f1a 100644\n> --- a/test/v4l2_videodevice/controls.cpp\n> +++ b/test/v4l2_videodevice/controls.cpp\n> @@ -57,18 +57,20 @@ protected:\n>  \t\tconst ControlInfo &u8 = infoMap.find(VIVID_CID_U8_4D_ARRAY)->second;\n>  \n>  \t\t/* Test getting controls. */\n> -\t\tControlList ctrls(infoMap);\n> -\t\tctrls.set(V4L2_CID_BRIGHTNESS, -1);\n> -\t\tctrls.set(V4L2_CID_CONTRAST, -1);\n> -\t\tctrls.set(V4L2_CID_SATURATION, -1);\n> -\t\tctrls.set(VIVID_CID_U8_4D_ARRAY, 0);\n> -\n> -\t\tint ret = capture_->getControls(&ctrls);\n> -\t\tif (ret) {\n> +\t\tControlList ctrls = capture_->getControls({ V4L2_CID_BRIGHTNESS,\n> +\t\t\t\t\t\t\t    V4L2_CID_CONTRAST,\n> +\t\t\t\t\t\t\t    V4L2_CID_SATURATION,\n> +\t\t\t\t\t\t\t    VIVID_CID_U8_4D_ARRAY });\n> +\t\tif (ctrls.empty()) {\n>  \t\t\tcerr << \"Failed to get controls\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n> +\t\tif (ctrls.infoMap() != &infoMap) {\n> +\t\t\tcerr << \"Incorrect infoMap for retrieved controls\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\tif (ctrls.get(V4L2_CID_BRIGHTNESS).get<int32_t>() == -1 ||\n>  \t\t    ctrls.get(V4L2_CID_CONTRAST).get<int32_t>() == -1 ||\n>  \t\t    ctrls.get(V4L2_CID_SATURATION).get<int32_t>() == -1) {\n> @@ -97,7 +99,7 @@ protected:\n>  \t\tstd::fill(u8Values.begin(), u8Values.end(), u8.min().get<uint8_t>());\n>  \t\tctrls.set(VIVID_CID_U8_4D_ARRAY, Span<const uint8_t>(u8Values));\n>  \n> -\t\tret = capture_->setControls(&ctrls);\n> +\t\tint ret = capture_->setControls(&ctrls);\n>  \t\tif (ret) {\n>  \t\t\tcerr << \"Failed to set controls\" << endl;\n>  \t\t\treturn TestFail;\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-x233.google.com (mail-lj1-x233.google.com\n\t[IPv6:2a00:1450:4864:20::233])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A5926603F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 04:14:35 +0200 (CEST)","by mail-lj1-x233.google.com with SMTP id w20so19805708ljj.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Apr 2020 19:14:35 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tw27sm14359071lfn.45.2020.04.27.19.14.33\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 27 Apr 2020 19:14:33 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"hIHipFmE\"; \n\tdkim-atps=neutral","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\tbh=8Mis1i1rkXZWHHmeuoWAWPZqah5E6GNdGQS01/un6N0=;\n\tb=hIHipFmEAtaTtxLIIhNRG5YhWtlcCRbLQ8ilIM8Ost5uIsFQ+x9OB3BW6EKSOmV1Al\n\tR4zgr5cyCXs9himhKRAnd6CKJUNeeNcE0EqGuklecvyABDNCXsfbk/b20HlOuUOZK3Hs\n\tMZvKZbrO2+uAVdtCyDMxYWLFaPCoCnQA6iY3ebNtqB2VDc/j1I1FcAhon+3PNimePTJh\n\tkXZUDNYKcYgX6u1ljbocgIIOO4n9cwNPCeGsad2clii2KC8M/hd9utzpZHNv+qWg0l3i\n\tJhN6UfQp8OH6d2UD86xuRLW+UhjMY6I53kTBA+JLNi7aBdeJTsvu/O53eChrjg5FeA69\n\tQUMA==","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;\n\tbh=8Mis1i1rkXZWHHmeuoWAWPZqah5E6GNdGQS01/un6N0=;\n\tb=n6AkhAurZBGY3W4/pkCeKXAHD+DHJYtPnfA4bOM41VpItaKfGSuwXHCvraOYJjCt5L\n\tEcxMsfuDK4vOH3Ht9oahS0RcOFgga/N7VXCatRck9JSvxFtZ1kpO+FaUVW6fKgXTrdx3\n\t7f6kHgj0EeHhJr96iu98CRiHgQDQTawPVtur5GOjMSMroBqRp546JG5diZVXLZQ/rcJT\n\tvC7GfJOFYSmh4UrxbQfDTxuh0+I+bwupyIokfegr/uG2A135N/Z7RNuix6p0xua6Zz2Z\n\tGKkZ6WcjrJ9ZgNkq4N5m0op7BexdiYGDWA23pFJ2BXrPKzv0em6pkVTqM8j3GDYOEwgP\n\tXvKQ==","X-Gm-Message-State":"AGi0Pua200saCk9/2rFJyS2fEa2IA94BH7Xp2URLFpz2hhGalPMAr69Y\n\tRBtHgA3672WSFmmHtChJwENI0Q==","X-Google-Smtp-Source":"APiQypKGdeuFXMAvbttw8CsMhu+VgebpalAOmDBFDPMB1g8XymJlXrxycIXqo3oylODIZap2yvA6uQ==","X-Received":"by 2002:a2e:a176:: with SMTP id\n\tu22mr16087758ljl.177.1588040074588; \n\tMon, 27 Apr 2020 19:14:34 -0700 (PDT)","Date":"Tue, 28 Apr 2020 04:14:32 +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":"<20200428021432.GA1208690@oden.dyn.berto.se>","References":"<20200428012122.2496-1-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":"<20200428012122.2496-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Simplify\n\tusage of getControls()","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, 28 Apr 2020 02:14:36 -0000"}},{"id":4617,"web_url":"https://patchwork.libcamera.org/comment/4617/","msgid":"<20200428120446.rvvqtprjfsg5jlcl@uno.localdomain>","date":"2020-04-28T12:04:46","subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Simplify\n\tusage of getControls()","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Tue, Apr 28, 2020 at 04:14:32AM +0200, Niklas Söderlund wrote:\n> Hi Laurent,\n>\n> Thanks four your work.\n>\n> On 2020-04-28 04:21:22 +0300, Laurent Pinchart wrote:\n> > The V4L2Device::getControls() function takes a ControlList that needs to\n> > be pre-populated with dummy entries for the controls that need to be\n> > read. This is a cumbersome API, especially when reading a single\n> > control. Make it nicer by passing the list of V4L2 controls as a vector\n> > of control IDs, and returning a ControlList.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> > Changes since v1:\n> >\n> > - Fill the ControlList and v4l2_ext_control arrays separately\n> >\n\nSorry, it should have been caught by review :/\n\n> > The patch has no dependency on \"[PATCH 1/2] libcamera: controls: Return\n> > ControlValue reference from ControlList::set()\" anymore.\n> > ---\n> >  src/libcamera/camera_sensor.cpp       | 23 ++++-------\n> >  src/libcamera/include/camera_sensor.h |  2 +-\n> >  src/libcamera/include/v4l2_device.h   |  2 +-\n> >  src/libcamera/v4l2_device.cpp         | 59 +++++++++++++++------------\n> >  test/v4l2_videodevice/controls.cpp    | 20 +++++----\n> >  5 files changed, 55 insertions(+), 51 deletions(-)\n> >\n> > diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> > index 140186b79f6f..55a9fbd71e69 100644\n> > --- a/src/libcamera/camera_sensor.cpp\n> > +++ b/src/libcamera/camera_sensor.cpp\n> > @@ -323,30 +323,25 @@ const ControlInfoMap &CameraSensor::controls() const\n> >\n> >  /**\n> >   * \\brief Read controls from the sensor\n> > - * \\param[inout] ctrls The list of controls to read\n> > + * \\param[in] ids The list of control to read, specified by their ID\n> >   *\n> > - * This method reads the value of all controls contained in \\a ctrls, and stores\n> > - * their values in the corresponding \\a ctrls entry.\n> > + * This method reads the value of all controls contained in \\a ids, and returns\n> > + * their values as a ControlList.\n> >   *\n> > - * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n> > + * If any control in \\a ids is not supported by the device, is disabled (i.e.\n> >   * has the V4L2_CTRL_FLAG_DISABLED flag set), is a compound control, or if any\n\nWhile at it, could you drop \"compound controls\" from documentation, as\nthey're now supported ?\n\nI did the the same for the v4l2 device but forgot camera sensor...\n\n> >   * other error occurs during validation of the requested controls, no control is\n> > - * read and this method returns -EINVAL.\n> > + * read and this method returns an empty control list.\n> >   *\n> > - * If an error occurs while reading the controls, the index of the first control\n> > - * that couldn't be read is returned. The value of all controls below that index\n> > - * are updated in \\a ctrls, while the value of all the other controls are not\n> > - * changed.\n> > + * If an error occurs while reading the controls, an empty list is returned.\n> >   *\n> >   * \\sa V4L2Device::getControls()\n> >   *\n> > - * \\return 0 on success or an error code otherwise\n> > - * \\retval -EINVAL One of the control is not supported or not accessible\n> > - * \\retval i The index of the control that failed\n> > + * \\return The control values in a ControlList\n>\n> Here and bellow, would it make sens to move the 'an empty list is\n> returned on error' information from above to the \\return statement?\n> Whit or without this addressed,\n\nor to match our canonical style:\n\", or an empty list on error\"\n\n>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n>\n> >   */\n> > -int CameraSensor::getControls(ControlList *ctrls)\n> > +ControlList CameraSensor::getControls(const std::vector<uint32_t> &ids)\n> >  {\n> > -\treturn subdev_->getControls(ctrls);\n> > +\treturn subdev_->getControls(ids);\n> >  }\n> >\n> >  /**\n> > diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> > index 7dc4ebc79051..e68185370eb2 100644\n> > --- a/src/libcamera/include/camera_sensor.h\n> > +++ b/src/libcamera/include/camera_sensor.h\n> > @@ -44,7 +44,7 @@ public:\n> >  \tint setFormat(V4L2SubdeviceFormat *format);\n> >\n> >  \tconst ControlInfoMap &controls() const;\n> > -\tint getControls(ControlList *ctrls);\n> > +\tControlList getControls(const std::vector<uint32_t> &ids);\n> >  \tint setControls(ControlList *ctrls);\n> >\n> >  \tconst ControlList &properties() const { return properties_; }\n> > diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> > index ce8edd98a01d..e604a40df4c9 100644\n> > --- a/src/libcamera/include/v4l2_device.h\n> > +++ b/src/libcamera/include/v4l2_device.h\n> > @@ -26,7 +26,7 @@ public:\n> >\n> >  \tconst ControlInfoMap &controls() const { return controls_; }\n> >\n> > -\tint getControls(ControlList *ctrls);\n> > +\tControlList getControls(const std::vector<uint32_t> &ids);\n> >  \tint setControls(ControlList *ctrls);\n> >\n> >  \tconst std::string &deviceNode() const { return deviceNode_; }\n> > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> > index c134266e5fd7..d009fc47c2ef 100644\n> > --- a/src/libcamera/v4l2_device.cpp\n> > +++ b/src/libcamera/v4l2_device.cpp\n> > @@ -147,46 +147,52 @@ void V4L2Device::close()\n> >\n> >  /**\n> >   * \\brief Read controls from the device\n> > - * \\param[inout] ctrls The list of controls to read\n> > + * \\param[in] ids The list of control to read, specified by their ID\n\nlist of control's'\n\n> >   *\n> > - * This method reads the value of all controls contained in \\a ctrls, and stores\n> > - * their values in the corresponding \\a ctrls entry.\n> > + * This method reads the value of all controls contained in \\a ids, and returns\n> > + * their values as a ControlList.\n> >   *\n> > - * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n> > + * If any control in \\a ids is not supported by the device, is disabled (i.e.\n> >   * has the V4L2_CTRL_FLAG_DISABLED flag set), or if any other error occurs\n> >   * during validation of the requested controls, no control is read and this\n> > - * method returns -EINVAL.\n> > + * method returns an empty control list.\n> >   *\n> > - * If an error occurs while reading the controls, the index of the first control\n> > - * that couldn't be read is returned. The value of all controls below that index\n> > - * are updated in \\a ctrls, while the value of all the other controls are not\n> > - * changed.\n> > + * If an error occurs while reading the controls, an empty list is returned.\n\nIsn't this a repetition of the above statement ?\n\n> >   *\n> > - * \\return 0 on success or an error code otherwise\n> > - * \\retval -EINVAL One of the control is not supported or not accessible\n> > - * \\retval i The index of the control that failed\n> > + * \\return The control values in a ControlList\n\nsame comment as above\n\n> >   */\n> > -int V4L2Device::getControls(ControlList *ctrls)\n> > +ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n> >  {\n> > -\tunsigned int count = ctrls->size();\n> > +\tunsigned int count = ids.size();\n> >  \tif (count == 0)\n> > -\t\treturn 0;\n> > +\t\treturn {};\n> >\n> > -\tstruct v4l2_ext_control v4l2Ctrls[count];\n> > -\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> > +\tControlList ctrls{ controls_ };\n> >\n> > -\tunsigned int i = 0;\n> > -\tfor (auto &ctrl : *ctrls) {\n> > -\t\tunsigned int id = ctrl.first;\n> > +\t/*\n> > +\t * Start by filling the ControlList. This can't be combined with filling\n> > +\t * v4l2Ctrls, as updateControls() relies on both containers having the\n> > +\t * same order, and the control list is based on a map, which is not\n> > +\t * sorted by insertion order.\n> > +\t */\n\nAh, this was nasty to debug I assume...\n\n> > +\tfor (uint32_t id : ids) {\n> >  \t\tconst auto iter = controls_.find(id);\n> >  \t\tif (iter == controls_.end()) {\n> >  \t\t\tLOG(V4L2, Error)\n> >  \t\t\t\t<< \"Control \" << utils::hex(id) << \" not found\";\n> > -\t\t\treturn -EINVAL;\n> > +\t\t\treturn {};\n> >  \t\t}\n> >\n> > +\t\tctrls.set(id, {});\n> > +\t}\n> > +\n> > +\tstruct v4l2_ext_control v4l2Ctrls[count];\n> > +\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n\nCan we initialize an array with {} and save memset ? I know this was\nthere already, so it's fine if you want to keep it\n\nAnyway, minors apart this looks good!\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nSide note: we now have a getControls() which works on ids and a\nsetControls() which work on lists. Would that make sense to provide\na setControls(id, T value) ? Would this be abused by lazy implementers\nwhich instead of grouping controls in a list would call multiple times\nthis new function ? Just wondering and not on this patch anyway...\n\nThanks\n  j\n\n> > +\n> > +\tunsigned int i = 0;\n> > +\tfor (auto &ctrl : ctrls) {\n> > +\t\tunsigned int id = ctrl.first;\n> >  \t\tconst struct v4l2_query_ext_ctrl &info = controlInfo_[id];\n> > -\t\tControlValue &value = ctrl.second;\n> >\n> >  \t\tif (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {\n> >  \t\t\tControlType type;\n> > @@ -200,9 +206,10 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >  \t\t\t\tLOG(V4L2, Error)\n> >  \t\t\t\t\t<< \"Unsupported payload control type \"\n> >  \t\t\t\t\t<< info.type;\n> > -\t\t\t\treturn -EINVAL;\n> > +\t\t\t\treturn {};\n> >  \t\t\t}\n> >\n> > +\t\t\tControlValue &value = ctrl.second;\n> >  \t\t\tvalue.reserve(type, true, info.elems);\n> >  \t\t\tSpan<uint8_t> data = value.data();\n> >\n> > @@ -227,7 +234,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >  \t\tif (errorIdx == 0 || errorIdx >= count) {\n> >  \t\t\tLOG(V4L2, Error) << \"Unable to read controls: \"\n> >  \t\t\t\t\t << strerror(-ret);\n> > -\t\t\treturn -EINVAL;\n> > +\t\t\treturn {};\n> >  \t\t}\n> >\n> >  \t\t/* A specific control failed. */\n> > @@ -237,9 +244,9 @@ int V4L2Device::getControls(ControlList *ctrls)\n> >  \t\tret = errorIdx;\n> >  \t}\n> >\n> > -\tupdateControls(ctrls, v4l2Ctrls, count);\n> > +\tupdateControls(&ctrls, v4l2Ctrls, count);\n> >\n> > -\treturn ret;\n> > +\treturn ctrls;\n> >  }\n> >\n> >  /**\n> > diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp\n> > index da9e0111e221..347af2112f1a 100644\n> > --- a/test/v4l2_videodevice/controls.cpp\n> > +++ b/test/v4l2_videodevice/controls.cpp\n> > @@ -57,18 +57,20 @@ protected:\n> >  \t\tconst ControlInfo &u8 = infoMap.find(VIVID_CID_U8_4D_ARRAY)->second;\n> >\n> >  \t\t/* Test getting controls. */\n> > -\t\tControlList ctrls(infoMap);\n> > -\t\tctrls.set(V4L2_CID_BRIGHTNESS, -1);\n> > -\t\tctrls.set(V4L2_CID_CONTRAST, -1);\n> > -\t\tctrls.set(V4L2_CID_SATURATION, -1);\n> > -\t\tctrls.set(VIVID_CID_U8_4D_ARRAY, 0);\n> > -\n> > -\t\tint ret = capture_->getControls(&ctrls);\n> > -\t\tif (ret) {\n> > +\t\tControlList ctrls = capture_->getControls({ V4L2_CID_BRIGHTNESS,\n> > +\t\t\t\t\t\t\t    V4L2_CID_CONTRAST,\n> > +\t\t\t\t\t\t\t    V4L2_CID_SATURATION,\n> > +\t\t\t\t\t\t\t    VIVID_CID_U8_4D_ARRAY });\n> > +\t\tif (ctrls.empty()) {\n> >  \t\t\tcerr << \"Failed to get controls\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > +\t\tif (ctrls.infoMap() != &infoMap) {\n> > +\t\t\tcerr << \"Incorrect infoMap for retrieved controls\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> >  \t\tif (ctrls.get(V4L2_CID_BRIGHTNESS).get<int32_t>() == -1 ||\n> >  \t\t    ctrls.get(V4L2_CID_CONTRAST).get<int32_t>() == -1 ||\n> >  \t\t    ctrls.get(V4L2_CID_SATURATION).get<int32_t>() == -1) {\n> > @@ -97,7 +99,7 @@ protected:\n> >  \t\tstd::fill(u8Values.begin(), u8Values.end(), u8.min().get<uint8_t>());\n> >  \t\tctrls.set(VIVID_CID_U8_4D_ARRAY, Span<const uint8_t>(u8Values));\n> >\n> > -\t\tret = capture_->setControls(&ctrls);\n> > +\t\tint ret = capture_->setControls(&ctrls);\n> >  \t\tif (ret) {\n> >  \t\t\tcerr << \"Failed to set controls\" << endl;\n> >  \t\t\treturn TestFail;\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\n>\n> --\n> Regards,\n> Niklas Söderlund\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 1188660AF5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 14:01:37 +0200 (CEST)","from uno.localdomain (a-ur1-85.tin.it [212.216.150.148])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id A6A4F4000A;\n\tTue, 28 Apr 2020 12:01:35 +0000 (UTC)"],"X-Originating-IP":"212.216.150.148","Date":"Tue, 28 Apr 2020 14:04:46 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Message-ID":"<20200428120446.rvvqtprjfsg5jlcl@uno.localdomain>","References":"<20200428012122.2496-1-laurent.pinchart@ideasonboard.com>\n\t<20200428021432.GA1208690@oden.dyn.berto.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200428021432.GA1208690@oden.dyn.berto.se>","Subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Simplify\n\tusage of getControls()","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, 28 Apr 2020 12:01:37 -0000"}},{"id":4619,"web_url":"https://patchwork.libcamera.org/comment/4619/","msgid":"<20200428123132.j2g5v67uhbqghweh@uno.localdomain>","date":"2020-04-28T12:31:32","subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Simplify\n\tusage of getControls()","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"On Tue, Apr 28, 2020 at 02:04:46PM +0200, Jacopo Mondi wrote:\n> Hi Laurent,\n>\n> On Tue, Apr 28, 2020 at 04:14:32AM +0200, Niklas Söderlund wrote:\n> > Hi Laurent,\n> >\n> > Thanks four your work.\n> >\n> > On 2020-04-28 04:21:22 +0300, Laurent Pinchart wrote:\n> > > The V4L2Device::getControls() function takes a ControlList that needs to\n> > > be pre-populated with dummy entries for the controls that need to be\n> > > read. This is a cumbersome API, especially when reading a single\n> > > control. Make it nicer by passing the list of V4L2 controls as a vector\n> > > of control IDs, and returning a ControlList.\n> > >\n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > > Changes since v1:\n> > >\n> > > - Fill the ControlList and v4l2_ext_control arrays separately\n> > >\n>\n> Sorry, it should have been caught by review :/\n>\n> > > The patch has no dependency on \"[PATCH 1/2] libcamera: controls: Return\n> > > ControlValue reference from ControlList::set()\" anymore.\n> > > ---\n> > >  src/libcamera/camera_sensor.cpp       | 23 ++++-------\n> > >  src/libcamera/include/camera_sensor.h |  2 +-\n> > >  src/libcamera/include/v4l2_device.h   |  2 +-\n> > >  src/libcamera/v4l2_device.cpp         | 59 +++++++++++++++------------\n> > >  test/v4l2_videodevice/controls.cpp    | 20 +++++----\n> > >  5 files changed, 55 insertions(+), 51 deletions(-)\n> > >\n> > > diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> > > index 140186b79f6f..55a9fbd71e69 100644\n> > > --- a/src/libcamera/camera_sensor.cpp\n> > > +++ b/src/libcamera/camera_sensor.cpp\n> > > @@ -323,30 +323,25 @@ const ControlInfoMap &CameraSensor::controls() const\n> > >\n> > >  /**\n> > >   * \\brief Read controls from the sensor\n> > > - * \\param[inout] ctrls The list of controls to read\n> > > + * \\param[in] ids The list of control to read, specified by their ID\n> > >   *\n> > > - * This method reads the value of all controls contained in \\a ctrls, and stores\n> > > - * their values in the corresponding \\a ctrls entry.\n> > > + * This method reads the value of all controls contained in \\a ids, and returns\n> > > + * their values as a ControlList.\n> > >   *\n> > > - * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n> > > + * If any control in \\a ids is not supported by the device, is disabled (i.e.\n> > >   * has the V4L2_CTRL_FLAG_DISABLED flag set), is a compound control, or if any\n>\n> While at it, could you drop \"compound controls\" from documentation, as\n> they're now supported ?\n>\n> I did the the same for the v4l2 device but forgot camera sensor...\n>\n> > >   * other error occurs during validation of the requested controls, no control is\n> > > - * read and this method returns -EINVAL.\n> > > + * read and this method returns an empty control list.\n> > >   *\n> > > - * If an error occurs while reading the controls, the index of the first control\n> > > - * that couldn't be read is returned. The value of all controls below that index\n> > > - * are updated in \\a ctrls, while the value of all the other controls are not\n> > > - * changed.\n> > > + * If an error occurs while reading the controls, an empty list is returned.\n> > >   *\n> > >   * \\sa V4L2Device::getControls()\n> > >   *\n> > > - * \\return 0 on success or an error code otherwise\n> > > - * \\retval -EINVAL One of the control is not supported or not accessible\n> > > - * \\retval i The index of the control that failed\n> > > + * \\return The control values in a ControlList\n> >\n> > Here and bellow, would it make sens to move the 'an empty list is\n> > returned on error' information from above to the \\return statement?\n> > Whit or without this addressed,\n>\n> or to match our canonical style:\n> \", or an empty list on error\"\n>\n> >\n> > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> >\n> > >   */\n> > > -int CameraSensor::getControls(ControlList *ctrls)\n> > > +ControlList CameraSensor::getControls(const std::vector<uint32_t> &ids)\n> > >  {\n> > > -\treturn subdev_->getControls(ctrls);\n> > > +\treturn subdev_->getControls(ids);\n> > >  }\n> > >\n> > >  /**\n> > > diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\n> > > index 7dc4ebc79051..e68185370eb2 100644\n> > > --- a/src/libcamera/include/camera_sensor.h\n> > > +++ b/src/libcamera/include/camera_sensor.h\n> > > @@ -44,7 +44,7 @@ public:\n> > >  \tint setFormat(V4L2SubdeviceFormat *format);\n> > >\n> > >  \tconst ControlInfoMap &controls() const;\n> > > -\tint getControls(ControlList *ctrls);\n> > > +\tControlList getControls(const std::vector<uint32_t> &ids);\n> > >  \tint setControls(ControlList *ctrls);\n> > >\n> > >  \tconst ControlList &properties() const { return properties_; }\n> > > diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> > > index ce8edd98a01d..e604a40df4c9 100644\n> > > --- a/src/libcamera/include/v4l2_device.h\n> > > +++ b/src/libcamera/include/v4l2_device.h\n> > > @@ -26,7 +26,7 @@ public:\n> > >\n> > >  \tconst ControlInfoMap &controls() const { return controls_; }\n> > >\n> > > -\tint getControls(ControlList *ctrls);\n> > > +\tControlList getControls(const std::vector<uint32_t> &ids);\n> > >  \tint setControls(ControlList *ctrls);\n> > >\n> > >  \tconst std::string &deviceNode() const { return deviceNode_; }\n> > > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> > > index c134266e5fd7..d009fc47c2ef 100644\n> > > --- a/src/libcamera/v4l2_device.cpp\n> > > +++ b/src/libcamera/v4l2_device.cpp\n> > > @@ -147,46 +147,52 @@ void V4L2Device::close()\n> > >\n> > >  /**\n> > >   * \\brief Read controls from the device\n> > > - * \\param[inout] ctrls The list of controls to read\n> > > + * \\param[in] ids The list of control to read, specified by their ID\n>\n> list of control's'\n>\n> > >   *\n> > > - * This method reads the value of all controls contained in \\a ctrls, and stores\n> > > - * their values in the corresponding \\a ctrls entry.\n> > > + * This method reads the value of all controls contained in \\a ids, and returns\n> > > + * their values as a ControlList.\n> > >   *\n> > > - * If any control in \\a ctrls is not supported by the device, is disabled (i.e.\n> > > + * If any control in \\a ids is not supported by the device, is disabled (i.e.\n> > >   * has the V4L2_CTRL_FLAG_DISABLED flag set), or if any other error occurs\n> > >   * during validation of the requested controls, no control is read and this\n> > > - * method returns -EINVAL.\n> > > + * method returns an empty control list.\n> > >   *\n> > > - * If an error occurs while reading the controls, the index of the first control\n> > > - * that couldn't be read is returned. The value of all controls below that index\n> > > - * are updated in \\a ctrls, while the value of all the other controls are not\n> > > - * changed.\n> > > + * If an error occurs while reading the controls, an empty list is returned.\n>\n> Isn't this a repetition of the above statement ?\n>\n> > >   *\n> > > - * \\return 0 on success or an error code otherwise\n> > > - * \\retval -EINVAL One of the control is not supported or not accessible\n> > > - * \\retval i The index of the control that failed\n> > > + * \\return The control values in a ControlList\n>\n> same comment as above\n>\n> > >   */\n> > > -int V4L2Device::getControls(ControlList *ctrls)\n> > > +ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n> > >  {\n> > > -\tunsigned int count = ctrls->size();\n> > > +\tunsigned int count = ids.size();\n> > >  \tif (count == 0)\n> > > -\t\treturn 0;\n> > > +\t\treturn {};\n> > >\n> > > -\tstruct v4l2_ext_control v4l2Ctrls[count];\n> > > -\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n> > > +\tControlList ctrls{ controls_ };\n> > >\n> > > -\tunsigned int i = 0;\n> > > -\tfor (auto &ctrl : *ctrls) {\n> > > -\t\tunsigned int id = ctrl.first;\n> > > +\t/*\n> > > +\t * Start by filling the ControlList. This can't be combined with filling\n> > > +\t * v4l2Ctrls, as updateControls() relies on both containers having the\n> > > +\t * same order, and the control list is based on a map, which is not\n> > > +\t * sorted by insertion order.\n> > > +\t */\n>\n> Ah, this was nasty to debug I assume...\n>\n> > > +\tfor (uint32_t id : ids) {\n> > >  \t\tconst auto iter = controls_.find(id);\n> > >  \t\tif (iter == controls_.end()) {\n> > >  \t\t\tLOG(V4L2, Error)\n> > >  \t\t\t\t<< \"Control \" << utils::hex(id) << \" not found\";\n> > > -\t\t\treturn -EINVAL;\n> > > +\t\t\treturn {};\n> > >  \t\t}\n> > >\n> > > +\t\tctrls.set(id, {});\n> > > +\t}\n> > > +\n> > > +\tstruct v4l2_ext_control v4l2Ctrls[count];\n> > > +\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n>\n> Can we initialize an array with {} and save memset ? I know this was\n> there already, so it's fine if you want to keep it\n>\n\nNo we can't :)\n../src/libcamera/v4l2_device.cpp:189:36: error: variable-sized object may not be initialized\n        struct v4l2_ext_control v4l2Ctrls[count]{};\n                                          ^~~~~\nIgnore this comment then!\n\n> Anyway, minors apart this looks good!\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n>\n> Side note: we now have a getControls() which works on ids and a\n> setControls() which work on lists. Would that make sense to provide\n> a setControls(id, T value) ? Would this be abused by lazy implementers\n> which instead of grouping controls in a list would call multiple times\n> this new function ? Just wondering and not on this patch anyway...\n>\n> Thanks\n>   j\n>\n> > > +\n> > > +\tunsigned int i = 0;\n> > > +\tfor (auto &ctrl : ctrls) {\n> > > +\t\tunsigned int id = ctrl.first;\n> > >  \t\tconst struct v4l2_query_ext_ctrl &info = controlInfo_[id];\n> > > -\t\tControlValue &value = ctrl.second;\n> > >\n> > >  \t\tif (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {\n> > >  \t\t\tControlType type;\n> > > @@ -200,9 +206,10 @@ int V4L2Device::getControls(ControlList *ctrls)\n> > >  \t\t\t\tLOG(V4L2, Error)\n> > >  \t\t\t\t\t<< \"Unsupported payload control type \"\n> > >  \t\t\t\t\t<< info.type;\n> > > -\t\t\t\treturn -EINVAL;\n> > > +\t\t\t\treturn {};\n> > >  \t\t\t}\n> > >\n> > > +\t\t\tControlValue &value = ctrl.second;\n> > >  \t\t\tvalue.reserve(type, true, info.elems);\n> > >  \t\t\tSpan<uint8_t> data = value.data();\n> > >\n> > > @@ -227,7 +234,7 @@ int V4L2Device::getControls(ControlList *ctrls)\n> > >  \t\tif (errorIdx == 0 || errorIdx >= count) {\n> > >  \t\t\tLOG(V4L2, Error) << \"Unable to read controls: \"\n> > >  \t\t\t\t\t << strerror(-ret);\n> > > -\t\t\treturn -EINVAL;\n> > > +\t\t\treturn {};\n> > >  \t\t}\n> > >\n> > >  \t\t/* A specific control failed. */\n> > > @@ -237,9 +244,9 @@ int V4L2Device::getControls(ControlList *ctrls)\n> > >  \t\tret = errorIdx;\n> > >  \t}\n> > >\n> > > -\tupdateControls(ctrls, v4l2Ctrls, count);\n> > > +\tupdateControls(&ctrls, v4l2Ctrls, count);\n> > >\n> > > -\treturn ret;\n> > > +\treturn ctrls;\n> > >  }\n> > >\n> > >  /**\n> > > diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp\n> > > index da9e0111e221..347af2112f1a 100644\n> > > --- a/test/v4l2_videodevice/controls.cpp\n> > > +++ b/test/v4l2_videodevice/controls.cpp\n> > > @@ -57,18 +57,20 @@ protected:\n> > >  \t\tconst ControlInfo &u8 = infoMap.find(VIVID_CID_U8_4D_ARRAY)->second;\n> > >\n> > >  \t\t/* Test getting controls. */\n> > > -\t\tControlList ctrls(infoMap);\n> > > -\t\tctrls.set(V4L2_CID_BRIGHTNESS, -1);\n> > > -\t\tctrls.set(V4L2_CID_CONTRAST, -1);\n> > > -\t\tctrls.set(V4L2_CID_SATURATION, -1);\n> > > -\t\tctrls.set(VIVID_CID_U8_4D_ARRAY, 0);\n> > > -\n> > > -\t\tint ret = capture_->getControls(&ctrls);\n> > > -\t\tif (ret) {\n> > > +\t\tControlList ctrls = capture_->getControls({ V4L2_CID_BRIGHTNESS,\n> > > +\t\t\t\t\t\t\t    V4L2_CID_CONTRAST,\n> > > +\t\t\t\t\t\t\t    V4L2_CID_SATURATION,\n> > > +\t\t\t\t\t\t\t    VIVID_CID_U8_4D_ARRAY });\n> > > +\t\tif (ctrls.empty()) {\n> > >  \t\t\tcerr << \"Failed to get controls\" << endl;\n> > >  \t\t\treturn TestFail;\n> > >  \t\t}\n> > >\n> > > +\t\tif (ctrls.infoMap() != &infoMap) {\n> > > +\t\t\tcerr << \"Incorrect infoMap for retrieved controls\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > >  \t\tif (ctrls.get(V4L2_CID_BRIGHTNESS).get<int32_t>() == -1 ||\n> > >  \t\t    ctrls.get(V4L2_CID_CONTRAST).get<int32_t>() == -1 ||\n> > >  \t\t    ctrls.get(V4L2_CID_SATURATION).get<int32_t>() == -1) {\n> > > @@ -97,7 +99,7 @@ protected:\n> > >  \t\tstd::fill(u8Values.begin(), u8Values.end(), u8.min().get<uint8_t>());\n> > >  \t\tctrls.set(VIVID_CID_U8_4D_ARRAY, Span<const uint8_t>(u8Values));\n> > >\n> > > -\t\tret = capture_->setControls(&ctrls);\n> > > +\t\tint ret = capture_->setControls(&ctrls);\n> > >  \t\tif (ret) {\n> > >  \t\t\tcerr << \"Failed to set controls\" << endl;\n> > >  \t\t\treturn TestFail;\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\n> >\n> > --\n> > Regards,\n> > Niklas Söderlund\n> > _______________________________________________\n> > libcamera-devel mailing list\n> > libcamera-devel@lists.libcamera.org\n> > https://lists.libcamera.org/listinfo/libcamera-devel\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 relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E6EC460AF5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 14:28:28 +0200 (CEST)","from uno.localdomain (a-ur1-85.tin.it [212.216.150.148])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id C91F71BF210;\n\tTue, 28 Apr 2020 12:28:27 +0000 (UTC)"],"X-Originating-IP":"212.216.150.148","Date":"Tue, 28 Apr 2020 14:31:32 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200428123132.j2g5v67uhbqghweh@uno.localdomain>","References":"<20200428012122.2496-1-laurent.pinchart@ideasonboard.com>\n\t<20200428021432.GA1208690@oden.dyn.berto.se>\n\t<20200428120446.rvvqtprjfsg5jlcl@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200428120446.rvvqtprjfsg5jlcl@uno.localdomain>","Subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_device: Simplify\n\tusage of getControls()","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, 28 Apr 2020 12:28:29 -0000"}}]