[{"id":23977,"web_url":"https://patchwork.libcamera.org/comment/23977/","msgid":"<YtcmkHpC4s0fwhRp@pendragon.ideasonboard.com>","date":"2022-07-19T21:48:00","subject":"Re: [libcamera-devel] [RFC PATCH 2/2] pipeline: rkisp1: Query the\n\tdriver for formats","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Tue, Jul 19, 2022 at 09:10:03PM +0900, Paul Elder via libcamera-devel wrote:\n> Query the driver for the output formats that it supports, instead of\n> hardcoding it.\n> \n> This allows future-proofing for formats that are supported by some but\n> not all versions of the driver.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n> One problem with this patch is that it causes YVU422 to be reported as\n> supported, but as discussed before, libcamera will try to configure a\n> non-existent pixelformat to the V4L2 device, as YVU422P does not exist\n> as a V4L2 format, and there currently is no infrastructure in place to\n> let libcamera configure YVU422M instead (which would work).\n\nI think that's fine for now, planar YUV formats are less commonly used\nthat packed and semi-planar YUV formats, so we can live with this until\nJacopo's work gets merged.\n\n> A patch [1] was submitted to fix this (tell libcamera to configure\n> YVU422M instead of the non-existent YVU422P), but it has been canceled\n> as a parallel effort is apparently in place [2].\n> \n> [1] https://patchwork.libcamera.org/patch/16573/\n> [2] https://patchwork.libcamera.org/patch/16573/#23799\n> \n>  src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 50 +++++++++----------\n>  src/libcamera/pipeline/rkisp1/rkisp1_path.h   |  6 ++-\n>  2 files changed, 29 insertions(+), 27 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> index 6f175758..00b5c3ed 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> @@ -20,9 +20,9 @@ namespace libcamera {\n>  \n>  LOG_DECLARE_CATEGORY(RkISP1)\n>  \n> -RkISP1Path::RkISP1Path(const char *name, const Span<const PixelFormat> &formats,\n> +RkISP1Path::RkISP1Path(const char *name,\n>  \t\t       const Size &minResolution, const Size &maxResolution)\n> -\t: name_(name), running_(false), formats_(formats),\n> +\t: name_(name), running_(false),\n>  \t  minResolution_(minResolution), maxResolution_(maxResolution),\n>  \t  link_(nullptr)\n>  {\n> @@ -41,6 +41,8 @@ bool RkISP1Path::init(MediaDevice *media)\n>  \tif (video_->open() < 0)\n>  \t\treturn false;\n>  \n> +\tformats_ = fetchFormats(video_);\n\n\tif (formats_.empty())\n\t\t/* Error handling */\n\n> +\n>  \tlink_ = media->link(\"rkisp1_isp\", 2, resizer, 0);\n>  \tif (!link_)\n>  \t\treturn false;\n> @@ -48,6 +50,24 @@ bool RkISP1Path::init(MediaDevice *media)\n>  \treturn true;\n>  }\n>  \n> +std::vector<PixelFormat> RkISP1Path::fetchFormats(std::unique_ptr<V4L2VideoDevice> &video)\n\nYou could call this populateFormats() and operate on formats_ directly,\ninstead of returning a vector. This would free the return value for an\nerror code, and will also come handy (I think) when expanding this\nfunction to also populate the min/max supported sizes dynamically.\n\n> +{\n> +\tV4L2VideoDevice::Formats v4l2Formats = video->formats(0, true);\n> +\tstd::vector<PixelFormat> formats;\n> +\n> +\tfor (auto pair : v4l2Formats) {\n> +\t\tconst PixelFormat pixelFormat = pair.first.toPixelFormat();\n> +\t\tconst PixelFormatInfo info = PixelFormatInfo::info(pixelFormat);\n\n\t\tconst PixelFormatInfo &info\n\n> +\n> +\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)\n> +\t\t\tcontinue;\n> +\n> +\t\tformats.push_back(pixelFormat);\n> +\t}\n> +\n> +\treturn formats;\n> +}\n> +\n>  StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution)\n>  {\n>  \tSize maxResolution = maxResolution_.boundedToAspectRatio(resolution)\n> @@ -72,6 +92,7 @@ CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg)\n>  \tconst StreamConfiguration reqCfg = *cfg;\n>  \tCameraConfiguration::Status status = CameraConfiguration::Valid;\n>  \n> +\t/* NV12 is definitely supported, no need to check */\n\nI'd move this comment within the if, or write it as\n\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\n>  \tif (std::find(formats_.begin(), formats_.end(), cfg->pixelFormat) ==\n>  \t    formats_.end())\n>  \t\tcfg->pixelFormat = formats::NV12;\n> @@ -207,39 +228,18 @@ void RkISP1Path::stop()\n>  namespace {\n>  constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 };\n>  constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 };\n> -constexpr std::array<PixelFormat, 6> RKISP1_RSZ_MP_FORMATS{\n> -\tformats::YUYV,\n> -\tformats::NV16,\n> -\tformats::NV61,\n> -\tformats::NV21,\n> -\tformats::NV12,\n> -\tformats::R8,\n> -\t/* \\todo Add support for RAW formats. */\n> -};\n>  \n>  constexpr Size RKISP1_RSZ_SP_SRC_MIN{ 32, 16 };\n>  constexpr Size RKISP1_RSZ_SP_SRC_MAX{ 1920, 1920 };\n> -constexpr std::array<PixelFormat, 8> RKISP1_RSZ_SP_FORMATS{\n> -\tformats::YUYV,\n> -\tformats::NV16,\n> -\tformats::NV61,\n> -\tformats::NV21,\n> -\tformats::NV12,\n> -\tformats::R8,\n> -\tformats::RGB565,\n> -\tformats::XRGB8888,\n> -};\n>  } /* namespace */\n>  \n>  RkISP1MainPath::RkISP1MainPath()\n> -\t: RkISP1Path(\"main\", RKISP1_RSZ_MP_FORMATS,\n> -\t\t     RKISP1_RSZ_MP_SRC_MIN, RKISP1_RSZ_MP_SRC_MAX)\n> +\t: RkISP1Path(\"main\", RKISP1_RSZ_MP_SRC_MIN, RKISP1_RSZ_MP_SRC_MAX)\n>  {\n>  }\n>  \n>  RkISP1SelfPath::RkISP1SelfPath()\n> -\t: RkISP1Path(\"self\", RKISP1_RSZ_SP_FORMATS,\n> -\t\t     RKISP1_RSZ_SP_SRC_MIN, RKISP1_RSZ_SP_SRC_MAX)\n> +\t: RkISP1Path(\"self\", RKISP1_RSZ_SP_SRC_MIN, RKISP1_RSZ_SP_SRC_MAX)\n\nI like how Jacopo's suggestion in 1/2 will allow dropping the min/max\nvalues passed to the constructor here. This could be done in this patch,\nor on top.\n\n>  {\n>  }\n>  \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> index f3f1ae39..77ea632b 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> @@ -30,7 +30,7 @@ struct V4L2SubdeviceFormat;\n>  class RkISP1Path\n>  {\n>  public:\n> -\tRkISP1Path(const char *name, const Span<const PixelFormat> &formats,\n> +\tRkISP1Path(const char *name,\n>  \t\t   const Size &minResolution, const Size &maxResolution);\n>  \n>  \tbool init(MediaDevice *media);\n> @@ -57,12 +57,14 @@ public:\n>  \tSignal<FrameBuffer *> &bufferReady() { return video_->bufferReady; }\n>  \n>  private:\n> +\tstd::vector<PixelFormat> fetchFormats(std::unique_ptr<V4L2VideoDevice> &video);\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> +\tstd::vector<PixelFormat> formats_;\n>  \tconst Size minResolution_;\n>  \tconst Size maxResolution_;\n>","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 83760BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Jul 2022 21:48:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DDF8F63312;\n\tTue, 19 Jul 2022 23:48:35 +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 67F1F603F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Jul 2022 23:48:34 +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 CD4436EE;\n\tTue, 19 Jul 2022 23:48:33 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658267315;\n\tbh=epERdqyONTo0matceB8DZHhojzxu+TPqnTIxfnjJ858=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=UJDU4shixFbF+HyEoFuwtgF5lxjCAc5Avhbq8AO/p9x90H1Hzi0yTdPV1SjzAT1S5\n\tOmWgo2SrLM455lfrX2P2B1oKb9Oz3zMcx4mX2/Wz7wEH4uCouu+H/OSkjL2+gCTJzO\n\td2i/Q/HTaPVVWR4sUhIGOjmQFPFws/3JVLPhi4kT+y6aHkonuQMipDSMPIj/zi9WTu\n\tCvVM4nRFUQy1KYOoS6ZD8ZR0YOJKRYZYg4TrLDiAFp11+bWq6QY8jC3UwpDSrqnz7u\n\tPb3lJv/pgr5tm4VMEB6fyBP9S2XUsOVgBQJiosr71CBaeNImipL/LDSAd06V7AoY5S\n\tmbm5fBtJDbckg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1658267314;\n\tbh=epERdqyONTo0matceB8DZHhojzxu+TPqnTIxfnjJ858=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=RVkHTeqO4sA07vU21KOmKilvThj0YdnPNUyseK1kMimru0QYKuhmTSfRCpJUYzUyi\n\tv8XNBw+9KbX6omLxZ9PxuHOhXULbWC4sN6t3ni3APBENDpYzDLTIUyUpNEo+xjyX+s\n\tCogMFo4a1xHc1HLmY/zuwAU2CSqQGUQkIzDxn3TU="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"RVkHTeqO\"; dkim-atps=neutral","Date":"Wed, 20 Jul 2022 00:48:00 +0300","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<YtcmkHpC4s0fwhRp@pendragon.ideasonboard.com>","References":"<20220719121003.1829916-1-paul.elder@ideasonboard.com>\n\t<20220719121003.1829916-3-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220719121003.1829916-3-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [RFC PATCH 2/2] 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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]