Show a patch.

GET /api/1.1/patches/19882/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 19882,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/19882/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19882/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240416091357.211951-14-mzamazal@redhat.com>",
    "date": "2024-04-16T09:13:49",
    "name": "[v8,13/18] libcamera: pipeline: simple: Enable use of Soft ISP and Soft IPA",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "7a6dcc9449ef98832bbeb8a387b533180d1799a1",
    "submitter": {
        "id": 177,
        "url": "https://patchwork.libcamera.org/api/1.1/people/177/?format=api",
        "name": "Milan Zamazal",
        "email": "mzamazal@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19882/mbox/",
    "series": [
        {
            "id": 4257,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4257/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4257",
            "date": "2024-04-16T09:13:36",
            "name": "libcamera: introduce Software ISP and Software IPA",
            "version": 8,
            "mbox": "https://patchwork.libcamera.org/series/4257/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19882/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19882/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 619E6BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Apr 2024 09:15:11 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BB17763375;\n\tTue, 16 Apr 2024 11:15:10 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7ACBE61B4F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Apr 2024 11:15:01 +0200 (CEST)",
            "from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-114-RPihM_TaOz2GP-TaXk5PKg-1;\n\tTue, 16 Apr 2024 05:14:56 -0400",
            "from smtp.corp.redhat.com\n\t(int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4])\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 D7A4138049FD;\n\tTue, 16 Apr 2024 09:14:55 +0000 (UTC)",
            "from nuthatch.redhat.com (unknown [10.45.225.245])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 78B432026962;\n\tTue, 16 Apr 2024 09:14:53 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"RHmxP/mY\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1713258900;\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=KQ01zRgY/0gaWdi3VaYT/+qfrqFItm7Va7PnLpheG7s=;\n\tb=RHmxP/mYgTBH9ywQdfpn7nUYS8eIsm8BHGXMlL0Z3ubwLVCDvRJWm0ku0e/rd9Dpt+lHUl\n\tRbmy5XDupYzvh4a9fg9Y2yj0z79DgokQM5AwSdrX9LsHc9YEg/NGinsfmC4Y5gItUECE0D\n\toPEf0Zm+wk1yvD7PhXCJrkSt5WjxPoE=",
        "X-MC-Unique": "RPihM_TaOz2GP-TaXk5PKg-1",
        "From": "Milan Zamazal <mzamazal@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Andrey Konovalov <andrey.konovalov@linaro.org>,\n\tMilan Zamazal <mzamazal@redhat.com>,\n\tAndrei Konovalov <andrey.konovalov.ynk@gmail.com>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>,\n\tMaxime Ripard <mripard@redhat.com>, Pavel Machek <pavel@ucw.cz>,\n\tHans de Goede <hdegoede@redhat.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Subject": "[PATCH v8 13/18] libcamera: pipeline: simple: Enable use of Soft ISP\n\tand Soft IPA",
        "Date": "Tue, 16 Apr 2024 11:13:49 +0200",
        "Message-ID": "<20240416091357.211951-14-mzamazal@redhat.com>",
        "In-Reply-To": "<20240416091357.211951-1-mzamazal@redhat.com>",
        "References": "<20240416091357.211951-1-mzamazal@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.4",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "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>",
        "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 -Dipas=simple\n\nAlso using the Soft ISP for the particular hardware platform must\nbe enabled in the supportedDevices[] table.  It is currently enabled\nfor and only for qcom-camss.\n\nIf the pipeline uses Converter, Soft ISP and Soft IPA aren't\navailable.\n\nTested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\nTested-by: Pavel Machek <pavel@ucw.cz>\nReviewed-by: Pavel Machek <pavel@ucw.cz>\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n src/libcamera/pipeline/simple/simple.cpp | 142 ++++++++++++++++++-----\n src/libcamera/software_isp/TODO          |  11 ++\n 2 files changed, 127 insertions(+), 26 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex c950f88f..61a59926 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/software_isp.h\"\n #include \"libcamera/internal/v4l2_subdevice.h\"\n #include \"libcamera/internal/v4l2_videodevice.h\"\n \n@@ -185,18 +186,24 @@ struct SimplePipelineInfo {\n \t * and the number of streams it supports.\n \t */\n \tstd::vector<std::pair<const char *, unsigned int>> converters;\n+\t/*\n+\t * Using Software ISP is to be enabled per driver.\n+\t *\n+\t * The Software ISP can't be used together with the converters.\n+\t */\n+\tbool swIspEnabled;\n };\n \n namespace {\n \n static const SimplePipelineInfo supportedDevices[] = {\n-\t{ \"dcmipp\", {} },\n-\t{ \"imx7-csi\", { { \"pxp\", 1 } } },\n-\t{ \"j721e-csi2rx\", {} },\n-\t{ \"mtk-seninf\", { { \"mtk-mdp\", 3 } } },\n-\t{ \"mxc-isi\", {} },\n-\t{ \"qcom-camss\", {} },\n-\t{ \"sun6i-csi\", {} },\n+\t{ \"dcmipp\", {}, false },\n+\t{ \"imx7-csi\", { { \"pxp\", 1 } }, false },\n+\t{ \"j721e-csi2rx\", {}, false },\n+\t{ \"mtk-seninf\", { { \"mtk-mdp\", 3 } }, false },\n+\t{ \"mxc-isi\", {}, false },\n+\t{ \"qcom-camss\", {}, true },\n+\t{ \"sun6i-csi\", {}, false },\n };\n \n } /* namespace */\n@@ -275,6 +282,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@@ -282,6 +290,9 @@ private:\n \n \tvoid conversionInputDone(FrameBuffer *buffer);\n \tvoid conversionOutputDone(FrameBuffer *buffer);\n+\n+\tvoid ispStatsReady();\n+\tvoid setSensorControls(const ControlList &sensorControls);\n };\n \n class SimpleCameraConfiguration : public CameraConfiguration\n@@ -333,6 +344,7 @@ public:\n \tV4L2VideoDevice *video(const MediaEntity *entity);\n \tV4L2Subdevice *subdev(const MediaEntity *entity);\n \tMediaDevice *converter() { return converter_; }\n+\tbool swIspEnabled() const { return swIspEnabled_; }\n \n protected:\n \tint queueRequestDevice(Camera *camera, Request *request) override;\n@@ -361,6 +373,7 @@ private:\n \tstd::map<const MediaEntity *, EntityData> entities_;\n \n \tMediaDevice *converter_;\n+\tbool swIspEnabled_;\n };\n \n /* -----------------------------------------------------------------------------\n@@ -510,6 +523,37 @@ int SimpleCameraData::init()\n \t\t}\n \t}\n \n+\t/*\n+\t * Instantiate Soft ISP if this is enabled for the given driver and no converter is used.\n+\t */\n+\tif (!converter_ && pipe->swIspEnabled()) {\n+\t\tswIsp_ = std::make_unique<SoftwareIsp>(pipe, sensor_.get());\n+\t\tif (!swIsp_->isValid()) {\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\t/*\n+\t\t\t * The inputBufferReady signal is emitted from the soft ISP thread,\n+\t\t\t * and needs to be handled in the pipeline handler thread. Signals\n+\t\t\t * implement queued delivery, but this works transparently only if\n+\t\t\t * the receiver is bound to the target thread. As the\n+\t\t\t * SimpleCameraData class doesn't inherit from the Object class, it\n+\t\t\t * is not bound to any thread, and the signal would be delivered\n+\t\t\t * synchronously. Instead, connect the signal to a lambda function\n+\t\t\t * bound explicitly to the pipe, which is bound to the pipeline\n+\t\t\t * handler thread. The function then simply forwards the call to\n+\t\t\t * conversionInputDone().\n+\t\t\t */\n+\t\t\tswIsp_->inputBufferReady.connect(pipe, [this](FrameBuffer *buffer) {\n+\t\t\t\tthis->conversionInputDone(buffer);\n+\t\t\t});\n+\t\t\tswIsp_->outputBufferReady.connect(this, &SimpleCameraData::conversionOutputDone);\n+\t\t\tswIsp_->ispStatsReady.connect(this, &SimpleCameraData::ispStatsReady);\n+\t\t\tswIsp_->setSensorControls.connect(this, &SimpleCameraData::setSensorControls);\n+\t\t}\n+\t}\n+\n \tvideo_ = pipe->video(entities_.back().entity);\n \tASSERT(video_);\n \n@@ -600,12 +644,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@@ -751,9 +803,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@@ -799,9 +851,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@@ -809,7 +861,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@@ -835,6 +891,19 @@ void SimpleCameraData::conversionOutputDone(FrameBuffer *buffer)\n \t\tpipe->completeRequest(request);\n }\n \n+void SimpleCameraData::ispStatsReady()\n+{\n+\t/* \\todo Use the DelayedControls class */\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@@ -1050,8 +1119,11 @@ 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\tdata_->converter_\n+\t\t\t\t\t? data_->converter_->strideAndFrameSize(cfg.pixelFormat,\n+\t\t\t\t\t\t\t\t\t\tcfg.size)\n+\t\t\t\t\t: data_->swIsp_->strideAndFrameSize(cfg.pixelFormat,\n+\t\t\t\t\t\t\t\t\t    cfg.size);\n \t\t\tif (cfg.stride == 0)\n \t\t\t\treturn Invalid;\n \t\t} else {\n@@ -1214,7 +1286,10 @@ 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_\n+\t\t       ? data->converter_->configure(inputCfg, outputCfgs)\n+\t\t       : data->swIsp_->configure(inputCfg, outputCfgs,\n+\t\t\t\t\t\t data->sensor_->controls());\n }\n \n int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream,\n@@ -1228,8 +1303,11 @@ 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_\n+\t\t\t       ? data->converter_->exportBuffers(data->streamIndex(stream),\n+\t\t\t\t\t\t\t\t count, buffers)\n+\t\t\t       : data->swIsp_->exportBuffers(data->streamIndex(stream),\n+\t\t\t\t\t\t\t     count, buffers);\n \telse\n \t\treturn data->video_->exportBuffers(count, buffers);\n }\n@@ -1274,7 +1352,13 @@ 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 (data->converter_)\n+\t\t\tret = data->converter_->start();\n+\t\telse if (data->swIsp_)\n+\t\t\tret = data->swIsp_->start();\n+\t\telse\n+\t\t\tret = 0;\n+\n \t\tif (ret < 0) {\n \t\t\tstop(camera);\n \t\t\treturn ret;\n@@ -1293,8 +1377,12 @@ 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}\n \n \tvideo->streamOff();\n \tvideo->releaseBuffers();\n@@ -1456,6 +1544,8 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n \t\t}\n \t}\n \n+\tswIspEnabled_ = info->swIspEnabled;\n+\n \t/* Locate the sensors. */\n \tstd::vector<MediaEntity *> sensors = locateSensors();\n \tif (sensors.empty()) {\ndiff --git a/src/libcamera/software_isp/TODO b/src/libcamera/software_isp/TODO\nindex ae0af25b..fcb02588 100644\n--- a/src/libcamera/software_isp/TODO\n+++ b/src/libcamera/software_isp/TODO\n@@ -256,3 +256,14 @@ At some point, yes.\n >\t}\n \n This could be handled better with DelayedControls.\n+\n+---\n+\n+12. Use DelayedControls class in ispStatsReady()\n+\n+> void SimpleCameraData::ispStatsReady()\n+> {\n+> \tswIsp_->processStats(sensor_->getControls({ V4L2_CID_ANALOGUE_GAIN,\n+> \t\t\t\t\t\t    V4L2_CID_EXPOSURE }));\n+\n+You should use the DelayedControls class.\n",
    "prefixes": [
        "v8",
        "13/18"
    ]
}