{"id":3507,"url":"https://patchwork.libcamera.org/api/1.1/patches/3507/?format=json","web_url":"https://patchwork.libcamera.org/patch/3507/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200423190443.31510-1-laurent.pinchart@ideasonboard.com>","date":"2020-04-23T19:04:43","name":"[libcamera-devel,v3.1,2/5] libcamera: pipeline: uvcvideo: Update exposure/gain ctrls set with new units","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e551de2c8e706418db68dc394082a380d05f1634","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/1.1/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/3507/mbox/","series":[{"id":819,"url":"https://patchwork.libcamera.org/api/1.1/series/819/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=819","date":"2020-04-23T19:04:43","name":null,"version":1,"mbox":"https://patchwork.libcamera.org/series/819/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3507/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3507/checks/","tags":{},"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 9EC6062E45\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Apr 2020 21:05:02 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0F63B4F7;\n\tThu, 23 Apr 2020 21:05:02 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"uHicGSgg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1587668702;\n\tbh=x8za8beMjIMY2dG8Ib7RxjJV2l6PoWdqzBtlPbVXS4k=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=uHicGSggJl4VJqfJzqm505GUv6mQERjl9zYJsfnp2tOpCSD7RzexDIcIW9w130aa0\n\tk53QJqBcKQB/KJn4zU+Fs+Bpwri1MAtjNDozvuzMuKIj/UbIXBDGPq/GOmlxTy1bSt\n\tCyWbuQbPHp3uGxBE77wOiqr35aGtfCxr9tPVD+zk=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 23 Apr 2020 22:04:43 +0300","Message-Id":"<20200423190443.31510-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.25.3","In-Reply-To":"<20200423173613.GI6196@pendragon.ideasonboard.com>","References":"<20200423173613.GI6196@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3.1 2/5] libcamera: pipeline: uvcvideo:\n\tUpdate exposure/gain ctrls set with new units","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":"Thu, 23 Apr 2020 19:05:03 -0000"},"content":"From: Naushir Patuck <naush@raspberrypi.com>\n\nThe ExposureTime control now uses units of 1 micro-second, and UVC\nuses units of 100 micro-seconds. Correctly map the values before\nsetting V4L2_CID_EXPOSURE_ABSOLUTE on the V4L2 device.\n\nThe AnalogueGain control now uses floats to allow fractional gain\nvalues. Since UVC has no explicit gain units, map the default gain value\nto 1.0 and linearly map to the requested value.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v3:\n\n- Round the gain value to the nearest integer when converting from float\n- Use float values for the gain range\n---\nHi Naush,\n\nI realized there were two issues in the previous version of the patch:\n\n- The gain was always rounded down, preventing my sine wave gain test\n  from reaching the maximum value as I never hit the case where sin(w*t)\n  was exactly equal to 1.0.\n\n- The gain control info was reported as int32_t values, when the control\n  is of type float. This was reported by an error message in\n  ControlInfoMap::generateIdmap() which I initially missed, wondering\n  why the gain was not applied.\n\nThis new version fixes both issues. The conversion from int32_t to float\nfor the range may not be very nice, but I propose addressing that\nseparately on top if we deem it necessary.\n\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 28 +++++++++++++++++---\n 1 file changed, 25 insertions(+), 3 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex d7df95e4519a..09176b4e0d17 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -253,9 +253,22 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n \t\t\tcontrols.set(V4L2_CID_SATURATION, value);\n \t\t} else if (id == controls::ExposureTime) {\n \t\t\tcontrols.set(V4L2_CID_EXPOSURE_AUTO, static_cast<int32_t>(1));\n-\t\t\tcontrols.set(V4L2_CID_EXPOSURE_ABSOLUTE, value);\n+\t\t\t/*\n+\t\t\t * controls::ExposureTime is in units of 1 us, and UVC\n+\t\t\t * expects V4L2_CID_EXPOSURE_ABSOLUTE in units of 100 us.\n+\t\t\t */\n+\t\t\tcontrols.set(V4L2_CID_EXPOSURE_ABSOLUTE,\n+\t\t\t\t     value.get<int32_t>() / 100);\n \t\t} else if (id == controls::AnalogueGain) {\n-\t\t\tcontrols.set(V4L2_CID_GAIN, value);\n+\t\t\t/*\n+\t\t\t * controls::AnalogueGain is specified as an absolute\n+\t\t\t * multiplier for all RGB samples. Map this multiplier\n+\t\t\t * in a linear way such that 1.0 -> default gain\n+\t\t\t * of the V4L2_CID_GAIN control on the uvcvideo device.\n+\t\t\t */\n+\t\t\tconst ControlInfo &gainInfo = controls.infoMap()->at(V4L2_CID_GAIN);\n+\t\t\tint32_t gain = lroundf(value.get<float>() * gainInfo.def().get<int32_t>());\n+\t\t\tcontrols.set(V4L2_CID_GAIN, gain);\n \t\t}\n \t}\n \n@@ -350,7 +363,7 @@ int UVCCameraData::init(MediaEntity *entity)\n \tControlInfoMap::Map ctrls;\n \n \tfor (const auto &ctrl : controls) {\n-\t\tconst ControlInfo &info = ctrl.second;\n+\t\tControlInfo info = ctrl.second;\n \t\tconst ControlId *id;\n \n \t\tswitch (ctrl.first->id()) {\n@@ -368,6 +381,15 @@ int UVCCameraData::init(MediaEntity *entity)\n \t\t\tbreak;\n \t\tcase V4L2_CID_GAIN:\n \t\t\tid = &controls::AnalogueGain;\n+\t\t\t/*\n+\t\t\t * AnalogueGain is a float control, convert the type of\n+\t\t\t * the range.\n+\t\t\t */\n+\t\t\tinfo = ControlInfo{\n+\t\t\t\t{ static_cast<float>(info.min().get<int32_t>()) },\n+\t\t\t\t{ static_cast<float>(info.max().get<int32_t>()) },\n+\t\t\t\t{ static_cast<float>(info.def().get<int32_t>()) }\n+\t\t\t};\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tcontinue;\n","prefixes":["libcamera-devel","v3.1","2/5"]}