From patchwork Wed Jul 20 16:40:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 16710 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 714B4BE173 for ; Wed, 20 Jul 2022 16:40:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BB1846330D; Wed, 20 Jul 2022 18:40:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658335221; bh=4lKxeG6LjdTsi8Pa1kiBbEjsKXzLa3oD323IYT3WqoA=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NDdd7QxJCEvM9hMD31vHS2MdMy4C5SaE0xq4JIOXYxKfe7ognMCvfhmADePHyFk7H 3/i45RcwGRT1WAD8Jj2SHdzDItF0tnZnb1741fBq/SzsQf7a5txpIUjGsWfoIEC1hh 7+htpIPmmqRR0+0ckmIJBCpCfKwe4VK0h0tJxhKteHH4El55iyE10SWFot+DqwNerR 5saqOPmcUNXSfAzPc+/oh9ltOnLfjQfklVgBZ9bzVwpQZSk8wjomvimuBUdUahUNOj pL9IATEh4Gzdhia2wAtbKPV6jxKr0vtqtybp09AV6oUlUZYcIyv+pFh43wPhIj4J0o JRxT0/GSxSO9Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7969460489 for ; Wed, 20 Jul 2022 18:40:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wFkms+ic"; dkim-atps=neutral Received: from pyrite.rasen.tech (softbank036240121080.bbtec.net [36.240.121.80]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBF346DB; Wed, 20 Jul 2022 18:40:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658335220; bh=4lKxeG6LjdTsi8Pa1kiBbEjsKXzLa3oD323IYT3WqoA=; h=From:To:Cc:Subject:Date:From; b=wFkms+icy79cIjqiKrseRE6kAXOJ/U0M5xCU4BWfnuMny08u6rdvuAI/mwa/wRjQQ A7ht7lBcEcxBRxDwXlxfDC6NKR9eepFU9CjdVoYB14lVKIaSY/1rNZeU7QPfGY0TiJ 2XMCQw93BaNG5I4AYDLqJp2gdr+m/QIkSMi1N5dY= To: libcamera-devel@lists.libcamera.org Date: Thu, 21 Jul 2022 01:40:04 +0900 Message-Id: <20220720164004.3813194-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2] 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. While at it, cache the framesizes as well. 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 --- Changes in v2: - 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 | 50 +++++++++++++++++-- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 3 ++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 6f175758..cf5feebe 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(video_); + link_ = media->link("rkisp1_isp", 2, resizer, 0); if (!link_) return false; @@ -48,15 +50,44 @@ bool RkISP1Path::init(MediaDevice *media) return true; } +void RkISP1Path::populateFormats(std::unique_ptr &video) +{ + V4L2VideoDevice::Formats v4l2Formats = video->formats(); + if (v4l2Formats.empty()) { + LOG(RkISP1, Warning) + << "Failed to enumerate framesizes. Loading default framesizes"; + + for (const PixelFormat &format : formats_) + streamFormats_[format] = { { minResolution_, maxResolution_ } }; + return; + } + + std::vector formats; + for (auto pair : v4l2Formats) { + const PixelFormat pixelFormat = pair.first.toPixelFormat(); + const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat); + + /* \todo Add support for RAW formats. */ + if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) + continue; + + streamFormats_[pixelFormat] = pair.second; + } +} + StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution) { Size maxResolution = maxResolution_.boundedToAspectRatio(resolution) .boundedTo(resolution); Size minResolution = minResolution_.expandedToAspectRatio(resolution); + /* + * Can we use the global min/max resolutions here or does it need to be + * resized to the same aspect ratio as the requested resolution? + */ std::map> streamFormats; - for (const PixelFormat &format : formats_) - streamFormats[format] = { { minResolution, maxResolution } }; + for (auto pair : streamFormats_) + streamFormats[pair.first] = { { minResolution, maxResolution } }; StreamFormats formats(streamFormats); StreamConfiguration cfg(formats); @@ -72,8 +103,14 @@ 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 (std::find_if(streamFormats_.begin(), streamFormats_.end(), + [cfg](auto pair) { return pair.first == cfg->pixelFormat; }) == + streamFormats_.end()) cfg->pixelFormat = formats::NV12; cfg->size.boundTo(maxResolution_); @@ -207,6 +244,8 @@ void RkISP1Path::stop() namespace { constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 }; constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 }; + +/* \todo Remove this eventually. */ constexpr std::array RKISP1_RSZ_MP_FORMATS{ formats::YUYV, formats::NV16, @@ -214,11 +253,12 @@ constexpr std::array RKISP1_RSZ_MP_FORMATS{ 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 }; + +/* \todo Remove this eventually. */ constexpr std::array RKISP1_RSZ_SP_FORMATS{ formats::YUYV, formats::NV16, diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index f3f1ae39..42db158f 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -57,11 +57,14 @@ public: Signal &bufferReady() { return video_->bufferReady; } private: + void populateFormats(std::unique_ptr &video); + static constexpr unsigned int RKISP1_BUFFER_COUNT = 4; const char *name_; bool running_; + std::map> streamFormats_; const Span formats_; const Size minResolution_; const Size maxResolution_;