From patchwork Thu Nov 19 13:13:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10451 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 70C79BE176 for ; Thu, 19 Nov 2020 13:13:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E00D615A4; Thu, 19 Nov 2020 14:13:40 +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="B4yt/NqF"; dkim-atps=neutral Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F308B615A4 for ; Thu, 19 Nov 2020 14:13:38 +0100 (CET) Received: by mail-ej1-x642.google.com with SMTP id f20so7828094ejz.4 for ; Thu, 19 Nov 2020 05:13:38 -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=RF8lsmNJBvg1jM+l8YKrOTVIOplSv3bSXXdpHvOv4GE=; b=B4yt/NqFIxqtfGmynnlj1MddQL71ygY42OIWIEgtP5xkOpPHjens8aMuMqzWUSvG6z dwny/nBt6sJBx9gEg6CW2zpXPzXnMGe3aGTfJi8QWdw+5Bc/cHyUcZXKKCFTmtnVy+IM N0nR44DqLmiHy1ujpw0v2JXxW1Lx9dCHXeDf2o8lCog+Ld7PngljGn7wwbNdoqyfgZhC 3TNv5/6WgBWBWJkZK+98uri3PoR4uC7lv2pXiKwAVwlG4xMMC/xRed9zoV/I/YO8sbze gf81E1IZkv4EBXzWAm9+ZQio3c87nu+hxGejNjDC7A1QaLBB2XdxeM1vh9MKIyziEIGB 1eSw== 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=RF8lsmNJBvg1jM+l8YKrOTVIOplSv3bSXXdpHvOv4GE=; b=uR9gdWEuKV8YBMiS5H1G4XdLUgdNtRPgy6kEHAvZyOHz7yPwe6O6V6uTkizXEAWib3 y7JSx3fDZ5zL03Dp+96pizvObYGkd+TEb/pCTeyKXaMDKLDEZFf0qd6p9JKlA1e8C4g3 qM/OEePtVhFcvZpjhaxIM5hrU9w0G1/ySKg5q6MRrnp33OnyGJl61qtq1PfUheb2xb33 Zkx4Ggyg2r533knJmwqUzr9Zrk7DWZXYZLeu/7eTkRCFJngYrG5CGSDdT7ghkM77uZkm uoitHIsP4AsYmsq7W+X3MsGDWQXGukBJCQe+PT9Yddl1IYaix4kyI1BJ5GurHlR2BByd 7HHg== X-Gm-Message-State: AOAM5323f+GQOkOV/Ho3B8JDkrbUxrxOVif6MmK9j6Ot391cR74VXWeX oGoxLiLQulpSQO2QzHQlI6KIqosTS6d3IA== X-Google-Smtp-Source: ABdhPJxd9arKQc0ugwRor7H/fVpvo7Ts8lrC9xeRLZlJPwdt9OMyLfkzxt+2A8P3z0GWkDRQVhwSjA== X-Received: by 2002:a17:906:4699:: with SMTP id a25mr27320878ejr.284.1605791618372; Thu, 19 Nov 2020 05:13:38 -0800 (PST) Received: from basti.fritz.box (p200300d1ff000d00631290ba0e9702d8.dip0.t-ipconnect.de. [2003:d1:ff00:d00:6312:90ba:e97:2d8]) by smtp.gmail.com with ESMTPSA id d19sm15056135eds.31.2020.11.19.05.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 05:13:37 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Thu, 19 Nov 2020 14:13:31 +0100 Message-Id: <20201119131331.30847-2-sebastian.fricke.linux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201119131331.30847-1-sebastian.fricke.linux@gmail.com> References: <20201119131331.30847-1-sebastian.fricke.linux@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 | 36 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 1b1922a..621e9bf 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -671,6 +671,9 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) RkISP1CameraData *data = cameraData(camera); CameraSensor *sensor = data->sensor_; int ret; + Size original_format_size = Size(0, 0); + Size max_size = Size(0, 0); + ret = initLinks(camera, sensor, *config); if (ret) @@ -682,17 +685,44 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) */ V4L2SubdeviceFormat format = config->sensorFormat(); LOG(RkISP1, Debug) << "Configuring sensor with " << format.toString(); + // format is changed in setFormat, keep the resolution for comparison + original_format_size = 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 (original_format_size > format.size) { + 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 <= format.size && size > max_size) + max_size = size; + } + if (max_size == 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(), max_size); - 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)