From patchwork Thu Nov 24 02:51:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17857 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 3A1B3C3286 for ; Thu, 24 Nov 2022 02:52:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE6A263328; Thu, 24 Nov 2022 03:52:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669258321; bh=vbZrXKcEm2GXr2rsjpJpTqeKEP7JchVUjp/cZ0lgleg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FcAZRNzVq+AnKekbd/52JWXU6ey2vVlwY2rUYHimA9uIuD784QFKlyO0B3+iIQI+K OMFe6TTXTm/v83Ahb7kbOR1Vny1ARCOrwbYG5WgHxNdY9B2aZGxGwYbRThg98WDuzk +F/64d10uG+/lKv7inIWzicuBozkolK+bkEfTrYuMGZ+X/dJf5PUzgTG3L0VNd8DJU gwm78pGTfHjoiK7fjaUuoY8yVcfN10y1BdTAqNq0uIy0gRA5HyFShPorU4WNqrg+iJ 0i1MmluDchwEZ7NEMC27gSx2N4KxQ0u6SgdvqdsR3S2K0fxBTbB9CJg+cCJE7V1l6q InW5EKYuUXtXg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7CEA96331D for ; Thu, 24 Nov 2022 03:51:58 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UbuAcE8O"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 04DCC7FA; Thu, 24 Nov 2022 03:51:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1669258318; bh=vbZrXKcEm2GXr2rsjpJpTqeKEP7JchVUjp/cZ0lgleg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UbuAcE8OG6OU+RMYsn0X4AQQ4qJvxiquWurytQASFriAqo/zLG5sni/4lHu+j+QBR xtyuZQzfncnat79SrsOKYxyAd2d8EJYMIDYYgz52pl3xOPlHqrfQUqyKu5dV88C8AP 7HrleVYQBzTYel8Q39dLVWmOYbHc92gNUyniKoCI= To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Nov 2022 04:51:30 +0200 Message-Id: <20221124025133.17875-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221124025133.17875-1-laurent.pinchart@ideasonboard.com> References: <20221124025133.17875-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/9] pipeline: rkisp1: Query the driver for formats 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Paul Elder Query the driver for the output formats and sizes that it supports, instead of hardcoding them. This allows future-proofing for formats that are supported by some but not all versions of the driver. As the rkisp1 driver currently does not support VIDIOC_ENUM_FRAMESIZES, fallback to the hardcoded list of supported formats and framesizes. This feature will be added to the driver in parallel, though we cannot guarantee that users will have a new enough kernel for it. Signed-off-by: Paul Elder Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes since v3: - Demote Warning message to Info and rewrite it Changes since v2: - Don't pass V4L2VideoDevice to RkISP1Path::populateFormats() - Use structured binding in for range loop - Use std::set::count() to replace std::find_if() - Don't cache sizes, use std::set instead of std::map - Update min and max resolutions based on enumerated sizes - Drop comment about aspect ratio Changes since v1: - Enumerate and cache framesizes as well - Massage generateConfiguration accordingly - This lets us skip modifying V4L2VideoDevice::formats() to support lack of ENUM_FRAMESIZES - Also requires us to keep the list of hardcoded formats for backward compatibility --- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 51 +++++++++++++++++-- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 8 ++- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 2d38f0fb37ab..7a2b0d172d84 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -41,6 +41,8 @@ bool RkISP1Path::init(MediaDevice *media) if (video_->open() < 0) return false; + populateFormats(); + link_ = media->link("rkisp1_isp", 2, resizer, 0); if (!link_) return false; @@ -48,6 +50,41 @@ bool RkISP1Path::init(MediaDevice *media) return true; } +void RkISP1Path::populateFormats() +{ + V4L2VideoDevice::Formats v4l2Formats = video_->formats(); + if (v4l2Formats.empty()) { + LOG(RkISP1, Info) + << "Failed to enumerate supported formats and sizes, using defaults"; + + for (const PixelFormat &format : formats_) + streamFormats_.insert(format); + return; + } + + minResolution_ = { 65535, 65535 }; + maxResolution_ = { 0, 0 }; + + std::vector formats; + for (const auto &[format, sizes] : v4l2Formats) { + const PixelFormat pixelFormat = format.toPixelFormat(); + const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat); + + /* \todo Add support for RAW formats. */ + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) + continue; + + streamFormats_.insert(pixelFormat); + + for (const auto &size : sizes) { + if (minResolution_ > size.min) + minResolution_ = size.min; + if (maxResolution_ < size.max) + maxResolution_ = size.max; + } + } +} + StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution) { Size maxResolution = maxResolution_.boundedToAspectRatio(resolution) @@ -55,7 +92,7 @@ StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution) Size minResolution = minResolution_.expandedToAspectRatio(resolution); std::map> streamFormats; - for (const PixelFormat &format : formats_) + for (const auto &format : streamFormats_) streamFormats[format] = { { minResolution, maxResolution } }; StreamFormats formats(streamFormats); @@ -72,8 +109,12 @@ CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg) const StreamConfiguration reqCfg = *cfg; CameraConfiguration::Status status = CameraConfiguration::Valid; - if (std::find(formats_.begin(), formats_.end(), cfg->pixelFormat) == - formats_.end()) + /* + * Default to NV12 if the requested format is not supported. All + * versions of the ISP are guaranteed to support NV12 on both the main + * and self paths. + */ + if (!streamFormats_.count(cfg->pixelFormat)) cfg->pixelFormat = formats::NV12; cfg->size.boundTo(maxResolution_); @@ -204,6 +245,10 @@ void RkISP1Path::stop() running_ = false; } +/* + * \todo Remove the hardcoded resolutions and formats once all users will have + * migrated to a recent enough kernel. + */ namespace { constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 }; constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 }; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index f3f1ae391d65..d88effbb6f56 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -57,14 +58,17 @@ public: Signal &bufferReady() { return video_->bufferReady; } private: + void populateFormats(); + static constexpr unsigned int RKISP1_BUFFER_COUNT = 4; const char *name_; bool running_; const Span formats_; - const Size minResolution_; - const Size maxResolution_; + std::set streamFormats_; + Size minResolution_; + Size maxResolution_; std::unique_ptr resizer_; std::unique_ptr video_;