{"id":19405,"url":"https://patchwork.libcamera.org/api/patches/19405/?format=json","web_url":"https://patchwork.libcamera.org/patch/19405/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240113142218.28063-16-hdegoede@redhat.com>","date":"2024-01-13T14:22:15","name":"[libcamera-devel,v2,15/18] libcamera: pipeline: simple: enable use of Soft ISP and Soft IPA","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e1e28ae2b762af385408b5ffd6810016d5a94bde","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/people/102/?format=json","name":"Hans de Goede","email":"hdegoede@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19405/mbox/","series":[{"id":4142,"url":"https://patchwork.libcamera.org/api/series/4142/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4142","date":"2024-01-13T14:22:00","name":"[libcamera-devel,v2,01/18] libcamera: pipeline: simple: fix size adjustment in validate()","version":2,"mbox":"https://patchwork.libcamera.org/series/4142/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19405/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19405/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9EB6CC32C0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 13 Jan 2024 14:23:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0108562916;\n\tSat, 13 Jan 2024 15:23:08 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 58F34628BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 13 Jan 2024 15:23:07 +0100 (CET)","from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n\t[66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-665-HK_Syl4ONiW-4GkyWTY6sA-1; Sat, 13 Jan 2024 09:23:03 -0500","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mimecast-mx02.redhat.com (Postfix) with ESMTPS id DF41682A6C0;\n\tSat, 13 Jan 2024 14:23:02 +0000 (UTC)","from localhost.localdomain (unknown [10.39.192.58])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id E4B823C25;\n\tSat, 13 Jan 2024 14:23:00 +0000 (UTC)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1705155789;\n\tbh=N+Fjz8FwbnlKfIqZ/ZRioDBkVZRrI6AGTRp91gDofNw=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=EhA7Kn3Lm1vjP793dru8U7SOQT+dj52X5z6Nes5Qp80p9ee9dltFvartFvvx3pw6L\n\t+yh3hS5F+BVCfPlQ+DxDyCzJG+uewRA+cwG3S5NjiTTNB+q2UfYx9bz0L8dKJITTE1\n\tT4PUlcwK/uUNw4BhcO28Qrq2hv7ucOikqU8VxHgePbdxTEqXvynU+8a7j4I+hb5DAg\n\tV7zf0RTLSjCWMugYN9RzgZAGkwvYA35TL/X+jkaVcp2MQLBW+s88EruOtjpqStMAyD\n\tj2+HvtX84iWzxk8OSgulQtjXiV6WQTxKDfCIHXiZAVcfrcQK0YyQC1wSl48UgBzys3\n\tphKzEN4KBfCLA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1705155786;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=p7sk4ygNJ1Kp3Chu8iXvFUxQRGjEV5sSXhNgOViZ9Cw=;\n\tb=ZGUu5dL/cv9vZ1cNiQXXmcwus452efYyn4Uqa7UJz/oXPBBtrSUVQ6AKKOHIFgvpNEKtNb\n\tklgxmlvt8VKGO09VCBd5Gk2RzsvOH04BE1pi+J/FFC/V08CTIIuLCZuEL7W6G539PKovVp\n\tDOSudlOMqpTfoLqUJz4mil8KjM4Wxao="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"ZGUu5dL/\"; \n\tdkim-atps=neutral","X-MC-Unique":"HK_Syl4ONiW-4GkyWTY6sA-1","To":"libcamera-devel@lists.libcamera.org,\n\tAndrey Konovalov <andrey.konovalov.ynk@gmail.com>","Date":"Sat, 13 Jan 2024 15:22:15 +0100","Message-ID":"<20240113142218.28063-16-hdegoede@redhat.com>","In-Reply-To":"<20240113142218.28063-1-hdegoede@redhat.com>","References":"<20240113142218.28063-1-hdegoede@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.11.54.1","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain; charset=\"US-ASCII\"; x-default=true","Subject":"[libcamera-devel] [PATCH v2 15/18] libcamera: pipeline: simple:\n\tenable use of Soft ISP and Soft IPA","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Hans de Goede via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Hans de Goede <hdegoede@redhat.com>","Cc":"Maxime Ripard <mripard@redhat.com>, g.martti@gmail.com,\n\tt.langendam@gmail.com, srinivas.kandagatla@linaro.org,\n\tPavel Machek <pavel@ucw.cz>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>, admin@dennisbonke.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Andrey Konovalov <andrey.konovalov@linaro.org>\n\nTo enable the Simple Soft ISP and Soft IPA for simple pipeline handler\nconfigure the build with:\n  -Dpipelines=simple/simple -Dipas=simple/simple\n\nIf the pipeline uses Converter, Soft ISP and Soft IPA aren't\navailable.\n\nConfiguring the build with just:\n  -Dpipelines=simple\nmakes it to work like before - Soft ISP and Soft IPA aren't used.\n\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\nTested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\nTested-by: Pavel Machek <pavel@ucw.cz>\n---\n src/libcamera/pipeline/simple/simple.cpp | 111 ++++++++++++++++++-----\n 1 file changed, 89 insertions(+), 22 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex fa298746..c76510c2 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -34,6 +34,7 @@\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/media_device.h\"\n #include \"libcamera/internal/pipeline_handler.h\"\n+#include \"libcamera/internal/software_isp.h\"\n #include \"libcamera/internal/v4l2_subdevice.h\"\n #include \"libcamera/internal/v4l2_videodevice.h\"\n \n@@ -274,6 +275,7 @@ public:\n \tbool useConversion_;\n \n \tstd::unique_ptr<Converter> converter_;\n+\tstd::unique_ptr<SoftwareIsp> swIsp_;\n \n private:\n \tvoid tryPipeline(unsigned int code, const Size &size);\n@@ -281,6 +283,9 @@ private:\n \n \tvoid conversionInputDone(FrameBuffer *buffer);\n \tvoid conversionOutputDone(FrameBuffer *buffer);\n+\n+\tvoid ispStatsReady(int dummy);\n+\tvoid setSensorControls(const ControlList &sensorControls);\n };\n \n class SimpleCameraConfiguration : public CameraConfiguration\n@@ -509,6 +514,25 @@ int SimpleCameraData::init()\n \t\t}\n \t}\n \n+\t/*\n+\t * Create SoftwareIsp unconditionally if no converter is used\n+\t * - to be revisited\n+\t */\n+\tif (!converter_) {\n+\t\tswIsp_ = SoftwareIspFactoryBase::create(pipe, sensor_->controls());\n+\t\tif (!swIsp_) {\n+\t\t\tLOG(SimplePipeline, Warning)\n+\t\t\t\t<< \"Failed to create software ISP, disabling software debayering\";\n+\t\t\tswIsp_.reset();\n+\t\t} else {\n+\t\t\tswIsp_->inputBufferReady.connect(this, &SimpleCameraData::conversionInputDone);\n+\t\t\tswIsp_->outputBufferReady.connect(this, &SimpleCameraData::conversionOutputDone);\n+\t\t\tswIsp_->ispStatsReady.connect(this, &SimpleCameraData::ispStatsReady);\n+\n+\t\t\tswIsp_->getSignalSetSensorControls().connect(this, &SimpleCameraData::setSensorControls);\n+\t\t}\n+\t}\n+\n \tvideo_ = pipe->video(entities_.back().entity);\n \tASSERT(video_);\n \n@@ -599,12 +623,20 @@ void SimpleCameraData::tryPipeline(unsigned int code, const Size &size)\n \t\tconfig.captureFormat = pixelFormat;\n \t\tconfig.captureSize = format.size;\n \n-\t\tif (!converter_) {\n-\t\t\tconfig.outputFormats = { pixelFormat };\n-\t\t\tconfig.outputSizes = config.captureSize;\n-\t\t} else {\n+\t\tif (converter_) {\n \t\t\tconfig.outputFormats = converter_->formats(pixelFormat);\n \t\t\tconfig.outputSizes = converter_->sizes(format.size);\n+\t\t} else if (swIsp_) {\n+\t\t\tconfig.outputFormats = swIsp_->formats(pixelFormat);\n+\t\t\tconfig.outputSizes = swIsp_->sizes(pixelFormat, format.size);\n+\t\t\tif (config.outputFormats.empty()) {\n+\t\t\t\t/* Do not use swIsp for unsupported pixelFormat's */\n+\t\t\t\tconfig.outputFormats = { pixelFormat };\n+\t\t\t\tconfig.outputSizes = config.captureSize;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tconfig.outputFormats = { pixelFormat };\n+\t\t\tconfig.outputSizes = config.captureSize;\n \t\t}\n \n \t\tconfigs_.push_back(config);\n@@ -750,9 +782,9 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer)\n \t\t}\n \n \t\t/*\n-\t\t * The converter is in use. Requeue the internal buffer for\n-\t\t * capture (unless the stream is being stopped), and complete\n-\t\t * the request with all the user-facing buffers.\n+\t\t * The converter or Software ISP is in use. Requeue the internal\n+\t\t * buffer for capture (unless the stream is being stopped), and\n+\t\t * complete the request with all the user-facing buffers.\n \t\t */\n \t\tif (buffer->metadata().status != FrameMetadata::FrameCancelled)\n \t\t\tvideo_->queueBuffer(buffer);\n@@ -798,9 +830,9 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer)\n \t\t\t\t\tbuffer->metadata().timestamp);\n \n \t/*\n-\t * Queue the captured and the request buffer to the converter if format\n-\t * conversion is needed. If there's no queued request, just requeue the\n-\t * captured buffer for capture.\n+\t * Queue the captured and the request buffer to the converter or Software\n+\t * ISP if format conversion is needed. If there's no queued request, just\n+\t * requeue the captured buffer for capture.\n \t */\n \tif (useConversion_) {\n \t\tif (conversionQueue_.empty()) {\n@@ -808,7 +840,11 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer)\n \t\t\treturn;\n \t\t}\n \n-\t\tconverter_->queueBuffers(buffer, conversionQueue_.front());\n+\t\tif (converter_)\n+\t\t\tconverter_->queueBuffers(buffer, conversionQueue_.front());\n+\t\telse\n+\t\t\tswIsp_->queueBuffers(buffer, conversionQueue_.front());\n+\n \t\tconversionQueue_.pop();\n \t\treturn;\n \t}\n@@ -834,6 +870,18 @@ void SimpleCameraData::conversionOutputDone(FrameBuffer *buffer)\n \t\tpipe->completeRequest(request);\n }\n \n+void SimpleCameraData::ispStatsReady([[maybe_unused]] int dummy)\n+{\n+\tswIsp_->processStats(sensor_->getControls({ V4L2_CID_ANALOGUE_GAIN,\n+\t\t\t\t\t\t    V4L2_CID_EXPOSURE }));\n+}\n+\n+void SimpleCameraData::setSensorControls(const ControlList &sensorControls)\n+{\n+\tControlList ctrls(sensorControls);\n+\tsensor_->setControls(&ctrls);\n+}\n+\n /* Retrieve all source pads connected to a sink pad through active routes. */\n std::vector<const MediaPad *> SimpleCameraData::routedSourcePads(MediaPad *sink)\n {\n@@ -1016,8 +1064,10 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n \t\t/* Set the stride, frameSize and bufferCount. */\n \t\tif (needConversion_) {\n \t\t\tstd::tie(cfg.stride, cfg.frameSize) =\n-\t\t\t\tdata_->converter_->strideAndFrameSize(cfg.pixelFormat,\n-\t\t\t\t\t\t\t\t      cfg.size);\n+\t\t\t\t(data_->converter_) ? data_->converter_->strideAndFrameSize(cfg.pixelFormat,\n+\t\t\t\t\t\t\t\t\t\t\t    cfg.size)\n+\t\t\t\t\t\t    : data_->swIsp_->strideAndFrameSize(cfg.pixelFormat,\n+\t\t\t\t\t\t\t\t\t\t\tcfg.size);\n \t\t\tif (cfg.stride == 0)\n \t\t\t\treturn Invalid;\n \t\t} else {\n@@ -1180,7 +1230,9 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)\n \tinputCfg.stride = captureFormat.planes[0].bpl;\n \tinputCfg.bufferCount = kNumInternalBuffers;\n \n-\treturn data->converter_->configure(inputCfg, outputCfgs);\n+\treturn (data->converter_) ? data->converter_->configure(inputCfg, outputCfgs)\n+\t\t\t\t  : data->swIsp_->configure(inputCfg, outputCfgs,\n+\t\t\t\t\t\t\t    data->sensor_->controls());\n }\n \n int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream,\n@@ -1194,8 +1246,10 @@ int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream,\n \t * whether the converter is used or not.\n \t */\n \tif (data->useConversion_)\n-\t\treturn data->converter_->exportBuffers(data->streamIndex(stream),\n-\t\t\t\t\t\t       count, buffers);\n+\t\treturn (data->converter_) ? data->converter_->exportBuffers(data->streamIndex(stream),\n+\t\t\t\t\t\t\t\t\t    count, buffers)\n+\t\t\t\t\t  : data->swIsp_->exportBuffers(data->streamIndex(stream),\n+\t\t\t\t\t\t\t\t\tcount, buffers);\n \telse\n \t\treturn data->video_->exportBuffers(count, buffers);\n }\n@@ -1240,10 +1294,18 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n \t}\n \n \tif (data->useConversion_) {\n-\t\tret = data->converter_->start();\n-\t\tif (ret < 0) {\n-\t\t\tstop(camera);\n-\t\t\treturn ret;\n+\t\tif (data->converter_) {\n+\t\t\tret = data->converter_->start();\n+\t\t\tif (ret < 0) {\n+\t\t\t\tstop(camera);\n+\t\t\t\treturn ret;\n+\t\t\t}\n+\t\t} else if (data->swIsp_) {\n+\t\t\tret = data->swIsp_->start();\n+\t\t\tif (ret < 0) {\n+\t\t\t\tstop(camera);\n+\t\t\t\treturn ret;\n+\t\t\t}\n \t\t}\n \n \t\t/* Queue all internal buffers for capture. */\n@@ -1259,8 +1321,13 @@ void SimplePipelineHandler::stopDevice(Camera *camera)\n \tSimpleCameraData *data = cameraData(camera);\n \tV4L2VideoDevice *video = data->video_;\n \n-\tif (data->useConversion_)\n-\t\tdata->converter_->stop();\n+\tif (data->useConversion_) {\n+\t\tif (data->converter_)\n+\t\t\tdata->converter_->stop();\n+\t\telse if (data->swIsp_) {\n+\t\t\tdata->swIsp_->stop();\n+\t\t}\n+\t}\n \n \tvideo->streamOff();\n \tvideo->releaseBuffers();\n","prefixes":["libcamera-devel","v2","15/18"]}