{"id":14793,"url":"https://patchwork.libcamera.org/api/1.1/patches/14793/?format=json","web_url":"https://patchwork.libcamera.org/patch/14793/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20211126050810.1871781-3-hiroh@chromium.org>","date":"2021-11-26T05:08:09","name":"[libcamera-devel,v8,2/3] libcamera: camera_sensor: Enable to set a test pattern mode","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3b2555dcc73c99fa51d1b54eca1c68f2f1fbed20","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14793/mbox/","series":[{"id":2759,"url":"https://patchwork.libcamera.org/api/1.1/series/2759/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2759","date":"2021-11-26T05:08:07","name":"Enable to apply test pattern mode in IPU3","version":8,"mbox":"https://patchwork.libcamera.org/series/2759/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14793/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14793/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 981C7BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 26 Nov 2021 05:08:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4B493604F9;\n\tFri, 26 Nov 2021 06:08:24 +0100 (CET)","from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com\n\t[IPv6:2607:f8b0:4864:20::62d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8315C6011D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Nov 2021 06:08:21 +0100 (CET)","by mail-pl1-x62d.google.com with SMTP id m24so5905862pls.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Nov 2021 21:08:21 -0800 (PST)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:139c:952e:8861:d909])\n\tby smtp.gmail.com with ESMTPSA id\n\tk6sm9280248pjt.14.2021.11.25.21.08.18\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 25 Nov 2021 21:08:19 -0800 (PST)"],"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=\"RvavMBfF\"; 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=BMR9GeCOSQN+ULweUyQmyaMYtRuhwZuDi/MCbB2HO6E=;\n\tb=RvavMBfFNrtiUY0AF7q1Plssa7a1DfYW5uZLrQm09jB52y9qupy/AH80WdVuOFfq5r\n\toNUXTv/2nGzmi32ow3/pl0RY7JwOkZuPjtMqhvOfyFaDNkp/w1WLpVC0HgXJ2Fw1dfP2\n\t5ytz5U1zHRjyB5mUyPPqufORKusR92j94h9TM=","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=BMR9GeCOSQN+ULweUyQmyaMYtRuhwZuDi/MCbB2HO6E=;\n\tb=qYDOpJE00E+L7Z21GgmAMl2gTwaLE4sDRjJwGvQXPqK7GZBVjfuL+9sH0tNF2wunDl\n\tIupH8hpM+6U9U1TNo7XyoRQCGFFSuI9oJY1K9l+vQFtMz4l4onSYJ0JiEXs0nlPokSCl\n\tcET+smc9pPCj98/KovdfBYBwVfyOFb6/9deTL+u5MknPht1uUPgfqONhTdTJ3Nuu7GqK\n\tfn8RLrUmQzEVTL3Sbxxe6yTyj32kP+q1b4GROJJQcSc2COkd7mrBV0wXeMNnhPafQXUV\n\tGcRqeWJMkl1GbJiRXo5BdeV0/2jo5JYcHa7DfCqyn5DsQggZK6bQAG6jLinKFZOK8wl9\n\tC7nQ==","X-Gm-Message-State":"AOAM533HkL11IlMgn0+AxRdDRsGtefMVpal2i6f4nOnLFhIhG1Jav/5f\n\t77eZmhO6sik2Jt28g5P32FdXxril2agt2w==","X-Google-Smtp-Source":"ABdhPJwNtyRH5v7heJedoJUBODONnd8MxJJJcCqEz78fja42RWehMrgO6W2qBYKMUIjqlAd0ffsEzg==","X-Received":"by 2002:a17:90a:be10:: with SMTP id\n\ta16mr12891471pjs.133.1637903299784; \n\tThu, 25 Nov 2021 21:08:19 -0800 (PST)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 26 Nov 2021 14:08:09 +0900","Message-Id":"<20211126050810.1871781-3-hiroh@chromium.org>","X-Mailer":"git-send-email 2.34.0.rc2.393.gf8c9666880-goog","In-Reply-To":"<20211126050810.1871781-1-hiroh@chromium.org>","References":"<20211126050810.1871781-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v8 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. CameraSensor initializes the test pattern mode by Off.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/camera_sensor.h |  6 ++\n src/libcamera/camera_sensor.cpp            | 75 ++++++++++++++++++++--\n 2 files changed, 74 insertions(+), 7 deletions(-)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex edef2220..a110fd08 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -28,6 +28,8 @@ namespace libcamera {\n class BayerFormat;\n class MediaEntity;\n \n+struct CameraSensorProperties;\n+\n class CameraSensor : protected Loggable\n {\n public:\n@@ -47,6 +49,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@@ -82,6 +85,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 +94,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..2c6312d4 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -54,8 +54,8 @@ 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  bayerFormat_(nullptr), properties_(properties::properties)\n {\n }\n \n@@ -161,6 +161,21 @@ int CameraSensor::init()\n \tif (ret)\n \t\treturn ret;\n \n+\tauto initTestPatternMode = controls::draft::TestPatternModeEnum::TestPatternModeOff;\n+\tif (staticProps_) {\n+\t\tauto it = staticProps_->testPatternModes.find(initTestPatternMode);\n+\t\tif (it != staticProps_->testPatternModes.end()) {\n+\t\t\tControlList ctrls{ controls() };\n+\t\t\tctrls.set(V4L2_CID_TEST_PATTERN, it->second);\n+\n+\t\t\tret = setControls(&ctrls);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\n+\t\t\ttestPatternMode_ = initTestPatternMode;\n+\t\t}\n+\t}\n+\n \treturn 0;\n }\n \n@@ -300,14 +315,14 @@ 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@@ -315,7 +330,17 @@ void CameraSensor::initTestPatternModes(\n {\n \tconst auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);\n \tif (v4l2TestPattern == controls().end()) {\n-\t\tLOG(CameraSensor, Debug) << \"No static test pattern map for \\'\"\n+\t\tLOG(CameraSensor, Debug)\n+\t\t\t<< \"V4L2_CID_TEST_PATTERN is not supported\";\n+\t\treturn;\n+\t}\n+\n+\tif (testPatternModes.empty()) {\n+\t\t/*\n+\t\t * The camera sensor supports test patterns but we don't know\n+\t\t * how to map them so this should be fixed.\n+\t\t */\n+\t\tLOG(CameraSensor, Error) << \"No static test pattern map for \\'\"\n \t\t\t\t\t << model() << \"\\'\";\n \t\treturn;\n \t}\n@@ -531,6 +556,42 @@ 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(controls::draft::TestPatternModeEnum testPatternMode)\n+{\n+\tif (testPatternMode_ == testPatternMode)\n+\t\treturn 0;\n+\n+\tif (!staticProps_ || testPatternModes_.empty())\n+\t\treturn 0;\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","prefixes":["libcamera-devel","v8","2/3"]}