From patchwork Wed Mar 17 10:02:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11599 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 C5B7BBD80C for ; Wed, 17 Mar 2021 10:02:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C4A2368D63; Wed, 17 Mar 2021 11:02:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Mz7apkiw"; dkim-atps=neutral Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B35C16084D for ; Wed, 17 Mar 2021 11:02:19 +0100 (CET) Received: by mail-ed1-x536.google.com with SMTP id w18so1525227edc.0 for ; Wed, 17 Mar 2021 03:02:19 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=WKPDbQVEm77UntYvf9XLAzDmJH8wdZX3/OhhnGXC8so=; b=Mz7apkiw9wYt23K3kNuFupiDK58T+2K0TiO020iQXLo9nixxBqc5nB5ngsx4QEws1o URLu8iAmOZcU+wIMdNxYXXBGk6MuaXiEQ/3OaWYmXnb9mY48hQo7acuXmCv/cZcGiSeJ TZcOLn2Od8DheUd+rbqdtfwMEUsCxig83qoVzKDMvh0GnUSrYyqtTIftMuXvvv8QJIUq jvo2dZp67yn0bizbUQgHaqiE2y7c6TOdSBB7RLOOzaSDyGAxJzksUesvWUF2FTJ/kTvi RluGbA3if8qObX9ApwyJ3TiuYP9MWJrNDOFlP9hCuYFwMVKmr8qDVZYvDavEXsmV0rLk yJkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WKPDbQVEm77UntYvf9XLAzDmJH8wdZX3/OhhnGXC8so=; b=JxTWEvulNgbDZD10JpYp7E34h3rscEcKwfCObjBaUMaU30n/1BrcMTwXFsim4g1ULa 1uWHkt0oQNhNjbxH2O7K+r0n5fdswL452vP/U+V/+45XAdKK2FAyU0OQ9OEF5s4qgrwj E3wIcc5/8ODN6eRJCmooMK+n4DJAWUQaQGUorQj/pOhs4I8tjRc4S0VRjmAb5jmHrmYT FyJRnn67UzsO4UUKu5OIQUQVV4JyzNHyFsL9ZCkcv53f7R+qfdIt2q0thpHtFiMx6R3g 6inoYcwKd7wAt3s3VuUgJkGyF6LIWv068snOlXMRLKtAz8L+ovaIOQepWmC07Gp8oX1t poxQ== X-Gm-Message-State: AOAM53330ZnqHGjDq2PV9fCn/xx70VM5AHHV9Z1l3Uqnr+fpmNJ2rFA0 /0DhG20iSKHkj7iNVITPjCL7vuVr8kJwWw== X-Google-Smtp-Source: ABdhPJzvOUXl2eceQhWTm8kdwmH075WT9v/znUJitKvM4mRv4yZTKQIX4b2k55hUb/SRFnZtcSocMw== X-Received: by 2002:a05:6402:6cb:: with SMTP id n11mr41677975edy.198.1615975338727; Wed, 17 Mar 2021 03:02:18 -0700 (PDT) Received: from naush-laptop.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id p24sm12061179edt.5.2021.03.17.03.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 03:02:18 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 17 Mar 2021 10:02:06 +0000 Message-Id: <20210317100211.1067585-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210317100211.1067585-1-naush@raspberrypi.com> References: <20210317100211.1067585-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/7] pipeline: ipa: raspberrypi: Open the CamHelper on ipa::init() 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" Move the opening of the CamHelper from ipa::configure() to ipa::init(). This allows the pipeline handler to get the sensor specific parameters in in pipeline_handler::match() where the ipa is initialised. Having the sensor parameters available earlier will allow selective use of the embedded data node in a future change. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- include/libcamera/ipa/raspberrypi.mojom | 7 +-- src/ipa/raspberrypi/raspberrypi.cpp | 60 +++++++++---------- .../pipeline/raspberrypi/raspberrypi.cpp | 36 ++++++----- 3 files changed, 46 insertions(+), 57 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index eb427697d349..a713c88eee19 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -15,10 +15,6 @@ enum BufferMask { /* Size of the LS grid allocation. */ const uint32 MaxLsGridSize = 0x8000; -enum ConfigOutputParameters { - ConfigSensorParams = 0x01, -}; - struct SensorConfig { uint32 gainDelay; uint32 exposureDelay; @@ -41,7 +37,6 @@ struct ConfigInput { struct ConfigOutput { uint32 params; - SensorConfig sensorConfig; ControlList controls; }; @@ -51,7 +46,7 @@ struct StartControls { }; interface IPARPiInterface { - init(IPASettings settings) => (int32 ret); + init(IPASettings settings) => (int32 ret, SensorConfig sensorConfig); start(StartControls controls) => (StartControls result); stop(); diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 7904225a29fa..8a9eb92b39ec 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -79,7 +79,7 @@ public: munmap(lsTable_, ipa::RPi::MaxLsGridSize); } - int init(const IPASettings &settings) override; + int init(const IPASettings &settings, ipa::RPi::SensorConfig *sensorConfig) override; void start(const ipa::RPi::StartControls &data, ipa::RPi::StartControls *result) override; void stop() override {} @@ -164,9 +164,35 @@ private: double maxFrameDuration_; }; -int IPARPi::init(const IPASettings &settings) +int IPARPi::init(const IPASettings &settings, ipa::RPi::SensorConfig *sensorConfig) { tuningFile_ = settings.configurationFile; + + /* + * Load the "helper" for this sensor. This tells us all the device specific stuff + * that the kernel driver doesn't. We only do this the first time; we don't need + * to re-parse the metadata after a simple mode-switch for no reason. + */ + helper_ = std::unique_ptr(RPiController::CamHelper::Create(settings.sensorModel)); + if (!helper_) { + LOG(IPARPI, Error) << "Could not create camera helper for " + << settings.sensorModel; + return -EINVAL; + } + + /* + * Pass out the sensor config to the pipeline handler in order + * to setup the staggered writer class. + */ + int gainDelay, exposureDelay, vblankDelay, sensorMetadata; + helper_->GetDelays(exposureDelay, gainDelay, vblankDelay); + sensorMetadata = helper_->SensorEmbeddedDataPresent(); + + sensorConfig->gainDelay = gainDelay; + sensorConfig->exposureDelay = exposureDelay; + sensorConfig->vblankDelay = vblankDelay; + sensorConfig->sensorMetadata = sensorMetadata; + return 0; } @@ -319,36 +345,6 @@ int IPARPi::configure(const CameraSensorInfo &sensorInfo, /* Setup a metadata ControlList to output metadata. */ libcameraMetadata_ = ControlList(controls::controls); - /* - * Load the "helper" for this sensor. This tells us all the device specific stuff - * that the kernel driver doesn't. We only do this the first time; we don't need - * to re-parse the metadata after a simple mode-switch for no reason. - */ - std::string cameraName(sensorInfo.model); - if (!helper_) { - helper_ = std::unique_ptr(RPiController::CamHelper::Create(cameraName)); - - if (!helper_) { - LOG(IPARPI, Error) << "Could not create camera helper for " - << cameraName; - return -1; - } - - /* - * Pass out the sensor config to the pipeline handler in order - * to setup the staggered writer class. - */ - int gainDelay, exposureDelay, vblankDelay, sensorMetadata; - helper_->GetDelays(exposureDelay, gainDelay, vblankDelay); - sensorMetadata = helper_->SensorEmbeddedDataPresent(); - - result->params |= ipa::RPi::ConfigSensorParams; - result->sensorConfig.gainDelay = gainDelay; - result->sensorConfig.exposureDelay = exposureDelay; - result->sensorConfig.vblankDelay = vblankDelay; - result->sensorConfig.sensorMetadata = sensorMetadata; - } - /* Re-assemble camera mode using the sensor info. */ setMode(sensorInfo); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 2c8ae31a28ad..ce1994186d66 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -146,7 +146,7 @@ public: void frameStarted(uint32_t sequence); - int loadIPA(); + int loadIPA(ipa::RPi::SensorConfig *sensorConfig); int configureIPA(const CameraConfiguration *config); void statsMetadataComplete(uint32_t bufferId, const ControlList &controls); @@ -1030,11 +1030,24 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) if (data->sensor_->init()) return false; - if (data->loadIPA()) { + ipa::RPi::SensorConfig sensorConfig; + if (data->loadIPA(&sensorConfig)) { LOG(RPI, Error) << "Failed to load a suitable IPA library"; return false; } + /* + * Setup our delayed control writer with the sensor default + * gain and exposure delays. Mark VBLANK for priority write. + */ + std::unordered_map params = { + { V4L2_CID_ANALOGUE_GAIN, { sensorConfig.gainDelay, false } }, + { V4L2_CID_EXPOSURE, { sensorConfig.exposureDelay, false } }, + { V4L2_CID_VBLANK, { sensorConfig.vblankDelay, true } } + }; + data->delayedCtrls_ = std::make_unique(data->unicam_[Unicam::Image].dev(), params); + data->sensorMetadata_ = sensorConfig.sensorMetadata; + /* Register the controls that the Raspberry Pi IPA can handle. */ data->controlInfo_ = RPi::Controls; /* Initialize the camera properties. */ @@ -1214,7 +1227,7 @@ void RPiCameraData::frameStarted(uint32_t sequence) delayedCtrls_->applyControls(sequence); } -int RPiCameraData::loadIPA() +int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig) { ipa_ = IPAManager::createIPA(pipe_, 1, 1); @@ -1230,7 +1243,7 @@ int RPiCameraData::loadIPA() IPASettings settings(ipa_->configurationFile(sensor_->model() + ".json"), sensor_->model()); - return ipa_->init(settings); + return ipa_->init(settings, sensorConfig); } int RPiCameraData::configureIPA(const CameraConfiguration *config) @@ -1293,21 +1306,6 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) return -EPIPE; } - if (result.params & ipa::RPi::ConfigSensorParams) { - /* - * Setup our delayed control writer with the sensor default - * gain and exposure delays. Mark VBLANK for priority write. - */ - std::unordered_map params = { - { V4L2_CID_ANALOGUE_GAIN, { result.sensorConfig.gainDelay, false } }, - { V4L2_CID_EXPOSURE, { result.sensorConfig.exposureDelay, false } }, - { V4L2_CID_VBLANK, { result.sensorConfig.vblankDelay, true } } - }; - - delayedCtrls_ = std::make_unique(unicam_[Unicam::Image].dev(), params); - sensorMetadata_ = result.sensorConfig.sensorMetadata; - } - if (!result.controls.empty()) { ControlList &ctrls = result.controls; unicam_[Unicam::Image].dev()->setControls(&ctrls);