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_;