<div dir="ltr"><div dir="ltr">Hi Jacopo, thank you for reviewing.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 27, 2021 at 5:58 AM Jacopo Mondi <<a href="mailto:jacopo@jmondi.org">jacopo@jmondi.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Hiro,<br>
<br>
On Wed, May 19, 2021 at 04:59:37PM +0900, Hirokazu Honda wrote:<br>
> This adds a support of v4l2 menu. The control info for v4l2 menu<br>
> contains indices without names and 64bit values of querymenu.<br>
><br>
> Signed-off-by: Hirokazu Honda <<a href="mailto:hiroh@chromium.org" target="_blank">hiroh@chromium.org</a>><br>
> ---<br>
>  include/libcamera/internal/v4l2_device.h |  3 ++<br>
>  src/libcamera/v4l2_device.cpp            | 64 ++++++++++++++++++++++--<br>
>  2 files changed, 63 insertions(+), 4 deletions(-)<br>
><br>
> diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h<br>
> index 5ba9b23b..34080b07 100644<br>
> --- a/include/libcamera/internal/v4l2_device.h<br>
> +++ b/include/libcamera/internal/v4l2_device.h<br>
> @@ -56,6 +56,9 @@ protected:<br>
>       int fd() const { return fd_; }<br>
><br>
>  private:<br>
> +     bool createControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl,<br>
> +                                   ControlInfo &ctrlInfo);<br>
> +<br>
<br>
We create ControlInfo from a v4l2_query_ext_ctrl with<br>
V4L2Device::v4l2ControlInfo()<br>
<br>
I would name this V4L2Device::v4l2MenuControlInfo() or maybe just<br>
expand V4L2Device::v4l2ControlInfo() with support for menu controls<br>
<br>
>       void listControls();<br>
>       void updateControls(ControlList *ctrls,<br>
>                           Span<const v4l2_ext_control> v4l2Ctrls);<br>
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp<br>
> index 515cbdfe..9f7873f1 100644<br>
> --- a/src/libcamera/v4l2_device.cpp<br>
> +++ b/src/libcamera/v4l2_device.cpp<br>
> @@ -464,6 +464,49 @@ int V4L2Device::ioctl(unsigned long request, void *argp)<br>
>   * \return The V4L2 device file descriptor, -1 if the device node is not open<br>
>   */<br>
><br>
> +/**<br>
> + * \brief Create ControlInfo for v4l2 menu ctrl.<br>
<br>
No '.' at the end of briefs<br>
<br>
> + * \param[in] ctrl The v4l2_query_ext_ctrl that represents a menu<br>
> + * \param[out] ctrlInfo The created controlInfo<br>
> + *<br>
> + * The created ControlInfo contains not only values and also extra values, which<br>
> + * are indices and name/value acquired by VIDIOC_QUERYMENU, respectively. The<br>
> + * extra values contains std::string if the type of \a ctrl is<br>
> + * V4L2_CTRL_TYPE_MENU or int64_t otherwise.<br>
<br>
I don't think this applies in full anymore<br>
<br>
> + *<br>
> + * \return True on success or false otherwise<br>
> + */<br>
> +bool V4L2Device::createControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl,<br>
> +                                       ControlInfo &ctrlInfo)<br>
<br>
ctrlInfo is an output parameter, a * is better suited<br>
<br>
> +{<br>
> +     ASSERT(ctrl.type == V4L2_CTRL_TYPE_MENU ||<br>
> +            ctrl.type == V4L2_CTRL_TYPE_INTEGER_MENU);<br>
<br>
This is internal code, the assertion makes only sure this patch does<br>
what you intend, does it bring any value ?<br>
<br>
> +<br>
> +     std::vector<ControlValue> indices;<br>
> +     v4l2_querymenu menu;<br>
> +     memset(&menu, 0, sizeof(menu));<br>
<br>
I don't recall if we already had a discussion about using menu{};<br>
<br></blockquote><div><br></div><div>I use memset for C structure.</div><div><br></div><div>-Hiro</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +     <a href="http://menu.id" rel="noreferrer" target="_blank">menu.id</a> = <a href="http://ctrl.id" rel="noreferrer" target="_blank">ctrl.id</a>;<br>
> +<br>
> +     for (menu.index = ctrl.minimum;<br>
> +          static_cast<int>(menu.index) <= ctrl.maximum; menu.index++) {<br>
<br>
Do you need the cast ? Here it compiles fine without (clang 11.1.0)<br>
<br>
<br>
> +             if (ioctl(VIDIOC_QUERYMENU, &menu) != 0)<br>
> +                     continue;<br>
> +<br>
> +             indices.emplace_back(static_cast<int32_t>(menu.index));<br>
> +     }<br>
> +<br>
> +     if (indices.empty()) {<br>
<br>
Can this happen ?<br>
More in general, can this function fail at all ?<br>
<br>
I don't like we have<br>
        ctrlInfo = v4l2ControlInfo(ctrl)<br>
and a few lines below<br>
        if (!createControlInfoForMenu(ctrl, ctrlInfo);<br>
<br>
which are basically doing the same thing (create a ControlInfo from a<br>
v4l2_query_ext_ctrl)<br>
<br>
I would suggest either<br>
        ctrlInfo = v4l2ControlInfo(ctrl)<br>
        ....<br>
        ctrlInfo = v4l2MenuControlInfo(ctrl)<br>
<br>
or just support menu in v4l2ControlInfo()<br>
<br>
<br>
> +             LOG(V4L2, Error)<br>
> +                     << "No applicable value: " << utils::hex(<a href="http://ctrl.id" rel="noreferrer" target="_blank">ctrl.id</a>);<br>
> +<br>
> +             return false;<br>
> +     }<br>
> +<br>
> +     ctrlInfo = ControlInfo(indices);<br>
> +<br>
> +     return true;<br>
> +}<br>
> +<br>
>  /*<br>
>   * \brief List and store information about all controls supported by the<br>
>   * V4L2 device<br>
> @@ -473,7 +516,6 @@ void V4L2Device::listControls()<br>
>       ControlInfoMap::Map ctrls;<br>
>       struct v4l2_query_ext_ctrl ctrl = {};<br>
><br>
> -     /* \todo Add support for menu controls. */<br>
>       while (1) {<br>
>               <a href="http://ctrl.id" rel="noreferrer" target="_blank">ctrl.id</a> |= V4L2_CTRL_FLAG_NEXT_CTRL |<br>
>                          V4L2_CTRL_FLAG_NEXT_COMPOUND;<br>
> @@ -484,15 +526,22 @@ void V4L2Device::listControls()<br>
>                   ctrl.flags & V4L2_CTRL_FLAG_DISABLED)<br>
>                       continue;<br>
><br>
> +             ControlInfo ctrlInfo;<br>
>               switch (ctrl.type) {<br>
>               case V4L2_CTRL_TYPE_INTEGER:<br>
>               case V4L2_CTRL_TYPE_BOOLEAN:<br>
> -             case V4L2_CTRL_TYPE_MENU:<br>
>               case V4L2_CTRL_TYPE_BUTTON:<br>
>               case V4L2_CTRL_TYPE_INTEGER64:<br>
>               case V4L2_CTRL_TYPE_BITMASK:<br>
> -             case V4L2_CTRL_TYPE_INTEGER_MENU:<br>
>               case V4L2_CTRL_TYPE_U8:<br>
> +                     ctrlInfo = V4L2ControlInfo(ctrl);<br>
> +                     break;<br>
> +<br>
> +             case V4L2_CTRL_TYPE_INTEGER_MENU:<br>
> +             case V4L2_CTRL_TYPE_MENU:<br>
> +                     if (!createControlInfoForMenu(ctrl, ctrlInfo))<br>
> +                             continue;<br>
> +<br>
>                       break;<br>
>               /* \todo Support other control types. */<br>
>               default:<br>
> @@ -502,10 +551,13 @@ void V4L2Device::listControls()<br>
>                       continue;<br>
>               }<br>
><br>
> +             LOG(V4L2, Debug) << "Control: " << <a href="http://ctrl.name" rel="noreferrer" target="_blank">ctrl.name</a><br>
> +                              << " (" << utils::hex(<a href="http://ctrl.id" rel="noreferrer" target="_blank">ctrl.id</a>) << ")";<br>
> +<br>
>               controlIds_.emplace_back(std::make_unique<V4L2ControlId>(ctrl));<br>
>               controlInfo_.emplace(<a href="http://ctrl.id" rel="noreferrer" target="_blank">ctrl.id</a>, ctrl);<br>
><br>
> -             ctrls.emplace(controlIds_.back().get(), V4L2ControlInfo(ctrl));<br>
> +             ctrls.emplace(controlIds_.back().get(), ctrlInfo);<br>
>       }<br>
><br>
>       controls_ = std::move(ctrls);<br>
> @@ -572,6 +624,10 @@ void V4L2Device::updateControls(ControlList *ctrls,<br>
>                       value.set<int64_t>(v4l2Ctrl->value64);<br>
>                       break;<br>
><br>
> +             case ControlTypeInteger32:<br>
> +                     value.set<int32_t>(v4l2Ctrl->value);<br>
> +                     break;<br>
> +<br>
>               case ControlTypeByte:<br>
>                       /*<br>
>                        * No action required, the VIDIOC_[GS]_EXT_CTRLS ioctl<br>
> --<br>
> 2.31.1.751.gd2f1c929bd-goog<br>
><br>
</blockquote></div></div>