[{"id":33677,"web_url":"https://patchwork.libcamera.org/comment/33677/","msgid":"<jevihgtnk7utjfbrxqs3zt4oedmtfgrwdr5vupy3ou6trbx7ut@32afqwrqs66e>","date":"2025-03-21T13:57:36","subject":"Re: [PATCH v3 2/4] libcamera: pipeline: uvcvideo: Fix\n\t`ExposureTimeMode` control setting","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Barnabás\n\nOn Fri, Mar 14, 2025 at 06:42:46PM +0100, Barnabás Pőcze wrote:\n> The mapping in `UVCCameraData::processControl()` is not entirely correct\n> because the control value is retrieved as a `bool` instead of `int32_t`.\n> Additionally, the available modes are not taken into account.\n>\n> Retrieve the control value with the right type, `int32_t`, check if the\n> requested mode is available, and if so, set the appropriate v4l2 control\n> value selected by `addControl()` earlier.\n>\n> Fixes: bad8d591f8acfa (\"libcamera: uvcvideo: Register ExposureTimeMode control\")\n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 29 ++++++++++++++------\n>  1 file changed, 20 insertions(+), 9 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n> index 5c9025d9b..4ff79c291 100644\n> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n> @@ -99,8 +99,8 @@ public:\n>  \tbool match(DeviceEnumerator *enumerator) override;\n>\n>  private:\n> -\tint processControl(ControlList *controls, unsigned int id,\n> -\t\t\t   const ControlValue &value);\n> +\tint processControl(const UVCCameraData *data, ControlList *controls,\n> +\t\t\t   unsigned int id, const ControlValue &value);\n>  \tint processControls(UVCCameraData *data, Request *request);\n>\n>  \tbool acquireDevice(Camera *camera) override;\n> @@ -313,8 +313,8 @@ void PipelineHandlerUVC::stopDevice(Camera *camera)\n>  \tdata->video_->releaseBuffers();\n>  }\n>\n> -int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n> -\t\t\t\t       const ControlValue &value)\n> +int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *controls,\n> +\t\t\t\t       unsigned int id, const ControlValue &value)\n>  {\n>  \tuint32_t cid;\n>\n> @@ -358,10 +358,21 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n>  \t}\n>\n>  \tcase V4L2_CID_EXPOSURE_AUTO: {\n> -\t\tint32_t ivalue = value.get<bool>()\n> -\t\t\t       ? V4L2_EXPOSURE_APERTURE_PRIORITY\n> -\t\t\t       : V4L2_EXPOSURE_MANUAL;\n> -\t\tcontrols->set(V4L2_CID_EXPOSURE_AUTO, ivalue);\n> +\t\tstd::optional<v4l2_exposure_auto_type> mode;\n> +\n> +\t\tswitch (value.get<int32_t>()) {\n> +\t\tcase controls::ExposureTimeModeAuto:\n> +\t\t\tmode = data->autoExposureMode_;\n> +\t\t\tbreak;\n> +\t\tcase controls::ExposureTimeModeManual:\n> +\t\t\tmode = data->manualExposureMode_;\n> +\t\t\tbreak;\n> +\t\t}\n> +\n> +\t\tif (!mode)\n> +\t\t\treturn -EINVAL;\n\nHere as well I don't think mode can be not initialized.\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\n> +\n> +\t\tcontrols->set(V4L2_CID_EXPOSURE_AUTO, static_cast<int32_t>(*mode));\n>  \t\tbreak;\n>  \t}\n>\n> @@ -399,7 +410,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n>  \tControlList controls(data->video_->controls());\n>\n>  \tfor (const auto &[id, value] : request->controls())\n> -\t\tprocessControl(&controls, id, value);\n> +\t\tprocessControl(data, &controls, id, value);\n>\n>  \tfor (const auto &ctrl : controls)\n>  \t\tLOG(UVC, Debug)\n> --\n> 2.48.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A2715C3274\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 21 Mar 2025 13:57:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CB42168952;\n\tFri, 21 Mar 2025 14:57:40 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 47C3268947\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Mar 2025 14:57:39 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CC6B6220;\n\tFri, 21 Mar 2025 14:55:54 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"MP3/XVTB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742565354;\n\tbh=Lu1MoPH7kiVkIkeagFjs9BBh0Av1Z5afqqIfED7S++k=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=MP3/XVTBAHiJrcTphpDaYXxTz5LHp34MpdS6p2rpVLHtrhbABJG0hVXwDKLOZ+IzB\n\tV1aLUSL/Y6jWJoSkB6TLCfTJ0Ft0loNtWyNc8sCDp9wjDdWNo3ZkO+3m6R/Ec7lg7f\n\tLHrR349ZG6gjABlssHaIig4UMPRy/YENC/kOlGwY=","Date":"Fri, 21 Mar 2025 14:57:36 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3 2/4] libcamera: pipeline: uvcvideo: Fix\n\t`ExposureTimeMode` control setting","Message-ID":"<jevihgtnk7utjfbrxqs3zt4oedmtfgrwdr5vupy3ou6trbx7ut@32afqwrqs66e>","References":"<20250314174248.1015718-1-barnabas.pocze@ideasonboard.com>\n\t<20250314174248.1015718-3-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250314174248.1015718-3-barnabas.pocze@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":33679,"web_url":"https://patchwork.libcamera.org/comment/33679/","msgid":"<544abe3e-4c77-4e75-b22f-9c34a93fbe92@ideasonboard.com>","date":"2025-03-21T14:04:42","subject":"Re: [PATCH v3 2/4] libcamera: pipeline: uvcvideo: Fix\n\t`ExposureTimeMode` control setting","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 03. 21. 14:57 keltezéssel, Jacopo Mondi írta:\n> Hi Barnabás\n> \n> On Fri, Mar 14, 2025 at 06:42:46PM +0100, Barnabás Pőcze wrote:\n>> The mapping in `UVCCameraData::processControl()` is not entirely correct\n>> because the control value is retrieved as a `bool` instead of `int32_t`.\n>> Additionally, the available modes are not taken into account.\n>>\n>> Retrieve the control value with the right type, `int32_t`, check if the\n>> requested mode is available, and if so, set the appropriate v4l2 control\n>> value selected by `addControl()` earlier.\n>>\n>> Fixes: bad8d591f8acfa (\"libcamera: uvcvideo: Register ExposureTimeMode control\")\n>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n>> ---\n>>   src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 29 ++++++++++++++------\n>>   1 file changed, 20 insertions(+), 9 deletions(-)\n>>\n>> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n>> index 5c9025d9b..4ff79c291 100644\n>> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n>> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n>> @@ -99,8 +99,8 @@ public:\n>>   \tbool match(DeviceEnumerator *enumerator) override;\n>>\n>>   private:\n>> -\tint processControl(ControlList *controls, unsigned int id,\n>> -\t\t\t   const ControlValue &value);\n>> +\tint processControl(const UVCCameraData *data, ControlList *controls,\n>> +\t\t\t   unsigned int id, const ControlValue &value);\n>>   \tint processControls(UVCCameraData *data, Request *request);\n>>\n>>   \tbool acquireDevice(Camera *camera) override;\n>> @@ -313,8 +313,8 @@ void PipelineHandlerUVC::stopDevice(Camera *camera)\n>>   \tdata->video_->releaseBuffers();\n>>   }\n>>\n>> -int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n>> -\t\t\t\t       const ControlValue &value)\n>> +int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *controls,\n>> +\t\t\t\t       unsigned int id, const ControlValue &value)\n>>   {\n>>   \tuint32_t cid;\n>>\n>> @@ -358,10 +358,21 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n>>   \t}\n>>\n>>   \tcase V4L2_CID_EXPOSURE_AUTO: {\n>> -\t\tint32_t ivalue = value.get<bool>()\n>> -\t\t\t       ? V4L2_EXPOSURE_APERTURE_PRIORITY\n>> -\t\t\t       : V4L2_EXPOSURE_MANUAL;\n>> -\t\tcontrols->set(V4L2_CID_EXPOSURE_AUTO, ivalue);\n>> +\t\tstd::optional<v4l2_exposure_auto_type> mode;\n>> +\n>> +\t\tswitch (value.get<int32_t>()) {\n>> +\t\tcase controls::ExposureTimeModeAuto:\n>> +\t\t\tmode = data->autoExposureMode_;\n>> +\t\t\tbreak;\n>> +\t\tcase controls::ExposureTimeModeManual:\n>> +\t\t\tmode = data->manualExposureMode_;\n>> +\t\t\tbreak;\n>> +\t\t}\n>> +\n>> +\t\tif (!mode)\n>> +\t\t\treturn -EINVAL;\n> \n> Here as well I don't think mode can be not initialized.\n\nI believe it is, because the `CameraControlValidator` class does not check\nactual values, only whether or not the control itself is supported. Maybe\nit should be extended to do so.\n\n\nRegards,\nBarnabás Pőcze\n\n\n> \n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> \n>> +\n>> +\t\tcontrols->set(V4L2_CID_EXPOSURE_AUTO, static_cast<int32_t>(*mode));\n>>   \t\tbreak;\n>>   \t}\n>>\n>> @@ -399,7 +410,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n>>   \tControlList controls(data->video_->controls());\n>>\n>>   \tfor (const auto &[id, value] : request->controls())\n>> -\t\tprocessControl(&controls, id, value);\n>> +\t\tprocessControl(data, &controls, id, value);\n>>\n>>   \tfor (const auto &ctrl : controls)\n>>   \t\tLOG(UVC, Debug)\n>> --\n>> 2.48.1\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id AC6A4C3274\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 21 Mar 2025 14:04:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BACB068953;\n\tFri, 21 Mar 2025 15:04:49 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AE6CF6894B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 21 Mar 2025 15:04:47 +0100 (CET)","from [192.168.33.18] (185.221.143.221.nat.pool.zt.hu\n\t[185.221.143.221])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9AD0F9FF;\n\tFri, 21 Mar 2025 15:03:02 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"UwHx31FO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742565783;\n\tbh=UcuCklIjOAusQtitewoXbvKvlPkVrk66ttrk1JibLfM=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=UwHx31FOZGHo2XlRAFB0PzPYVJ7Myl/OO8Ztb7JUXTSyUUBGDOiyTjYDvAB3Px+N3\n\tzGvIOobKclvpd15qVl/ziP7+tvVZhU5HX9zpiG6xwVio+AiFjnl7flQlqMs2C9AcN3\n\tfWNJFFBUheAL79GR6uIlNgs7MWP0XSyu9KURoO1Q=","Message-ID":"<544abe3e-4c77-4e75-b22f-9c34a93fbe92@ideasonboard.com>","Date":"Fri, 21 Mar 2025 15:04:42 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 2/4] libcamera: pipeline: uvcvideo: Fix\n\t`ExposureTimeMode` control setting","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20250314174248.1015718-1-barnabas.pocze@ideasonboard.com>\n\t<20250314174248.1015718-3-barnabas.pocze@ideasonboard.com>\n\t<jevihgtnk7utjfbrxqs3zt4oedmtfgrwdr5vupy3ou6trbx7ut@32afqwrqs66e>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<jevihgtnk7utjfbrxqs3zt4oedmtfgrwdr5vupy3ou6trbx7ut@32afqwrqs66e>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]