From patchwork Thu Nov 4 06:42: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: 14452 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 B4F9FBDB1C for ; Thu, 4 Nov 2021 06:43:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 52DE66033E; Thu, 4 Nov 2021 07:43:03 +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="RQt2Cv5r"; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 70B3D60121 for ; Thu, 4 Nov 2021 07:43:01 +0100 (CET) Received: by mail-pf1-x433.google.com with SMTP id u33so4897715pfg.8 for ; Wed, 03 Nov 2021 23:43:01 -0700 (PDT) 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=snzi0oUm9WISwJDyr3Hm4OC/jfSnXbHxxwO/stRIWu4=; b=RQt2Cv5rz3Ypq3EBRVhxfKj/r5GApKLR9PTFs0nW78blRTvh+7k0xM0QbzQkAeLKwm KPlHQgrfME0r1aOwRTc0nzwOJ4ttfTQzTX479c3QLYvRqyoayfvW51y1R/SMD2MSiTU+ 7he6tXr0zKndOcrdW40oCz+bAdQtwgY+HUGYA= 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=snzi0oUm9WISwJDyr3Hm4OC/jfSnXbHxxwO/stRIWu4=; b=4RJOfhqlaKjxEfWqU/3mi5AskrzPAE4jvCAahWasZhoJDx3UNEXZVHp4tQSw4jftt1 duTlhAjCGVXMe8pmgxtc1sYBJHKjr6rNuyNGgHSfo2tUsl/uX4xzqmV9qJLru4+pb95V sqYY1nCCCO1Q1Q8b+nSHiyzWU/ncYLC1XsmbsAvJZ9uFrcxUBzkdWesy/VkaTJ0DeMp3 pFjRnbAFIFzO2nSfCOr5x9cAAR+jsfVaTADEE4f59iEgYmFRR3X1UqgcHXCVvorIkutP XuWjRzIWKolIeM2ya3G0CwPgXSO6+JnLM955s07s7GVrD6tFWAznFNKXgXqsBEhqwJlb 33ZQ== X-Gm-Message-State: AOAM531H2gtupO1GWq/k3yF2BJSltMhQtCgA7pYt+19ofZLwyjndss9Y FvfcjQQorgXq6ynrWJu9biDlrLvna7nIWA== X-Google-Smtp-Source: ABdhPJzte4kByrlVWZOSTrQsGbJyBo7HW7DoTuapS8JT71rE5dEs3XtAOVL8vtSHsKG7NcgZFZJKpA== X-Received: by 2002:a63:be4e:: with SMTP id g14mr37917005pgo.194.1636008179624; Wed, 03 Nov 2021 23:42:59 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:9022:fd2e:f66e:b99b]) by smtp.gmail.com with ESMTPSA id s6sm4265580pfu.137.2021.11.03.23.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Nov 2021 23:42:59 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Nov 2021 15:42:50 +0900 Message-Id: <20211104064252.2091330-2-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 Subject: [libcamera-devel] [PATCH v4 1/3] camera_sensor: Deal test pattern mode control values with its enum 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 changes the type of test pattern mode control values to controls::draft::TestPatternModeEnum from int32_t 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 Thu Nov 4 06:42: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: 14453 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 33674BDB1C for ; Thu, 4 Nov 2021 06:43:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E1F5160341; Thu, 4 Nov 2021 07:43: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="iZk8681O"; dkim-atps=neutral Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 680EC60341 for ; Thu, 4 Nov 2021 07:43:03 +0100 (CET) Received: by mail-pl1-x633.google.com with SMTP id t21so5646157plr.6 for ; Wed, 03 Nov 2021 23:43:03 -0700 (PDT) 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=75SYs/bSY+JgMTa/Gyr2joLcLqjYgX6ECTOMav8wiac=; b=iZk8681OQ523P0pCgsRuPblH1v6zPwQyLXoTqdCSMqCjADZCUFPudqkCVQJwvoUvDw W7oc/lhKXMeCFzHgpubI7IsUSc9BF4rok7Bp7RZIlFPtCF1tVZfSI6M355t/EJNn+A+1 eqTZM7fUZ2GBP/gOyIjW6Qk2xi0m/7Z7iImdY= 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=75SYs/bSY+JgMTa/Gyr2joLcLqjYgX6ECTOMav8wiac=; b=SHwcGE0ocVZUGSiqnLFNUGxzi/DSaxlGTSKgQ8WJD2QJ3YJsK5zPHPFiHIuc7QKFCh 066fu4g09yijvEbyip+6B69DO+bl/uuzB7YZrDIJf2SvexITd1zg+fVrn+0Q9yBPxJ8T or4nlCuogg6lNIeXe7bQEKXBeMSxa1GfgpKnMalimd3iz0+zVjECGF03ajFU2481W5PK KCyDnosszGCJTzrCnOO4VC82jV6XZDWQ0vGGbmklplbj/69FB2xaYeY9hyZBgrW+f4GO C2zqVT1coOZ133n7BJtpBQlcL6ZEVj1/5DssgWsn+Izk2ubOSAOAfujBD0QMPcvSYwy2 UXmQ== X-Gm-Message-State: AOAM5316A+oKLcZ2CUZAXohSHMV6BEydsJ4JOv+xvYJjreBqJTv1ZAX+ rsoQPQfZk61ojk50HC6RZVN9RUiR98pCwA== X-Google-Smtp-Source: ABdhPJxQaXyUKJlTLKMO8jkCjd9w5T75hXDwkbs8gCPke15Q2qmJ4BTr4/qPn/xQBk88p5j8/eNc0A== X-Received: by 2002:a17:90a:5b0c:: with SMTP id o12mr20389936pji.194.1636008181586; Wed, 03 Nov 2021 23:43:01 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:9022:fd2e:f66e:b99b]) by smtp.gmail.com with ESMTPSA id s6sm4265580pfu.137.2021.11.03.23.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Nov 2021 23:43:01 -0700 (PDT) From: Hirokazu Honda 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 Subject: [libcamera-devel] [PATCH v4 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 | 95 ++++++++++++++++++++-- src/libcamera/control_ids.yaml | 5 ++ 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index edef2220..40db792a 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 { @@ -47,6 +50,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -55,6 +59,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(); } @@ -82,6 +87,8 @@ private: 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..bb429b3e 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) { } @@ -300,25 +302,30 @@ 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( const std::map &testPatternModes) { - const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN); - if (v4l2TestPattern == controls().end()) { + if (testPatternModes.empty()) { LOG(CameraSensor, Debug) << "No static test pattern map for \'" << model() << "\'"; return; } + const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN); + if (v4l2TestPattern == controls().end()) { + LOG(CameraSensor, Debug) + << "V4L2_CID_TEST_PATTERN is not supported"; + return; + } /* * Create a map that associates the V4L2 control index to the test @@ -531,6 +538,44 @@ 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_) { + 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 @@ -705,6 +750,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/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 Thu Nov 4 06:42:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14454 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 BBA70C324E for ; Thu, 4 Nov 2021 06:43:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 57F316033D; Thu, 4 Nov 2021 07:43:06 +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="EN025RLr"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0CF986033D for ; Thu, 4 Nov 2021 07:43:05 +0100 (CET) Received: by mail-pl1-x629.google.com with SMTP id k4so5628944plx.8 for ; Wed, 03 Nov 2021 23:43:04 -0700 (PDT) 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=GlBe5o3IfiKGRsb6hEZvnIPGee2xBRdPPb3dmgbxfzA=; b=EN025RLrb1OtdI0RcqX/5ILp7vGKfw7W2J5CGhRD8AbftSUsVoEjn1VksP1eFbwuQE /lDDQ8NjUhQiYqKF/6vuvU9wkkLsxCFzxhleIJnC1v4znXksFSrImmXhRCvfOd849Lvk OQRuQJk/RyzgbXTHmsprFKfYJAUuX8QlVUwJU= 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=GlBe5o3IfiKGRsb6hEZvnIPGee2xBRdPPb3dmgbxfzA=; b=qeZptontKhzLaigPAgxi8Zne23wDdKGnpZQ3JEPmqnblGUplnsPn35eoWuXNrw3vLc v0fNRHCNNOtMx11sWWSlerwEZPdMeYWWAss1yIR2XyzF0jKNpMkfdzLO4WZ94DA5ztMT swSFPO4jmi3HyNNny4J1ddx0oAIQEtB70kvM3r+I6BrcYsxpCVRZJIK8y+OoAXkV7xz1 RegKHDhl3S9PvWlJ71aTLVr+qSHz1saCG4rnXcEL7MlNPpZ9Wp5trLaM7hy8yBIKpue1 T3NLbm6hsrul0dHt8cZeErN0f8baLX9lnouG+b1B20aoEWSv5KLmT8wh5otIpwRCmVmW RP8A== X-Gm-Message-State: AOAM530Hfa+aVsaPRBunyoKMo9gpZ0rz+20BE777cpu89hRtI3oxtKPF 7WBzuZaLADUZcfrA3fTC13A+XnBlQBwaCA== X-Google-Smtp-Source: ABdhPJyETqHxDglpztu0soOMFhojfs5OjW1rAOz6VuXu98D938zG4aHI1EBA7OsRuuKPEFSrMraZsQ== X-Received: by 2002:a17:90b:4a89:: with SMTP id lp9mr20162763pjb.6.1636008183423; Wed, 03 Nov 2021 23:43:03 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:9022:fd2e:f66e:b99b]) by smtp.gmail.com with ESMTPSA id s6sm4265580pfu.137.2021.11.03.23.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Nov 2021 23:43:02 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Nov 2021 15:42:52 +0900 Message-Id: <20211104064252.2091330-4-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 Subject: [libcamera-devel] [PATCH v4 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 --- src/libcamera/pipeline/ipu3/ipu3.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 63cb7f11..cb141ba9 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_; @@ -78,6 +79,7 @@ public: std::unique_ptr ipa_; std::queue pendingRequests_; + std::queue processingRequests_; ControlInfoMap ipaControls_; @@ -569,6 +571,8 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) cio2->sensor()->sensorInfo(&sensorInfo); data->cropRegion_ = sensorInfo.analogCrop; + cio2->sensor()->setTestPatternMode(controls::draft::TestPatternModeOff); + /* * Configure the H/V flip controls based on the combination of * the sensor and user transform. @@ -797,11 +801,13 @@ void PipelineHandlerIPU3::stop(Camera *camera) int ret = 0; data->cancelPendingRequests(); + data->processingRequests_ = {}; data->ipa_->stop(); ret |= data->imgu_->stop(); ret |= data->cio2_.stop(); + if (ret) LOG(IPU3, Warning) << "Failed to stop camera " << camera->id(); @@ -852,6 +858,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 +1139,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 +1431,22 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) ipa_->processEvent(ev); } +void IPU3CameraData::frameStart(uint32_t sequence) +{ + if (!processingRequests_.empty()) { + /* Assumes applying the test pattern mode affects immediately. */ + 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 */