From patchwork Tue Jul 25 12:56:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 18891 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C4E8ABDC71 for ; Tue, 25 Jul 2023 12:56:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED3EB628C4; Tue, 25 Jul 2023 14:56:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690289811; bh=zvBHbP5hQQ3RLymul2dakGq72RThh7OoxW54kOu9ffE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=xvLVEPVFrNFGFBPFngmXc0l0M627IqVbWZgXQg0H8V+N/iErFH+db6jUViYjFeG9k Y+X2Lvd3gw3HG3Q4CBW5Flc2WO1TYMETRYHxz1EX1FmifOiflIgUgDol5jqwD6TKit oygdOstSJiUQnL/jpjd49c+5kC42kL+k02DwY3KbDi0WbGf2vseRosXHHMd69J0OaH jgZ+f9I0nfCzsjJP1dYz4omoV3eFp0/Fr/nvw9iaYspoe7/z+lp6JGiqw9zbXo0KdY PnhHUymK2F6sadoswV2zXEJ8w32A51RiZC8EthjzESQu4iZSp6uFsswO45iZJAtRG6 /TMx9GciB8lpw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A57E628BD for ; Tue, 25 Jul 2023 14:56:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Hu6XuJWQ"; dkim-atps=neutral Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B378EBA; Tue, 25 Jul 2023 14:55:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690289749; bh=zvBHbP5hQQ3RLymul2dakGq72RThh7OoxW54kOu9ffE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hu6XuJWQa0zRZ5MPTm9BikBKaOCoYW/1Xi7vnravWQLpnkYPgobJ9V9gOoAbQwo2k SsBjRvYXcX2+kYI4OB0TqnO5UFbXbSN6Zq8jt7Wcpl8JAOYluI+1Pqi7DhWZuXKv+s V1FEAXnI0iBTp24LfBXIaNJLn6m6f4XyLa6jOo1k= To: libcamera devel Date: Tue, 25 Jul 2023 13:56:41 +0100 Message-Id: <20230725125641.1557350-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230725125641.1557350-1-kieran.bingham@ideasonboard.com> References: <20230725125641.1557350-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: pipeline: uvcvideo: Implement AeFlickerMode X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Cc: Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" UVC devices often provide controls to support setting the power line frequency which adapts the camera processing to avoid flicker visible to the user. Now that libcamera has implemented AeFlickerMode, use the new control to implement support for UVC devices. Signed-off-by: Kieran Bingham Reviewed-by: David Plowman --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 59 ++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 38f48a5d9269..365410284e5b 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -89,8 +89,8 @@ public: bool match(DeviceEnumerator *enumerator) override; private: - int processControl(ControlList *controls, unsigned int id, - const ControlValue &value); + int processControl(Request *request, ControlList *controls, + unsigned int id, const ControlValue &value); int processControls(UVCCameraData *data, Request *request); UVCCameraData *cameraData(Camera *camera) @@ -260,7 +260,8 @@ void PipelineHandlerUVC::stopDevice(Camera *camera) data->video_->releaseBuffers(); } -int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id, +int PipelineHandlerUVC::processControl(Request *request, ControlList *controls, + unsigned int id, const ControlValue &value) { uint32_t cid; @@ -277,6 +278,8 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id, cid = V4L2_CID_EXPOSURE_ABSOLUTE; else if (id == controls::AnalogueGain) cid = V4L2_CID_GAIN; + else if (id == controls::AeFlickerMode) + cid = V4L2_CID_POWER_LINE_FREQUENCY; else return -EINVAL; @@ -331,6 +334,42 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id, break; } + case V4L2_CID_POWER_LINE_FREQUENCY: { + enum v4l2_power_line_frequency mode; + unsigned int period = request->controls().get(controls::AeFlickerPeriod) + .value_or(0); + switch (value.get()) { + default: + case controls::FlickerOff: + mode = V4L2_CID_POWER_LINE_FREQUENCY_DISABLED; + break; + case controls::FlickerAuto: + mode = V4L2_CID_POWER_LINE_FREQUENCY_AUTO; + break; + case controls::FlickerManual: + switch (period) { + case 10000: /* 100Hz in microseconds */ + mode = V4L2_CID_POWER_LINE_FREQUENCY_50HZ; + break; + case 8333: /* 120Hz in microseconds */ + mode = V4L2_CID_POWER_LINE_FREQUENCY_60HZ; + break; + default: + LOG(UVC, Warning) + << "Unsupported AeFlickerPeriod : " + << period; + [[fallthrough]]; + case 0: + mode = V4L2_CID_POWER_LINE_FREQUENCY_DISABLED; + break; + } + break; + } + + controls->set(cid, static_cast(mode)); + break; + } + default: { int32_t ivalue = value.get(); controls->set(cid, ivalue); @@ -346,7 +385,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request) ControlList controls(data->video_->controls()); for (const auto &[id, value] : request->controls()) - processControl(&controls, id, value); + processControl(request, &controls, id, value); for (const auto &ctrl : controls) LOG(UVC, Debug) @@ -605,6 +644,9 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info, case V4L2_CID_GAIN: id = &controls::AnalogueGain; break; + case V4L2_CID_POWER_LINE_FREQUENCY: + id = &controls::AeFlickerMode; + break; default: return; } @@ -689,6 +731,15 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info, break; } + case V4L2_CID_POWER_LINE_FREQUENCY: { + info = ControlInfo{ + { static_cast(controls::FlickerOff) }, + { static_cast(controls::FlickerAuto) }, + { static_cast(controls::FlickerOff) } + }; + break; + } + default: info = v4l2Info; break;