From patchwork Mon Dec 6 05:49:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15038 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 ABBE5BDB13 for ; Mon, 6 Dec 2021 05:49:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D268F6086A; Mon, 6 Dec 2021 06:49:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="btDz0jRW"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9A6D360224 for ; Mon, 6 Dec 2021 06:49:26 +0100 (CET) Received: by mail-pl1-x62a.google.com with SMTP id u11so6368618plf.3 for ; Sun, 05 Dec 2021 21:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HWVakCseTmApR8POV7cSLk9Fe28Jm4ZGfdfI2CCeE+4=; b=btDz0jRWlF7ZMyDMwdThIZxFMRUc78llkuqeXhNRwqlGpWtTeD8cafg38xJoxWMZGu tuWHzdBh4A8uuw6stm3YVmpOKRG+Q9hE/fjJtbvYckkE7R9QED+/gfbN3iMiXFLhGVrF YWKIwFv9On4JWb3cFLcwIkX1zgMEGikyg4Cdw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HWVakCseTmApR8POV7cSLk9Fe28Jm4ZGfdfI2CCeE+4=; b=LBRqP216jjHMp+f2eyvyikqHkso/O1Ni1cTVRgPEyuLcG0oy1abO5WnpIIUotw9mZP dvtE1PQwcZB72Yul2Lha9Q6qYl7Q6CtoBIxoQqADxICcoOl7Eq7VydWsYXfQ9wO6sZ3I Y0tPcnnQ4Xh8wdAnWmkXm5fn8+D85u1tBrCWZkkwyT+iO0bWfNQHrYx+b7dACW8GZPtD nso4pGxqZ/eEf/hIfAOmogRQg6WtRmJC+Y8igFTR2m7vtnniECpLtwSwPxJ9rQZMYaky ivRh1s/mT2UkeIlK3woDUJw1Oh9S2ihP6iUg6LktQF5HTAwq7j8AXr8M49/jxJJuZc4o +0WQ== X-Gm-Message-State: AOAM533Wtz2cuXu4qQHdN/jQjSnvxC2a+cQE+r5v7AoAsWs7PbvEnAft voiVux8FmNq+QJ95jTY/VtZecge0wZtJYg== X-Google-Smtp-Source: ABdhPJxLtdmgC9CysKpnhc6rehMeXROjTxVYbNAyly9IpzfrX82DN0qr2bVku1bJLz+vKC2L+rl2Mg== X-Received: by 2002:a17:902:d34d:b0:143:c927:dc48 with SMTP id l13-20020a170902d34d00b00143c927dc48mr41672917plk.71.1638769764323; Sun, 05 Dec 2021 21:49:24 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:749e:cfe6:fd85:77b7]) by smtp.gmail.com with ESMTPSA id a1sm11492368pfv.99.2021.12.05.21.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:49:23 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 6 Dec 2021 14:49:16 +0900 Message-Id: <20211206054918.2467049-1-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 1/3] libcamera: camera_sensor: Reference test pattern modes by enum type 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 CameraSensor stores TestPatternModes as an int32_t. This prevents the compiler from verifying the usage against the defined enum types. Fix references to the TestPatternMode to store the value as the TestPatternModeEnum type which is defined by the control generator. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 10 +++++++--- include/libcamera/internal/camera_sensor_properties.h | 3 ++- src/libcamera/camera_sensor.cpp | 4 ++-- src/libcamera/pipeline/ipu3/ipu3.cpp | 7 ++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 2facbf3c..310571ca 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -14,8 +14,10 @@ #include #include +#include #include #include + #include #include "libcamera/internal/formats.h" @@ -40,7 +42,8 @@ public: const std::vector &mbusCodes() const { return mbusCodes_; } const std::vector sizes(unsigned int mbusCode) const; Size resolution() const; - const std::vector &testPatternModes() const + const std::vector + &testPatternModes() const { return testPatternModes_; } @@ -71,7 +74,8 @@ private: void initVimcDefaultProperties(); void initStaticProperties(); void initTestPatternModes( - const std::map &testPatternModeMap); + const std::map + &testPatternModeMap); int initProperties(); const MediaEntity *entity_; @@ -84,7 +88,7 @@ private: V4L2Subdevice::Formats formats_; std::vector mbusCodes_; std::vector sizes_; - std::vector testPatternModes_; + std::vector testPatternModes_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/include/libcamera/internal/camera_sensor_properties.h b/include/libcamera/internal/camera_sensor_properties.h index af381a12..1ee3cb99 100644 --- a/include/libcamera/internal/camera_sensor_properties.h +++ b/include/libcamera/internal/camera_sensor_properties.h @@ -10,6 +10,7 @@ #include #include +#include #include namespace libcamera { @@ -18,7 +19,7 @@ struct CameraSensorProperties { static const CameraSensorProperties *get(const std::string &sensor); Size unitCellSize; - std::map testPatternModes; + std::map testPatternModes; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..f0aa9f24 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -311,7 +311,7 @@ void CameraSensor::initStaticProperties() } void CameraSensor::initTestPatternModes( - const std::map &testPatternModes) + const std::map &testPatternModes) { const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN); if (v4l2TestPattern == controls().end()) { @@ -327,7 +327,7 @@ void CameraSensor::initTestPatternModes( * control index is supported in the below for loop that creates the * list of supported test patterns. */ - std::map indexToTestPatternMode; + std::map indexToTestPatternMode; for (const auto &it : testPatternModes) indexToTestPatternMode[it.second] = it.first; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index c65afdb2..25490dcf 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -982,13 +982,14 @@ int PipelineHandlerIPU3::updateControls(IPU3CameraData *data) return ret; ControlInfoMap::Map controls = IPU3Controls; - const std::vector &testPatternModes = sensor->testPatternModes(); + const std::vector + &testPatternModes = sensor->testPatternModes(); if (!testPatternModes.empty()) { std::vector values; values.reserve(testPatternModes.size()); - for (int32_t pattern : testPatternModes) - values.emplace_back(pattern); + for (auto pattern : testPatternModes) + values.emplace_back(static_cast(pattern)); controls[&controls::draft::TestPatternMode] = ControlInfo(values); } From patchwork Mon Dec 6 05:49:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15039 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 1A6F6BDB13 for ; Mon, 6 Dec 2021 05:49:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 845206087E; Mon, 6 Dec 2021 06:49:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="VeXk6pXl"; dkim-atps=neutral Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A2F76059E for ; Mon, 6 Dec 2021 06:49:28 +0100 (CET) Received: by mail-pg1-x531.google.com with SMTP id 137so9451421pgg.3 for ; Sun, 05 Dec 2021 21:49:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gn8suQVYM0/PytL1fNvYzUjpec+1U7zCRfoSEqoUqYE=; b=VeXk6pXl0JiCzQcYmgGmb3Xl9x+RSzK+/sMnkaC2hRPH/mV7jbYFzxOUQNu7Mmu1Jz wBwEZwscPliSAEKUrplW2hWVswdsyi3p5mjXKW6Ekxo8xdobuKunSn5qG3rqdp243XoF IxnOQu1sH+Gn0o59AxAFsHXlj0tvFXS53SONw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gn8suQVYM0/PytL1fNvYzUjpec+1U7zCRfoSEqoUqYE=; b=HMkkBTji5pMcOxjyyEox/ozw8TbE5Re5Yj3KJBTrrFlxB+YlkgYumk7/FIwgoPc0Fg zGiZ/eQULhnUCgxN/f73TVpfUJia6R2lP6g4b1ylYwcWO0vIH75i12zaGZhb4PDDtSyK uPAK95ik1gB0KFL0Tmj/QsYRqTRflVSf9B/4hq2LQUmDZPh7n6R6gmwiZi0+Nd5CnqNT fhI0yP0cUq5SwKP6DcIpBBwJIkJp0plC/PyPNKyI2amKEjbKk1dyjV7MwTalEp4EP50Y FYt3sN5myeutt9Fw0O89DsdEuGhFFIEp4SVjCmLjorsZnYeF4WQcpsPH1eKQypjC0MvY pzWQ== X-Gm-Message-State: AOAM530nlHxkp8ovxkC8JsKZgsff9uwQ+g8ZAm8x+hAny3Z5DpV4NlaD KySLu/DuEbSFOVoPdHlLQx054MAr1hY//w== X-Google-Smtp-Source: ABdhPJxd/Zdjt2i9HKSy4ZpnvnCys5vcR4+XRsYtsamFEVARD3u1H5OcbYMZILUC1c8S+ghXS6htJw== X-Received: by 2002:a62:5142:0:b0:4a3:4d13:e7da with SMTP id f63-20020a625142000000b004a34d13e7damr35100667pfb.84.1638769766078; Sun, 05 Dec 2021 21:49:26 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:749e:cfe6:fd85:77b7]) by smtp.gmail.com with ESMTPSA id a1sm11492368pfv.99.2021.12.05.21.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:49:25 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 6 Dec 2021 14:49:17 +0900 Message-Id: <20211206054918.2467049-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211206054918.2467049-1-hiroh@chromium.org> References: <20211206054918.2467049-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 2/3] libcamera: camera_sensor: Enable to set a test pattern mode 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" This adds a function to set a camera sensor driver a test pattern mode. CameraSensor initializes the test pattern mode by Off. Signed-off-by: Hirokazu Honda Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 11 ++- src/libcamera/camera_sensor.cpp | 82 +++++++++++++++++++--- 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 310571ca..3362eaff 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -28,6 +28,8 @@ namespace libcamera { class BayerFormat; class MediaEntity; +struct CameraSensorProperties; + class CameraSensor : protected Loggable { public: @@ -47,6 +49,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -73,15 +76,16 @@ private: int validateSensorDriver(); void initVimcDefaultProperties(); void initStaticProperties(); - void initTestPatternModes( - const std::map - &testPatternModeMap); + void initTestPatternModes(); int initProperties(); + int initTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode); const MediaEntity *entity_; std::unique_ptr subdev_; unsigned int pad_; + const CameraSensorProperties *staticProps_; + std::string model_; std::string id_; @@ -89,6 +93,7 @@ private: std::vector mbusCodes_; std::vector sizes_; std::vector testPatternModes_; + controls::draft::TestPatternModeEnum testPatternMode_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index f0aa9f24..8a79b970 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -54,8 +54,8 @@ LOG_DEFINE_CATEGORY(CameraSensor) * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr), - properties_(properties::properties) + : entity_(entity), pad_(UINT_MAX), staticProps_(nullptr), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -161,7 +161,7 @@ int CameraSensor::init() if (ret) return ret; - return 0; + return initTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); } int CameraSensor::validateSensorDriver() @@ -300,22 +300,33 @@ void CameraSensor::initVimcDefaultProperties() void CameraSensor::initStaticProperties() { - const CameraSensorProperties *props = CameraSensorProperties::get(model_); - if (!props) + staticProps_ = CameraSensorProperties::get(model_); + if (!staticProps_) return; /* Register the properties retrieved from the sensor database. */ - properties_.set(properties::UnitCellSize, props->unitCellSize); + properties_.set(properties::UnitCellSize, staticProps_->unitCellSize); - initTestPatternModes(props->testPatternModes); + initTestPatternModes(); } -void CameraSensor::initTestPatternModes( - const std::map &testPatternModes) +void CameraSensor::initTestPatternModes() { const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN); if (v4l2TestPattern == controls().end()) { - LOG(CameraSensor, Debug) << "No static test pattern map for \'" + LOG(CameraSensor, Debug) + << "V4L2_CID_TEST_PATTERN is not supported"; + return; + } + + ASSERT(staticProps_); + const auto &testPatternModes = staticProps_->testPatternModes; + if (testPatternModes.empty()) { + /* + * The camera sensor supports test patterns but we don't know + * how to map them so this should be fixed. + */ + LOG(CameraSensor, Error) << "No static test pattern map for \'" << model() << "\'"; return; } @@ -531,6 +542,57 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \brief Set the test pattern mode for the camera sensor if it is not the + * currently set test pattern mode. + * \param[in] testPatternMode Test pattern mode control value to set the camera + * sensor + * + * \return 0 on success or a negative error code otherwise + */ +int CameraSensor::setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode) +{ + if (testPatternMode_ == testPatternMode) + return 0; + + return initTestPatternMode(testPatternMode); +} + +/** + * \brief Set the test pattern mode for the camera sensor + * \param[in] testPatternMode Test pattern mode control value to set the camera + * sensor + * + * \return 0 on success or a negative error code otherwise + */ +int CameraSensor::initTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode) +{ + if (!staticProps_ || testPatternModes_.empty()) + return 0; + + auto it = std::find(testPatternModes_.begin(), testPatternModes_.end(), + testPatternMode); + if (it == testPatternModes_.end()) { + LOG(CameraSensor, Error) << "Unsupported test pattern mode " + << testPatternMode; + return -EINVAL; + } + + LOG(CameraSensor, Debug) << "Apply test pattern mode: " << testPatternMode; + + int32_t index = staticProps_->testPatternModes.at(testPatternMode); + ControlList ctrls{ controls() }; + ctrls.set(V4L2_CID_TEST_PATTERN, index); + + int ret = setControls(&ctrls); + if (ret) + return ret; + + testPatternMode_ = testPatternMode; + + return 0; +} + /** * \brief Retrieve the best sensor format for a desired output * \param[in] mbusCodes The list of acceptable media bus codes From patchwork Mon Dec 6 05:49:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15040 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 76054BDB13 for ; Mon, 6 Dec 2021 05:49:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E3F760822; Mon, 6 Dec 2021 06:49:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="a5h5D9h+"; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C94AB605C4 for ; Mon, 6 Dec 2021 06:49:29 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id x7so6890026pjn.0 for ; Sun, 05 Dec 2021 21:49:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dHKC2RYHq2gqVWdlhIepmvHhZoUkoLTI/xkbg0KNkD0=; b=a5h5D9h+iLpXPpN318V6ecKKpbo6yP0zrFF9O3fEYmkk3MO1pp5c+KM40mrgbSOgv9 TsSS4zAklCHU/4d13SKy3LAlSYBBChoCMzu5ztkbzUd8q/Q9RiCFWvXRYW+WQcTqYbci GPyS8gL17kgdvroMj8D77G5dgVlhzS9diq3Tw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dHKC2RYHq2gqVWdlhIepmvHhZoUkoLTI/xkbg0KNkD0=; b=AUgnm4X8jeUB/wqf/GSAybpNDmULIavuR5WSUudcQ9qdxBg7WVQ3t3s0dMkU3bXb92 hArjco05N4Yau9Kqz0V/64WTZU9rag76IeFfPd3+qvJFGSnlsrfzGLeRS0wBk7McDMPP G7WQYZ2G90YFWUzcGAL5HaV+dJX3orgmsIGkAo9iIIgTMCg36fc171jvM2O+NYqBwI4k V85t9mRGZwTH51tzarFpzL5iIacsp5fJlFOIt8xsxsu+wGquGRDf2SssquhU7Qbgeb7l CUZBn7ZNaFa513nJQouIktQU8hsKQPX59IIKJFZxdl66WWKAuW171h0dTcWoScfTms48 C4oA== X-Gm-Message-State: AOAM531nQMfe1hEv8FO17xkWA1sMc7cAbHN56DChMak3xQAsY8aJm5jP lt/GKTnvdXoam8fyDOlQbuPAnqzAxwAGKw== X-Google-Smtp-Source: ABdhPJz7Qvw3eVnGCsUlRwJurehoG4QyX5QpAiWeXBZksIGvl0YpwJERtPs6Vg6TxSa/xZf+e6NlOQ== X-Received: by 2002:a17:902:e5d0:b0:141:cdfe:97d7 with SMTP id u16-20020a170902e5d000b00141cdfe97d7mr40752563plf.65.1638769768062; Sun, 05 Dec 2021 21:49:28 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:749e:cfe6:fd85:77b7]) by smtp.gmail.com with ESMTPSA id a1sm11492368pfv.99.2021.12.05.21.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 21:49:27 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 6 Dec 2021 14:49:18 +0900 Message-Id: <20211206054918.2467049-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211206054918.2467049-1-hiroh@chromium.org> References: <20211206054918.2467049-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 3/3] libcamera: pipeline: ipu3: Apply a requested test pattern mode 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" This introduces a way to set controls immediately for a capture in ipu3 pipeline handler. It enables to apply a test pattern mode per frame. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/ipu3.cpp | 59 +++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 25490dcf..ee1ad27e 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -59,6 +59,7 @@ public: void statBufferReady(FrameBuffer *buffer); void queuePendingRequests(); void cancelPendingRequests(); + void frameStart(uint32_t sequence); CIO2Device cio2_; ImgUDevice *imgu_; @@ -76,7 +77,10 @@ public: std::unique_ptr ipa_; + /* Requests before queueing cio2 device. */ std::queue pendingRequests_; + /* Requests queued in cio2 device and before passing imgu device. */ + std::queue processingRequests_; ControlInfoMap ipaControls_; @@ -564,6 +568,11 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) if (ret) return ret; + ret = cio2->sensor()->setTestPatternMode( + controls::draft::TestPatternModeEnum::TestPatternModeOff); + if (ret) + return ret; + IPACameraSensorInfo sensorInfo; cio2->sensor()->sensorInfo(&sensorInfo); data->cropRegion_ = sensorInfo.analogCrop; @@ -811,6 +820,8 @@ void PipelineHandlerIPU3::stop(Camera *camera) void IPU3CameraData::cancelPendingRequests() { + processingRequests_ = {}; + while (!pendingRequests_.empty()) { Request *request = pendingRequests_.front(); @@ -853,6 +864,8 @@ void IPU3CameraData::queuePendingRequests() info->rawBuffer = rawBuffer; + processingRequests_.push(request); + ipa::ipu3::IPU3Event ev; ev.op = ipa::ipu3::EventProcessControls; ev.frame = info->id; @@ -1121,8 +1134,8 @@ int PipelineHandlerIPU3::registerCameras() data->delayedCtrls_ = std::make_unique(cio2->sensor()->device(), params); - data->cio2_.frameStart().connect(data->delayedCtrls_.get(), - &DelayedControls::applyControls); + data->cio2_.frameStart().connect(data.get(), + &IPU3CameraData::frameStart); /* Convert the sensor rotation to a transformation */ int32_t rotation = 0; @@ -1414,6 +1427,48 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) ipa_->processEvent(ev); } +/* + * \brief Handle the start of frame exposure signal + * \param[in] sequence The sequence number of frame + * + * Inspect the list of pending requests waiting for a RAW frame to be + * produced and apply controls for the 'next' one. + * + * Some controls need to be applied immediately, such as the + * TestPatternMode one. Other controls are handled through the delayed + * controls class. + */ +void IPU3CameraData::frameStart(uint32_t sequence) +{ + delayedCtrls_->applyControls(sequence); + + if (processingRequests_.empty()) + return; + + /* Handle controls which are to be set ready for the next frame to start. */ + Request *request = processingRequests_.front(); + processingRequests_.pop(); + + /* Takes effect applying the test pattern mode affects immediately. */ + if (!request->controls().contains(controls::draft::TestPatternMode)) + return; + + const int32_t testPatternMode = request->controls().get( + controls::draft::TestPatternMode); + + int ret = cio2_.sensor()->setTestPatternMode( + static_cast( + testPatternMode)); + if (ret) { + LOG(IPU3, Error) << "Failed to set test pattern mode: " + << ret; + return; + } + + request->metadata().set(controls::draft::TestPatternMode, + testPatternMode); +} + REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3) } /* namespace libcamera */