From patchwork Fri Mar 14 17:42:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22959 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 848FFC32F7 for ; Fri, 14 Mar 2025 17:42:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D6BA66895A; Fri, 14 Mar 2025 18:42:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="f3xLEkwe"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BBF06894D for ; Fri, 14 Mar 2025 18:42:52 +0100 (CET) Received: from pb-laptop.local (185.221.143.221.nat.pool.zt.hu [185.221.143.221]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2DC66606 for ; Fri, 14 Mar 2025 18:41:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741974073; bh=67/K44/eDRlEHwKTL+1GBN2Sg83yl7CLohkRF8CvJzA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=f3xLEkwe6k4LkGThQQJ1nAQJoXggm1kiNe43kRpG7PONa+xFFxxEMq2eHpmVpq80r y4htDFlnTyHrCTEWWQ2Ls96pCEmVopzLu8gcwcw1s2RQqsZ0g90BtQ3G7LoHaoAb52 XrHO5QKj0I8Guw1cegNvHPGpZht22PZEqXtTkJqs= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 4/4] libcamera: pipeline: uvcvideo: Fix `ExposureTime` control handling Date: Fri, 14 Mar 2025 18:42:48 +0100 Message-ID: <20250314174248.1015718-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250314174248.1015718-1-barnabas.pocze@ideasonboard.com> References: <20250314174248.1015718-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 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" The documentation of `ExposureTime` states that its value is ignored if `ExposureTimeMode` is not manual. This is currently not handled, and if `ExposureTimeMode` is automatic and `ExposureTime` is set, then the controls will be rejected, as expected. Only try to set `V4L2_CID_EXPOSURE_ABSOLUTE` if the current exposure mode is manual. To be able to handle requests that set both `ExposureTime{,Mode}`, process `ExposureTimeMode` first directly in `processControls()`, and store this new mode in a temporary location. Then have `processControl()` act on this temporary state, and only persist the temporary state if `setControls()` on the video device succeeds. Bug: https://bugs.libcamera.org/show_bug.cgi?id=242 Signed-off-by: Barnabás Pőcze --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 52 ++++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 7d882ebe1..22d286e49 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -108,7 +108,7 @@ public: bool match(DeviceEnumerator *enumerator) override; private: - int processControl(const UVCCameraData *data, ControlList *controls, + int processControl(const UVCCameraData::State &state, ControlList *controls, unsigned int id, const ControlValue &value); int processControls(UVCCameraData *data, Request *request); @@ -333,7 +333,7 @@ void PipelineHandlerUVC::stopDevice(Camera *camera) data->state_.reset(); } -int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *controls, +int PipelineHandlerUVC::processControl(const UVCCameraData::State &state, ControlList *controls, unsigned int id, const ControlValue &value) { uint32_t cid; @@ -378,26 +378,13 @@ int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *c } case V4L2_CID_EXPOSURE_AUTO: { - std::optional mode; - - switch (value.get()) { - case controls::ExposureTimeModeAuto: - mode = data->autoExposureMode_; - break; - case controls::ExposureTimeModeManual: - mode = data->manualExposureMode_; - break; - } - - if (!mode) - return -EINVAL; - - controls->set(V4L2_CID_EXPOSURE_AUTO, static_cast(*mode)); + /* Handled directly in `processControls()`. */ break; } case V4L2_CID_EXPOSURE_ABSOLUTE: - controls->set(cid, value.get() / 100); + if (state.exp == controls::ExposureTimeModeManual) + controls->set(cid, value.get() / 100); break; case V4L2_CID_CONTRAST: @@ -428,9 +415,30 @@ int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *c int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request) { ControlList controls(data->video_->controls()); + const auto &reqControls = request->controls(); + auto newState = data->state_; + + if (const auto exp = reqControls.get(controls::ExposureTimeMode)) { + std::optional mode; - for (const auto &[id, value] : request->controls()) - processControl(data, &controls, id, value); + switch (*exp) { + case controls::ExposureTimeModeAuto: + mode = data->autoExposureMode_; + break; + case controls::ExposureTimeModeManual: + mode = data->manualExposureMode_; + break; + } + + if (!mode) + return -EINVAL; + + controls.set(V4L2_CID_EXPOSURE_AUTO, static_cast(*mode)); + newState.exp = static_cast(*exp); + } + + for (const auto &[id, value] : reqControls) + processControl(newState, &controls, id, value); for (const auto &ctrl : controls) LOG(UVC, Debug) @@ -443,7 +451,9 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request) return ret < 0 ? ret : -EINVAL; } - return ret; + data->state_ = newState; + + return 0; } int PipelineHandlerUVC::queueRequestDevice(Camera *camera, Request *request)