Patch Detail
Show a patch.
GET /api/1.1/patches/19412/?format=api
{ "id": 19412, "url": "https://patchwork.libcamera.org/api/1.1/patches/19412/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19412/", "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": "<20240116091754.100654-4-paul.elder@ideasonboard.com>", "date": "2024-01-16T09:17:54", "name": "[libcamera-devel,3/3] pipeline: rkisp1: Plumb SensorConfiguration", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "aa8122f332329d4ae3f39f181bf87dd848eb4d40", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19412/mbox/", "series": [ { "id": 4143, "url": "https://patchwork.libcamera.org/api/1.1/series/4143/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4143", "date": "2024-01-16T09:17:51", "name": "i.MX8MP support, plus misc fixes", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4143/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19412/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19412/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 781B7C32BC\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Jan 2024 09:18:40 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 10CAD628EC;\n\tTue, 16 Jan 2024 10:18:40 +0100 (CET)", "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 C9306628D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Jan 2024 10:18:35 +0100 (CET)", "from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp\n\t[175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DF1A415B5;\n\tTue, 16 Jan 2024 10:17:25 +0100 (CET)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1705396720;\n\tbh=y5hJ9bKEkJDrsNyEjY73xRUJguA4iG6nxTtKXqgBf8A=;\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:\n\tFrom;\n\tb=oe1wkcE/wgpetT8lliJvFl3jV/RTMgTrFesTYE7/CpQoVS2mrEp1pG6ENFsivsKNN\n\t4RXME5ImWflWUK6vrWa8nitos/P9JwnGJ2aZP+wdsZOKczTlpLzbVlOkGP+JCQkRMT\n\tm5+hGJSVVP0y7sEKJL7WMy5iALxw1dbzv1LwtTgeDVeR8wIIB9o0dVqNIogf2/l9GW\n\tT7ZpDXn2lgzIGCw0wSmYg7T2CThVvIxA1bXEUCK776K8FNO/DYu41YlGuE/Zew3kl8\n\tyf6wNMwBKv926v6+vfvlLswwzDbE83ZtxrxZUxR0YMPzobnWCCdMif7pher14A+Z+Z\n\t/bYAScSUoWN8g==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1705396646;\n\tbh=y5hJ9bKEkJDrsNyEjY73xRUJguA4iG6nxTtKXqgBf8A=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Jo1ekhYa6f5W/4Z9DgB3zlZAuQ6JjvTVnEXfMWk4jBcDx22crIMVQR8EfXxroLo7l\n\tBSFnQco4sDOJXVaJ7SQUbDGUZDxaM7klsTdw7E8gFXD5fTnDBlKCo5DZow2kD3v452\n\tf/78Op4ZnlC7Nnc7SIRyXQ5H9YP4ebqJAZAe/Vn4=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Jo1ekhYa\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 16 Jan 2024 18:17:54 +0900", "Message-Id": "<20240116091754.100654-4-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.39.2", "In-Reply-To": "<20240116091754.100654-1-paul.elder@ideasonboard.com>", "References": "<20240116091754.100654-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 3/3] pipeline: rkisp1: Plumb\n\tSensorConfiguration", "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": "Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Paul Elder <paul.elder@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add support to the rkisp1 pipeline handler for validating and\nconfiguring SensorConfiguration.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 97 ++++++++++++++++---\n src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 37 +++++--\n src/libcamera/pipeline/rkisp1/rkisp1_path.h | 3 +-\n 3 files changed, 115 insertions(+), 22 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex fb67ba8f4..74da9c1b1 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -128,7 +128,8 @@ public:\n \tconst Transform &combinedTransform() { return combinedTransform_; }\n \n private:\n-\tbool fitsAllPaths(const StreamConfiguration &cfg);\n+\tbool fitsAllPaths(const StreamConfiguration &cfg,\n+\t\t\t std::optional<unsigned int> sensorBPP);\n \n \t/*\n \t * The RkISP1CameraData instance is guaranteed to be valid as long as the\n@@ -448,17 +449,18 @@ RkISP1CameraConfiguration::RkISP1CameraConfiguration(Camera *camera,\n \tdata_ = data;\n }\n \n-bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg)\n+bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg,\n+\t\t\t\t\t std::optional<unsigned int> sensorBPP)\n {\n \tconst CameraSensor *sensor = data_->sensor_.get();\n \tStreamConfiguration config;\n \n \tconfig = cfg;\n-\tif (data_->mainPath_->validate(sensor, &config) != Valid)\n+\tif (data_->mainPath_->validate(sensor, &config, sensorBPP) != Valid)\n \t\treturn false;\n \n \tconfig = cfg;\n-\tif (data_->selfPath_ && data_->selfPath_->validate(sensor, &config) != Valid)\n+\tif (data_->selfPath_ && data_->selfPath_->validate(sensor, &config, sensorBPP) != Valid)\n \t\treturn false;\n \n \treturn true;\n@@ -475,6 +477,24 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \n \tstatus = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);\n \n+\t/*\n+\t * For the sensor configuration, default to the first supported bit\n+\t * depth for the sensor configuration if an unsupported one is\n+\t * supplied.\n+\t */\n+\tstd::optional<unsigned int> bitDepth;\n+\tif (sensorConfig) {\n+\t\tbitDepth = sensorConfig->bitDepth;\n+\t\tif (bitDepth != 8 && bitDepth != 10 && bitDepth != 12) {\n+\t\t\tV4L2SubdeviceFormat format = {};\n+\t\t\tformat.mbus_code = data_->sensor_->mbusCodes().at(0);\n+\n+\t\t\tsensorConfig->bitDepth = format.bitsPerPixel();\n+\t\t\tbitDepth = sensorConfig->bitDepth;\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@@ -510,7 +530,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t */\n \tstd::vector<unsigned int> order(config_.size());\n \tstd::iota(order.begin(), order.end(), 0);\n-\tif (config_.size() == 2 && fitsAllPaths(config_[0]))\n+\tif (config_.size() == 2 && fitsAllPaths(config_[0], bitDepth))\n \t\tstd::reverse(order.begin(), order.end());\n \n \tbool mainPathAvailable = true;\n@@ -521,7 +541,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, &tryCfg, bitDepth) == 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@@ -531,7 +551,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, &tryCfg, bitDepth) == 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@@ -542,7 +562,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, &tryCfg, bitDepth) == 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@@ -553,7 +573,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, &tryCfg, bitDepth) == 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@@ -570,28 +590,75 @@ 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\tconst PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);\n-\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)\n+\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) {\n \t\t\trawFormat = cfg.pixelFormat;\n+\t\t\trawSize = cfg.size;\n+\t\t}\n \n+\t\t/* path->validate binds this to a sensor-supported resolution */\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} else if (!rawFormat.isValid() && sensorConfig) {\n+\t\t/*\n+\t\t * TODO Handle this properly taking into account the upscaling\n+\t\t * capabilities and dual ISP mode (for the i.MX8MP).\n+\t\t *\n+\t\t * x1.5 should be a reasonable hardcoded ballpark for now.\n+\t\t */\n+\t\tdouble factor = 1.5;\n+\t\tSize before = sensorConfig->outputSize;\n+\t\tSize upscaleLimit = {\n+\t\t\tstatic_cast<unsigned int>(maxSize.width / factor),\n+\t\t\tstatic_cast<unsigned int>(maxSize.height / factor)\n+\t\t};\n+\n+\t\tif (sensorConfig->outputSize < upscaleLimit)\n+\t\t\tsensorConfig->outputSize = maxSize;\n+\n+\t\tif (before != sensorConfig->outputSize)\n+\t\t\tstatus = Adjusted;\n+\n+\t\t/* No need to validate bpp for non-raw */\n+\t}\n+\n \tstd::vector<unsigned int> mbusCodes;\n+\tSize size = maxSize;\n \n \tif (rawFormat.isValid()) {\n \t\tmbusCodes = { rawFormats.at(rawFormat) };\n+\t\tsize = 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} 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, size);\n \n+\t/* This should never happen if sensorConfig is valid */\n \tif (sensorFormat_.size.isNull())\n \t\tsensorFormat_.size = sensor->resolution();\n \n@@ -730,7 +797,13 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \tV4L2SubdeviceFormat format = config->sensorFormat();\n \tLOG(RkISP1, Debug) << \"Configuring sensor with \" << format;\n \n-\tret = sensor->setFormat(&format, config->combinedTransform());\n+\tif (config->sensorConfig) {\n+\t\tret = sensor->applyConfiguration(*config->sensorConfig,\n+\t\t\t\t\t\t config->combinedTransform(), &format);\n+\t} else {\n+\t\tret = sensor->setFormat(&format, config->combinedTransform());\n+\t}\n+\n \tif (ret < 0)\n \t\treturn ret;\n \ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\nindex eaab7e857..a598b289b 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n@@ -220,7 +220,8 @@ RkISP1Path::generateConfiguration(const CameraSensor *sensor, const Size &size,\n }\n \n CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,\n-\t\t\t\t\t\t StreamConfiguration *cfg)\n+\t\t\t\t\t\t StreamConfiguration *cfg,\n+\t\t\t\t\t\t std::optional<unsigned int> sensorBPP)\n {\n \tconst std::vector<unsigned int> &mbusCodes = sensor->mbusCodes();\n \tconst Size &resolution = sensor->resolution();\n@@ -231,10 +232,15 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,\n \t/*\n \t * Validate the pixel format. If the requested format isn't supported,\n \t * default to either NV12 (all versions of the ISP are guaranteed to\n-\t * support NV12 on both the main and self paths) if the requested format\n-\t * is not a raw format, or to the supported raw format with the highest\n-\t * bits per pixel otherwise.\n+\t * support NV12 on both the main and self paths) if the requested\n+\t * format is not a raw format, or otherwise to a supported raw format\n+\t * with the same number of bits per pixel, or to maximum bits per pixel\n+\t * if the same is not supported.\n \t */\n+\tconst PixelFormatInfo &formatInfo = PixelFormatInfo::info(cfg->pixelFormat);\n+\tunsigned int reqRawBitsPerPixel = formatInfo.bitsPerPixel;\n+\tPixelFormat reqRawFormat;\n+\n \tunsigned int rawBitsPerPixel = 0;\n \tPixelFormat rawFormat;\n \tbool found = false;\n@@ -250,12 +256,22 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,\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\n+\t\t\t * with it. Otherwise store the raw format with the\n+\t\t\t * highest bits per pixel for later usage.\n \t\t\t */\n-\t\t\tif (info.bitsPerPixel > rawBitsPerPixel) {\n-\t\t\t\trawBitsPerPixel = info.bitsPerPixel;\n-\t\t\t\trawFormat = format;\n+\t\t\tif (sensorBPP) {\n+\t\t\t\tif (info.bitsPerPixel == sensorBPP)\n+\t\t\t\t\trawFormat = format;\n+\t\t\t} else {\n+\t\t\t\tif (info.bitsPerPixel == reqRawBitsPerPixel)\n+\t\t\t\t\treqRawFormat = format;\n+\n+\t\t\t\tif (info.bitsPerPixel > rawBitsPerPixel) {\n+\t\t\t\t\trawBitsPerPixel = info.bitsPerPixel;\n+\t\t\t\t\trawFormat = format;\n+\t\t\t\t}\n \t\t\t}\n \t\t}\n \n@@ -265,6 +281,9 @@ CameraConfiguration::Status RkISP1Path::validate(const CameraSensor *sensor,\n \t\t}\n \t}\n \n+\tif (reqRawFormat.isValid())\n+\t\trawFormat = reqRawFormat;\n+\n \tbool isRaw = PixelFormatInfo::info(cfg->pixelFormat).colourEncoding ==\n \t\t PixelFormatInfo::ColourEncodingRAW;\n \ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\nindex c96bd5557..784bcea77 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n@@ -44,7 +44,8 @@ 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 StreamConfiguration *cfg);\n+\t\t\t\t\t StreamConfiguration *cfg,\n+\t\t\t\t\t std::optional<unsigned int> sensorBPP);\n \n \tint configure(const StreamConfiguration &config,\n \t\t const V4L2SubdeviceFormat &inputFormat);\n", "prefixes": [ "libcamera-devel", "3/3" ] }