From patchwork Fri Sep 13 17:46:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cl=C3=A1udio_Paulo?= X-Patchwork-Id: 21265 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 AA7D6C324C for ; Fri, 13 Sep 2024 17:46:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6FA6F634F8; Fri, 13 Sep 2024 19:46:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=makewise.pt header.i=@makewise.pt header.b="ncXZJdp3"; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.b="YAdCBSvB"; dkim-atps=neutral Received: from a7-20.smtp-out.eu-west-1.amazonses.com (a7-20.smtp-out.eu-west-1.amazonses.com [54.240.7.20]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 44114634E3 for ; Fri, 13 Sep 2024 19:46:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=4ymqmigrodjwq5luewph2eedidgwlpqq; d=makewise.pt; t=1726249569; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=JH5D+nAlVtZPXcWvi8cjEkTpNJjf4VBKppmK/kZY1Dc=; b=ncXZJdp3qpktb3NJxdkhHhdOdHcsNwnMkk2muhjHoS6zaGlsQ68Q57Y0fTVYdVad KucA3XVjBNDAQ109uTLOKHYjddvoIKsL/7iDObBAGdabwI2yvjMAFQOHeEr0NkhVMgs MU02lyC5FTjBMF0cfoWhpxebZwIF8qghNz2/MSzrdW+rUObEUUGgTndW7Y91aEywg2h E11/33MP0ZewfLQvOiT8fhJPvBF4yYjalUAq2t/ytVaUZOIwxx8ycFkNi9jw+PPBRQq SxXmvLtSz6WUGO8fQwMfGLzCrqIio7iRlTuDKGwYEq+jWSRaFMsWsEc8PZIjjrZr93H 9F37iGScfQ== DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726249569; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID; bh=JH5D+nAlVtZPXcWvi8cjEkTpNJjf4VBKppmK/kZY1Dc=; b=YAdCBSvB2Kt8YMnFJH8XyQ1Ztn3kacfDhkUWgLzxQwJGkw2Dhtt8nRuYiF3+T/W+ QxKhihoycCugOyOKJ5pnfX+cst6Q3uLQZX770psJL6bGWbGdlXJQibh04s3TWi10JI1 eWtDFDdD7UG+5jvF1B5uQuEKSPtHEjEPCzgxwZfc= From: =?utf-8?q?Cl=C3=A1udio_Paulo?= To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Cl=C3=A1udio_Paulo?= Subject: [PATCH] libcamera: pipeline: uvcvideo: Retrieve v4l2 device control information Date: Fri, 13 Sep 2024 17:46:08 +0000 Message-ID: <01020191ec7e0ad5-37e0d829-4553-4d41-8063-37af6c08c380-000000@eu-west-1.amazonses.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Feedback-ID: ::1.eu-west-1.z8xjvhxVxUk+kM5mx7i/KMS/a2avhcAXFe/noI67NVQ=:AmazonSES X-SES-Outgoing: 2024.09.13-54.240.7.20 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Populate frame metadata by using V4L2Device::getControls() to get the values for all supported controls on each frame. Signed-off-by: Cláudio Paulo --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 58 ++++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 6b32fa18..98a41557 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -333,8 +333,8 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id, case V4L2_CID_EXPOSURE_AUTO: { int32_t ivalue = value.get() - ? V4L2_EXPOSURE_APERTURE_PRIORITY - : V4L2_EXPOSURE_MANUAL; + ? V4L2_EXPOSURE_APERTURE_PRIORITY + : V4L2_EXPOSURE_MANUAL; controls->set(V4L2_CID_EXPOSURE_AUTO, ivalue); break; } @@ -750,10 +750,60 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info, void UVCCameraData::bufferReady(FrameBuffer *buffer) { Request *request = buffer->request(); + ControlList *metadata = &request->metadata(); /* \todo Use the UVC metadata to calculate a more precise timestamp */ - request->metadata().set(controls::SensorTimestamp, - buffer->metadata().timestamp); + metadata->set(controls::SensorTimestamp, buffer->metadata().timestamp); + + /* Retrieve control as reported by the device. */ + std::vector ids; + for (const auto &ctrl : video_->controls()) { + uint32_t cid = ctrl.first->id(); + switch (cid) { + case V4L2_CID_BRIGHTNESS: + case V4L2_CID_CONTRAST: + case V4L2_CID_SATURATION: + case V4L2_CID_EXPOSURE_AUTO: + case V4L2_CID_EXPOSURE_ABSOLUTE: + case V4L2_CID_GAIN: + case V4L2_CID_FOCUS_ABSOLUTE: + case V4L2_CID_FOCUS_AUTO: + ids.push_back(cid); + break; + default: + continue; + } + } + + ControlList deviceControls = video_->getControls(ids); + for (const auto &item : deviceControls) { + switch (item.first) { + case V4L2_CID_BRIGHTNESS: + metadata->set(controls::Brightness, item.second.get()); + break; + case V4L2_CID_CONTRAST: + metadata->set(controls::Contrast, item.second.get()); + break; + case V4L2_CID_SATURATION: + metadata->set(controls::Saturation, item.second.get()); + break; + case V4L2_CID_EXPOSURE_AUTO: + metadata->set(controls::AeEnable, item.second.get()); + break; + case V4L2_CID_EXPOSURE_ABSOLUTE: + metadata->set(controls::ExposureTime, item.second.get()); + break; + case V4L2_CID_GAIN: + metadata->set(controls::AnalogueGain, item.second.get()); + break; + case V4L2_CID_FOCUS_ABSOLUTE: + metadata->set(controls::LensPosition, item.second.get()); + break; + case V4L2_CID_FOCUS_AUTO: + metadata->set(controls::AfMode, item.second.get()); + break; + } + } pipe()->completeBuffer(request, buffer); pipe()->completeRequest(request);