{"id":1568,"url":"https://patchwork.libcamera.org/api/patches/1568/?format=json","web_url":"https://patchwork.libcamera.org/patch/1568/","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":"<20190701201504.28487-10-laurent.pinchart@ideasonboard.com>","date":"2019-07-01T20:15:00","name":"[libcamera-devel,v4,09/13] libcamera: pipeline: vimc: Add controls support","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"ff081b9ee00bf0491f532b32b00ffd3d9fee0bdd","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/1568/mbox/","series":[{"id":386,"url":"https://patchwork.libcamera.org/api/series/386/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=386","date":"2019-07-01T20:14:51","name":"libcamera Controls","version":4,"mbox":"https://patchwork.libcamera.org/series/386/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1568/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1568/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 281F561F51\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Jul 2019 22:15:31 +0200 (CEST)","from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CB6B6524\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Jul 2019 22:15:30 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562012130;\n\tbh=Qa7AX4MJcxSsLSKsShHQuX8rpQboFf/UV4jQb1ZJ7KA=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=WwHV8eDz/du+DBeg19Wc26Fvg9CjQOuUEvbI5VgyUOfJph82ZfH2bVLECrwEoPjoV\n\th6ZI/Hw6TVLRwl7em4dbkwofTBJiLFhikZLNn4O0AO0iPRzIx/a2KkOctY7AyjvrDN\n\tbZdX/9Zpj7j3+oBh7L/QxLPw/xmPSLSErNTKaBLM=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  1 Jul 2019 23:15:00 +0300","Message-Id":"<20190701201504.28487-10-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>","References":"<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 09/13] libcamera: pipeline: vimc: Add\n\tcontrols support","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Mon, 01 Jul 2019 20:15:32 -0000"},"content":"Implement control support in the VIMC pipeline handler by dynamically\nquerying the V4L2 device for the supported V4L2 controls and populating\nthe list of camera controls accordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v3:\n\n- Fixed error checking when setting controls\n---\n src/libcamera/pipeline/vimc.cpp | 107 ++++++++++++++++++++++++++++++--\n 1 file changed, 102 insertions(+), 5 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex 6833213650dc..f8a58be060bb 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -7,19 +7,24 @@\n \n #include <algorithm>\n #include <array>\n+#include <iomanip>\n+#include <tuple>\n \n #include <libcamera/camera.h>\n+#include <libcamera/controls.h>\n #include <libcamera/ipa/ipa_interface.h>\n #include <libcamera/ipa/ipa_module_info.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"camera_sensor.h\"\n #include \"device_enumerator.h\"\n #include \"ipa_manager.h\"\n #include \"log.h\"\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n+#include \"v4l2_controls.h\"\n #include \"v4l2_videodevice.h\"\n \n namespace libcamera {\n@@ -36,12 +41,15 @@ public:\n \n \t~VimcCameraData()\n \t{\n+\t\tdelete sensor_;\n \t\tdelete video_;\n \t}\n \n+\tint init(MediaDevice *media);\n \tvoid bufferReady(Buffer *buffer);\n \n \tV4L2VideoDevice *video_;\n+\tCameraSensor *sensor_;\n \tStream stream_;\n };\n \n@@ -75,6 +83,8 @@ public:\n \tbool match(DeviceEnumerator *enumerator) override;\n \n private:\n+\tint processControls(VimcCameraData *data, Request *request);\n+\n \tVimcCameraData *cameraData(const Camera *camera)\n \t{\n \t\treturn static_cast<VimcCameraData *>(\n@@ -215,6 +225,47 @@ void PipelineHandlerVimc::stop(Camera *camera)\n \tPipelineHandler::stop(camera);\n }\n \n+int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n+{\n+\tV4L2ControlList controls;\n+\n+\tfor (auto it : request->controls()) {\n+\t\tconst ControlInfo *ci = it.first;\n+\t\tControlValue &value = it.second;\n+\n+\t\tswitch (ci->id()) {\n+\t\tcase Brightness:\n+\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.getInt());\n+\t\t\tbreak;\n+\n+\t\tcase Contrast:\n+\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.getInt());\n+\t\t\tbreak;\n+\n+\t\tcase Saturation:\n+\t\t\tcontrols.add(V4L2_CID_SATURATION, value.getInt());\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tfor (const V4L2Control &ctrl : controls)\n+\t\tLOG(VIMC, Debug)\n+\t\t\t<< \"Setting control 0x\"\n+\t\t\t<< std::hex << std::setw(8) << ctrl.id() << std::dec\n+\t\t\t<< \" to \" << ctrl.value();\n+\n+\tint ret = data->sensor_->setControls(&controls);\n+\tif (ret) {\n+\t\tLOG(VIMC, Error) << \"Failed to set controls: \" << ret;\n+\t\treturn ret < 0 ? ret : -EINVAL;\n+\t}\n+\n+\treturn ret;\n+}\n+\n int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)\n {\n \tVimcCameraData *data = cameraData(camera);\n@@ -226,7 +277,11 @@ int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)\n \t\treturn -ENOENT;\n \t}\n \n-\tint ret = data->video_->queueBuffer(buffer);\n+\tint ret = processControls(data, request);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tret = data->video_->queueBuffer(buffer);\n \tif (ret < 0)\n \t\treturn ret;\n \n@@ -262,12 +317,9 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \tstd::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);\n \n \t/* Locate and open the capture video node. */\n-\tdata->video_ = new V4L2VideoDevice(media->getEntityByName(\"Raw Capture 1\"));\n-\tif (data->video_->open())\n+\tif (data->init(media))\n \t\treturn false;\n \n-\tdata->video_->bufferReady.connect(data.get(), &VimcCameraData::bufferReady);\n-\n \t/* Create and register the camera. */\n \tstd::set<Stream *> streams{ &data->stream_ };\n \tstd::shared_ptr<Camera> camera = Camera::create(this, \"VIMC Sensor B\",\n@@ -277,6 +329,51 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \treturn true;\n }\n \n+int VimcCameraData::init(MediaDevice *media)\n+{\n+\tint ret;\n+\n+\t/* Create and open the video device and the camera sensor. */\n+\tvideo_ = new V4L2VideoDevice(media->getEntityByName(\"Raw Capture 1\"));\n+\tif (video_->open())\n+\t\treturn -ENODEV;\n+\n+\tvideo_->bufferReady.connect(this, &VimcCameraData::bufferReady);\n+\n+\tsensor_ = new CameraSensor(media->getEntityByName(\"Sensor B\"));\n+\tret = sensor_->init();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Initialise the supported controls. */\n+\tconst V4L2ControlInfoMap &controls = sensor_->controls();\n+\tfor (const auto &ctrl : controls) {\n+\t\tunsigned int v4l2Id = ctrl.first;\n+\t\tconst V4L2ControlInfo &info = ctrl.second;\n+\t\tControlId id;\n+\n+\t\tswitch (v4l2Id) {\n+\t\tcase V4L2_CID_BRIGHTNESS:\n+\t\t\tid = Brightness;\n+\t\t\tbreak;\n+\t\tcase V4L2_CID_CONTRAST:\n+\t\t\tid = Contrast;\n+\t\t\tbreak;\n+\t\tcase V4L2_CID_SATURATION:\n+\t\t\tid = Saturation;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tcontrolInfo_.emplace(std::piecewise_construct,\n+\t\t\t\t     std::forward_as_tuple(id),\n+\t\t\t\t     std::forward_as_tuple(id, info.min(), info.max()));\n+\t}\n+\n+\treturn 0;\n+}\n+\n void VimcCameraData::bufferReady(Buffer *buffer)\n {\n \tRequest *request = queuedRequests_.front();\n","prefixes":["libcamera-devel","v4","09/13"]}