From patchwork Fri Nov 26 05:08:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14792 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 253D6BDB13 for ; Fri, 26 Nov 2021 05:08:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D6D8B604FC; Fri, 26 Nov 2021 06:08:21 +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="iKni2Ift"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C054C604FC for ; Fri, 26 Nov 2021 06:08:19 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id cq22-20020a17090af99600b001a9550a17a5so9118647pjb.2 for ; Thu, 25 Nov 2021 21:08:19 -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=dU+ajapeoM9GAYlsiUIGsiZ8ATHPqNzBP0EXs7GoRcQ=; b=iKni2IftbRZD9TPhjQTinkwSOCm2eAXIF40IfUmpZx0enTgGOpoMDdRs7nPsdD5jQY HPRGzErOVCPVgQzI7THgARHUw/uQs/kyr9oUkZu0jFuMQ+PLyBr+43rcM9R7Ko9BurH6 f1NWuVjGr28S2PcVlXZQ1J0AA+j69+qHNm6C4= 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=dU+ajapeoM9GAYlsiUIGsiZ8ATHPqNzBP0EXs7GoRcQ=; b=xFL371qfs+tUR+TquTdmlWe937ztIlHYeJXxeUIbvmwlNEqEUZl2isOQUFTlxTxvf2 8Y9rZMa33zG00SEz+bPLJULCuRDcGSsjwo8vjL3zkFlHmEahgyCCGQAYhKP3o4xUbu1B SD280yOSd4i2v0Ldu+P3AKCjEtdY4yOlwMY75n3bvLdW1LCKsblQ3MPRyvVxL/j0Cv+k d7n2QA/NzVcAvmPC8ae16m2/QyIAnZibtFFit4fyXwct6sRUiHqM+G6L+JR+CftTSc3D +rGhlCFyum2DjVYNp8VslNSe+Qrcoefu0nxIyEcAlZnmcBHXGJ7NZKxM84MMkkNF7QBK OEtA== X-Gm-Message-State: AOAM533pIvJl8Ygp3iluHTArw4kmP9EcYh+Ir/tz+v+aR2eSxtUbkSen dUcxfVT71OQrMeGsxKIi7pqKfi1N5tkkvQ== X-Google-Smtp-Source: ABdhPJy1QqSVndM1ufJf8fOF1qqmNKo6mhNtIs2cGeoV9YqtUONSVnb2dTNQfimf7HjdGMeel5PwDQ== X-Received: by 2002:a17:90a:4894:: with SMTP id b20mr12971949pjh.121.1637903298018; Thu, 25 Nov 2021 21:08:18 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:139c:952e:8861:d909]) by smtp.gmail.com with ESMTPSA id k6sm9280248pjt.14.2021.11.25.21.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 21:08:17 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 14:08:08 +0900 Message-Id: <20211126050810.1871781-2-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 Subject: [libcamera-devel] [PATCH v8 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 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 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 Fri Nov 26 05:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14793 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 981C7BDB13 for ; Fri, 26 Nov 2021 05:08:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4B493604F9; Fri, 26 Nov 2021 06:08:24 +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="RvavMBfF"; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8315C6011D for ; Fri, 26 Nov 2021 06:08:21 +0100 (CET) Received: by mail-pl1-x62d.google.com with SMTP id m24so5905862pls.10 for ; Thu, 25 Nov 2021 21:08:21 -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=BMR9GeCOSQN+ULweUyQmyaMYtRuhwZuDi/MCbB2HO6E=; b=RvavMBfFNrtiUY0AF7q1Plssa7a1DfYW5uZLrQm09jB52y9qupy/AH80WdVuOFfq5r oNUXTv/2nGzmi32ow3/pl0RY7JwOkZuPjtMqhvOfyFaDNkp/w1WLpVC0HgXJ2Fw1dfP2 5ytz5U1zHRjyB5mUyPPqufORKusR92j94h9TM= 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=BMR9GeCOSQN+ULweUyQmyaMYtRuhwZuDi/MCbB2HO6E=; b=qYDOpJE00E+L7Z21GgmAMl2gTwaLE4sDRjJwGvQXPqK7GZBVjfuL+9sH0tNF2wunDl IupH8hpM+6U9U1TNo7XyoRQCGFFSuI9oJY1K9l+vQFtMz4l4onSYJ0JiEXs0nlPokSCl cET+smc9pPCj98/KovdfBYBwVfyOFb6/9deTL+u5MknPht1uUPgfqONhTdTJ3Nuu7GqK fn8RLrUmQzEVTL3Sbxxe6yTyj32kP+q1b4GROJJQcSc2COkd7mrBV0wXeMNnhPafQXUV GcRqeWJMkl1GbJiRXo5BdeV0/2jo5JYcHa7DfCqyn5DsQggZK6bQAG6jLinKFZOK8wl9 C7nQ== X-Gm-Message-State: AOAM533HkL11IlMgn0+AxRdDRsGtefMVpal2i6f4nOnLFhIhG1Jav/5f 77eZmhO6sik2Jt28g5P32FdXxril2agt2w== X-Google-Smtp-Source: ABdhPJwNtyRH5v7heJedoJUBODONnd8MxJJJcCqEz78fja42RWehMrgO6W2qBYKMUIjqlAd0ffsEzg== X-Received: by 2002:a17:90a:be10:: with SMTP id a16mr12891471pjs.133.1637903299784; Thu, 25 Nov 2021 21:08:19 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:139c:952e:8861:d909]) by smtp.gmail.com with ESMTPSA id k6sm9280248pjt.14.2021.11.25.21.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 21:08:19 -0800 (PST) From: Hirokazu Honda 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 Subject: [libcamera-devel] [PATCH v8 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 --- include/libcamera/internal/camera_sensor.h | 6 ++ src/libcamera/camera_sensor.cpp | 75 ++++++++++++++++++++-- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index edef2220..a110fd08 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; @@ -82,6 +85,8 @@ private: std::unique_ptr subdev_; unsigned int pad_; + const CameraSensorProperties *staticProps_; + std::string model_; std::string id_; @@ -89,6 +94,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..2c6312d4 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,6 +161,21 @@ int CameraSensor::init() if (ret) return ret; + auto initTestPatternMode = controls::draft::TestPatternModeEnum::TestPatternModeOff; + if (staticProps_) { + auto it = staticProps_->testPatternModes.find(initTestPatternMode); + if (it != staticProps_->testPatternModes.end()) { + ControlList ctrls{ controls() }; + ctrls.set(V4L2_CID_TEST_PATTERN, it->second); + + ret = setControls(&ctrls); + if (ret) + return ret; + + testPatternMode_ = initTestPatternMode; + } + } + return 0; } @@ -300,14 +315,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 +330,17 @@ 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 +556,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 From patchwork Fri Nov 26 05:08:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14794 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 3C1D2BDB13 for ; Fri, 26 Nov 2021 05:08:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EDC6B6049A; Fri, 26 Nov 2021 06:08:25 +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="e55YqXkb"; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6BB7F60492 for ; Fri, 26 Nov 2021 06:08:23 +0100 (CET) Received: by mail-pj1-x1029.google.com with SMTP id y14-20020a17090a2b4e00b001a5824f4918so9094531pjc.4 for ; Thu, 25 Nov 2021 21:08:23 -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=oOLVLe+hX0g+Qrj/5QThziAsLyhcjI7qFpkEZYN0EjA=; b=e55YqXkb7MvGfFqWA/tlDewrEexEi7IRBhabSls5GxwHXu4x5FpJp9C/9GuqWyTrHm jfK/2V4MxWMBmvhls1c1cdOZhbeCIhnHzw8zeQk1liKncrGRhS5WxUMbiC5W1XpsSy16 s2UL/sVCjHpPbDc9OU2rsj9b7+tSFMHb931rM= 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=oOLVLe+hX0g+Qrj/5QThziAsLyhcjI7qFpkEZYN0EjA=; b=PQIZimPCI6AZyX5Bz6g7IpAJVlUzCIvTnUWS1LVMEDMMpYUbVKq2b+OiMX7hPAHUGP S24GtP0cis59lVuTJjUAcTCWWgDTOA0T/a1kSFDzIHgKAhkytcxLaBAFZuDFCBT72AJq l6B4Iz2LDngHX6zEYTDjGAzQ02s9HdkBUsK6U0ablvxlv6v/4Hnt9v1UnsPO+qaD8VPL KjbYHVMGWEF3Dkww2ZiFUUmOs2bT9UlN9duVzp6g4gHPr+SZnc/b+jP0qEhxFY7QOPyH VpkHjAaf+O+p4oXA1ktX4ivV1BDqHc+NTfj/jJ3wH6ePESenZZyICe+K3pldNNXDTXLt JlCw== X-Gm-Message-State: AOAM532cudWnT5mAiQDYPN74SE3P5sHRAj3yiSpHKsJUIdm5wxgpRcXq Vz0iFxoSEYxnHu8RLBHoCNIIp972D/pc6g== X-Google-Smtp-Source: ABdhPJx1kwtTqog9Bojqt8XWk2ZRazXjDvL0tkZgDRgo2qSoRDWTqi3quIri1p49awouhZu+ApQKGg== X-Received: by 2002:a17:90b:4d8f:: with SMTP id oj15mr12737068pjb.127.1637903301768; Thu, 25 Nov 2021 21:08:21 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:139c:952e:8861:d909]) by smtp.gmail.com with ESMTPSA id k6sm9280248pjt.14.2021.11.25.21.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 21:08:21 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 14:08:10 +0900 Message-Id: <20211126050810.1871781-4-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 Subject: [libcamera-devel] [PATCH v8 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 --- src/libcamera/pipeline/ipu3/ipu3.cpp | 55 +++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 25490dcf..31f5f9dd 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_; @@ -823,6 +827,8 @@ void IPU3CameraData::cancelPendingRequests() pipe()->completeRequest(request); pendingRequests_.pop(); } + + processingRequests_ = {}; } void IPU3CameraData::queuePendingRequests() @@ -853,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; @@ -1121,8 +1129,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 +1422,49 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) ipa_->processEvent(ev); } +void IPU3CameraData::frameStart(uint32_t sequence) +{ + /* + * Handle the start of frame exposure signal. + * + * 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. + */ + + delayedCtrls_->applyControls(sequence); + + if (!processingRequests_.empty()) { + /* Handle controls which are to be set ready for the next frame to start. */ + Request *request = processingRequests_.front(); + processingRequests_.pop(); + + /* Assumes 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); + + LOG(IPU3, Debug) << "Apply test pattern mode: " + << 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 */