From patchwork Wed Feb 17 08:02:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 11315 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 BDDD4BD1F6 for ; Wed, 17 Feb 2021 08:02:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1DABF637F1; Wed, 17 Feb 2021 09:02:49 +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="ezxwAvqB"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3F964602FA for ; Wed, 17 Feb 2021 09:02:47 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id n4so13346556wrx.1 for ; Wed, 17 Feb 2021 00:02:47 -0800 (PST) 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=VPn50grLwEyGeUbBP5c0hDHBCj9ikgPqmTyWMoqiTps=; b=ezxwAvqBV1+pZNJymZsQWsuHdrtVTxgBemv4BPqABej+0S6AHMymrdOEZwTiFc2K8O j22F+DCKqdZfkmIWFs/tCAABwqOg2i2HfpWkrZH8YFvO5kxwLGjV/XwqEvuujlZLkvgk 8bDeTC4uJXa1t+JeqC7BPhnwk1TxXff9wc1nj8vWfUUhsbms0LJ3brYgS7ZR2hroqYK9 d7PUnEIzeYjzYjN8c28wbToedTdf7eVCoVk1KGA6Z05dIinZnxy4cof4Lv//qOcQnuCH 5zifwPRl8dLBb75PUyk/Klw+TKGu9p2zpgYNrkj4C94oPXq5UT3qIa+BoLaWKAxYe7Dx LyTw== 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:mime-version :content-transfer-encoding; bh=VPn50grLwEyGeUbBP5c0hDHBCj9ikgPqmTyWMoqiTps=; b=a59UhpNeYTZxeWzu+lMHS4O/RPEPeGxNUVesSzT6+odVtwh9W/KpPdBLjETk/hK5fT z+XAs+aBjFB2s/VlZ8Xd5+DmUf+iM3/lFRM6eqV8GKKp4hJ8zx1m3AUmk8LvK6Wzj5ay BUxKxZvQVikjzioGLwOoIhTT4Y1popu/WO3kaLAdip5auGtEKVOmHoKxALmKmCoJ9kk0 QkMcRwBgB49qpDi7Suml0przBi+/B8vbNPLcH4FTHsX6ALimVPtwoMTyzO/BNvQxgq58 YBtacEZuWxzzH7sCjaPc3HYsMlOrf4ydwaVIK1JOFQOh/eM5fnu4YQcsY/Unu5LhcunZ hM6A== X-Gm-Message-State: AOAM533BctqIeihsbkfuOpa3kXQV7ZR6QRRGIdrYUCDauL/34ol0tXKL 0NRh6Z0xZbJlWM/Cj8qFfAxpB/gLcSW/obQc X-Google-Smtp-Source: ABdhPJzeamkzBJSIev/xEI45dfmUXsMA0W4JqpvV3OcefoySOEwJ9LNB3V0OzMKFvTthMrtuWsop+g== X-Received: by 2002:adf:97d3:: with SMTP id t19mr28985571wrb.164.1613548966236; Wed, 17 Feb 2021 00:02:46 -0800 (PST) Received: from naush-laptop.patuck.local ([88.97.76.4]) by smtp.gmail.com with ESMTPSA id q15sm2620045wrr.58.2021.02.17.00.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 00:02:45 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 17 Feb 2021 08:02:41 +0000 Message-Id: <20210217080241.1492143-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] pipeline: ipa: raspberrypi: Various fixups after IPAInterface changes 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 commit addresses a few fixes and tidy-ups after the IPAInterface rework: - Rename ConfigStaggeredWrite -> ConfigSensorParams - Rename setIsp -> setIspControls - Signal handlers statsMetadataComplete(), runISP(), embeddedComplete() should only run when state != Stopped. This matches the behavior of the original code. Without this, start/stop cycles may cause errors. - In setIspControls(), only update the LS config (with the fd) when a LS control is present. Signed-off-by: Naushir Patuck Fixes: e201cb4f5450 ("libcamera: IPAInterface: Replace C API with the new C++-only API") Reviewed-by: Paul Elder --- include/libcamera/ipa/raspberrypi.mojom | 4 +- src/ipa/raspberrypi/raspberrypi.cpp | 4 +- .../pipeline/raspberrypi/raspberrypi.cpp | 91 ++++++++++--------- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index bab19a946e18..8a256d022270 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -16,7 +16,7 @@ enum BufferMask { const uint32 MaxLsGridSize = 0x8000; enum ConfigOutputParameters { - ConfigStaggeredWrite = 0x01, + ConfigSensorParams = 0x01, }; struct SensorConfig { @@ -126,6 +126,6 @@ interface IPARPiEventInterface { statsMetadataComplete(uint32 bufferId, ControlList controls); runIsp(uint32 bufferId); embeddedComplete(uint32 bufferId); - setIsp(ControlList controls); + setIspControls(ControlList controls); setDelayedControls(ControlList controls); }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 81a3195c82e9..0bf88bcc5f72 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -344,7 +344,7 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo, helper_->GetDelays(exposureDelay, gainDelay); sensorMetadata = helper_->SensorEmbeddedDataPresent(); - result->params |= ipa::rpi::ConfigStaggeredWrite; + result->params |= ipa::rpi::ConfigSensorParams; result->sensorConfig.gainDelay = gainDelay; result->sensorConfig.exposureDelay = exposureDelay; result->sensorConfig.vblank = exposureDelay; @@ -968,7 +968,7 @@ void IPARPi::prepareISP(unsigned int bufferId) applyDPC(dpcStatus, ctrls); if (!ctrls.empty()) - setIsp.emit(ctrls); + setIspControls.emit(ctrls); } } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 15aa600ed581..d0ca015a01dc 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -152,7 +152,7 @@ public: void statsMetadataComplete(uint32_t bufferId, const ControlList &controls); void runIsp(uint32_t bufferId); void embeddedComplete(uint32_t bufferId); - void setIsp(const ControlList &controls); + void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls); /* bufferComplete signal handlers. */ @@ -1172,7 +1172,7 @@ int RPiCameraData::loadIPA() ipa_->statsMetadataComplete.connect(this, &RPiCameraData::statsMetadataComplete); ipa_->runIsp.connect(this, &RPiCameraData::runIsp); ipa_->embeddedComplete.connect(this, &RPiCameraData::embeddedComplete); - ipa_->setIsp.connect(this, &RPiCameraData::setIsp); + ipa_->setIspControls.connect(this, &RPiCameraData::setIspControls); ipa_->setDelayedControls.connect(this, &RPiCameraData::setDelayedControls); IPASettings settings(ipa_->configurationFile(sensor_->model() + ".json")); @@ -1241,7 +1241,7 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) return -EPIPE; } - if (result.params & ipa::rpi::ConfigStaggeredWrite) { + if (result.params & ipa::rpi::ConfigSensorParams) { /* * Setup our delayed control writer with the sensor default * gain and exposure delays. @@ -1280,75 +1280,76 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config) void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &controls) { - if (state_ == State::Stopped) - handleState(); + if (state_ != State::Stopped) { + FrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(bufferId); - FrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(bufferId); + handleStreamBuffer(buffer, &isp_[Isp::Stats]); - handleStreamBuffer(buffer, &isp_[Isp::Stats]); + /* Fill the Request metadata buffer with what the IPA has provided */ + Request *request = requestQueue_.front(); + request->metadata() = std::move(controls); - /* Fill the Request metadata buffer with what the IPA has provided */ - Request *request = requestQueue_.front(); - request->metadata() = std::move(controls); + /* + * Also update the ScalerCrop in the metadata with what we actually + * used. But we must first rescale that from ISP (camera mode) pixels + * back into sensor native pixels. + * + * Sending this information on every frame may be helpful. + */ + if (updateScalerCrop_) { + updateScalerCrop_ = false; + scalerCrop_ = ispCrop_.scaledBy(sensorInfo_.analogCrop.size(), + sensorInfo_.outputSize); + scalerCrop_.translateBy(sensorInfo_.analogCrop.topLeft()); + } + request->metadata().set(controls::ScalerCrop, scalerCrop_); - /* - * Also update the ScalerCrop in the metadata with what we actually - * used. But we must first rescale that from ISP (camera mode) pixels - * back into sensor native pixels. - * - * Sending this information on every frame may be helpful. - */ - if (updateScalerCrop_) { - updateScalerCrop_ = false; - scalerCrop_ = ispCrop_.scaledBy(sensorInfo_.analogCrop.size(), - sensorInfo_.outputSize); - scalerCrop_.translateBy(sensorInfo_.analogCrop.topLeft()); + state_ = State::IpaComplete; } - request->metadata().set(controls::ScalerCrop, scalerCrop_); - - state_ = State::IpaComplete; handleState(); } void RPiCameraData::runIsp(uint32_t bufferId) { - if (state_ == State::Stopped) - handleState(); + if (state_ != State::Stopped) { + FrameBuffer *buffer = unicam_[Unicam::Image].getBuffers().at(bufferId); - FrameBuffer *buffer = unicam_[Unicam::Image].getBuffers().at(bufferId); + LOG(RPI, Debug) << "Input re-queue to ISP, buffer id " << bufferId + << ", timestamp: " << buffer->metadata().timestamp; - LOG(RPI, Debug) << "Input re-queue to ISP, buffer id " << bufferId - << ", timestamp: " << buffer->metadata().timestamp; + isp_[Isp::Input].queueBuffer(buffer); + ispOutputCount_ = 0; + } - isp_[Isp::Input].queueBuffer(buffer); - ispOutputCount_ = 0; handleState(); } void RPiCameraData::embeddedComplete(uint32_t bufferId) { - if (state_ == State::Stopped) - handleState(); + if (state_ != State::Stopped) { + FrameBuffer *buffer = unicam_[Unicam::Embedded].getBuffers().at(bufferId); + handleStreamBuffer(buffer, &unicam_[Unicam::Embedded]); + } - FrameBuffer *buffer = unicam_[Unicam::Embedded].getBuffers().at(bufferId); - handleStreamBuffer(buffer, &unicam_[Unicam::Embedded]); handleState(); } -void RPiCameraData::setIsp(const ControlList &controls) +void RPiCameraData::setIspControls(const ControlList &controls) { ControlList ctrls = controls; - Span s = - ctrls.get(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING).data(); - bcm2835_isp_lens_shading ls = - *reinterpret_cast(s.data()); - ls.dmabuf = lsTable_.fd(); + if (ctrls.contains(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING)) { + Span s = + ctrls.get(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING).data(); + bcm2835_isp_lens_shading ls = + *reinterpret_cast(s.data()); + ls.dmabuf = lsTable_.fd(); - ControlValue c(Span{ reinterpret_cast(&ls), - sizeof(ls) }); - ctrls.set(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING, c); + ControlValue c(Span{ reinterpret_cast(&ls), + sizeof(ls) }); + ctrls.set(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING, c); + } isp_[Isp::Input].dev()->setControls(&ctrls); handleState();