Patch Detail
Show a patch.
GET /api/1.1/patches/11180/?format=api
{ "id": 11180, "url": "https://patchwork.libcamera.org/api/1.1/patches/11180/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11180/", "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": "<20210207125805.82180-1-sebastian.fricke@posteo.net>", "date": "2021-02-07T12:58:06", "name": "[libcamera-devel,v4] pipeline-rkisp1-Fix-sensor-ISP-format-mismatch", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "3a5add6d8cf69184b1ce133d3589e1fcf1158b6f", "submitter": { "id": 78, "url": "https://patchwork.libcamera.org/api/1.1/people/78/?format=api", "name": "Sebastian Fricke", "email": "sebastian.fricke@posteo.net" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11180/mbox/", "series": [ { "id": 1660, "url": "https://patchwork.libcamera.org/api/1.1/series/1660/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1660", "date": "2021-02-07T12:58:06", "name": "[libcamera-devel,v4] pipeline-rkisp1-Fix-sensor-ISP-format-mismatch", "version": 4, "mbox": "https://patchwork.libcamera.org/series/1660/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11180/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11180/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 ED39FBD162\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 7 Feb 2021 12:59:11 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 812F0601AF;\n\tSun, 7 Feb 2021 13:59:11 +0100 (CET)", "from mout01.posteo.de (mout01.posteo.de [185.67.36.65])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8CE54601AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 7 Feb 2021 13:59:09 +0100 (CET)", "from submission (posteo.de [89.146.220.130]) \n\tby mout01.posteo.de (Postfix) with ESMTPS id BF052160063\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 7 Feb 2021 13:59:08 +0100 (CET)", "from customer (localhost [127.0.0.1])\n\tby submission (posteo.de) with ESMTPSA id 4DYTkM5TY6z9rxW;\n\tSun, 7 Feb 2021 13:59:07 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=posteo.net header.i=@posteo.net\n\theader.b=\"PDrGZDMV\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;\n\tt=1612702748; bh=FiX//AHovBHvhY/baFtNw+baxK1nJPsZLrfcGcVqS0U=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=PDrGZDMVFg8V73DAsNms/smKe6geakLrzPpGx96jO1gvEHLt3Yw9Tj0MU+XG76yIn\n\tsIrFhtCYJXxxSP8/UpAbjxq0G64j3gds2pZObfiXK+f9idp4L1OEoWfmjemasUH7TT\n\twMfEjLu3skr78VLMhxKjobCO8m+hbxtaaHbxesc7nILN7U40geglB3w/53HY1USsXH\n\tSGFk6b4r66xcVYZItkrhDfIDOHgkQ7BuUqX5RZxVtV9U7gL6bPIg8HEDnY1xEnTx3+\n\tsDoZ3N87FMqNkU6xPoIs/tUGOFxN0jjNTt/KjsqT0Emi7b5PIuIhFJqohJXuUzipFd\n\tQZ3hU1HlGY1tQ==", "From": "Sebastian Fricke <sebastian.fricke@posteo.net>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 7 Feb 2021 13:58:06 +0100", "Message-Id": "<20210207125805.82180-1-sebastian.fricke@posteo.net>", "X-Mailer": "git-send-email 2.25.1", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v4]\n\tpipeline-rkisp1-Fix-sensor-ISP-format-mismatch", "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>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "This patch fixes a mismatch of image formats during the pipeline\ncreation of the RkISP1. The mismatch happens because the current code\ndoes not check if the configured format exceeds the maximum viable\nresolution of the ISP.\n\nMake sure to use a sensor format resolution that is smaller or equal to\nthe maximum allowed resolution for the RkISP1. The maximum resolution\nis defined within the `rkisp1-common.h` file as:\ndefine RKISP1_ISP_MAX_WIDTH 4032\ndefine RKISP1_ISP_MAX_HEIGHT 3024\n\nEnumerate the frame-sizes of the ISP entity and compare the maximum with\nthe configured resolution. Additionally, make sure that the media bus code\nof the format is valid on the ISP.\n\nThis means that some camera sensors can never operate with their maximum\nresolution, for example on my OV13850 camera sensor, there are two\npossible resolutions: 4224x3136 & 2112x1568, the first of those two will\nnever be picked as it surpasses the maximum of the ISP.\n\nSigned-off-by: Sebastian Fricke <sebastian.fricke@posteo.net>\n---\n\nv1: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015113.html\nv2: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015136.html\nv3: https://patchwork.libcamera.org/patch/10660/\n\nChangelog:\n\nChanges since v3:\n\n* Introduce a helper method for finding the correct sensor format:\n `findBestFitFormat`\n* Besides checking for a valid format resolution also check for a\n matching media bus code\n* Return -EINVAL on an error instead of -1\n* Add documentation for the `findBestFitFormat` method\n\nChanges since v2:\n\n* Replace the act of attempting to set the ISP format before negotiating\n the actual format for both the ISP input pad and the sensor in order\n to get the maximum frame size. With a logic that involves enumerating\n the maximum size directly from the subdevice and using that size for\n the negotiation process.\n* Improve the log messages\n\nChanges since v1:\n\n* Change snake_case variable names to camelCase\n* Use the request comment style\n* Correct the scope of the newly implemented variables\n* Correct the subject of the debug log for the ISP format configuration\n* Update the comment above the ISP format configuration\n* Check if the original format is not equal to the configured ISP format\n instead of checking if it is greater, this denies a false positive\n where the height exceeds the maximum while the width is smaller.\n If the configured format does not exceed the maximum resolution of the\n ISP, it will stay untouched so the inequality always means that we\n have to reconfigure the format.\n* Adjust the comparison of the ISP format size with the available sensor\n formats, to detect a false-positive were the width is smaller while\n the height exceeds the maximum\n* Use the standard function `max`\n\n-----\n\nThe following tests were all able to create a working camera pipeline:\n1. Without stream configuration\n2. With a normal stream configuration\n3. With a stream configuration that exceeds the maximum of the ISP\n4. With a very small resolution stream configuration\n5. With a configuration that is closer to the upper than to the lower\nresolution\n\n-----\n\n1. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3\n\n[6:41:00.383092648] [28903] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12\n[6:41:00.383284855] [28903] INFO Camera camera.cpp:890 configuring streams: (0) 1920x1920-NV12\n...\n[6:41:00.384053394] [28904] INFO RkISP1 rkisp1.cpp:573 Sensor format 4224x3136 is not supported by the ISP (maximum: 4032x3024), trying to re-configure to a smaller sensor format\n[6:41:00.384124851] [28904] DEBUG RkISP1 rkisp1.cpp:637 Sensor configured with 2112x1568-SBGGR10_1X10\n[6:41:00.384184351] [28904] DEBUG RkISP1 rkisp1.cpp:648 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568\n[6:41:00.384214684] [28904] DEBUG RkISP1 rkisp1.cpp:654 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:41:00.384252309] [28904] DEBUG RkISP1 rkisp1.cpp:666 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:41:00.384295184] [28904] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:41:00.384324059] [28904] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 1920x1920-YUYV8_2X8\n[6:41:00.384351475] [28904] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 1920x1920-YUYV8_1_5X8\n\n2. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=900,height=600,pixelformat=NV12,role=video\n\n[6:51:11.037976397] [28922] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12\n[6:51:11.038439562] [28922] INFO Camera camera.cpp:890 configuring streams: (0) 900x600-NV12\n...\n[6:51:11.040661843] [28923] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10\n[6:51:11.040884092] [28923] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568\n[6:51:11.041015633] [28923] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:51:11.041182757] [28923] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:51:11.041374089] [28923] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:51:11.041498339] [28923] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 900x600-YUYV8_2X8\n[6:51:11.041619380] [28923] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 900x600-YUYV8_1_5X8\n\n3. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=4500,height=3500,pixelformat=NV12,role=video\n\n[6:52:41.156286265] [28926] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12\n[6:52:41.156612639] [28926] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12\n[6:52:41.156745055] [28926] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 1920x1920-NV12\n[6:52:41.156849471] [28926] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12\n[6:52:41.156959137] [28926] DEBUG CameraSensor camera_sensor.cpp:560 'ov13850 1-0010': No supported format or size found\nCamera configuration adjusted\n[6:52:41.157176136] [28926] DEBUG CameraSensor camera_sensor.cpp:560 'ov13850 1-0010': No supported format or size found\n[6:52:41.157245844] [28926] INFO Camera camera.cpp:890 configuring streams: (0) 4416x3312-NV12\n...\n[6:52:41.159387000] [28927] INFO RkISP1 rkisp1.cpp:585 Sensor format 4224x3136 is not supported by the ISP (maximum: 4032x3024), trying to re-configure to a smaller sensor format\n[6:52:41.159552958] [28927] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10\n[6:52:41.159752749] [28927] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568\n[6:52:41.159883123] [28927] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:52:41.160129289] [28927] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:52:41.160322079] [28927] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:52:41.160451870] [28927] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 4416x3312-YUYV8_2X8\n[6:52:41.160574370] [28927] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 4416x3312-YUYV8_1_5X8\n\n4. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=40,height=30,pixelformat=NV12,role=video\n\n[6:53:43.547487714] [28930] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12\n[6:53:43.547902462] [28930] INFO Camera camera.cpp:890 configuring streams: (0) 40x30-NV12\n...\n[6:53:43.550449033] [28931] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10\n[6:53:43.550650282] [28931] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568\n[6:53:43.550773657] [28931] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:53:43.550932323] [28931] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:53:43.551103822] [28931] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:53:43.551222530] [28931] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 40x30-YUYV8_2X8\n[6:53:43.551334237] [28931] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 40x30-YUYV8_1_5X8\n\n5. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=3450,height=2456,pixelformat=NV12,role=video\n\n[6:54:43.212517584] [28933] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12\n[6:54:43.212946040] [28933] INFO Camera camera.cpp:890 configuring streams: (0) 3450x2456-NV12\n...\n[6:54:43.215050739] [28934] INFO RkISP1 rkisp1.cpp:585 Sensor format 4224x3136 is not supported by the ISP (maximum: 4032x3024), trying to re-configure to a smaller sensor format\n[6:54:43.215213779] [28934] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10\n[6:54:43.215416487] [28934] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568\n[6:54:43.215545986] [28934] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:54:43.215710485] [28934] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:54:43.215891026] [28934] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568\n[6:54:43.216104233] [28934] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 3450x2456-YUYV8_2X8\n[6:54:43.216246274] [28934] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 3450x2456-YUYV8_1_5X8\n\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 67 ++++++++++++++++++++++++\n 1 file changed, 67 insertions(+)", "diff": "diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex e85979a7..55b1a10d 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -163,6 +163,8 @@ private:\n \tvoid paramReady(FrameBuffer *buffer);\n \tvoid statReady(FrameBuffer *buffer);\n \tvoid frameStart(uint32_t sequence);\n+\tint findBestFitFormat(V4L2SubdeviceFormat *format,\n+\t\t\t CameraSensor *sensor);\n \n \tint allocateBuffers(Camera *camera);\n \tint freeBuffers(Camera *camera);\n@@ -551,6 +553,67 @@ CameraConfiguration *PipelineHandlerRkISP1::generateConfiguration(Camera *camera\n \treturn config;\n }\n \n+/**\n+ * \\brief Find the closest possible match to the desired configuration format,\n+ * that is valid on the RkISP1.\n+ * \\param[out] format The configuration format for the image sensor\n+ * \\param[in] sensor The camera sensor object\n+ * \\return 0 on success, -1 on failure\n+ */\n+int PipelineHandlerRkISP1::findBestFitFormat(\n+\tV4L2SubdeviceFormat *format, CameraSensor *sensor)\n+{\n+\tV4L2Subdevice::Formats ispFormats = isp_->formats(0);\n+\tif (ispFormats.empty()) {\n+\t\tLOG(RkISP1, Error) << \"Unable to fetch ISP formats.\";\n+\t\treturn -1;\n+\t}\n+\t/*\n+\t * The maximum resolution is identical for all media bus codes on\n+\t * the RkISP1 isp entity. Therefore take the first available resolution.\n+\t */\n+\tSize ispMaximum = ispFormats.begin()->second[0].max;\n+\n+\tif (ispMaximum.width < format->size.width ||\n+\t ispMaximum.height < format->size.height) {\n+\t\tSize maxSize;\n+\t\tLOG(RkISP1, Info) << \"Sensor format \" << format->size.toString()\n+\t\t\t\t << \" is not supported by the ISP (maximum: \"\n+\t\t\t\t << ispMaximum.toString() << \"), trying to \"\n+\t\t\t\t << \"re-configure to a smaller sensor format\";\n+\n+\t\tfor (const Size &size : sensor->sizes()) {\n+\t\t\tif (size.width > ispMaximum.width ||\n+\t\t\t size.height > ispMaximum.height)\n+\t\t\t\tcontinue;\n+\t\t\tmaxSize = std::max(maxSize, size);\n+\t\t}\n+\t\tif (maxSize == Size(0, 0)) {\n+\t\t\tLOG(RkISP1, Error) << \"No avail. sensor resolution <= \"\n+\t\t\t\t\t << format->toString();\n+\t\t\treturn -1;\n+\t\t}\n+\t\tformat->size = maxSize;\n+\t}\n+\n+\tauto mbusCodeMatch = ispFormats.find(format->mbus_code);\n+\tif (mbusCodeMatch == ispFormats.end()) {\n+\t\tformat->mbus_code = 0;\n+\t\tfor (unsigned int mbusCode : sensor->mbusCodes()) {\n+\t\t\tmbusCodeMatch = ispFormats.find(mbusCode);\n+\t\t\tif (mbusCodeMatch != ispFormats.end()) {\n+\t\t\t\tformat->mbus_code = mbusCode;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tif (format->mbus_code == 0) {\n+\t\t\tLOG(RkISP1, Error) << \"No valid sensor mbus-code found\";\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n {\n \tRkISP1CameraConfiguration *config =\n@@ -570,6 +633,10 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \tV4L2SubdeviceFormat format = config->sensorFormat();\n \tLOG(RkISP1, Debug) << \"Configuring sensor with \" << format.toString();\n \n+\tret = findBestFitFormat(&format, sensor);\n+\tif (ret < 0)\n+\t\treturn -EINVAL;\n+\n \tret = sensor->setFormat(&format);\n \tif (ret < 0)\n \t\treturn ret;\n", "prefixes": [ "libcamera-devel", "v4" ] }