Show a patch.

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

{
    "id": 19495,
    "url": "https://patchwork.libcamera.org/api/patches/19495/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19495/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20240214170122.60754-13-hdegoede@redhat.com>",
    "date": "2024-02-14T17:01:16",
    "name": "[v3,12/16] libcamera: pipeline: simple: enable use of Soft ISP and Soft IPA",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "cf4395012eb8f30c7ca3352d4ce544596980c0c2",
    "submitter": {
        "id": 102,
        "url": "https://patchwork.libcamera.org/api/people/102/?format=api",
        "name": "Hans de Goede",
        "email": "hdegoede@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19495/mbox/",
    "series": [
        {
            "id": 4167,
            "url": "https://patchwork.libcamera.org/api/series/4167/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4167",
            "date": "2024-02-14T17:01:04",
            "name": "libcamera: introduce Software ISP and Software IPA",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/4167/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19495/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19495/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 34664C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Feb 2024 17:01:56 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D404A6282C;\n\tWed, 14 Feb 2024 18:01:55 +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 9914862806\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Feb 2024 18:01:53 +0100 (CET)",
            "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-265-YyFOBCYQODuEUfoKWfYj2w-1;\n\tWed, 14 Feb 2024 12:01:49 -0500",
            "from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6])\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 C9FB6381259D;\n\tWed, 14 Feb 2024 17:01:48 +0000 (UTC)",
            "from localhost.localdomain (unknown [10.39.192.30])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id B90EC2166B4F;\n\tWed, 14 Feb 2024 17:01:47 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"XqCFtlMj\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1707930112;\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=zp0NXe2fRzyeSM+aQxzQ0Aq5G8TI6UHD2uAIThifcY4=;\n\tb=XqCFtlMj+MnPbH7k2o7lArzZJEVooxweqmX7lHZexq69shhONKkXjOXXvlYTHctY4EJ7t9\n\tPQ6MaG20jLYB12K9mc+usLmxo2uoAwd518KjDX935yxg6I2rDJ+NIuMg9nWc1EShufKbGj\n\tMDdo2khB2NPnOg6pCZ+oxNbZrRHMd3k=",
        "X-MC-Unique": "YyFOBCYQODuEUfoKWfYj2w-1",
        "From": "Hans de Goede <hdegoede@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v3 12/16] libcamera: pipeline: simple: enable use of Soft ISP\n\tand Soft IPA",
        "Date": "Wed, 14 Feb 2024 18:01:16 +0100",
        "Message-ID": "<20240214170122.60754-13-hdegoede@redhat.com>",
        "In-Reply-To": "<20240214170122.60754-1-hdegoede@redhat.com>",
        "References": "<20240214170122.60754-1-hdegoede@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.6",
        "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>",
        "Cc": "Maxime Ripard <mripard@redhat.com>, Pavel Machek <pavel@ucw.cz>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>",
        "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.\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 | 136 ++++++++++++++++++-----\n 1 file changed, 108 insertions(+), 28 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 78854ef8..eab5b56e 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,17 +186,22 @@ 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 * 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{ \"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{ \"mxc-isi\", {}, false },\n+\t{ \"qcom-camss\", {}, true },\n+\t{ \"sun6i-csi\", {}, false },\n };\n \n } /* namespace */\n@@ -274,6 +280,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 +288,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@@ -332,6 +342,7 @@ public:\n \tV4L2VideoDevice *video(const MediaEntity *entity);\n \tV4L2Subdevice *subdev(const MediaEntity *entity);\n \tMediaDevice *converter() { return converter_; }\n+\tbool swIspEnabled() { return swIspEnabled_; }\n \n protected:\n \tint queueRequestDevice(Camera *camera, Request *request) override;\n@@ -360,6 +371,7 @@ private:\n \tstd::map<const MediaEntity *, EntityData> entities_;\n \n \tMediaDevice *converter_;\n+\tbool swIspEnabled_;\n };\n \n /* -----------------------------------------------------------------------------\n@@ -509,6 +521,29 @@ 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_->controls());\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 * \\todo explain why SimpleCameraData::conversionInputDone() can't be directly\n+\t\t\t * connected to inputBufferReady signal.\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@@ -599,12 +634,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 +793,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 +841,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 +851,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 +881,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@@ -1046,8 +1105,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@@ -1210,7 +1271,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@@ -1224,8 +1287,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@@ -1270,10 +1335,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@@ -1289,8 +1362,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@@ -1452,6 +1530,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()) {\n",
    "prefixes": [
        "v3",
        "12/16"
    ]
}