From patchwork Tue Nov 2 02:55:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14447 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 023CFBF415 for ; Tue, 2 Nov 2021 02:55:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 69B7060325; Tue, 2 Nov 2021 03:55:32 +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="SRmuC+bm"; 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 F3D0560122 for ; Tue, 2 Nov 2021 03:55:30 +0100 (CET) Received: by mail-pg1-x52c.google.com with SMTP id g184so18855105pgc.6 for ; Mon, 01 Nov 2021 19:55:30 -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:mime-version :content-transfer-encoding; bh=bR2E/rRUz9GO/O8iAKRnCbBmN61briK7K/2FP8sHj/o=; b=SRmuC+bm5ucUSDwbpZRSyadlcG6bIen/FVZt8Zl5GboKrup0i6E+C576yAbxe5rBJl rYARX9NH++AVXPuR26kbgrzMRrlyMXzOZuocDlPkGXldnLX1+sTfOMBwXub/YYEvkVvB vTzmfL5BarsNKxl5hjVcEY17QGauhJDr6nj30= 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=bR2E/rRUz9GO/O8iAKRnCbBmN61briK7K/2FP8sHj/o=; b=fKfQSRc+NHoKaF8KL7qz0J0ccAOiwJvkTwIqlksKH4u4s7SH02Gj0E+rutj7VSOyJq Brod3c/iRPgwVP/wRJuU+6xabpwyg2MnjnhQ49O91p39/CQH8Mz+AGfkF9xgTWFczCqo RNpHB6OhrDejP08PCc/+QxJ8ygFZbtdbKRKQTtXAydq4ODKMICI9gd82gIBd5giAm6Yj VZRa1D4zAD9e8pJQ0Tgkm32z7XdiHAUdrHDub3nwYwpAWqcwXL4vZuf32a0274T+++2G qoqtW6mGgFZrmHLEY8hrPwkp7zGGlRncG5Feypvr9wv7x2kWdhVWDqfbvDscn8oOJL5d go4A== X-Gm-Message-State: AOAM5335eUo/UDzfzTU+jxx1hosh5uWFb+YwnJtARj0EWv8eJ/x1Qk+p JzheKGiABsVuDDNBZbkTj6rz1BL7FJ+b4w== X-Google-Smtp-Source: ABdhPJz7IZCY5EQQeFhvaw697KaAYCMc7SQf+tqP8zbJFLZ4YDSzXTO4TjWebhwTwVAORHov+PywdQ== X-Received: by 2002:a05:6a00:a8e:b0:480:ab08:1568 with SMTP id b14-20020a056a000a8e00b00480ab081568mr18057296pfl.28.1635821728597; Mon, 01 Nov 2021 19:55:28 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:da96:7796:6eb0:5a01]) by smtp.gmail.com with ESMTPSA id n15sm3589677pfv.216.2021.11.01.19.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 19:55:28 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Nov 2021 11:55:21 +0900 Message-Id: <20211102025522.735085-1-hiroh@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/2] 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 | 6 +++ src/libcamera/camera_sensor.cpp | 50 +++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index d25a1165..d08cfec5 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -26,6 +26,8 @@ namespace libcamera { class BayerFormat; class MediaEntity; +struct CameraSensorProperties; + class CameraSensor : protected Loggable { public: @@ -44,6 +46,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(int32_t testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -78,6 +81,8 @@ private: std::unique_ptr subdev_; unsigned int pad_; + const CameraSensorProperties *props_; + std::string model_; std::string id_; @@ -85,6 +90,7 @@ private: std::vector mbusCodes_; std::vector sizes_; std::vector testPatternModes_; + int32_t testPatternMode_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..4770f52e 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), testPatternMode_(-1), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -300,14 +300,16 @@ void CameraSensor::initVimcDefaultProperties() void CameraSensor::initStaticProperties() { - const CameraSensorProperties *props = CameraSensorProperties::get(model_); - if (!props) + props_ = CameraSensorProperties::get(model_); + if (!props_) { + LOG(CameraSensor, Debug) << "No properties for " << model_; return; + } /* Register the properties retrieved from the sensor database. */ - properties_.set(properties::UnitCellSize, props->unitCellSize); + properties_.set(properties::UnitCellSize, props_->unitCellSize); - initTestPatternModes(props->testPatternModes); + initTestPatternModes(props_->testPatternModes); } void CameraSensor::initTestPatternModes( @@ -531,6 +533,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(int32_t testPatternMode) +{ + if (testPatternMode_ == testPatternMode) + return 0; + + if (!props_) { + LOG(CameraSensor, Error) << "No properties are found"; + return -EINVAL; + } + + auto it = props_->testPatternModes.find(testPatternMode); + if (it == props_->testPatternModes.end()) { + LOG(CameraSensor, Error) << "Unsupported test pattern mode " + << testPatternMode; + return -EINVAL; + } + + ControlList ctrls{ controls() }; + ctrls.set(V4L2_CID_TEST_PATTERN, it->second); + + 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 Tue Nov 2 02:55:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14448 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 1AE91C324E for ; Tue, 2 Nov 2021 02:55:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 294C360159; Tue, 2 Nov 2021 03:55:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Q5AJ93KS"; dkim-atps=neutral Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C2C860128 for ; Tue, 2 Nov 2021 03:55:32 +0100 (CET) Received: by mail-pf1-x436.google.com with SMTP id g11so6808868pfv.7 for ; Mon, 01 Nov 2021 19:55:31 -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=AyPVF5b+teiJdYnh1nhGdlslz3kzCEfGpuvgiTubbJ8=; b=Q5AJ93KSRO5jm4jYjCfQcQdv6R91Pvv1lCZogXXdtNWh8xEIb1DWLrN0k7ZrIFClZ5 edJrWq0QYhmd3hcxa9HBq1qocWFqaO8hbk6ZFT0ZPG8ZZF9cROIW8SALH+CuQRSU2a9Z KORej+9YYyQXG12JZ1PcZwFrb7lcz9Mpj9gRk= 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=AyPVF5b+teiJdYnh1nhGdlslz3kzCEfGpuvgiTubbJ8=; b=vg7Vjd4aNVicekv59Q+EhYc2jUKZPTYCI6nIahNGKbmVJ3A6587d81lcF5RprYQpiL e0tdl995Ie/UR15N7lyH2qhQgPXGw9qNj4mN4R1F/aGCEbD+8ZjPkHzTgV8GMtrf8aKQ +2Q1VmmU/hFxmFkMAZk2OVU11XD+UOlrC1l9ifvyuQRv+/JJNupgJKCcywWZWtz0fK8X i0/q8tDAm0jKfBarvrLFesruKZXZpXtM/LN1daLXjZ+HE8hshBBPfRU4vVa7sm6fcJ79 Njja/5kyfV+3dfjM/h8mjHPb1VNVItt2yoL2DZt73i5yNWVJcPjQ4SsGT9PLZaZoNsrp gygg== X-Gm-Message-State: AOAM532S9mb/aidocNB5aWWezUItKfT8npfb+bubNw1XUA+Q7/VoU/CT DwAvRKkOkl05tKDtf0pVwLyAFEKwRrV1pA== X-Google-Smtp-Source: ABdhPJxzvJscO+/wH0bAzp6Hd03+W0oZdIpy6yshMmma0VoLt/eO2ydvJIBzALnYb5gTjbFToVjO0A== X-Received: by 2002:aa7:8213:0:b0:47b:fc35:db26 with SMTP id k19-20020aa78213000000b0047bfc35db26mr33459092pfi.1.1635821730318; Mon, 01 Nov 2021 19:55:30 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:da96:7796:6eb0:5a01]) by smtp.gmail.com with ESMTPSA id n15sm3589677pfv.216.2021.11.01.19.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 19:55:29 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Nov 2021 11:55:22 +0900 Message-Id: <20211102025522.735085-2-hiroh@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211102025522.735085-1-hiroh@chromium.org> References: <20211102025522.735085-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/2] 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 | 41 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index eb714aa6..e81ba63c 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; @@ -1130,8 +1138,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; @@ -1422,6 +1430,35 @@ 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(); + + 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(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 */