Show a patch.

GET /api/1.1/patches/23340/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 23340,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/23340/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23340/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20250506155314.1544104-1-barnabas.pocze@ideasonboard.com>",
    "date": "2025-05-06T15:53:14",
    "name": "[v4] libcamera: pipeline: uvcvideo: Fix `ExposureTime` control handling",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "48cc8b62085c3ae87afa1c5c6990b157305adc37",
    "submitter": {
        "id": 216,
        "url": "https://patchwork.libcamera.org/api/1.1/people/216/?format=api",
        "name": "Barnabás Pőcze",
        "email": "barnabas.pocze@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23340/mbox/",
    "series": [
        {
            "id": 5163,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5163/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5163",
            "date": "2025-05-06T15:53:14",
            "name": "[v4] libcamera: pipeline: uvcvideo: Fix `ExposureTime` control handling",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/5163/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23340/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23340/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B5EB5C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  6 May 2025 15:53:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E3CB568B2C;\n\tTue,  6 May 2025 17:53:19 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E61E968AD5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  6 May 2025 17:53:18 +0200 (CEST)",
            "from pb-laptop.local (185.221.141.56.nat.pool.zt.hu\n\t[185.221.141.56])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0A29956D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  6 May 2025 17:53:08 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ViaUr73o\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746546788;\n\tbh=yIF04YwxBY1jJ7AoqdakHk7Rj858MNZUQ89xMTN4Wfo=;\n\th=From:To:Subject:Date:From;\n\tb=ViaUr73org1VBmF4smxbKLPa33qFYMobegC3UtS9+/jpLO79CrrQRlQ7gnx9396SI\n\tozwRoRH7IHlRofFVhzfeeJ9kk8w7SfiujQL8FeGVKwf7wJor4W/H5/6ihoVthJwNhp\n\t42qFdgu2kSF12T+9VGujrQjI1aq8C4Lno6j97xM4=",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v4] libcamera: pipeline: uvcvideo: Fix `ExposureTime` control\n\thandling",
        "Date": "Tue,  6 May 2025 17:53:14 +0200",
        "Message-ID": "<20250506155314.1544104-1-barnabas.pocze@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.49.0",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The documentation of `ExposureTime` states that its value is ignored if\n`ExposureTimeMode` is not manual. This is currently not handled, and if\n`ExposureTimeMode` is automatic and `ExposureTime` is set, then the\ncontrols will be rejected, as expected.\n\nTo fix that, keep track of the current value of `ExposureTimeMode`, and\nonly set `V4L2_CID_EXPOSURE_ABSOLUTE` if the current exposure mode is\nmanual.\n\nHowever, the current state of `V4L2_CID_EXPOSURE_AUTO` is not retrieved\nwhen streaming starts, thus if the user does not set `ExposureTimeMode`\nthen it will remain in an \"unset\" state and all attempts to set\n`ExposureTime` will be ignored. This is done for two reasons:\n\n  * the current values of controls cannot be retrieved with libcamera,\n    therefore this unset state cannot be observed by the user;\n  * the user will have to set `ExposureTimeMode` either way if they\n    want to guarantee that setting `ExposureTime` will have any effect.\n\nIf `ExposureTimeMode` is not exposed by the camera, but `ExposeTime` is\nsupported, then the exposure mode is assumed to be manual to allow\nchanging `V4L2_CID_EXPOSURE_ABSOLUTE`.\n\nTo be able to handle requests that set both `ExposureTime{,Mode}`, process\n`ExposureTimeMode` first directly in `processControls()`, and store this\nnew mode in a temporary location. Then have `processControl()` act on this\ntemporary state, and only persist the temporary state if `setControls()`\non the video device succeeds.\n\nBug: https://bugs.libcamera.org/show_bug.cgi?id=242\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\nchanges in v4:\n  * first two patches of v3 already merged\n  * last two patches of v3 combined into this single patch\n  * do not retrieve V4L2_CID_EXPOSURE_AUTO when streaming starts\n\nchanges in v3:\n  * fix default value: set it based on the v4l2 default\n  * store current value of `ExposureTimeMode`\n  * fix https://bugs.libcamera.org/show_bug.cgi?id=242 as well\n\nchanges in v2:\n  * split into two patches\n  * make it compile with old libstdc++ when _GLIBCXX_DEBUG is set\n\nv3: https://patchwork.libcamera.org/patch/22959/\n    https://patchwork.libcamera.org/patch/22958/\nv2: https://patchwork.libcamera.org/project/libcamera/list/?series=5006\nv1: https://patchwork.libcamera.org/project/libcamera/list/?series=4974\n---\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 67 ++++++++++++++------\n 1 file changed, 46 insertions(+), 21 deletions(-)\n\n--\n2.49.0",
    "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 586e932d2..af0c8dedd 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -53,6 +53,8 @@ public:\n\n \tconst std::string &id() const { return id_; }\n\n+\tbool supportsExposureTimeMode() const { return autoExposureMode_ || manualExposureMode_; }\n+\n \tMutex openLock_;\n \tstd::unique_ptr<V4L2VideoDevice> video_;\n \tStream stream_;\n@@ -61,6 +63,15 @@ public:\n \tstd::optional<v4l2_exposure_auto_type> autoExposureMode_;\n \tstd::optional<v4l2_exposure_auto_type> manualExposureMode_;\n\n+\tstruct State {\n+\t\tstd::optional<controls::ExposureTimeModeEnum> exp;\n+\n+\t\tvoid reset()\n+\t\t{\n+\t\t\texp.reset();\n+\t\t}\n+\t} state_ = {};\n+\n private:\n \tbool generateId();\n\n@@ -98,7 +109,7 @@ public:\n \tbool match(DeviceEnumerator *enumerator) override;\n\n private:\n-\tint processControl(const UVCCameraData *data, ControlList *controls,\n+\tint processControl(const UVCCameraData::State &state, ControlList *controls,\n \t\t\t   unsigned int id, const ControlValue &value);\n \tint processControls(UVCCameraData *data, Request *request);\n\n@@ -302,6 +313,9 @@ int PipelineHandlerUVC::start(Camera *camera, [[maybe_unused]] const ControlList\n \t\treturn ret;\n \t}\n\n+\tif (!data->supportsExposureTimeMode())\n+\t\tdata->state_.exp = controls::ExposureTimeModeManual;\n+\n \treturn 0;\n }\n\n@@ -310,9 +324,10 @@ void PipelineHandlerUVC::stopDevice(Camera *camera)\n \tUVCCameraData *data = cameraData(camera);\n \tdata->video_->streamOff();\n \tdata->video_->releaseBuffers();\n+\tdata->state_.reset();\n }\n\n-int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *controls,\n+int PipelineHandlerUVC::processControl(const UVCCameraData::State &state, ControlList *controls,\n \t\t\t\t       unsigned int id, const ControlValue &value)\n {\n \tuint32_t cid;\n@@ -359,26 +374,13 @@ int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *c\n \t}\n\n \tcase V4L2_CID_EXPOSURE_AUTO: {\n-\t\tstd::optional<v4l2_exposure_auto_type> mode;\n-\n-\t\tswitch (value.get<int32_t>()) {\n-\t\tcase controls::ExposureTimeModeAuto:\n-\t\t\tmode = data->autoExposureMode_;\n-\t\t\tbreak;\n-\t\tcase controls::ExposureTimeModeManual:\n-\t\t\tmode = data->manualExposureMode_;\n-\t\t\tbreak;\n-\t\t}\n-\n-\t\tif (!mode)\n-\t\t\treturn -EINVAL;\n-\n-\t\tcontrols->set(V4L2_CID_EXPOSURE_AUTO, static_cast<int32_t>(*mode));\n+\t\t/* Handled directly in `processControls()`. */\n \t\tbreak;\n \t}\n\n \tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n-\t\tcontrols->set(cid, value.get<int32_t>() / 100);\n+\t\tif (state.exp == controls::ExposureTimeModeManual)\n+\t\t\tcontrols->set(cid, value.get<int32_t>() / 100);\n \t\tbreak;\n\n \tcase V4L2_CID_CONTRAST:\n@@ -413,9 +415,30 @@ int PipelineHandlerUVC::processControl(const UVCCameraData *data, ControlList *c\n int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n {\n \tControlList controls(data->video_->controls());\n+\tconst auto &reqControls = request->controls();\n+\tauto newState = data->state_;\n\n-\tfor (const auto &[id, value] : request->controls())\n-\t\tprocessControl(data, &controls, id, value);\n+\tif (const auto exp = reqControls.get(controls::ExposureTimeMode)) {\n+\t\tstd::optional<v4l2_exposure_auto_type> mode;\n+\n+\t\tswitch (*exp) {\n+\t\tcase controls::ExposureTimeModeAuto:\n+\t\t\tmode = data->autoExposureMode_;\n+\t\t\tbreak;\n+\t\tcase controls::ExposureTimeModeManual:\n+\t\t\tmode = data->manualExposureMode_;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (!mode)\n+\t\t\treturn -EINVAL;\n+\n+\t\tcontrols.set(V4L2_CID_EXPOSURE_AUTO, static_cast<int32_t>(*mode));\n+\t\tnewState.exp = static_cast<controls::ExposureTimeModeEnum>(*exp);\n+\t}\n+\n+\tfor (const auto &[id, value] : reqControls)\n+\t\tprocessControl(newState, &controls, id, value);\n\n \tfor (const auto &ctrl : controls)\n \t\tLOG(UVC, Debug)\n@@ -428,7 +451,9 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n \t\treturn ret < 0 ? ret : -EINVAL;\n \t}\n\n-\treturn ret;\n+\tdata->state_ = newState;\n+\n+\treturn 0;\n }\n\n int PipelineHandlerUVC::queueRequestDevice(Camera *camera, Request *request)\n",
    "prefixes": [
        "v4"
    ]
}