{"id":19269,"url":"https://patchwork.libcamera.org/api/1.1/patches/19269/?format=json","web_url":"https://patchwork.libcamera.org/patch/19269/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20231204001013.404720-8-andrey.konovalov@linaro.org>","date":"2023-12-04T00:10:13","name":"[libcamera-devel,RFC,7/7,DNI] libcamera: pipeline: simple: enable use of SoftwareISP and Soft IPA","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"755dd3ae9e7a7e835475cc436a47856b533e9a06","submitter":{"id":25,"url":"https://patchwork.libcamera.org/api/1.1/people/25/?format=json","name":"Andrey Konovalov","email":"andrey.konovalov@linaro.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19269/mbox/","series":[{"id":4096,"url":"https://patchwork.libcamera.org/api/1.1/series/4096/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4096","date":"2023-12-04T00:10:06","name":"libcamera: introduce Software ISP and Software IPA","version":1,"mbox":"https://patchwork.libcamera.org/series/4096/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19269/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19269/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 14353C322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Dec 2023 00:10:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A20D6629DB;\n\tMon,  4 Dec 2023 01:10:53 +0100 (CET)","from mail-wr1-x432.google.com (mail-wr1-x432.google.com\n\t[IPv6:2a00:1450:4864:20::432])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B5B67629D6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Dec 2023 01:10:52 +0100 (CET)","by mail-wr1-x432.google.com with SMTP id\n\tffacd0b85a97d-3316d09c645so3751104f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 03 Dec 2023 16:10:52 -0800 (PST)","from Lat-5310.. ([87.116.165.212]) by smtp.gmail.com with ESMTPSA\n\tid\n\tu29-20020adfa19d000000b003332db7d91dsm8835997wru.39.2023.12.03.16.10.51\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 03 Dec 2023 16:10:52 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1701648653;\n\tbh=X2oPJy3GZr8rWVQz96jg/g4d2q0hf8JwiEbzhCfdJ2M=;\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=1LTKBiJQxrgY+1a3OWd8VsSTZ0zOiIozDMlxBsgUO0pXQ8ns8JMBCpSFEwVxKqsRC\n\tsU/DNa97+K3R6RLk41Lf17IdBja0+HGOpPOpivEUx/KAX+L9MRbNI6NLz6hitSGQNX\n\t3tVDrHtO7LvolabtqHkCMW9+UvaajGzc+3/L/ZkTjqu17nd556pGf7RAOvlKLnlcgN\n\t4T3+tSx3uCU4gR8WJ6QT9DPTbrcraYondw+ZFsMmljmMDCLajxXxgBH3kvKumuHQdm\n\t6q9z5WamAye2Xk5wRvMtjQt+Uc6mt1+aMoAhhFmq7cy/oZUpWRgqIlFd+G/5ZOvt6L\n\tzFzJz1VfOUYKQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1701648652; x=1702253452;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=uWT6dMbaiuLENDzwFc4xPPz9KU9sfJhCzfIGiy01m4M=;\n\tb=lU2VD5s0eoTvLBuWNtBd/xhV3x1312d9e+V/YvJn7kQP62UCvnBNVWA2/89nmawLza\n\tRkovyqnwksnDu4q30D98mV2TH9zCtjEAVU7fvH2p1YfJakqURtak2z06SQ181nl0U32F\n\t8UNLHAhABdgKuxAIbAdd8KlstK67zABHAXIAbaMvTspYfGFIsCV0GrqGQ+xi+Xmcy5KC\n\teY9ms355JXFbDsdnQDB4DS3+pddZjCoG+WaN1BWrcYpYdwQ7PYeFg7Pz80xKssgDHsCx\n\tkd7WnRPV8r3mgmw/jO1wmtja/eS8fYOCN3aJ8jERvoEdqzHTH1qZ04UngsxBPWhxz7B8\n\tSb8w=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=linaro.org\n\theader.i=@linaro.org header.b=\"lU2VD5s0\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1701648652; x=1702253452;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=uWT6dMbaiuLENDzwFc4xPPz9KU9sfJhCzfIGiy01m4M=;\n\tb=tTxCr539IBebJgHygsQKqIF54jKdA0Ggk+wJ9NeDuu6UIfRGhWWbeS+nkXG6UjqOUS\n\t+JIKQD/OeMiB2gZR1iAYkssAOKbxYb7DXqe8O4RZTm7UlwygZsyLDA1zbsIvoe9mFqVN\n\t/Ln/lhVmyLmOLLRGfhtb6xEz2YRpaswJTtNRgVPRQUhjgmjYTYhjGQjDviw/8VCsq5Af\n\tge9lKvBhyhg6XnZ8r60qEE6rOQWUM/p6NTIcKP7YZp3mtCvqhnjcOAga51aUSKBcCqNI\n\tGBE1YJesdxFEqkn/VPOs+m0Jgp1YmxiecRnY1aj/5Vn4GQ+LuS9hp7MhOmvg4lFUhpCi\n\tqr8A==","X-Gm-Message-State":"AOJu0YwsGL/iLoU410JPnAWu57zsTP6+tIL8LgPLRKIkzCE1b2eQLVf8\n\ttxlhycslucYeNuWppdRpoj+Sm3xScMV11PbJPlc=","X-Google-Smtp-Source":"AGHT+IHBx/C1Kxp4bUv5MC/KL5sbrtJM9xvxvGO2tDRIUWyJiv8Tnv+6ckcymJb3yIONjJNX3uVVzA==","X-Received":"by 2002:adf:e5c9:0:b0:333:2fd2:4afb with SMTP id\n\ta9-20020adfe5c9000000b003332fd24afbmr2384787wrn.119.1701648652407; \n\tSun, 03 Dec 2023 16:10:52 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  4 Dec 2023 03:10:13 +0300","Message-Id":"<20231204001013.404720-8-andrey.konovalov@linaro.org>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20231204001013.404720-1-andrey.konovalov@linaro.org>","References":"<20231204001013.404720-1-andrey.konovalov@linaro.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH 7/7] [DNI] libcamera: pipeline:\n\tsimple: enable use of SoftwareISP 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":"Andrey Konovalov via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Andrey Konovalov <andrey.konovalov@linaro.org>","Cc":"mripard@redhat.com, g.martti@gmail.com, t.langendam@gmail.com,\n\tsrinivas.kandagatla@linaro.org, bryan.odonoghue@linaro.org,\n\tadmin@dennisbonke.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Some quick changes to make SoftwareISP and Soft IPA usable\nin the cases when the pipeline doesn't use Converter.\n\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\n---\n src/libcamera/pipeline/simple/simple.cpp | 134 +++++++++++++++++++----\n 1 file changed, 111 insertions(+), 23 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 878794f6..8c119a98 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -25,6 +25,8 @@\n \n #include <libcamera/camera.h>\n #include <libcamera/control_ids.h>\n+#include <libcamera/ipa/soft_ipa_interface.h>\n+#include <libcamera/ipa/soft_ipa_proxy.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n@@ -32,12 +34,14 @@\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/converter.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n+#include \"libcamera/internal/ipa_manager.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/software_isp/swisp_linaro.h\"\n #include \"libcamera/internal/v4l2_subdevice.h\"\n #include \"libcamera/internal/v4l2_videodevice.h\"\n \n-\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(SimplePipeline)\n@@ -274,6 +278,8 @@ public:\n \tbool useConversion_;\n \n \tstd::unique_ptr<Converter> converter_;\n+\tstd::unique_ptr<SoftwareIsp> swIsp_;\n+\tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n \n private:\n \tvoid tryPipeline(unsigned int code, const Size &size);\n@@ -281,6 +287,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 +518,38 @@ int SimpleCameraData::init()\n \t\t}\n \t}\n \n+\t/*\n+\t * Create Linaro's implementation of SoftwareIsp unconditionally if no converter is used\n+\t * - to be revisited\n+\t */\n+\tif (!converter_) {\n+\t\tswIsp_ = std::make_unique<SwIspLinaro>(\"linaro\");\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}\n+\t\tswIsp_->inputBufferReady.connect(this, &SimpleCameraData::conversionInputDone);\n+\t\tswIsp_->outputBufferReady.connect(this, &SimpleCameraData::conversionOutputDone);\n+\t\tswIsp_->ispStatsReady.connect(this, &SimpleCameraData::ispStatsReady);\n+\n+\t\t/* Create Linaro's IPA for the SoftwareIsp - to be revisited */\n+\t\tipa_ = IPAManager::createIPA<ipa::soft::IPAProxySoft>(pipe, 0, 0);\n+\t\tif (!ipa_) {\n+\t\t\tLOG(SimplePipeline, Warning) << \"Creating IPA for software ISP failed\";\n+\t\t\treturn -ENOENT;\n+\t\t}\n+\t\tret = ipa_->init(IPASettings{ \"No cfg file\", \"No sensor model\" },\n+\t\t\t\t swIsp_->getStatsFD(),\n+\t\t\t\t sensor_->controls());\n+\t\tif (ret) {\n+\t\t\tLOG(SimplePipeline, Warning) << \"IPA init failed\";\n+\t\t\treturn ret;\n+\t\t}\n+\t\tipa_->setSensorControls.connect(this, &SimpleCameraData::setSensorControls);\n+\t\tipa_->configure(sensor_->controls());\n+\t}\n+\n \tvideo_ = pipe->video(entities_.back().entity);\n \tASSERT(video_);\n \n@@ -599,12 +640,15 @@ 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} 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 +794,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 +842,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 +852,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 +882,21 @@ void SimpleCameraData::conversionOutputDone(FrameBuffer *buffer)\n \t\tpipe->completeRequest(request);\n }\n \n+void SimpleCameraData::ispStatsReady([[maybe_unused]] int dummy)\n+{\n+\tif (!ipa_)\n+\t\treturn;\n+\n+\tipa_->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@@ -1013,8 +1076,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@@ -1177,7 +1242,8 @@ 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 }\n \n int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream,\n@@ -1191,8 +1257,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@@ -1237,10 +1305,24 @@ 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->ipa_->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\tret = data->swIsp_->start();\n+\t\t\tif (ret < 0) {\n+\t\t\t\tdata->ipa_->stop();\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@@ -1256,8 +1338,14 @@ 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\tdata->ipa_->stop();\n+\t\t}\n+\t}\n \n \tvideo->streamOff();\n \tvideo->releaseBuffers();\n","prefixes":["libcamera-devel","RFC","7/7","DNI"]}