From patchwork Thu Jun 9 12:58:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16188 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 50D90BD161 for ; Thu, 9 Jun 2022 12:58:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6DFE265631; Thu, 9 Jun 2022 14:58:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1654779516; bh=wxaScBZBf9fu7sZWB18jutT4pDoDMJnabsrdCwiMBzY=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=T0FK33fu8skvfMHM5sv2N7JFxLX+4KJ5a0Kov9r/7JRADik2G1wdsLYJkML5irmWn HYdpMrDys8FcEyoZMcOKzkImVYDgjL9GXBXRCfpwrIWNxgwb4b9DFubpgqRONtQFKq bVb8RQ5DWqhn27hos241eFyo+lYkbyuwOWUph2OjDKQYq8eTAV2BRVOt0IY4ugz0fn 5SlpQ5A3mwxOuxQ55esdXPHUuzAKpxZlHpueDquoDZl6JSyd2X+ao8hrYqhSJR77in 5fjqO/R2uvHPPmoy6X2390qXPOeeVWl/l4UWlgdvILp+J1YhssLudSVuVwzK49zkVn 43zip5ib5dyIg== Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B31516559A for ; Thu, 9 Jun 2022 14:58:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZGbDNTVN"; dkim-atps=neutral Received: by mail-wr1-x42d.google.com with SMTP id x17so32310915wrg.6 for ; Thu, 09 Jun 2022 05:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ok9ouy0Sf8uhWyfQ6c0zvhxPDI8isGrPvBbpQ9sJMIs=; b=ZGbDNTVNEJ4dNeklz9VyJVEOa9ToymDhN+nA+LMGWmRjGzQ4h5R1UbBq/TwAvFQgGV hodQSzgs7FGDQhEiWeICLk/SSt6UWtIb5zrruH1DKOKIW1zg6adbmsCtSE+tJQXEQBsJ 106JM3cNCEkJ4ce090Qy3B2YS65MyAbJ/NbqfuY6PctObHmuyS0N8JEY6kOHDWuRlfmd qNdSEfpkAyYJt7sIEQhVvmIitRqa5d5GDVKHwPOLrCUOWMcaH/b06uetrhZ1UjDCeHd1 yA/RKQtNsPfLGSs6vZolpJuZF/VLqTcS/jkS7iP3eg6SRAnZ0YTgUTYz+SqD4YSmZh2I EkkA== 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=Ok9ouy0Sf8uhWyfQ6c0zvhxPDI8isGrPvBbpQ9sJMIs=; b=7qoJzjr+umZR0lqrMuE4xT+tXKic7D7hhf3p669Av6Lj32ZRbyUENLIMpRp4D7djvp /t0sC0D07Vg2deTDBzDGgKEqNTwRKsE1/HHVIPs5I+kkIYEegYZRq2hP35BkjDHiVOBZ BX9YvDQEuSeDC202TR9qMLFlCzm/YFJZA3aV+qyH13IJcVhb4/q55/KBnR6RN30ovuLN XfQeO9PsCW2DXM7aUqhOzRfeWQGHA65JbzUie313VrMloVdzLq/C3qe1gfFRCT55jqcu YWw9WDorYE0UMv3WIwsaY6E77+bzAPeqbWnfgQoDzUkhxJ9VKhJzX+B87biOnYCanaXD UJIA== X-Gm-Message-State: AOAM531E25EaCbdB8dSkeqpa133jpOizyOjYDjT5UbmM1DjrY87amfis DR9Pq0N0vpt4pin/BBx98TU5zN8wuXXD4ePc X-Google-Smtp-Source: ABdhPJxiMK7kfxE7bH69nKi5fKQNs/vOMpFoFN+/TRtecpEM5MKjajN23SlJopOfczQkG9e7HjTKVg== X-Received: by 2002:a5d:598c:0:b0:218:3fe6:40bd with SMTP id n12-20020a5d598c000000b002183fe640bdmr20853636wri.373.1654779513834; Thu, 09 Jun 2022 05:58:33 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id i13-20020a05600c354d00b0039c60e33702sm6826395wmq.16.2022.06.09.05.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jun 2022 05:58:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 9 Jun 2022 13:58:30 +0100 Message-Id: <20220609125830.4325-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] pipeline: ipa: raspberrypi: Correctly report available controls 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The pipeline handler currently advertises a static ControlInfoMap to specify the available controls and their limits. Fix this limitation by having the IPA populate a ControlInfoMap during Camera::Configure() that is then returned from the pipeline handle. This will allow the ExposureTime, AnalogueGain, and FrameDurationLimits controls to advertise the correct limits for the programmed mode. Note that with this change, the ControlInfoMap provided by Camera::Controls() is only valid after a successful Camera::Configure() call. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- include/libcamera/ipa/raspberrypi.h | 55 ------------------- include/libcamera/ipa/raspberrypi.mojom | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 42 +++++++++++++- .../pipeline/raspberrypi/raspberrypi.cpp | 6 +- .../pipeline/raspberrypi/rpi_stream.h | 1 - 5 files changed, 45 insertions(+), 60 deletions(-) delete mode 100644 include/libcamera/ipa/raspberrypi.h diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h deleted file mode 100644 index 6a56b0083b85..000000000000 --- a/include/libcamera/ipa/raspberrypi.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019-2020, Raspberry Pi Ltd. - * - * raspberrypi.h - Image Processing Algorithm interface for Raspberry Pi - */ - -#pragma once - -#include - -#include -#include - -#ifndef __DOXYGEN__ - -namespace libcamera { - -namespace RPi { - -/* - * List of controls handled by the Raspberry Pi IPA - * - * \todo This list will need to be built dynamically from the control - * algorithms loaded by the json file, once this is supported. At that - * point applications should check first whether a control is supported, - * and the pipeline handler may be reverted so that it aborts when an - * unsupported control is encountered. - */ -static const ControlInfoMap Controls({ - { &controls::AeEnable, ControlInfo(false, true) }, - { &controls::ExposureTime, ControlInfo(0, 999999) }, - { &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) }, - { &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) }, - { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) }, - { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) }, - { &controls::ExposureValue, ControlInfo(-8.0f, 8.0f, 0.0f) }, - { &controls::AwbEnable, ControlInfo(false, true) }, - { &controls::ColourGains, ControlInfo(0.0f, 32.0f) }, - { &controls::AwbMode, ControlInfo(controls::AwbModeValues) }, - { &controls::Brightness, ControlInfo(-1.0f, 1.0f, 0.0f) }, - { &controls::Contrast, ControlInfo(0.0f, 32.0f, 1.0f) }, - { &controls::Saturation, ControlInfo(0.0f, 32.0f, 1.0f) }, - { &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) }, - { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) }, - { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, - { &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, - { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) } - }, controls::controls); - -} /* namespace RPi */ - -} /* namespace libcamera */ - -#endif /* __DOXYGEN__ */ diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index a60c3bb43d3c..ed7adebce1b8 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -40,6 +40,7 @@ struct IPAConfig { struct IPAConfigResult { float modeSensitivity; + libcamera.ControlInfoMap controlInfo; }; struct StartConfig { diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 3b126bb5175e..7eb04a24c41e 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -72,6 +71,28 @@ constexpr Duration defaultMaxFrameDuration = 250.0s; */ constexpr Duration controllerMinFrameDuration = 1.0s / 30.0; +/* List of controls handled by the Raspberry Pi IPA */ +static const ControlInfoMap Controls({ + { &controls::AeEnable, ControlInfo(false, true) }, + { &controls::ExposureTime, ControlInfo(0, 999999) }, + { &controls::AnalogueGain, ControlInfo(1.0f, 32.0f) }, + { &controls::AeMeteringMode, ControlInfo(controls::AeMeteringModeValues) }, + { &controls::AeConstraintMode, ControlInfo(controls::AeConstraintModeValues) }, + { &controls::AeExposureMode, ControlInfo(controls::AeExposureModeValues) }, + { &controls::ExposureValue, ControlInfo(-8.0f, 8.0f, 0.0f) }, + { &controls::AwbEnable, ControlInfo(false, true) }, + { &controls::ColourGains, ControlInfo(0.0f, 32.0f) }, + { &controls::AwbMode, ControlInfo(controls::AwbModeValues) }, + { &controls::Brightness, ControlInfo(-1.0f, 1.0f, 0.0f) }, + { &controls::Contrast, ControlInfo(0.0f, 32.0f, 1.0f) }, + { &controls::Saturation, ControlInfo(0.0f, 32.0f, 1.0f) }, + { &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) }, + { &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) }, + { &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) }, + { &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) }, + { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) } +}, controls::controls); + LOG_DEFINE_CATEGORY(IPARPI) namespace ipa::RPi { @@ -421,6 +442,25 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, ASSERT(controls); *controls = std::move(ctrls); + /* + * Apply the correct limits to the exposure, gain and frame duration controls + * based on the current sensor mode. + */ + result->controlInfo = Controls; + const Duration minSensorFrameDuration = mode_.min_frame_length * mode_.line_length; + const Duration maxSensorFrameDuration = mode_.max_frame_length * mode_.line_length; + result->controlInfo.at(controls::FrameDurationLimits.id()) = + ControlInfo(static_cast(minSensorFrameDuration.get()), + static_cast(maxSensorFrameDuration.get())); + + result->controlInfo.at(controls::AnalogueGain.id()) = + ControlInfo(1.0f, static_cast(helper_->Gain(maxSensorGainCode_))); + + const uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get(); + const uint32_t exposureMax = sensorCtrls_.at(V4L2_CID_EXPOSURE).max().get(); + result->controlInfo.at(controls::ExposureTime.id()) = + ControlInfo(static_cast(helper_->Exposure(exposureMin).get()), + static_cast(helper_->Exposure(exposureMax).get())); return 0; } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index adc397e8aabd..abb29a8d24b9 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -941,6 +940,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) /* Store the mode sensitivity for the application. */ data->properties_.set(properties::SensorSensitivity, result.modeSensitivity); + /* Register the controls that the Raspberry Pi IPA can handle. */ + data->controlInfo_ = result.controlInfo; + /* Setup the Video Mux/Bridge entities. */ for (auto &[device, link] : data->bridgeDevices_) { /* @@ -1282,8 +1284,6 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me data->delayedCtrls_ = std::make_unique(data->sensor_->device(), params); data->sensorMetadata_ = sensorConfig.sensorMetadata; - /* Register the controls that the Raspberry Pi IPA can handle. */ - data->controlInfo_ = RPi::Controls; /* Initialize the camera properties. */ data->properties_ = data->sensor_->properties(); diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.h b/src/libcamera/pipeline/raspberrypi/rpi_stream.h index c37f7e82eef6..fe01110019b7 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.h +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.h @@ -12,7 +12,6 @@ #include #include -#include #include #include