Patch Detail
Show a patch.
GET /api/1.1/patches/1551/?format=api
{ "id": 1551, "url": "https://patchwork.libcamera.org/api/1.1/patches/1551/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1551/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190630233817.10130-10-laurent.pinchart@ideasonboard.com>", "date": "2019-06-30T23:38:12", "name": "[libcamera-devel,v3,09/14] libcamera: pipeline: uvcvideo: Add controls support", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "dd197aa0c85188d099562a2a70f54c81539626ef", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1551/mbox/", "series": [ { "id": 384, "url": "https://patchwork.libcamera.org/api/1.1/series/384/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=384", "date": "2019-06-30T23:38:03", "name": "libcamera Controls", "version": 3, "mbox": "https://patchwork.libcamera.org/series/384/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1551/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1551/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 7846A61F3A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 1 Jul 2019 01:38:45 +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 1B232BC5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 1 Jul 2019 01:38:45 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1561937925;\n\tbh=uoC0+3e4gZCQL+TPsJ3lWagINWmWETTe6AMv9Hh8+Tc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=dfgfXwXM28vRYvhtvodcAfDFvLDZKZlH7d8rGxd7IJFB2pzWpsVQ6yikMGDBHC7Bv\n\tnRgtgINY8pyYQRS82g0XZXk9Mhr/i5Q7h9wbmqZSb4Zzlg9vDX+OYMvSHQ6IbPqhRv\n\tQGCWDuzyQnyv4wxteKTi5XaGSuOdJSpaMxDV9+QE=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 1 Jul 2019 02:38:12 +0300", "Message-Id": "<20190630233817.10130-10-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190630233817.10130-1-laurent.pinchart@ideasonboard.com>", "References": "<20190630233817.10130-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 09/14] libcamera: pipeline: uvcvideo:\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": "Sun, 30 Jun 2019 23:38:47 -0000" }, "content": "From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nImplement control support in the UVC pipeline handler by dynamically\nquerying the V4L2 device for the supported V4L2 controls and populating\nthe list of camera controls accordingly.\n\nNot-signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/uvcvideo.cpp | 129 +++++++++++++++++++++++++---\n 1 file changed, 115 insertions(+), 14 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\nindex 2e22523d7cb1..f68dc5bd6f74 100644\n--- a/src/libcamera/pipeline/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo.cpp\n@@ -6,8 +6,11 @@\n */\n \n #include <algorithm>\n+#include <iomanip>\n+#include <tuple>\n \n #include <libcamera/camera.h>\n+#include <libcamera/controls.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n@@ -16,6 +19,7 @@\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@@ -35,6 +39,7 @@ public:\n \t\tdelete video_;\n \t}\n \n+\tint init(MediaEntity *entity);\n \tvoid bufferReady(Buffer *buffer);\n \n \tV4L2VideoDevice *video_;\n@@ -71,6 +76,8 @@ public:\n \tbool match(DeviceEnumerator *enumerator) override;\n \n private:\n+\tint processControls(UVCCameraData *data, Request *request);\n+\n \tUVCCameraData *cameraData(const Camera *camera)\n \t{\n \t\treturn static_cast<UVCCameraData *>(\n@@ -216,6 +223,54 @@ void PipelineHandlerUVC::stop(Camera *camera)\n \tPipelineHandler::stop(camera);\n }\n \n+int PipelineHandlerUVC::processControls(UVCCameraData *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\tcase ManualExposure:\n+\t\t\tcontrols.add(V4L2_CID_EXPOSURE_AUTO, 1);\n+\t\t\tcontrols.add(V4L2_CID_EXPOSURE_ABSOLUTE, value.getInt());\n+\t\t\tbreak;\n+\n+\t\tcase ManualGain:\n+\t\t\tcontrols.add(V4L2_CID_GAIN, 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(UVC, 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->video_->setControls(&controls);\n+\tif (ret)\n+\t\tLOG(UVC, Error) << \"Failed to set controls\";\n+\n+\treturn ret;\n+}\n+\n int PipelineHandlerUVC::queueRequest(Camera *camera, Request *request)\n {\n \tUVCCameraData *data = cameraData(camera);\n@@ -227,7 +282,11 @@ int PipelineHandlerUVC::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@@ -247,24 +306,14 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n \n \tstd::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(this);\n \n-\t/* Locate and open the default video node. */\n+\t/* Locate and initialise the camera data with the default video node. */\n \tfor (MediaEntity *entity : media->entities()) {\n \t\tif (entity->flags() & MEDIA_ENT_FL_DEFAULT) {\n-\t\t\tdata->video_ = new V4L2VideoDevice(entity);\n-\t\t\tbreak;\n+\t\t\tif (data->init(entity))\n+\t\t\t\treturn false;\n \t\t}\n \t}\n \n-\tif (!data->video_) {\n-\t\tLOG(UVC, Error) << \"Could not find a default video device\";\n-\t\treturn false;\n-\t}\n-\n-\tif (data->video_->open())\n-\t\treturn false;\n-\n-\tdata->video_->bufferReady.connect(data.get(), &UVCCameraData::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, media->model(), streams);\n@@ -276,6 +325,58 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n \treturn true;\n }\n \n+int UVCCameraData::init(MediaEntity *entity)\n+{\n+\tint ret;\n+\n+\t/* Create and open the video device. */\n+\tvideo_ = new V4L2VideoDevice(entity);\n+\tif (!video_) {\n+\t\tLOG(UVC, Error) << \"Could not find a default video device\";\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tret = video_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tvideo_->bufferReady.connect(this, &UVCCameraData::bufferReady);\n+\n+\t/* Initialise the supported controls. */\n+\tconst V4L2ControlInfoMap &controls = video_->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\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n+\t\t\tid = ManualExposure;\n+\t\t\tbreak;\n+\t\tcase V4L2_CID_GAIN:\n+\t\t\tid = ManualGain;\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 UVCCameraData::bufferReady(Buffer *buffer)\n {\n \tRequest *request = queuedRequests_.front();\n", "prefixes": [ "libcamera-devel", "v3", "09/14" ] }