From patchwork Tue Nov 23 19: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: 14728 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 E8D40BF415 for ; Tue, 23 Nov 2021 19:08:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A25056038A; Tue, 23 Nov 2021 20: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="ges1Q1+n"; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B94D60228 for ; Tue, 23 Nov 2021 20:08:23 +0100 (CET) Received: by mail-pf1-x42f.google.com with SMTP id 8so224210pfo.4 for ; Tue, 23 Nov 2021 11:08:22 -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=ges1Q1+nk3oFISRy5IqPjkE6D5stO/QPZjjGCx5a4by5bMrCc+sM2V/UtUW3U2hAFM Ag/VLEFwRU9SjAS+z4NSkPVRUiFdZd5ZcrhcG0mR0q6HVdZpfi1ttT93ksRiHa4EsFKr bfxvWFpLoGQZ0vnjLeShrDo8zMaGF3lYfUTWQ= 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=kivTzr1ESJt9BAFOJfd03ndukOOBvbzTJHkJAO1XfAstlgB/LNLJqmse2zMCDPA4QG FPovbqpmfYvymOZvCUp47b3BYvZiq5MEbtMxPtoRx9A2x7xAILdErJP1r7yI8VsKJ3L+ FecDZZ5iUKM+s9O7BxeaFzuhxa5jIgAfKYR9FWqx2duwnjwTfh6oOKvbwgnA6sa5Bnz9 WnMtxwgrjIMbSIFqeRPEIJfZ5n3buQtOsj1rOv7l/NI7/PU0kvyUhbHdvfFGw7J0Hxot crn2iBloOleGL1mM/NmUa5C2hTSwy2n63rCfJYbFJXvW1ni9/tHj2nLU+qH/cF1726d1 OUMg== X-Gm-Message-State: AOAM5308aXlIKs5Ps/AfrYs/r4y/XDnHo/iyGEb7E0mjAtUD/VPOR0Y1 vEjuMPKc4yHxwky9b70ezWZSEKCTKk9z+g== X-Google-Smtp-Source: ABdhPJyrC4ihuWcdBXJpXDuT6OkwrcTwYcGCo2gh0XIVi1y3Vp971ztWvwZFuNu0dkpEjYZA7dI21A== X-Received: by 2002:a62:7803:0:b0:494:64ef:7bd7 with SMTP id t3-20020a627803000000b0049464ef7bd7mr7235199pfc.85.1637694500905; Tue, 23 Nov 2021 11:08:20 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cc8f:f5a6:5a9f:7275]) by smtp.gmail.com with ESMTPSA id t4sm14550916pfq.163.2021.11.23.11.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 11:08:20 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 24 Nov 2021 04:08:10 +0900 Message-Id: <20211123190812.69805-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123190812.69805-1-hiroh@chromium.org> References: <20211123190812.69805-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 Tue Nov 23 19:08:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14729 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 7AFC2C324F for ; Tue, 23 Nov 2021 19:08:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3329360394; Tue, 23 Nov 2021 20:08:26 +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="HmclwGJc"; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E1A3B60394 for ; Tue, 23 Nov 2021 20:08:24 +0100 (CET) Received: by mail-pg1-x52b.google.com with SMTP id f65so24311pgc.0 for ; Tue, 23 Nov 2021 11:08:24 -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=vn/9bqGZ6VDlOVOvMtRWyeDLjxJmAjik0KpfoKdAx+0=; b=HmclwGJcmv712h1c3jaeJ70/U9b567+OKqbZ9AtrN1V3P/hKeclK6kr3fySKR3O4y2 OdFinW3zSTypDLZR0gHASetceJyFLZ5DMsMgCy0SBwhOXPzt+J+BSIgI8fFpqrndhSip uYL+/55x03WLe8iS2GuUc3B1c1HWMlJjWVVng= 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=vn/9bqGZ6VDlOVOvMtRWyeDLjxJmAjik0KpfoKdAx+0=; b=o/9+gphLMEVVg3OjsksvcHWBb3sMkICQkNNFrL+TlH++0LoG8iiRObHqtrTwIDVlP6 2Vn+OeaHyH4/PQ+ckxwdilKf0h+QV2gZmdlOQs1PQ+CFo9BfB6GqrxSZ2E7DqDBYE3PC 4zG9VX8IaBlxIrOKjmQmj13BWqw2JgzaDdnElUpUll14CMTK63ZdCo1yj71Ud7hH++W0 K3Q4HVmdVHgnvX+Pdl0LySLvJogvEOS0osCrO8EbaZLLFLFvMOzc5HHLOjmiyQ+49v0l g0twnPEJvK6BmhUmUFMJ0uIEvzhDasqUejE3ByJAwDK8ClhGybt247o+nenqtsZ+E2o/ AAEg== X-Gm-Message-State: AOAM530ZR+dG9T0yZMV1R0agse6wpUD/NwbZ9OW3wIdfyRRC4wGV8pZT +QDr0ZmtdH9VyJkef3lPIKUd8b+a2uMcKQ== X-Google-Smtp-Source: ABdhPJz/h1KZs2I2uEIbOyDcdHsP57ztqFfzQSwS+pTHxjYECFE3hq/shf15N8MRuYv6g8RnWernMw== X-Received: by 2002:aa7:950f:0:b0:4a2:54da:3a73 with SMTP id b15-20020aa7950f000000b004a254da3a73mr7360830pfp.18.1637694502858; Tue, 23 Nov 2021 11:08:22 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cc8f:f5a6:5a9f:7275]) by smtp.gmail.com with ESMTPSA id t4sm14550916pfq.163.2021.11.23.11.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 11:08:22 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 24 Nov 2021 04:08:11 +0900 Message-Id: <20211123190812.69805-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123190812.69805-1-hiroh@chromium.org> References: <20211123190812.69805-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 | 7 +++ src/libcamera/camera_sensor.cpp | 60 +++++++++++++++++++--- src/libcamera/control_ids.yaml | 5 ++ 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index edef2220..f355f323 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; @@ -82,6 +86,8 @@ private: std::unique_ptr subdev_; unsigned int pad_; + const CameraSensorProperties *staticProps_; + std::string model_; std::string id_; @@ -89,6 +95,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..e1293980 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,14 +302,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 +317,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 +541,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 Tue Nov 23 19:08:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14730 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 DF52EBF415 for ; Tue, 23 Nov 2021 19:08:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9C5CE60230; Tue, 23 Nov 2021 20:08: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="e5s5yaVj"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B4C0D60121 for ; Tue, 23 Nov 2021 20:08:26 +0100 (CET) Received: by mail-pj1-x102b.google.com with SMTP id w33-20020a17090a6ba400b001a722a06212so2732491pjj.0 for ; Tue, 23 Nov 2021 11:08: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=NAGwrqk/6sxLdYfulrdkK4538cN3U1ACtQJMMm76BKM=; b=e5s5yaVjR9BQNRCsVz09r1DbU5cvZekHsVSCFnhvZjHC+Vq1zUUed0zHkg+qOeJ9DK drlG1Owch40bodxIl9haPKUrYrz7Oycioh+oeKAyodHw7DtNbdpAcsYuHhHiUXVOGzQb 4BuipZ/8CASQJNAc9GV4pK9+wCQ4HluNKk2bQ= 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=NAGwrqk/6sxLdYfulrdkK4538cN3U1ACtQJMMm76BKM=; b=JTM9AcJqODMBRiZK0fzO3lyL5a+U5iLMcOtQglKiCpX1kTzW/kSp7B/720GdmmSUmP /UiyAFMlZxGYMY+C98iI+qAJMJOYgJV0oRaQV1ePasXG3f5MPF7uHYpf0rcv/cdSC2XP G2zaxaaQZIVtycv+1cqSUl05PrDSfFkgN9uIqMDxDxxSK5k1Fv5jrWb5QUwjh6F39B71 xOg3B62KSCscq7hQ/XT+I4Za1aAWQLoKc+/Z1oxO+7rMbc62H8DVbMJ4HCrrXaS1xmQq S/egwRHhG0DCNUeCbdoLBaVYSeu0+4MCxJBNW63C5kGcOzYDylsV9mo9unTYWeDp8ApX fsIQ== X-Gm-Message-State: AOAM530kp7UUa88OggUb4F031dtBtNGGcD/4//8bS7hJiNLKab08UzpU sBKLjSEOA8x0tYX8f3BKkzdEkD01QvstFA== X-Google-Smtp-Source: ABdhPJy+F6U8LOZ5fyoSWUYJWXwY3XRbNd8zsHrmOZGNAVLTOADW1SVpfO92IobzRiUTFGND9w7Uxw== X-Received: by 2002:a17:90b:30c4:: with SMTP id hi4mr5981503pjb.12.1637694504636; Tue, 23 Nov 2021 11:08:24 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cc8f:f5a6:5a9f:7275]) by smtp.gmail.com with ESMTPSA id t4sm14550916pfq.163.2021.11.23.11.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 11:08:24 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 24 Nov 2021 04:08:12 +0900 Message-Id: <20211123190812.69805-4-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123190812.69805-1-hiroh@chromium.org> References: <20211123190812.69805-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 enables ipu3 pipeline handler to apply a test pattern mode per frame. Signed-off-by: Hirokazu Honda Reviewed-by: Jean-Michel Hautbois Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 45 ++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 25490dcf..a15c6466 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_; @@ -803,6 +807,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(); @@ -823,6 +828,8 @@ void IPU3CameraData::cancelPendingRequests() pipe()->completeRequest(request); pendingRequests_.pop(); } + + processingRequests_ = {}; } void IPU3CameraData::queuePendingRequests() @@ -853,6 +860,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 +1130,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 +1423,38 @@ 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(); + + /* 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(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; + } else { + request->metadata().set(controls::draft::TestPatternMode, + testPatternMode); + } + } + } + + /* Controls that don't affect immediately are applied in delayedCtrls. */ + delayedCtrls_->applyControls(sequence); +} + REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3) } /* namespace libcamera */