{"id":17673,"url":"https://patchwork.libcamera.org/api/1.1/patches/17673/?format=json","web_url":"https://patchwork.libcamera.org/patch/17673/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221024000356.29521-11-laurent.pinchart@ideasonboard.com>","date":"2022-10-24T00:03:53","name":"[libcamera-devel,v3,10/13] pipeline: rkisp1: Query the driver for formats","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"0267afd01ea5569299af00d714f2c64593d31519","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17673/mbox/","series":[{"id":3574,"url":"https://patchwork.libcamera.org/api/1.1/series/3574/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3574","date":"2022-10-24T00:03:43","name":"Add Bayer format support for RkISP1","version":3,"mbox":"https://patchwork.libcamera.org/series/3574/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17673/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17673/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A9D66C328A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Oct 2022 00:04:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3D5E362F00;\n\tMon, 24 Oct 2022 02:04:39 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0BA1262EF9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Oct 2022 02:04:35 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8314C471;\n\tMon, 24 Oct 2022 02:04:34 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666569879;\n\tbh=lXmxsGaajmMUMaQK4fbBRs1N2A8GSS2qalHjgA39cdw=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=lIz+4yZW0tsPIMrqdfbg+zt2+R7xawiNWCsiajpKjUGQqZzKEHpM4XYG8miBQdMmu\n\t6+SFGAPRlIYqHUEziSm2fdwcJV14C0Ws9PQYotmElXA/IxPhRg2psdZ2wGTYsQeIX5\n\tOHLTCh41+p4WShLToeUBpE6o0ZGRmwVz8SySmXq/9Ul3uL9ySKZQPNrk6aiM6sfOpR\n\tfhBjkMxyZmWtfY53iQPXiZCyoaIHz1sZPvwyZmFQJRA1UVd3K1QMgvyHZTWPXSj4gq\n\tNJXmC140vo8lwEVZQUTPTjZCfS4MsaY8RzqJKGbo1F4bNyaBUlshEZ6zmQuPgonva+\n\t0ZtEgPPQNwIhw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666569874;\n\tbh=lXmxsGaajmMUMaQK4fbBRs1N2A8GSS2qalHjgA39cdw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=UGl1L9GU7v+i3QtK/Abb6dvvbXFh3oNrQD0JV1fqMp4A5TPmZt7zmZPgPHCNjXRMz\n\tsdsLw3Wy1ns02uWB7I1DsVpN1KOedgHw8A970woYijPZFrWOToW2bPV1sly5VnVlTB\n\trYDXDkCzy7PdnRNgA57Ld/Ww+LLrCsDBz7rVP8b4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"UGl1L9GU\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 24 Oct 2022 03:03:53 +0300","Message-Id":"<20221024000356.29521-11-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.37.4","In-Reply-To":"<20221024000356.29521-1-laurent.pinchart@ideasonboard.com>","References":"<20221024000356.29521-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 10/13] pipeline: rkisp1: Query the\n\tdriver for formats","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Paul Elder <paul.elder@ideasonboard.com>\n\nQuery the driver for the output formats and sizes that it supports,\ninstead of hardcoding them. This allows future-proofing for formats that\nare supported by some but not all versions of the driver.\n\nAs the rkisp1 driver currently does not support VIDIOC_ENUM_FRAMESIZES,\nfallback to the hardcoded list of supported formats and framesizes. This\nfeature will be added to the driver in parallel, though we cannot\nguarantee that users will have a new enough kernel for it.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges since v2:\n\n- Don't pass V4L2VideoDevice to RkISP1Path::populateFormats()\n- Use structured binding in for range loop\n- Use std::set::count() to replace std::find_if()\n- Don't cache sizes, use std::set instead of std::map\n- Update min and max resolutions based on enumerated sizes\n- Drop comment about aspect ratio\n\nChanges since v1:\n\n- Enumerate and cache framesizes as well\n- Massage generateConfiguration accordingly\n- This lets us skip modifying V4L2VideoDevice::formats() to support lack\n  of ENUM_FRAMESIZES\n- Also requires us to keep the list of hardcoded formats for backward\n  compatibility\n---\n src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 51 +++++++++++++++++--\n src/libcamera/pipeline/rkisp1/rkisp1_path.h   |  8 ++-\n 2 files changed, 54 insertions(+), 5 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\nindex 2d38f0fb37ab..8077a54494a5 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n@@ -41,6 +41,8 @@ bool RkISP1Path::init(MediaDevice *media)\n \tif (video_->open() < 0)\n \t\treturn false;\n \n+\tpopulateFormats();\n+\n \tlink_ = media->link(\"rkisp1_isp\", 2, resizer, 0);\n \tif (!link_)\n \t\treturn false;\n@@ -48,6 +50,41 @@ bool RkISP1Path::init(MediaDevice *media)\n \treturn true;\n }\n \n+void RkISP1Path::populateFormats()\n+{\n+\tV4L2VideoDevice::Formats v4l2Formats = video_->formats();\n+\tif (v4l2Formats.empty()) {\n+\t\tLOG(RkISP1, Warning)\n+\t\t\t<< \"Failed to enumerate framesizes. Loading default framesizes\";\n+\n+\t\tfor (const PixelFormat &format : formats_)\n+\t\t\tstreamFormats_.insert(format);\n+\t\treturn;\n+\t}\n+\n+\tminResolution_ = { 65535, 65535 };\n+\tmaxResolution_ = { 0, 0 };\n+\n+\tstd::vector<PixelFormat> formats;\n+\tfor (const auto &[format, sizes] : v4l2Formats) {\n+\t\tconst PixelFormat pixelFormat = format.toPixelFormat();\n+\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n+\n+\t\t/* \\todo Add support for RAW formats. */\n+\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)\n+\t\t\tcontinue;\n+\n+\t\tstreamFormats_.insert(pixelFormat);\n+\n+\t\tfor (const auto &size : sizes) {\n+\t\t\tif (minResolution_ > size.min)\n+\t\t\t\tminResolution_ = size.min;\n+\t\t\tif (maxResolution_ < size.max)\n+\t\t\t\tmaxResolution_ = size.max;\n+\t\t}\n+\t}\n+}\n+\n StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution)\n {\n \tSize maxResolution = maxResolution_.boundedToAspectRatio(resolution)\n@@ -55,7 +92,7 @@ StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution)\n \tSize minResolution = minResolution_.expandedToAspectRatio(resolution);\n \n \tstd::map<PixelFormat, std::vector<SizeRange>> streamFormats;\n-\tfor (const PixelFormat &format : formats_)\n+\tfor (const auto &format : streamFormats_)\n \t\tstreamFormats[format] = { { minResolution, maxResolution } };\n \n \tStreamFormats formats(streamFormats);\n@@ -72,8 +109,12 @@ CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg)\n \tconst StreamConfiguration reqCfg = *cfg;\n \tCameraConfiguration::Status status = CameraConfiguration::Valid;\n \n-\tif (std::find(formats_.begin(), formats_.end(), cfg->pixelFormat) ==\n-\t    formats_.end())\n+\t/*\n+\t * Default to NV12 if the requested format is not supported. All\n+\t * versions of the ISP are guaranteed to support NV12 on both the main\n+\t * and self paths.\n+\t */\n+\tif (!streamFormats_.count(cfg->pixelFormat))\n \t\tcfg->pixelFormat = formats::NV12;\n \n \tcfg->size.boundTo(maxResolution_);\n@@ -204,6 +245,10 @@ void RkISP1Path::stop()\n \trunning_ = false;\n }\n \n+/*\n+ * \\todo Remove the hardcoded resolutions and formats once all users will have\n+ * migrated to a recent enough kernel.\n+ */\n namespace {\n constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 };\n constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 };\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\nindex f3f1ae391d65..d88effbb6f56 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n@@ -8,6 +8,7 @@\n #pragma once\n \n #include <memory>\n+#include <set>\n #include <vector>\n \n #include <libcamera/base/signal.h>\n@@ -57,14 +58,17 @@ public:\n \tSignal<FrameBuffer *> &bufferReady() { return video_->bufferReady; }\n \n private:\n+\tvoid populateFormats();\n+\n \tstatic constexpr unsigned int RKISP1_BUFFER_COUNT = 4;\n \n \tconst char *name_;\n \tbool running_;\n \n \tconst Span<const PixelFormat> formats_;\n-\tconst Size minResolution_;\n-\tconst Size maxResolution_;\n+\tstd::set<PixelFormat> streamFormats_;\n+\tSize minResolution_;\n+\tSize maxResolution_;\n \n \tstd::unique_ptr<V4L2Subdevice> resizer_;\n \tstd::unique_ptr<V4L2VideoDevice> video_;\n","prefixes":["libcamera-devel","v3","10/13"]}