{"id":3535,"url":"https://patchwork.libcamera.org/api/patches/3535/?format=json","web_url":"https://patchwork.libcamera.org/patch/3535/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20200425004533.26907-2-laurent.pinchart@ideasonboard.com>","date":"2020-04-25T00:45:27","name":"[libcamera-devel,v5,1/7] libcamera: pipeline: uvcvideo: Refactor control handling","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"250e6c5460dc66a363ed6fec5ffc88e392dfcb7c","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3535/mbox/","series":[{"id":824,"url":"https://patchwork.libcamera.org/api/series/824/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=824","date":"2020-04-25T00:45:26","name":"Patchset for libcamera controls","version":5,"mbox":"https://patchwork.libcamera.org/series/824/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3535/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3535/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 9229262E67\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 25 Apr 2020 02:45:52 +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 14AC8A2A;\n\tSat, 25 Apr 2020 02:45:52 +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=\"c1VnRet0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1587775552;\n\tbh=448iEOPlaUemeZNL2zT+W4rOBRbWl1QT4fdKb9St0Js=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=c1VnRet0acqX7sdQKSLhRdx8MzPhxDJwsq3PKnCwkl+r3JJMLRBKgZfI7n2qGvYDd\n\tXPQHtlj8tyQdZQ4fOU2RDN9sGZxIPzIaAXON1v4HYLyqf3/SnIz+WkED7YeHnpJBOq\n\t8n8imFZ9bgCLGvivr0wOXIf4Hl0Xu0JDXI3U//yA=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 25 Apr 2020 03:45:27 +0300","Message-Id":"<20200425004533.26907-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.25.3","In-Reply-To":"<20200425004533.26907-1-laurent.pinchart@ideasonboard.com>","References":"<20200425004533.26907-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 1/7] libcamera: pipeline: uvcvideo:\n\tRefactor control handling","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":"Sat, 25 Apr 2020 00:45:52 -0000"},"content":"Move addition and processing of individual controls to separate\nfunctions, to prepare for more complex mappings of control values.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 103 ++++++++++++-------\n 1 file changed, 67 insertions(+), 36 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex ffbddf27ae2f..92777b9f5fe4 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -42,6 +42,8 @@ public:\n \t}\n \n \tint init(MediaEntity *entity);\n+\tvoid addControl(uint32_t cid, const ControlInfo &v4l2info,\n+\t\t\tControlInfoMap::Map *ctrls);\n \tvoid bufferReady(FrameBuffer *buffer);\n \n \tV4L2VideoDevice *video_;\n@@ -76,6 +78,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 processControls(UVCCameraData *data, Request *request);\n \n \tUVCCameraData *cameraData(const Camera *camera)\n@@ -237,6 +241,37 @@ void PipelineHandlerUVC::stop(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+{\n+\tif (value.type() != ControlTypeInteger32)\n+\t\treturn -EINVAL;\n+\n+\tuint32_t cid;\n+\n+\tif (id == controls::Brightness)\n+\t\tcid = V4L2_CID_BRIGHTNESS;\n+\telse if (id == controls::Contrast)\n+\t\tcid = V4L2_CID_CONTRAST;\n+\telse if (id == controls::Saturation)\n+\t\tcid = V4L2_CID_SATURATION;\n+\telse if (id == controls::ManualExposure)\n+\t\tcid = V4L2_CID_EXPOSURE_ABSOLUTE;\n+\telse if (id == controls::ManualGain)\n+\t\tcid = V4L2_CID_GAIN;\n+\telse\n+\t\treturn -EINVAL;\n+\n+\tint32_t ivalue = value.get<int32_t>();\n+\n+\tif (cid == V4L2_CID_EXPOSURE_ABSOLUTE)\n+\t\tcontrols->set(V4L2_CID_EXPOSURE_AUTO, static_cast<int32_t>(1));\n+\n+\tcontrols->set(cid, ivalue);\n+\n+\treturn 0;\n+}\n+\n int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n {\n \tControlList controls(data->video_->controls());\n@@ -245,18 +280,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n \t\tunsigned int id = it.first;\n \t\tControlValue &value = it.second;\n \n-\t\tif (id == controls::Brightness) {\n-\t\t\tcontrols.set(V4L2_CID_BRIGHTNESS, value);\n-\t\t} else if (id == controls::Contrast) {\n-\t\t\tcontrols.set(V4L2_CID_CONTRAST, value);\n-\t\t} else if (id == controls::Saturation) {\n-\t\t\tcontrols.set(V4L2_CID_SATURATION, value);\n-\t\t} else if (id == controls::ManualExposure) {\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} else if (id == controls::ManualGain) {\n-\t\t\tcontrols.set(V4L2_CID_GAIN, value);\n-\t\t}\n+\t\tprocessControl(&controls, id, value);\n \t}\n \n \tfor (const auto &ctrl : controls)\n@@ -346,34 +370,13 @@ int UVCCameraData::init(MediaEntity *entity)\n \tvideo_->bufferReady.connect(this, &UVCCameraData::bufferReady);\n \n \t/* Initialise the supported controls. */\n-\tconst ControlInfoMap &controls = video_->controls();\n \tControlInfoMap::Map ctrls;\n \n-\tfor (const auto &ctrl : controls) {\n+\tfor (const auto &ctrl : video_->controls()) {\n+\t\tuint32_t cid = ctrl.first->id();\n \t\tconst ControlInfo &info = ctrl.second;\n-\t\tconst ControlId *id;\n \n-\t\tswitch (ctrl.first->id()) {\n-\t\tcase V4L2_CID_BRIGHTNESS:\n-\t\t\tid = &controls::Brightness;\n-\t\t\tbreak;\n-\t\tcase V4L2_CID_CONTRAST:\n-\t\t\tid = &controls::Contrast;\n-\t\t\tbreak;\n-\t\tcase V4L2_CID_SATURATION:\n-\t\t\tid = &controls::Saturation;\n-\t\t\tbreak;\n-\t\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n-\t\t\tid = &controls::ManualExposure;\n-\t\t\tbreak;\n-\t\tcase V4L2_CID_GAIN:\n-\t\t\tid = &controls::ManualGain;\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\tcontinue;\n-\t\t}\n-\n-\t\tctrls.emplace(id, info);\n+\t\taddControl(cid, info, &ctrls);\n \t}\n \n \tcontrolInfo_ = std::move(ctrls);\n@@ -381,6 +384,34 @@ int UVCCameraData::init(MediaEntity *entity)\n \treturn 0;\n }\n \n+void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n+\t\t\t       ControlInfoMap::Map *ctrls)\n+{\n+\tconst ControlId *id;\n+\n+\tswitch (cid) {\n+\tcase V4L2_CID_BRIGHTNESS:\n+\t\tid = &controls::Brightness;\n+\t\tbreak;\n+\tcase V4L2_CID_CONTRAST:\n+\t\tid = &controls::Contrast;\n+\t\tbreak;\n+\tcase V4L2_CID_SATURATION:\n+\t\tid = &controls::Saturation;\n+\t\tbreak;\n+\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n+\t\tid = &controls::ManualExposure;\n+\t\tbreak;\n+\tcase V4L2_CID_GAIN:\n+\t\tid = &controls::ManualGain;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn;\n+\t}\n+\n+\tctrls->emplace(id, v4l2Info);\n+}\n+\n void UVCCameraData::bufferReady(FrameBuffer *buffer)\n {\n \tRequest *request = buffer->request();\n","prefixes":["libcamera-devel","v5","1/7"]}