From patchwork Fri Jun 21 16:14:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1501 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A8E8F600F7 for ; Fri, 21 Jun 2019 18:14:08 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4907D52A; Fri, 21 Jun 2019 18:14:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1561133648; bh=0wLOUMpJartSM/CFN0lzrHPCTIpwC5tvrXjd1gi13vY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VD2cfcmsZqeFUOoplhHeX6GxE/n49nADOx/4N4uz4ONErpXKhM3rKhnzvuXeOHUzS xNRIFcF7XXFz/sl2UZ8bcMrlnNaE1Eko4ufZvkdXspWmc12RUw0krdqvNLf7eiKtH9 jehG03qnoTtmIUrRRtw/YjSyjvo3WE0p3/hMPpY4= From: Kieran Bingham To: LibCamera Devel Date: Fri, 21 Jun 2019 17:14:00 +0100 Message-Id: <20190621161401.28337-9-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621161401.28337-1-kieran.bingham@ideasonboard.com> References: <20190621161401.28337-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 8/9] [PoC] UVCPipelineHandler: Set Controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jun 2019 16:14:09 -0000 Provide an initial sketch of setting controls on the UVC Video Device making use of the V4L2Control API and interacting with Libcamera controls. This is not intended to be a full implementation, simply an initial demonstration of setting real-world controls from requests. Not-signed-off-by: Kieran Bingham --- src/libcamera/pipeline/uvcvideo.cpp | 43 ++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 2e22523d7cb1..14a2089ea654 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -16,6 +17,7 @@ #include "media_device.h" #include "pipeline_handler.h" #include "utils.h" +#include "v4l2_controls.h" #include "v4l2_videodevice.h" namespace libcamera { @@ -71,6 +73,8 @@ public: bool match(DeviceEnumerator *enumerator) override; private: + int processControls(UVCCameraData *data, Request *request); + UVCCameraData *cameraData(const Camera *camera) { return static_cast( @@ -216,6 +220,39 @@ void PipelineHandlerUVC::stop(Camera *camera) PipelineHandler::stop(camera); } +int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request) +{ + V4L2Controls controls; + + for (auto it : request->controls()) { + const ControlInfo &ci = it.first; + Value &value = it.second; + + switch (ci.id()) { + case ManualBrightness: + LOG(UVC, Debug) << "Setting Brightness to : " << value; + controls.add(V4L2_CID_BRIGHTNESS, value.getInt()); + break; + case ManualExposure: + LOG(UVC, Debug) << "Setting Exposure to : " << value; + controls.add(V4L2_CID_EXPOSURE_AUTO, 1); + controls.add(V4L2_CID_EXPOSURE_ABSOLUTE, value.getInt()); + break; + case ManualGain: + default: + LOG(UVC, Debug) << "Unsupported control: " + << ci.name() << " : " << value; + break; + } + } + + int ret = data->video_->setControls(&controls); + if (ret) + LOG(UVC, Error) << "Failed to set controls"; + + return ret; +} + int PipelineHandlerUVC::queueRequest(Camera *camera, Request *request) { UVCCameraData *data = cameraData(camera); @@ -227,7 +264,11 @@ int PipelineHandlerUVC::queueRequest(Camera *camera, Request *request) return -ENOENT; } - int ret = data->video_->queueBuffer(buffer); + int ret = processControls(data, request); + if (ret < 0) + return ret; + + ret = data->video_->queueBuffer(buffer); if (ret < 0) return ret;