From patchwork Fri Mar 14 17:42:45 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: 22956 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 A71FCC32F9 for ; Fri, 14 Mar 2025 17:42:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67BEE68951; Fri, 14 Mar 2025 18:42:53 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="iUNMPEXp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C02A46893D for ; Fri, 14 Mar 2025 18:42:51 +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 6ABD8842 for ; Fri, 14 Mar 2025 18:41:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741974072; bh=2qpqoZ3DL/NFKSUdh8Ka6YMds0Yuv/5ybzbZpYqe++0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iUNMPEXpGVbgQnPr9hWXIjrW+wzlmfhveAafs8xdO0ROsQ9CHG2/yxX7aXrDQtaHv N7am+izqrModjCAO42UhGRRrMJ5CMDsEn6ZWw0OkYAhOKd8p7ZVy4Lj1ZysHaA2rZb yRercF7QBVz8UJBou/X97NEoG9nlOeiA/anIrrHM= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 1/4] libcamera: pipeline: uvcvideo: Fix `ExposureTimeMode` control setup Date: Fri, 14 Mar 2025 18:42:45 +0100 Message-ID: <20250314174248.1015718-2-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" `ControlInfo(Span{...})` calls the incorrect constructor of `ControlInfo`. The intended constructor to be called is `ControlInfo(Span, ...)` however that is not called because a span of `const int32_t` is passed. Instead, the constructor `ControlInfo(const ControlValue &min, const ControlValue &max, ...)` will be called. Furthermore, since `values.back()` is used, only the last element of the array is actually set. To fix this, convert the array to contain `ControlValue` objects and use a separate variable to keep track of which element to set next. For each of `ExposureTimeMode{Auto,Manual}` save the V4L2 control value that is to be used when the libcamera control is set. Fixes: bad8d591f8acfa ("libcamera: uvcvideo: Register ExposureTimeMode control") Signed-off-by: Barnabás Pőcze --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 89 +++++++++++++++----- 1 file changed, 70 insertions(+), 19 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index dedcac89b..5c9025d9b 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -58,6 +59,9 @@ public: Stream stream_; std::map> formats_; + std::optional autoExposureMode_; + std::optional manualExposureMode_; + private: bool generateId(); @@ -108,6 +112,26 @@ private: } }; +namespace { + +std::optional v4l2ToExposureMode(int32_t x) +{ + using namespace controls; + + switch (x) { + case V4L2_EXPOSURE_AUTO: + case V4L2_EXPOSURE_APERTURE_PRIORITY: + return ExposureTimeModeAuto; + case V4L2_EXPOSURE_MANUAL: + case V4L2_EXPOSURE_SHUTTER_PRIORITY: + return ExposureTimeModeManual; + default: + return {}; + } +} + +} /* namespace */ + UVCCameraConfiguration::UVCCameraConfiguration(UVCCameraData *data) : CameraConfiguration(), data_(data) { @@ -725,25 +749,52 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info, * ExposureTimeModeManual = { V4L2_EXPOSURE_MANUAL, * V4L2_EXPOSURE_SHUTTER_PRIORITY } */ - std::array values{}; - - auto it = std::find_if(v4l2Values.begin(), v4l2Values.end(), - [&](const ControlValue &val) { - return (val.get() == V4L2_EXPOSURE_APERTURE_PRIORITY || - val.get() == V4L2_EXPOSURE_AUTO) ? true : false; - }); - if (it != v4l2Values.end()) - values.back() = static_cast(controls::ExposureTimeModeAuto); - - it = std::find_if(v4l2Values.begin(), v4l2Values.end(), - [&](const ControlValue &val) { - return (val.get() == V4L2_EXPOSURE_SHUTTER_PRIORITY || - val.get() == V4L2_EXPOSURE_MANUAL) ? true : false; - }); - if (it != v4l2Values.end()) - values.back() = static_cast(controls::ExposureTimeModeManual); - - info = ControlInfo{Span{values}, values[0]}; + + std::bitset< + std::max(V4L2_EXPOSURE_AUTO, + std::max(V4L2_EXPOSURE_APERTURE_PRIORITY, + std::max(V4L2_EXPOSURE_MANUAL, + V4L2_EXPOSURE_SHUTTER_PRIORITY))) + 1 + > exposureModes; + std::optional lcDef; + + for (const ControlValue &value : v4l2Values) { + const auto x = value.get(); + + if (0 <= x && static_cast(x) < exposureModes.size()) { + exposureModes[x] = true; + + if (x == def) + lcDef = v4l2ToExposureMode(x); + } + } + + if (exposureModes[V4L2_EXPOSURE_AUTO]) + autoExposureMode_ = V4L2_EXPOSURE_AUTO; + else if (exposureModes[V4L2_EXPOSURE_APERTURE_PRIORITY]) + autoExposureMode_ = V4L2_EXPOSURE_APERTURE_PRIORITY; + + if (exposureModes[V4L2_EXPOSURE_MANUAL]) + manualExposureMode_ = V4L2_EXPOSURE_MANUAL; + else if (exposureModes[V4L2_EXPOSURE_SHUTTER_PRIORITY]) + manualExposureMode_ = V4L2_EXPOSURE_SHUTTER_PRIORITY; + + std::array values; + std::size_t count = 0; + + if (autoExposureMode_) + values[count++] = controls::ExposureTimeModeAuto; + + if (manualExposureMode_) + values[count++] = controls::ExposureTimeModeManual; + + if (count == 0) + return; + + info = ControlInfo{ + Span{ values.data(), count }, + !lcDef ? values.front() : *lcDef, + }; break; } case V4L2_CID_EXPOSURE_ABSOLUTE: From patchwork Fri Mar 14 17:42:46 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: 22957 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 34FC8C32F7 for ; Fri, 14 Mar 2025 17:42:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ABAA26894D; Fri, 14 Mar 2025 18:42:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ANKwIXvX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F0416052C 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 A8119606 for ; Fri, 14 Mar 2025 18:41:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741974072; bh=ls5A5H9AzHH8EShw3Uj+YSMQ4y+43xqaf4XDERlIPZs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ANKwIXvXDU+rXSRDjVozxE/aC8MhaAGRIyE7Bxt5OeNkqLF676+qb1VIv2a2bRWJc NmyGiT33VyF3TxVPvQxlXF2lBb/tHUcNL9t/a3Y+YkrvpyiDSL97b3o1OW0Y/C+K+7 R+5ftCdjD0D/J2HiDOd7ueVZsA6nsksFoj4euMiI= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 2/4] libcamera: pipeline: uvcvideo: Fix `ExposureTimeMode` control setting Date: Fri, 14 Mar 2025 18:42:46 +0100 Message-ID: <20250314174248.1015718-3-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 mapping in `UVCCameraData::processControl()` is not entirely correct because the control value is retrieved as a `bool` instead of `int32_t`. Additionally, the available modes are not taken into account. Retrieve the control value with the right type, `int32_t`, check if the requested mode is available, and if so, set the appropriate v4l2 control value selected by `addControl()` earlier. Fixes: bad8d591f8acfa ("libcamera: uvcvideo: Register ExposureTimeMode control") Signed-off-by: Barnabás Pőcze --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 29 ++++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 5c9025d9b..4ff79c291 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -99,8 +99,8 @@ public: bool match(DeviceEnumerator *enumerator) override; private: - int processControl(ControlList *controls, unsigned int id, - const ControlValue &value); + int processControl(const UVCCameraData *data, ControlList *controls, + unsigned int id, const ControlValue &value); int processControls(UVCCameraData *data, Request *request); bool acquireDevice(Camera *camera) override; @@ -313,8 +313,8 @@ void PipelineHandlerUVC::stopDevice(Camera *camera) data->video_->releaseBuffers(); } -int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id, - const ControlValue &value) +int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *controls, + unsigned int id, const ControlValue &value) { uint32_t cid; @@ -358,10 +358,21 @@ 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; - controls->set(V4L2_CID_EXPOSURE_AUTO, ivalue); + 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)); break; } @@ -399,7 +410,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(data, &controls, id, value); for (const auto &ctrl : controls) LOG(UVC, Debug) From patchwork Fri Mar 14 17:42:47 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: 22958 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 512F7C32F9 for ; Fri, 14 Mar 2025 17:42:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AB01368951; Fri, 14 Mar 2025 18:42:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="V0sRLGmL"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4C6866893D 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 E5CD1842 for ; Fri, 14 Mar 2025 18:41:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741974073; bh=8eCneV/+CdU4vWjx2GhnPNxmZoqqI8kdB6VmcYyZu0w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=V0sRLGmL6XqmQlpqAyL+CiHo1jUiTXJcPP7g9FbR+ZozIPCXlKYtdeu+bZcgpw9dv zsDpDa+u9olYj8QbHJM2kzm8v394A4m5PVGfK66rxJMEAYuAFKJiuHbWSQOhjNFrO6 j+6agw+l2EgcZDYnx7/VSv/mK+Y7IlM9X1OP7P/g= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 3/4] libcamera: pipeline: uvcvideo: Retrieve current exposure mode on start Date: Fri, 14 Mar 2025 18:42:47 +0100 Message-ID: <20250314174248.1015718-4-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" If `ExposureTimeMode` is supported, then retrieve the current value of `V4L2_CID_EXPOSURE_AUTO` in `PipelineHandlerUVC::start()`, and convert it to the appropriate `ExposureTimeModeEnum` value. If it is not supported or the conversion fails, then fall back to assuming that `ExposureTimeModeManual` is in effect. This is necessary to be able to properly handle the `ExposureTime` control as its value is required to be ignored if `ExposureTimeMode` is not manual. Signed-off-by: Barnabás Pőcze --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 4ff79c291..7d882ebe1 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -62,6 +62,15 @@ public: std::optional autoExposureMode_; std::optional manualExposureMode_; + struct State { + std::optional exp; + + void reset() + { + exp.reset(); + } + } state_; + private: bool generateId(); @@ -303,6 +312,16 @@ int PipelineHandlerUVC::start(Camera *camera, [[maybe_unused]] const ControlList return ret; } + if (data->autoExposureMode_ || data->manualExposureMode_) { + const auto &ctrls = data->video_->getControls({ V4L2_CID_EXPOSURE_AUTO }); + const auto &value = ctrls.get(V4L2_CID_EXPOSURE_AUTO); + if (!value.isNone()) + data->state_.exp = v4l2ToExposureMode(value.get()); + } + + if (!data->state_.exp) + data->state_.exp = controls::ExposureTimeModeManual; + return 0; } @@ -311,6 +330,7 @@ void PipelineHandlerUVC::stopDevice(Camera *camera) UVCCameraData *data = cameraData(camera); data->video_->streamOff(); data->video_->releaseBuffers(); + data->state_.reset(); } int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *controls, 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)