[{"id":2084,"web_url":"https://patchwork.libcamera.org/comment/2084/","msgid":"<20190701170444.ucsenwqw7hfulylb@uno.localdomain>","date":"2019-07-01T17:04:44","subject":"Re: [libcamera-devel] [PATCH v3 10/14] libcamera: pipeline: vimc:\n\tAdd controls support","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Mon, Jul 01, 2019 at 02:38:13AM +0300, Laurent Pinchart wrote:\n> Implement control support in the VIMC pipeline handler by dynamically\n> querying the V4L2 device for the supported V4L2 controls and populating\n> the list of camera controls accordingly.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nSame comments as the UVC pipeline handler.\n\nThanks\n   j\n\n> ---\n>  src/libcamera/pipeline/vimc.cpp | 105 ++++++++++++++++++++++++++++++--\n>  1 file changed, 100 insertions(+), 5 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index 6833213650dc..fb073f2d078e 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,45 @@ 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\";\n> +\n> +\treturn ret;\n> +}\n> +\n>  int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)\n>  {\n>  \tVimcCameraData *data = cameraData(camera);\n> @@ -226,7 +275,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 +315,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 +327,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> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 51D8660BF8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Jul 2019 19:03:28 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay1-d.mail.gandi.net (Postfix) with ESMTPSA id DDB0C240002;\n\tMon,  1 Jul 2019 17:03:27 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Mon, 1 Jul 2019 19:04:44 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190701170444.ucsenwqw7hfulylb@uno.localdomain>","References":"<20190630233817.10130-1-laurent.pinchart@ideasonboard.com>\n\t<20190630233817.10130-11-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"2qyv224oz6g7rcgt\"","Content-Disposition":"inline","In-Reply-To":"<20190630233817.10130-11-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH v3 10/14] libcamera: pipeline: vimc:\n\tAdd controls 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 17:03:28 -0000"}}]