From patchwork Fri Nov 20 12:45:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10456 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 CBAB9BE08A for ; Fri, 20 Nov 2020 12:45:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9AEBE61564; Fri, 20 Nov 2020 13:45:38 +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="CFNsZUPh"; dkim-atps=neutral Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45DDC61564 for ; Fri, 20 Nov 2020 13:45:37 +0100 (CET) Received: by mail-ej1-x643.google.com with SMTP id oq3so12668488ejb.7 for ; Fri, 20 Nov 2020 04:45:37 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=oSGqzQg4SKRtBdyqkNnbRsVBO68Cz9bVSvwczoOzO54=; b=CFNsZUPhlaBkyeG1SHnTak0BZyGP+D+VgaKXuTBqOxa8ryftzZ7ZoiEUToBzMnFfYR v0P5TRBWWbdzpm3/1jKN3ecVw+aYX/6Gw0F5HSOV1Wwgi2MHgY4udtlwlQy0G+z11VXv BqyIkwtr42bZZzQSlJxtEeToSHWPr6h3+ApnnMSo8zHVFpC9P3s6O/PtIR4hpmpKaTY5 pkjORFpqbXto263rkeqTBLaI33Mtak+l8W0O4qvDx4CUwGueo+b346X+ZjyCMXiTKNLr bpvXjuCwqdTBw18NBCaBZiLP/qSqkkDrRn0vV1bxn++6anuuG2KnThuS4KcYkGEY4jKL wunw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=oSGqzQg4SKRtBdyqkNnbRsVBO68Cz9bVSvwczoOzO54=; b=uLownDF+53xOu49LID3i2TAWK7N+mM+r5WMaMoZkRj9PtAb6cV64/M/tg1rz8w6ZL4 od4u9qqZdcAOUYTcj2FdnOrgCwooRzHl0kSuUU2MBY2eDantbSlgTUrfBNWY5mlS60QY W2m9B+MDhNRx4m0aRZgScOBEoK+XhNJx6X0ISYlVWR4L5dhw2z86la+ZtGZVqOHhBG7m ZJtSwrLNFiIR0+xqaDeyMrq8aAHJsOjVD7qSkBFj4T0LOc0HQtumPoVvHOOJMylw1Jz4 zcpYzVxLnhdMA1wnGeLk/um+D42oVRQZn1C3B5O97ghgh5wYywdTHuNS/wzAcpZXG2hB 7lqw== X-Gm-Message-State: AOAM531Wm9I8uZh8KDN4L0QzTLBZBaBT3IYSMCMFI5q6ubdIwaK2ibOt UKUt+wgsget6Wzb0MC2SOQpkY3Jtx6g= X-Google-Smtp-Source: ABdhPJymt/+d4BGECDt75lBc58JiMu7BbaphDHfhQ9eNkTCeRUZq+yUrzYLPiVnSqNdfOGoPDNHB2A== X-Received: by 2002:a17:906:d931:: with SMTP id rn17mr32245820ejb.308.1605876336648; Fri, 20 Nov 2020 04:45:36 -0800 (PST) Received: from basti.fritz.box (p200300d1ff2882007ff0233db4c9f029.dip0.t-ipconnect.de. [2003:d1:ff28:8200:7ff0:233d:b4c9:f029]) by smtp.gmail.com with ESMTPSA id 22sm1093492ejw.27.2020.11.20.04.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 04:45:36 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Fri, 20 Nov 2020 13:45:03 +0100 Message-Id: <20201120124503.22718-2-sebastian.fricke.linux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201120124503.22718-1-sebastian.fricke.linux@gmail.com> References: <20201120124503.22718-1-sebastian.fricke.linux@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/1] 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" 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 Change the order of setting the formats, in order to first check if the requested resolution exceeds the maximum and search for the next smaller available sensor resolution if that is the case. Fail if no viable sensor format was located. 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 --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 46 ++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 1b1922a..3ef8acd 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -677,22 +677,56 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) return ret; /* - * Configure the format on the sensor output and propagate it through - * the pipeline. + * Configure the format at the ISP input and pass it on through + * the pipeline after checking that the maximum resolution allowed + * for the ISP is not exceeded. */ V4L2SubdeviceFormat format = config->sensorFormat(); - LOG(RkISP1, Debug) << "Configuring sensor with " << format.toString(); + LOG(RkISP1, Debug) << "Configuring ISP with " << format.toString(); + /* + * format is changed in setFormat, keep the resolution for comparison + */ + Size originalFormatSize = format.size; - ret = sensor->setFormat(&format); + ret = isp_->setFormat(0, &format); if (ret < 0) return ret; + LOG(RkISP1, Debug) << "ISP configured with " << format.toString(); + + if (originalFormatSize != format.size) { + Size maxSize = Size(0, 0); + LOG(RkISP1, Info) << "Configured resolution is greater than " + "the maximum resolution for the ISP, " + "trying to re-configure to a smaller " + "valid sensor format"; + + for (const Size &size : sensor->sizes()) { + if (size.width > format.size.width || + size.height > format.size.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 = sensor->getFormat(sensor->mbusCodes(), maxSize); - LOG(RkISP1, Debug) << "Sensor configured with " << format.toString(); + ret = isp_->setFormat(0, &format); + if (ret < 0) + return ret; + LOG(RkISP1, Debug) << "ISP re-configured with " + << format.toString(); + } - ret = isp_->setFormat(0, &format); + ret = sensor->setFormat(&format); if (ret < 0) return ret; + LOG(RkISP1, Debug) << "Sensor configured with " << format.toString(); + Rectangle rect(0, 0, format.size); ret = isp_->setSelection(0, V4L2_SEL_TGT_CROP, &rect); if (ret < 0)