[{"id":20785,"web_url":"https://patchwork.libcamera.org/comment/20785/","msgid":"<163653835521.1896795.4224447351191805328@Monstersaurus>","date":"2021-11-10T09:59:15","subject":"Re: [libcamera-devel] [PATCH v6 3/4] libcamera: camera_sensor:\n\tEnable to set a test pattern mode","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Hirokazu Honda (2021-11-10 07:22:06)\n> This adds a function to set a camera sensor driver a test pattern\n> mode.\n> \n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  include/libcamera/internal/camera_sensor.h |  8 +++\n>  src/libcamera/camera_sensor.cpp            | 64 +++++++++++++++++++---\n>  src/libcamera/control_ids.yaml             |  5 ++\n>  3 files changed, 70 insertions(+), 7 deletions(-)\n> \n> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\n> index edef2220..60ce0c45 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> @@ -78,10 +81,14 @@ private:\n>                         &testPatternModeMap);\n>         int initProperties();\n>  \n> +       int setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode);\n> +\n>         const MediaEntity *entity_;\n>         std::unique_ptr<V4L2Subdevice> subdev_;\n>         unsigned int pad_;\n>  \n> +       const CameraSensorProperties *staticProps_;\n> +\n>         std::string model_;\n>         std::string id_;\n>  \n> @@ -89,6 +96,7 @@ private:\n>         std::vector<unsigned int> mbusCodes_;\n>         std::vector<Size> sizes_;\n>         std::vector<controls::draft::TestPatternModeEnum> testPatternModes_;\n> +       controls::draft::TestPatternModeEnum testPatternMode_;\n>  \n>         Size pixelArraySize_;\n>         Rectangle activeArea_;\n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index f0aa9f24..cfb9bc17 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> -       : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr),\n> -         properties_(properties::properties)\n> +       : entity_(entity), pad_(UINT_MAX), staticProps_(nullptr),\n> +         testPatternMode_(controls::draft::TestPatternModeUnset),\n> +         bayerFormat_(nullptr), properties_(properties::properties)\n>  {\n>  }\n>  \n> @@ -161,6 +163,10 @@ int CameraSensor::init()\n>         if (ret)\n>                 return ret;\n>  \n> +       ret = setTestPatternMode(controls::draft::TestPatternModeOff);\n> +       if (ret)\n> +               return ret;\n> +\n>         return 0;\n>  }\n>  \n> @@ -300,14 +306,14 @@ void CameraSensor::initVimcDefaultProperties()\n>  \n>  void CameraSensor::initStaticProperties()\n>  {\n> -       const CameraSensorProperties *props = CameraSensorProperties::get(model_);\n> -       if (!props)\n> +       staticProps_ = CameraSensorProperties::get(model_);\n> +       if (!staticProps_)\n>                 return;\n>  \n>         /* Register the properties retrieved from the sensor database. */\n> -       properties_.set(properties::UnitCellSize, props->unitCellSize);\n> +       properties_.set(properties::UnitCellSize, staticProps_->unitCellSize);\n>  \n> -       initTestPatternModes(props->testPatternModes);\n> +       initTestPatternModes(staticProps_->testPatternModes);\n>  }\n>  \n>  void CameraSensor::initTestPatternModes(\n> @@ -315,7 +321,15 @@ void CameraSensor::initTestPatternModes(\n>  {\n>         const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);\n>         if (v4l2TestPattern == controls().end()) {\n> -               LOG(CameraSensor, Debug) << \"No static test pattern map for \\'\"\n> +               LOG(CameraSensor, Debug)\n> +                       << \"V4L2_CID_TEST_PATTERN is not supported\";\n> +               return;\n> +       }\n> +\n> +       if (testPatternModes.empty()) {\n> +               // The camera sensor supports test patterns but we don't know\n> +               // how to map them so this should be fixed.\n> +               LOG(CameraSensor, Error) << \"No static test pattern map for \\'\"\n>                                          << model() << \"\\'\";\n>                 return;\n>         }\n> @@ -531,6 +545,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> +       if (testPatternMode_ == testPatternMode)\n> +               return 0;\n> +\n> +       if (!staticProps_ || testPatternModes_.empty())\n> +               return 0;\n> +\n> +       auto it = std::find(testPatternModes_.begin(), testPatternModes_.end(),\n> +                           testPatternMode);\n> +       if (it == testPatternModes_.end()) {\n> +               LOG(CameraSensor, Error) << \"Unsupported test pattern mode \"\n> +                                        << testPatternMode;\n> +               return -EINVAL;\n> +       }\n> +\n> +       int32_t index = staticProps_->testPatternModes.at(testPatternMode);\n> +       ControlList ctrls{ controls() };\n> +       ctrls.set(V4L2_CID_TEST_PATTERN, index);\n> +\n> +       int ret = setControls(&ctrls);\n> +       if (ret)\n> +               return ret;\n> +\n> +       testPatternMode_ = testPatternMode;\n> +\n> +       return 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> diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml\n> index 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> -- \n> 2.34.0.rc0.344.g81b53c2807-goog\n>","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 39A66BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Nov 2021 09:59:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5A10E6035A;\n\tWed, 10 Nov 2021 10:59:18 +0100 (CET)","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 8A00760128\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Nov 2021 10:59:17 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 119ECD8B;\n\tWed, 10 Nov 2021 10:59:17 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VX+69ZjO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1636538357;\n\tbh=DhYeoo1ZzSvPcSjmCd04zklzgKnEDHm7QrTFI/mFDIg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=VX+69ZjOga2FlvJvtb4wQgmpxutGxi4/RSDcBCKHAjvPg9n6DAUtkGG6Q1nfdLmaw\n\tFO+YW+3Z+TPua4+TbimTOOE37sW8FByOVwruaZljNXoGo6v8HmAX9KAnt5xcA0Bv6M\n\t6THbn1DGgm/qqZPRaBnxvapWPSQ4sk5iND2w/2GU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211110072207.3273703-3-hiroh@chromium.org>","References":"<20211110072207.3273703-1-hiroh@chromium.org>\n\t<20211110072207.3273703-3-hiroh@chromium.org>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>, libcamera-devel@lists.libcamera.org","Date":"Wed, 10 Nov 2021 09:59:15 +0000","Message-ID":"<163653835521.1896795.4224447351191805328@Monstersaurus>","User-Agent":"alot/0.9.1","Subject":"Re: [libcamera-devel] [PATCH v6 3/4] libcamera: camera_sensor:\n\tEnable to 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>"}}]