From patchwork Sun Dec 13 13:42:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10660 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 EF282C0F1A for ; Sun, 13 Dec 2020 13:43:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 76E116033B; Sun, 13 Dec 2020 14:43:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g/fqz48w"; dkim-atps=neutral Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2133760322 for ; Sun, 13 Dec 2020 14:43:16 +0100 (CET) Received: by mail-wr1-x443.google.com with SMTP id m5so13736754wrx.9 for ; Sun, 13 Dec 2020 05:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4M6iPsppgQfot7CHRP0EYYcM6J7H2HJ6x0eOj6CH1fo=; b=g/fqz48wN+TYgsDtcVva7pqVWhfBGdzWZSr/oW7HvmeNptcMjCur8Sc07SBLmsI7u3 ZlbKj9npysA24X0lVejnmND1W6b8xemrt0opNJghPSKTz/DoWnNgc2/V/T3fGLN6v0Jl nSOyOotpZLzQLENR9iFOZhZnR+4tfLdcEpEMzAvXksz991HyemBoreznWkMdF62A3obM M0ietvqsKB5t+LOoqv5G+skVLx1j/29msZIAd2IAESChXRKjDi2Sb4ekzxFaGWbR1C/r ZjcDIYEIOgrEvJVJkdJ9KBA02yPYr0b3+ZmMAHSskWeaY5Ag8ImwLp2raPFBYVCn6bCK mUtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4M6iPsppgQfot7CHRP0EYYcM6J7H2HJ6x0eOj6CH1fo=; b=SHedRvPfBdeX1107Zh/6DGebbJC4jn73qDCObskS+Lnn6Nu0XZrk0MprL+CNnzhS0v 0n/vsPdVrM2nLvGCnSFPLrq02RzJ27D+pPPp3qZU+jOE+b5TdQXIqeAg9iJHk12hZttJ 315SKo+aU8usv/fi1NMWggBnqIn/dFbJF2ni25Bmv3/tw9dikbLdBNkoX5+tLVMx1w/q wiPQCWd/iyXmb2s6vo12M1wxAjW9swaLNP/xiUGpEABuYWpFXgZ2PKvJC6jW19kDpQaS aUcgpAsmn6VBx2tWBBNCxlX0Y4CK8uwZo9CF/Oblo7dqtmNYp1KyG+vCMG5sBFY2oAoi ZdWA== X-Gm-Message-State: AOAM533Tq4KRW+Y9odf4RbkQqaANWXZlDYAGb+3mZy6RMnxCNqwGB+yC 5vAWAZQ3PlOsvhxQF0Cq0tAu6N8VbCs= X-Google-Smtp-Source: ABdhPJzxwgmp3RzUXO7NsEjC7U2RyJ17p9Y2G9OGlmKHM0bW7XiKfr9D1ZWqwcJxmeIxctGfVEQn/Q== X-Received: by 2002:adf:e541:: with SMTP id z1mr24034806wrm.143.1607866995326; Sun, 13 Dec 2020 05:43:15 -0800 (PST) Received: from basti.fritz.box (p200300d1ff3f43008b35b1d5c468db1a.dip0.t-ipconnect.de. [2003:d1:ff3f:4300:8b35:b1d5:c468:db1a]) by smtp.gmail.com with ESMTPSA id h20sm28360705wrb.21.2020.12.13.05.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Dec 2020 05:43:14 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Sun, 13 Dec 2020 14:42:52 +0100 Message-Id: <20201213134251.7574-1-sebastian.fricke.linux@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] pipeline-rkisp1-Fix-sensor-ISP-format-mismatch 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 fixes a mismatch of image formats during the pipeline creation of the RkISP1. The mismatch happens because the current code does not check if the configured format exceeds the maximum viable resolution of the ISP. Make sure to use a sensor format resolution that is smaller or equal to the maximum allowed resolution for the RkISP1. The maximum resolution is defined within the `rkisp1-common.h` file as: define RKISP1_ISP_MAX_WIDTH        4032 define RKISP1_ISP_MAX_HEIGHT        3024 Enumerate the frame-sizes of the ISP entity and compare the maximum with the configured resolution. This means that some camera sensors can never operate with their maximum resolution, for example on my OV13850 camera sensor, there are two possible resolutions: 4224x3136 & 2112x1568, the first of those two will never be picked as it surpasses the maximum of the ISP. Signed-off-by: Sebastian Fricke Reviewed-by: Helen Koike --- Attention: This patch depends on the following patch for the Linux Kernel media subsystem. https://patchwork.kernel.org/project/linux-media/patch/20201212185306.19135-1-sebastian.fricke.linux@gmail.com/ v1: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015113.html v2: https://lists.libcamera.org/pipermail/libcamera-devel/2020-November/015136.html Changelog: 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 [7:56:14.564557994] [9200] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [7:56:14.565294449] [9200] INFO Camera camera.cpp:890 configuring streams: (0) 1920x1920-NV12 ... [7:56:14.567584898] [9201] INFO RkISP1 rkisp1.cpp:689 Sensor format 4224x3136 is not supported by the ISP (maximum: 4032x3024), trying to re-configure to a smaller sensor format [7:56:14.567738605] [9201] DEBUG RkISP1 rkisp1.cpp:713 Sensor configured with 2112x1568-SBGGR10_1X10 [7:56:14.567941896] [9201] DEBUG RkISP1 rkisp1.cpp:724 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [7:56:14.568196812] [9201] DEBUG RkISP1 rkisp1.cpp:730 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:56:14.568360144] [9201] DEBUG RkISP1 rkisp1.cpp:742 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:56:14.568529602] [9201] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:56:14.568647435] [9201] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 1920x1920-YUYV8_2X8 [7:56:14.568762351] [9201] 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 [7:57:58.012056371] [9204] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [7:57:58.012524202] [9204] INFO Camera camera.cpp:890 configuring streams: (0) 900x600-NV12 ... [7:57:58.014565860] [9205] DEBUG RkISP1 rkisp1.cpp:713 Sensor configured with 2112x1568-SBGGR10_1X10 [7:57:58.014776442] [9205] DEBUG RkISP1 rkisp1.cpp:724 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [7:57:58.014913816] [9205] DEBUG RkISP1 rkisp1.cpp:730 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:57:58.015064607] [9205] DEBUG RkISP1 rkisp1.cpp:742 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:57:58.015230273] [9205] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:57:58.015348689] [9205] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 900x600-YUYV8_2X8 [7:57:58.015463314] [9205] 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 [7:59:52.764968202] [9210] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [7:59:52.765415033] [9210] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12 [7:59:52.765671115] [9210] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 1920x1920-NV12 [7:59:52.765905613] [9210] DEBUG RkISP1 rkisp1_path.cpp:94 Adjusting format from 4500x3500-NV12 to 4416x3312-NV12 [7:59:52.766147987] [9210] DEBUG CameraSensor camera_sensor.cpp:436 'ov13850 1-0010': No supported format or size found Camera configuration adjusted [7:59:52.766558943] [9210] DEBUG CameraSensor camera_sensor.cpp:436 'ov13850 1-0010': No supported format or size found [7:59:52.766702151] [9210] INFO Camera camera.cpp:890 configuring streams: (0) 4416x3312-NV12 ... [7:59:52.768968097] [9211] INFO RkISP1 rkisp1.cpp:689 Sensor format 4224x3136 is not supported by the ISP (maximum: 4032x3024), trying to re-configure to a smaller sensor format [7:59:52.769120347] [9211] DEBUG RkISP1 rkisp1.cpp:713 Sensor configured with 2112x1568-SBGGR10_1X10 [7:59:52.769320721] [9211] DEBUG RkISP1 rkisp1.cpp:724 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [7:59:52.769455762] [9211] DEBUG RkISP1 rkisp1.cpp:730 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:59:52.769606552] [9211] DEBUG RkISP1 rkisp1.cpp:742 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:59:52.769771927] [9211] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [7:59:52.769888301] [9211] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 4416x3312-YUYV8_2X8 [7:59:52.770003217] [9211] 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 [8:03:00.496627233] [9218] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [8:03:00.497419103] [9218] INFO Camera camera.cpp:890 configuring streams: (0) 40x30-NV12 ... [8:03:00.499715966] [9219] DEBUG RkISP1 rkisp1.cpp:713 Sensor configured with 2112x1568-SBGGR10_1X10 [8:03:00.499924215] [9219] DEBUG RkISP1 rkisp1.cpp:724 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [8:03:00.500168047] [9219] DEBUG RkISP1 rkisp1.cpp:730 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [8:03:00.500336630] [9219] DEBUG RkISP1 rkisp1.cpp:742 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [8:03:00.500513087] [9219] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [8:03:00.500632962] [9219] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 40x30-YUYV8_2X8 [8:03:00.500745836] [9219] 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 [8:01:23.689086810] [9215] DEBUG Camera camera.cpp:831 streams configuration: (0) 1920x1920-NV12 [8:01:23.689893848] [9215] INFO Camera camera.cpp:890 configuring streams: (0) 3450x2456-NV12 ... [8:01:23.692257211] [9216] INFO RkISP1 rkisp1.cpp:689 Sensor format 4224x3136 is not supported by the ISP (maximum: 4032x3024), trying to re-configure to a smaller sensor format [8:01:23.692415876] [9216] DEBUG RkISP1 rkisp1.cpp:713 Sensor configured with 2112x1568-SBGGR10_1X10 [8:01:23.692615084] [9216] DEBUG RkISP1 rkisp1.cpp:724 ISP input pad configured with 2112x1568-SBGGR10_1X10 crop (0x0)/2112x1568 [8:01:23.692753041] [9216] DEBUG RkISP1 rkisp1.cpp:730 Configuring ISP output pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [8:01:23.692901499] [9216] DEBUG RkISP1 rkisp1.cpp:742 ISP output pad configured with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [8:01:23.693066581] [9216] DEBUG RkISP1 rkisp1_path.cpp:119 Configured main resizer input pad with 2112x1568-YUYV8_2X8 crop (0x0)/2112x1568 [8:01:23.693183831] [9216] DEBUG RkISP1 rkisp1_path.cpp:125 Configuring main resizer output pad with 3450x2456-YUYV8_2X8 [8:01:23.693297289] [9216] DEBUG RkISP1 rkisp1_path.cpp:143 Configured main resizer output pad with 3450x2456-YUYV8_1_5X8 --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 34 +++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 4d98c902..d6fc624c 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -667,12 +667,44 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) if (ret) return ret; + V4L2Subdevice::Formats ispFormats = isp_->formats(0); + if (ispFormats.empty()) + return -1; + + /* + * The maximum resolution is identical for all media bus codes on + * the RkISP1 isp entity. Therefore take the first available resolution. + */ + Size ispMaximum = ispFormats.begin()->second[0].max; + /* * Configure the format on the sensor output and propagate it through * the pipeline. */ V4L2SubdeviceFormat format = config->sensorFormat(); - LOG(RkISP1, Debug) << "Configuring sensor with " << format.toString(); + + if (ispMaximum.width < format.size.width || + ispMaximum.height < format.size.height) { + Size maxSize; + LOG(RkISP1, Info) << "Sensor format " << format.size.toString() + << " is not supported by the ISP (maximum: " + << ispMaximum.toString() << "), trying to " + << "re-configure to a smaller sensor format"; + + for (const Size &size : sensor->sizes()) { + if (size.width > ispMaximum.width || + size.height > ispMaximum.height) + continue; + maxSize = std::max(maxSize, size); + } + if (maxSize == Size(0, 0)) { + LOG(RkISP1, Error) << "No available sensor resolution" + "that is smaller or equal to " + << format.toString(); + return -1; + } + format.size = maxSize; + } ret = sensor->setFormat(&format); if (ret < 0)