{"id":14453,"url":"https://patchwork.libcamera.org/api/patches/14453/?format=json","web_url":"https://patchwork.libcamera.org/patch/14453/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211104064252.2091330-3-hiroh@chromium.org>","date":"2021-11-04T06:42:51","name":"[libcamera-devel,v4,2/3] libcamera: camera_sensor: Enable to set a test pattern mode","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"9faaf486ff724f5f33c02f9873f18163d1737f60","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14453/mbox/","series":[{"id":2688,"url":"https://patchwork.libcamera.org/api/series/2688/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2688","date":"2021-11-04T06:42:49","name":"Apply a sensor test pattern mode","version":4,"mbox":"https://patchwork.libcamera.org/series/2688/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14453/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14453/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 33674BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Nov 2021 06:43:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E1F5160341;\n\tThu,  4 Nov 2021 07:43:05 +0100 (CET)","from mail-pl1-x633.google.com (mail-pl1-x633.google.com\n\t[IPv6:2607:f8b0:4864:20::633])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 680EC60341\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Nov 2021 07:43:03 +0100 (CET)","by mail-pl1-x633.google.com with SMTP id t21so5646157plr.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 03 Nov 2021 23:43:03 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:9022:fd2e:f66e:b99b])\n\tby smtp.gmail.com with ESMTPSA id\n\ts6sm4265580pfu.137.2021.11.03.23.42.59\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 03 Nov 2021 23:43:01 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"iZk8681O\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=75SYs/bSY+JgMTa/Gyr2joLcLqjYgX6ECTOMav8wiac=;\n\tb=iZk8681OQ523P0pCgsRuPblH1v6zPwQyLXoTqdCSMqCjADZCUFPudqkCVQJwvoUvDw\n\tW7oc/lhKXMeCFzHgpubI7IsUSc9BF4rok7Bp7RZIlFPtCF1tVZfSI6M355t/EJNn+A+1\n\teqTZM7fUZ2GBP/gOyIjW6Qk2xi0m/7Z7iImdY=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=75SYs/bSY+JgMTa/Gyr2joLcLqjYgX6ECTOMav8wiac=;\n\tb=SHwcGE0ocVZUGSiqnLFNUGxzi/DSaxlGTSKgQ8WJD2QJ3YJsK5zPHPFiHIuc7QKFCh\n\t066fu4g09yijvEbyip+6B69DO+bl/uuzB7YZrDIJf2SvexITd1zg+fVrn+0Q9yBPxJ8T\n\tor4nlCuogg6lNIeXe7bQEKXBeMSxa1GfgpKnMalimd3iz0+zVjECGF03ajFU2481W5PK\n\tKCyDnosszGCJTzrCnOO4VC82jV6XZDWQ0vGGbmklplbj/69FB2xaYeY9hyZBgrW+f4GO\n\tC2zqVT1coOZ133n7BJtpBQlcL6ZEVj1/5DssgWsn+Izk2ubOSAOAfujBD0QMPcvSYwy2\n\tUXmQ==","X-Gm-Message-State":"AOAM5316A+oKLcZ2CUZAXohSHMV6BEydsJ4JOv+xvYJjreBqJTv1ZAX+\n\trsoQPQfZk61ojk50HC6RZVN9RUiR98pCwA==","X-Google-Smtp-Source":"ABdhPJxQaXyUKJlTLKMO8jkCjd9w5T75hXDwkbs8gCPke15Q2qmJ4BTr4/qPn/xQBk88p5j8/eNc0A==","X-Received":"by 2002:a17:90a:5b0c:: with SMTP id\n\to12mr20389936pji.194.1636008181586; \n\tWed, 03 Nov 2021 23:43:01 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  4 Nov 2021 15:42:51 +0900","Message-Id":"<20211104064252.2091330-3-hiroh@chromium.org>","X-Mailer":"git-send-email 2.33.1.1089.g2158813163f-goog","In-Reply-To":"<20211104064252.2091330-1-hiroh@chromium.org>","References":"<20211104064252.2091330-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 2/3] libcamera: camera_sensor: Enable\n\tto set a test pattern mode","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":"This adds a function to set a camera sensor driver a test pattern\nmode.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/camera_sensor.h |  8 ++\n src/libcamera/camera_sensor.cpp            | 95 ++++++++++++++++++++--\n src/libcamera/control_ids.yaml             |  5 ++\n 3 files changed, 100 insertions(+), 8 deletions(-)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex edef2220..40db792a 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -27,6 +27,9 @@ namespace libcamera {\n \n class BayerFormat;\n class MediaEntity;\n+class Request;\n+\n+struct CameraSensorProperties;\n \n class CameraSensor : protected Loggable\n {\n@@ -47,6 +50,7 @@ public:\n \t{\n \t\treturn testPatternModes_;\n \t}\n+\tint setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode);\n \n \tV4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,\n \t\t\t\t      const Size &size) const;\n@@ -55,6 +59,7 @@ public:\n \tconst ControlInfoMap &controls() const;\n \tControlList getControls(const std::vector<uint32_t> &ids);\n \tint setControls(ControlList *ctrls);\n+\tint applyRequestControls(Request *request);\n \n \tV4L2Subdevice *device() { return subdev_.get(); }\n \n@@ -82,6 +87,8 @@ private:\n \tstd::unique_ptr<V4L2Subdevice> subdev_;\n \tunsigned int pad_;\n \n+\tconst CameraSensorProperties *staticProps_;\n+\n \tstd::string model_;\n \tstd::string id_;\n \n@@ -89,6 +96,7 @@ private:\n \tstd::vector<unsigned int> mbusCodes_;\n \tstd::vector<Size> sizes_;\n \tstd::vector<controls::draft::TestPatternModeEnum> testPatternModes_;\n+\tcontrols::draft::TestPatternModeEnum testPatternMode_;\n \n \tSize pixelArraySize_;\n \tRectangle activeArea_;\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex f0aa9f24..bb429b3e 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -17,6 +17,7 @@\n #include <string.h>\n \n #include <libcamera/property_ids.h>\n+#include <libcamera/request.h>\n \n #include <libcamera/base/utils.h>\n \n@@ -54,8 +55,9 @@ LOG_DEFINE_CATEGORY(CameraSensor)\n  * Once constructed the instance must be initialized with init().\n  */\n CameraSensor::CameraSensor(const MediaEntity *entity)\n-\t: entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr),\n-\t  properties_(properties::properties)\n+\t: entity_(entity), pad_(UINT_MAX), staticProps_(nullptr),\n+\t  testPatternMode_(controls::draft::TestPatternModeUnset),\n+\t  bayerFormat_(nullptr), properties_(properties::properties)\n {\n }\n \n@@ -300,25 +302,30 @@ void CameraSensor::initVimcDefaultProperties()\n \n void CameraSensor::initStaticProperties()\n {\n-\tconst CameraSensorProperties *props = CameraSensorProperties::get(model_);\n-\tif (!props)\n+\tstaticProps_ = CameraSensorProperties::get(model_);\n+\tif (!staticProps_)\n \t\treturn;\n \n \t/* Register the properties retrieved from the sensor database. */\n-\tproperties_.set(properties::UnitCellSize, props->unitCellSize);\n+\tproperties_.set(properties::UnitCellSize, staticProps_->unitCellSize);\n \n-\tinitTestPatternModes(props->testPatternModes);\n+\tinitTestPatternModes(staticProps_->testPatternModes);\n }\n \n void CameraSensor::initTestPatternModes(\n \tconst std::map<controls::draft::TestPatternModeEnum, int32_t> &testPatternModes)\n {\n-\tconst auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);\n-\tif (v4l2TestPattern == controls().end()) {\n+\tif (testPatternModes.empty()) {\n \t\tLOG(CameraSensor, Debug) << \"No static test pattern map for \\'\"\n \t\t\t\t\t << model() << \"\\'\";\n \t\treturn;\n \t}\n+\tconst auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);\n+\tif (v4l2TestPattern == controls().end()) {\n+\t\tLOG(CameraSensor, Debug)\n+\t\t\t<< \"V4L2_CID_TEST_PATTERN is not supported\";\n+\t\treturn;\n+\t}\n \n \t/*\n \t * Create a map that associates the V4L2 control index to the test\n@@ -531,6 +538,44 @@ Size CameraSensor::resolution() const\n  * \\return The list of test pattern modes\n  */\n \n+/**\n+ * \\brief Set the test pattern mode for the camera sensor\n+ * \\param[in] testPatternMode Test pattern mode control value to set the camera\n+ * sensor\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int CameraSensor::setTestPatternMode(\n+\tcontrols::draft::TestPatternModeEnum testPatternMode)\n+{\n+\tif (testPatternMode_ == testPatternMode)\n+\t\treturn 0;\n+\n+\tif (!staticProps_) {\n+\t\treturn 0;\n+\t}\n+\n+\tauto it = std::find(testPatternModes_.begin(), testPatternModes_.end(),\n+\t\t\t    testPatternMode);\n+\tif (it != testPatternModes_.end()) {\n+\t\tLOG(CameraSensor, Error) << \"Unsupported test pattern mode \"\n+\t\t\t\t\t << testPatternMode;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tint32_t index = staticProps_->testPatternModes.at(testPatternMode);\n+\tControlList ctrls{ controls() };\n+\tctrls.set(V4L2_CID_TEST_PATTERN, index);\n+\n+\tint ret = setControls(&ctrls);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\ttestPatternMode_ = testPatternMode;\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Retrieve the best sensor format for a desired output\n  * \\param[in] mbusCodes The list of acceptable media bus codes\n@@ -705,6 +750,40 @@ int CameraSensor::setControls(ControlList *ctrls)\n \treturn subdev_->setControls(ctrls);\n }\n \n+/**\n+ * \\brief Apply controls associated with Request\n+ * \\param[in] request Request that may contain contorls to be applied\n+ *\n+ * Some controls have to be applied for a capture associated with Request.\n+ * This picks up such controls and set the driver them.\n+ *\n+ * \\return 0 on success or an error code otherwise\n+ */\n+int32_t CameraSensor::applyRequestControls(Request *request)\n+{\n+\t/* Assumes applying the test pattern mode affects immediately. */\n+\tif (request->controls().contains(controls::draft::TestPatternMode)) {\n+\t\tconst int32_t testPatternMode = request->controls().get(\n+\t\t\tcontrols::draft::TestPatternMode);\n+\n+\t\tLOG(CameraSensor, Debug) << \"Apply test pattern mode: \"\n+\t\t\t\t\t << testPatternMode;\n+\n+\t\tint ret = setTestPatternMode(\n+\t\t\tstatic_cast<controls::draft::TestPatternModeEnum>(testPatternMode));\n+\t\tif (ret) {\n+\t\t\tLOG(CameraSensor, Error)\n+\t\t\t\t<< \"Failed to set test pattern mode: \" << ret;\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\trequest->metadata().set(controls::draft::TestPatternMode,\n+\t\t\t\t\ttestPatternMode);\n+\t}\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\fn CameraSensor::device()\n  * \\brief Retrieve the camera sensor device\ndiff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml\nindex 9d4638ae..083bac7b 100644\n--- a/src/libcamera/control_ids.yaml\n+++ b/src/libcamera/control_ids.yaml\n@@ -639,6 +639,11 @@ controls:\n         Control to select the test pattern mode. Currently identical to\n         ANDROID_SENSOR_TEST_PATTERN_MODE.\n       enum:\n+        - name: TestPatternModeUnset\n+          value: -1\n+          description: |\n+            No test pattern is set. Returned frames by the camera device are\n+            undefined.\n         - name: TestPatternModeOff\n           value: 0\n           description: |\n","prefixes":["libcamera-devel","v4","2/3"]}