From patchwork Tue Jul 19 12:10:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 16688 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 BF615BE173 for ; Tue, 19 Jul 2022 12:10:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 80BD763316; Tue, 19 Jul 2022 14:10:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658232619; bh=vvfiO3dVc7gDxmenoyNqR0bmxkV4ZkX00sO8C3kTbeA=; 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=sPYeQZziu/yreZXRjVs8lwRvoZ6Sd6uCynmIXHDAlEJ0nSHN9rgLrfYtsSlvhfqUI 3beuOkHpe2fqa5fFh7L5fGRnTM/aqufoY1Kua/dT+KuYcV6/KlqAjq3dsjEn5PMovy +amxr2rKWJub/Y7dyHex6B8rs2lAL5rKbcYpqcjFF01BhcFK6zpb51/PuO6CtswWMb ommtrQiWQYpbkEowNTcHI6f5KV9GkQYBQaQ1dIj5BmHV/91RXscS4cyZ9LfeJZZajc Q76SRx41OqhJ/xbhgjSHnsDZT+mz08WcD8GXHaoUSsSCGvFNVO7Js3JH4qNV9Vv7E3 JK4tGP5TOaznA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E4A686048A for ; Tue, 19 Jul 2022 14:10:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RbTyibzR"; dkim-atps=neutral Received: from pyrite.rasen.tech (softbank036240121080.bbtec.net [36.240.121.80]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A1C36EE; Tue, 19 Jul 2022 14:10:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658232617; bh=vvfiO3dVc7gDxmenoyNqR0bmxkV4ZkX00sO8C3kTbeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RbTyibzRqmbyXysMO1R+I9TY90safXz/uBCGcdKnlhnf1K1ZaNPt7h288pYPaquUs E2fkrFLwTbxrArWDvTbd9q9CWU67WSfxvJ3rKPxPUkgXEDK/Zw6PnCvDxdujxxbv4I ap/2SZd3A9yWVqCY4Z8NxLkt4OhOODem5QPcTvG0= To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Jul 2022 21:10:02 +0900 Message-Id: <20220719121003.1829916-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220719121003.1829916-1-paul.elder@ideasonboard.com> References: <20220719121003.1829916-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/2] libcamera: v4l2_videodevice: Get formats even if no framesizes 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: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" V4L2VideoDevice::formats() returns an empty list of formats if enumSizes fails, including if the driver doesn't implement ENUM_FRAMESIZES. Add an optional ignoreSizes parameter to formats() so that it can still be used when the pipeline handler knows that its driver doesn't implement ENUM_FRAMESIZES. Signed-off-by: Paul Elder --- include/libcamera/internal/v4l2_videodevice.h | 2 +- src/libcamera/v4l2_videodevice.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 8525acbc..6cc9be85 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -205,7 +205,7 @@ public: int getFormat(V4L2DeviceFormat *format); int tryFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format); - Formats formats(uint32_t code = 0); + Formats formats(uint32_t code = 0, bool ignoreSizes = false); int setSelection(unsigned int target, Rectangle *rect); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 63911339..b8bd4bc4 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1045,14 +1045,18 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) * * \return A list of the supported video device formats */ -V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code) +V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code, bool ignoreSizes) { Formats formats; for (V4L2PixelFormat pixelFormat : enumPixelformats(code)) { - std::vector sizes = enumSizes(pixelFormat); - if (sizes.empty()) - return {}; + std::vector sizes; + + if (!ignoreSizes) { + sizes = enumSizes(pixelFormat); + if (sizes.empty()) + return {}; + } if (formats.find(pixelFormat) != formats.end()) { LOG(V4L2, Error) From patchwork Tue Jul 19 12:10:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 16689 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 49DE3BE173 for ; Tue, 19 Jul 2022 12:10:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 067C46048A; Tue, 19 Jul 2022 14:10:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658232622; bh=V0GxVPxAtHGHz7vI/8zM3dm/leDGNJAihXMNVAMZTL4=; 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=LqzXK7VO975JZXRrjmSlhy4uamU/6nDV/KeDLHzWgTEr/MKGtrUniAjQLEjKbfqqn nXcHcK0FZ9KLTAFlfz6UqrBA79foFIehNqppXGvI3fCK2M8+pD44sM9mqURtNfcJcT YD3WcpWTgJCFxvWuBq5Q8fyYA5yp08XvpN/JJnmcXrMXjtUIahWNBCdDUB6HtslwIP vPJeMNyRWiDdoEQtLqXWa0W6DHCGeFQ9UHXrIEvimIwDwb/1ppzIueKk3//8W3tB7G zkVPcvJzQXfxNspPu32TQ9VLtHr+fgE4URqD19+TYsREqyCXJj1KMJ4XKbc0TDdDQN 76+W5qb/C7GGQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C85EB63318 for ; Tue, 19 Jul 2022 14:10:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="f/nihdte"; dkim-atps=neutral Received: from pyrite.rasen.tech (softbank036240121080.bbtec.net [36.240.121.80]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E0A46EE; Tue, 19 Jul 2022 14:10:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658232619; bh=V0GxVPxAtHGHz7vI/8zM3dm/leDGNJAihXMNVAMZTL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f/nihdteKACtHyIGDNt4inmqoZGD7AFoDAkUWkJEwY0ww9cBuAmRpXZpXzGMr4HMb irLNJjIwhCEmUWnb50/I8ux0L/FeaJ68zLOLfZkL3be4c/VeC8QYEWaLvpX4lIb0jR rszqqvf1zKc6bCATDdQlKhSHSAq7d/M2usfjJwXM= To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Jul 2022 21:10:03 +0900 Message-Id: <20220719121003.1829916-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220719121003.1829916-1-paul.elder@ideasonboard.com> References: <20220719121003.1829916-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/2] 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: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Query the driver for the output formats that it supports, instead of hardcoding it. This allows future-proofing for formats that are supported by some but not all versions of the driver. Signed-off-by: Paul Elder --- One problem with this patch is that it causes YVU422 to be reported as supported, but as discussed before, libcamera will try to configure a non-existent pixelformat to the V4L2 device, as YVU422P does not exist as a V4L2 format, and there currently is no infrastructure in place to let libcamera configure YVU422M instead (which would work). A patch [1] was submitted to fix this (tell libcamera to configure YVU422M instead of the non-existent YVU422P), but it has been canceled as a parallel effort is apparently in place [2]. [1] https://patchwork.libcamera.org/patch/16573/ [2] https://patchwork.libcamera.org/patch/16573/#23799 src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 50 +++++++++---------- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 6 ++- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 6f175758..00b5c3ed 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -20,9 +20,9 @@ namespace libcamera { LOG_DECLARE_CATEGORY(RkISP1) -RkISP1Path::RkISP1Path(const char *name, const Span &formats, +RkISP1Path::RkISP1Path(const char *name, const Size &minResolution, const Size &maxResolution) - : name_(name), running_(false), formats_(formats), + : name_(name), running_(false), minResolution_(minResolution), maxResolution_(maxResolution), link_(nullptr) { @@ -41,6 +41,8 @@ bool RkISP1Path::init(MediaDevice *media) if (video_->open() < 0) return false; + formats_ = fetchFormats(video_); + link_ = media->link("rkisp1_isp", 2, resizer, 0); if (!link_) return false; @@ -48,6 +50,24 @@ bool RkISP1Path::init(MediaDevice *media) return true; } +std::vector RkISP1Path::fetchFormats(std::unique_ptr &video) +{ + V4L2VideoDevice::Formats v4l2Formats = video->formats(0, true); + std::vector formats; + + for (auto pair : v4l2Formats) { + const PixelFormat pixelFormat = pair.first.toPixelFormat(); + const PixelFormatInfo info = PixelFormatInfo::info(pixelFormat); + + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) + continue; + + formats.push_back(pixelFormat); + } + + return formats; +} + StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution) { Size maxResolution = maxResolution_.boundedToAspectRatio(resolution) @@ -72,6 +92,7 @@ CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg) const StreamConfiguration reqCfg = *cfg; CameraConfiguration::Status status = CameraConfiguration::Valid; + /* NV12 is definitely supported, no need to check */ if (std::find(formats_.begin(), formats_.end(), cfg->pixelFormat) == formats_.end()) cfg->pixelFormat = formats::NV12; @@ -207,39 +228,18 @@ void RkISP1Path::stop() namespace { constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 }; constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 }; -constexpr std::array RKISP1_RSZ_MP_FORMATS{ - formats::YUYV, - formats::NV16, - formats::NV61, - formats::NV21, - formats::NV12, - formats::R8, - /* \todo Add support for RAW formats. */ -}; constexpr Size RKISP1_RSZ_SP_SRC_MIN{ 32, 16 }; constexpr Size RKISP1_RSZ_SP_SRC_MAX{ 1920, 1920 }; -constexpr std::array RKISP1_RSZ_SP_FORMATS{ - formats::YUYV, - formats::NV16, - formats::NV61, - formats::NV21, - formats::NV12, - formats::R8, - formats::RGB565, - formats::XRGB8888, -}; } /* namespace */ RkISP1MainPath::RkISP1MainPath() - : RkISP1Path("main", RKISP1_RSZ_MP_FORMATS, - RKISP1_RSZ_MP_SRC_MIN, RKISP1_RSZ_MP_SRC_MAX) + : RkISP1Path("main", RKISP1_RSZ_MP_SRC_MIN, RKISP1_RSZ_MP_SRC_MAX) { } RkISP1SelfPath::RkISP1SelfPath() - : RkISP1Path("self", RKISP1_RSZ_SP_FORMATS, - RKISP1_RSZ_SP_SRC_MIN, RKISP1_RSZ_SP_SRC_MAX) + : RkISP1Path("self", RKISP1_RSZ_SP_SRC_MIN, RKISP1_RSZ_SP_SRC_MAX) { } diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index f3f1ae39..77ea632b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -30,7 +30,7 @@ struct V4L2SubdeviceFormat; class RkISP1Path { public: - RkISP1Path(const char *name, const Span &formats, + RkISP1Path(const char *name, const Size &minResolution, const Size &maxResolution); bool init(MediaDevice *media); @@ -57,12 +57,14 @@ public: Signal &bufferReady() { return video_->bufferReady; } private: + std::vector fetchFormats(std::unique_ptr &video); + static constexpr unsigned int RKISP1_BUFFER_COUNT = 4; const char *name_; bool running_; - const Span formats_; + std::vector formats_; const Size minResolution_; const Size maxResolution_;