From patchwork Wed Nov 10 03:16:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14505 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 14235BDB1C for ; Wed, 10 Nov 2021 03:17:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 66BDB6034E; Wed, 10 Nov 2021 04:17:00 +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="cfoOFvaX"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DD8A960234 for ; Wed, 10 Nov 2021 04:16:58 +0100 (CET) Received: by mail-pj1-x1031.google.com with SMTP id v23so384237pjr.5 for ; Tue, 09 Nov 2021 19:16:58 -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=8zv8+6CeG3JlrqiA2HdTIX0u11iqVcSsHDAfnyGUIBU=; b=cfoOFvaX3az/D1J21iankdYvuIBFgQAZ2YL38iPMBnS9pwIVefd62D90kgBZP6b4m1 N2mDIHa3373I9N6BSYkpEfrD8U0Eh5onnZkjVnOfiBae3f4mtoFJrHcngpdjvbORhLqv fb/yTXf285u5B14iPSQ2MmNRoGHH1P0adqnBQ= 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=8zv8+6CeG3JlrqiA2HdTIX0u11iqVcSsHDAfnyGUIBU=; b=yqj2aTv+tzwZoc31VyyyrSIdfRozlyYXYRHTCvmklfN5oSf8iDWtg9Dn1B9yWJJFYi CNr7arxowtzWEuRpY78bvOYLwqVgW3iu8VLemqWYoH5XhaCn/j7/5Cr4KTq6TguVmeL6 0Y+EydBPXPfvw3hvm7V3vNlE3r8qGa7I28swe/WMHTkZlUb8MA0pT4iRHU7bU2fEPKpC WXdcZRfwzKS/UDPDQmZh3Mg4z6wh6ocgeRXoweOaw+++ynwDgiJn077Df75ImdDZKr7i QL4C70FlZK8zVHbcA4AogOmgKD2g8FP0Br0n3Kv7Dl7BVh0Q5SLg6TdQLMFzPR20qX5p AQjA== X-Gm-Message-State: AOAM533I1fdnvNrhZ6rf0TShTwQUsEbz4eRSS8b1V5M2TMwSQ83yU3+X CF/rpH352sZfonCfV4XxWhQ8MCQoZVYfuQ== X-Google-Smtp-Source: ABdhPJyufEwxvSjzpYHCMT58HWt3BdXBsgr0Z3awB+4/oniS1C4JXmy7YcdnJNttNxSuRzOprtUb5g== X-Received: by 2002:a17:90b:4a05:: with SMTP id kk5mr13058534pjb.232.1636514217189; Tue, 09 Nov 2021 19:16:57 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4a73:e1bd:9b3f:4903]) by smtp.gmail.com with ESMTPSA id k3sm7550163pff.211.2021.11.09.19.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 19:16:56 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Nov 2021 12:16:49 +0900 Message-Id: <20211110031651.2808099-1-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 --- 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 d25a1165..edef2220 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 67c77920..5c7e5e87 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 eb714aa6..63cb7f11 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -981,13 +981,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 Wed Nov 10 03:16:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14506 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 384CDBDB1C for ; Wed, 10 Nov 2021 03:17:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EB97F60362; Wed, 10 Nov 2021 04:17:02 +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="Nms6knkc"; dkim-atps=neutral Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F1B946032C for ; Wed, 10 Nov 2021 04:17:00 +0100 (CET) Received: by mail-pl1-x62b.google.com with SMTP id v20so1819401plo.7 for ; Tue, 09 Nov 2021 19:17:00 -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=ctF0x2IRQJUstC5IPaYwhfO22QK23fcQHyF6A24usGk=; b=Nms6knkc+ewaCc46QX4WW54aLYEWbli8/vDlVSPJDV9qBObuGp/kYr4L+uVvabo+j4 PW6zyOjgxvvPKbs/4ndseHY7yG/NdAMaPbT1I7g96y2fh/8+zVB5L8SISdfjzEZ7NBW/ 3QszcaXfZChQRCTGpgXP1PjZNGGWTeswhzeoM= 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=ctF0x2IRQJUstC5IPaYwhfO22QK23fcQHyF6A24usGk=; b=0Sq9vgW4cht3GZnAsoiH2W5blktupLog+1C+AqJdxEMKq7Qf5HwKeg54TfJNOVRuzT 3+XXKGWmm7IL45HpHwRqA3kbk6FLsGW4CVfXnh4XODP/9KJvcn+T61YlPIOt/nD8WXkd tTwbdYWxQhjugKW+aL9zof0GuZ1oyOyS3aDpUE1XL1MIVAVSL2SLwHwpZQGW8JEaMB0H hH6qNyQ9zFg1BK5ydMThB8QC2voP8W9PdKRxha+g8fjKutLOvkPey++ZHUkqETZsadmd wGGTqgbcYZyiGvegcyQPFbcGc2HFVLNxfrsAmfNmkjd6B7X23imiD1u/wa1yFk5zAJ0K 9qQg== X-Gm-Message-State: AOAM531uGM5EdUoBwXQJr8clOugpbq8v6HTkOQaWaeT2htULzb7SUftr QZPDtbmSQXcyn8b28kyQyloMk3iW82Y6CA== X-Google-Smtp-Source: ABdhPJw2avVgqZHX7z6Z2R5O0uk/anWvdv/ysnjYocS8cBajZqWJ/XXpfxrTkIK3dYVzZT20MXVlrQ== X-Received: by 2002:a17:90a:4e02:: with SMTP id n2mr12963784pjh.170.1636514219201; Tue, 09 Nov 2021 19:16:59 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4a73:e1bd:9b3f:4903]) by smtp.gmail.com with ESMTPSA id k3sm7550163pff.211.2021.11.09.19.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 19:16:58 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Nov 2021 12:16:50 +0900 Message-Id: <20211110031651.2808099-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110031651.2808099-1-hiroh@chromium.org> References: <20211110031651.2808099-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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. Signed-off-by: Hirokazu Honda Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 8 +++ src/libcamera/camera_sensor.cpp | 64 +++++++++++++++++++--- src/libcamera/control_ids.yaml | 5 ++ 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index edef2220..60ce0c45 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -27,6 +27,9 @@ namespace libcamera { class BayerFormat; class MediaEntity; +class Request; + +struct CameraSensorProperties; class CameraSensor : protected Loggable { @@ -78,10 +81,14 @@ private: &testPatternModeMap); int initProperties(); + int setTestPatternMode(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 +96,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..35925a95 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -17,6 +17,7 @@ #include #include +#include #include @@ -54,8 +55,9 @@ 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), + testPatternMode_(controls::draft::TestPatternModeUnset), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -161,6 +163,10 @@ int CameraSensor::init() if (ret) return ret; + ret = setTestPatternMode(controls::draft::TestPatternModeOff); + if (ret) + return ret; + return 0; } @@ -300,14 +306,14 @@ 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(staticProps_->testPatternModes); } void CameraSensor::initTestPatternModes( @@ -315,7 +321,15 @@ 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; + } + + 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 +545,42 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \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::setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode) +{ + if (testPatternMode_ == testPatternMode) + return 0; + + 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; + } + + 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 diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml index 9d4638ae..083bac7b 100644 --- a/src/libcamera/control_ids.yaml +++ b/src/libcamera/control_ids.yaml @@ -639,6 +639,11 @@ controls: Control to select the test pattern mode. Currently identical to ANDROID_SENSOR_TEST_PATTERN_MODE. enum: + - name: TestPatternModeUnset + value: -1 + description: | + No test pattern is set. Returned frames by the camera device are + undefined. - name: TestPatternModeOff value: 0 description: | From patchwork Wed Nov 10 03:16:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14507 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 B3E8EC324E for ; Wed, 10 Nov 2021 03:17:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 55AD760345; Wed, 10 Nov 2021 04:17:05 +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="KSidUDw6"; dkim-atps=neutral Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E3E0C60345 for ; Wed, 10 Nov 2021 04:17:02 +0100 (CET) Received: by mail-pg1-x52c.google.com with SMTP id r28so983009pga.0 for ; Tue, 09 Nov 2021 19:17:02 -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=oy7jE/IlKj7PzVfnuxUOddepDqkTfQ/0J9TOVft3tQU=; b=KSidUDw6jmNxrw0miur1Y8OUeFCD5oqxEy9iZKxywPselfeUpGHf8GvI9GKLsao8Vr 2hy74yG/DadA6K4HdLASKYW7G8y56PFai7rA51mdq2xPmqx6stxfygjxhbQdCtOexZDl Bs0gZ3jgMH8lVZSLa0Incpp6ssv/fA0O4uT6E= 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=oy7jE/IlKj7PzVfnuxUOddepDqkTfQ/0J9TOVft3tQU=; b=mLJmzTa38TwcWlqgWqnWbzNfygUWrmBDaZmpN9SuevciRhdxavN1mCvk3k4oEepr3N OTwgefpQ8OgVVKHzDyDJCJtk/VkZJgPkZezsNM3pvUcVjFMSuKr2audrKqy591nlRzH8 T9d9LLpPOrgNze2eDFq4OSoE4rXWlSAmKzbwmVoxL6h8zNmi7niX2Y0DPXcwdvI4miFz EV2XYsnVU5TNC6BgcGCcfeTjJnnnBDyst987N59XeZx0zOh4bJkyz3dLdfxzynbXlurI gB0JUvpCk+VIViS8uJOEY7u2DuXBqRYNZpWs/EX3YxNqwKGvpEM/bsltYaJDn2LL/4C6 RMtQ== X-Gm-Message-State: AOAM531U8Irwk7edIQBzxhHO7XCUtVRBhftzkaUI8P+Zq9J125GCsSE7 g/oYGt2PKN8+tml3nELZC5PmkSKVKTHR0w== X-Google-Smtp-Source: ABdhPJyVDBj+dqrZMIliAYti0rgV90U53hnDNi+fWklUyqHckCznCfzDUG0DMX8OG08xkxa5bcyxrg== X-Received: by 2002:a63:8b41:: with SMTP id j62mr9782680pge.420.1636514221037; Tue, 09 Nov 2021 19:17:01 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4a73:e1bd:9b3f:4903]) by smtp.gmail.com with ESMTPSA id k3sm7550163pff.211.2021.11.09.19.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 19:17:00 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Nov 2021 12:16:51 +0900 Message-Id: <20211110031651.2808099-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110031651.2808099-1-hiroh@chromium.org> References: <20211110031651.2808099-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 3/3] libcamera: pipeline: ipu3: Apply the 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 enables ipu3 pipeline handler to apply the test pattern mode per frame. Signed-off-by: Hirokazu Honda Reviewed-by: Jean-Michel Hautbois --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 34 ++++++++++++++++++++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 29 ++++++++++++++++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 60ce0c45..ed782476 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -58,6 +58,7 @@ public: const ControlInfoMap &controls() const; ControlList getControls(const std::vector &ids); int setControls(ControlList *ctrls); + int applyRequestControls(Request *request); V4L2Subdevice *device() { return subdev_.get(); } diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 35925a95..db13d9ea 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -755,6 +755,40 @@ int CameraSensor::setControls(ControlList *ctrls) return subdev_->setControls(ctrls); } +/** + * \brief Apply controls associated with Request + * \param[in] request Request that may contain contorls to be applied + * + * Some controls have to be applied for a capture associated with Request. + * This picks up such controls and set the driver them. + * + * \return 0 on success or an error code otherwise + */ +int32_t CameraSensor::applyRequestControls(Request *request) +{ + /* Assumes applying the test pattern mode affects immediately. */ + if (request->controls().contains(controls::draft::TestPatternMode)) { + const int32_t testPatternMode = request->controls().get( + controls::draft::TestPatternMode); + + LOG(CameraSensor, Debug) << "Apply test pattern mode: " + << testPatternMode; + + int ret = setTestPatternMode( + static_cast(testPatternMode)); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to set test pattern mode: " << ret; + return ret; + } + + request->metadata().set(controls::draft::TestPatternMode, + testPatternMode); + } + + return 0; +} + /** * \fn CameraSensor::device() * \brief Retrieve the camera sensor device diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 63cb7f11..dd662ff1 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_; @@ -77,7 +78,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_; @@ -802,6 +806,7 @@ void PipelineHandlerIPU3::stop(Camera *camera) ret |= data->imgu_->stop(); ret |= data->cio2_.stop(); + if (ret) LOG(IPU3, Warning) << "Failed to stop camera " << camera->id(); @@ -822,6 +827,8 @@ void IPU3CameraData::cancelPendingRequests() pipe()->completeRequest(request); pendingRequests_.pop(); } + + data->processingRequests_ = {}; } void IPU3CameraData::queuePendingRequests() @@ -852,6 +859,8 @@ void IPU3CameraData::queuePendingRequests() info->rawBuffer = rawBuffer; + processingRequests_.push(request); + ipa::ipu3::IPU3Event ev; ev.op = ipa::ipu3::EventProcessControls; ev.frame = info->id; @@ -1131,8 +1140,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; @@ -1423,6 +1432,22 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) ipa_->processEvent(ev); } +void IPU3CameraData::frameStart(uint32_t sequence) +{ + if (!processingRequests_.empty()) { + /* Handle controls which are to be set ready for the next frame to start. */ + Request *request = processingRequests_.front(); + processingRequests_.pop(); + + int ret = cio2_.sensor()->applyRequestControls(request); + if (ret) + LOG(IPU3, Error) << "Failed applying controls: " << ret; + } + + /* Controls that don't affect immediately are applied in delayedCtrls. */ + delayedCtrls_->applyControls(sequence); +} + REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3) } /* namespace libcamera */