From patchwork Tue Dec 12 11:50:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 19312 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 ED333BD87C for ; Tue, 12 Dec 2023 11:51:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9871462B33; Tue, 12 Dec 2023 12:51:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1702381893; bh=2+oVwBiLoDG1CDdrv0bdoRdovwtqIl7Ba33ZLynjJBQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=yfxoTOwL6wtnVYF5uFsmnTyWz+0W7lYlm3ff8nb8piIrtodd+kWOdBxuko3FMnEnb wfVOvxeJTybLuHAX+Vs6w8ykmXhWYHvnpMRHh09fWPH1Hfd6BFui/BxhGfCYNX/8Hy p9Jo+FrSSHBt6DP+ROMy5e4ctaYNxq3Arnb4zguLDTPH++3LQCDJsGerrxZmfI//cF Lz1/HQytZLekMi8BuZvnaqe3hyjh8OOKuwcUQxaVjWZ+8rYWumUJ5iPIqMm/8OjBm2 BJXyXd4hGmRWfC2gxS6xhmg9dvCGq2fKkI3ri0g3oufWsqLvivpDE45cg3hMRexRrT TGe9bEyBbBIgQ== Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 70BEE62B2E for ; Tue, 12 Dec 2023 12:51:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="T9UiCMrj"; dkim-atps=neutral Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a1da1017a09so676275566b.3 for ; Tue, 12 Dec 2023 03:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702381891; x=1702986691; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DOT0/3W2904w/yNWAzyag1CLj3C5QSiWMpVEzLHWH2Q=; b=T9UiCMrjzG1aJcOOJAjvP5wOHE5x4K56eA/qs9e5rZe7nNcIsRSTBVjV2uSHbZOqc3 rxF4glrti8EtNiSq3LZX+zHmj1rcG8cN56IoxEj+fupSq9jzq7rBu4bAqjXmvKzMug/c cg3mWJaZDtFqXAf1vUapYnakro42npZJ1G2xtuQYUrZ15vWEgFf5nZpXxBslEs47P49K +jnWeGkedFmHiX6PfMod8U25yfseJ8nhP/BszEaf+IX9j25rK0RT5XCKL9ZFF0h6E2gz JxgNCx77Nv+bxy4dWxXr24yrQvw3rtDrvrrguEHRCdb7TQVhk0xfDByNQEO8+vzZ5gVL aRew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702381891; x=1702986691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DOT0/3W2904w/yNWAzyag1CLj3C5QSiWMpVEzLHWH2Q=; b=Qk/jyHFgzC4NKua122wUCRTVyhvMd7sFIfQ2ZVhXQ9PZI227KBUfH0U//i+PWQGeRp SilC5c6X6+GwCo46QiDbn+NDzgyix3M2ifaXaF2Z65XPygOLdOlTJpwXy+7vyge7RpOy 3PFqGJ8R9/p04OkIz4djeOAmkUFcrZbOGwmXwWzjPU9fp8hS88NRoDfi+wSoBgdV7fYK ucBS8rzW6UlVecQJ0fdVQWDspMcAOrrOucESWKloC8gfMiyzaut2OHGm15EUj75jhQjR HJjN4PVM1FoDNofH6d0TEzP3Ww05kfLlG5B/A3NHZGYtspZ75XI+CJy6WnfvJxpTow/y 4uAA== X-Gm-Message-State: AOJu0YwLO/P8sL1VU+W5ti4uhEYwatW2FECCqWiyKsWVn1tX2qWDighI 1s2JrLXNRPOLC2t78PcYOmGgdeDiScbTuZO0LUU= X-Google-Smtp-Source: AGHT+IGe2oAaT+rnR+kYKUmHpjoF6xyDshVKL4aTIMMapCtQSCTSleeQF4RpzMjmRK8dUVdryUZZfQ== X-Received: by 2002:a17:907:510:b0:a19:a19b:78a5 with SMTP id wj16-20020a170907051000b00a19a19b78a5mr2699050ejb.104.1702381889790; Tue, 12 Dec 2023 03:51:29 -0800 (PST) Received: from Lat-5310.. ([87.116.161.153]) by smtp.gmail.com with ESMTPSA id tx17-20020a1709078e9100b00a1b75e0e061sm6213188ejc.130.2023.12.12.03.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 03:51:29 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Dec 2023 14:50:46 +0300 Message-Id: <20231212115046.102726-8-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212115046.102726-1-andrey.konovalov@linaro.org> References: <20231212115046.102726-1-andrey.konovalov@linaro.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 7/7] libcamera: pipeline: simple: enable use of Soft ISP and Soft IPA 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: Andrey Konovalov via libcamera-devel From: Andrey Konovalov Reply-To: Andrey Konovalov Cc: mripard@redhat.com, g.martti@gmail.com, t.langendam@gmail.com, srinivas.kandagatla@linaro.org, pavel@ucw.cz, bryan.odonoghue@linaro.org, admin@dennisbonke.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To enable the Soft ISP and Soft IPA for simple pipeline handler configure the build with: -Dpipelines=simple/linaro -Dipas=simple/linaro If the pipeline uses Converter, Soft ISP and Soft IPA aren't available. Configuring the build with just: -Dpipelines=simple makes it to work like before - Soft ISP and Soft IPA aren't used. Signed-off-by: Andrey Konovalov --- src/libcamera/pipeline/simple/simple.cpp | 106 ++++++++++++++++++----- 1 file changed, 83 insertions(+), 23 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 878794f6..276e9d72 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -34,10 +34,10 @@ #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" +#include "libcamera/internal/software_isp.h" #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" - namespace libcamera { LOG_DEFINE_CATEGORY(SimplePipeline) @@ -274,6 +274,7 @@ public: bool useConversion_; std::unique_ptr converter_; + std::unique_ptr swIsp_; private: void tryPipeline(unsigned int code, const Size &size); @@ -281,6 +282,9 @@ private: void conversionInputDone(FrameBuffer *buffer); void conversionOutputDone(FrameBuffer *buffer); + + void ispStatsReady(int dummy); + void setSensorControls(const ControlList &sensorControls); }; class SimpleCameraConfiguration : public CameraConfiguration @@ -509,6 +513,25 @@ int SimpleCameraData::init() } } + /* + * Create Linaro's implementation of SoftwareIsp unconditionally if no converter is used + * - to be revisited + */ + if (!converter_) { + swIsp_ = SoftwareIspFactoryBase::create(pipe, sensor_->controls()); + if (!swIsp_) { + LOG(SimplePipeline, Warning) + << "Failed to create software ISP, disabling software debayering"; + swIsp_.reset(); + } else { + swIsp_->inputBufferReady.connect(this, &SimpleCameraData::conversionInputDone); + swIsp_->outputBufferReady.connect(this, &SimpleCameraData::conversionOutputDone); + swIsp_->ispStatsReady.connect(this, &SimpleCameraData::ispStatsReady); + + swIsp_->getSignalSetSensorControls().connect(this, &SimpleCameraData::setSensorControls); + } + } + video_ = pipe->video(entities_.back().entity); ASSERT(video_); @@ -599,12 +622,15 @@ void SimpleCameraData::tryPipeline(unsigned int code, const Size &size) config.captureFormat = pixelFormat; config.captureSize = format.size; - if (!converter_) { - config.outputFormats = { pixelFormat }; - config.outputSizes = config.captureSize; - } else { + if (converter_) { config.outputFormats = converter_->formats(pixelFormat); config.outputSizes = converter_->sizes(format.size); + } else if (swIsp_) { + config.outputFormats = swIsp_->formats(pixelFormat); + config.outputSizes = swIsp_->sizes(pixelFormat, format.size); + } else { + config.outputFormats = { pixelFormat }; + config.outputSizes = config.captureSize; } configs_.push_back(config); @@ -750,9 +776,9 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer) } /* - * The converter is in use. Requeue the internal buffer for - * capture (unless the stream is being stopped), and complete - * the request with all the user-facing buffers. + * The converter or Software ISP is in use. Requeue the internal + * buffer for capture (unless the stream is being stopped), and + * complete the request with all the user-facing buffers. */ if (buffer->metadata().status != FrameMetadata::FrameCancelled) video_->queueBuffer(buffer); @@ -798,9 +824,9 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer) buffer->metadata().timestamp); /* - * Queue the captured and the request buffer to the converter if format - * conversion is needed. If there's no queued request, just requeue the - * captured buffer for capture. + * Queue the captured and the request buffer to the converter or Software + * ISP if format conversion is needed. If there's no queued request, just + * requeue the captured buffer for capture. */ if (useConversion_) { if (conversionQueue_.empty()) { @@ -808,7 +834,11 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer) return; } - converter_->queueBuffers(buffer, conversionQueue_.front()); + if (converter_) + converter_->queueBuffers(buffer, conversionQueue_.front()); + else + swIsp_->queueBuffers(buffer, conversionQueue_.front()); + conversionQueue_.pop(); return; } @@ -834,6 +864,18 @@ void SimpleCameraData::conversionOutputDone(FrameBuffer *buffer) pipe->completeRequest(request); } +void SimpleCameraData::ispStatsReady([[maybe_unused]] int dummy) +{ + swIsp_->processStats(sensor_->getControls({ V4L2_CID_ANALOGUE_GAIN, + V4L2_CID_EXPOSURE })); +} + +void SimpleCameraData::setSensorControls(const ControlList &sensorControls) +{ + ControlList ctrls(sensorControls); + sensor_->setControls(&ctrls); +} + /* Retrieve all source pads connected to a sink pad through active routes. */ std::vector SimpleCameraData::routedSourcePads(MediaPad *sink) { @@ -1013,8 +1055,10 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate() /* Set the stride, frameSize and bufferCount. */ if (needConversion_) { std::tie(cfg.stride, cfg.frameSize) = - data_->converter_->strideAndFrameSize(cfg.pixelFormat, - cfg.size); + (data_->converter_) ? data_->converter_->strideAndFrameSize(cfg.pixelFormat, + cfg.size) + : data_->swIsp_->strideAndFrameSize(cfg.pixelFormat, + cfg.size); if (cfg.stride == 0) return Invalid; } else { @@ -1177,7 +1221,8 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c) inputCfg.stride = captureFormat.planes[0].bpl; inputCfg.bufferCount = kNumInternalBuffers; - return data->converter_->configure(inputCfg, outputCfgs); + return (data->converter_) ? data->converter_->configure(inputCfg, outputCfgs) + : data->swIsp_->configure(inputCfg, outputCfgs); } int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream, @@ -1191,8 +1236,10 @@ int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream, * whether the converter is used or not. */ if (data->useConversion_) - return data->converter_->exportBuffers(data->streamIndex(stream), - count, buffers); + return (data->converter_) ? data->converter_->exportBuffers(data->streamIndex(stream), + count, buffers) + : data->swIsp_->exportBuffers(data->streamIndex(stream), + count, buffers); else return data->video_->exportBuffers(count, buffers); } @@ -1237,10 +1284,18 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL } if (data->useConversion_) { - ret = data->converter_->start(); - if (ret < 0) { - stop(camera); - return ret; + if (data->converter_) { + ret = data->converter_->start(); + if (ret < 0) { + stop(camera); + return ret; + } + } else if (data->swIsp_) { + ret = data->swIsp_->start(); + if (ret < 0) { + stop(camera); + return ret; + } } /* Queue all internal buffers for capture. */ @@ -1256,8 +1311,13 @@ void SimplePipelineHandler::stopDevice(Camera *camera) SimpleCameraData *data = cameraData(camera); V4L2VideoDevice *video = data->video_; - if (data->useConversion_) - data->converter_->stop(); + if (data->useConversion_) { + if (data->converter_) + data->converter_->stop(); + else if (data->swIsp_) { + data->swIsp_->stop(); + } + } video->streamOff(); video->releaseBuffers();