Show a patch.

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

{
    "id": 21463,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21463/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21463/",
    "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": "<20241001141738.17471-1-umang.jain@ideasonboard.com>",
    "date": "2024-10-01T14:17:38",
    "name": "libcamera: rkisp1: Integrate SensorConfiguration support",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "5c7d5981603b7a545863c92be683e33bb6861841",
    "submitter": {
        "id": 86,
        "url": "https://patchwork.libcamera.org/api/1.1/people/86/?format=api",
        "name": "Umang Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21463/mbox/",
    "series": [
        {
            "id": 4645,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4645/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4645",
            "date": "2024-10-01T14:17:38",
            "name": "libcamera: rkisp1: Integrate SensorConfiguration support",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4645/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21463/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21463/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 502ADBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  1 Oct 2024 14:17:57 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 282566351F;\n\tTue,  1 Oct 2024 16:17:56 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C91AC60553\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  1 Oct 2024 16:17:54 +0200 (CEST)",
            "from localhost.localdomain (unknown\n\t[IPv6:2405:201:2015:f873:55f8:639e:8e9f:12ec])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DCA9810B8;\n\tTue,  1 Oct 2024 16:16:19 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gh2Qk2Ng\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727792181;\n\tbh=XpStW0HgvXEpsC8K56hDz2YA1GFPArjlKbNDR6S/+r8=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=gh2Qk2NgUZtcNj3aO9vG5Cn1ztXEeLmIroxHchm4rlMYHt3ZaMKF3P82TzaOX8H0W\n\tDI3dVsK7i9Ob9hA6EkrhjadhUT6DSmX6YneotMmmv95w2FzT6FhQQvsTFJTa0fvALr\n\tD7Xme/WxFTuh0CxedtQO7cEouC4QWolVAVlMptZU=",
        "From": "Umang Jain <umang.jain@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>,\n\tUmang Jain <umang.jain@ideasonboard.com>",
        "Subject": "[PATCH] libcamera: rkisp1: Integrate SensorConfiguration support",
        "Date": "Tue,  1 Oct 2024 19:47:38 +0530",
        "Message-ID": "<20241001141738.17471-1-umang.jain@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.45.0",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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": "Integrate the RkISP1 pipeline handler to support sensor configuration\nprovided by applications through CameraConfiguration::sensorConfig.\n\nThe SensorConfiguration must be validated on both RkISP1Path (mainPath\nand selfPath), so the parameters of RkISP1Path::validate() have been\nupdated to include sensorConfig.\n\nFor RAW paths, if a sensor configuration is provided, it will be\nadjusted based on the stream configuration.\n\nFinally, if the sensor configuration fails to apply, the camera\nconfiguration validation will be marked as invalid.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\nTesting:\n- Developed over [PATCH 0/2] libcamera: pixelformat: Add isRaw() helper\n- Tested with cam+[1] on i.MX8MP with IMX283 attached\n\n[1]: https://patchwork.libcamera.org/patch/20080/\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp      | 79 +++++++++++++++++--\n src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 20 +++--\n src/libcamera/pipeline/rkisp1/rkisp1_path.h   |  2 +\n 3 files changed, 87 insertions(+), 14 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 0c4519de..49fe8fb1 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -474,11 +474,12 @@ bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg)\n \tStreamConfiguration config;\n \n \tconfig = cfg;\n-\tif (data_->mainPath_->validate(sensor, &config) != Valid)\n+\tif (data_->mainPath_->validate(sensor, sensorConfig, &config) != Valid)\n \t\treturn false;\n \n \tconfig = cfg;\n-\tif (data_->selfPath_ && data_->selfPath_->validate(sensor, &config) != Valid)\n+\tif (data_->selfPath_ &&\n+\t    data_->selfPath_->validate(sensor, sensorConfig, &config) != Valid)\n \t\treturn false;\n \n \treturn true;\n@@ -495,6 +496,31 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \n \tstatus = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);\n \n+\t/*\n+\t * Make sure that if a sensor configuration has been requested it\n+\t * is valid.\n+\t */\n+\tif (sensorConfig && !sensorConfig->isValid()) {\n+\t\tLOG(RkISP1, Error) << \"Invalid sensor configuration request\";\n+\t\treturn Invalid;\n+\t}\n+\n+\tif (sensorConfig) {\n+\t\tstd::optional<unsigned int> bitDepth = sensorConfig->bitDepth;\n+\t\tif (bitDepth != 8 && bitDepth != 10 && bitDepth != 12) {\n+\t\t\t/*\n+\t\t\t * Default to the first supported bit depth, if an\n+\t\t\t * unsupported one is supplied.\n+\t\t\t */\n+\t\t\tV4L2SubdeviceFormat format = {};\n+\t\t\tformat.code = sensor->mbusCodes().at(0);\n+\n+\t\t\tsensorConfig->bitDepth =\n+\t\t\t\tMediaBusFormatInfo::info(format.code).bitsPerPixel;\n+\t\t\tstatus = Adjusted;\n+\t\t}\n+\t}\n+\n \t/* Cap the number of entries to the available streams. */\n \tif (config_.size() > pathCount) {\n \t\tconfig_.resize(pathCount);\n@@ -540,7 +566,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\t/* Try to match stream without adjusting configuration. */\n \t\tif (mainPathAvailable) {\n \t\t\tStreamConfiguration tryCfg = cfg;\n-\t\t\tif (data_->mainPath_->validate(sensor, &tryCfg) == Valid) {\n+\t\t\tif (data_->mainPath_->validate(sensor, sensorConfig, &tryCfg) == Valid) {\n \t\t\t\tmainPathAvailable = false;\n \t\t\t\tcfg = tryCfg;\n \t\t\t\tcfg.setStream(const_cast<Stream *>(&data_->mainPathStream_));\n@@ -550,7 +576,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \n \t\tif (selfPathAvailable) {\n \t\t\tStreamConfiguration tryCfg = cfg;\n-\t\t\tif (data_->selfPath_->validate(sensor, &tryCfg) == Valid) {\n+\t\t\tif (data_->selfPath_->validate(sensor, sensorConfig, &tryCfg) == Valid) {\n \t\t\t\tselfPathAvailable = false;\n \t\t\t\tcfg = tryCfg;\n \t\t\t\tcfg.setStream(const_cast<Stream *>(&data_->selfPathStream_));\n@@ -561,7 +587,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\t/* Try to match stream allowing adjusting configuration. */\n \t\tif (mainPathAvailable) {\n \t\t\tStreamConfiguration tryCfg = cfg;\n-\t\t\tif (data_->mainPath_->validate(sensor, &tryCfg) == Adjusted) {\n+\t\t\tif (data_->mainPath_->validate(sensor, sensorConfig, &tryCfg) == Adjusted) {\n \t\t\t\tmainPathAvailable = false;\n \t\t\t\tcfg = tryCfg;\n \t\t\t\tcfg.setStream(const_cast<Stream *>(&data_->mainPathStream_));\n@@ -572,7 +598,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \n \t\tif (selfPathAvailable) {\n \t\t\tStreamConfiguration tryCfg = cfg;\n-\t\t\tif (data_->selfPath_->validate(sensor, &tryCfg) == Adjusted) {\n+\t\t\tif (data_->selfPath_->validate(sensor, sensorConfig, &tryCfg) == Adjusted) {\n \t\t\t\tselfPathAvailable = false;\n \t\t\t\tcfg = tryCfg;\n \t\t\t\tcfg.setStream(const_cast<Stream *>(&data_->selfPathStream_));\n@@ -589,26 +615,63 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \n \t/* Select the sensor format. */\n \tPixelFormat rawFormat;\n+\tSize rawSize;\n \tSize maxSize;\n \n \tfor (const StreamConfiguration &cfg : config_) {\n-\t\tif (cfg.pixelFormat.isRaw())\n+\t\tif (cfg.pixelFormat.isRaw()) {\n \t\t\trawFormat = cfg.pixelFormat;\n+\t\t\trawSize = cfg.size;\n+\t\t}\n \n \t\tmaxSize = std::max(maxSize, cfg.size);\n \t}\n \n+\tif (rawFormat.isValid() && sensorConfig) {\n+\t\tif (sensorConfig->outputSize != rawSize) {\n+\t\t\tsensorConfig->outputSize = rawSize;\n+\t\t\tstatus = Adjusted;\n+\t\t}\n+\n+\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(rawFormat);\n+\t\tif (sensorConfig->bitDepth != info.bitsPerPixel) {\n+\t\t\tsensorConfig->bitDepth = info.bitsPerPixel;\n+\t\t\tstatus = Adjusted;\n+\t\t}\n+\t}\n+\n \tstd::vector<unsigned int> mbusCodes;\n+\tSize sz = maxSize;\n \n \tif (rawFormat.isValid()) {\n \t\tmbusCodes = { rawFormats.at(rawFormat) };\n+\t\tsz = rawSize;\n+\t} else if (sensorConfig) {\n+\t\tfor (const auto &value : rawFormats) {\n+\t\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(value.first);\n+\t\t\tif (info.bitsPerPixel == sensorConfig->bitDepth)\n+\t\t\t\tmbusCodes.push_back(value.second);\n+\t\t}\n+\t\tsz = sensorConfig->outputSize;\n \t} else {\n \t\tstd::transform(rawFormats.begin(), rawFormats.end(),\n \t\t\t       std::back_inserter(mbusCodes),\n \t\t\t       [](const auto &value) { return value.second; });\n \t}\n \n-\tsensorFormat_ = sensor->getFormat(mbusCodes, maxSize);\n+\tsensorFormat_ = sensor->getFormat(mbusCodes, sz);\n+\tif (sensorConfig) {\n+\t\tint ret = data_->sensor_->applyConfiguration(*sensorConfig,\n+\t\t\t\t\t\t\t     combinedTransform_,\n+\t\t\t\t\t\t\t     &sensorFormat_);\n+\t\tif (ret) {\n+\t\t\tLOG(RkISP1, Error)\n+\t\t\t\t<< \"Sensor Configuration not supported: \"\n+\t\t\t\t<< strerror(-ret);\n+\n+\t\t\treturn Invalid;\n+\t\t}\n+\t}\n \n \tif (sensorFormat_.size.isNull())\n \t\tsensorFormat_.size = sensor->resolution();\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\nindex 7c1f0c73..30becb75 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n@@ -253,8 +253,10 @@ RkISP1Path::generateConfiguration(const CameraSensor *sensor, const Size &size,\n \treturn cfg;\n }\n \n-CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,\n-\t\t\t\t\t\t StreamConfiguration *cfg)\n+CameraConfiguration::Status\n+RkISP1Path::validate(const CameraSensor *sensor,\n+\t\t     std::optional<SensorConfiguration> sensorConfig,\n+\t\t     StreamConfiguration *cfg)\n {\n \tconst std::vector<unsigned int> &mbusCodes = sensor->mbusCodes();\n \tSize resolution = filterSensorResolution(sensor);\n@@ -281,12 +283,18 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,\n \t\t\t    mbusCodes.end())\n \t\t\t\tcontinue;\n \n-\t\t\t/*\n-\t\t\t * Store the raw format with the highest bits per pixel\n-\t\t\t * for later usage.\n+\t\t\t/* If the bits per pixel is supplied from the sensor\n+\t\t\t * configuration, choose a raw format that complies with\n+\t\t\t * it. Otherwise, store the raw format with the highest\n+\t\t\t * bits per pixel for later usage.\n \t\t\t */\n \t\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(format);\n-\t\t\tif (info.bitsPerPixel > rawBitsPerPixel) {\n+\n+\t\t\tif (sensorConfig &&\n+\t\t\t    info.bitsPerPixel == sensorConfig->bitDepth) {\n+\t\t\t\trawFormat = format;\n+\t\t\t\trawBitsPerPixel = info.bitsPerPixel;\n+\t\t\t} else if (info.bitsPerPixel > rawBitsPerPixel) {\n \t\t\t\trawBitsPerPixel = info.bitsPerPixel;\n \t\t\t\trawFormat = format;\n \t\t\t}\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\nindex 9f75fe1f..8aae00ef 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n@@ -27,6 +27,7 @@ namespace libcamera {\n class CameraSensor;\n class MediaDevice;\n class V4L2Subdevice;\n+class SensorConfiguration;\n struct StreamConfiguration;\n struct V4L2SubdeviceFormat;\n \n@@ -45,6 +46,7 @@ public:\n \t\t\t\t\t\t  const Size &resolution,\n \t\t\t\t\t\t  StreamRole role);\n \tCameraConfiguration::Status validate(const CameraSensor *sensor,\n+\t\t\t\t\t     std::optional<SensorConfiguration> sensorConfig,\n \t\t\t\t\t     StreamConfiguration *cfg);\n \n \tint configure(const StreamConfiguration &config,\n",
    "prefixes": []
}