From patchwork Sat Feb 27 18:01:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 11406 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D6E81BD1F1 for ; Sat, 27 Feb 2021 18:01:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 21D8B68A62; Sat, 27 Feb 2021 19:01:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=posteo.net header.i=@posteo.net header.b="AkIFuKuz"; dkim-atps=neutral Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F1BC7689DD for ; Sat, 27 Feb 2021 19:01:30 +0100 (CET) Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 4A24B2400FB for ; Sat, 27 Feb 2021 19:01:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1614448890; bh=aUiFPujpvyxM6Ctpfw8vv2A6idn15Gzg8h4Brk9COWc=; h=From:To:Cc:Subject:Date:From; b=AkIFuKuzSQq4X3J3yx2ozjMfCJBFqlY/M16jXnwxTtVjN+HD4AbCcHrYwIxjmAP8n W+89awE/ujlROi+wmhQFVMhEXVlwlPeop+hvk7cNl9NCT3HQF5qoVUqsFZ9sRXefJG ygy+SVP+qERxtwJNBg2B7txT3tYmu4mpc78kzKi8myCYkMQ/5CtVdH/fPx1XL5y7yc TJ2hTGdRjK8u/4XjYOSEZYyh4hMdauh23/oZLU3DnXKvhhvguAZrLWZA3UuGHY+JPi iXd0U/3WX6/7kJQAMpCPmoI6rBySskWN8XqZ97P5sKdgo3ijoZ36ZJ8o1wajJy0TPJ 2z31MAwtlUaoA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DnvV14H0Mz9rxB; Sat, 27 Feb 2021 19:01:29 +0100 (CET) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Sat, 27 Feb 2021 19:01:24 +0100 Message-Id: <20210227180126.37591-1-sebastian.fricke@posteo.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 0/2] Fix a format mismatch within the RkISP1 pipeline X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This patch-set fixes a format mismatch, that occurs when a sensor format is used that is greater than the maximum resolution for the Image Signal Processor. Within the validate method, which is called during the configuration generation, we request the sensor format. We have to check for one special case, that can lead to an oversized sensor resolution. The getFormat method takes the smallest sensor resolution, where the width and height are greater or equal to the input size parameter. Example for a problematic case: Sensor resolutions: - 2112x1568 - 4224x3136 Stream configuration size: - 1920x1920 In this case, the requested resolution for the stream is smaller than the ISP maximum, but the only viable alternative has a height that is smaller than the requested height, so getFormat will pick the oversized resolution. We resolve this issue by making sure, that the stream configuration resolution is smaller than the maximum viable sensor resolution before requesting the best-fit sensor format. Additionally, the ISP subdevice has to be shared with the CameraData class, so that we can access that device within a method of the RkISP1CameraConfiguration class. v1: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015113.html v2: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015136.html v3: https://patchwork.libcamera.org/patch/10660/ v4: https://patchwork.libcamera.org/patch/11180/ Changelog: Changes since v4: * Completely rework the design of the fix, adjust the sensor resolution during the validate() method, in order to have a correct sensor format within configure() * Share the ISP subdevice between the PipelineHandler and the CameraData class, so that the CameraConfiguration class has access to this device Changes since v3: * Introduce a helper method for finding the correct sensor format: `findBestFitFormat` * Besides checking for a valid format resolution also check for a matching media bus code * Return -EINVAL on an error instead of -1 * Add documentation for the `findBestFitFormat` method Changes since v2: * Replace the act of attempting to set the ISP format before negotiating the actual format for both the ISP input pad and the sensor in order to get the maximum frame size. With a logic that involves enumerating the maximum size directly from the subdevice and using that size for the negotiation process. * Improve the log messages Changes since v1: * Change snake_case variable names to camelCase * Use the request comment style * Correct the scope of the newly implemented variables * Correct the subject of the debug log for the ISP format configuration * Update the comment above the ISP format configuration * Check if the original format is not equal to the configured ISP format instead of checking if it is greater, this denies a false positive where the height exceeds the maximum while the width is smaller. If the configured format does not exceed the maximum resolution of the ISP, it will stay untouched so the inequality always means that we have to reconfigure the format. * Adjust the comparison of the ISP format size with the available sensor formats, to detect a false-positive were the width is smaller while the height exceeds the maximum * Use the standard function `max` ----- The following tests were all able to create a working camera pipeline: 1. Without stream configuration 2. With a normal stream configuration 3. With a stream configuration that exceeds the maximum of the ISP 4. With a very small resolution stream configuration 5. With a configuration that is closer to the upper than to the lower resolution ----- 1. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 [9:26:53.975708264] [7581] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [9:26:53.976907882] [7581] INFO Camera camera.cpp:890 configuring streams: (0) 1920x1920-NV12 ... [9:26:53.978132875] [7582] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10 [9:26:53.978232332] [7582] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10 [9:26:53.978358332] [7582] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [9:26:53.978441748] [7582] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:26:53.978548789] [7582] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:26:53.978680621] [7582] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:26:53.978763454] [7582] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 1920x1920-YUYV8_2X8 [9:26:53.978840454] [7582] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 1920x1920-YUYV8_1_5X8 2. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=900,height=600,pixelformat=NV12,role=video [9:27:40.379117478] [7586] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [9:27:40.380064806] [7586] INFO Camera camera.cpp:890 configuring streams: (0) 900x600-NV12 ... [9:27:40.381540047] [7587] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10 [9:27:40.381681796] [7587] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10 [9:27:40.381864670] [7587] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [9:27:40.381985419] [7587] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:27:40.382142335] [7587] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:27:40.382334251] [7587] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:27:40.382452667] [7587] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 900x600-YUYV8_2X8 [9:27:40.382564666] [7587] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 900x600-YUYV8_1_5X8 3. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=4500,height=3500,pixelformat=NV12,role=video [9:28:21.358328098] [7589] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [9:28:21.358584180] [7589] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12 [9:28:21.358701137] [7589] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 1920x1920-NV12 [9:28:21.358801470] [7589] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12 Camera configuration adjusted [9:28:21.359524799] [7589] INFO Camera camera.cpp:890 configuring streams: (0) 4416x3312-NV12 ... [9:28:21.360212587] [7590] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10 [9:28:21.360255753] [7590] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10 [9:28:21.360309419] [7590] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [9:28:21.360340336] [7590] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:28:21.360378252] [7590] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:28:21.360430169] [7590] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:28:21.360459918] [7590] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 4416x3312-YUYV8_2X8 [9:28:21.360487918] [7590] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 4416x3312-YUYV8_1_5X8 4. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=40,height=30,pixelformat=NV12,role=video [9:29:21.653077053] [7592] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [9:29:21.653987340] [7592] INFO Camera camera.cpp:890 configuring streams: (0) 40x30-NV12 ... [9:29:21.655460873] [7593] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10 [9:29:21.655601455] [7593] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10 [9:29:21.655780829] [7593] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [9:29:21.655901578] [7593] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:29:21.656136077] [7593] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:29:21.656356576] [7593] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:29:21.656487533] [7593] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 40x30-YUYV8_2X8 [9:29:21.656608574] [7593] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 40x30-YUYV8_1_5X8 5. LIBCAMERA_LOG_LEVELS=0 cam -c 1 --capture=3 -s width=3450,height=2456,pixelformat=NV12,role=video [9:30:08.027510441] [7595] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [9:30:08.028457768] [7595] INFO Camera camera.cpp:890 configuring streams: (0) 3450x2456-NV12 ... [9:30:08.029969509] [7596] DEBUG RkISP1 rkisp1.cpp:603 Configuring sensor with 2112x1568-SBGGR10_1X10 [9:30:08.030114758] [7596] DEBUG RkISP1 rkisp1.cpp:609 Sensor configured with 2112x1568-SBGGR10_1X10 [9:30:08.030296174] [7596] DEBUG RkISP1 rkisp1.cpp:620 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [9:30:08.030422465] [7596] DEBUG RkISP1 rkisp1.cpp:626 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:30:08.030582881] [7596] DEBUG RkISP1 rkisp1.cpp:638 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:30:08.030776546] [7596] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [9:30:08.030899629] [7596] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 3450x2456-YUYV8_2X8 [9:30:08.031016586] [7596] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 3450x2456-YUYV8_1_5X8 Sebastian Fricke (2): pipeline: rkisp1: Share the ISP subdevice pipeline: rkisp1: Fix sensor ISP format mismatch src/libcamera/pipeline/rkisp1/rkisp1.cpp | 40 +++++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-)